use of java.security.spec.EllipticCurve in project robovm by robovm.
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) {
}
}
use of java.security.spec.EllipticCurve in project robovm by robovm.
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) {
}
}
use of java.security.spec.EllipticCurve in project robovm by robovm.
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()));
}
use of java.security.spec.EllipticCurve in project robovm by robovm.
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);
}
use of java.security.spec.EllipticCurve in project XobotOS by xamarin.
the class JCEECPrivateKey method populateFromPrivKeyInfo.
private void populateFromPrivKeyInfo(PrivateKeyInfo info) {
X962Parameters params = new X962Parameters((DERObject) info.getAlgorithmId().getParameters());
if (params.isNamedCurve()) {
DERObjectIdentifier oid = (DERObjectIdentifier) params.getParameters();
X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
// BEGIN android-removed
// if (ecP == null) // GOST Curve
// {
// ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
// EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());
//
// ecSpec = new ECNamedCurveSpec(
// ECGOST3410NamedCurves.getName(oid),
// ellipticCurve,
// new ECPoint(
// gParam.getG().getX().toBigInteger(),
// gParam.getG().getY().toBigInteger()),
// gParam.getN(),
// gParam.getH());
// }
// else
// END android-removed
{
EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());
ecSpec = new ECNamedCurveSpec(ECUtil.getCurveName(oid), ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH());
}
} else if (params.isImplicitlyCA()) {
ecSpec = null;
} else {
X9ECParameters ecP = new X9ECParameters((ASN1Sequence) params.getParameters());
EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());
this.ecSpec = new ECParameterSpec(ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH().intValue());
}
if (info.getPrivateKey() instanceof DERInteger) {
DERInteger derD = (DERInteger) info.getPrivateKey();
this.d = derD.getValue();
} else {
ECPrivateKeyStructure ec = new ECPrivateKeyStructure((ASN1Sequence) info.getPrivateKey());
this.d = ec.getKey();
this.publicKey = ec.getPublicKey();
}
}
Aggregations