ECDomainParameters.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Math;
  4. using Org.BouncyCastle.Math.EC;
  5. using Org.BouncyCastle.Utilities;
  6. namespace Org.BouncyCastle.Crypto.Parameters
  7. {
  8. public class ECDomainParameters
  9. {
  10. internal ECCurve curve;
  11. internal byte[] seed;
  12. internal ECPoint g;
  13. internal BigInteger n;
  14. internal BigInteger h;
  15. public ECDomainParameters(
  16. ECCurve curve,
  17. ECPoint g,
  18. BigInteger n)
  19. : this(curve, g, n, BigInteger.One)
  20. {
  21. }
  22. public ECDomainParameters(
  23. ECCurve curve,
  24. ECPoint g,
  25. BigInteger n,
  26. BigInteger h)
  27. : this(curve, g, n, h, null)
  28. {
  29. }
  30. public ECDomainParameters(
  31. ECCurve curve,
  32. ECPoint g,
  33. BigInteger n,
  34. BigInteger h,
  35. byte[] seed)
  36. {
  37. if (curve == null)
  38. throw new ArgumentNullException("curve");
  39. if (g == null)
  40. throw new ArgumentNullException("g");
  41. if (n == null)
  42. throw new ArgumentNullException("n");
  43. if (h == null)
  44. throw new ArgumentNullException("h");
  45. this.curve = curve;
  46. this.g = g.Normalize();
  47. this.n = n;
  48. this.h = h;
  49. this.seed = Arrays.Clone(seed);
  50. }
  51. public ECCurve Curve
  52. {
  53. get { return curve; }
  54. }
  55. public ECPoint G
  56. {
  57. get { return g; }
  58. }
  59. public BigInteger N
  60. {
  61. get { return n; }
  62. }
  63. public BigInteger H
  64. {
  65. get { return h; }
  66. }
  67. public byte[] GetSeed()
  68. {
  69. return Arrays.Clone(seed);
  70. }
  71. public override bool Equals(
  72. object obj)
  73. {
  74. if (obj == this)
  75. return true;
  76. ECDomainParameters other = obj as ECDomainParameters;
  77. if (other == null)
  78. return false;
  79. return Equals(other);
  80. }
  81. protected virtual bool Equals(
  82. ECDomainParameters other)
  83. {
  84. return curve.Equals(other.curve)
  85. && g.Equals(other.g)
  86. && n.Equals(other.n)
  87. && h.Equals(other.h);
  88. }
  89. public override int GetHashCode()
  90. {
  91. int hc = curve.GetHashCode();
  92. hc *= 37;
  93. hc ^= g.GetHashCode();
  94. hc *= 37;
  95. hc ^= n.GetHashCode();
  96. hc *= 37;
  97. hc ^= h.GetHashCode();
  98. return hc;
  99. }
  100. }
  101. }
  102. #endif