NaccacheSternKeyGenerationParameters.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
  7. namespace BestHTTP.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. * Parameters for a NaccacheStern KeyPair.
  49. *
  50. * @param random
  51. * The source of randomness
  52. * @param strength
  53. * The desired strength of the Key in Bits
  54. * @param certainty
  55. * the probability that the generated primes are not really prime
  56. * as integer: 2^(-certainty) is then the probability
  57. * @param cntSmallPrimes
  58. * How many small key factors are desired
  59. * @param debug
  60. * Ignored
  61. */
  62. [Obsolete("Use version without 'debug' parameter")]
  63. public NaccacheSternKeyGenerationParameters(
  64. SecureRandom random,
  65. int strength,
  66. int certainty,
  67. int countSmallPrimes,
  68. bool debug)
  69. : this(random, strength, certainty, countSmallPrimes)
  70. {
  71. }
  72. /**
  73. * @return Returns the certainty.
  74. */
  75. public int Certainty
  76. {
  77. get { return certainty; }
  78. }
  79. /**
  80. * @return Returns the countSmallPrimes.
  81. */
  82. public int CountSmallPrimes
  83. {
  84. get { return countSmallPrimes; }
  85. }
  86. [Obsolete("Remove: always false")]
  87. public bool IsDebug
  88. {
  89. get { return false; }
  90. }
  91. }
  92. }
  93. #pragma warning restore
  94. #endif