GlvMultiplier.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Endo;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Multiplier
  6. {
  7. public class GlvMultiplier
  8. : AbstractECMultiplier
  9. {
  10. protected readonly ECCurve curve;
  11. protected readonly GlvEndomorphism glvEndomorphism;
  12. public GlvMultiplier(ECCurve curve, GlvEndomorphism glvEndomorphism)
  13. {
  14. if (curve == null || curve.Order == null)
  15. throw new ArgumentException("Need curve with known group order", "curve");
  16. this.curve = curve;
  17. this.glvEndomorphism = glvEndomorphism;
  18. }
  19. protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
  20. {
  21. if (!curve.Equals(p.Curve))
  22. throw new InvalidOperationException();
  23. BigInteger n = p.Curve.Order;
  24. BigInteger[] ab = glvEndomorphism.DecomposeScalar(k.Mod(n));
  25. BigInteger a = ab[0], b = ab[1];
  26. if (glvEndomorphism.HasEfficientPointMap)
  27. {
  28. return ECAlgorithms.ImplShamirsTrickWNaf(glvEndomorphism, p, a, b);
  29. }
  30. ECPoint q = EndoUtilities.MapPoint(glvEndomorphism, p);
  31. return ECAlgorithms.ImplShamirsTrickWNaf(p, a, q, b);
  32. }
  33. }
  34. }
  35. #pragma warning restore
  36. #endif