/*--------------------------------------------------------------------------------------------------------------------------- X ---------------------------------------------------------------------------------------------------------------------------*/ private static BigInteger calculateX(EllipticCurve curve, EllipticCurvePoint point) { return ModulusLogic.convertToModulus( (calculateXNumerator(curve, point) * calculateXDenominator(curve, point)), curve.n ); }
private static BigInteger calculateXDenominator(EllipticCurve curve, EllipticCurvePoint point) { BigInteger xDenominator = 4 * point.y * point.y; return ModulusLogic.inverseModuloN( ModulusLogic.convertToModulus(xDenominator, curve.n), curve.n ); }
private static BigInteger calculateXNumerator(EllipticCurve curve, EllipticCurvePoint point) { BigInteger xNumerator = 9 * point.x * point.x * point.x * point.x + 6 * curve.a * point.x * point.x + curve.a * curve.a - 8 * point.x * point.y * point.y; return ModulusLogic.convertToModulus(xNumerator, curve.n); }
public static bool verifyMessage(Signature signature, string message, EllipticCurvePoint publicKey, EllipticCurve theCurve) { //step 2+3 BigInteger z = Common.computeZ(Common.getHash(message), theCurve); //step 4 BigInteger u1 = ModulusLogic.convertToModulus(z * ModulusLogic.inverseModuloN(signature.s, theCurve.p), theCurve.p); BigInteger u2 = ModulusLogic.convertToModulus(signature.r * ModulusLogic.inverseModuloN(signature.s, theCurve.p), theCurve.p); //step 5 return(getPoint(u1, u2, publicKey, theCurve).x == signature.r); }
//step 6 private static BigInteger calculateS(BigInteger privateKey, BigInteger k, BigInteger z, BigInteger r, EllipticCurve theCurve) { BigInteger inverseK = ModulusLogic.inverseModuloN(k, theCurve.p); return(ModulusLogic.convertToModulus(inverseK * (z + (r * privateKey)), theCurve.p)); }
private static BigInteger calculateYDenominator(EllipticCurve curve, EllipticCurvePoint point1, EllipticCurvePoint point2) { BigInteger yDenominator = point2.x - point1.x; return(ModulusLogic.inverseModuloN(ModulusLogic.convertToModulus(yDenominator, curve.n), curve.n)); }
private static BigInteger calculateYNumerator(EllipticCurve curve, EllipticCurvePoint point1, EllipticCurvePoint point2, BigInteger xResult) { BigInteger yNumerator = (point2.y - point1.y) * (point1.x - xResult) - point1.y * (point2.x - point1.x); return(ModulusLogic.convertToModulus(yNumerator, curve.n)); }
/*--------------------------------------------------------------------------------------------------------------------------- * Y * ---------------------------------------------------------------------------------------------------------------------------*/ private static BigInteger calculateY(EllipticCurve curve, EllipticCurvePoint point1, EllipticCurvePoint point2, BigInteger xResult) { return(ModulusLogic.convertToModulus(calculateYNumerator(curve, point1, point2, xResult) * calculateYDenominator(curve, point1, point2), curve.n)); }
private static BigInteger calculateXNumerator(EllipticCurve curve, EllipticCurvePoint point1, EllipticCurvePoint point2) { BigInteger xNumerator = (point2.y - point1.y) * (point2.y - point1.y) - (point1.x + point2.x) * (point2.x - point1.x) * (point2.x - point1.x); return(ModulusLogic.convertToModulus(xNumerator, curve.n)); }
private static BigInteger calculateYNumerator(EllipticCurve curve, EllipticCurvePoint point, BigInteger xResult) { BigInteger yNumerator = (3 * point.x * point.x + curve.a) * (point.x - xResult) - 2 * point.y * point.y; return(ModulusLogic.convertToModulus(yNumerator, curve.n)); }