use of java.security.spec.ECPoint in project robovm by robovm.
the class OpenSSLECGroupContext method getInstance.
public static OpenSSLECGroupContext getInstance(ECParameterSpec params) throws InvalidAlgorithmParameterException {
final String curveName = params.getCurveName();
if (curveName != null) {
return OpenSSLECGroupContext.getCurveByName(curveName);
}
final EllipticCurve curve = params.getCurve();
final ECField field = curve.getField();
final int type;
final BigInteger p;
if (field instanceof ECFieldFp) {
type = NativeCrypto.EC_CURVE_GFP;
p = ((ECFieldFp) field).getP();
} else if (field instanceof ECFieldF2m) {
type = NativeCrypto.EC_CURVE_GF2M;
p = ((ECFieldF2m) field).getReductionPolynomial();
} else {
throw new InvalidParameterException("unhandled field class " + field.getClass().getName());
}
final ECPoint generator = params.getGenerator();
return OpenSSLECGroupContext.getInstance(type, p, curve.getA(), curve.getB(), generator.getAffineX(), generator.getAffineY(), params.getOrder(), BigInteger.valueOf(params.getCofactor()));
}
use of java.security.spec.ECPoint in project robovm by robovm.
the class OpenSSLECGroupContext method getECParameterSpec.
public ECParameterSpec getECParameterSpec() {
final String curveName = NativeCrypto.EC_GROUP_get_curve_name(groupCtx);
final byte[][] curveParams = NativeCrypto.EC_GROUP_get_curve(groupCtx);
final BigInteger p = new BigInteger(curveParams[0]);
final BigInteger a = new BigInteger(curveParams[1]);
final BigInteger b = new BigInteger(curveParams[2]);
final ECField field;
final int type = NativeCrypto.get_EC_GROUP_type(groupCtx);
if (type == NativeCrypto.EC_CURVE_GFP) {
field = new ECFieldFp(p);
} else if (type == NativeCrypto.EC_CURVE_GF2M) {
field = new ECFieldF2m(p.bitLength() - 1, p);
} else {
throw new RuntimeException("unknown curve type " + type);
}
final EllipticCurve curve = new EllipticCurve(field, a, b);
final OpenSSLECPointContext generatorCtx = new OpenSSLECPointContext(this, NativeCrypto.EC_GROUP_get_generator(groupCtx));
final ECPoint generator = generatorCtx.getECPoint();
final BigInteger order = new BigInteger(NativeCrypto.EC_GROUP_get_order(groupCtx));
final BigInteger cofactor = new BigInteger(NativeCrypto.EC_GROUP_get_cofactor(groupCtx));
return new ECParameterSpec(curve, generator, order, cofactor.intValue(), curveName);
}
use of java.security.spec.ECPoint in project robovm by robovm.
the class OpenSSLECPointContext method getECPoint.
public ECPoint getECPoint() {
final byte[][] generatorCoords = NativeCrypto.EC_POINT_get_affine_coordinates(group.getContext(), pointCtx);
final BigInteger x = new BigInteger(generatorCoords[0]);
final BigInteger y = new BigInteger(generatorCoords[1]);
return new ECPoint(x, y);
}
use of java.security.spec.ECPoint in project cxf by apache.
the class CryptoUtils method getECPublicKey.
public static ECPublicKey getECPublicKey(String curve, byte[] xPoint, byte[] yPoint) {
try {
ECParameterSpec params = getECParameterSpec(curve, false);
ECPoint ecPoint = new ECPoint(toBigInteger(xPoint), toBigInteger(yPoint));
ECPublicKeySpec keySpec = new ECPublicKeySpec(ecPoint, params);
KeyFactory kf = KeyFactory.getInstance("EC");
return (ECPublicKey) kf.generatePublic(keySpec);
} catch (Exception ex) {
throw new SecurityException(ex);
}
}
Aggregations