GOST3410ParamSetParameters.cs 2.2 KB

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