ZSignedDigitR2LMultiplier.cs 863 B

12345678910111213141516171819202122232425262728293031323334353637
  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 ZSignedDigitR2LMultiplier
  7. : AbstractECMultiplier
  8. {
  9. /**
  10. * 'Zeroless' Signed Digit Right-to-Left.
  11. */
  12. protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
  13. {
  14. ECPoint R0 = p.Curve.Infinity, R1 = p;
  15. int n = k.BitLength;
  16. int s = k.GetLowestSetBit();
  17. R1 = R1.TimesPow2(s);
  18. int i = s;
  19. while (++i < n)
  20. {
  21. R0 = R0.Add(k.TestBit(i) ? R1 : R1.Negate());
  22. R1 = R1.Twice();
  23. }
  24. R0 = R0.Add(R1);
  25. return R0;
  26. }
  27. }
  28. }
  29. #pragma warning restore
  30. #endif