1 /* ecparam-1.0.1.js (c) 2013-2021 Kenji Urushima | kjur.github.io/jsrsasign/license 2 */ 3 /* 4 * ecparam.js - Elliptic Curve Cryptography Curve Parameter Definition class 5 * 6 * Copyright (c) 2013-2021 Kenji Urushima (kenji.urushima@gmail.com) 7 * 8 * This software is licensed under the terms of the MIT License. 9 * https://kjur.github.io/jsrsasign/license 10 * 11 * The above copyright and license notice shall be 12 * included in all copies or substantial portions of the Software. 13 */ 14 15 /** 16 * @fileOverview 17 * @name ecparam-1.1.js 18 * @author Kenji Urushima kenji.urushima@gmail.com 19 * @version jsrsasign 10.5.0 ecparam 1.0.1 (2021-Nov-21) 20 * @since jsrsasign 4.0 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ 23 24 if (typeof KJUR == "undefined" || !KJUR) KJUR = {}; 25 if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {}; 26 27 /** 28 * static object for elliptic curve names and parameters 29 * @name KJUR.crypto.ECParameterDB 30 * @class static object for elliptic curve names and parameters 31 * @description 32 * This class provides parameters for named elliptic curves. 33 * Currently it supoprts following curve names and aliases however 34 * the name marked (*) are available for {@link KJUR.crypto.ECDSA} and 35 * {@link KJUR.crypto.Signature} classes. 36 * <ul> 37 * <li>secp128r1</li> 38 * <li>secp160r1</li> 39 * <li>secp160k1</li> 40 * <li>secp192r1</li> 41 * <li>secp192k1</li> 42 * <li>secp224r1</li> 43 * <li>secp256r1, NIST P-256, P-256, prime256v1 (*)</li> 44 * <li>secp256k1 (*)</li> 45 * <li>secp384r1, NIST P-384, P-384 (*)</li> 46 * <li>secp521r1, NIST P-521, P-521</li> 47 * </ul> 48 * You can register new curves by using 'register' method. 49 */ 50 KJUR.crypto.ECParameterDB = new function() { 51 var db = {}; 52 var aliasDB = {}; 53 54 function hex2bi(hex) { 55 return new BigInteger(hex, 16); 56 } 57 58 /** 59 * get curve inforamtion associative array for curve name or alias 60 * @name getByName 61 * @memberOf KJUR.crypto.ECParameterDB 62 * @function 63 * @param {String} nameOrAlias curve name or alias name 64 * @return {Array} associative array of curve parameters 65 * @example 66 * var param = KJUR.crypto.ECParameterDB.getByName('prime256v1'); 67 * var keylen = param['keylen']; 68 * var n = param['n']; 69 */ 70 this.getByName = function(nameOrAlias) { 71 var name = nameOrAlias; 72 if (typeof aliasDB[name] != "undefined") { 73 name = aliasDB[nameOrAlias]; 74 } 75 if (typeof db[name] != "undefined") { 76 return db[name]; 77 } 78 throw "unregistered EC curve name: " + name; 79 }; 80 81 /** 82 * register new curve 83 * @name regist 84 * @memberOf KJUR.crypto.ECParameterDB 85 * @function 86 * @param {String} name name of curve 87 * @param {Integer} keylen key length 88 * @param {String} pHex hexadecimal value of p 89 * @param {String} aHex hexadecimal value of a 90 * @param {String} bHex hexadecimal value of b 91 * @param {String} nHex hexadecimal value of n 92 * @param {String} hHex hexadecimal value of h 93 * @param {String} gxHex hexadecimal value of Gx 94 * @param {String} gyHex hexadecimal value of Gy 95 * @param {Array} aliasList array of string for curve names aliases 96 * @param {String} oid Object Identifier for the curve 97 * @param {String} info information string for the curve 98 */ 99 this.regist = function(name, keylen, pHex, aHex, bHex, nHex, hHex, gxHex, gyHex, aliasList, oid, info) { 100 db[name] = {}; 101 var p = hex2bi(pHex); 102 var a = hex2bi(aHex); 103 var b = hex2bi(bHex); 104 var n = hex2bi(nHex); 105 var h = hex2bi(hHex); 106 var curve = new ECCurveFp(p, a, b); 107 var G = curve.decodePointHex("04" + gxHex + gyHex); 108 db[name]['name'] = name; 109 db[name]['keylen'] = keylen; 110 db[name]['keycharlen'] = Math.ceil(keylen / 8) * 2; // for P-521 111 db[name]['curve'] = curve; 112 db[name]['G'] = G; 113 db[name]['n'] = n; 114 db[name]['h'] = h; 115 db[name]['oid'] = oid; 116 db[name]['info'] = info; 117 118 for (var i = 0; i < aliasList.length; i++) { 119 aliasDB[aliasList[i]] = name; 120 } 121 }; 122 }; 123 124 KJUR.crypto.ECParameterDB.regist( 125 "secp128r1", // name / p = 2^128 - 2^97 - 1 126 128, 127 "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", // p 128 "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC", // a 129 "E87579C11079F43DD824993C2CEE5ED3", // b 130 "FFFFFFFE0000000075A30D1B9038A115", // n 131 "1", // h 132 "161FF7528B899B2D0C28607CA52C5B86", // gx 133 "CF5AC8395BAFEB13C02DA292DDED7A83", // gy 134 [], // alias 135 "", // oid (underconstruction) 136 "secp128r1 : SECG curve over a 128 bit prime field"); // info 137 138 KJUR.crypto.ECParameterDB.regist( 139 "secp160k1", // name / p = 2^160 - 2^32 - 2^14 - 2^12 - 2^9 - 2^8 - 2^7 - 2^3 - 2^2 - 1 140 160, 141 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", // p 142 "0", // a 143 "7", // b 144 "0100000000000000000001B8FA16DFAB9ACA16B6B3", // n 145 "1", // h 146 "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB", // gx 147 "938CF935318FDCED6BC28286531733C3F03C4FEE", // gy 148 [], // alias 149 "", // oid 150 "secp160k1 : SECG curve over a 160 bit prime field"); // info 151 152 KJUR.crypto.ECParameterDB.regist( 153 "secp160r1", // name / p = 2^160 - 2^31 - 1 154 160, 155 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF", // p 156 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC", // a 157 "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45", // b 158 "0100000000000000000001F4C8F927AED3CA752257", // n 159 "1", // h 160 "4A96B5688EF573284664698968C38BB913CBFC82", // gx 161 "23A628553168947D59DCC912042351377AC5FB32", // gy 162 [], // alias 163 "", // oid 164 "secp160r1 : SECG curve over a 160 bit prime field"); // info 165 166 KJUR.crypto.ECParameterDB.regist( 167 "secp192k1", // name / p = 2^192 - 2^32 - 2^12 - 2^8 - 2^7 - 2^6 - 2^3 - 1 168 192, 169 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37", // p 170 "0", // a 171 "3", // b 172 "FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D", // n 173 "1", // h 174 "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D", // gx 175 "9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D", // gy 176 []); // alias 177 178 KJUR.crypto.ECParameterDB.regist( 179 "secp192r1", // name / p = 2^192 - 2^64 - 1 180 192, 181 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", // p 182 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", // a 183 "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", // b 184 "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831", // n 185 "1", // h 186 "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012", // gx 187 "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811", // gy 188 []); // alias 189 190 KJUR.crypto.ECParameterDB.regist( 191 "secp224r1", // name / p = 2^224 - 2^96 + 1 192 224, 193 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", // p 194 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", // a 195 "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", // b 196 "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", // n 197 "1", // h 198 "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21", // gx 199 "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", // gy 200 []); // alias 201 202 KJUR.crypto.ECParameterDB.regist( 203 "secp256k1", // name / p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1 204 256, 205 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", // p 206 "0", // a 207 "7", // b 208 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", // n 209 "1", // h 210 "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", // gx 211 "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", // gy 212 []); // alias 213 214 KJUR.crypto.ECParameterDB.regist( 215 "secp256r1", // name / p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1 216 256, 217 "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", // p 218 "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", // a 219 "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", // b 220 "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", // n 221 "1", // h 222 "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", // gx 223 "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", // gy 224 ["NIST P-256", "P-256", "prime256v1"]); // alias 225 226 KJUR.crypto.ECParameterDB.regist( 227 "secp384r1", // name 228 384, 229 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", // p 230 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", // a 231 "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", // b 232 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", // n 233 "1", // h 234 "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7", // gx 235 "3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f", // gy 236 ["NIST P-384", "P-384"]); // alias 237 238 KJUR.crypto.ECParameterDB.regist( 239 "secp521r1", // name 240 521, 241 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // p 242 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", // a 243 "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", // b 244 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", // n 245 "1", // h 246 "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66", // gx 247 "011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", // gy 248 ["NIST P-521", "P-521"]); // alias 249 250