Search in sources :

Example 46 with ECFieldF2m

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

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 47 with ECFieldF2m

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

the class ECNamedCurveSpec method convertCurve.

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);
        }
    }
}
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 48 with ECFieldF2m

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

the class ECFieldF2mTest method testEqualsObject05.

/**
     * Test #5 for <code>equals()</code> method.<br>
     *
     * Assertion: objects equal if their m, and rp are mutually equal.
     */
public final void testEqualsObject05() {
    ECFieldF2m f1 = new ECFieldF2m(2000);
    ECFieldF2m f2 = new ECFieldF2m(2000, BigInteger.valueOf(0L).setBit(0).setBit(1).setBit(2).setBit(981).setBit(2000));
    assertFalse(f1.equals(f2) || f2.equals(f1));
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m)

Example 49 with ECFieldF2m

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

the class OpenSSLECGroupContext method getInstance.

public static OpenSSLECGroupContext getInstance(ECParameterSpec params) throws InvalidAlgorithmParameterException {
    final String curveName = params.getCurveName();
    if (curveName != null) {
        return OpenSSLECGroupContext.getCurveByName(curveName);
    }
    final EllipticCurve curve = params.getCurve();
    final ECField field = curve.getField();
    final int type;
    final BigInteger p;
    if (field instanceof ECFieldFp) {
        type = NativeCrypto.EC_CURVE_GFP;
        p = ((ECFieldFp) field).getP();
    } else if (field instanceof ECFieldF2m) {
        type = NativeCrypto.EC_CURVE_GF2M;
        p = ((ECFieldF2m) field).getReductionPolynomial();
    } else {
        throw new InvalidParameterException("unhandled field class " + field.getClass().getName());
    }
    final ECPoint generator = params.getGenerator();
    return OpenSSLECGroupContext.getInstance(type, p, curve.getA(), curve.getB(), generator.getAffineX(), generator.getAffineY(), params.getOrder(), BigInteger.valueOf(params.getCofactor()));
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint) ECPoint(java.security.spec.ECPoint)

Example 50 with ECFieldF2m

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

the class OpenSSLECGroupContext method getECParameterSpec.

public ECParameterSpec getECParameterSpec() {
    final String curveName = NativeCrypto.EC_GROUP_get_curve_name(groupCtx);
    final byte[][] curveParams = NativeCrypto.EC_GROUP_get_curve(groupCtx);
    final BigInteger p = new BigInteger(curveParams[0]);
    final BigInteger a = new BigInteger(curveParams[1]);
    final BigInteger b = new BigInteger(curveParams[2]);
    final ECField field;
    final int type = NativeCrypto.get_EC_GROUP_type(groupCtx);
    if (type == NativeCrypto.EC_CURVE_GFP) {
        field = new ECFieldFp(p);
    } else if (type == NativeCrypto.EC_CURVE_GF2M) {
        field = new ECFieldF2m(p.bitLength() - 1, p);
    } else {
        throw new RuntimeException("unknown curve type " + type);
    }
    final EllipticCurve curve = new EllipticCurve(field, a, b);
    final OpenSSLECPointContext generatorCtx = new OpenSSLECPointContext(this, NativeCrypto.EC_GROUP_get_generator(groupCtx));
    final ECPoint generator = generatorCtx.getECPoint();
    final BigInteger order = new BigInteger(NativeCrypto.EC_GROUP_get_order(groupCtx));
    final BigInteger cofactor = new BigInteger(NativeCrypto.EC_GROUP_get_cofactor(groupCtx));
    return new ECParameterSpec(curve, generator, order, cofactor.intValue(), curveName);
}
Also used : ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) ECParameterSpec(java.security.spec.ECParameterSpec) BigInteger(java.math.BigInteger) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint) ECPoint(java.security.spec.ECPoint)

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