TeleTrusTNamedCurves.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System.Collections;
  3. using Org.BouncyCastle.Asn1.X9;
  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.TeleTrust
  10. {
  11. /**
  12. * elliptic curves defined in "ECC Brainpool Standard Curves and Curve Generation"
  13. * http://www.ecc-brainpool.org/download/draft_pkix_additional_ecc_dp.txt
  14. */
  15. public class TeleTrusTNamedCurves
  16. {
  17. private static ECCurve ConfigureCurve(ECCurve curve)
  18. {
  19. return curve;
  20. }
  21. internal class BrainpoolP160r1Holder
  22. : X9ECParametersHolder
  23. {
  24. private BrainpoolP160r1Holder() {}
  25. internal static readonly X9ECParametersHolder Instance = new BrainpoolP160r1Holder();
  26. protected override X9ECParameters CreateParameters()
  27. {
  28. BigInteger n = new BigInteger("E95E4A5F737059DC60DF5991D45029409E60FC09", 16);
  29. BigInteger h = new BigInteger("01", 16);
  30. ECCurve curve = ConfigureCurve(new FpCurve(
  31. new BigInteger("E95E4A5F737059DC60DFC7AD95B3D8139515620F", 16), // q
  32. new BigInteger("340E7BE2A280EB74E2BE61BADA745D97E8F7C300", 16), // a
  33. new BigInteger("1E589A8595423412134FAA2DBDEC95C8D8675E58", 16), // b
  34. n, h));
  35. return new X9ECParameters(
  36. curve,
  37. new X9ECPoint(curve, Hex.Decode("04BED5AF16EA3F6A4F62938C4631EB5AF7BDBCDBC31667CB477A1A8EC338F94741669C976316DA6321")), // G
  38. n, h);
  39. }
  40. }
  41. internal class BrainpoolP160t1Holder
  42. : X9ECParametersHolder
  43. {
  44. private BrainpoolP160t1Holder() {}
  45. internal static readonly X9ECParametersHolder Instance = new BrainpoolP160t1Holder();
  46. protected override X9ECParameters CreateParameters()
  47. {
  48. BigInteger n = new BigInteger("E95E4A5F737059DC60DF5991D45029409E60FC09", 16);
  49. BigInteger h = new BigInteger("01", 16);
  50. ECCurve curve = ConfigureCurve(new FpCurve(
  51. // new BigInteger("24DBFF5DEC9B986BBFE5295A29BFBAE45E0F5D0B", 16), // Z
  52. new BigInteger("E95E4A5F737059DC60DFC7AD95B3D8139515620F", 16), // q
  53. new BigInteger("E95E4A5F737059DC60DFC7AD95B3D8139515620C", 16), // a'
  54. new BigInteger("7A556B6DAE535B7B51ED2C4D7DAA7A0B5C55F380", 16), // b'
  55. n, h));
  56. return new X9ECParameters(
  57. curve,
  58. new X9ECPoint(curve, Hex.Decode("04B199B13B9B34EFC1397E64BAEB05ACC265FF2378ADD6718B7C7C1961F0991B842443772152C9E0AD")), // G
  59. n, h);
  60. }
  61. }
  62. internal class BrainpoolP192r1Holder
  63. : X9ECParametersHolder
  64. {
  65. private BrainpoolP192r1Holder() {}
  66. internal static readonly X9ECParametersHolder Instance = new BrainpoolP192r1Holder();
  67. protected override X9ECParameters CreateParameters()
  68. {
  69. BigInteger n = new BigInteger("C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1", 16);
  70. BigInteger h = new BigInteger("01", 16);
  71. ECCurve curve = ConfigureCurve(new FpCurve(
  72. new BigInteger("C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297", 16), // q
  73. new BigInteger("6A91174076B1E0E19C39C031FE8685C1CAE040E5C69A28EF", 16), // a
  74. new BigInteger("469A28EF7C28CCA3DC721D044F4496BCCA7EF4146FBF25C9", 16), // b
  75. n, h));
  76. return new X9ECParameters(
  77. curve,
  78. new X9ECPoint(curve, Hex.Decode("04C0A0647EAAB6A48753B033C56CB0F0900A2F5C4853375FD614B690866ABD5BB88B5F4828C1490002E6773FA2FA299B8F")), // G
  79. n, h);
  80. }
  81. }
  82. internal class BrainpoolP192t1Holder
  83. : X9ECParametersHolder
  84. {
  85. private BrainpoolP192t1Holder() {}
  86. internal static readonly X9ECParametersHolder Instance = new BrainpoolP192t1Holder();
  87. protected override X9ECParameters CreateParameters()
  88. {
  89. BigInteger n = new BigInteger("C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1", 16);
  90. BigInteger h = new BigInteger("01", 16);
  91. ECCurve curve = ConfigureCurve(new FpCurve(
  92. //new BigInteger("1B6F5CC8DB4DC7AF19458A9CB80DC2295E5EB9C3732104CB") //Z
  93. new BigInteger("C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297", 16), // q
  94. new BigInteger("C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86294", 16), // a'
  95. new BigInteger("13D56FFAEC78681E68F9DEB43B35BEC2FB68542E27897B79", 16), // b'
  96. n, h));
  97. return new X9ECParameters(
  98. curve,
  99. new X9ECPoint(curve, Hex.Decode("043AE9E58C82F63C30282E1FE7BBF43FA72C446AF6F4618129097E2C5667C2223A902AB5CA449D0084B7E5B3DE7CCC01C9")), // G'
  100. n, h);
  101. }
  102. }
  103. internal class BrainpoolP224r1Holder
  104. : X9ECParametersHolder
  105. {
  106. private BrainpoolP224r1Holder() {}
  107. internal static readonly X9ECParametersHolder Instance = new BrainpoolP224r1Holder();
  108. protected override X9ECParameters CreateParameters()
  109. {
  110. BigInteger n = new BigInteger("D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F", 16);
  111. BigInteger h = new BigInteger("01", 16);
  112. ECCurve curve = ConfigureCurve(new FpCurve(
  113. new BigInteger("D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF", 16), // q
  114. new BigInteger("68A5E62CA9CE6C1C299803A6C1530B514E182AD8B0042A59CAD29F43", 16), // a
  115. new BigInteger("2580F63CCFE44138870713B1A92369E33E2135D266DBB372386C400B", 16), // b
  116. n, h));
  117. return new X9ECParameters(
  118. curve,
  119. new X9ECPoint(curve, Hex.Decode("040D9029AD2C7E5CF4340823B2A87DC68C9E4CE3174C1E6EFDEE12C07D58AA56F772C0726F24C6B89E4ECDAC24354B9E99CAA3F6D3761402CD")), // G
  120. n, h);
  121. }
  122. }
  123. internal class BrainpoolP224t1Holder
  124. : X9ECParametersHolder
  125. {
  126. private BrainpoolP224t1Holder() {}
  127. internal static readonly X9ECParametersHolder Instance = new BrainpoolP224t1Holder();
  128. protected override X9ECParameters CreateParameters()
  129. {
  130. BigInteger n = new BigInteger("D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F", 16);
  131. BigInteger h = new BigInteger("01", 16);
  132. ECCurve curve = ConfigureCurve(new FpCurve(
  133. //new BigInteger("2DF271E14427A346910CF7A2E6CFA7B3F484E5C2CCE1C8B730E28B3F") //Z
  134. new BigInteger("D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF", 16), // q
  135. new BigInteger("D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FC", 16), // a'
  136. new BigInteger("4B337D934104CD7BEF271BF60CED1ED20DA14C08B3BB64F18A60888D", 16), // b'
  137. n, h));
  138. return new X9ECParameters(
  139. curve,
  140. new X9ECPoint(curve, Hex.Decode("046AB1E344CE25FF3896424E7FFE14762ECB49F8928AC0C76029B4D5800374E9F5143E568CD23F3F4D7C0D4B1E41C8CC0D1C6ABD5F1A46DB4C")), // G'
  141. n, h);
  142. }
  143. }
  144. internal class BrainpoolP256r1Holder
  145. : X9ECParametersHolder
  146. {
  147. private BrainpoolP256r1Holder() {}
  148. internal static readonly X9ECParametersHolder Instance = new BrainpoolP256r1Holder();
  149. protected override X9ECParameters CreateParameters()
  150. {
  151. BigInteger n = new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", 16);
  152. BigInteger h = new BigInteger("01", 16);
  153. ECCurve curve = ConfigureCurve(new FpCurve(
  154. new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", 16), // q
  155. new BigInteger("7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", 16), // a
  156. new BigInteger("26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", 16), // b
  157. n, h));
  158. return new X9ECParameters(
  159. curve,
  160. new X9ECPoint(curve, Hex.Decode("048BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997")), // G
  161. n, h);
  162. }
  163. }
  164. internal class BrainpoolP256t1Holder
  165. : X9ECParametersHolder
  166. {
  167. private BrainpoolP256t1Holder() {}
  168. internal static readonly X9ECParametersHolder Instance = new BrainpoolP256t1Holder();
  169. protected override X9ECParameters CreateParameters()
  170. {
  171. BigInteger n = new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", 16);
  172. BigInteger h = new BigInteger("01", 16);
  173. ECCurve curve = ConfigureCurve(new FpCurve(
  174. //new BigInteger("3E2D4BD9597B58639AE7AA669CAB9837CF5CF20A2C852D10F655668DFC150EF0") //Z
  175. new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", 16), // q
  176. new BigInteger("A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5374", 16), // a'
  177. new BigInteger("662C61C430D84EA4FE66A7733D0B76B7BF93EBC4AF2F49256AE58101FEE92B04", 16), // b'
  178. n, h));
  179. return new X9ECParameters(
  180. curve,
  181. new X9ECPoint(curve, Hex.Decode("04A3E8EB3CC1CFE7B7732213B23A656149AFA142C47AAFBC2B79A191562E1305F42D996C823439C56D7F7B22E14644417E69BCB6DE39D027001DABE8F35B25C9BE")), // G'
  182. n, h);
  183. }
  184. }
  185. internal class BrainpoolP320r1Holder
  186. : X9ECParametersHolder
  187. {
  188. private BrainpoolP320r1Holder() {}
  189. internal static readonly X9ECParametersHolder Instance = new BrainpoolP320r1Holder();
  190. protected override X9ECParameters CreateParameters()
  191. {
  192. BigInteger n = new BigInteger("D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D482EC7EE8658E98691555B44C59311", 16);
  193. BigInteger h = new BigInteger("01", 16);
  194. ECCurve curve = ConfigureCurve(new FpCurve(
  195. new BigInteger("D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E27", 16), // q
  196. new BigInteger("3EE30B568FBAB0F883CCEBD46D3F3BB8A2A73513F5EB79DA66190EB085FFA9F492F375A97D860EB4", 16), // a
  197. new BigInteger("520883949DFDBC42D3AD198640688A6FE13F41349554B49ACC31DCCD884539816F5EB4AC8FB1F1A6", 16), // b
  198. n, h));
  199. return new X9ECParameters(
  200. curve,
  201. new X9ECPoint(curve, Hex.Decode("0443BD7E9AFB53D8B85289BCC48EE5BFE6F20137D10A087EB6E7871E2A10A599C710AF8D0D39E2061114FDD05545EC1CC8AB4093247F77275E0743FFED117182EAA9C77877AAAC6AC7D35245D1692E8EE1")), // G
  202. n, h);
  203. }
  204. }
  205. internal class BrainpoolP320t1Holder
  206. : X9ECParametersHolder
  207. {
  208. private BrainpoolP320t1Holder() {}
  209. internal static readonly X9ECParametersHolder Instance = new BrainpoolP320t1Holder();
  210. protected override X9ECParameters CreateParameters()
  211. {
  212. BigInteger n = new BigInteger("D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D482EC7EE8658E98691555B44C59311", 16);
  213. BigInteger h = new BigInteger("01", 16);
  214. ECCurve curve = ConfigureCurve(new FpCurve(
  215. //new BigInteger("15F75CAF668077F7E85B42EB01F0A81FF56ECD6191D55CB82B7D861458A18FEFC3E5AB7496F3C7B1") //Z
  216. new BigInteger("D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E27", 16), // q
  217. new BigInteger("D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E24", 16), // a'
  218. new BigInteger("A7F561E038EB1ED560B3D147DB782013064C19F27ED27C6780AAF77FB8A547CEB5B4FEF422340353", 16), // b'
  219. n, h));
  220. return new X9ECParameters(
  221. curve,
  222. new X9ECPoint(curve, Hex.Decode("04925BE9FB01AFC6FB4D3E7D4990010F813408AB106C4F09CB7EE07868CC136FFF3357F624A21BED5263BA3A7A27483EBF6671DBEF7ABB30EBEE084E58A0B077AD42A5A0989D1EE71B1B9BC0455FB0D2C3")), // G'
  223. n, h);
  224. }
  225. }
  226. internal class BrainpoolP384r1Holder
  227. : X9ECParametersHolder
  228. {
  229. private BrainpoolP384r1Holder() {}
  230. internal static readonly X9ECParametersHolder Instance = new BrainpoolP384r1Holder();
  231. protected override X9ECParameters CreateParameters()
  232. {
  233. BigInteger n = new BigInteger("8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC3103B883202E9046565", 16);
  234. BigInteger h = new BigInteger("01", 16);
  235. ECCurve curve = ConfigureCurve(new FpCurve(
  236. new BigInteger("8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53", 16), // q
  237. new BigInteger("7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F90F8AA5814A503AD4EB04A8C7DD22CE2826", 16), // a
  238. new BigInteger("4A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62D57CB4390295DBC9943AB78696FA504C11", 16), // b
  239. n, h));
  240. return new X9ECParameters(
  241. curve,
  242. new X9ECPoint(curve, Hex.Decode("041D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10E8E826E03436D646AAEF87B2E247D4AF1E8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF99129280E4646217791811142820341263C5315")), // G
  243. n, h);
  244. }
  245. }
  246. internal class BrainpoolP384t1Holder
  247. : X9ECParametersHolder
  248. {
  249. private BrainpoolP384t1Holder() {}
  250. internal static readonly X9ECParametersHolder Instance = new BrainpoolP384t1Holder();
  251. protected override X9ECParameters CreateParameters()
  252. {
  253. BigInteger n = new BigInteger("8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC3103B883202E9046565", 16);
  254. BigInteger h = new BigInteger("01", 16);
  255. ECCurve curve = ConfigureCurve(new FpCurve(
  256. //new BigInteger("41DFE8DD399331F7166A66076734A89CD0D2BCDB7D068E44E1F378F41ECBAE97D2D63DBC87BCCDDCCC5DA39E8589291C") //Z
  257. new BigInteger("8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53", 16), // q
  258. new BigInteger("8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC50", 16), // a'
  259. new BigInteger("7F519EADA7BDA81BD826DBA647910F8C4B9346ED8CCDC64E4B1ABD11756DCE1D2074AA263B88805CED70355A33B471EE", 16), // b'
  260. n, h));
  261. return new X9ECParameters(
  262. curve,
  263. new X9ECPoint(curve, Hex.Decode("0418DE98B02DB9A306F2AFCD7235F72A819B80AB12EBD653172476FECD462AABFFC4FF191B946A5F54D8D0AA2F418808CC25AB056962D30651A114AFD2755AD336747F93475B7A1FCA3B88F2B6A208CCFE469408584DC2B2912675BF5B9E582928")), // G'
  264. n, h);
  265. }
  266. }
  267. internal class BrainpoolP512r1Holder
  268. : X9ECParametersHolder
  269. {
  270. private BrainpoolP512r1Holder() {}
  271. internal static readonly X9ECParametersHolder Instance = new BrainpoolP512r1Holder();
  272. protected override X9ECParameters CreateParameters()
  273. {
  274. BigInteger n = new BigInteger("AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069", 16);
  275. BigInteger h = new BigInteger("01", 16);
  276. ECCurve curve = ConfigureCurve(new FpCurve(
  277. new BigInteger("AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3", 16), // q
  278. new BigInteger("7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA", 16), // a
  279. new BigInteger("3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723", 16), // b
  280. n, h));
  281. return new X9ECParameters(
  282. curve,
  283. new X9ECPoint(curve, Hex.Decode("0481AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D0098EFF3B1F78E2D0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F8227DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F8111B2DCDE494A5F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892")), // G
  284. n, h);
  285. }
  286. }
  287. internal class BrainpoolP512t1Holder
  288. : X9ECParametersHolder
  289. {
  290. private BrainpoolP512t1Holder() {}
  291. internal static readonly X9ECParametersHolder Instance = new BrainpoolP512t1Holder();
  292. protected override X9ECParameters CreateParameters()
  293. {
  294. BigInteger n = new BigInteger("AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069", 16);
  295. BigInteger h = new BigInteger("01", 16);
  296. ECCurve curve = ConfigureCurve(new FpCurve(
  297. //new BigInteger("12EE58E6764838B69782136F0F2D3BA06E27695716054092E60A80BEDB212B64E585D90BCE13761F85C3F1D2A64E3BE8FEA2220F01EBA5EEB0F35DBD29D922AB") //Z
  298. new BigInteger("AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3", 16), // q
  299. new BigInteger("AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F0", 16), // a'
  300. new BigInteger("7CBBBCF9441CFAB76E1890E46884EAE321F70C0BCB4981527897504BEC3E36A62BCDFA2304976540F6450085F2DAE145C22553B465763689180EA2571867423E", 16), // b'
  301. n, h));
  302. return new X9ECParameters(
  303. curve,
  304. new X9ECPoint(curve, Hex.Decode("04640ECE5C12788717B9C1BA06CBC2A6FEBA85842458C56DDE9DB1758D39C0313D82BA51735CDB3EA499AA77A7D6943A64F7A3F25FE26F06B51BAA2696FA9035DA5B534BD595F5AF0FA2C892376C84ACE1BB4E3019B71634C01131159CAE03CEE9D9932184BEEF216BD71DF2DADF86A627306ECFF96DBB8BACE198B61E00F8B332")), // G'
  305. n, h);
  306. }
  307. }
  308. private static readonly IDictionary objIds = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  309. private static readonly IDictionary curves = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  310. private static readonly IDictionary names = Org.BouncyCastle.Utilities.Platform.CreateHashtable();
  311. private static void DefineCurve(
  312. string name,
  313. DerObjectIdentifier oid,
  314. X9ECParametersHolder holder)
  315. {
  316. objIds.Add(Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name), oid);
  317. names.Add(oid, name);
  318. curves.Add(oid, holder);
  319. }
  320. static TeleTrusTNamedCurves()
  321. {
  322. DefineCurve("brainpoolP160r1", TeleTrusTObjectIdentifiers.BrainpoolP160R1, BrainpoolP160r1Holder.Instance);
  323. DefineCurve("brainpoolP160t1", TeleTrusTObjectIdentifiers.BrainpoolP160T1, BrainpoolP160t1Holder.Instance);
  324. DefineCurve("brainpoolP192r1", TeleTrusTObjectIdentifiers.BrainpoolP192R1, BrainpoolP192r1Holder.Instance);
  325. DefineCurve("brainpoolP192t1", TeleTrusTObjectIdentifiers.BrainpoolP192T1, BrainpoolP192t1Holder.Instance);
  326. DefineCurve("brainpoolP224r1", TeleTrusTObjectIdentifiers.BrainpoolP224R1, BrainpoolP224r1Holder.Instance);
  327. DefineCurve("brainpoolP224t1", TeleTrusTObjectIdentifiers.BrainpoolP224T1, BrainpoolP224t1Holder.Instance);
  328. DefineCurve("brainpoolP256r1", TeleTrusTObjectIdentifiers.BrainpoolP256R1, BrainpoolP256r1Holder.Instance);
  329. DefineCurve("brainpoolP256t1", TeleTrusTObjectIdentifiers.BrainpoolP256T1, BrainpoolP256t1Holder.Instance);
  330. DefineCurve("brainpoolP320r1", TeleTrusTObjectIdentifiers.BrainpoolP320R1, BrainpoolP320r1Holder.Instance);
  331. DefineCurve("brainpoolP320t1", TeleTrusTObjectIdentifiers.BrainpoolP320T1, BrainpoolP320t1Holder.Instance);
  332. DefineCurve("brainpoolP384r1", TeleTrusTObjectIdentifiers.BrainpoolP384R1, BrainpoolP384r1Holder.Instance);
  333. DefineCurve("brainpoolP384t1", TeleTrusTObjectIdentifiers.BrainpoolP384T1, BrainpoolP384t1Holder.Instance);
  334. DefineCurve("brainpoolP512r1", TeleTrusTObjectIdentifiers.BrainpoolP512R1, BrainpoolP512r1Holder.Instance);
  335. DefineCurve("brainpoolP512t1", TeleTrusTObjectIdentifiers.BrainpoolP512T1, BrainpoolP512t1Holder.Instance);
  336. }
  337. public static X9ECParameters GetByName(
  338. string name)
  339. {
  340. DerObjectIdentifier oid = GetOid(name);
  341. return oid == null ? null : GetByOid(oid);
  342. }
  343. /**
  344. * return the X9ECParameters object for the named curve represented by
  345. * the passed in object identifier. Null if the curve isn't present.
  346. *
  347. * @param oid an object identifier representing a named curve, if present.
  348. */
  349. public static X9ECParameters GetByOid(
  350. DerObjectIdentifier oid)
  351. {
  352. X9ECParametersHolder holder = (X9ECParametersHolder)curves[oid];
  353. return holder == null ? null : holder.Parameters;
  354. }
  355. /**
  356. * return the object identifier signified by the passed in name. Null
  357. * if there is no object identifier associated with name.
  358. *
  359. * @return the object identifier associated with name, if present.
  360. */
  361. public static DerObjectIdentifier GetOid(
  362. string name)
  363. {
  364. return (DerObjectIdentifier)objIds[Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(name)];
  365. }
  366. /**
  367. * return the named curve name represented by the given object identifier.
  368. */
  369. public static string GetName(
  370. DerObjectIdentifier oid)
  371. {
  372. return (string)names[oid];
  373. }
  374. /**
  375. * returns an enumeration containing the name strings for curves
  376. * contained in this structure.
  377. */
  378. public static IEnumerable Names
  379. {
  380. get { return new EnumerableProxy(names.Values); }
  381. }
  382. public static DerObjectIdentifier GetOid(
  383. short curvesize,
  384. bool twisted)
  385. {
  386. return GetOid("brainpoolP" + curvesize + (twisted ? "t" : "r") + "1");
  387. }
  388. }
  389. }
  390. #endif