BasicGcmExponentiator.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes.Gcm
  5. {
  6. public class BasicGcmExponentiator
  7. : IGcmExponentiator
  8. {
  9. private GcmUtilities.FieldElement x;
  10. public void Init(byte[] x)
  11. {
  12. GcmUtilities.AsFieldElement(x, out this.x);
  13. }
  14. public void ExponentiateX(long pow, byte[] output)
  15. {
  16. GcmUtilities.FieldElement y;
  17. GcmUtilities.One(out y);
  18. if (pow > 0)
  19. {
  20. GcmUtilities.FieldElement powX = x;
  21. do
  22. {
  23. if ((pow & 1L) != 0)
  24. {
  25. GcmUtilities.Multiply(ref y, ref powX);
  26. }
  27. GcmUtilities.Square(ref powX);
  28. pow >>= 1;
  29. }
  30. while (pow > 0);
  31. }
  32. GcmUtilities.AsBytes(ref y, output);
  33. }
  34. }
  35. }
  36. #pragma warning restore
  37. #endif