Search in sources :

Example 41 with EllipticCurve

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

the class EllipticCurveTest method testGetA.

/**
     * Test for <code>getA()</code> method<br>
     * Assertion: returns coefficient <code>a</code><br>
     * Test preconditions: <code>ECFieldF2m</code> instance
     * created using valid parameters<br>
     * Expected: must return coefficient <code>a</code> which is equal
     * to the one passed to the constructor; (both must refer
     * the same object)
     */
public final void testGetA() {
    ECFieldF2m f = new ECFieldF2m(5);
    BigInteger a = BigInteger.valueOf(5L);
    BigInteger b = BigInteger.valueOf(19L);
    EllipticCurve c = new EllipticCurve(f, a, b);
    assertEquals(a, c.getA());
    assertSame(a, c.getA());
}
Also used : EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger) ECFieldF2m(java.security.spec.ECFieldF2m)

Example 42 with EllipticCurve

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

Example 43 with EllipticCurve

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigIntegerbyteArray04.

/**
     * Test #4 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>ECFieldF2m</code><br>
     * Expected: must throw <code>IllegalArgumentException</code>
     */
public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray04() {
    // test case 1 parameters set,
    // a is not in field
    ECFieldF2m f = new ECFieldF2m(5);
    BigInteger a = BigInteger.valueOf(32L);
    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 2 parameters set,
    // b is not in field
    f = new ECFieldF2m(5);
    a = BigInteger.valueOf(19L);
    b = BigInteger.valueOf(32L);
    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 ECFieldF2m(5);
    a = BigInteger.valueOf(32L);
    b = BigInteger.valueOf(43L);
    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 : EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger) ECFieldF2m(java.security.spec.ECFieldF2m)

Example 44 with EllipticCurve

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

the class EllipticCurveTest method testGetSeed04.

/**
     * java.security.spec.EllipticCurve#getSeed()
     * Assertion: null if not specified
     */
public final void testGetSeed04() {
    //Regression for HARMONY-732
    ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    BigInteger a = BigInteger.ONE;
    assertNull(new EllipticCurve(f, a, a).getSeed());
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger)

Example 45 with EllipticCurve

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigInteger02.

/**
     * Test #2 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code>
     * constructor<br>
     * Assertion: throws <code>NullPointerException</code> if <code>field</code>,
     * <code>a</code> or <code>b</code> is <code>null</code><br>
     * Test preconditions: pass <code>null</code> as mentioned parameters<br>
     * Expected: must throw <code>NullPointerException</code>
     */
public final void testEllipticCurveECFieldBigIntegerBigInteger02() {
    // test case 1 parameters set
    ECFieldFp f = null;
    BigInteger a = BigInteger.ONE;
    BigInteger b = BigInteger.valueOf(19L);
    // perform test case 1
    try {
        new EllipticCurve(f, a, b);
        fail("#1: Expected NPE not thrown");
    } catch (NullPointerException ok) {
    }
    // test case 2 parameters set,
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = null;
    b = BigInteger.valueOf(19L);
    // perform test case 2
    try {
        new EllipticCurve(f, a, b);
        fail("#2: Expected NPE not thrown");
    } catch (NullPointerException ok) {
    }
    // test case 3 parameters set,
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.ONE;
    b = null;
    // perform test case 3
    try {
        new EllipticCurve(f, a, b);
        fail("#3: Expected NPE not thrown");
    } catch (NullPointerException ok) {
    }
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger)

Aggregations

EllipticCurve (java.security.spec.EllipticCurve)78 BigInteger (java.math.BigInteger)48 ECFieldFp (java.security.spec.ECFieldFp)43 ECPoint (java.security.spec.ECPoint)30 ECFieldF2m (java.security.spec.ECFieldF2m)28 ECParameterSpec (java.security.spec.ECParameterSpec)23 GeneralSecurityException (java.security.GeneralSecurityException)7 ECField (java.security.spec.ECField)7 ECCurve (org.bouncycastle.math.ec.ECCurve)7 X962Parameters (org.bouncycastle.asn1.x9.X962Parameters)6 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)6 ECNamedCurveSpec (org.bouncycastle.jce.spec.ECNamedCurveSpec)6 KeyPair (java.security.KeyPair)5 KeyPairGenerator (java.security.KeyPairGenerator)5 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)5 IOException (java.io.IOException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 ECPublicKey (java.security.interfaces.ECPublicKey)4 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 ECPrivateKey (java.security.interfaces.ECPrivateKey)3