Search in sources :

Example 31 with ECFieldFp

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigInteger03.

/**
     * Test #3 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code>
     * constructor<br>
     * Assertion: throws <code>IllegalArgumentException</code> if
     * <code>a</code> or <code>b</code> is not <code>null</code> and not in
     * the <code>field</code><br>
     * Test preconditions: pass <code>a</code>, <code>b</code> which are
     * not in the <code>field</code> of type <code>ECFieldFp</code><br>
     * Expected: must throw <code>IllegalArgumentException</code>
     */
public final void testEllipticCurveECFieldBigIntegerBigInteger03() {
    // test case 1 parameters set,
    // a is not in field
    ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    BigInteger a = BigInteger.valueOf(24L);
    BigInteger b = BigInteger.valueOf(19L);
    // perform test case 1
    try {
        new EllipticCurve(f, a, b);
        fail("#1: Expected IAE not thrown");
    } catch (IllegalArgumentException ok) {
    }
    // test case 1.1 parameters set,
    // a is not in field
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.valueOf(23L);
    b = BigInteger.valueOf(19L);
    // perform test case 1.1
    try {
        new EllipticCurve(f, a, b);
        fail("#1.1: Expected IAE not thrown");
    } catch (IllegalArgumentException ok) {
    }
    // test case 2 parameters set,
    // b is not in field
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.valueOf(19L);
    b = BigInteger.valueOf(24L);
    // perform test case 2
    try {
        new EllipticCurve(f, a, b);
        fail("#2: Expected IAE not thrown");
    } catch (IllegalArgumentException ok) {
    }
    // test case 3 parameters set,
    // both a and b are not in field
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.valueOf(25L);
    b = BigInteger.valueOf(240L);
    // perform test case 3
    try {
        new EllipticCurve(f, a, b);
        fail("#3: Expected IAE not thrown");
    } catch (IllegalArgumentException ok) {
    }
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger)

Example 32 with ECFieldFp

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

the class EllipticCurveTest method testGetSeed03.

/**
     * Test #3 for <code>getSeed()</code> method<br>
     * Assertion: returned array is copied to prevent subsequent modification<br>
     * Test preconditions: <code>ECFieldF2m</code> instance
     * created using valid parameters<br>
     * Expected: repeated method calls must return different refs
     */
public final void testGetSeed03() {
    ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    BigInteger a = BigInteger.ONE;
    BigInteger b = BigInteger.valueOf(19L);
    byte[] seed = new byte[24];
    EllipticCurve c = new EllipticCurve(f, a, b, seed);
    c.getSeed();
    assertNotSame(c.getSeed(), c.getSeed());
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger)

Example 33 with ECFieldFp

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

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 34 with ECFieldFp

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

the class EllipticCurveTest method testGetSeed01.

/**
     * Test #1 for <code>getSeed()</code> method<br>
     * Assertion: returns <code>seed</code><br>
     * Test preconditions: <code>ECFieldF2m</code> instance
     * created using valid parameters<br>
     * Expected: must return <code>seed</code> which is equal
     * to the one passed to the constructor
     */
public final void testGetSeed01() {
    ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    BigInteger a = BigInteger.ONE;
    BigInteger b = BigInteger.valueOf(19L);
    byte[] seed = new byte[24];
    EllipticCurve c = new EllipticCurve(f, a, b, seed);
    byte[] seedRet = c.getSeed();
    assertNotNull(seedRet);
    assertTrue(Arrays.equals(seed, seedRet));
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger)

Example 35 with ECFieldFp

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigIntegerbyteArray03.

/**
     * Test #3 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
     * constructor<br>
     * Assertion: throws <code>IllegalArgumentException</code> if
     * <code>a</code> or <code>b</code> is not <code>null</code> and not in
     * the <code>field</code><br>
     * Test preconditions: pass <code>a</code>, <code>b</code> which are
     * not in the <code>field</code> of type <code>ECFieldFp</code><br>
     * Expected: must throw <code>IllegalArgumentException</code>
     */
public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray03() {
    // test case 1 parameters set,
    // a is not in field
    ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    BigInteger a = BigInteger.valueOf(24L);
    BigInteger b = BigInteger.valueOf(19L);
    byte[] seed = new byte[24];
    // perform test case 1
    try {
        new EllipticCurve(f, a, b, seed);
        fail("#1: Expected IAE not thrown");
    } catch (IllegalArgumentException ok) {
    }
    // test case 1.1 parameters set,
    // b is not in field
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.valueOf(1L);
    b = BigInteger.valueOf(23L);
    seed = new byte[24];
    // perform test case 1.1
    try {
        new EllipticCurve(f, a, b, seed);
        fail("#1.1: Expected IAE not thrown");
    } catch (IllegalArgumentException ok) {
    }
    // test case 2 parameters set,
    // b is not in field
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.valueOf(19L);
    b = BigInteger.valueOf(24L);
    seed = new byte[24];
    // perform test case 2
    try {
        new EllipticCurve(f, a, b, seed);
        fail("#2: Expected IAE not thrown");
    } catch (IllegalArgumentException ok) {
    }
    // test case 3 parameters set,
    // both a and b are not in field
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.valueOf(25L);
    b = BigInteger.valueOf(240L);
    seed = new byte[24];
    // perform test case 3
    try {
        new EllipticCurve(f, a, b, seed);
        fail("#3: Expected IAE not thrown");
    } catch (IllegalArgumentException ok) {
    }
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger)

Aggregations

ECFieldFp (java.security.spec.ECFieldFp)43 EllipticCurve (java.security.spec.EllipticCurve)35 BigInteger (java.math.BigInteger)31 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