Example #1
0
        /// <summary>
        /// https://eprint.iacr.org/2008/522.pdf uses extended twisted coordinates
        /// </summary>
        private ExtendedEdPoint Double(ExtendedEdPoint point)
        {
            var A    = _operator.Multiply(point.X, point.X);
            var B    = _operator.Multiply(point.Y, point.Y);
            var C    = _operator.Multiply(2, _operator.Multiply(point.Z, point.Z));
            var D    = _operator.Multiply(CoefficientA, A);
            var Esub = _operator.Add(point.X, point.Y);
            var E    = _operator.Subtract(_operator.Subtract(_operator.Multiply(Esub, Esub), A), B);
            var G    = _operator.Add(D, B);
            var F    = _operator.Subtract(G, C);
            var H    = _operator.Subtract(D, B);
            var X3   = _operator.Multiply(E, F);
            var Y3   = _operator.Multiply(G, H);
            var T3   = _operator.Multiply(E, H);
            var Z3   = _operator.Multiply(F, G);

            return(new ExtendedEdPoint(X3, Y3, T3, Z3));
        }
Example #2
0
        /// <summary>
        /// https://eprint.iacr.org/2008/522.pdf uses extended twisted coordinates
        /// </summary>
        private ExtendedEdPoint Add(ExtendedEdPoint pointA, ExtendedEdPoint pointB)
        {
            var A = _operator.Multiply(pointA.X, pointB.X);
            var B = _operator.Multiply(pointA.Y, pointB.Y);
            var C = _operator.Multiply(pointA.Z, pointB.T);
            var D = _operator.Multiply(pointA.T, pointB.Z);
            var E = _operator.Add(D, C);
            var F = _operator.Multiply(_operator.Subtract(pointA.X, pointA.Y), _operator.Add(pointB.X, pointB.Y));

            F = _operator.Subtract(_operator.Add(F, B), A);
            var G  = _operator.Add(B, _operator.Multiply(CoefficientA, A));
            var H  = _operator.Subtract(D, C);
            var X3 = _operator.Multiply(E, F);
            var Y3 = _operator.Multiply(G, H);
            var T3 = _operator.Multiply(E, H);
            var Z3 = _operator.Multiply(F, G);

            return(new ExtendedEdPoint(X3, Y3, T3, Z3));
        }
Example #3
0
        private EdPoint Multiply(ExtendedEdPoint startPoint, NonAdjacentBitString nafBs)
        {
            var point  = new ExtendedEdPoint(0, 1, 0, 1);
            var naBits = nafBs.Bits;

            for (var i = naBits.Length - 1; i >= 0; i--)
            {
                point = Double(point);
                if (naBits[i] == 1)
                {
                    point = Add(point, startPoint);
                }
                else if (naBits[i] == -1)
                {
                    point = Subtract(point, startPoint);
                }
            }

            return(ExtendedToEdPoint(point));
        }
Example #4
0
 private EdPoint ExtendedToEdPoint(ExtendedEdPoint point)
 {
     return(new EdPoint(_operator.Divide(point.X, point.Z), _operator.Divide(point.Y, point.Z)));
 }
Example #5
0
 private ExtendedEdPoint Subtract(ExtendedEdPoint pointA, ExtendedEdPoint pointB)
 {
     return(Add(pointA, Negate(pointB)));
 }
Example #6
0
 private ExtendedEdPoint Negate(ExtendedEdPoint point)
 {
     return(new ExtendedEdPoint(_operator.Negate(point.X), point.Y, _operator.Negate(point.T), point.Z));
 }