/*--------------------------------------------------------------------------------------------------------------------------- X ---------------------------------------------------------------------------------------------------------------------------*/ private static BigInteger calculateX(EllipticCurve curve, EllipticCurvePoint point) { return ModulusLogic.convertToModulus( (calculateXNumerator(curve, point) * calculateXDenominator(curve, point)), curve.n ); }
public static EllipticCurvePoint addPoints(EllipticCurve curve, EllipticCurvePoint point1, EllipticCurvePoint point2) { BigInteger xResult = calculateX(curve, point1, point2); return(new EllipticCurvePoint { x = xResult, y = calculateY(curve, point1, point2, xResult) }); }
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); }
private static EllipticCurvePoint getResult(int[] bits, int index, EllipticCurve curve, EllipticCurvePoint auxPoint) { EllipticCurvePoint result = auxPoint; while (index < bits.Length) { auxPoint = PointDoubling.doublePoint(curve, auxPoint); if (bits[index] == 1) { result = PointAddition.addPoints(curve, result, auxPoint); } index++; } return(result); }
public static EllipticCurvePoint multiplyPoint(BigInteger prk, EllipticCurvePoint point, EllipticCurve curve) { if (prk == 0) { return new EllipticCurvePoint { x = 0, y = 0 } } ; int[] bits = BitOperations.getBits(prk); int index = 0; EllipticCurvePoint initial = point; while (bits[index] == 0) { initial = PointDoubling.doublePoint(curve, initial); index++; } return(getResult(bits, index + 1, curve, initial)); }
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)); }
public static EllipticCurvePoint doublePoint(EllipticCurve curve, EllipticCurvePoint point) { BigInteger xResult = calculateX(curve, point); return new EllipticCurvePoint { x = xResult, y = calculateY(curve, point, xResult) }; }
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); }