BasicGcmExponentiator.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes.Gcm
  6. {
  7. public class BasicGcmExponentiator
  8. : IGcmExponentiator
  9. {
  10. private ulong[] x;
  11. public void Init(byte[] x)
  12. {
  13. this.x = GcmUtilities.AsUlongs(x);
  14. }
  15. public void ExponentiateX(long pow, byte[] output)
  16. {
  17. // Initial value is little-endian 1
  18. ulong[] y = GcmUtilities.OneAsUlongs();
  19. if (pow > 0)
  20. {
  21. ulong[] powX = Arrays.Clone(x);
  22. do
  23. {
  24. if ((pow & 1L) != 0)
  25. {
  26. GcmUtilities.Multiply(y, powX);
  27. }
  28. GcmUtilities.Square(powX, powX);
  29. pow >>= 1;
  30. }
  31. while (pow > 0);
  32. }
  33. GcmUtilities.AsBytes(y, output);
  34. }
  35. }
  36. }
  37. #pragma warning restore
  38. #endif