01: package org.bouncycastle.asn1.x9;
02:
03: import java.math.BigInteger;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1EncodableVector;
07: import org.bouncycastle.asn1.ASN1Sequence;
08: import org.bouncycastle.asn1.DERInteger;
09: import org.bouncycastle.asn1.DERObject;
10: import org.bouncycastle.asn1.DERObjectIdentifier;
11: import org.bouncycastle.asn1.DERSequence;
12:
13: /**
14: * ASN.1 def for Elliptic-Curve Field ID structure. See
15: * X9.62, for further details.
16: */
17: public class X9FieldID extends ASN1Encodable implements
18: X9ObjectIdentifiers {
19: private DERObjectIdentifier id;
20: private DERObject parameters;
21:
22: /**
23: * Constructor for elliptic curves over prime fields
24: * <code>F<sub>2</sub></code>.
25: * @param primeP The prime <code>p</code> defining the prime field.
26: */
27: public X9FieldID(BigInteger primeP) {
28: this .id = prime_field;
29: this .parameters = new DERInteger(primeP);
30: }
31:
32: /**
33: * Constructor for elliptic curves over binary fields
34: * <code>F<sub>2<sup>m</sup></sub></code>.
35: * @param m The exponent <code>m</code> of
36: * <code>F<sub>2<sup>m</sup></sub></code>.
37: * @param k1 The integer <code>k1</code> where <code>x<sup>m</sup> +
38: * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
39: * represents the reduction polynomial <code>f(z)</code>.
40: * @param k2 The integer <code>k2</code> where <code>x<sup>m</sup> +
41: * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
42: * represents the reduction polynomial <code>f(z)</code>.
43: * @param k3 The integer <code>k3</code> where <code>x<sup>m</sup> +
44: * x<sup>k3</sup> + x<sup>k2</sup> + x<sup>k1</sup> + 1</code>
45: * represents the reduction polynomial <code>f(z)</code>..
46: */
47: public X9FieldID(int m, int k1, int k2, int k3) {
48: this .id = characteristic_two_field;
49: ASN1EncodableVector fieldIdParams = new ASN1EncodableVector();
50: fieldIdParams.add(new DERInteger(m));
51:
52: if (k2 == 0) {
53: fieldIdParams.add(tpBasis);
54: fieldIdParams.add(new DERInteger(k1));
55: } else {
56: fieldIdParams.add(ppBasis);
57: ASN1EncodableVector pentanomialParams = new ASN1EncodableVector();
58: pentanomialParams.add(new DERInteger(k1));
59: pentanomialParams.add(new DERInteger(k2));
60: pentanomialParams.add(new DERInteger(k3));
61: fieldIdParams.add(new DERSequence(pentanomialParams));
62: }
63:
64: this .parameters = new DERSequence(fieldIdParams);
65: }
66:
67: public X9FieldID(ASN1Sequence seq) {
68: this .id = (DERObjectIdentifier) seq.getObjectAt(0);
69: this .parameters = (DERObject) seq.getObjectAt(1);
70: }
71:
72: public DERObjectIdentifier getIdentifier() {
73: return id;
74: }
75:
76: public DERObject getParameters() {
77: return parameters;
78: }
79:
80: /**
81: * Produce a DER encoding of the following structure.
82: * <pre>
83: * FieldID ::= SEQUENCE {
84: * fieldType FIELD-ID.&id({IOSet}),
85: * parameters FIELD-ID.&Type({IOSet}{@fieldType})
86: * }
87: * </pre>
88: */
89: public DERObject toASN1Object() {
90: ASN1EncodableVector v = new ASN1EncodableVector();
91:
92: v.add(this .id);
93: v.add(this .parameters);
94:
95: return new DERSequence(v);
96: }
97: }
|