Exemplo n.º 1
0
        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)
            });
        }
Exemplo n.º 2
0
        public static EllipticCurvePoint doublePoint(EllipticCurve curve, EllipticCurvePoint point)
        {
            BigInteger xResult = calculateX(curve, point);

            return(new EllipticCurvePoint {
                x = xResult, y = calculateY(curve, point, xResult)
            });
        }
Exemplo n.º 3
0
        private static BigInteger calculateYDenominator(EllipticCurve curve, EllipticCurvePoint point)
        {
            BigInteger yDenominator = 2 * point.y;

            return(ModulusLogic.inverseModuloN(ModulusLogic.convertToModulus(yDenominator, curve.n), curve.n));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        /*---------------------------------------------------------------------------------------------------------------------------
        *  Y
        *  ---------------------------------------------------------------------------------------------------------------------------*/

        private static BigInteger calculateY(EllipticCurve curve, EllipticCurvePoint point, BigInteger xResult)
        {
            return(ModulusLogic.convertToModulus(calculateYNumerator(curve, point, xResult) * calculateYDenominator(curve, point), curve.n));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        /*---------------------------------------------------------------------------------------------------------------------------
        *  X
        *  ---------------------------------------------------------------------------------------------------------------------------*/

        private static BigInteger calculateX(EllipticCurve curve, EllipticCurvePoint point)
        {
            return(ModulusLogic.convertToModulus((calculateXNumerator(curve, point) * calculateXDenominator(curve, point)), curve.n));
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        private static BigInteger calculateXDenominator(EllipticCurve curve, EllipticCurvePoint point1, EllipticCurvePoint point2)
        {
            BigInteger xDenominator = (point2.x - point1.x) * (point2.x - point1.x);

            return(ModulusLogic.inverseModuloN(ModulusLogic.convertToModulus(xDenominator, curve.n), curve.n));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
 public static EllipticCurvePoint calculatePublicKey(BigInteger prk, EllipticCurve curve)
 {
     return(PointMultiplication.multiplyPoint(prk, curve.G, curve));
 }
Exemplo n.º 12
0
 public static EllipticCurvePoint calculateMasterKey(BigInteger prk, EllipticCurvePoint theirPublicKey, EllipticCurve curve)
 {
     return(PointAddition.addPoints(curve, theirPublicKey, PointMultiplication.multiplyPoint(prk, curve.G, curve)));
 }