use of java.security.spec.ECPoint in project robovm by robovm.
the class ECPointTest method testGetAffineX01.
/**
* Test #1 for <code>getAffineX()</code> method<br>
* Assertion: returns affine <code>x</code> coordinate<br>
* Test preconditions: <code>ECPoint</code> instance
* created using valid parameters<br>
* Expected: must return affine <code>x</code> coordinate
* which is equal to the one passed to the constructor;
* (both must refer the same object)
*/
public final void testGetAffineX01() {
BigInteger x = BigInteger.valueOf(-23456L);
ECPoint p = new ECPoint(x, BigInteger.valueOf(23456L));
BigInteger xRet = p.getAffineX();
assertEquals(x, xRet);
assertSame(x, xRet);
}
use of java.security.spec.ECPoint in project robovm by robovm.
the class ECPointTest method testEqualsObject01.
/**
* Test #1 for <code>equals(Object other)</code> method<br>
* Assertion: return true if this and other objects are equal<br>
* Test preconditions: see test comments<br>
* Expected: all objects in this test must be equal
*/
public final void testEqualsObject01() {
// test case 1: must be equal to itself
ECPoint p2 = null, p1 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.ONE);
assertTrue(p1.equals(p1));
// test case 2: equal objects
p1 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.ONE);
p2 = new ECPoint(BigInteger.valueOf(-23456L), BigInteger.valueOf(1L));
assertTrue(p1.equals(p2) && p2.equals(p1));
// test case 3: equal POINT_INFINITY object(s)
p1 = ECPoint.POINT_INFINITY;
p2 = ECPoint.POINT_INFINITY;
assertTrue(p1.equals(p2) && p2.equals(p1));
}
use of java.security.spec.ECPoint in project robovm by robovm.
the class ECPointTest 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() {
ECPoint f = new ECPoint(BigInteger.valueOf(-23457L), BigInteger.ONE);
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());
// the same for POINT_INFINITY
hc = ECPoint.POINT_INFINITY.hashCode();
assertTrue(hc == ECPoint.POINT_INFINITY.hashCode() && hc == ECPoint.POINT_INFINITY.hashCode() && hc == ECPoint.POINT_INFINITY.hashCode() && hc == ECPoint.POINT_INFINITY.hashCode() && hc == ECPoint.POINT_INFINITY.hashCode() && hc == ECPoint.POINT_INFINITY.hashCode() && hc == ECPoint.POINT_INFINITY.hashCode() && hc == ECPoint.POINT_INFINITY.hashCode());
}
use of java.security.spec.ECPoint in project XobotOS by xamarin.
the class JCEECPrivateKey method populateFromPrivKeyInfo.
private void populateFromPrivKeyInfo(PrivateKeyInfo info) {
X962Parameters params = new X962Parameters((DERObject) info.getAlgorithmId().getParameters());
if (params.isNamedCurve()) {
DERObjectIdentifier oid = (DERObjectIdentifier) params.getParameters();
X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
// BEGIN android-removed
// if (ecP == null) // GOST Curve
// {
// ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
// EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());
//
// ecSpec = new ECNamedCurveSpec(
// ECGOST3410NamedCurves.getName(oid),
// ellipticCurve,
// new ECPoint(
// gParam.getG().getX().toBigInteger(),
// gParam.getG().getY().toBigInteger()),
// gParam.getN(),
// gParam.getH());
// }
// else
// END android-removed
{
EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), 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;
} else {
X9ECParameters ecP = new X9ECParameters((ASN1Sequence) params.getParameters());
EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());
this.ecSpec = new ECParameterSpec(ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH().intValue());
}
if (info.getPrivateKey() instanceof DERInteger) {
DERInteger derD = (DERInteger) info.getPrivateKey();
this.d = derD.getValue();
} else {
ECPrivateKeyStructure ec = new ECPrivateKeyStructure((ASN1Sequence) info.getPrivateKey());
this.d = ec.getKey();
this.publicKey = ec.getPublicKey();
}
}
use of java.security.spec.ECPoint in project robovm by robovm.
the class BCECPrivateKey method populateFromPrivKeyInfo.
private void populateFromPrivKeyInfo(PrivateKeyInfo info) throws IOException {
X962Parameters params = X962Parameters.getInstance(info.getPrivateKeyAlgorithm().getParameters());
if (params.isNamedCurve()) {
ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters());
X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
// BEGIN android-removed
// if (ecP == null) // GOST Curve
// {
// ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
// EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());
//
// ecSpec = new ECNamedCurveSpec(
// ECGOST3410NamedCurves.getName(oid),
// ellipticCurve,
// new ECPoint(
// gParam.getG().getX().toBigInteger(),
// gParam.getG().getY().toBigInteger()),
// gParam.getN(),
// gParam.getH());
// }
// else
// END android-removed
{
EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), 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;
} else {
X9ECParameters ecP = X9ECParameters.getInstance(params.getParameters());
EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());
this.ecSpec = new ECParameterSpec(ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH().intValue());
}
ASN1Encodable privKey = info.parsePrivateKey();
if (privKey instanceof DERInteger) {
DERInteger derD = DERInteger.getInstance(privKey);
this.d = derD.getValue();
} else {
org.bouncycastle.asn1.sec.ECPrivateKey ec = org.bouncycastle.asn1.sec.ECPrivateKey.getInstance(privKey);
this.d = ec.getKey();
this.publicKey = ec.getPublicKey();
}
}
Aggregations