use of java.security.spec.ECFieldF2m in project j2objc by google.
the class ECFieldF2mTest method testHashCode02.
/**
* Test #2 for <code>hashCode()</code> method.<br>
*
* Assertion: must return the same value if invoked
* repeatedly on the same object.
*/
public final void testHashCode02() {
ECFieldF2m f = new ECFieldF2m(2000, new int[] { 981, 2, 1 });
int hc = f.hashCode();
assertTrue(hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode() && hc == f.hashCode());
}
use of java.security.spec.ECFieldF2m 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);
}
use of java.security.spec.ECFieldF2m in project j2objc by google.
the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigIntegerbyteArray04.
/**
* 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 testEllipticCurveECFieldBigIntegerBigIntegerbyteArray04() {
// 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);
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 2 parameters set,
// b is not in field
f = new ECFieldF2m(5);
a = BigInteger.valueOf(19L);
b = BigInteger.valueOf(32L);
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 ECFieldF2m(5);
a = BigInteger.valueOf(32L);
b = BigInteger.valueOf(43L);
seed = new byte[24];
// perform test case 3
try {
new EllipticCurve(f, a, b, seed);
fail("#3: Expected IAE not thrown");
} catch (IllegalArgumentException ok) {
}
}
use of java.security.spec.ECFieldF2m in project j2objc by google.
the class EllipticCurveTest method testGetA.
/**
* Test for <code>getA()</code> method<br>
* Assertion: returns coefficient <code>a</code><br>
* Test preconditions: <code>ECFieldF2m</code> instance
* created using valid parameters<br>
* Expected: must return coefficient <code>a</code> which is equal
* to the one passed to the constructor; (both must refer
* the same object)
*/
public final void testGetA() {
ECFieldF2m f = new ECFieldF2m(5);
BigInteger a = BigInteger.valueOf(5L);
BigInteger b = BigInteger.valueOf(19L);
EllipticCurve c = new EllipticCurve(f, a, b);
assertEquals(a, c.getA());
assertSame(a, c.getA());
}
use of java.security.spec.ECFieldF2m in project robovm by robovm.
the class ECNamedCurveSpec method convertCurve.
private static EllipticCurve convertCurve(ECCurve curve, byte[] seed) {
if (curve instanceof ECCurve.Fp) {
return new EllipticCurve(new ECFieldFp(((ECCurve.Fp) curve).getQ()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
} else {
ECCurve.F2m curveF2m = (ECCurve.F2m) curve;
int[] ks;
if (curveF2m.isTrinomial()) {
ks = new int[] { curveF2m.getK1() };
return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
} else {
ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() };
return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
}
}
}
Aggregations