use of java.security.spec.ECFieldFp in project j2objc by google.
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.ECFieldFp in project j2objc by google.
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 j2objc by google.
the class ECFieldFpTest method testGetP.
/**
* Test for <code>getP()</code> method.<br>
*
* Assertion: returns prime
*/
public final void testGetP() {
BigInteger p = BigInteger.valueOf(23L);
assertTrue(p.equals(new ECFieldFp(p).getP()));
}
use of java.security.spec.ECFieldFp in project wycheproof by google.
the class EcUtil method getPoint.
/**
* Decompress a point
*
* @param x The x-coordinate of the point
* @param bit0 true if the least significant bit of y is set.
* @param ecParams contains the curve of the point. This must be over a prime order field.
*/
public static ECPoint getPoint(BigInteger x, boolean bit0, ECParameterSpec ecParams) throws GeneralSecurityException {
EllipticCurve ec = ecParams.getCurve();
ECField field = ec.getField();
if (!(field instanceof ECFieldFp)) {
throw new GeneralSecurityException("Only curves over prime order fields are supported");
}
BigInteger p = ((java.security.spec.ECFieldFp) field).getP();
if (x.compareTo(BigInteger.ZERO) == -1 || x.compareTo(p) != -1) {
throw new GeneralSecurityException("x is out of range");
}
// Compute rhs == x^3 + a x + b (mod p)
BigInteger rhs = x.multiply(x).add(ec.getA()).multiply(x).add(ec.getB()).mod(p);
BigInteger y = modSqrt(rhs, p);
if (bit0 != y.testBit(0)) {
y = p.subtract(y).mod(p);
}
return new ECPoint(x, y);
}
use of java.security.spec.ECFieldFp in project XobotOS by xamarin.
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