01: package org.bouncycastle.jce.spec;
02:
03: import java.math.BigInteger;
04: import java.security.spec.ECFieldF2m;
05: import java.security.spec.ECFieldFp;
06: import java.security.spec.ECPoint;
07: import java.security.spec.EllipticCurve;
08:
09: import org.bouncycastle.math.ec.ECCurve;
10:
11: /**
12: * specification signifying that the curve parameters can also be
13: * referred to by name.
14: */
15: public class ECNamedCurveSpec extends
16: java.security.spec.ECParameterSpec {
17: private String name;
18:
19: private static EllipticCurve convertCurve(ECCurve curve, byte[] seed) {
20: if (curve instanceof ECCurve.Fp) {
21: return new EllipticCurve(new ECFieldFp(((ECCurve.Fp) curve)
22: .getQ()), curve.getA().toBigInteger(), curve.getB()
23: .toBigInteger(), seed);
24: } else {
25: ECCurve.F2m curveF2m = (ECCurve.F2m) curve;
26: int ks[];
27:
28: if (curveF2m.isTrinomial()) {
29: ks = new int[] { curveF2m.getK1() };
30:
31: return new EllipticCurve(new ECFieldF2m(
32: curveF2m.getM(), ks), curve.getA()
33: .toBigInteger(), curve.getB().toBigInteger(),
34: seed);
35: } else {
36: ks = new int[] { curveF2m.getK3(), curveF2m.getK2(),
37: curveF2m.getK1() };
38:
39: return new EllipticCurve(new ECFieldF2m(
40: curveF2m.getM(), ks), curve.getA()
41: .toBigInteger(), curve.getB().toBigInteger(),
42: seed);
43: }
44: }
45:
46: }
47:
48: private static ECPoint convertPoint(
49: org.bouncycastle.math.ec.ECPoint g) {
50: return new ECPoint(g.getX().toBigInteger(), g.getY()
51: .toBigInteger());
52: }
53:
54: public ECNamedCurveSpec(String name, ECCurve curve,
55: org.bouncycastle.math.ec.ECPoint g, BigInteger n) {
56: super (convertCurve(curve, null), convertPoint(g), n, 1);
57:
58: this .name = name;
59: }
60:
61: public ECNamedCurveSpec(String name, EllipticCurve curve,
62: ECPoint g, BigInteger n) {
63: super (curve, g, n, 1);
64:
65: this .name = name;
66: }
67:
68: public ECNamedCurveSpec(String name, ECCurve curve,
69: org.bouncycastle.math.ec.ECPoint g, BigInteger n,
70: BigInteger h) {
71: super (convertCurve(curve, null), convertPoint(g), n, h
72: .intValue());
73:
74: this .name = name;
75: }
76:
77: public ECNamedCurveSpec(String name, EllipticCurve curve,
78: ECPoint g, BigInteger n, BigInteger h) {
79: super (curve, g, n, h.intValue());
80:
81: this .name = name;
82: }
83:
84: public ECNamedCurveSpec(String name, ECCurve curve,
85: org.bouncycastle.math.ec.ECPoint g, BigInteger n,
86: BigInteger h, byte[] seed) {
87: super (convertCurve(curve, seed), convertPoint(g), n, h
88: .intValue());
89:
90: this .name = name;
91: }
92:
93: /**
94: * return the name of the curve the EC domain parameters belong to.
95: */
96: public String getName() {
97: return name;
98: }
99: }
|