RandomDsaKCalculator.cs 1.1 KB

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