RandomDsaKCalculator.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Signers
  7. {
  8. public class RandomDsaKCalculator
  9. : IDsaKCalculator
  10. {
  11. private BigInteger q;
  12. private SecureRandom random;
  13. public virtual bool IsDeterministic
  14. {
  15. get { return false; }
  16. }
  17. public virtual void Init(BigInteger n, SecureRandom random)
  18. {
  19. this.q = n;
  20. this.random = random;
  21. }
  22. public virtual void Init(BigInteger n, BigInteger d, byte[] message)
  23. {
  24. throw new InvalidOperationException("Operation not supported");
  25. }
  26. public virtual BigInteger NextK()
  27. {
  28. int qBitLength = q.BitLength;
  29. BigInteger k;
  30. do
  31. {
  32. k = new BigInteger(qBitLength, random);
  33. }
  34. while (k.SignValue < 1 || k.CompareTo(q) >= 0);
  35. return k;
  36. }
  37. }
  38. }
  39. #pragma warning restore
  40. #endif