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 length = ps.Length;

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

            case 2:
                return(SumOfTwoMultiplies(ps[0], ks[0], ps[1], ks[1]));
            }
            ECPoint point = ps[0];
            ECCurve c     = point.Curve;

            ECPoint[] pointArray = new ECPoint[length];
            pointArray[0] = point;
            for (int i = 1; i < length; i++)
            {
                pointArray[i] = ImportPoint(c, ps[i]);
            }
            GlvEndomorphism glvEndomorphism = c.GetEndomorphism() as GlvEndomorphism;

            if (glvEndomorphism != null)
            {
                return(ValidatePoint(ImplSumOfMultipliesGlv(pointArray, ks, glvEndomorphism)));
            }
            return(ValidatePoint(ImplSumOfMultiplies(pointArray, ks)));
        }
Beispiel #2
0
        public static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger a, ECPoint Q, BigInteger b)
        {
            ECCurve cp = P.Curve;

            Q = ImportPoint(cp, Q);

            // Point multiplication for Koblitz curves (using WTNAF) beats Shamir's trick
            if (cp is F2mCurve)
            {
                F2mCurve f2mCurve = (F2mCurve)cp;
                if (f2mCurve.IsKoblitz)
                {
                    return(ValidatePoint(P.Multiply(a).Add(Q.Multiply(b))));
                }
            }

            GlvEndomorphism glvEndomorphism = cp.GetEndomorphism() as GlvEndomorphism;

            if (glvEndomorphism != null)
            {
                return(ValidatePoint(
                           ImplSumOfMultipliesGlv(new ECPoint[] { P, Q }, new BigInteger[] { a, b }, glvEndomorphism)));
            }

            return(ValidatePoint(ImplShamirsTrickWNaf(P, a, Q, b)));
        }
        public static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger a, ECPoint Q, BigInteger b)
        {
            ECCurve curve = P.Curve;

            Q = ECAlgorithms.ImportPoint(curve, Q);
            if (curve is F2mCurve)
            {
                F2mCurve f2mCurve = (F2mCurve)curve;
                if (f2mCurve.IsKoblitz)
                {
                    return(ECAlgorithms.ValidatePoint(P.Multiply(a).Add(Q.Multiply(b))));
                }
            }
            GlvEndomorphism glvEndomorphism = curve.GetEndomorphism() as GlvEndomorphism;

            if (glvEndomorphism != null)
            {
                return(ECAlgorithms.ValidatePoint(ECAlgorithms.ImplSumOfMultipliesGlv(new ECPoint[]
                {
                    P,
                    Q
                }, new BigInteger[]
                {
                    a,
                    b
                }, glvEndomorphism)));
            }
            return(ECAlgorithms.ValidatePoint(ECAlgorithms.ImplShamirsTrickWNaf(P, a, Q, b)));
        }
        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)));
            }
            }
        }
        public static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger a, ECPoint Q, BigInteger b)
        {
            ECCurve c = P.Curve;

            Q = ImportPoint(c, Q);
            AbstractF2mCurve curve2 = c as AbstractF2mCurve;

            if ((curve2 != null) && curve2.IsKoblitz)
            {
                return(ValidatePoint(P.Multiply(a).Add(Q.Multiply(b))));
            }
            GlvEndomorphism glvEndomorphism = c.GetEndomorphism() as GlvEndomorphism;

            if (glvEndomorphism != null)
            {
                ECPoint[]    ps = new ECPoint[] { P, Q };
                BigInteger[] ks = new BigInteger[] { a, b };
                return(ValidatePoint(ImplSumOfMultipliesGlv(ps, ks, glvEndomorphism)));
            }
            return(ValidatePoint(ImplShamirsTrickWNaf(P, a, Q, b)));
        }
Beispiel #6
0
        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 count = ps.Length;

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

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

            default:
                break;
            }

            ECPoint p = ps[0];
            ECCurve c = p.Curve;

            ECPoint[] imported = new ECPoint[count];
            imported[0] = p;
            for (int i = 1; i < count; ++i)
            {
                imported[i] = ImportPoint(c, ps[i]);
            }

            GlvEndomorphism glvEndomorphism = c.GetEndomorphism() as GlvEndomorphism;

            if (glvEndomorphism != null)
            {
                return(ValidatePoint(ImplSumOfMultipliesGlv(imported, ks, glvEndomorphism)));
            }

            return(ValidatePoint(ImplSumOfMultiplies(imported, ks)));
        }
Beispiel #7
0
        public static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger a, ECPoint Q, BigInteger b)
        {
            ECCurve curve = P.Curve;

            Q = ImportPoint(curve, Q);
            AbstractF2mCurve abstractF2mCurve = curve as AbstractF2mCurve;

            if (abstractF2mCurve != null && abstractF2mCurve.IsKoblitz)
            {
                return(ValidatePoint(P.Multiply(a).Add(Q.Multiply(b))));
            }
            GlvEndomorphism glvEndomorphism = curve.GetEndomorphism() as GlvEndomorphism;

            if (glvEndomorphism != null)
            {
                return(ValidatePoint(ImplSumOfMultipliesGlv(new ECPoint[2] {
                    P, Q
                }, new BigInteger[2] {
                    a, b
                }, glvEndomorphism)));
            }
            return(ValidatePoint(ImplShamirsTrickWNaf(P, a, Q, b)));
        }