ECGOST3410ParamSetParameters.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro
  7. {
  8. public class ECGost3410ParamSetParameters
  9. : Asn1Encodable
  10. {
  11. internal readonly DerInteger p, q, a, b, x, y;
  12. public static ECGost3410ParamSetParameters GetInstance(Asn1TaggedObject obj, bool explicitly)
  13. {
  14. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  15. }
  16. public static ECGost3410ParamSetParameters GetInstance(object obj)
  17. {
  18. if (obj == null || obj is ECGost3410ParamSetParameters)
  19. {
  20. return (ECGost3410ParamSetParameters) obj;
  21. }
  22. if (obj is Asn1Sequence seq)
  23. return new ECGost3410ParamSetParameters(seq);
  24. throw new ArgumentException("Invalid GOST3410Parameter: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  25. }
  26. public ECGost3410ParamSetParameters(
  27. BigInteger a,
  28. BigInteger b,
  29. BigInteger p,
  30. BigInteger q,
  31. int x,
  32. BigInteger y)
  33. {
  34. this.a = new DerInteger(a);
  35. this.b = new DerInteger(b);
  36. this.p = new DerInteger(p);
  37. this.q = new DerInteger(q);
  38. this.x = new DerInteger(x);
  39. this.y = new DerInteger(y);
  40. }
  41. public ECGost3410ParamSetParameters(
  42. Asn1Sequence seq)
  43. {
  44. if (seq.Count != 6)
  45. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  46. this.a = DerInteger.GetInstance(seq[0]);
  47. this.b = DerInteger.GetInstance(seq[1]);
  48. this.p = DerInteger.GetInstance(seq[2]);
  49. this.q = DerInteger.GetInstance(seq[3]);
  50. this.x = DerInteger.GetInstance(seq[4]);
  51. this.y = DerInteger.GetInstance(seq[5]);
  52. }
  53. public BigInteger P
  54. {
  55. get { return p.PositiveValue; }
  56. }
  57. public BigInteger Q
  58. {
  59. get { return q.PositiveValue; }
  60. }
  61. public BigInteger A
  62. {
  63. get { return a.PositiveValue; }
  64. }
  65. public override Asn1Object ToAsn1Object()
  66. {
  67. return new DerSequence(a, b, p, q, x, y);
  68. }
  69. }
  70. }
  71. #pragma warning restore
  72. #endif