Search in sources :

Example 26 with EllipticCurve

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

the class EllipticCurveTest method testGetB.

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

Example 27 with EllipticCurve

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

the class EllipticCurveTest method testGetSeed02.

/**
 * Test #2 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; <code>getSeed()</code>
 * called and then returned array modified<br>
 * Expected: internal state must not be affected by the modification
 */
public final void testGetSeed02() {
    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.clone());
    byte[] seedRet = c.getSeed();
    // modify returned array
    seedRet[0] = (byte) 1;
    // check that above modification did not changed
    // internal state of test object
    assertTrue(Arrays.equals(seed, c.getSeed()));
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger)

Example 28 with EllipticCurve

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigInteger01.

/**
 * Test #1 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code>
 * constructor<br>
 * Assertion: creates instance of EllipticCurve<br>
 * Test preconditions: valid parameters passed, field type is ECFieldFp<br>
 * Expected: must pass without any exceptions
 */
public final void testEllipticCurveECFieldBigIntegerBigInteger01() {
    // test case 1 parameters set
    ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    BigInteger a = BigInteger.ONE;
    BigInteger b = BigInteger.valueOf(19L);
    // perform test case 1
    new EllipticCurve(f, a, b);
    // test case 2 parameters set
    ECFieldF2m f1 = new ECFieldF2m(5);
    a = BigInteger.ZERO;
    b = BigInteger.valueOf(23L);
    // perform test case 2
    new EllipticCurve(f1, a, b);
    // test case 3 parameters set,
    // the seed parameter may be null
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.ONE;
    b = BigInteger.valueOf(19L);
    // perform test case 3
    new EllipticCurve(f, a, b);
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger) ECFieldF2m(java.security.spec.ECFieldF2m)

Example 29 with EllipticCurve

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigInteger05.

/**
 * java/security/spec/EllipticCurve#EllipticCurve(EcField,BigInteger,BigInteger)
 */
public final void testEllipticCurveECFieldBigIntegerBigInteger05() {
    // Regression for Harmony-731
    EllipticCurve ec = new EllipticCurve(new testECField(), BigInteger.valueOf(4L), BigInteger.ONE);
    assertEquals("incorrect a", ec.getA(), BigInteger.valueOf(4L));
    assertEquals("incorrect b", ec.getB(), BigInteger.ONE);
    assertEquals("incorrect size", ec.getField().getFieldSize(), 2);
}
Also used : EllipticCurve(java.security.spec.EllipticCurve)

Example 30 with EllipticCurve

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigIntegerbyteArray02.

/**
 * Test #2 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</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 testEllipticCurveECFieldBigIntegerBigIntegerbyteArray02() {
    // test case 1 parameters set
    ECFieldFp f = null;
    BigInteger a = BigInteger.ONE;
    BigInteger b = BigInteger.valueOf(19L);
    byte[] seed = new byte[24];
    // perform test case 1
    try {
        new EllipticCurve(f, a, b, seed);
        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);
    seed = new byte[24];
    // perform test case 2
    try {
        new EllipticCurve(f, a, b, seed);
        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;
    seed = new byte[24];
    // perform test case 2
    try {
        new EllipticCurve(f, a, b, seed);
        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