Search in sources :

Example 11 with ECFieldF2m

use of java.security.spec.ECFieldF2m in project j2objc by google.

the class ECParameterSpecTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    curve = new EllipticCurve(new ECFieldF2m(2), BigInteger.valueOf(1), BigInteger.valueOf(1));
    ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1));
    ecps = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1);
}
Also used : EllipticCurve(java.security.spec.EllipticCurve) ECParameterSpec(java.security.spec.ECParameterSpec) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint)

Example 12 with ECFieldF2m

use of java.security.spec.ECFieldF2m in project XobotOS by xamarin.

the class EC5Util method convertCurve.

public static EllipticCurve convertCurve(ECCurve curve, byte[] seed) {
    // so at the moment it's set to null. Should probably look at making this configurable
    if (curve instanceof ECCurve.Fp) {
        return new EllipticCurve(new ECFieldFp(((ECCurve.Fp) curve).getQ()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
    } 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(), null);
        } else {
            ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() };
            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
        }
    }
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) ECCurve(org.bouncycastle.math.ec.ECCurve) ECFieldFp(java.security.spec.ECFieldFp) ECFieldF2m(java.security.spec.ECFieldF2m)

Example 13 with ECFieldF2m

use of java.security.spec.ECFieldF2m in project XobotOS by xamarin.

the class EC5Util method convertCurve.

public static ECCurve convertCurve(EllipticCurve ec) {
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();
    if (field instanceof ECFieldFp) {
        return new ECCurve.Fp(((ECFieldFp) field).getP(), a, b);
    } else {
        ECFieldF2m fieldF2m = (ECFieldF2m) field;
        int m = fieldF2m.getM();
        int[] ks = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());
        return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b);
    }
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m) ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) BigInteger(java.math.BigInteger) ECFieldFp(java.security.spec.ECFieldFp) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint)

Example 14 with ECFieldF2m

use of java.security.spec.ECFieldF2m in project robovm by robovm.

the class EC5Util method convertCurve.

public static ECCurve convertCurve(EllipticCurve ec) {
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();
    if (field instanceof ECFieldFp) {
        return new ECCurve.Fp(((ECFieldFp) field).getP(), a, b);
    } else {
        ECFieldF2m fieldF2m = (ECFieldF2m) field;
        int m = fieldF2m.getM();
        int[] ks = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());
        return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b);
    }
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m) ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) BigInteger(java.math.BigInteger) ECFieldFp(java.security.spec.ECFieldFp) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint)

Example 15 with ECFieldF2m

use of java.security.spec.ECFieldF2m in project robovm by robovm.

the class EC5Util method convertCurve.

public static EllipticCurve convertCurve(ECCurve curve, byte[] seed) {
    // so at the moment it's set to null. Should probably look at making this configurable
    if (curve instanceof ECCurve.Fp) {
        return new EllipticCurve(new ECFieldFp(((ECCurve.Fp) curve).getQ()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
    } 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(), null);
        } else {
            ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() };
            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
        }
    }
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) ECCurve(org.bouncycastle.math.ec.ECCurve) ECFieldFp(java.security.spec.ECFieldFp) ECFieldF2m(java.security.spec.ECFieldF2m)

Aggregations

ECFieldF2m (java.security.spec.ECFieldF2m)50 EllipticCurve (java.security.spec.EllipticCurve)28 BigInteger (java.math.BigInteger)22 ECFieldFp (java.security.spec.ECFieldFp)12 ECPoint (java.security.spec.ECPoint)10 ECParameterSpec (java.security.spec.ECParameterSpec)7 ECField (java.security.spec.ECField)4 ECCurve (org.bouncycastle.math.ec.ECCurve)4 ECPrivateKeySpec (java.security.spec.ECPrivateKeySpec)2 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)2 InvalidParameterException (java.security.InvalidParameterException)1