1 package org.bouncycastle.crypto.ec; 2 3 import java.math.BigInteger; 4 import java.util.Enumeration; 5 import java.util.Hashtable; 6 import java.util.Vector; 7 8 import org.bouncycastle.asn1.ASN1ObjectIdentifier; 9 import org.bouncycastle.asn1.sec.SECObjectIdentifiers; 10 import org.bouncycastle.asn1.x9.X9ECParameters; 11 import org.bouncycastle.asn1.x9.X9ECParametersHolder; 12 import org.bouncycastle.asn1.x9.X9ECPoint; 13 import org.bouncycastle.math.ec.ECCurve; 14 import org.bouncycastle.math.ec.ECPoint; 15 // BEGIN android-removed 16 // import org.bouncycastle.math.ec.custom.djb.Curve25519; 17 // import org.bouncycastle.math.ec.custom.sec.SecP128R1Curve; 18 // import org.bouncycastle.math.ec.custom.sec.SecP160K1Curve; 19 // import org.bouncycastle.math.ec.custom.sec.SecP160R1Curve; 20 // import org.bouncycastle.math.ec.custom.sec.SecP160R2Curve; 21 // END android-removed 22 import org.bouncycastle.math.ec.custom.sec.SecP192K1Curve; 23 import org.bouncycastle.math.ec.custom.sec.SecP192R1Curve; 24 import org.bouncycastle.math.ec.custom.sec.SecP224K1Curve; 25 import org.bouncycastle.math.ec.custom.sec.SecP224R1Curve; 26 import org.bouncycastle.math.ec.custom.sec.SecP256K1Curve; 27 import org.bouncycastle.math.ec.custom.sec.SecP256R1Curve; 28 import org.bouncycastle.math.ec.custom.sec.SecP384R1Curve; 29 import org.bouncycastle.math.ec.custom.sec.SecP521R1Curve; 30 // BEGIN android-removed 31 // import org.bouncycastle.math.ec.custom.sec.SecT113R1Curve; 32 // import org.bouncycastle.math.ec.custom.sec.SecT113R2Curve; 33 // import org.bouncycastle.math.ec.custom.sec.SecT131R1Curve; 34 // import org.bouncycastle.math.ec.custom.sec.SecT131R2Curve; 35 // import org.bouncycastle.math.ec.custom.sec.SecT163K1Curve; 36 // import org.bouncycastle.math.ec.custom.sec.SecT163R1Curve; 37 // import org.bouncycastle.math.ec.custom.sec.SecT163R2Curve; 38 // import org.bouncycastle.math.ec.custom.sec.SecT193R1Curve; 39 // import org.bouncycastle.math.ec.custom.sec.SecT193R2Curve; 40 // import org.bouncycastle.math.ec.custom.sec.SecT233K1Curve; 41 // import org.bouncycastle.math.ec.custom.sec.SecT233R1Curve; 42 // import org.bouncycastle.math.ec.custom.sec.SecT239K1Curve; 43 // import org.bouncycastle.math.ec.custom.sec.SecT283K1Curve; 44 // import org.bouncycastle.math.ec.custom.sec.SecT283R1Curve; 45 // import org.bouncycastle.math.ec.custom.sec.SecT409K1Curve; 46 // import org.bouncycastle.math.ec.custom.sec.SecT409R1Curve; 47 // import org.bouncycastle.math.ec.custom.sec.SecT571K1Curve; 48 // import org.bouncycastle.math.ec.custom.sec.SecT571R1Curve; 49 // END android-removed 50 import org.bouncycastle.math.ec.endo.GLVTypeBEndomorphism; 51 import org.bouncycastle.math.ec.endo.GLVTypeBParameters; 52 import org.bouncycastle.util.Strings; 53 import org.bouncycastle.util.encoders.Hex; 54 55 public class CustomNamedCurves 56 { configureCurve(ECCurve curve)57 private static ECCurve configureCurve(ECCurve curve) 58 { 59 return curve; 60 } 61 configureCurveGLV(ECCurve c, GLVTypeBParameters p)62 private static ECCurve configureCurveGLV(ECCurve c, GLVTypeBParameters p) 63 { 64 return c.configure().setEndomorphism(new GLVTypeBEndomorphism(c, p)).create(); 65 } 66 67 // BEGIN android-removed 68 // /* 69 // * curve25519 70 // */ 71 // static X9ECParametersHolder curve25519 = new X9ECParametersHolder() 72 // { 73 // protected X9ECParameters createParameters() 74 // { 75 // byte[] S = null; 76 // ECCurve curve = configureCurve(new Curve25519()); 77 // 78 // /* 79 // * NOTE: Curve25519 was specified in Montgomery form. Rewriting in Weierstrass form 80 // * involves substitution of variables, so the base-point x coordinate is 9 + (486662 / 3). 81 // * 82 // * The Curve25519 paper doesn't say which of the two possible y values the base 83 // * point has. The choice here is guided by language in the Ed25519 paper. 84 // * 85 // * (The other possible y value is 5F51E65E475F794B1FE122D388B72EB36DC2B28192839E4DD6163A5D81312C14) 86 // */ 87 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 88 // + "2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD245A" 89 // + "20AE19A1B8A086B4E01EDD2C7748D14C923D4D7E6D7C61B229E9C5A27ECED3D9")); 90 // 91 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 92 // } 93 // }; 94 // 95 // /* 96 // * secp128r1 97 // */ 98 // static X9ECParametersHolder secp128r1 = new X9ECParametersHolder() 99 // { 100 // protected X9ECParameters createParameters() 101 // { 102 // byte[] S = Hex.decode("000E0D4D696E6768756151750CC03A4473D03679"); 103 // ECCurve curve = configureCurve(new SecP128R1Curve()); 104 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 105 // + "161FF7528B899B2D0C28607CA52C5B86" 106 // + "CF5AC8395BAFEB13C02DA292DDED7A83")); 107 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 108 // } 109 // }; 110 // 111 // /* 112 // * secp160k1 113 // */ 114 // static X9ECParametersHolder secp160k1 = new X9ECParametersHolder() 115 // { 116 // protected X9ECParameters createParameters() 117 // { 118 // byte[] S = null; 119 // GLVTypeBParameters glv = new GLVTypeBParameters( 120 // new BigInteger("9ba48cba5ebcb9b6bd33b92830b2a2e0e192f10a", 16), 121 // new BigInteger("c39c6c3b3a36d7701b9c71a1f5804ae5d0003f4", 16), 122 // new BigInteger[]{ 123 // new BigInteger("9162fbe73984472a0a9e", 16), 124 // new BigInteger("-96341f1138933bc2f505", 16) }, 125 // new BigInteger[]{ 126 // new BigInteger("127971af8721782ecffa3", 16), 127 // new BigInteger("9162fbe73984472a0a9e", 16) }, 128 // new BigInteger("9162fbe73984472a0a9d0590", 16), 129 // new BigInteger("96341f1138933bc2f503fd44", 16), 130 // 176); 131 // ECCurve curve = configureCurveGLV(new SecP160K1Curve(), glv); 132 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 133 // + "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB" 134 // + "938CF935318FDCED6BC28286531733C3F03C4FEE")); 135 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 136 // } 137 // }; 138 // 139 // /* 140 // * secp160r1 141 // */ 142 // static X9ECParametersHolder secp160r1 = new X9ECParametersHolder() 143 // { 144 // protected X9ECParameters createParameters() 145 // { 146 // byte[] S = Hex.decode("1053CDE42C14D696E67687561517533BF3F83345"); 147 // ECCurve curve = configureCurve(new SecP160R1Curve()); 148 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 149 // + "4A96B5688EF573284664698968C38BB913CBFC82" 150 // + "23A628553168947D59DCC912042351377AC5FB32")); 151 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 152 // } 153 // }; 154 // 155 // /* 156 // * secp160r2 157 // */ 158 // static X9ECParametersHolder secp160r2 = new X9ECParametersHolder() 159 // { 160 // protected X9ECParameters createParameters() 161 // { 162 // byte[] S = Hex.decode("B99B99B099B323E02709A4D696E6768756151751"); 163 // ECCurve curve = configureCurve(new SecP160R2Curve()); 164 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 165 // + "52DCB034293A117E1F4FF11B30F7199D3144CE6D" 166 // + "FEAFFEF2E331F296E071FA0DF9982CFEA7D43F2E")); 167 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 168 // } 169 // }; 170 // END android-removed 171 172 /* 173 * secp192k1 174 */ 175 static X9ECParametersHolder secp192k1 = new X9ECParametersHolder() 176 { 177 protected X9ECParameters createParameters() 178 { 179 byte[] S = null; 180 GLVTypeBParameters glv = new GLVTypeBParameters( 181 new BigInteger("bb85691939b869c1d087f601554b96b80cb4f55b35f433c2", 16), 182 new BigInteger("3d84f26c12238d7b4f3d516613c1759033b1a5800175d0b1", 16), 183 new BigInteger[]{ 184 new BigInteger("71169be7330b3038edb025f1", 16), 185 new BigInteger("-b3fb3400dec5c4adceb8655c", 16) }, 186 new BigInteger[]{ 187 new BigInteger("12511cfe811d0f4e6bc688b4d", 16), 188 new BigInteger("71169be7330b3038edb025f1", 16) }, 189 new BigInteger("71169be7330b3038edb025f1d0f9", 16), 190 new BigInteger("b3fb3400dec5c4adceb8655d4c94", 16), 191 208); 192 ECCurve curve = configureCurveGLV(new SecP192K1Curve(), glv); 193 X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 194 + "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D" 195 + "9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D")); 196 return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 197 } 198 }; 199 200 /* 201 * secp192r1 202 */ 203 static X9ECParametersHolder secp192r1 = new X9ECParametersHolder() 204 { 205 protected X9ECParameters createParameters() 206 { 207 byte[] S = Hex.decode("3045AE6FC8422F64ED579528D38120EAE12196D5"); 208 ECCurve curve = configureCurve(new SecP192R1Curve()); 209 X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 210 + "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012" 211 + "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")); 212 return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 213 } 214 }; 215 216 /* 217 * secp224k1 218 */ 219 static X9ECParametersHolder secp224k1 = new X9ECParametersHolder() 220 { 221 protected X9ECParameters createParameters() 222 { 223 byte[] S = null; 224 GLVTypeBParameters glv = new GLVTypeBParameters( 225 new BigInteger("fe0e87005b4e83761908c5131d552a850b3f58b749c37cf5b84d6768", 16), 226 new BigInteger("60dcd2104c4cbc0be6eeefc2bdd610739ec34e317f9b33046c9e4788", 16), 227 new BigInteger[]{ 228 new BigInteger("6b8cf07d4ca75c88957d9d670591", 16), 229 new BigInteger("-b8adf1378a6eb73409fa6c9c637d", 16) }, 230 new BigInteger[]{ 231 new BigInteger("1243ae1b4d71613bc9f780a03690e", 16), 232 new BigInteger("6b8cf07d4ca75c88957d9d670591", 16) }, 233 new BigInteger("6b8cf07d4ca75c88957d9d67059037a4", 16), 234 new BigInteger("b8adf1378a6eb73409fa6c9c637ba7f5", 16), 235 240); 236 ECCurve curve = configureCurveGLV(new SecP224K1Curve(), glv); 237 X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 238 + "A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C" 239 + "7E089FED7FBA344282CAFBD6F7E319F7C0B0BD59E2CA4BDB556D61A5")); 240 return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 241 } 242 }; 243 244 /* 245 * secp224r1 246 */ 247 static X9ECParametersHolder secp224r1 = new X9ECParametersHolder() 248 { 249 protected X9ECParameters createParameters() 250 { 251 byte[] S = Hex.decode("BD71344799D5C7FCDC45B59FA3B9AB8F6A948BC5"); 252 ECCurve curve = configureCurve(new SecP224R1Curve()); 253 X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 254 + "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21" 255 + "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")); 256 return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 257 } 258 }; 259 260 /* 261 * secp256k1 262 */ 263 static X9ECParametersHolder secp256k1 = new X9ECParametersHolder() 264 { 265 protected X9ECParameters createParameters() 266 { 267 byte[] S = null; 268 GLVTypeBParameters glv = new GLVTypeBParameters( 269 new BigInteger("7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee", 16), 270 new BigInteger("5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72", 16), 271 new BigInteger[]{ 272 new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16), 273 new BigInteger("-e4437ed6010e88286f547fa90abfe4c3", 16) }, 274 new BigInteger[]{ 275 new BigInteger("114ca50f7a8e2f3f657c1108d9d44cfd8", 16), 276 new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16) }, 277 new BigInteger("3086d221a7d46bcde86c90e49284eb153dab", 16), 278 new BigInteger("e4437ed6010e88286f547fa90abfe4c42212", 16), 279 272); 280 ECCurve curve = configureCurveGLV(new SecP256K1Curve(), glv); 281 X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 282 + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798" 283 + "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8")); 284 return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 285 } 286 }; 287 288 /* 289 * secp256r1 290 */ 291 static X9ECParametersHolder secp256r1 = new X9ECParametersHolder() 292 { 293 protected X9ECParameters createParameters() 294 { 295 byte[] S = Hex.decode("C49D360886E704936A6678E1139D26B7819F7E90"); 296 ECCurve curve = configureCurve(new SecP256R1Curve()); 297 X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 298 + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296" 299 + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")); 300 return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 301 } 302 }; 303 304 /* 305 * secp384r1 306 */ 307 static X9ECParametersHolder secp384r1 = new X9ECParametersHolder() 308 { 309 protected X9ECParameters createParameters() 310 { 311 byte[] S = Hex.decode("A335926AA319A27A1D00896A6773A4827ACDAC73"); 312 ECCurve curve = configureCurve(new SecP384R1Curve()); 313 X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 314 + "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7" 315 + "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")); 316 return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 317 } 318 }; 319 320 /* 321 * secp521r1 322 */ 323 static X9ECParametersHolder secp521r1 = new X9ECParametersHolder() 324 { 325 protected X9ECParameters createParameters() 326 { 327 byte[] S = Hex.decode("D09E8800291CB85396CC6717393284AAA0DA64BA"); 328 ECCurve curve = configureCurve(new SecP521R1Curve()); 329 X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 330 + "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66" 331 + "011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650")); 332 return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 333 } 334 }; 335 336 // BEGIN android-removed 337 // /* 338 // * sect113r1 339 // */ 340 // static X9ECParametersHolder sect113r1 = new X9ECParametersHolder() 341 // { 342 // protected X9ECParameters createParameters() 343 // { 344 // byte[] S = Hex.decode("10E723AB14D696E6768756151756FEBF8FCB49A9"); 345 // ECCurve curve = configureCurve(new SecT113R1Curve()); 346 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 347 // + "009D73616F35F4AB1407D73562C10F" 348 // + "00A52830277958EE84D1315ED31886")); 349 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 350 // } 351 // }; 352 353 // /* 354 // * sect113r2 355 // */ 356 // static X9ECParametersHolder sect113r2 = new X9ECParametersHolder() 357 // { 358 // protected X9ECParameters createParameters() 359 // { 360 // byte[] S = Hex.decode("10C0FB15760860DEF1EEF4D696E676875615175D"); 361 // ECCurve curve = configureCurve(new SecT113R2Curve()); 362 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 363 // + "01A57A6A7B26CA5EF52FCDB8164797" 364 // + "00B3ADC94ED1FE674C06E695BABA1D")); 365 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 366 // } 367 // }; 368 369 // /* 370 // * sect131r1 371 // */ 372 // static X9ECParametersHolder sect131r1 = new X9ECParametersHolder() 373 // { 374 // protected X9ECParameters createParameters() 375 // { 376 // byte[] S = Hex.decode("4D696E676875615175985BD3ADBADA21B43A97E2"); 377 // ECCurve curve = configureCurve(new SecT131R1Curve()); 378 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 379 // + "0081BAF91FDF9833C40F9C181343638399" 380 // + "078C6E7EA38C001F73C8134B1B4EF9E150")); 381 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 382 // } 383 // }; 384 385 // /* 386 // * sect131r2 387 // */ 388 // static X9ECParametersHolder sect131r2 = new X9ECParametersHolder() 389 // { 390 // protected X9ECParameters createParameters() 391 // { 392 // byte[] S = Hex.decode("985BD3ADBAD4D696E676875615175A21B43A97E3"); 393 // ECCurve curve = configureCurve(new SecT131R2Curve()); 394 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 395 // + "0356DCD8F2F95031AD652D23951BB366A8" 396 // + "0648F06D867940A5366D9E265DE9EB240F")); 397 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 398 // } 399 // }; 400 401 // /* 402 // * sect163k1 403 // */ 404 // static X9ECParametersHolder sect163k1 = new X9ECParametersHolder() 405 // { 406 // protected X9ECParameters createParameters() 407 // { 408 // byte[] S = null; 409 // ECCurve curve = configureCurve(new SecT163K1Curve()); 410 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 411 // + "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8" 412 // + "0289070FB05D38FF58321F2E800536D538CCDAA3D9")); 413 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 414 // } 415 // }; 416 417 // /* 418 // * sect163r1 419 // */ 420 // static X9ECParametersHolder sect163r1 = new X9ECParametersHolder() 421 // { 422 // protected X9ECParameters createParameters() 423 // { 424 // byte[] S = Hex.decode("24B7B137C8A14D696E6768756151756FD0DA2E5C"); 425 // ECCurve curve = configureCurve(new SecT163R1Curve()); 426 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 427 // + "0369979697AB43897789566789567F787A7876A654" 428 // + "00435EDB42EFAFB2989D51FEFCE3C80988F41FF883")); 429 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 430 // } 431 // }; 432 433 // /* 434 // * sect163r2 435 // */ 436 // static X9ECParametersHolder sect163r2 = new X9ECParametersHolder() 437 // { 438 // protected X9ECParameters createParameters() 439 // { 440 // byte[] S = Hex.decode("85E25BFE5C86226CDB12016F7553F9D0E693A268"); 441 // ECCurve curve = configureCurve(new SecT163R2Curve()); 442 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 443 // + "03F0EBA16286A2D57EA0991168D4994637E8343E36" 444 // + "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1")); 445 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 446 // } 447 // }; 448 449 // /* 450 // * sect193r1 451 // */ 452 // static X9ECParametersHolder sect193r1 = new X9ECParametersHolder() 453 // { 454 // protected X9ECParameters createParameters() 455 // { 456 // byte[] S = Hex.decode("103FAEC74D696E676875615175777FC5B191EF30"); 457 // ECCurve curve = configureCurve(new SecT193R1Curve()); 458 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 459 // + "01F481BC5F0FF84A74AD6CDF6FDEF4BF6179625372D8C0C5E1" 460 // + "0025E399F2903712CCF3EA9E3A1AD17FB0B3201B6AF7CE1B05")); 461 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 462 // } 463 // }; 464 465 // /* 466 // * sect193r2 467 // */ 468 // static X9ECParametersHolder sect193r2 = new X9ECParametersHolder() 469 // { 470 // protected X9ECParameters createParameters() 471 // { 472 // byte[] S = Hex.decode("10B7B4D696E676875615175137C8A16FD0DA2211"); 473 // ECCurve curve = configureCurve(new SecT193R2Curve()); 474 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 475 // + "00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F" 476 // + "01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C")); 477 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 478 // } 479 // }; 480 481 // /* 482 // * sect233k1 483 // */ 484 // static X9ECParametersHolder sect233k1 = new X9ECParametersHolder() 485 // { 486 // protected X9ECParameters createParameters() 487 // { 488 // byte[] S = null; 489 // ECCurve curve = configureCurve(new SecT233K1Curve()); 490 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 491 // + "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126" 492 // + "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3")); 493 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 494 // } 495 // }; 496 497 // /* 498 // * sect233r1 499 // */ 500 // static X9ECParametersHolder sect233r1 = new X9ECParametersHolder() 501 // { 502 // protected X9ECParameters createParameters() 503 // { 504 // byte[] S = Hex.decode("74D59FF07F6B413D0EA14B344B20A2DB049B50C3"); 505 // ECCurve curve = configureCurve(new SecT233R1Curve()); 506 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 507 // + "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B" 508 // + "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052")); 509 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 510 // } 511 // }; 512 513 // /* 514 // * sect239k1 515 // */ 516 // static X9ECParametersHolder sect239k1 = new X9ECParametersHolder() 517 // { 518 // protected X9ECParameters createParameters() 519 // { 520 // byte[] S = null; 521 // ECCurve curve = configureCurve(new SecT239K1Curve()); 522 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 523 // + "29A0B6A887A983E9730988A68727A8B2D126C44CC2CC7B2A6555193035DC" 524 // + "76310804F12E549BDB011C103089E73510ACB275FC312A5DC6B76553F0CA")); 525 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 526 // } 527 // }; 528 529 // /* 530 // * sect283k1 531 // */ 532 // static X9ECParametersHolder sect283k1 = new X9ECParametersHolder() 533 // { 534 // protected X9ECParameters createParameters() 535 // { 536 // byte[] S = null; 537 // ECCurve curve = configureCurve(new SecT283K1Curve()); 538 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 539 // + "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836" 540 // + "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259")); 541 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 542 // } 543 // }; 544 545 // /* 546 // * sect283r1 547 // */ 548 // static X9ECParametersHolder sect283r1 = new X9ECParametersHolder() 549 // { 550 // protected X9ECParameters createParameters() 551 // { 552 // byte[] S = Hex.decode("77E2B07370EB0F832A6DD5B62DFC88CD06BB84BE"); 553 // ECCurve curve = configureCurve(new SecT283R1Curve()); 554 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 555 // + "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053" 556 // + "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4")); 557 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 558 // } 559 // }; 560 561 // /* 562 // * sect409k1 563 // */ 564 // static X9ECParametersHolder sect409k1 = new X9ECParametersHolder() 565 // { 566 // protected X9ECParameters createParameters() 567 // { 568 // byte[] S = null; 569 // ECCurve curve = configureCurve(new SecT409K1Curve()); 570 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 571 // + "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746" 572 // + "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B")); 573 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 574 // } 575 // }; 576 577 // /* 578 // * sect409r1 579 // */ 580 // static X9ECParametersHolder sect409r1 = new X9ECParametersHolder() 581 // { 582 // protected X9ECParameters createParameters() 583 // { 584 // byte[] S = Hex.decode("4099B5A457F9D69F79213D094C4BCD4D4262210B"); 585 // ECCurve curve = configureCurve(new SecT409R1Curve()); 586 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 587 // + "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7" 588 // + "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706")); 589 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 590 // } 591 // }; 592 593 // /* 594 // * sect571k1 595 // */ 596 // static X9ECParametersHolder sect571k1 = new X9ECParametersHolder() 597 // { 598 // protected X9ECParameters createParameters() 599 // { 600 // byte[] S = null; 601 // ECCurve curve = configureCurve(new SecT571K1Curve()); 602 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 603 // + "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972" 604 // + "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3")); 605 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 606 // } 607 // }; 608 609 // /* 610 // * sect571r1 611 // */ 612 // static X9ECParametersHolder sect571r1 = new X9ECParametersHolder() 613 // { 614 // protected X9ECParameters createParameters() 615 // { 616 // byte[] S = Hex.decode("2AA058F73A0E33AB486B0F610410C53A7F132310"); 617 // ECCurve curve = configureCurve(new SecT571R1Curve()); 618 // X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" 619 // + "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19" 620 // + "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B")); 621 // return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); 622 // } 623 // }; 624 // END android-removed 625 626 627 static final Hashtable nameToCurve = new Hashtable(); 628 static final Hashtable nameToOID = new Hashtable(); 629 static final Hashtable oidToCurve = new Hashtable(); 630 static final Hashtable oidToName = new Hashtable(); 631 static final Vector names = new Vector(); 632 defineCurve(String name, X9ECParametersHolder holder)633 static void defineCurve(String name, X9ECParametersHolder holder) 634 { 635 names.addElement(name); 636 name = Strings.toLowerCase(name); 637 nameToCurve.put(name, holder); 638 } 639 defineCurveWithOID(String name, ASN1ObjectIdentifier oid, X9ECParametersHolder holder)640 static void defineCurveWithOID(String name, ASN1ObjectIdentifier oid, X9ECParametersHolder holder) 641 { 642 names.addElement(name); 643 oidToName.put(oid, name); 644 oidToCurve.put(oid, holder); 645 name = Strings.toLowerCase(name); 646 nameToOID.put(name, oid); 647 nameToCurve.put(name, holder); 648 } 649 defineCurveAlias(String name, ASN1ObjectIdentifier oid)650 static void defineCurveAlias(String name, ASN1ObjectIdentifier oid) 651 { 652 Object curve = oidToCurve.get(oid); 653 if (curve == null) 654 { 655 throw new IllegalStateException(); 656 } 657 658 name = Strings.toLowerCase(name); 659 nameToOID.put(name, oid); 660 nameToCurve.put(name, curve); 661 } 662 663 static 664 { 665 // BEGIN android-removed 666 // defineCurve("curve25519", curve25519); 667 // END android-removed 668 669 // defineCurveWithOID("secp112r1", SECObjectIdentifiers.secp112r1, secp112r1); 670 // defineCurveWithOID("secp112r2", SECObjectIdentifiers.secp112r2, secp112r2); 671 // BEGIN android-removed 672 // defineCurveWithOID("secp128r1", SECObjectIdentifiers.secp128r1, secp128r1); 673 // END android-removed 674 // defineCurveWithOID("secp128r2", SECObjectIdentifiers.secp128r2, secp128r2); 675 // BEGIN android-removed 676 // defineCurveWithOID("secp160k1", SECObjectIdentifiers.secp160k1, secp160k1); 677 // defineCurveWithOID("secp160r1", SECObjectIdentifiers.secp160r1, secp160r1); 678 // defineCurveWithOID("secp160r2", SECObjectIdentifiers.secp160r2, secp160r2); 679 // END android-removed 680 defineCurveWithOID("secp192k1", SECObjectIdentifiers.secp192k1, secp192k1); 681 defineCurveWithOID("secp192r1", SECObjectIdentifiers.secp192r1, secp192r1); 682 defineCurveWithOID("secp224k1", SECObjectIdentifiers.secp224k1, secp224k1); 683 defineCurveWithOID("secp224r1", SECObjectIdentifiers.secp224r1, secp224r1); 684 defineCurveWithOID("secp256k1", SECObjectIdentifiers.secp256k1, secp256k1); 685 defineCurveWithOID("secp256r1", SECObjectIdentifiers.secp256r1, secp256r1); 686 defineCurveWithOID("secp384r1", SECObjectIdentifiers.secp384r1, secp384r1); 687 defineCurveWithOID("secp521r1", SECObjectIdentifiers.secp521r1, secp521r1); 688 689 // BEGIN android-removed 690 // defineCurveWithOID("sect113r1", SECObjectIdentifiers.sect113r1, sect113r1); 691 // defineCurveWithOID("sect113r2", SECObjectIdentifiers.sect113r2, sect113r2); 692 // defineCurveWithOID("sect131r1", SECObjectIdentifiers.sect131r1, sect131r1); 693 // defineCurveWithOID("sect131r2", SECObjectIdentifiers.sect131r2, sect131r2); 694 // defineCurveWithOID("sect163k1", SECObjectIdentifiers.sect163k1, sect163k1); 695 // defineCurveWithOID("sect163r1", SECObjectIdentifiers.sect163r1, sect163r1); 696 // defineCurveWithOID("sect163r2", SECObjectIdentifiers.sect163r2, sect163r2); 697 // defineCurveWithOID("sect193r1", SECObjectIdentifiers.sect193r1, sect193r1); 698 // defineCurveWithOID("sect193r2", SECObjectIdentifiers.sect193r2, sect193r2); 699 // defineCurveWithOID("sect233k1", SECObjectIdentifiers.sect233k1, sect233k1); 700 // defineCurveWithOID("sect233r1", SECObjectIdentifiers.sect233r1, sect233r1); 701 // defineCurveWithOID("sect239k1", SECObjectIdentifiers.sect239k1, sect239k1); 702 // defineCurveWithOID("sect283k1", SECObjectIdentifiers.sect283k1, sect283k1); 703 // defineCurveWithOID("sect283r1", SECObjectIdentifiers.sect283r1, sect283r1); 704 // defineCurveWithOID("sect409k1", SECObjectIdentifiers.sect409k1, sect409k1); 705 // defineCurveWithOID("sect409r1", SECObjectIdentifiers.sect409r1, sect409r1); 706 // defineCurveWithOID("sect571k1", SECObjectIdentifiers.sect571k1, sect571k1); 707 // defineCurveWithOID("sect571r1", SECObjectIdentifiers.sect571r1, sect571r1); 708 709 // defineCurveAlias("B-163", SECObjectIdentifiers.sect163r2); 710 // defineCurveAlias("B-233", SECObjectIdentifiers.sect233r1); 711 // defineCurveAlias("B-283", SECObjectIdentifiers.sect283r1); 712 // defineCurveAlias("B-409", SECObjectIdentifiers.sect409r1); 713 // defineCurveAlias("B-571", SECObjectIdentifiers.sect571r1); 714 715 // defineCurveAlias("K-163", SECObjectIdentifiers.sect163k1); 716 // defineCurveAlias("K-233", SECObjectIdentifiers.sect233k1); 717 // defineCurveAlias("K-283", SECObjectIdentifiers.sect283k1); 718 // defineCurveAlias("K-409", SECObjectIdentifiers.sect409k1); 719 // defineCurveAlias("K-571", SECObjectIdentifiers.sect571k1); 720 // END android-removed 721 722 defineCurveAlias("P-192", SECObjectIdentifiers.secp192r1); 723 defineCurveAlias("P-224", SECObjectIdentifiers.secp224r1); 724 defineCurveAlias("P-256", SECObjectIdentifiers.secp256r1); 725 defineCurveAlias("P-384", SECObjectIdentifiers.secp384r1); 726 defineCurveAlias("P-521", SECObjectIdentifiers.secp521r1); 727 } 728 getByName(String name)729 public static X9ECParameters getByName(String name) 730 { 731 X9ECParametersHolder holder = (X9ECParametersHolder)nameToCurve.get(Strings.toLowerCase(name)); 732 return holder == null ? null : holder.getParameters(); 733 } 734 735 /** 736 * return the X9ECParameters object for the named curve represented by the passed in object 737 * identifier. Null if the curve isn't present. 738 * 739 * @param oid 740 * an object identifier representing a named curve, if present. 741 */ getByOID(ASN1ObjectIdentifier oid)742 public static X9ECParameters getByOID(ASN1ObjectIdentifier oid) 743 { 744 X9ECParametersHolder holder = (X9ECParametersHolder)oidToCurve.get(oid); 745 return holder == null ? null : holder.getParameters(); 746 } 747 748 /** 749 * return the object identifier signified by the passed in name. Null if there is no object 750 * identifier associated with name. 751 * 752 * @return the object identifier associated with name, if present. 753 */ getOID(String name)754 public static ASN1ObjectIdentifier getOID(String name) 755 { 756 return (ASN1ObjectIdentifier)nameToOID.get(Strings.toLowerCase(name)); 757 } 758 759 /** 760 * return the named curve name represented by the given object identifier. 761 */ getName(ASN1ObjectIdentifier oid)762 public static String getName(ASN1ObjectIdentifier oid) 763 { 764 return (String)oidToName.get(oid); 765 } 766 767 /** 768 * returns an enumeration containing the name strings for curves contained in this structure. 769 */ getNames()770 public static Enumeration getNames() 771 { 772 return names.elements(); 773 } 774 } 775