NaccacheSternKeyGenerationParameters.cs 2.8 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. public NaccacheSternKeyGenerationParameters(
  63. SecureRandom random,
  64. int strength,
  65. int certainty,
  66. int countSmallPrimes,
  67. bool debug)
  68. : this(random, strength, certainty, countSmallPrimes)
  69. {
  70. }
  71. /**
  72. * @return Returns the certainty.
  73. */
  74. public int Certainty
  75. {
  76. get { return certainty; }
  77. }
  78. /**
  79. * @return Returns the countSmallPrimes.
  80. */
  81. public int CountSmallPrimes
  82. {
  83. get { return countSmallPrimes; }
  84. }
  85. public bool IsDebug
  86. {
  87. get { return false; }
  88. }
  89. }
  90. }
  91. #pragma warning restore
  92. #endif