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 { var f2mCurve = cp as AbstractF2mCurve; if (f2mCurve != null && f2mCurve.IsKoblitz) { return(ValidatePoint(P.Multiply(a).Add(Q.Multiply(b)))); } } var 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 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; var imported = new ECPoint[count]; imported[0] = p; for (int i = 1; i < count; ++i) { imported[i] = ImportPoint(c, ps[i]); } var glvEndomorphism = c.GetEndomorphism() as GlvEndomorphism; if (glvEndomorphism != null) { return(ValidatePoint(ImplSumOfMultipliesGlv(imported, ks, glvEndomorphism))); } return(ValidatePoint(ImplSumOfMultiplies(imported, ks))); }