1
package org.bouncycastle.asn1.x9;
3
import org.bouncycastle.asn1.ASN1Encodable;
4
import org.bouncycastle.asn1.ASN1EncodableVector;
5
import org.bouncycastle.asn1.ASN1OctetString;
6
import org.bouncycastle.asn1.ASN1Sequence;
7
import org.bouncycastle.asn1.DERInteger;
8
import org.bouncycastle.asn1.DERObject;
9
import org.bouncycastle.asn1.DERSequence;
10
import org.bouncycastle.math.ec.ECCurve;
11
import org.bouncycastle.math.ec.ECPoint;
13
import java.math.BigInteger;
16
* ASN.1 def for Elliptic-Curve ECParameters structure. See
17
* X9.62, for further details.
19
public class X9ECParameters
21
implements X9ObjectIdentifiers
23
private static final BigInteger ONE = BigInteger.valueOf(1);
25
private X9FieldID fieldID;
26
private ECCurve curve;
32
public X9ECParameters(
35
if (!(seq.getObjectAt(0) instanceof DERInteger)
36
|| !((DERInteger)seq.getObjectAt(0)).getValue().equals(ONE))
38
throw new IllegalArgumentException("bad version in X9ECParameters");
41
X9Curve x9c = new X9Curve(
42
new X9FieldID((ASN1Sequence)seq.getObjectAt(1)),
43
(ASN1Sequence)seq.getObjectAt(2));
45
this.curve = x9c.getCurve();
46
this.g = new X9ECPoint(curve, (ASN1OctetString)seq.getObjectAt(3)).getPoint();
47
this.n = ((DERInteger)seq.getObjectAt(4)).getValue();
48
this.seed = x9c.getSeed();
52
this.h = ((DERInteger)seq.getObjectAt(5)).getValue();
56
public X9ECParameters(
61
this(curve, g, n, ONE, null);
64
public X9ECParameters(
70
this(curve, g, n, h, null);
73
public X9ECParameters(
86
if (curve instanceof ECCurve.Fp)
88
this.fieldID = new X9FieldID(((ECCurve.Fp)curve).getQ());
92
if (curve instanceof ECCurve.F2m)
94
ECCurve.F2m curveF2m = (ECCurve.F2m)curve;
95
this.fieldID = new X9FieldID(curveF2m.getM(), curveF2m.getK1(),
96
curveF2m.getK2(), curveF2m.getK3());
101
public ECCurve getCurve()
106
public ECPoint getG()
111
public BigInteger getN()
116
public BigInteger getH()
120
return ONE; // TODO - this should be calculated, it will cause issues with custom curves.
126
public byte[] getSeed()
132
* Produce an object suitable for an ASN1OutputStream.
134
* ECParameters ::= SEQUENCE {
135
* version INTEGER { ecpVer1(1) } (ecpVer1),
136
* fieldID FieldID {{FieldTypes}},
140
* cofactor INTEGER OPTIONAL
144
public DERObject toASN1Object()
146
ASN1EncodableVector v = new ASN1EncodableVector();
148
v.add(new DERInteger(1));
150
v.add(new X9Curve(curve, seed));
151
v.add(new X9ECPoint(g));
152
v.add(new DERInteger(n));
156
v.add(new DERInteger(h));
159
return new DERSequence(v);