List of usage examples for org.bouncycastle.math.ec ECCurve fromBigInteger
public abstract ECFieldElement fromBigInteger(BigInteger x);
From source file:com.github.horrorho.inflatabledonkey.crypto.ec.ECPointsCompact.java
License:Open Source License
public static BigInteger y(ECCurve curve, BigInteger x) { // Andrey Jivsov https://www.ietf.org/archive/id/draft-jivsov-ecc-compact-05.txt. ECFieldElement X = curve.fromBigInteger(x); ECFieldElement rhs = X.square().add(curve.getA()).multiply(X).add(curve.getB()); // y' = sqrt( C(x) ), where y'>0 ECFieldElement yTilde = rhs.sqrt();//from ww w . j a va 2s .com if (yTilde == null) { throw new IllegalArgumentException("invalid point compression"); } // y = min(y',p-y') BigInteger yT = yTilde.toBigInteger(); BigInteger yTn = yTilde.negate().toBigInteger(); BigInteger y = yT.compareTo(yTn) == -1 ? yT : yTn; return y; }
From source file:com.github.horrorho.inflatabledonkey.crypto.ec.ECPointsCompact.java
License:Open Source License
@Deprecated public static ECPoint decompressFPPoint(ECCurve curve, BigInteger X) { // See Andrey Jivsov https://www.ietf.org/archive/id/draft-jivsov-ecc-compact-05.txt. ECFieldElement x = curve.fromBigInteger(X); ECFieldElement rhs = x.square().add(curve.getA()).multiply(x).add(curve.getB()); // y' = sqrt( C(x) ), where y'>0 ECFieldElement yTilde = rhs.sqrt();//from ww w . java 2 s . c om if (yTilde == null) { throw new IllegalArgumentException("invalid point compression"); } // y = min(y',p-y') BigInteger yT = yTilde.toBigInteger(); BigInteger yTn = yTilde.negate().toBigInteger(); BigInteger y = yT.compareTo(yTn) == -1 ? yT : yTn; // Q=(x,y) is the canonical representation of the point ECPoint Q = curve.createPoint(X, y); return Q; }
From source file:org.jmrtd.Util.java
License:Open Source License
/** * This just solves the curve equation for y. * * @param affineX the x coord of a point on the curve * @param params EC parameters for curve over Fp * @return the corresponding y coord//from w w w . j a v a2s .co m */ public static BigInteger computeAffineY(BigInteger affineX, ECParameterSpec params) { ECCurve bcCurve = toBouncyCastleECCurve(params); ECFieldElement a = bcCurve.getA(); ECFieldElement b = bcCurve.getB(); ECFieldElement x = bcCurve.fromBigInteger(affineX); ECFieldElement y = x.multiply(x).add(a).multiply(x).add(b).sqrt(); return y.toBigInteger(); }
From source file:service.ACService.java
License:Open Source License
private static ECPoint reconstructPoint(ECCurve c, BigInteger i, boolean negate) { ECFieldElement x = c.fromBigInteger(i); ECFieldElement y = x.multiply(x).multiply(x).add(c.getA().multiply(x)).add(c.getB()).sqrt(); if (negate) { return c.createPoint(x.toBigInteger(), y.toBigInteger().negate(), false); } else {//from www . j a v a 2s . c om return c.createPoint(x.toBigInteger(), y.toBigInteger(), false); } }