org.spongycastle.asn1.x9.X9FieldID Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scprov-jdk15 Show documentation
Show all versions of scprov-jdk15 Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for Android.
Android ships with a stripped-down version of Bouncy Castle - this causes classloader collisions if you try to add
an alternative (updated/complete) Bouncy Castle jar.
This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.
package org.spongycastle.asn1.x9;
import java.math.BigInteger;
import org.spongycastle.asn1.ASN1Encodable;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.DERInteger;
import org.spongycastle.asn1.DERObject;
import org.spongycastle.asn1.DERObjectIdentifier;
import org.spongycastle.asn1.DERSequence;
/**
* ASN.1 def for Elliptic-Curve Field ID structure. See
* X9.62, for further details.
*/
public class X9FieldID
extends ASN1Encodable
implements X9ObjectIdentifiers
{
private DERObjectIdentifier id;
private DERObject parameters;
/**
* Constructor for elliptic curves over prime fields
* F2
.
* @param primeP The prime p
defining the prime field.
*/
public X9FieldID(BigInteger primeP)
{
this.id = prime_field;
this.parameters = new DERInteger(primeP);
}
/**
* Constructor for elliptic curves over binary fields
* F2m
.
* @param m The exponent m
of
* F2m
.
* @param k1 The integer k1
where xm +
* xk3 + xk2 + xk1 + 1
* represents the reduction polynomial f(z)
.
* @param k2 The integer k2
where xm +
* xk3 + xk2 + xk1 + 1
* represents the reduction polynomial f(z)
.
* @param k3 The integer k3
where xm +
* xk3 + xk2 + xk1 + 1
* represents the reduction polynomial f(z)
..
*/
public X9FieldID(int m, int k1, int k2, int k3)
{
this.id = characteristic_two_field;
ASN1EncodableVector fieldIdParams = new ASN1EncodableVector();
fieldIdParams.add(new DERInteger(m));
if (k2 == 0)
{
fieldIdParams.add(tpBasis);
fieldIdParams.add(new DERInteger(k1));
}
else
{
fieldIdParams.add(ppBasis);
ASN1EncodableVector pentanomialParams = new ASN1EncodableVector();
pentanomialParams.add(new DERInteger(k1));
pentanomialParams.add(new DERInteger(k2));
pentanomialParams.add(new DERInteger(k3));
fieldIdParams.add(new DERSequence(pentanomialParams));
}
this.parameters = new DERSequence(fieldIdParams);
}
public X9FieldID(
ASN1Sequence seq)
{
this.id = (DERObjectIdentifier)seq.getObjectAt(0);
this.parameters = (DERObject)seq.getObjectAt(1);
}
public DERObjectIdentifier getIdentifier()
{
return id;
}
public DERObject getParameters()
{
return parameters;
}
/**
* Produce a DER encoding of the following structure.
*
* FieldID ::= SEQUENCE {
* fieldType FIELD-ID.&id({IOSet}),
* parameters FIELD-ID.&Type({IOSet}{@fieldType})
* }
*
*/
public DERObject toASN1Object()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(this.id);
v.add(this.parameters);
return new DERSequence(v);
}
}