DsaPublicKeyParameters.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 DsaPublicKeyParameters
  8. : DsaKeyParameters
  9. {
  10. private static BigInteger Validate(BigInteger y, DsaParameters parameters)
  11. {
  12. // we can't validate without params, fortunately we can't use the key either...
  13. if (parameters != null)
  14. {
  15. if (y.CompareTo(BigInteger.Two) < 0
  16. || y.CompareTo(parameters.P.Subtract(BigInteger.Two)) > 0
  17. || !y.ModPow(parameters.Q, parameters.P).Equals(BigInteger.One))
  18. {
  19. throw new ArgumentException("y value does not appear to be in correct group");
  20. }
  21. }
  22. return y;
  23. }
  24. private readonly BigInteger y;
  25. public DsaPublicKeyParameters(
  26. BigInteger y,
  27. DsaParameters parameters)
  28. : base(false, parameters)
  29. {
  30. if (y == null)
  31. throw new ArgumentNullException("y");
  32. this.y = Validate(y, parameters);
  33. }
  34. public BigInteger Y
  35. {
  36. get { return y; }
  37. }
  38. public override bool Equals(object obj)
  39. {
  40. if (obj == this)
  41. return true;
  42. DsaPublicKeyParameters other = obj as DsaPublicKeyParameters;
  43. if (other == null)
  44. return false;
  45. return Equals(other);
  46. }
  47. protected bool Equals(
  48. DsaPublicKeyParameters other)
  49. {
  50. return y.Equals(other.y) && base.Equals(other);
  51. }
  52. public override int GetHashCode()
  53. {
  54. return y.GetHashCode() ^ base.GetHashCode();
  55. }
  56. }
  57. }
  58. #pragma warning restore
  59. #endif