GOST3410NamedParameters.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using System.Collections;
  4. using Org.BouncyCastle.Asn1;
  5. using Org.BouncyCastle.Math;
  6. using Org.BouncyCastle.Utilities;
  7. using Org.BouncyCastle.Utilities.Collections;
  8. namespace Org.BouncyCastle.Asn1.CryptoPro
  9. {
  10. /**
  11. * table of the available named parameters for GOST 3410-94.
  12. */
  13. public sealed class Gost3410NamedParameters
  14. {
  15. private Gost3410NamedParameters()
  16. {
  17. }
  18. private static readonly IDictionary objIds = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  19. private static readonly IDictionary parameters = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  20. private static readonly Gost3410ParamSetParameters cryptoProA = new Gost3410ParamSetParameters(
  21. 1024,
  22. new BigInteger("127021248288932417465907042777176443525787653508916535812817507265705031260985098497423188333483401180925999995120988934130659205614996724254121049274349357074920312769561451689224110579311248812610229678534638401693520013288995000362260684222750813532307004517341633685004541062586971416883686778842537820383"),
  23. new BigInteger("68363196144955700784444165611827252895102170888761442055095051287550314083023"),
  24. new BigInteger("100997906755055304772081815535925224869841082572053457874823515875577147990529272777244152852699298796483356699682842027972896052747173175480590485607134746852141928680912561502802222185647539190902656116367847270145019066794290930185446216399730872221732889830323194097355403213400972588322876850946740663962")
  25. // validationAlgorithm {
  26. // algorithm
  27. // id-GostR3410-94-bBis,
  28. // parameters
  29. // GostR3410-94-ValidationBisParameters: {
  30. // x0 1376285941,
  31. // c 3996757427
  32. // }
  33. // }
  34. );
  35. private static readonly Gost3410ParamSetParameters cryptoProB = new Gost3410ParamSetParameters(
  36. 1024,
  37. new BigInteger("139454871199115825601409655107690713107041707059928031797758001454375765357722984094124368522288239833039114681648076688236921220737322672160740747771700911134550432053804647694904686120113087816240740184800477047157336662926249423571248823968542221753660143391485680840520336859458494803187341288580489525163"),
  38. new BigInteger("79885141663410976897627118935756323747307951916507639758300472692338873533959"),
  39. new BigInteger("42941826148615804143873447737955502392672345968607143066798112994089471231420027060385216699563848719957657284814898909770759462613437669456364882730370838934791080835932647976778601915343474400961034231316672578686920482194932878633360203384797092684342247621055760235016132614780652761028509445403338652341")
  40. // validationAlgorithm {
  41. // algorithm
  42. // id-GostR3410-94-bBis,
  43. // parameters
  44. // GostR3410-94-ValidationBisParameters: {
  45. // x0 1536654555,
  46. // c 1855361757,
  47. // d 14408629386140014567655
  48. //4902939282056547857802241461782996702017713059974755104394739915140
  49. //6115284791024439062735788342744854120601660303926203867703556828005
  50. //8957203818114895398976594425537561271800850306
  51. // }
  52. // }
  53. //}
  54. );
  55. private static readonly Gost3410ParamSetParameters cryptoProXchA = new Gost3410ParamSetParameters(
  56. 1024,
  57. new BigInteger("142011741597563481196368286022318089743276138395243738762872573441927459393512718973631166078467600360848946623567625795282774719212241929071046134208380636394084512691828894000571524625445295769349356752728956831541775441763139384457191755096847107846595662547942312293338483924514339614727760681880609734239"),
  58. new BigInteger("91771529896554605945588149018382750217296858393520724172743325725474374979801"),
  59. new BigInteger("133531813272720673433859519948319001217942375967847486899482359599369642528734712461590403327731821410328012529253871914788598993103310567744136196364803064721377826656898686468463277710150809401182608770201615324990468332931294920912776241137878030224355746606283971659376426832674269780880061631528163475887")
  60. );
  61. static Gost3410NamedParameters()
  62. {
  63. parameters[CryptoProObjectIdentifiers.GostR3410x94CryptoProA] = cryptoProA;
  64. parameters[CryptoProObjectIdentifiers.GostR3410x94CryptoProB] = cryptoProB;
  65. //parameters[CryptoProObjectIdentifiers.GostR3410x94CryptoProC] = cryptoProC;
  66. //parameters[CryptoProObjectIdentifiers.GostR3410x94CryptoProD] = cryptoProD;
  67. parameters[CryptoProObjectIdentifiers.GostR3410x94CryptoProXchA] = cryptoProXchA;
  68. //parameters[CryptoProObjectIdentifiers.GostR3410x94CryptoProXchB] = cryptoProXchA;
  69. //parameters[CryptoProObjectIdentifiers.GostR3410x94CryptoProXchC] = cryptoProXchA;
  70. objIds["GostR3410-94-CryptoPro-A"] = CryptoProObjectIdentifiers.GostR3410x94CryptoProA;
  71. objIds["GostR3410-94-CryptoPro-B"] = CryptoProObjectIdentifiers.GostR3410x94CryptoProB;
  72. objIds["GostR3410-94-CryptoPro-XchA"] = CryptoProObjectIdentifiers.GostR3410x94CryptoProXchA;
  73. }
  74. /**
  75. * return the GOST3410ParamSetParameters object for the given OID, null if it
  76. * isn't present.
  77. *
  78. * @param oid an object identifier representing a named parameters, if present.
  79. */
  80. public static Gost3410ParamSetParameters GetByOid(
  81. DerObjectIdentifier oid)
  82. {
  83. return (Gost3410ParamSetParameters) parameters[oid];
  84. }
  85. /**
  86. * returns an enumeration containing the name strings for parameters
  87. * contained in this structure.
  88. */
  89. public static IEnumerable Names
  90. {
  91. get { return new EnumerableProxy(objIds.Keys); }
  92. }
  93. public static Gost3410ParamSetParameters GetByName(
  94. string name)
  95. {
  96. DerObjectIdentifier oid = (DerObjectIdentifier) objIds[name];
  97. if (oid != null)
  98. {
  99. return (Gost3410ParamSetParameters) parameters[oid];
  100. }
  101. return null;
  102. }
  103. public static DerObjectIdentifier GetOid(
  104. string name)
  105. {
  106. return (DerObjectIdentifier) objIds[name];
  107. }
  108. }
  109. }
  110. #endif