Search in sources :

Example 26 with ECFieldF2m

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigIntegerbyteArray05.

/**
     * Test #5 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
     * constructor<br>
     * Assertion: array <code>seed</code> is copied to prevent subsequent modification<br>
     * Test preconditions: pass <code>seed</code> to the ctor then modify it<br>
     * Expected: getSeed() must return unmodified array
     */
public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray05() {
    ECFieldF2m f = new ECFieldF2m(5);
    BigInteger a = BigInteger.valueOf(0L);
    BigInteger b = BigInteger.valueOf(19L);
    byte[] seed = new byte[24];
    byte[] seedCopy = seed.clone();
    EllipticCurve c = new EllipticCurve(f, a, b, seedCopy);
    // modify array passed
    seedCopy[0] = (byte) 1;
    // check that above modification did not changed
    // internal state of test object
    assertTrue(Arrays.equals(seed, c.getSeed()));
}
Also used : EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger) ECFieldF2m(java.security.spec.ECFieldF2m)

Example 27 with ECFieldF2m

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigInteger04.

/**
     * 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 testEllipticCurveECFieldBigIntegerBigInteger04() {
    // 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);
    // perform test case 1
    try {
        new EllipticCurve(f, a, b);
        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);
    // 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 ECFieldF2m(5);
    a = BigInteger.valueOf(32L);
    b = BigInteger.valueOf(43L);
    // perform test case 3
    try {
        new EllipticCurve(f, a, b);
        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 28 with ECFieldF2m

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

the class ECFieldF2mTest method testEqualsObject01.

/**
     * Test #1 for <code>equals()</code> method.<br>
     *
     * Assertion: object equals to itself.
     */
public final void testEqualsObject01() {
    ECFieldF2m obj = new ECFieldF2m(1999, new int[] { 367 });
    assertTrue(obj.equals(obj));
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m)

Example 29 with ECFieldF2m

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

the class ECFieldF2mTest method testIsStatePreserved01.

/**
     * Tests that object state is preserved against modifications
     * through array reference passed to the constructor.
     */
public final void testIsStatePreserved01() {
    // reference array
    int[] a = new int[] { 367 };
    // reference array copy
    int[] aCopy = a.clone();
    // create obj using copy
    ECFieldF2m f = new ECFieldF2m(1999, aCopy);
    // modify copy
    aCopy[0] = 5;
    // compare reference with returned array
    assertTrue(Arrays.equals(a, f.getMidTermsOfReductionPolynomial()));
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m)

Example 30 with ECFieldF2m

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

the class ECFieldF2mTest method testGetMidTermsOfReductionPolynomial01.

/**
     * Test #1 for <code>getMidTermsOfReductionPolynomial()</code> method.<br>
     *
     * Assertion: returns mid terms of reduction polynomial
     */
public final void testGetMidTermsOfReductionPolynomial01() {
    int[] a = new int[] { 981, 2, 1 };
    int[] b = new ECFieldF2m(2000, BigInteger.valueOf(0L).setBit(0).setBit(1).setBit(2).setBit(981).setBit(2000)).getMidTermsOfReductionPolynomial();
    assertTrue(Arrays.equals(a, b));
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m)

Aggregations

ECFieldF2m (java.security.spec.ECFieldF2m)50 EllipticCurve (java.security.spec.EllipticCurve)28 BigInteger (java.math.BigInteger)22 ECFieldFp (java.security.spec.ECFieldFp)12 ECPoint (java.security.spec.ECPoint)10 ECParameterSpec (java.security.spec.ECParameterSpec)7 ECField (java.security.spec.ECField)4 ECCurve (org.bouncycastle.math.ec.ECCurve)4 ECPrivateKeySpec (java.security.spec.ECPrivateKeySpec)2 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)2 InvalidParameterException (java.security.InvalidParameterException)1