Esempio n. 1
0
        /*---------------------------------------------------------------------------------------------------------------------------
        X
        ---------------------------------------------------------------------------------------------------------------------------*/

        private static BigInteger calculateX(EllipticCurve curve, EllipticCurvePoint point)
        {
            return ModulusLogic.convertToModulus(
                (calculateXNumerator(curve, point) * calculateXDenominator(curve, point)), 
                curve.n
                );
        }
Esempio n. 2
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
         );
 }
Esempio n. 3
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);
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        //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));
        }
Esempio n. 6
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));
        }
Esempio n. 7
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));
        }
Esempio n. 8
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));
        }
Esempio n. 9
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));
        }
Esempio n. 10
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));
        }