ECGOST3410ParamSetParameters.cs 2.4 KB

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