diff options
Diffstat (limited to 'libraries/spongycastle/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveSpec.java')
-rw-r--r-- | libraries/spongycastle/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveSpec.java | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/libraries/spongycastle/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveSpec.java b/libraries/spongycastle/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveSpec.java new file mode 100644 index 000000000..68b64a2a0 --- /dev/null +++ b/libraries/spongycastle/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveSpec.java @@ -0,0 +1,122 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; +import java.security.spec.ECFieldF2m; +import java.security.spec.ECFieldFp; +import java.security.spec.ECPoint; +import java.security.spec.EllipticCurve; + +import org.spongycastle.math.ec.ECCurve; + +/** + * specification signifying that the curve parameters can also be + * referred to by name. + */ +public class ECNamedCurveSpec + extends java.security.spec.ECParameterSpec +{ + private String name; + + private static EllipticCurve convertCurve( + ECCurve curve, + byte[] seed) + { + if (curve instanceof ECCurve.Fp) + { + return new EllipticCurve(new ECFieldFp(((ECCurve.Fp)curve).getQ()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed); + } + else + { + ECCurve.F2m curveF2m = (ECCurve.F2m)curve; + int ks[]; + + if (curveF2m.isTrinomial()) + { + ks = new int[] { curveF2m.getK1() }; + + return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed); + } + else + { + ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() }; + + return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed); + } + } + + } + + private static ECPoint convertPoint( + org.spongycastle.math.ec.ECPoint g) + { + g = g.normalize(); + return new ECPoint(g.getAffineXCoord().toBigInteger(), g.getAffineYCoord().toBigInteger()); + } + + public ECNamedCurveSpec( + String name, + ECCurve curve, + org.spongycastle.math.ec.ECPoint g, + BigInteger n) + { + super(convertCurve(curve, null), convertPoint(g), n, 1); + + this.name = name; + } + + public ECNamedCurveSpec( + String name, + EllipticCurve curve, + ECPoint g, + BigInteger n) + { + super(curve, g, n, 1); + + this.name = name; + } + + public ECNamedCurveSpec( + String name, + ECCurve curve, + org.spongycastle.math.ec.ECPoint g, + BigInteger n, + BigInteger h) + { + super(convertCurve(curve, null), convertPoint(g), n, h.intValue()); + + this.name = name; + } + + public ECNamedCurveSpec( + String name, + EllipticCurve curve, + ECPoint g, + BigInteger n, + BigInteger h) + { + super(curve, g, n, h.intValue()); + + this.name = name; + } + + public ECNamedCurveSpec( + String name, + ECCurve curve, + org.spongycastle.math.ec.ECPoint g, + BigInteger n, + BigInteger h, + byte[] seed) + { + super(convertCurve(curve, seed), convertPoint(g), n, h.intValue()); + + this.name = name; + } + + /** + * return the name of the curve the EC domain parameters belong to. + */ + public String getName() + { + return name; + } +} |