Search in sources :

Example 66 with EllipticCurve

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

the class EcUtil method getBrainpoolP256r1Params.

public static ECParameterSpec getBrainpoolP256r1Params() {
    BigInteger p = new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", 16);
    BigInteger a = new BigInteger("7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", 16);
    BigInteger b = new BigInteger("26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", 16);
    BigInteger x = new BigInteger("8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", 16);
    BigInteger y = new BigInteger("547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", 16);
    BigInteger n = new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", 16);
    final int h = 1;
    ECFieldFp fp = new ECFieldFp(p);
    EllipticCurve curve = new EllipticCurve(fp, a, b);
    ECPoint g = new ECPoint(x, y);
    return new ECParameterSpec(curve, g, n, h);
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) ECParameterSpec(java.security.spec.ECParameterSpec) BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint) ECPoint(java.security.spec.ECPoint)

Example 67 with EllipticCurve

use of java.security.spec.EllipticCurve in project dhis2-core by dhis2.

the class TestKeys method generateEcKeyPair.

static KeyPair generateEcKeyPair() {
    EllipticCurve ellipticCurve = new EllipticCurve(new ECFieldFp(new BigInteger("115792089210356248762697446949407573530086143415290314195533631308867097853951")), new BigInteger("115792089210356248762697446949407573530086143415290314195533631308867097853948"), new BigInteger("41058363725152142129326129780047268409114441015993725554835256314039467401291"));
    ECPoint ecPoint = new ECPoint(new BigInteger("48439561293906451759052585252797914202762949526041747995844080717082404635286"), new BigInteger("36134250956749795798585127919587881956611106672985015071877198253568414405109"));
    ECParameterSpec ecParameterSpec = new ECParameterSpec(ellipticCurve, ecPoint, new BigInteger("115792089210356248762697446949407573529996955224135760342422259061068512044369"), 1);
    KeyPair keyPair;
    try {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC");
        keyPairGenerator.initialize(ecParameterSpec);
        keyPair = keyPairGenerator.generateKeyPair();
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
    return keyPair;
}
Also used : KeyPair(java.security.KeyPair) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) ECParameterSpec(java.security.spec.ECParameterSpec) BigInteger(java.math.BigInteger) KeyPairGenerator(java.security.KeyPairGenerator) ECPoint(java.security.spec.ECPoint) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 68 with EllipticCurve

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

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 69 with EllipticCurve

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

the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigIntegerbyteArray01.

/**
 * Test #1 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
 * constructor<br>
 * Assertion: creates instance of EllipticCurve<br>
 * Test preconditions: valid parameters passed<br>
 * Expected: must pass without any exceptions
 */
public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray01() {
    // test case 1 parameters set
    ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
    BigInteger a = BigInteger.ONE;
    BigInteger b = BigInteger.valueOf(19L);
    byte[] seed = new byte[24];
    // perform test case 1
    new EllipticCurve(f, a, b, seed);
    // 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, seed);
    // test case 3 parameters set,
    // the seed parameter may be null
    f = new ECFieldFp(BigInteger.valueOf(23L));
    a = BigInteger.ONE;
    b = BigInteger.valueOf(19L);
    seed = null;
    // perform test case 3
    new EllipticCurve(f, a, b, seed);
}
Also used : ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) BigInteger(java.math.BigInteger) ECFieldF2m(java.security.spec.ECFieldF2m)

Example 70 with EllipticCurve

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

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)

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