Search in sources :

Example 1 with ECField

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);
    }
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m) ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) BigInteger(java.math.BigInteger) ECFieldFp(java.security.spec.ECFieldFp) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint)

Example 2 with ECField

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);
    }
}
Also used : ECFieldF2m(java.security.spec.ECFieldF2m) ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) BigInteger(java.math.BigInteger) ECFieldFp(java.security.spec.ECFieldFp) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint)

Example 3 with ECField

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();
}
Also used : ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve)

Example 4 with ECField

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);
}
Also used : ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) GeneralSecurityException(java.security.GeneralSecurityException) BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint)

Example 5 with ECField

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());
}
Also used : ECField(java.security.spec.ECField) ECFieldFp(java.security.spec.ECFieldFp) EllipticCurve(java.security.spec.EllipticCurve) ECPoint(java.security.spec.ECPoint)

Aggregations

ECField (java.security.spec.ECField)9 ECFieldFp (java.security.spec.ECFieldFp)9 ECPoint (java.security.spec.ECPoint)8 BigInteger (java.math.BigInteger)7 EllipticCurve (java.security.spec.EllipticCurve)7 ECFieldF2m (java.security.spec.ECFieldF2m)4 GeneralSecurityException (java.security.GeneralSecurityException)2 InvalidParameterException (java.security.InvalidParameterException)1 ECParameterSpec (java.security.spec.ECParameterSpec)1