use of java.security.spec.ECField 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.ECField in project XobotOS by xamarin.
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.ECField in project jmulticard by ctt-gob-es.
the class JseCryptoHelper method getPrime.
private static BigInteger getPrime(final ECParameterSpec params) {
if (params == null) {
throw new IllegalArgumentException(// $NON-NLS-1$
"Los parametros no pueden ser nulos");
}
final EllipticCurve curve = params.getCurve();
final ECField field = curve.getField();
if (!(field instanceof ECFieldFp)) {
throw new IllegalStateException(// $NON-NLS-1$
"Solo se soporta 'ECFieldFp' y se proporciono " + field.getClass().getCanonicalName());
}
return ((ECFieldFp) field).getP();
}
use of java.security.spec.ECField 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.ECField in project wycheproof by google.
the class EcUtil method printParameters.
public static void printParameters(ECParameterSpec spec) {
System.out.println("cofactor:" + spec.getCofactor());
EllipticCurve curve = spec.getCurve();
System.out.println("A:" + curve.getA());
System.out.println("B:" + curve.getB());
ECField field = curve.getField();
System.out.println("field size:" + field.getFieldSize());
if (field instanceof ECFieldFp) {
ECFieldFp fp = (ECFieldFp) field;
System.out.println("P:" + fp.getP());
}
ECPoint generator = spec.getGenerator();
System.out.println("Gx:" + generator.getAffineX());
System.out.println("Gy:" + generator.getAffineY());
System.out.println("order:" + spec.getOrder());
}
Aggregations