Beispiel #1
0
        internal static ECPoint ImplShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
        {
            ECCurve curve    = P.Curve;
            ECPoint infinity = curve.Infinity;

            // TODO conjugate co-Z addition (ZADDC) can return both of these
            ECPoint PaddQ = P.Add(Q);
            ECPoint PsubQ = P.Subtract(Q);

            ECPoint[] points = new ECPoint[] { Q, PsubQ, P, PaddQ };
            curve.NormalizeAll(points);

            ECPoint[] table = new ECPoint[] {
                points[3].Negate(), points[2].Negate(), points[1].Negate(),
                points[0].Negate(), infinity, points[0],
                points[1], points[2], points[3]
            };

            byte[] jsf = WNafUtilities.GenerateJsf(k, l);

            ECPoint R = infinity;

            int i = jsf.Length;

            while (--i >= 0)
            {
                int jsfi = jsf[i];

                // NOTE: The shifting ensures the sign is extended correctly
                int kDigit = ((jsfi << 24) >> 28), lDigit = ((jsfi << 28) >> 28);

                int index = 4 + (kDigit * 3) + lDigit;
                R = R.TwicePlus(table[index]);
            }

            return(R);
        }
Beispiel #2
0
        internal static ECPoint ImplShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
        {
            ECCurve curve    = P.Curve;
            ECPoint infinity = curve.Infinity;
            ECPoint eCPoint  = P.Add(Q);
            ECPoint eCPoint2 = P.Subtract(Q);

            ECPoint[] array = new ECPoint[4] {
                Q, eCPoint2, P, eCPoint
            };
            curve.NormalizeAll(array);
            ECPoint[] array2 = new ECPoint[9]
            {
                array[3].Negate(),
                array[2].Negate(),
                array[1].Negate(),
                array[0].Negate(),
                infinity,
                array[0],
                array[1],
                array[2],
                array[3]
            };
            byte[]  array3   = WNafUtilities.GenerateJsf(k, l);
            ECPoint eCPoint3 = infinity;
            int     num      = array3.Length;

            while (--num >= 0)
            {
                int num2 = array3[num];
                int num3 = num2 << 24 >> 28;
                int num4 = num2 << 28 >> 28;
                int num5 = 4 + num3 * 3 + num4;
                eCPoint3 = eCPoint3.TwicePlus(array2[num5]);
            }
            return(eCPoint3);
        }
        internal static ECPoint ImplShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
        {
            ECCurve curve    = P.Curve;
            ECPoint infinity = curve.Infinity;
            ECPoint point2   = P.Add(Q);
            ECPoint point3   = P.Subtract(Q);

            ECPoint[] points = new ECPoint[] { Q, point3, P, point2 };
            curve.NormalizeAll(points);
            ECPoint[] pointArray2 = new ECPoint[] { points[3].Negate(), points[2].Negate(), points[1].Negate(), points[0].Negate(), infinity, points[0], points[1], points[2], points[3] };
            byte[]    buffer      = WNafUtilities.GenerateJsf(k, l);
            ECPoint   point4      = infinity;
            int       length      = buffer.Length;

            while (--length >= 0)
            {
                int num2  = buffer[length];
                int num3  = (num2 << 0x18) >> 0x1c;
                int num4  = (num2 << 0x1c) >> 0x1c;
                int index = (4 + (num3 * 3)) + num4;
                point4 = point4.TwicePlus(pointArray2[index]);
            }
            return(point4);
        }