ElGamalParameters.cs 1.4 KB

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