ElGamalParameters.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
  6. {
  7. public class ElGamalParameters
  8. : ICipherParameters
  9. {
  10. private readonly BigInteger p, g;
  11. private readonly int l;
  12. public ElGamalParameters(
  13. BigInteger p,
  14. BigInteger g)
  15. : this(p, g, 0)
  16. {
  17. }
  18. public ElGamalParameters(
  19. BigInteger p,
  20. BigInteger g,
  21. int l)
  22. {
  23. if (p == null)
  24. throw new ArgumentNullException("p");
  25. if (g == null)
  26. throw new ArgumentNullException("g");
  27. this.p = p;
  28. this.g = g;
  29. this.l = l;
  30. }
  31. public BigInteger P
  32. {
  33. get { return p; }
  34. }
  35. /**
  36. * return the generator - g
  37. */
  38. public BigInteger G
  39. {
  40. get { return g; }
  41. }
  42. /**
  43. * return private value limit - l
  44. */
  45. public int L
  46. {
  47. get { return l; }
  48. }
  49. public override bool Equals(
  50. object obj)
  51. {
  52. if (obj == this)
  53. return true;
  54. ElGamalParameters other = obj as ElGamalParameters;
  55. if (other == null)
  56. return false;
  57. return Equals(other);
  58. }
  59. protected bool Equals(
  60. ElGamalParameters other)
  61. {
  62. return p.Equals(other.p) && g.Equals(other.g) && l == other.l;
  63. }
  64. public override int GetHashCode()
  65. {
  66. return p.GetHashCode() ^ g.GetHashCode() ^ l;
  67. }
  68. }
  69. }
  70. #pragma warning restore
  71. #endif