use of java.security.spec.EllipticCurve in project XobotOS by xamarin.
the class JCEECPublicKey method populateFromPubKeyInfo.
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info) {
// BEGIN android-removed
// if (info.getAlgorithmId().getObjectId().equals(CryptoProObjectIdentifiers.gostR3410_2001))
// {
// DERBitString bits = info.getPublicKeyData();
// ASN1OctetString key;
// this.algorithm = "ECGOST3410";
//
// try
// {
// key = (ASN1OctetString) ASN1Object.fromByteArray(bits.getBytes());
// }
// catch (IOException ex)
// {
// throw new IllegalArgumentException("error recovering public key");
// }
//
// byte[] keyEnc = key.getOctets();
// byte[] x = new byte[32];
// byte[] y = new byte[32];
//
// for (int i = 0; i != x.length; i++)
// {
// x[i] = keyEnc[32 - 1 - i];
// }
//
// for (int i = 0; i != y.length; i++)
// {
// y[i] = keyEnc[64 - 1 - i];
// }
//
// gostParams = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
//
// ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));
//
// ECCurve curve = spec.getCurve();
// EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());
//
// this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y), false);
//
// ecSpec = new ECNamedCurveSpec(
// ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
// ellipticCurve,
// new ECPoint(
// spec.getG().getX().toBigInteger(),
// spec.getG().getY().toBigInteger()),
// spec.getN(), spec.getH());
//
// }
// else
// END android-removed
{
X962Parameters params = new X962Parameters((DERObject) info.getAlgorithmId().getParameters());
ECCurve curve;
EllipticCurve ellipticCurve;
if (params.isNamedCurve()) {
DERObjectIdentifier oid = (DERObjectIdentifier) params.getParameters();
X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
curve = ecP.getCurve();
ellipticCurve = EC5Util.convertCurve(curve, ecP.getSeed());
ecSpec = new ECNamedCurveSpec(ECUtil.getCurveName(oid), ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH());
} else if (params.isImplicitlyCA()) {
ecSpec = null;
curve = ProviderUtil.getEcImplicitlyCa().getCurve();
} else {
X9ECParameters ecP = new X9ECParameters((ASN1Sequence) params.getParameters());
curve = ecP.getCurve();
ellipticCurve = EC5Util.convertCurve(curve, ecP.getSeed());
this.ecSpec = new ECParameterSpec(ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH().intValue());
}
DERBitString bits = info.getPublicKeyData();
byte[] data = bits.getBytes();
ASN1OctetString key = new DEROctetString(data);
//
if (data[0] == 0x04 && data[1] == data.length - 2 && (data[2] == 0x02 || data[2] == 0x03)) {
int qLength = new X9IntegerConverter().getByteLength(curve);
if (qLength >= data.length - 3) {
try {
key = (ASN1OctetString) ASN1Object.fromByteArray(data);
} catch (IOException ex) {
throw new IllegalArgumentException("error recovering public key");
}
}
}
X9ECPoint derQ = new X9ECPoint(curve, key);
this.q = derQ.getPoint();
}
}
use of java.security.spec.EllipticCurve 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);
}
}
}
use of java.security.spec.EllipticCurve in project robovm by robovm.
the class ECPrivateKeySpecTest method setUp.
protected void setUp() throws Exception {
super.setUp();
ECPoint ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1));
EllipticCurve curve = new EllipticCurve(new ECFieldF2m(2), BigInteger.valueOf(1), BigInteger.valueOf(1));
s = BigInteger.valueOf(1);
ecparams = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1);
ecpks = new ECPrivateKeySpec(s, ecparams);
}
use of java.security.spec.EllipticCurve in project robovm by robovm.
the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigInteger05.
/**
* java/security/spec/EllipticCurve#EllipticCurve(EcField,BigInteger,BigInteger)
*/
public final void testEllipticCurveECFieldBigIntegerBigInteger05() {
// Regression for Harmony-731
EllipticCurve ec = new EllipticCurve(new testECField(), BigInteger.valueOf(4L), BigInteger.ONE);
assertEquals("incorrect a", ec.getA(), BigInteger.valueOf(4L));
assertEquals("incorrect b", ec.getB(), BigInteger.ONE);
assertEquals("incorrect size", ec.getField().getFieldSize(), 2);
}
use of java.security.spec.EllipticCurve in project robovm by robovm.
the class EllipticCurveTest method testEllipticCurveECFieldBigIntegerBigInteger03.
/**
* Test #3 for <code>EllipticCurve(ECField, BigInteger, BigInteger)</code>
* constructor<br>
* Assertion: throws <code>IllegalArgumentException</code> if
* <code>a</code> or <code>b</code> is not <code>null</code> and not in
* the <code>field</code><br>
* Test preconditions: pass <code>a</code>, <code>b</code> which are
* not in the <code>field</code> of type <code>ECFieldFp</code><br>
* Expected: must throw <code>IllegalArgumentException</code>
*/
public final void testEllipticCurveECFieldBigIntegerBigInteger03() {
// test case 1 parameters set,
// a is not in field
ECFieldFp f = new ECFieldFp(BigInteger.valueOf(23L));
BigInteger a = BigInteger.valueOf(24L);
BigInteger b = BigInteger.valueOf(19L);
// perform test case 1
try {
new EllipticCurve(f, a, b);
fail("#1: Expected IAE not thrown");
} catch (IllegalArgumentException ok) {
}
// test case 1.1 parameters set,
// a is not in field
f = new ECFieldFp(BigInteger.valueOf(23L));
a = BigInteger.valueOf(23L);
b = BigInteger.valueOf(19L);
// perform test case 1.1
try {
new EllipticCurve(f, a, b);
fail("#1.1: Expected IAE not thrown");
} catch (IllegalArgumentException ok) {
}
// test case 2 parameters set,
// b is not in field
f = new ECFieldFp(BigInteger.valueOf(23L));
a = BigInteger.valueOf(19L);
b = BigInteger.valueOf(24L);
// perform test case 2
try {
new EllipticCurve(f, a, b);
fail("#2: Expected IAE not thrown");
} catch (IllegalArgumentException ok) {
}
// test case 3 parameters set,
// both a and b are not in field
f = new ECFieldFp(BigInteger.valueOf(23L));
a = BigInteger.valueOf(25L);
b = BigInteger.valueOf(240L);
// perform test case 3
try {
new EllipticCurve(f, a, b);
fail("#3: Expected IAE not thrown");
} catch (IllegalArgumentException ok) {
}
}
Aggregations