Beispiel #1
0
        internal static ECPoint ImplSumOfMultipliesGlv(ECPoint[] ps, BigInteger[] ks, GlvEndomorphism glvEndomorphism)
        {
            BigInteger n = ps[0].Curve.Order;

            int len = ps.Length;

            BigInteger[] abs = new BigInteger[len << 1];
            for (int i = 0, j = 0; i < len; ++i)
            {
                BigInteger[] ab = glvEndomorphism.DecomposeScalar(ks[i].Mod(n));
                abs[j++] = ab[0];
                abs[j++] = ab[1];
            }

            ECPointMap pointMap = glvEndomorphism.PointMap;

            if (glvEndomorphism.HasEfficientPointMap)
            {
                return(ECAlgorithms.ImplSumOfMultiplies(ps, pointMap, abs));
            }

            ECPoint[] pqs = new ECPoint[len << 1];
            for (int i = 0, j = 0; i < len; ++i)
            {
                ECPoint p = ps[i], q = pointMap.Map(p);
                pqs[j++] = p;
                pqs[j++] = q;
            }

            return(ECAlgorithms.ImplSumOfMultiplies(pqs, abs));
        }
        internal static ECPoint ImplSumOfMultiplies(ECPoint[] ps, ECPointMap pointMap, BigInteger[] ks)
        {
            int num  = ps.Length;
            int num2 = num << 1;

            bool[]            array  = new bool[num2];
            WNafPreCompInfo[] array2 = new WNafPreCompInfo[num2];
            byte[][]          array3 = new byte[num2][];
            for (int i = 0; i < num; i++)
            {
                int        num3       = i << 1;
                int        num4       = num3 + 1;
                BigInteger bigInteger = ks[num3];
                array[num3] = (bigInteger.SignValue < 0);
                bigInteger  = bigInteger.Abs();
                BigInteger bigInteger2 = ks[num4];
                array[num4] = (bigInteger2.SignValue < 0);
                bigInteger2 = bigInteger2.Abs();
                int     width = Math.Max(2, Math.Min(16, WNafUtilities.GetWindowSize(Math.Max(bigInteger.BitLength, bigInteger2.BitLength))));
                ECPoint p     = ps[i];
                ECPoint p2    = WNafUtilities.MapPointWithPrecomp(p, width, true, pointMap);
                array2[num3] = WNafUtilities.GetWNafPreCompInfo(p);
                array2[num4] = WNafUtilities.GetWNafPreCompInfo(p2);
                array3[num3] = WNafUtilities.GenerateWindowNaf(width, bigInteger);
                array3[num4] = WNafUtilities.GenerateWindowNaf(width, bigInteger2);
            }
            return(ECAlgorithms.ImplSumOfMultiplies(array, array2, array3));
        }
        public static ECPoint SumOfMultiplies(ECPoint[] ps, BigInteger[] ks)
        {
            if (ps == null || ks == null || ps.Length != ks.Length || ps.Length < 1)
            {
                throw new ArgumentException("point and scalar arrays should be non-null, and of equal, non-zero, length");
            }
            int num = ps.Length;

            switch (num)
            {
            case 1:
                return(ps[0].Multiply(ks[0]));

            case 2:
                return(ECAlgorithms.SumOfTwoMultiplies(ps[0], ks[0], ps[1], ks[1]));

            default:
            {
                ECPoint   eCPoint = ps[0];
                ECCurve   curve   = eCPoint.Curve;
                ECPoint[] array   = new ECPoint[num];
                array[0] = eCPoint;
                for (int i = 1; i < num; i++)
                {
                    array[i] = ECAlgorithms.ImportPoint(curve, ps[i]);
                }
                GlvEndomorphism glvEndomorphism = curve.GetEndomorphism() as GlvEndomorphism;
                if (glvEndomorphism != null)
                {
                    return(ECAlgorithms.ValidatePoint(ECAlgorithms.ImplSumOfMultipliesGlv(array, ks, glvEndomorphism)));
                }
                return(ECAlgorithms.ValidatePoint(ECAlgorithms.ImplSumOfMultiplies(array, ks)));
            }
            }
        }
        internal static ECPoint ImplSumOfMultiplies(ECPoint[] ps, BigInteger[] ks)
        {
            int num = ps.Length;

            bool[]            array  = new bool[num];
            WNafPreCompInfo[] array2 = new WNafPreCompInfo[num];
            byte[][]          array3 = new byte[num][];
            for (int i = 0; i < num; i++)
            {
                BigInteger bigInteger = ks[i];
                array[i]   = (bigInteger.SignValue < 0);
                bigInteger = bigInteger.Abs();
                int width = Math.Max(2, Math.Min(16, WNafUtilities.GetWindowSize(bigInteger.BitLength)));
                array2[i] = WNafUtilities.Precompute(ps[i], width, true);
                array3[i] = WNafUtilities.GenerateWindowNaf(width, bigInteger);
            }
            return(ECAlgorithms.ImplSumOfMultiplies(array, array2, array3));
        }
        internal static ECPoint ImplSumOfMultipliesGlv(ECPoint[] ps, BigInteger[] ks, GlvEndomorphism glvEndomorphism)
        {
            BigInteger order = ps[0].Curve.Order;
            int        num   = ps.Length;

            BigInteger[] array = new BigInteger[num << 1];
            int          i     = 0;
            int          num2  = 0;

            while (i < num)
            {
                BigInteger[] array2 = glvEndomorphism.DecomposeScalar(ks[i].Mod(order));
                array[num2++] = array2[0];
                array[num2++] = array2[1];
                i++;
            }
            ECPointMap pointMap = glvEndomorphism.PointMap;

            if (glvEndomorphism.HasEfficientPointMap)
            {
                return(ECAlgorithms.ImplSumOfMultiplies(ps, pointMap, array));
            }
            ECPoint[] array3 = new ECPoint[num << 1];
            int       j      = 0;
            int       num3   = 0;

            while (j < num)
            {
                ECPoint eCPoint  = ps[j];
                ECPoint eCPoint2 = pointMap.Map(eCPoint);
                array3[num3++] = eCPoint;
                array3[num3++] = eCPoint2;
                j++;
            }
            return(ECAlgorithms.ImplSumOfMultiplies(array3, array));
        }