List of usage examples for org.bouncycastle.math.ec ECFieldElement.Fp sqrt
public abstract ECFieldElement sqrt();
From source file:edu.biu.scapi.primitives.dlog.ECFpUtility.java
License:Open Source License
/** * This function finds the y coordinate of a point in the curve for a given x, if it exists. * @param params the parameters of the group * @param x/*from ww w .j ava 2 s . c o m*/ * @return the y coordinate of point in the curve for a given x, if it exists * else, null */ public BigInteger findYInCurveEquationForX(ECFpGroupParams params, BigInteger x) { /* get a, b, p from group params */ BigInteger a = params.getA(); BigInteger b = params.getB(); BigInteger p = params.getP(); // compute x^3 BigInteger x3 = x.modPow(new BigInteger("3"), p); // compute x^3+ax+b BigInteger rightSide = x3.add(a.multiply(x)).add(b).mod(p); //try to compute y = square_root(x^3+ax+b) //If it exists return it //else, return null //We compute the square root via the ECFieldElement.Fp of Bouncy Castle, since BigInteger does not implement this function. //ECFieldElement.Fp ySquare = new ECFieldElement.Fp(params.getQ(), rightSide); ECFieldElement.Fp ySquare = new ECFieldElement.Fp(params.getP(), rightSide); //TODO I am not sure which one of the square roots it returns (if they exist). We need to check this!! (Yael) ECFieldElement.Fp y = (Fp) ySquare.sqrt(); if (y != null) { return y.toBigInteger().mod(p); } else { return null; } }