Search in sources :

Example 31 with EllipticCurve

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

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

the class ECPrivateKeySpecTest method setUp.

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

Example 33 with EllipticCurve

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

the class EllipticCurveTest method testGetField.

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

Example 34 with EllipticCurve

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

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)

Example 35 with EllipticCurve

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

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)

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