Search in sources :

Example 6 with ECFieldFp

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

the class EllipticCurveTest method testEqualsObject01.

/**
     * Test #1 for <code>equals(Object other)</code> method<br>
     * Assertion: return true if this and other objects are equal<br>
     * Test preconditions: see test comments<br>
     * Expected: all objects in this test must be equal
     */
public final void testEqualsObject01() {
    // test case 1: must be equal to itself
    EllipticCurve c2 = null, c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L));
    assertTrue(c1.equals(c1));
    // test case 2: equal objects
    c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L));
    c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.valueOf(1L), BigInteger.valueOf(19L));
    assertTrue(c1.equals(c2) && c2.equals(c1));
    // test case 3: equal objects with seed not null
    c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]);
    c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.valueOf(1L), BigInteger.valueOf(19L), new byte[24]);
    assertTrue(c1.equals(c2) && c2.equals(c1));
    // test case 4: equal object and subclass object
    c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]);
    MyEllipticCurve c3 = new MyEllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]);
    assertTrue(c1.equals(c3) && c3.equals(c1));
    // test case 5: equal objects
    c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L));
    c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.valueOf(1L), BigInteger.valueOf(19L), null);
    assertTrue(c1.equals(c2) && c2.equals(c1));
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve)

Example 7 with ECFieldFp

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

the class ECFieldFpTest method testEqualsObject01.

/**
     * Test #1 for <code>equals()</code> method.<br>
     *
     * Assertion: object equals to itself.
     */
public final void testEqualsObject01() {
    ECFieldFp obj = new ECFieldFp(BigInteger.valueOf(23L));
    assertTrue(obj.equals(obj));
}
Also used : ECFieldFp(java.security.spec.ECFieldFp)

Example 8 with ECFieldFp

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

the class ECFieldFpTest method testHashCode01.

/**
     * Test #1 for <code>hashCode()</code> method.<br>
     *
     * Assertion: must return the same value if invoked
     * repeatedly on the same object.
     */
public final void testHashCode01() {
    ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    int hc = f.hashCode();
    assertTrue(hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode());
}
Also used : ECFieldFp(java.security.spec.ECFieldFp)

Example 9 with ECFieldFp

use of java.security.spec.ECFieldFp 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 10 with ECFieldFp

use of java.security.spec.ECFieldFp 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

ECFieldFp (java.security.spec.ECFieldFp)42 EllipticCurve (java.security.spec.EllipticCurve)34 BigInteger (java.math.BigInteger)30 ECFieldF2m (java.security.spec.ECFieldF2m)12 ECPoint (java.security.spec.ECPoint)8 ECField (java.security.spec.ECField)6 ECCurve (org.bouncycastle.math.ec.ECCurve)4 ECParameterSpec (java.security.spec.ECParameterSpec)3 GeneralSecurityException (java.security.GeneralSecurityException)2 InvalidParameterException (java.security.InvalidParameterException)1