X962NamedCurves.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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.Math.EC;
  6. using Org.BouncyCastle.Utilities;
  7. using Org.BouncyCastle.Utilities.Collections;
  8. using Org.BouncyCastle.Utilities.Encoders;
  9. namespace Org.BouncyCastle.Asn1.X9
  10. {
  11. /**
  12. * table of the current named curves defined in X.962 EC-DSA.
  13. */
  14. public sealed class X962NamedCurves
  15. {
  16. private X962NamedCurves()
  17. {
  18. }
  19. internal class Prime192v1Holder
  20. : X9ECParametersHolder
  21. {
  22. private Prime192v1Holder() {}
  23. internal static readonly X9ECParametersHolder Instance = new Prime192v1Holder();
  24. protected override X9ECParameters CreateParameters()
  25. {
  26. BigInteger n = new BigInteger("ffffffffffffffffffffffff99def836146bc9b1b4d22831", 16);
  27. BigInteger h = BigInteger.One;
  28. ECCurve cFp192v1 = new FpCurve(
  29. new BigInteger("6277101735386680763835789423207666416083908700390324961279"),
  30. new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16),
  31. new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16),
  32. n, h);
  33. return new X9ECParameters(
  34. cFp192v1,
  35. new X9ECPoint(cFp192v1,
  36. Hex.Decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012")),
  37. n, h,
  38. Hex.Decode("3045AE6FC8422f64ED579528D38120EAE12196D5"));
  39. }
  40. }
  41. internal class Prime192v2Holder
  42. : X9ECParametersHolder
  43. {
  44. private Prime192v2Holder() {}
  45. internal static readonly X9ECParametersHolder Instance = new Prime192v2Holder();
  46. protected override X9ECParameters CreateParameters()
  47. {
  48. BigInteger n = new BigInteger("fffffffffffffffffffffffe5fb1a724dc80418648d8dd31", 16);
  49. BigInteger h = BigInteger.One;
  50. ECCurve cFp192v2 = new FpCurve(
  51. new BigInteger("6277101735386680763835789423207666416083908700390324961279"),
  52. new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16),
  53. new BigInteger("cc22d6dfb95c6b25e49c0d6364a4e5980c393aa21668d953", 16),
  54. n, h);
  55. return new X9ECParameters(
  56. cFp192v2,
  57. new X9ECPoint(cFp192v2,
  58. Hex.Decode("03eea2bae7e1497842f2de7769cfe9c989c072ad696f48034a")),
  59. n, h,
  60. Hex.Decode("31a92ee2029fd10d901b113e990710f0d21ac6b6"));
  61. }
  62. }
  63. internal class Prime192v3Holder
  64. : X9ECParametersHolder
  65. {
  66. private Prime192v3Holder() {}
  67. internal static readonly X9ECParametersHolder Instance = new Prime192v3Holder();
  68. protected override X9ECParameters CreateParameters()
  69. {
  70. BigInteger n = new BigInteger("ffffffffffffffffffffffff7a62d031c83f4294f640ec13", 16);
  71. BigInteger h = BigInteger.One;
  72. ECCurve cFp192v3 = new FpCurve(
  73. new BigInteger("6277101735386680763835789423207666416083908700390324961279"),
  74. new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16),
  75. new BigInteger("22123dc2395a05caa7423daeccc94760a7d462256bd56916", 16),
  76. n, h);
  77. return new X9ECParameters(
  78. cFp192v3,
  79. new X9ECPoint(cFp192v3,
  80. Hex.Decode("027d29778100c65a1da1783716588dce2b8b4aee8e228f1896")),
  81. n, h,
  82. Hex.Decode("c469684435deb378c4b65ca9591e2a5763059a2e"));
  83. }
  84. }
  85. internal class Prime239v1Holder
  86. : X9ECParametersHolder
  87. {
  88. private Prime239v1Holder() {}
  89. internal static readonly X9ECParametersHolder Instance = new Prime239v1Holder();
  90. protected override X9ECParameters CreateParameters()
  91. {
  92. BigInteger n = new BigInteger("7fffffffffffffffffffffff7fffff9e5e9a9f5d9071fbd1522688909d0b", 16);
  93. BigInteger h = BigInteger.One;
  94. ECCurve cFp239v1 = new FpCurve(
  95. new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
  96. new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16),
  97. new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16),
  98. n, h);
  99. return new X9ECParameters(
  100. cFp239v1,
  101. new X9ECPoint(cFp239v1,
  102. Hex.Decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")),
  103. n, h,
  104. Hex.Decode("e43bb460f0b80cc0c0b075798e948060f8321b7d"));
  105. }
  106. }
  107. internal class Prime239v2Holder
  108. : X9ECParametersHolder
  109. {
  110. private Prime239v2Holder() {}
  111. internal static readonly X9ECParametersHolder Instance = new Prime239v2Holder();
  112. protected override X9ECParameters CreateParameters()
  113. {
  114. BigInteger n = new BigInteger("7fffffffffffffffffffffff800000cfa7e8594377d414c03821bc582063", 16);
  115. BigInteger h = BigInteger.One;
  116. ECCurve cFp239v2 = new FpCurve(
  117. new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
  118. new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16),
  119. new BigInteger("617fab6832576cbbfed50d99f0249c3fee58b94ba0038c7ae84c8c832f2c", 16),
  120. n, h);
  121. return new X9ECParameters(
  122. cFp239v2,
  123. new X9ECPoint(cFp239v2,
  124. Hex.Decode("0238af09d98727705120c921bb5e9e26296a3cdcf2f35757a0eafd87b830e7")),
  125. n, h,
  126. Hex.Decode("e8b4011604095303ca3b8099982be09fcb9ae616"));
  127. }
  128. }
  129. internal class Prime239v3Holder
  130. : X9ECParametersHolder
  131. {
  132. private Prime239v3Holder() {}
  133. internal static readonly X9ECParametersHolder Instance = new Prime239v3Holder();
  134. protected override X9ECParameters CreateParameters()
  135. {
  136. BigInteger n = new BigInteger("7fffffffffffffffffffffff7fffff975deb41b3a6057c3c432146526551", 16);
  137. BigInteger h = BigInteger.One;
  138. ECCurve cFp239v3 = new FpCurve(
  139. new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"),
  140. new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16),
  141. new BigInteger("255705fa2a306654b1f4cb03d6a750a30c250102d4988717d9ba15ab6d3e", 16),
  142. n, h);
  143. return new X9ECParameters(
  144. cFp239v3,
  145. new X9ECPoint(cFp239v3,
  146. Hex.Decode("036768ae8e18bb92cfcf005c949aa2c6d94853d0e660bbf854b1c9505fe95a")),
  147. n, h,
  148. Hex.Decode("7d7374168ffe3471b60a857686a19475d3bfa2ff"));
  149. }
  150. }
  151. internal class Prime256v1Holder
  152. : X9ECParametersHolder
  153. {
  154. private Prime256v1Holder() {}
  155. internal static readonly X9ECParametersHolder Instance = new Prime256v1Holder();
  156. protected override X9ECParameters CreateParameters()
  157. {
  158. BigInteger n = new BigInteger("ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", 16);
  159. BigInteger h = BigInteger.One;
  160. ECCurve cFp256v1 = new FpCurve(
  161. new BigInteger("115792089210356248762697446949407573530086143415290314195533631308867097853951"),
  162. new BigInteger("ffffffff00000001000000000000000000000000fffffffffffffffffffffffc", 16),
  163. new BigInteger("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", 16),
  164. n, h);
  165. return new X9ECParameters(
  166. cFp256v1,
  167. new X9ECPoint(cFp256v1,
  168. Hex.Decode("036b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296")),
  169. n, h,
  170. Hex.Decode("c49d360886e704936a6678e1139d26b7819f7e90"));
  171. }
  172. }
  173. /*
  174. * F2m Curves
  175. */
  176. internal class C2pnb163v1Holder
  177. : X9ECParametersHolder
  178. {
  179. private C2pnb163v1Holder() {}
  180. internal static readonly X9ECParametersHolder Instance = new C2pnb163v1Holder();
  181. protected override X9ECParameters CreateParameters()
  182. {
  183. BigInteger n = new BigInteger("0400000000000000000001E60FC8821CC74DAEAFC1", 16);
  184. BigInteger h = BigInteger.Two;
  185. ECCurve c2m163v1 = new F2mCurve(
  186. 163,
  187. 1, 2, 8,
  188. new BigInteger("072546B5435234A422E0789675F432C89435DE5242", 16),
  189. new BigInteger("00C9517D06D5240D3CFF38C74B20B6CD4D6F9DD4D9", 16),
  190. n, h);
  191. return new X9ECParameters(
  192. c2m163v1,
  193. new X9ECPoint(c2m163v1,
  194. Hex.Decode("0307AF69989546103D79329FCC3D74880F33BBE803CB")),
  195. n, h,
  196. Hex.Decode("D2C0FB15760860DEF1EEF4D696E6768756151754"));
  197. }
  198. }
  199. internal class C2pnb163v2Holder
  200. : X9ECParametersHolder
  201. {
  202. private C2pnb163v2Holder() {}
  203. internal static readonly X9ECParametersHolder Instance = new C2pnb163v2Holder();
  204. protected override X9ECParameters CreateParameters()
  205. {
  206. BigInteger n = new BigInteger("03FFFFFFFFFFFFFFFFFFFDF64DE1151ADBB78F10A7", 16);
  207. BigInteger h = BigInteger.Two;
  208. ECCurve c2m163v2 = new F2mCurve(
  209. 163,
  210. 1, 2, 8,
  211. new BigInteger("0108B39E77C4B108BED981ED0E890E117C511CF072", 16),
  212. new BigInteger("0667ACEB38AF4E488C407433FFAE4F1C811638DF20", 16),
  213. n, h);
  214. return new X9ECParameters(
  215. c2m163v2,
  216. new X9ECPoint(c2m163v2,
  217. Hex.Decode("030024266E4EB5106D0A964D92C4860E2671DB9B6CC5")),
  218. n, h,
  219. null);
  220. }
  221. }
  222. internal class C2pnb163v3Holder
  223. : X9ECParametersHolder
  224. {
  225. private C2pnb163v3Holder() {}
  226. internal static readonly X9ECParametersHolder Instance = new C2pnb163v3Holder();
  227. protected override X9ECParameters CreateParameters()
  228. {
  229. BigInteger n = new BigInteger("03FFFFFFFFFFFFFFFFFFFE1AEE140F110AFF961309", 16);
  230. BigInteger h = BigInteger.Two;
  231. ECCurve c2m163v3 = new F2mCurve(
  232. 163,
  233. 1, 2, 8,
  234. new BigInteger("07A526C63D3E25A256A007699F5447E32AE456B50E", 16),
  235. new BigInteger("03F7061798EB99E238FD6F1BF95B48FEEB4854252B", 16),
  236. n, h);
  237. return new X9ECParameters(
  238. c2m163v3,
  239. new X9ECPoint(c2m163v3, Hex.Decode("0202F9F87B7C574D0BDECF8A22E6524775F98CDEBDCB")),
  240. n, h,
  241. null);
  242. }
  243. }
  244. internal class C2pnb176w1Holder
  245. : X9ECParametersHolder
  246. {
  247. private C2pnb176w1Holder() {}
  248. internal static readonly X9ECParametersHolder Instance = new C2pnb176w1Holder();
  249. protected override X9ECParameters CreateParameters()
  250. {
  251. BigInteger n = new BigInteger("010092537397ECA4F6145799D62B0A19CE06FE26AD", 16);
  252. BigInteger h = BigInteger.ValueOf(0xFF6E);
  253. ECCurve c2m176w1 = new F2mCurve(
  254. 176,
  255. 1, 2, 43,
  256. new BigInteger("00E4E6DB2995065C407D9D39B8D0967B96704BA8E9C90B", 16),
  257. new BigInteger("005DDA470ABE6414DE8EC133AE28E9BBD7FCEC0AE0FFF2", 16),
  258. n, h);
  259. return new X9ECParameters(
  260. c2m176w1,
  261. new X9ECPoint(c2m176w1,
  262. Hex.Decode("038D16C2866798B600F9F08BB4A8E860F3298CE04A5798")),
  263. n, h,
  264. null);
  265. }
  266. }
  267. internal class C2tnb191v1Holder
  268. : X9ECParametersHolder
  269. {
  270. private C2tnb191v1Holder() {}
  271. internal static readonly X9ECParametersHolder Instance = new C2tnb191v1Holder();
  272. protected override X9ECParameters CreateParameters()
  273. {
  274. BigInteger n = new BigInteger("40000000000000000000000004A20E90C39067C893BBB9A5", 16);
  275. BigInteger h = BigInteger.Two;
  276. ECCurve c2m191v1 = new F2mCurve(
  277. 191,
  278. 9,
  279. new BigInteger("2866537B676752636A68F56554E12640276B649EF7526267", 16),
  280. new BigInteger("2E45EF571F00786F67B0081B9495A3D95462F5DE0AA185EC", 16),
  281. n, h);
  282. return new X9ECParameters(
  283. c2m191v1,
  284. new X9ECPoint(c2m191v1,
  285. Hex.Decode("0236B3DAF8A23206F9C4F299D7B21A9C369137F2C84AE1AA0D")),
  286. n, h,
  287. Hex.Decode("4E13CA542744D696E67687561517552F279A8C84"));
  288. }
  289. }
  290. internal class C2tnb191v2Holder
  291. : X9ECParametersHolder
  292. {
  293. private C2tnb191v2Holder() {}
  294. internal static readonly X9ECParametersHolder Instance = new C2tnb191v2Holder();
  295. protected override X9ECParameters CreateParameters()
  296. {
  297. BigInteger n = new BigInteger("20000000000000000000000050508CB89F652824E06B8173", 16);
  298. BigInteger h = BigInteger.ValueOf(4);
  299. ECCurve c2m191v2 = new F2mCurve(
  300. 191,
  301. 9,
  302. new BigInteger("401028774D7777C7B7666D1366EA432071274F89FF01E718", 16),
  303. new BigInteger("0620048D28BCBD03B6249C99182B7C8CD19700C362C46A01", 16),
  304. n, h);
  305. return new X9ECParameters(
  306. c2m191v2,
  307. new X9ECPoint(c2m191v2,
  308. Hex.Decode("023809B2B7CC1B28CC5A87926AAD83FD28789E81E2C9E3BF10")),
  309. n, h,
  310. null);
  311. }
  312. }
  313. internal class C2tnb191v3Holder
  314. : X9ECParametersHolder
  315. {
  316. private C2tnb191v3Holder() {}
  317. internal static readonly X9ECParametersHolder Instance = new C2tnb191v3Holder();
  318. protected override X9ECParameters CreateParameters()
  319. {
  320. BigInteger n = new BigInteger("155555555555555555555555610C0B196812BFB6288A3EA3", 16);
  321. BigInteger h = BigInteger.ValueOf(6);
  322. ECCurve c2m191v3 = new F2mCurve(
  323. 191,
  324. 9,
  325. new BigInteger("6C01074756099122221056911C77D77E77A777E7E7E77FCB", 16),
  326. new BigInteger("71FE1AF926CF847989EFEF8DB459F66394D90F32AD3F15E8", 16),
  327. n, h);
  328. return new X9ECParameters(
  329. c2m191v3,
  330. new X9ECPoint(c2m191v3,
  331. Hex.Decode("03375D4CE24FDE434489DE8746E71786015009E66E38A926DD")),
  332. n, h,
  333. null);
  334. }
  335. }
  336. internal class C2pnb208w1Holder
  337. : X9ECParametersHolder
  338. {
  339. private C2pnb208w1Holder() {}
  340. internal static readonly X9ECParametersHolder Instance = new C2pnb208w1Holder();
  341. protected override X9ECParameters CreateParameters()
  342. {
  343. BigInteger n = new BigInteger("0101BAF95C9723C57B6C21DA2EFF2D5ED588BDD5717E212F9D", 16);
  344. BigInteger h = BigInteger.ValueOf(0xFE48);
  345. ECCurve c2m208w1 = new F2mCurve(
  346. 208,
  347. 1, 2, 83,
  348. new BigInteger("0", 16),
  349. new BigInteger("00C8619ED45A62E6212E1160349E2BFA844439FAFC2A3FD1638F9E", 16),
  350. n, h);
  351. return new X9ECParameters(
  352. c2m208w1,
  353. new X9ECPoint(c2m208w1,
  354. Hex.Decode("0289FDFBE4ABE193DF9559ECF07AC0CE78554E2784EB8C1ED1A57A")),
  355. n, h,
  356. null);
  357. }
  358. }
  359. internal class C2tnb239v1Holder
  360. : X9ECParametersHolder
  361. {
  362. private C2tnb239v1Holder() {}
  363. internal static readonly X9ECParametersHolder Instance = new C2tnb239v1Holder();
  364. protected override X9ECParameters CreateParameters()
  365. {
  366. BigInteger n = new BigInteger("2000000000000000000000000000000F4D42FFE1492A4993F1CAD666E447", 16);
  367. BigInteger h = BigInteger.ValueOf(4);
  368. ECCurve c2m239v1 = new F2mCurve(
  369. 239,
  370. 36,
  371. new BigInteger("32010857077C5431123A46B808906756F543423E8D27877578125778AC76", 16),
  372. new BigInteger("790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", 16),
  373. n, h);
  374. return new X9ECParameters(
  375. c2m239v1,
  376. new X9ECPoint(c2m239v1,
  377. Hex.Decode("0257927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D")),
  378. n, h,
  379. null);
  380. }
  381. }
  382. internal class C2tnb239v2Holder
  383. : X9ECParametersHolder
  384. {
  385. private C2tnb239v2Holder() {}
  386. internal static readonly X9ECParametersHolder Instance = new C2tnb239v2Holder();
  387. protected override X9ECParameters CreateParameters()
  388. {
  389. BigInteger n = new BigInteger("1555555555555555555555555555553C6F2885259C31E3FCDF154624522D", 16);
  390. BigInteger h = BigInteger.ValueOf(6);
  391. ECCurve c2m239v2 = new F2mCurve(
  392. 239,
  393. 36,
  394. new BigInteger("4230017757A767FAE42398569B746325D45313AF0766266479B75654E65F", 16),
  395. new BigInteger("5037EA654196CFF0CD82B2C14A2FCF2E3FF8775285B545722F03EACDB74B", 16),
  396. n, h);
  397. return new X9ECParameters(
  398. c2m239v2,
  399. new X9ECPoint(c2m239v2,
  400. Hex.Decode("0228F9D04E900069C8DC47A08534FE76D2B900B7D7EF31F5709F200C4CA205")),
  401. n, h,
  402. null);
  403. }
  404. }
  405. internal class C2tnb239v3Holder
  406. : X9ECParametersHolder
  407. {
  408. private C2tnb239v3Holder() {}
  409. internal static readonly X9ECParametersHolder Instance = new C2tnb239v3Holder();
  410. protected override X9ECParameters CreateParameters()
  411. {
  412. BigInteger n = new BigInteger("0CCCCCCCCCCCCCCCCCCCCCCCCCCCCCAC4912D2D9DF903EF9888B8A0E4CFF", 16);
  413. BigInteger h = BigInteger.ValueOf(10);
  414. ECCurve c2m239v3 = new F2mCurve(
  415. 239,
  416. 36,
  417. new BigInteger("01238774666A67766D6676F778E676B66999176666E687666D8766C66A9F", 16),
  418. new BigInteger("6A941977BA9F6A435199ACFC51067ED587F519C5ECB541B8E44111DE1D40", 16),
  419. n, h);
  420. return new X9ECParameters(
  421. c2m239v3,
  422. new X9ECPoint(c2m239v3,
  423. Hex.Decode("0370F6E9D04D289C4E89913CE3530BFDE903977D42B146D539BF1BDE4E9C92")),
  424. n, h,
  425. null);
  426. }
  427. }
  428. internal class C2pnb272w1Holder
  429. : X9ECParametersHolder
  430. {
  431. private C2pnb272w1Holder() {}
  432. internal static readonly X9ECParametersHolder Instance = new C2pnb272w1Holder();
  433. protected override X9ECParameters CreateParameters()
  434. {
  435. BigInteger n = new BigInteger("0100FAF51354E0E39E4892DF6E319C72C8161603FA45AA7B998A167B8F1E629521", 16);
  436. BigInteger h = BigInteger.ValueOf(0xFF06);
  437. ECCurve c2m272w1 = new F2mCurve(
  438. 272,
  439. 1, 3, 56,
  440. new BigInteger("0091A091F03B5FBA4AB2CCF49C4EDD220FB028712D42BE752B2C40094DBACDB586FB20", 16),
  441. new BigInteger("7167EFC92BB2E3CE7C8AAAFF34E12A9C557003D7C73A6FAF003F99F6CC8482E540F7", 16),
  442. n, h);
  443. return new X9ECParameters(
  444. c2m272w1,
  445. new X9ECPoint(c2m272w1,
  446. Hex.Decode("026108BABB2CEEBCF787058A056CBE0CFE622D7723A289E08A07AE13EF0D10D171DD8D")),
  447. n, h,
  448. null);
  449. }
  450. }
  451. internal class C2pnb304w1Holder
  452. : X9ECParametersHolder
  453. {
  454. private C2pnb304w1Holder() {}
  455. internal static readonly X9ECParametersHolder Instance = new C2pnb304w1Holder();
  456. protected override X9ECParameters CreateParameters()
  457. {
  458. BigInteger n = new BigInteger("0101D556572AABAC800101D556572AABAC8001022D5C91DD173F8FB561DA6899164443051D", 16);
  459. BigInteger h = BigInteger.ValueOf(0xFE2E);
  460. ECCurve c2m304w1 = new F2mCurve(
  461. 304,
  462. 1, 2, 11,
  463. new BigInteger("00FD0D693149A118F651E6DCE6802085377E5F882D1B510B44160074C1288078365A0396C8E681", 16),
  464. new BigInteger("00BDDB97E555A50A908E43B01C798EA5DAA6788F1EA2794EFCF57166B8C14039601E55827340BE", 16),
  465. n, h);
  466. return new X9ECParameters(
  467. c2m304w1,
  468. new X9ECPoint(c2m304w1,
  469. Hex.Decode("02197B07845E9BE2D96ADB0F5F3C7F2CFFBD7A3EB8B6FEC35C7FD67F26DDF6285A644F740A2614")),
  470. n, h,
  471. null);
  472. }
  473. }
  474. internal class C2tnb359v1Holder
  475. : X9ECParametersHolder
  476. {
  477. private C2tnb359v1Holder() {}
  478. internal static readonly X9ECParametersHolder Instance = new C2tnb359v1Holder();
  479. protected override X9ECParameters CreateParameters()
  480. {
  481. BigInteger n = new BigInteger("01AF286BCA1AF286BCA1AF286BCA1AF286BCA1AF286BC9FB8F6B85C556892C20A7EB964FE7719E74F490758D3B", 16);
  482. BigInteger h = BigInteger.ValueOf(0x4C);
  483. ECCurve c2m359v1 = new F2mCurve(
  484. 359,
  485. 68,
  486. new BigInteger("5667676A654B20754F356EA92017D946567C46675556F19556A04616B567D223A5E05656FB549016A96656A557", 16),
  487. new BigInteger("2472E2D0197C49363F1FE7F5B6DB075D52B6947D135D8CA445805D39BC345626089687742B6329E70680231988", 16),
  488. n, h);
  489. return new X9ECParameters(
  490. c2m359v1,
  491. new X9ECPoint(c2m359v1,
  492. Hex.Decode("033C258EF3047767E7EDE0F1FDAA79DAEE3841366A132E163ACED4ED2401DF9C6BDCDE98E8E707C07A2239B1B097")),
  493. n, h,
  494. null);
  495. }
  496. }
  497. internal class C2pnb368w1Holder
  498. : X9ECParametersHolder
  499. {
  500. private C2pnb368w1Holder() {}
  501. internal static readonly X9ECParametersHolder Instance = new C2pnb368w1Holder();
  502. protected override X9ECParameters CreateParameters()
  503. {
  504. BigInteger n = new BigInteger("010090512DA9AF72B08349D98A5DD4C7B0532ECA51CE03E2D10F3B7AC579BD87E909AE40A6F131E9CFCE5BD967", 16);
  505. BigInteger h = BigInteger.ValueOf(0xFF70);
  506. ECCurve c2m368w1 = new F2mCurve(
  507. 368,
  508. 1, 2, 85,
  509. new BigInteger("00E0D2EE25095206F5E2A4F9ED229F1F256E79A0E2B455970D8D0D865BD94778C576D62F0AB7519CCD2A1A906AE30D", 16),
  510. new BigInteger("00FC1217D4320A90452C760A58EDCD30C8DD069B3C34453837A34ED50CB54917E1C2112D84D164F444F8F74786046A", 16),
  511. n, h);
  512. return new X9ECParameters(
  513. c2m368w1,
  514. new X9ECPoint(c2m368w1,
  515. Hex.Decode("021085E2755381DCCCE3C1557AFA10C2F0C0C2825646C5B34A394CBCFA8BC16B22E7E789E927BE216F02E1FB136A5F")),
  516. n, h,
  517. null);
  518. }
  519. }
  520. internal class C2tnb431r1Holder
  521. : X9ECParametersHolder
  522. {
  523. private C2tnb431r1Holder() {}
  524. internal static readonly X9ECParametersHolder Instance = new C2tnb431r1Holder();
  525. protected override X9ECParameters CreateParameters()
  526. {
  527. BigInteger n = new BigInteger("0340340340340340340340340340340340340340340340340340340323C313FAB50589703B5EC68D3587FEC60D161CC149C1AD4A91", 16);
  528. BigInteger h = BigInteger.ValueOf(0x2760);
  529. ECCurve c2m431r1 = new F2mCurve(
  530. 431,
  531. 120,
  532. new BigInteger("1A827EF00DD6FC0E234CAF046C6A5D8A85395B236CC4AD2CF32A0CADBDC9DDF620B0EB9906D0957F6C6FEACD615468DF104DE296CD8F", 16),
  533. new BigInteger("10D9B4A3D9047D8B154359ABFB1B7F5485B04CEB868237DDC9DEDA982A679A5A919B626D4E50A8DD731B107A9962381FB5D807BF2618", 16),
  534. n, h);
  535. return new X9ECParameters(
  536. c2m431r1,
  537. new X9ECPoint(c2m431r1,
  538. Hex.Decode("02120FC05D3C67A99DE161D2F4092622FECA701BE4F50F4758714E8A87BBF2A658EF8C21E7C5EFE965361F6C2999C0C247B0DBD70CE6B7")),
  539. n, h,
  540. null);
  541. }
  542. }
  543. private static readonly IDictionary objIds = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  544. private static readonly IDictionary curves = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  545. private static readonly IDictionary names = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  546. private static void DefineCurve(
  547. string name,
  548. DerObjectIdentifier oid,
  549. X9ECParametersHolder holder)
  550. {
  551. objIds.Add(Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name), oid);
  552. names.Add(oid, name);
  553. curves.Add(oid, holder);
  554. }
  555. static X962NamedCurves()
  556. {
  557. DefineCurve("prime192v1", X9ObjectIdentifiers.Prime192v1, Prime192v1Holder.Instance);
  558. DefineCurve("prime192v2", X9ObjectIdentifiers.Prime192v2, Prime192v2Holder.Instance);
  559. DefineCurve("prime192v3", X9ObjectIdentifiers.Prime192v3, Prime192v3Holder.Instance);
  560. DefineCurve("prime239v1", X9ObjectIdentifiers.Prime239v1, Prime239v1Holder.Instance);
  561. DefineCurve("prime239v2", X9ObjectIdentifiers.Prime239v2, Prime239v2Holder.Instance);
  562. DefineCurve("prime239v3", X9ObjectIdentifiers.Prime239v3, Prime239v3Holder.Instance);
  563. DefineCurve("prime256v1", X9ObjectIdentifiers.Prime256v1, Prime256v1Holder.Instance);
  564. DefineCurve("c2pnb163v1", X9ObjectIdentifiers.C2Pnb163v1, C2pnb163v1Holder.Instance);
  565. DefineCurve("c2pnb163v2", X9ObjectIdentifiers.C2Pnb163v2, C2pnb163v2Holder.Instance);
  566. DefineCurve("c2pnb163v3", X9ObjectIdentifiers.C2Pnb163v3, C2pnb163v3Holder.Instance);
  567. DefineCurve("c2pnb176w1", X9ObjectIdentifiers.C2Pnb176w1, C2pnb176w1Holder.Instance);
  568. DefineCurve("c2tnb191v1", X9ObjectIdentifiers.C2Tnb191v1, C2tnb191v1Holder.Instance);
  569. DefineCurve("c2tnb191v2", X9ObjectIdentifiers.C2Tnb191v2, C2tnb191v2Holder.Instance);
  570. DefineCurve("c2tnb191v3", X9ObjectIdentifiers.C2Tnb191v3, C2tnb191v3Holder.Instance);
  571. DefineCurve("c2pnb208w1", X9ObjectIdentifiers.C2Pnb208w1, C2pnb208w1Holder.Instance);
  572. DefineCurve("c2tnb239v1", X9ObjectIdentifiers.C2Tnb239v1, C2tnb239v1Holder.Instance);
  573. DefineCurve("c2tnb239v2", X9ObjectIdentifiers.C2Tnb239v2, C2tnb239v2Holder.Instance);
  574. DefineCurve("c2tnb239v3", X9ObjectIdentifiers.C2Tnb239v3, C2tnb239v3Holder.Instance);
  575. DefineCurve("c2pnb272w1", X9ObjectIdentifiers.C2Pnb272w1, C2pnb272w1Holder.Instance);
  576. DefineCurve("c2pnb304w1", X9ObjectIdentifiers.C2Pnb304w1, C2pnb304w1Holder.Instance);
  577. DefineCurve("c2tnb359v1", X9ObjectIdentifiers.C2Tnb359v1, C2tnb359v1Holder.Instance);
  578. DefineCurve("c2pnb368w1", X9ObjectIdentifiers.C2Pnb368w1, C2pnb368w1Holder.Instance);
  579. DefineCurve("c2tnb431r1", X9ObjectIdentifiers.C2Tnb431r1, C2tnb431r1Holder.Instance);
  580. }
  581. public static X9ECParameters GetByName(
  582. string name)
  583. {
  584. DerObjectIdentifier oid = GetOid(name);
  585. return oid == null ? null : GetByOid(oid);
  586. }
  587. /**
  588. * return the X9ECParameters object for the named curve represented by
  589. * the passed in object identifier. Null if the curve isn't present.
  590. *
  591. * @param oid an object identifier representing a named curve, if present.
  592. */
  593. public static X9ECParameters GetByOid(
  594. DerObjectIdentifier oid)
  595. {
  596. X9ECParametersHolder holder = (X9ECParametersHolder)curves[oid];
  597. return holder == null ? null : holder.Parameters;
  598. }
  599. /**
  600. * return the object identifier signified by the passed in name. Null
  601. * if there is no object identifier associated with name.
  602. *
  603. * @return the object identifier associated with name, if present.
  604. */
  605. public static DerObjectIdentifier GetOid(
  606. string name)
  607. {
  608. return (DerObjectIdentifier)objIds[Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name)];
  609. }
  610. /**
  611. * return the named curve name represented by the given object identifier.
  612. */
  613. public static string GetName(
  614. DerObjectIdentifier oid)
  615. {
  616. return (string)names[oid];
  617. }
  618. /**
  619. * returns an enumeration containing the name strings for curves
  620. * contained in this structure.
  621. */
  622. public static IEnumerable Names
  623. {
  624. get { return new EnumerableProxy(names.Values); }
  625. }
  626. }
  627. }
  628. #endif