ECGOST3410NamedCurves.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.Crypto.Parameters;
  6. using Org.BouncyCastle.Math;
  7. using Org.BouncyCastle.Math.EC;
  8. using Org.BouncyCastle.Utilities;
  9. using Org.BouncyCastle.Utilities.Collections;
  10. namespace Org.BouncyCastle.Asn1.CryptoPro
  11. {
  12. /**
  13. * table of the available named parameters for GOST 3410-2001.
  14. */
  15. public sealed class ECGost3410NamedCurves
  16. {
  17. private ECGost3410NamedCurves()
  18. {
  19. }
  20. internal static readonly IDictionary objIds = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  21. internal static readonly IDictionary parameters = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  22. internal static readonly IDictionary names = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  23. static ECGost3410NamedCurves()
  24. {
  25. BigInteger mod_p = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639319");
  26. BigInteger mod_q = new BigInteger("115792089237316195423570985008687907853073762908499243225378155805079068850323");
  27. FpCurve curve = new FpCurve(
  28. mod_p, // p
  29. new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639316"), // a
  30. new BigInteger("166"), // b
  31. mod_q,
  32. BigInteger.One);
  33. ECDomainParameters ecParams = new ECDomainParameters(
  34. curve,
  35. curve.CreatePoint(
  36. new BigInteger("1"), // x
  37. new BigInteger("64033881142927202683649881450433473985931760268884941288852745803908878638612")), // y
  38. mod_q);
  39. parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProA] = ecParams;
  40. mod_p = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639319");
  41. mod_q = new BigInteger("115792089237316195423570985008687907853073762908499243225378155805079068850323");
  42. curve = new FpCurve(
  43. mod_p, // p
  44. new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639316"),
  45. new BigInteger("166"),
  46. mod_q,
  47. BigInteger.One);
  48. ecParams = new ECDomainParameters(
  49. curve,
  50. curve.CreatePoint(
  51. new BigInteger("1"), // x
  52. new BigInteger("64033881142927202683649881450433473985931760268884941288852745803908878638612")), // y
  53. mod_q);
  54. parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchA] = ecParams;
  55. mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564823193"); //p
  56. mod_q = new BigInteger("57896044618658097711785492504343953927102133160255826820068844496087732066703"); //q
  57. curve = new FpCurve(
  58. mod_p, // p
  59. new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564823190"), // a
  60. new BigInteger("28091019353058090096996979000309560759124368558014865957655842872397301267595"), // b
  61. mod_q,
  62. BigInteger.One);
  63. ecParams = new ECDomainParameters(
  64. curve,
  65. curve.CreatePoint(
  66. new BigInteger("1"), // x
  67. new BigInteger("28792665814854611296992347458380284135028636778229113005756334730996303888124")), // y
  68. mod_q); // q
  69. parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProB] = ecParams;
  70. mod_p = new BigInteger("70390085352083305199547718019018437841079516630045180471284346843705633502619");
  71. mod_q = new BigInteger("70390085352083305199547718019018437840920882647164081035322601458352298396601");
  72. curve = new FpCurve(
  73. mod_p, // p
  74. new BigInteger("70390085352083305199547718019018437841079516630045180471284346843705633502616"),
  75. new BigInteger("32858"),
  76. mod_q,
  77. BigInteger.One);
  78. ecParams = new ECDomainParameters(
  79. curve,
  80. curve.CreatePoint(
  81. new BigInteger("0"),
  82. new BigInteger("29818893917731240733471273240314769927240550812383695689146495261604565990247")),
  83. mod_q);
  84. parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchB] = ecParams;
  85. mod_p = new BigInteger("70390085352083305199547718019018437841079516630045180471284346843705633502619"); //p
  86. mod_q = new BigInteger("70390085352083305199547718019018437840920882647164081035322601458352298396601"); //q
  87. curve = new FpCurve(
  88. mod_p, // p
  89. new BigInteger("70390085352083305199547718019018437841079516630045180471284346843705633502616"), // a
  90. new BigInteger("32858"), // b
  91. mod_q,
  92. BigInteger.One);
  93. ecParams = new ECDomainParameters(
  94. curve,
  95. curve.CreatePoint(
  96. new BigInteger("0"), // x
  97. new BigInteger("29818893917731240733471273240314769927240550812383695689146495261604565990247")), // y
  98. mod_q); // q
  99. parameters[CryptoProObjectIdentifiers.GostR3410x2001CryptoProC] = ecParams;
  100. objIds["GostR3410-2001-CryptoPro-A"] = CryptoProObjectIdentifiers.GostR3410x2001CryptoProA;
  101. objIds["GostR3410-2001-CryptoPro-B"] = CryptoProObjectIdentifiers.GostR3410x2001CryptoProB;
  102. objIds["GostR3410-2001-CryptoPro-C"] = CryptoProObjectIdentifiers.GostR3410x2001CryptoProC;
  103. objIds["GostR3410-2001-CryptoPro-XchA"] = CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchA;
  104. objIds["GostR3410-2001-CryptoPro-XchB"] = CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchB;
  105. names[CryptoProObjectIdentifiers.GostR3410x2001CryptoProA] = "GostR3410-2001-CryptoPro-A";
  106. names[CryptoProObjectIdentifiers.GostR3410x2001CryptoProB] = "GostR3410-2001-CryptoPro-B";
  107. names[CryptoProObjectIdentifiers.GostR3410x2001CryptoProC] = "GostR3410-2001-CryptoPro-C";
  108. names[CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchA] = "GostR3410-2001-CryptoPro-XchA";
  109. names[CryptoProObjectIdentifiers.GostR3410x2001CryptoProXchB] = "GostR3410-2001-CryptoPro-XchB";
  110. }
  111. /**
  112. * return the ECDomainParameters object for the given OID, null if it
  113. * isn't present.
  114. *
  115. * @param oid an object identifier representing a named parameters, if present.
  116. */
  117. public static ECDomainParameters GetByOid(
  118. DerObjectIdentifier oid)
  119. {
  120. return (ECDomainParameters) parameters[oid];
  121. }
  122. /**
  123. * returns an enumeration containing the name strings for curves
  124. * contained in this structure.
  125. */
  126. public static IEnumerable Names
  127. {
  128. get { return new EnumerableProxy(names.Values); }
  129. }
  130. public static ECDomainParameters GetByName(
  131. string name)
  132. {
  133. DerObjectIdentifier oid = (DerObjectIdentifier) objIds[name];
  134. if (oid != null)
  135. {
  136. return (ECDomainParameters) parameters[oid];
  137. }
  138. return null;
  139. }
  140. /**
  141. * return the named curve name represented by the given object identifier.
  142. */
  143. public static string GetName(
  144. DerObjectIdentifier oid)
  145. {
  146. return (string) names[oid];
  147. }
  148. public static DerObjectIdentifier GetOid(
  149. string name)
  150. {
  151. return (DerObjectIdentifier) objIds[name];
  152. }
  153. }
  154. }
  155. #endif