MontgomeryLadderMultiplier.cs 813 B

1234567891011121314151617181920212223242526272829303132
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC.Multiplier
  5. {
  6. public class MontgomeryLadderMultiplier
  7. : AbstractECMultiplier
  8. {
  9. /**
  10. * Montgomery ladder.
  11. */
  12. protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
  13. {
  14. ECPoint[] R = new ECPoint[]{ p.Curve.Infinity, p };
  15. int n = k.BitLength;
  16. int i = n;
  17. while (--i >= 0)
  18. {
  19. int b = k.TestBit(i) ? 1 : 0;
  20. int bp = 1 - b;
  21. R[bp] = R[bp].Add(R[b]);
  22. R[b] = R[b].Twice();
  23. }
  24. return R[0];
  25. }
  26. }
  27. }
  28. #pragma warning restore
  29. #endif