Ejemplo n.º 1
0
        /*---------------------------------------------------------------------------------------------------------------------------
        X
        ---------------------------------------------------------------------------------------------------------------------------*/

        private static BigInteger calculateX(EllipticCurve curve, EllipticCurvePoint point)
        {
            return ModulusLogic.convertToModulus(
                (calculateXNumerator(curve, point) * calculateXDenominator(curve, point)), 
                curve.n
                );
        }
Ejemplo n.º 2
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)
            });
        }
Ejemplo n.º 3
0
 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
         );
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo 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));
        }
Ejemplo n.º 9
0
        /*---------------------------------------------------------------------------------------------------------------------------
        *  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));
        }
Ejemplo 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));
        }
Ejemplo n.º 11
0
 public static EllipticCurvePoint doublePoint(EllipticCurve curve, EllipticCurvePoint point)
 {
     BigInteger xResult = calculateX(curve, point);
     return new EllipticCurvePoint { x = xResult, y = calculateY(curve, point, xResult) };
 }
Ejemplo n.º 12
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);
 }