Пример #1
0
        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)));
        }
Пример #2
0
        public static ECPoint ShamirsTrick(ECPoint P, BigInteger k, ECPoint Q, BigInteger l)
        {
            ECCurve curve = P.Curve;

            Q = ECAlgorithms.ImportPoint(curve, Q);
            return(ECAlgorithms.ValidatePoint(ECAlgorithms.ImplShamirsTrickJsf(P, k, Q, l)));
        }
Пример #3
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 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)));
            }
            }
        }