NaccacheSternKeyGenerationParameters.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Security;
  7. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
  8. {
  9. /**
  10. * Parameters for NaccacheStern public private key generation. For details on
  11. * this cipher, please see
  12. *
  13. * http://www.gemplus.com/smart/rd/publications/pdf/NS98pkcs.pdf
  14. */
  15. public class NaccacheSternKeyGenerationParameters : KeyGenerationParameters
  16. {
  17. // private BigInteger publicExponent;
  18. private readonly int certainty;
  19. private readonly int countSmallPrimes;
  20. /**
  21. * Parameters for generating a NaccacheStern KeyPair.
  22. *
  23. * @param random
  24. * The source of randomness
  25. * @param strength
  26. * The desired strength of the Key in Bits
  27. * @param certainty
  28. * the probability that the generated primes are not really prime
  29. * as integer: 2^(-certainty) is then the probability
  30. * @param countSmallPrimes
  31. * How many small key factors are desired
  32. */
  33. public NaccacheSternKeyGenerationParameters(
  34. SecureRandom random,
  35. int strength,
  36. int certainty,
  37. int countSmallPrimes)
  38. : base(random, strength)
  39. {
  40. if (countSmallPrimes % 2 == 1)
  41. throw new ArgumentException("countSmallPrimes must be a multiple of 2");
  42. if (countSmallPrimes < 30)
  43. throw new ArgumentException("countSmallPrimes must be >= 30 for security reasons");
  44. this.certainty = certainty;
  45. this.countSmallPrimes = countSmallPrimes;
  46. }
  47. /**
  48. * @return Returns the certainty.
  49. */
  50. public int Certainty
  51. {
  52. get { return certainty; }
  53. }
  54. /**
  55. * @return Returns the countSmallPrimes.
  56. */
  57. public int CountSmallPrimes
  58. {
  59. get { return countSmallPrimes; }
  60. }
  61. }
  62. }
  63. #pragma warning restore
  64. #endif