use of java.security.spec.ECFieldFp in project robovm by robovm.
the class EllipticCurveTest method testEqualsObject01.
/**
* Test #1 for <code>equals(Object other)</code> method<br>
* Assertion: return true if this and other objects are equal<br>
* Test preconditions: see test comments<br>
* Expected: all objects in this test must be equal
*/
public final void testEqualsObject01() {
// test case 1: must be equal to itself
EllipticCurve c2 = null, c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L));
assertTrue(c1.equals(c1));
// test case 2: equal objects
c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L));
c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.valueOf(1L), BigInteger.valueOf(19L));
assertTrue(c1.equals(c2) && c2.equals(c1));
// test case 3: equal objects with seed not null
c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]);
c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.valueOf(1L), BigInteger.valueOf(19L), new byte[24]);
assertTrue(c1.equals(c2) && c2.equals(c1));
// test case 4: equal object and subclass object
c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]);
MyEllipticCurve c3 = new MyEllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L), new byte[24]);
assertTrue(c1.equals(c3) && c3.equals(c1));
// test case 5: equal objects
c1 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.ONE, BigInteger.valueOf(19L));
c2 = new EllipticCurve(new ECFieldFp(BigInteger.valueOf(23L)), BigInteger.valueOf(1L), BigInteger.valueOf(19L), null);
assertTrue(c1.equals(c2) && c2.equals(c1));
}
use of java.security.spec.ECFieldFp in project robovm by robovm.
the class ECFieldFpTest method testEqualsObject01.
/**
* Test #1 for <code>equals()</code> method.<br>
*
* Assertion: object equals to itself.
*/
public final void testEqualsObject01() {
ECFieldFp obj = new ECFieldFp(BigInteger.valueOf(23L));
assertTrue(obj.equals(obj));
}
use of java.security.spec.ECFieldFp in project robovm by robovm.
the class ECFieldFpTest method testHashCode01.
/**
* Test #1 for <code>hashCode()</code> method.<br>
*
* Assertion: must return the same value if invoked
* repeatedly on the same object.
*/
public final void testHashCode01() {
ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
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.ECFieldFp in project robovm by robovm.
the class EC5Util method convertCurve.
public static ECCurve convertCurve(EllipticCurve ec) {
ECField field = ec.getField();
BigInteger a = ec.getA();
BigInteger b = ec.getB();
if (field instanceof ECFieldFp) {
return new ECCurve.Fp(((ECFieldFp) field).getP(), a, b);
} else {
ECFieldF2m fieldF2m = (ECFieldF2m) field;
int m = fieldF2m.getM();
int[] ks = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());
return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b);
}
}
use of java.security.spec.ECFieldFp in project robovm by robovm.
the class EC5Util method convertCurve.
public static EllipticCurve convertCurve(ECCurve curve, byte[] seed) {
// so at the moment it's set to null. Should probably look at making this configurable
if (curve instanceof ECCurve.Fp) {
return new EllipticCurve(new ECFieldFp(((ECCurve.Fp) curve).getQ()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
} 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(), null);
} else {
ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() };
return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
}
}
}
Aggregations