SECNamedCurves.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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.Asn1.X9;
  6. using Org.BouncyCastle.Math;
  7. using Org.BouncyCastle.Math.EC;
  8. using Org.BouncyCastle.Math.EC.Endo;
  9. using Org.BouncyCastle.Utilities;
  10. using Org.BouncyCastle.Utilities.Collections;
  11. using Org.BouncyCastle.Utilities.Encoders;
  12. namespace Org.BouncyCastle.Asn1.Sec
  13. {
  14. public sealed class SecNamedCurves
  15. {
  16. private SecNamedCurves()
  17. {
  18. }
  19. private static ECCurve ConfigureCurve(ECCurve curve)
  20. {
  21. return curve;
  22. }
  23. private static ECCurve ConfigureCurveGlv(ECCurve c, GlvTypeBParameters p)
  24. {
  25. return c.Configure().SetEndomorphism(new GlvTypeBEndomorphism(c, p)).Create();
  26. }
  27. private static BigInteger FromHex(string hex)
  28. {
  29. return new BigInteger(1, Hex.Decode(hex));
  30. }
  31. /*
  32. * secp112r1
  33. */
  34. internal class Secp112r1Holder
  35. : X9ECParametersHolder
  36. {
  37. private Secp112r1Holder() {}
  38. internal static readonly X9ECParametersHolder Instance = new Secp112r1Holder();
  39. protected override X9ECParameters CreateParameters()
  40. {
  41. // p = (2^128 - 3) / 76439
  42. BigInteger p = FromHex("DB7C2ABF62E35E668076BEAD208B");
  43. BigInteger a = FromHex("DB7C2ABF62E35E668076BEAD2088");
  44. BigInteger b = FromHex("659EF8BA043916EEDE8911702B22");
  45. byte[] S = Hex.Decode("00F50B028E4D696E676875615175290472783FB1");
  46. BigInteger n = FromHex("DB7C2ABF62E35E7628DFAC6561C5");
  47. BigInteger h = BigInteger.One;
  48. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  49. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  50. + "09487239995A5EE76B55F9C2F098"
  51. + "A89CE5AF8724C0A23E0E0FF77500"));
  52. return new X9ECParameters(curve, G, n, h, S);
  53. }
  54. }
  55. /*
  56. * secp112r2
  57. */
  58. internal class Secp112r2Holder
  59. : X9ECParametersHolder
  60. {
  61. private Secp112r2Holder() {}
  62. internal static readonly X9ECParametersHolder Instance = new Secp112r2Holder();
  63. protected override X9ECParameters CreateParameters()
  64. {
  65. // p = (2^128 - 3) / 76439
  66. BigInteger p = FromHex("DB7C2ABF62E35E668076BEAD208B");
  67. BigInteger a = FromHex("6127C24C05F38A0AAAF65C0EF02C");
  68. BigInteger b = FromHex("51DEF1815DB5ED74FCC34C85D709");
  69. byte[] S = Hex.Decode("002757A1114D696E6768756151755316C05E0BD4");
  70. BigInteger n = FromHex("36DF0AAFD8B8D7597CA10520D04B");
  71. BigInteger h = BigInteger.ValueOf(4);
  72. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  73. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  74. + "4BA30AB5E892B4E1649DD0928643"
  75. + "ADCD46F5882E3747DEF36E956E97"));
  76. return new X9ECParameters(curve, G, n, h, S);
  77. }
  78. }
  79. /*
  80. * secp128r1
  81. */
  82. internal class Secp128r1Holder
  83. : X9ECParametersHolder
  84. {
  85. private Secp128r1Holder() {}
  86. internal static readonly X9ECParametersHolder Instance = new Secp128r1Holder();
  87. protected override X9ECParameters CreateParameters()
  88. {
  89. // p = 2^128 - 2^97 - 1
  90. BigInteger p = FromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF");
  91. BigInteger a = FromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC");
  92. BigInteger b = FromHex("E87579C11079F43DD824993C2CEE5ED3");
  93. byte[] S = Hex.Decode("000E0D4D696E6768756151750CC03A4473D03679");
  94. BigInteger n = FromHex("FFFFFFFE0000000075A30D1B9038A115");
  95. BigInteger h = BigInteger.One;
  96. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  97. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  98. + "161FF7528B899B2D0C28607CA52C5B86"
  99. + "CF5AC8395BAFEB13C02DA292DDED7A83"));
  100. return new X9ECParameters(curve, G, n, h, S);
  101. }
  102. }
  103. /*
  104. * secp128r2
  105. */
  106. internal class Secp128r2Holder
  107. : X9ECParametersHolder
  108. {
  109. private Secp128r2Holder() {}
  110. internal static readonly X9ECParametersHolder Instance = new Secp128r2Holder();
  111. protected override X9ECParameters CreateParameters()
  112. {
  113. // p = 2^128 - 2^97 - 1
  114. BigInteger p = FromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF");
  115. BigInteger a = FromHex("D6031998D1B3BBFEBF59CC9BBFF9AEE1");
  116. BigInteger b = FromHex("5EEEFCA380D02919DC2C6558BB6D8A5D");
  117. byte[] S = Hex.Decode("004D696E67687561517512D8F03431FCE63B88F4");
  118. BigInteger n = FromHex("3FFFFFFF7FFFFFFFBE0024720613B5A3");
  119. BigInteger h = BigInteger.ValueOf(4);
  120. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  121. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  122. + "7B6AA5D85E572983E6FB32A7CDEBC140"
  123. + "27B6916A894D3AEE7106FE805FC34B44"));
  124. return new X9ECParameters(curve, G, n, h, S);
  125. }
  126. }
  127. /*
  128. * secp160k1
  129. */
  130. internal class Secp160k1Holder
  131. : X9ECParametersHolder
  132. {
  133. private Secp160k1Holder() {}
  134. internal static readonly X9ECParametersHolder Instance = new Secp160k1Holder();
  135. protected override X9ECParameters CreateParameters()
  136. {
  137. // p = 2^160 - 2^32 - 2^14 - 2^12 - 2^9 - 2^8 - 2^7 - 2^3 - 2^2 - 1
  138. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73");
  139. BigInteger a = BigInteger.Zero;
  140. BigInteger b = BigInteger.ValueOf(7);
  141. byte[] S = null;
  142. BigInteger n = FromHex("0100000000000000000001B8FA16DFAB9ACA16B6B3");
  143. BigInteger h = BigInteger.One;
  144. GlvTypeBParameters glv = new GlvTypeBParameters(
  145. new BigInteger("9ba48cba5ebcb9b6bd33b92830b2a2e0e192f10a", 16),
  146. new BigInteger("c39c6c3b3a36d7701b9c71a1f5804ae5d0003f4", 16),
  147. new BigInteger[]{
  148. new BigInteger("9162fbe73984472a0a9e", 16),
  149. new BigInteger("-96341f1138933bc2f505", 16) },
  150. new BigInteger[]{
  151. new BigInteger("127971af8721782ecffa3", 16),
  152. new BigInteger("9162fbe73984472a0a9e", 16) },
  153. new BigInteger("9162fbe73984472a0a9d0590", 16),
  154. new BigInteger("96341f1138933bc2f503fd44", 16),
  155. 176);
  156. ECCurve curve = ConfigureCurveGlv(new FpCurve(p, a, b, n, h), glv);
  157. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  158. + "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB"
  159. + "938CF935318FDCED6BC28286531733C3F03C4FEE"));
  160. return new X9ECParameters(curve, G, n, h, S);
  161. }
  162. }
  163. /*
  164. * secp160r1
  165. */
  166. internal class Secp160r1Holder
  167. : X9ECParametersHolder
  168. {
  169. private Secp160r1Holder() {}
  170. internal static readonly X9ECParametersHolder Instance = new Secp160r1Holder();
  171. protected override X9ECParameters CreateParameters()
  172. {
  173. // p = 2^160 - 2^31 - 1
  174. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF");
  175. BigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC");
  176. BigInteger b = FromHex("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45");
  177. byte[] S = Hex.Decode("1053CDE42C14D696E67687561517533BF3F83345");
  178. BigInteger n = FromHex("0100000000000000000001F4C8F927AED3CA752257");
  179. BigInteger h = BigInteger.One;
  180. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  181. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  182. + "4A96B5688EF573284664698968C38BB913CBFC82"
  183. + "23A628553168947D59DCC912042351377AC5FB32"));
  184. return new X9ECParameters(curve, G, n, h, S);
  185. }
  186. }
  187. /*
  188. * secp160r2
  189. */
  190. internal class Secp160r2Holder
  191. : X9ECParametersHolder
  192. {
  193. private Secp160r2Holder() {}
  194. internal static readonly X9ECParametersHolder Instance = new Secp160r2Holder();
  195. protected override X9ECParameters CreateParameters()
  196. {
  197. // p = 2^160 - 2^32 - 2^14 - 2^12 - 2^9 - 2^8 - 2^7 - 2^3 - 2^2 - 1
  198. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73");
  199. BigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70");
  200. BigInteger b = FromHex("B4E134D3FB59EB8BAB57274904664D5AF50388BA");
  201. byte[] S = Hex.Decode("B99B99B099B323E02709A4D696E6768756151751");
  202. BigInteger n = FromHex("0100000000000000000000351EE786A818F3A1A16B");
  203. BigInteger h = BigInteger.One;
  204. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  205. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  206. + "52DCB034293A117E1F4FF11B30F7199D3144CE6D"
  207. + "FEAFFEF2E331F296E071FA0DF9982CFEA7D43F2E"));
  208. return new X9ECParameters(curve, G, n, h, S);
  209. }
  210. }
  211. /*
  212. * secp192k1
  213. */
  214. internal class Secp192k1Holder
  215. : X9ECParametersHolder
  216. {
  217. private Secp192k1Holder() {}
  218. internal static readonly X9ECParametersHolder Instance = new Secp192k1Holder();
  219. protected override X9ECParameters CreateParameters()
  220. {
  221. // p = 2^192 - 2^32 - 2^12 - 2^8 - 2^7 - 2^6 - 2^3 - 1
  222. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37");
  223. BigInteger a = BigInteger.Zero;
  224. BigInteger b = BigInteger.ValueOf(3);
  225. byte[] S = null;
  226. BigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D");
  227. BigInteger h = BigInteger.One;
  228. GlvTypeBParameters glv = new GlvTypeBParameters(
  229. new BigInteger("bb85691939b869c1d087f601554b96b80cb4f55b35f433c2", 16),
  230. new BigInteger("3d84f26c12238d7b4f3d516613c1759033b1a5800175d0b1", 16),
  231. new BigInteger[]{
  232. new BigInteger("71169be7330b3038edb025f1", 16),
  233. new BigInteger("-b3fb3400dec5c4adceb8655c", 16) },
  234. new BigInteger[]{
  235. new BigInteger("12511cfe811d0f4e6bc688b4d", 16),
  236. new BigInteger("71169be7330b3038edb025f1", 16) },
  237. new BigInteger("71169be7330b3038edb025f1d0f9", 16),
  238. new BigInteger("b3fb3400dec5c4adceb8655d4c94", 16),
  239. 208);
  240. ECCurve curve = ConfigureCurveGlv(new FpCurve(p, a, b, n, h), glv);
  241. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  242. + "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D"
  243. + "9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D"));
  244. return new X9ECParameters(curve, G, n, h, S);
  245. }
  246. }
  247. /*
  248. * secp192r1
  249. */
  250. internal class Secp192r1Holder
  251. : X9ECParametersHolder
  252. {
  253. private Secp192r1Holder() {}
  254. internal static readonly X9ECParametersHolder Instance = new Secp192r1Holder();
  255. protected override X9ECParameters CreateParameters()
  256. {
  257. // p = 2^192 - 2^64 - 1
  258. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF");
  259. BigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC");
  260. BigInteger b = FromHex("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1");
  261. byte[] S = Hex.Decode("3045AE6FC8422F64ED579528D38120EAE12196D5");
  262. BigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831");
  263. BigInteger h = BigInteger.One;
  264. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  265. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  266. + "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012"
  267. + "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811"));
  268. return new X9ECParameters(curve, G, n, h, S);
  269. }
  270. }
  271. /*
  272. * secp224k1
  273. */
  274. internal class Secp224k1Holder
  275. : X9ECParametersHolder
  276. {
  277. private Secp224k1Holder() {}
  278. internal static readonly X9ECParametersHolder Instance = new Secp224k1Holder();
  279. protected override X9ECParameters CreateParameters()
  280. {
  281. // p = 2^224 - 2^32 - 2^12 - 2^11 - 2^9 - 2^7 - 2^4 - 2 - 1
  282. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D");
  283. BigInteger a = BigInteger.Zero;
  284. BigInteger b = BigInteger.ValueOf(5);
  285. byte[] S = null;
  286. BigInteger n = FromHex("010000000000000000000000000001DCE8D2EC6184CAF0A971769FB1F7");
  287. BigInteger h = BigInteger.One;
  288. GlvTypeBParameters glv = new GlvTypeBParameters(
  289. new BigInteger("fe0e87005b4e83761908c5131d552a850b3f58b749c37cf5b84d6768", 16),
  290. new BigInteger("60dcd2104c4cbc0be6eeefc2bdd610739ec34e317f9b33046c9e4788", 16),
  291. new BigInteger[]{
  292. new BigInteger("6b8cf07d4ca75c88957d9d670591", 16),
  293. new BigInteger("-b8adf1378a6eb73409fa6c9c637d", 16) },
  294. new BigInteger[]{
  295. new BigInteger("1243ae1b4d71613bc9f780a03690e", 16),
  296. new BigInteger("6b8cf07d4ca75c88957d9d670591", 16) },
  297. new BigInteger("6b8cf07d4ca75c88957d9d67059037a4", 16),
  298. new BigInteger("b8adf1378a6eb73409fa6c9c637ba7f5", 16),
  299. 240);
  300. ECCurve curve = ConfigureCurveGlv(new FpCurve(p, a, b, n, h), glv);
  301. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  302. + "A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C"
  303. + "7E089FED7FBA344282CAFBD6F7E319F7C0B0BD59E2CA4BDB556D61A5"));
  304. return new X9ECParameters(curve, G, n, h, S);
  305. }
  306. }
  307. /*
  308. * secp224r1
  309. */
  310. internal class Secp224r1Holder
  311. : X9ECParametersHolder
  312. {
  313. private Secp224r1Holder() {}
  314. internal static readonly X9ECParametersHolder Instance = new Secp224r1Holder();
  315. protected override X9ECParameters CreateParameters()
  316. {
  317. // p = 2^224 - 2^96 + 1
  318. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001");
  319. BigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE");
  320. BigInteger b = FromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4");
  321. byte[] S = Hex.Decode("BD71344799D5C7FCDC45B59FA3B9AB8F6A948BC5");
  322. BigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D");
  323. BigInteger h = BigInteger.One;
  324. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  325. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  326. + "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21"
  327. + "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34"));
  328. return new X9ECParameters(curve, G, n, h, S);
  329. }
  330. }
  331. /*
  332. * secp256k1
  333. */
  334. internal class Secp256k1Holder
  335. : X9ECParametersHolder
  336. {
  337. private Secp256k1Holder() {}
  338. internal static readonly X9ECParametersHolder Instance = new Secp256k1Holder();
  339. protected override X9ECParameters CreateParameters()
  340. {
  341. // p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
  342. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F");
  343. BigInteger a = BigInteger.Zero;
  344. BigInteger b = BigInteger.ValueOf(7);
  345. byte[] S = null;
  346. BigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
  347. BigInteger h = BigInteger.One;
  348. GlvTypeBParameters glv = new GlvTypeBParameters(
  349. new BigInteger("7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee", 16),
  350. new BigInteger("5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72", 16),
  351. new BigInteger[]{
  352. new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16),
  353. new BigInteger("-e4437ed6010e88286f547fa90abfe4c3", 16) },
  354. new BigInteger[]{
  355. new BigInteger("114ca50f7a8e2f3f657c1108d9d44cfd8", 16),
  356. new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16) },
  357. new BigInteger("3086d221a7d46bcde86c90e49284eb153dab", 16),
  358. new BigInteger("e4437ed6010e88286f547fa90abfe4c42212", 16),
  359. 272);
  360. ECCurve curve = ConfigureCurveGlv(new FpCurve(p, a, b, n, h), glv);
  361. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  362. + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
  363. + "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"));
  364. return new X9ECParameters(curve, G, n, h, S);
  365. }
  366. }
  367. /*
  368. * secp256r1
  369. */
  370. internal class Secp256r1Holder
  371. : X9ECParametersHolder
  372. {
  373. private Secp256r1Holder() {}
  374. internal static readonly X9ECParametersHolder Instance = new Secp256r1Holder();
  375. protected override X9ECParameters CreateParameters()
  376. {
  377. // p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1
  378. BigInteger p = FromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
  379. BigInteger a = FromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
  380. BigInteger b = FromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");
  381. byte[] S = Hex.Decode("C49D360886E704936A6678E1139D26B7819F7E90");
  382. BigInteger n = FromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
  383. BigInteger h = BigInteger.One;
  384. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  385. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  386. + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"
  387. + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5"));
  388. return new X9ECParameters(curve, G, n, h, S);
  389. }
  390. }
  391. /*
  392. * secp384r1
  393. */
  394. internal class Secp384r1Holder
  395. : X9ECParametersHolder
  396. {
  397. private Secp384r1Holder() {}
  398. internal static readonly X9ECParametersHolder Instance = new Secp384r1Holder();
  399. protected override X9ECParameters CreateParameters()
  400. {
  401. // p = 2^384 - 2^128 - 2^96 + 2^32 - 1
  402. BigInteger p = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF");
  403. BigInteger a = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC");
  404. BigInteger b = FromHex("B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF");
  405. byte[] S = Hex.Decode("A335926AA319A27A1D00896A6773A4827ACDAC73");
  406. BigInteger n = FromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973");
  407. BigInteger h = BigInteger.One;
  408. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  409. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  410. + "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7"
  411. + "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F"));
  412. return new X9ECParameters(curve, G, n, h, S);
  413. }
  414. }
  415. /*
  416. * secp521r1
  417. */
  418. internal class Secp521r1Holder
  419. : X9ECParametersHolder
  420. {
  421. private Secp521r1Holder() {}
  422. internal static readonly X9ECParametersHolder Instance = new Secp521r1Holder();
  423. protected override X9ECParameters CreateParameters()
  424. {
  425. // p = 2^521 - 1
  426. BigInteger p = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
  427. BigInteger a = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC");
  428. BigInteger b = FromHex("0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00");
  429. byte[] S = Hex.Decode("D09E8800291CB85396CC6717393284AAA0DA64BA");
  430. BigInteger n = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409");
  431. BigInteger h = BigInteger.One;
  432. ECCurve curve = ConfigureCurve(new FpCurve(p, a, b, n, h));
  433. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  434. + "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66"
  435. + "011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650"));
  436. return new X9ECParameters(curve, G, n, h, S);
  437. }
  438. }
  439. /*
  440. * sect113r1
  441. */
  442. internal class Sect113r1Holder
  443. : X9ECParametersHolder
  444. {
  445. private Sect113r1Holder() {}
  446. internal static readonly X9ECParametersHolder Instance = new Sect113r1Holder();
  447. private const int m = 113;
  448. private const int k = 9;
  449. protected override X9ECParameters CreateParameters()
  450. {
  451. BigInteger a = FromHex("003088250CA6E7C7FE649CE85820F7");
  452. BigInteger b = FromHex("00E8BEE4D3E2260744188BE0E9C723");
  453. byte[] S = Hex.Decode("10E723AB14D696E6768756151756FEBF8FCB49A9");
  454. BigInteger n = FromHex("0100000000000000D9CCEC8A39E56F");
  455. BigInteger h = BigInteger.ValueOf(2);
  456. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  457. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  458. + "009D73616F35F4AB1407D73562C10F"
  459. + "00A52830277958EE84D1315ED31886"));
  460. return new X9ECParameters(curve, G, n, h, S);
  461. }
  462. }
  463. /*
  464. * sect113r2
  465. */
  466. internal class Sect113r2Holder
  467. : X9ECParametersHolder
  468. {
  469. private Sect113r2Holder() {}
  470. internal static readonly X9ECParametersHolder Instance = new Sect113r2Holder();
  471. private const int m = 113;
  472. private const int k = 9;
  473. protected override X9ECParameters CreateParameters()
  474. {
  475. BigInteger a = FromHex("00689918DBEC7E5A0DD6DFC0AA55C7");
  476. BigInteger b = FromHex("0095E9A9EC9B297BD4BF36E059184F");
  477. byte[] S = Hex.Decode("10C0FB15760860DEF1EEF4D696E676875615175D");
  478. BigInteger n = FromHex("010000000000000108789B2496AF93");
  479. BigInteger h = BigInteger.ValueOf(2);
  480. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  481. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  482. + "01A57A6A7B26CA5EF52FCDB8164797"
  483. + "00B3ADC94ED1FE674C06E695BABA1D"));
  484. return new X9ECParameters(curve, G, n, h, S);
  485. }
  486. }
  487. /*
  488. * sect131r1
  489. */
  490. internal class Sect131r1Holder
  491. : X9ECParametersHolder
  492. {
  493. private Sect131r1Holder() {}
  494. internal static readonly X9ECParametersHolder Instance = new Sect131r1Holder();
  495. private const int m = 131;
  496. private const int k1 = 2;
  497. private const int k2 = 3;
  498. private const int k3 = 8;
  499. protected override X9ECParameters CreateParameters()
  500. {
  501. BigInteger a = FromHex("07A11B09A76B562144418FF3FF8C2570B8");
  502. BigInteger b = FromHex("0217C05610884B63B9C6C7291678F9D341");
  503. byte[] S = Hex.Decode("4D696E676875615175985BD3ADBADA21B43A97E2");
  504. BigInteger n = FromHex("0400000000000000023123953A9464B54D");
  505. BigInteger h = BigInteger.ValueOf(2);
  506. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  507. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  508. + "0081BAF91FDF9833C40F9C181343638399"
  509. + "078C6E7EA38C001F73C8134B1B4EF9E150"));
  510. return new X9ECParameters(curve, G, n, h, S);
  511. }
  512. }
  513. /*
  514. * sect131r2
  515. */
  516. internal class Sect131r2Holder
  517. : X9ECParametersHolder
  518. {
  519. private Sect131r2Holder() {}
  520. internal static readonly X9ECParametersHolder Instance = new Sect131r2Holder();
  521. private const int m = 131;
  522. private const int k1 = 2;
  523. private const int k2 = 3;
  524. private const int k3 = 8;
  525. protected override X9ECParameters CreateParameters()
  526. {
  527. BigInteger a = FromHex("03E5A88919D7CAFCBF415F07C2176573B2");
  528. BigInteger b = FromHex("04B8266A46C55657AC734CE38F018F2192");
  529. byte[] S = Hex.Decode("985BD3ADBAD4D696E676875615175A21B43A97E3");
  530. BigInteger n = FromHex("0400000000000000016954A233049BA98F");
  531. BigInteger h = BigInteger.ValueOf(2);
  532. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  533. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  534. + "0356DCD8F2F95031AD652D23951BB366A8"
  535. + "0648F06D867940A5366D9E265DE9EB240F"));
  536. return new X9ECParameters(curve, G, n, h, S);
  537. }
  538. }
  539. /*
  540. * sect163k1
  541. */
  542. internal class Sect163k1Holder
  543. : X9ECParametersHolder
  544. {
  545. private Sect163k1Holder() {}
  546. internal static readonly X9ECParametersHolder Instance = new Sect163k1Holder();
  547. private const int m = 163;
  548. private const int k1 = 3;
  549. private const int k2 = 6;
  550. private const int k3 = 7;
  551. protected override X9ECParameters CreateParameters()
  552. {
  553. BigInteger a = BigInteger.One;
  554. BigInteger b = BigInteger.One;
  555. byte[] S = null;
  556. BigInteger n = FromHex("04000000000000000000020108A2E0CC0D99F8A5EF");
  557. BigInteger h = BigInteger.ValueOf(2);
  558. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  559. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  560. + "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8"
  561. + "0289070FB05D38FF58321F2E800536D538CCDAA3D9"));
  562. return new X9ECParameters(curve, G, n, h, S);
  563. }
  564. }
  565. /*
  566. * sect163r1
  567. */
  568. internal class Sect163r1Holder
  569. : X9ECParametersHolder
  570. {
  571. private Sect163r1Holder() {}
  572. internal static readonly X9ECParametersHolder Instance = new Sect163r1Holder();
  573. private const int m = 163;
  574. private const int k1 = 3;
  575. private const int k2 = 6;
  576. private const int k3 = 7;
  577. protected override X9ECParameters CreateParameters()
  578. {
  579. BigInteger a = FromHex("07B6882CAAEFA84F9554FF8428BD88E246D2782AE2");
  580. BigInteger b = FromHex("0713612DCDDCB40AAB946BDA29CA91F73AF958AFD9");
  581. byte[] S = Hex.Decode("24B7B137C8A14D696E6768756151756FD0DA2E5C");
  582. BigInteger n = FromHex("03FFFFFFFFFFFFFFFFFFFF48AAB689C29CA710279B");
  583. BigInteger h = BigInteger.ValueOf(2);
  584. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  585. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  586. + "0369979697AB43897789566789567F787A7876A654"
  587. + "00435EDB42EFAFB2989D51FEFCE3C80988F41FF883"));
  588. return new X9ECParameters(curve, G, n, h, S);
  589. }
  590. }
  591. /*
  592. * sect163r2
  593. */
  594. internal class Sect163r2Holder
  595. : X9ECParametersHolder
  596. {
  597. private Sect163r2Holder() {}
  598. internal static readonly X9ECParametersHolder Instance = new Sect163r2Holder();
  599. private const int m = 163;
  600. private const int k1 = 3;
  601. private const int k2 = 6;
  602. private const int k3 = 7;
  603. protected override X9ECParameters CreateParameters()
  604. {
  605. BigInteger a = BigInteger.One;
  606. BigInteger b = FromHex("020A601907B8C953CA1481EB10512F78744A3205FD");
  607. byte[] S = Hex.Decode("85E25BFE5C86226CDB12016F7553F9D0E693A268");
  608. BigInteger n = FromHex("040000000000000000000292FE77E70C12A4234C33");
  609. BigInteger h = BigInteger.ValueOf(2);
  610. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  611. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  612. + "03F0EBA16286A2D57EA0991168D4994637E8343E36"
  613. + "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1"));
  614. return new X9ECParameters(curve, G, n, h, S);
  615. }
  616. }
  617. /*
  618. * sect193r1
  619. */
  620. internal class Sect193r1Holder
  621. : X9ECParametersHolder
  622. {
  623. private Sect193r1Holder() {}
  624. internal static readonly X9ECParametersHolder Instance = new Sect193r1Holder();
  625. private const int m = 193;
  626. private const int k = 15;
  627. protected override X9ECParameters CreateParameters()
  628. {
  629. BigInteger a = FromHex("0017858FEB7A98975169E171F77B4087DE098AC8A911DF7B01");
  630. BigInteger b = FromHex("00FDFB49BFE6C3A89FACADAA7A1E5BBC7CC1C2E5D831478814");
  631. byte[] S = Hex.Decode("103FAEC74D696E676875615175777FC5B191EF30");
  632. BigInteger n = FromHex("01000000000000000000000000C7F34A778F443ACC920EBA49");
  633. BigInteger h = BigInteger.ValueOf(2);
  634. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  635. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  636. + "01F481BC5F0FF84A74AD6CDF6FDEF4BF6179625372D8C0C5E1"
  637. + "0025E399F2903712CCF3EA9E3A1AD17FB0B3201B6AF7CE1B05"));
  638. return new X9ECParameters(curve, G, n, h, S);
  639. }
  640. }
  641. /*
  642. * sect193r2
  643. */
  644. internal class Sect193r2Holder
  645. : X9ECParametersHolder
  646. {
  647. private Sect193r2Holder() {}
  648. internal static readonly X9ECParametersHolder Instance = new Sect193r2Holder();
  649. private const int m = 193;
  650. private const int k = 15;
  651. protected override X9ECParameters CreateParameters()
  652. {
  653. BigInteger a = FromHex("0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B");
  654. BigInteger b = FromHex("00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE");
  655. byte[] S = Hex.Decode("10B7B4D696E676875615175137C8A16FD0DA2211");
  656. BigInteger n = FromHex("010000000000000000000000015AAB561B005413CCD4EE99D5");
  657. BigInteger h = BigInteger.ValueOf(2);
  658. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  659. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  660. + "00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F"
  661. + "01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C"));
  662. return new X9ECParameters(curve, G, n, h, S);
  663. }
  664. }
  665. /*
  666. * sect233k1
  667. */
  668. internal class Sect233k1Holder
  669. : X9ECParametersHolder
  670. {
  671. private Sect233k1Holder() {}
  672. internal static readonly X9ECParametersHolder Instance = new Sect233k1Holder();
  673. private const int m = 233;
  674. private const int k = 74;
  675. protected override X9ECParameters CreateParameters()
  676. {
  677. BigInteger a = BigInteger.Zero;
  678. BigInteger b = BigInteger.One;
  679. byte[] S = null;
  680. BigInteger n = FromHex("8000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF");
  681. BigInteger h = BigInteger.ValueOf(4);
  682. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  683. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  684. + "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126"
  685. + "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3"));
  686. return new X9ECParameters(curve, G, n, h, S);
  687. }
  688. }
  689. /*
  690. * sect233r1
  691. */
  692. internal class Sect233r1Holder
  693. : X9ECParametersHolder
  694. {
  695. private Sect233r1Holder() {}
  696. internal static readonly X9ECParametersHolder Instance = new Sect233r1Holder();
  697. private const int m = 233;
  698. private const int k = 74;
  699. protected override X9ECParameters CreateParameters()
  700. {
  701. BigInteger a = BigInteger.One;
  702. BigInteger b = FromHex("0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD");
  703. byte[] S = Hex.Decode("74D59FF07F6B413D0EA14B344B20A2DB049B50C3");
  704. BigInteger n = FromHex("01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7");
  705. BigInteger h = BigInteger.ValueOf(2);
  706. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  707. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  708. + "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B"
  709. + "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052"));
  710. return new X9ECParameters(curve, G, n, h, S);
  711. }
  712. }
  713. /*
  714. * sect239k1
  715. */
  716. internal class Sect239k1Holder
  717. : X9ECParametersHolder
  718. {
  719. private Sect239k1Holder() {}
  720. internal static readonly X9ECParametersHolder Instance = new Sect239k1Holder();
  721. private const int m = 239;
  722. private const int k = 158;
  723. protected override X9ECParameters CreateParameters()
  724. {
  725. BigInteger a = BigInteger.Zero;
  726. BigInteger b = BigInteger.One;
  727. byte[] S = null;
  728. BigInteger n = FromHex("2000000000000000000000000000005A79FEC67CB6E91F1C1DA800E478A5");
  729. BigInteger h = BigInteger.ValueOf(4);
  730. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  731. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  732. + "29A0B6A887A983E9730988A68727A8B2D126C44CC2CC7B2A6555193035DC"
  733. + "76310804F12E549BDB011C103089E73510ACB275FC312A5DC6B76553F0CA"));
  734. return new X9ECParameters(curve, G, n, h, S);
  735. }
  736. }
  737. /*
  738. * sect283k1
  739. */
  740. internal class Sect283k1Holder
  741. : X9ECParametersHolder
  742. {
  743. private Sect283k1Holder() {}
  744. internal static readonly X9ECParametersHolder Instance = new Sect283k1Holder();
  745. private const int m = 283;
  746. private const int k1 = 5;
  747. private const int k2 = 7;
  748. private const int k3 = 12;
  749. protected override X9ECParameters CreateParameters()
  750. {
  751. BigInteger a = BigInteger.Zero;
  752. BigInteger b = BigInteger.One;
  753. byte[] S = null;
  754. BigInteger n = FromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61");
  755. BigInteger h = BigInteger.ValueOf(4);
  756. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  757. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  758. + "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836"
  759. + "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259"));
  760. return new X9ECParameters(curve, G, n, h, S);
  761. }
  762. }
  763. /*
  764. * sect283r1
  765. */
  766. internal class Sect283r1Holder
  767. : X9ECParametersHolder
  768. {
  769. private Sect283r1Holder() {}
  770. internal static readonly X9ECParametersHolder Instance = new Sect283r1Holder();
  771. private const int m = 283;
  772. private const int k1 = 5;
  773. private const int k2 = 7;
  774. private const int k3 = 12;
  775. protected override X9ECParameters CreateParameters()
  776. {
  777. BigInteger a = BigInteger.One;
  778. BigInteger b = FromHex("027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5");
  779. byte[] S = Hex.Decode("77E2B07370EB0F832A6DD5B62DFC88CD06BB84BE");
  780. BigInteger n = FromHex("03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307");
  781. BigInteger h = BigInteger.ValueOf(2);
  782. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  783. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  784. + "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053"
  785. + "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4"));
  786. return new X9ECParameters(curve, G, n, h, S);
  787. }
  788. }
  789. /*
  790. * sect409k1
  791. */
  792. internal class Sect409k1Holder
  793. : X9ECParametersHolder
  794. {
  795. private Sect409k1Holder() {}
  796. internal static readonly X9ECParametersHolder Instance = new Sect409k1Holder();
  797. private const int m = 409;
  798. private const int k = 87;
  799. protected override X9ECParameters CreateParameters()
  800. {
  801. BigInteger a = BigInteger.Zero;
  802. BigInteger b = BigInteger.One;
  803. byte[] S = null;
  804. BigInteger n = FromHex("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF");
  805. BigInteger h = BigInteger.ValueOf(4);
  806. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  807. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  808. + "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746"
  809. + "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B"));
  810. return new X9ECParameters(curve, G, n, h, S);
  811. }
  812. }
  813. /*
  814. * sect409r1
  815. */
  816. internal class Sect409r1Holder
  817. : X9ECParametersHolder
  818. {
  819. private Sect409r1Holder() {}
  820. internal static readonly X9ECParametersHolder Instance = new Sect409r1Holder();
  821. private const int m = 409;
  822. private const int k = 87;
  823. protected override X9ECParameters CreateParameters()
  824. {
  825. BigInteger a = BigInteger.One;
  826. BigInteger b = FromHex("0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F");
  827. byte[] S = Hex.Decode("4099B5A457F9D69F79213D094C4BCD4D4262210B");
  828. BigInteger n = FromHex("010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173");
  829. BigInteger h = BigInteger.ValueOf(2);
  830. ECCurve curve = new F2mCurve(m, k, a, b, n, h);
  831. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  832. + "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7"
  833. + "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706"));
  834. return new X9ECParameters(curve, G, n, h, S);
  835. }
  836. }
  837. /*
  838. * sect571k1
  839. */
  840. internal class Sect571k1Holder
  841. : X9ECParametersHolder
  842. {
  843. private Sect571k1Holder() {}
  844. internal static readonly X9ECParametersHolder Instance = new Sect571k1Holder();
  845. private const int m = 571;
  846. private const int k1 = 2;
  847. private const int k2 = 5;
  848. private const int k3 = 10;
  849. protected override X9ECParameters CreateParameters()
  850. {
  851. BigInteger a = BigInteger.Zero;
  852. BigInteger b = BigInteger.One;
  853. byte[] S = null;
  854. BigInteger n = FromHex("020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001");
  855. BigInteger h = BigInteger.ValueOf(4);
  856. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  857. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  858. + "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972"
  859. + "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3"));
  860. return new X9ECParameters(curve, G, n, h, S);
  861. }
  862. }
  863. /*
  864. * sect571r1
  865. */
  866. internal class Sect571r1Holder
  867. : X9ECParametersHolder
  868. {
  869. private Sect571r1Holder() {}
  870. internal static readonly X9ECParametersHolder Instance = new Sect571r1Holder();
  871. private const int m = 571;
  872. private const int k1 = 2;
  873. private const int k2 = 5;
  874. private const int k3 = 10;
  875. protected override X9ECParameters CreateParameters()
  876. {
  877. BigInteger a = BigInteger.One;
  878. BigInteger b = FromHex("02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A");
  879. byte[] S = Hex.Decode("2AA058F73A0E33AB486B0F610410C53A7F132310");
  880. BigInteger n = FromHex("03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47");
  881. BigInteger h = BigInteger.ValueOf(2);
  882. ECCurve curve = new F2mCurve(m, k1, k2, k3, a, b, n, h);
  883. X9ECPoint G = new X9ECPoint(curve, Hex.Decode("04"
  884. + "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19"
  885. + "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B"));
  886. return new X9ECParameters(curve, G, n, h, S);
  887. }
  888. }
  889. private static readonly IDictionary objIds = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  890. private static readonly IDictionary curves = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  891. private static readonly IDictionary names = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  892. private static void DefineCurve(
  893. string name,
  894. DerObjectIdentifier oid,
  895. X9ECParametersHolder holder)
  896. {
  897. objIds.Add(Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name), oid);
  898. names.Add(oid, name);
  899. curves.Add(oid, holder);
  900. }
  901. static SecNamedCurves()
  902. {
  903. DefineCurve("secp112r1", SecObjectIdentifiers.SecP112r1, Secp112r1Holder.Instance);
  904. DefineCurve("secp112r2", SecObjectIdentifiers.SecP112r2, Secp112r2Holder.Instance);
  905. DefineCurve("secp128r1", SecObjectIdentifiers.SecP128r1, Secp128r1Holder.Instance);
  906. DefineCurve("secp128r2", SecObjectIdentifiers.SecP128r2, Secp128r2Holder.Instance);
  907. DefineCurve("secp160k1", SecObjectIdentifiers.SecP160k1, Secp160k1Holder.Instance);
  908. DefineCurve("secp160r1", SecObjectIdentifiers.SecP160r1, Secp160r1Holder.Instance);
  909. DefineCurve("secp160r2", SecObjectIdentifiers.SecP160r2, Secp160r2Holder.Instance);
  910. DefineCurve("secp192k1", SecObjectIdentifiers.SecP192k1, Secp192k1Holder.Instance);
  911. DefineCurve("secp192r1", SecObjectIdentifiers.SecP192r1, Secp192r1Holder.Instance);
  912. DefineCurve("secp224k1", SecObjectIdentifiers.SecP224k1, Secp224k1Holder.Instance);
  913. DefineCurve("secp224r1", SecObjectIdentifiers.SecP224r1, Secp224r1Holder.Instance);
  914. DefineCurve("secp256k1", SecObjectIdentifiers.SecP256k1, Secp256k1Holder.Instance);
  915. DefineCurve("secp256r1", SecObjectIdentifiers.SecP256r1, Secp256r1Holder.Instance);
  916. DefineCurve("secp384r1", SecObjectIdentifiers.SecP384r1, Secp384r1Holder.Instance);
  917. DefineCurve("secp521r1", SecObjectIdentifiers.SecP521r1, Secp521r1Holder.Instance);
  918. DefineCurve("sect113r1", SecObjectIdentifiers.SecT113r1, Sect113r1Holder.Instance);
  919. DefineCurve("sect113r2", SecObjectIdentifiers.SecT113r2, Sect113r2Holder.Instance);
  920. DefineCurve("sect131r1", SecObjectIdentifiers.SecT131r1, Sect131r1Holder.Instance);
  921. DefineCurve("sect131r2", SecObjectIdentifiers.SecT131r2, Sect131r2Holder.Instance);
  922. DefineCurve("sect163k1", SecObjectIdentifiers.SecT163k1, Sect163k1Holder.Instance);
  923. DefineCurve("sect163r1", SecObjectIdentifiers.SecT163r1, Sect163r1Holder.Instance);
  924. DefineCurve("sect163r2", SecObjectIdentifiers.SecT163r2, Sect163r2Holder.Instance);
  925. DefineCurve("sect193r1", SecObjectIdentifiers.SecT193r1, Sect193r1Holder.Instance);
  926. DefineCurve("sect193r2", SecObjectIdentifiers.SecT193r2, Sect193r2Holder.Instance);
  927. DefineCurve("sect233k1", SecObjectIdentifiers.SecT233k1, Sect233k1Holder.Instance);
  928. DefineCurve("sect233r1", SecObjectIdentifiers.SecT233r1, Sect233r1Holder.Instance);
  929. DefineCurve("sect239k1", SecObjectIdentifiers.SecT239k1, Sect239k1Holder.Instance);
  930. DefineCurve("sect283k1", SecObjectIdentifiers.SecT283k1, Sect283k1Holder.Instance);
  931. DefineCurve("sect283r1", SecObjectIdentifiers.SecT283r1, Sect283r1Holder.Instance);
  932. DefineCurve("sect409k1", SecObjectIdentifiers.SecT409k1, Sect409k1Holder.Instance);
  933. DefineCurve("sect409r1", SecObjectIdentifiers.SecT409r1, Sect409r1Holder.Instance);
  934. DefineCurve("sect571k1", SecObjectIdentifiers.SecT571k1, Sect571k1Holder.Instance);
  935. DefineCurve("sect571r1", SecObjectIdentifiers.SecT571r1, Sect571r1Holder.Instance);
  936. }
  937. public static X9ECParameters GetByName(
  938. string name)
  939. {
  940. DerObjectIdentifier oid = GetOid(name);
  941. return oid == null ? null : GetByOid(oid);
  942. }
  943. /**
  944. * return the X9ECParameters object for the named curve represented by
  945. * the passed in object identifier. Null if the curve isn't present.
  946. *
  947. * @param oid an object identifier representing a named curve, if present.
  948. */
  949. public static X9ECParameters GetByOid(
  950. DerObjectIdentifier oid)
  951. {
  952. X9ECParametersHolder holder = (X9ECParametersHolder)curves[oid];
  953. return holder == null ? null : holder.Parameters;
  954. }
  955. /**
  956. * return the object identifier signified by the passed in name. Null
  957. * if there is no object identifier associated with name.
  958. *
  959. * @return the object identifier associated with name, if present.
  960. */
  961. public static DerObjectIdentifier GetOid(
  962. string name)
  963. {
  964. return (DerObjectIdentifier)objIds[Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name)];
  965. }
  966. /**
  967. * return the named curve name represented by the given object identifier.
  968. */
  969. public static string GetName(
  970. DerObjectIdentifier oid)
  971. {
  972. return (string)names[oid];
  973. }
  974. /**
  975. * returns an enumeration containing the name strings for curves
  976. * contained in this structure.
  977. */
  978. public static IEnumerable Names
  979. {
  980. get { return new EnumerableProxy(names.Values); }
  981. }
  982. }
  983. }
  984. #endif