avoid potential confusion about curves (prime192v1 and prime256v1 are
[openssl.git] / crypto / ec / ec_curve.c
index 93f775d5567566e1553e7d2c8e8002bb13bd1254..0b9b7ca7c79069842531447036b0a1df025bca8d 100644 (file)
  * The Contribution is licensed pursuant to the OpenSSL open source
  * license provided above.
  *
- * In addition, Sun covenants to all licensees who provide a reciprocal
- * covenant with respect to their own patents if any, not to sue under
- * current and future patent claims necessarily infringed by the making,
- * using, practicing, selling, offering for sale and/or otherwise
- * disposing of the Contribution as delivered hereunder 
- * (or portions thereof), provided that such covenant shall not apply:
- *  1) for code that a licensee deletes from the Contribution;
- *  2) separates from the Contribution; or
- *  3) for infringements caused by:
- *       i) the modification of the Contribution or
- *      ii) the combination of the Contribution with other software or
- *          devices where such combination causes the infringement.
- *
  * The elliptic curve binary polynomial software is originally written by 
  * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
  *
@@ -116,7 +103,7 @@ static const EC_CURVE_DATA _EC_NIST_PRIME_192 = {
        "07192b95ffc8da78631011ed6b24cdd573f977a11e794811",
        "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831",1,
        _EC_NIST_PRIME_192_SEED, 20,
-       "192 bit prime curve from the X9.62 draft"
+       "192 bit prime curve from X9.62 and SECG"
        };
 
 static const unsigned char _EC_NIST_PRIME_224_SEED[] = {
@@ -188,7 +175,7 @@ static const EC_CURVE_DATA _EC_X9_62_PRIME_192V2 = {
        "6574d11d69b6ec7a672bb82a083df2f2b0847de970b2de15",
        "FFFFFFFFFFFFFFFFFFFFFFFE5FB1A724DC80418648D8DD31",1,
        _EC_X9_62_PRIME_192V2_SEED, 20,
-       "192 bit prime curve from the X9.62 draft"
+       "192 bit prime curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_PRIME_192V3_SEED[] = {
@@ -203,7 +190,7 @@ static const EC_CURVE_DATA _EC_X9_62_PRIME_192V3 = {
        "38a90f22637337334b49dcb66a6dc8f9978aca7648a943b0",
        "FFFFFFFFFFFFFFFFFFFFFFFF7A62D031C83F4294F640EC13",1,
        _EC_X9_62_PRIME_192V3_SEED, 20,
-       "192 bit prime curve from the X9.62 draft"
+       "192 bit prime curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_PRIME_239V1_SEED[] = {
@@ -218,7 +205,7 @@ static const EC_CURVE_DATA _EC_X9_62_PRIME_239V1 = {
        "7debe8e4e90a5dae6e4054ca530ba04654b36818ce226b39fccb7b02f1ae",
        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF9E5E9A9F5D9071FBD1522688909D0B",1,
        _EC_X9_62_PRIME_239V1_SEED, 20,
-       "239 bit prime curve from the X9.62 draft"
+       "239 bit prime curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_PRIME_239V2_SEED[] = {
@@ -233,7 +220,7 @@ static const EC_CURVE_DATA _EC_X9_62_PRIME_239V2 = {
        "5b0125e4dbea0ec7206da0fc01d9b081329fb555de6ef460237dff8be4ba",
        "7FFFFFFFFFFFFFFFFFFFFFFF800000CFA7E8594377D414C03821BC582063",1,
        _EC_X9_62_PRIME_239V2_SEED, 20,
-       "239 bit prime curve from the X9.62 draft"
+       "239 bit prime curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_PRIME_239V3_SEED[] = {
@@ -248,7 +235,7 @@ static const EC_CURVE_DATA _EC_X9_62_PRIME_239V3 = {
        "1607e6898f390c06bc1d552bad226f3b6fcfe48b6e818499af18e3ed6cf3",
        "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF975DEB41B3A6057C3C432146526551",1,
        _EC_X9_62_PRIME_239V3_SEED, 20,
-       "239 bit prime curve from the X9.62 draft"
+       "239 bit prime curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_PRIME_256V1_SEED[] = {
@@ -263,7 +250,7 @@ static const EC_CURVE_DATA _EC_X9_62_PRIME_256V1 = {
        "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5",
        "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551",1,
        _EC_X9_62_PRIME_256V1_SEED, 20,
-       "256 bit prime curve from the X9.62 draft"
+       "256 bit prime curve from X9.62 and SECG"
        };
 /* the secg prime curves (minus the nist and x9.62 prime curves) */
 static const unsigned char _EC_SECG_PRIME_112R1_SEED[] = {
@@ -739,14 +726,14 @@ static const unsigned char _EC_X9_62_CHAR2_163V1_SEED[] = {
        0xF4,0xD6,0x96,0xE6,0x76,0x87,0x56,0x15,0x17,0x54};
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_163V1 = {
        NID_X9_62_characteristic_two_field,
-       "0800000000000000000000000000000000000000C9",
+       "080000000000000000000000000000000000000107",
        "072546B5435234A422E0789675F432C89435DE5242",
        "00C9517D06D5240D3CFF38C74B20B6CD4D6F9DD4D9",
        "07AF69989546103D79329FCC3D74880F33BBE803CB",
-       "0190C402D65BCC2B845337BC52352774E879B94B0D",
+       "01EC23211B5966ADEA1D3F87F7EA5848AEF0B7CA9F",
        "0400000000000000000001E60FC8821CC74DAEAFC1", 2,
        _EC_X9_62_CHAR2_163V1_SEED, 20,
-       "163 bit binary curve from the X9.62 draft"
+       "163 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_163V2_SEED[] = {
@@ -754,14 +741,14 @@ static const unsigned char _EC_X9_62_CHAR2_163V2_SEED[] = {
        0x87,0x56,0x15,0x17,0x58,0x0C,0xA4,0xE2,0x9F,0xFD};
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_163V2 = {
        NID_X9_62_characteristic_two_field,
-       "0800000000000000000000000000000000000000C9",
+       "080000000000000000000000000000000000000107",
        "0108B39E77C4B108BED981ED0E890E117C511CF072",
        "0667ACEB38AF4E488C407433FFAE4F1C811638DF20",
        "0024266E4EB5106D0A964D92C4860E2671DB9B6CC5",
-       "01F64F1C0280E19A062003DBAECEAEDEC1CE141D41",
+       "079F684DDF6684C5CD258B3890021B2386DFD19FC5",
        "03FFFFFFFFFFFFFFFFFFFDF64DE1151ADBB78F10A7", 2,
        _EC_X9_62_CHAR2_163V2_SEED, 20,
-       "163 bit binary curve from the X9.62 draft"
+       "163 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_163V3_SEED[] = {
@@ -769,14 +756,14 @@ static const unsigned char _EC_X9_62_CHAR2_163V3_SEED[] = {
        0x68,0x75,0x61,0x51,0x75,0xF1,0x6A,0x36,0xA3,0xB8};
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_163V3 = {
        NID_X9_62_characteristic_two_field,
-       "0800000000000000000000000000000000000000C9",
+       "080000000000000000000000000000000000000107",
        "07A526C63D3E25A256A007699F5447E32AE456B50E",
        "03F7061798EB99E238FD6F1BF95B48FEEB4854252B",
        "02F9F87B7C574D0BDECF8A22E6524775F98CDEBDCB",
-       "01D42417D750A363F61E455807D047059CA039ACFE",
+       "05B935590C155E17EA48EB3FF3718B893DF59A05D0",
        "03FFFFFFFFFFFFFFFFFFFE1AEE140F110AFF961309", 2,
        _EC_X9_62_CHAR2_163V3_SEED, 20,
-       "163 bit binary curve from the X9.62 draft"
+       "163 bit binary curve from X9.62"
        };
 
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_176V1 = {
@@ -788,7 +775,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_176V1 = {
        "6FA4539C2DADDDD6BAB5167D61B436E1D92BB16A562C",
        "00010092537397ECA4F6145799D62B0A19CE06FE26AD", 0xFF6E,
        NULL, 0,
-       "176 bit binary curve from the X9.62 draft"
+       "176 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_191V1_SEED[] = {
@@ -803,7 +790,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_191V1 = {
        "765BE73433B3F95E332932E70EA245CA2418EA0EF98018FB",
        "40000000000000000000000004A20E90C39067C893BBB9A5", 2,
        _EC_X9_62_CHAR2_191V1_SEED, 20,
-       "191 bit binary curve from the X9.62 draft"
+       "191 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_191V2_SEED[] = {
@@ -818,7 +805,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_191V2 = {
        "17434386626D14F3DBF01760D9213A3E1CF37AEC437D668A",
        "20000000000000000000000050508CB89F652824E06B8173", 4,
        _EC_X9_62_CHAR2_191V2_SEED, 20,
-       "191 bit binary curve from the X9.62 draft"
+       "191 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_191V3_SEED[] = {
@@ -833,7 +820,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_191V3 = {
        "545A39176196575D985999366E6AD34CE0A77CD7127B06BE",
        "155555555555555555555555610C0B196812BFB6288A3EA3", 6,
        _EC_X9_62_CHAR2_191V3_SEED, 20,
-       "191 bit binary curve from the X9.62 draft"
+       "191 bit binary curve from X9.62"
        };
 
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_208W1 = {
@@ -845,7 +832,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_208W1 = {
        "0F55B51A06E78E9AC38A035FF520D8B01781BEB1A6BB08617DE3",
        "000101BAF95C9723C57B6C21DA2EFF2D5ED588BDD5717E212F9D", 0xFE48,
        NULL, 0,
-       "208 bit binary curve from the X9.62 draft"
+       "208 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_239V1_SEED[] = {
@@ -860,7 +847,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_239V1 = {
        "61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305",
        "2000000000000000000000000000000F4D42FFE1492A4993F1CAD666E447", 4,
        _EC_X9_62_CHAR2_239V1_SEED, 20,
-       "239 bit binary curve from the X9.62 draft"
+       "239 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_239V2_SEED[] = {
@@ -875,7 +862,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_239V2 = {
        "5667334C45AFF3B5A03BAD9DD75E2C71A99362567D5453F7FA6E227EC833",
        "1555555555555555555555555555553C6F2885259C31E3FCDF154624522D", 6,
        _EC_X9_62_CHAR2_239V2_SEED, 20,
-       "239 bit binary curve from the X9.62 draft"
+       "239 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_239V3_SEED[] = {
@@ -890,7 +877,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_239V3 = {
        "2E5A0EAF6E5E1305B9004DCE5C0ED7FE59A35608F33837C816D80B79F461",
        "0CCCCCCCCCCCCCCCCCCCCCCCCCCCCCAC4912D2D9DF903EF9888B8A0E4CFF", 0xA,
        _EC_X9_62_CHAR2_239V3_SEED, 20,
-       "239 bit binary curve from the X9.62 draft"
+       "239 bit binary curve from X9.62"
        };
 
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_272W1 = {
@@ -904,7 +891,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_272W1 = {
        "000100FAF51354E0E39E4892DF6E319C72C8161603FA45AA7B998A167B8F1E629521",
        0xFF06,
        NULL, 0,
-       "272 bit binary curve from the X9.62 draft"
+       "272 bit binary curve from X9.62"
        };
 
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_304W1 = {
@@ -922,7 +909,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_304W1 = {
        "000101D556572AABAC800101D556572AABAC8001022D5C91DD173F8FB561DA6899164"
        "443051D", 0xFE2E,
        NULL, 0,
-       "304 bit binary curve from the X9.62 draft"
+       "304 bit binary curve from X9.62"
        };
 
 static const unsigned char _EC_X9_62_CHAR2_359V1_SEED[] = {
@@ -943,7 +930,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_359V1 = {
        "01AF286BCA1AF286BCA1AF286BCA1AF286BCA1AF286BC9FB8F6B85C556892C20A7EB9"
        "64FE7719E74F490758D3B", 0x4C,
        _EC_X9_62_CHAR2_359V1_SEED, 20,
-       "359 bit binary curve from the X9.62 draft"
+       "359 bit binary curve from X9.62"
        };
 
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_368W1 = {
@@ -961,7 +948,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_368W1 = {
        "00010090512DA9AF72B08349D98A5DD4C7B0532ECA51CE03E2D10F3B7AC579BD87E90"
        "9AE40A6F131E9CFCE5BD967", 0xFF70,
        NULL, 0,
-       "368 bit binary curve from the X9.62 draft"
+       "368 bit binary curve from X9.62"
        };
 
 static const EC_CURVE_DATA _EC_X9_62_CHAR2_431R1 = {
@@ -979,7 +966,7 @@ static const EC_CURVE_DATA _EC_X9_62_CHAR2_431R1 = {
        "0340340340340340340340340340340340340340340340340340340323C313FAB5058"
        "9703B5EC68D3587FEC60D161CC149C1AD4A91", 0x2760,
        NULL, 0,
-       "431 bit binary curve from the X9.62 draft"
+       "431 bit binary curve from X9.62"
        };
 
 static const EC_CURVE_DATA _EC_WTLS_1 = {
@@ -1009,14 +996,16 @@ static const ec_list_element curve_list[] = {
        { NID_secp160k1, &_EC_SECG_PRIME_160K1},
        { NID_secp160r1, &_EC_SECG_PRIME_160R1},
        { NID_secp160r2, &_EC_SECG_PRIME_160R2},
+       /* SECG secp192r1 is the same as X9.62 prime192v1 and hence omitted */
        { NID_secp192k1, &_EC_SECG_PRIME_192K1},
        { NID_secp224k1, &_EC_SECG_PRIME_224K1},
        { NID_secp224r1, &_EC_NIST_PRIME_224},
        { NID_secp256k1, &_EC_SECG_PRIME_256K1},
+       /* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
        { NID_secp384r1, &_EC_NIST_PRIME_384},
        { NID_secp521r1, &_EC_NIST_PRIME_521},
        /* X9.62 curves */
-       { NID_X9_62_prime192v1,  &_EC_NIST_PRIME_192},
+       { NID_X9_62_prime192v1, &_EC_NIST_PRIME_192},
        { NID_X9_62_prime192v2, &_EC_X9_62_PRIME_192V2},
        { NID_X9_62_prime192v3, &_EC_X9_62_PRIME_192V3},
        { NID_X9_62_prime239v1, &_EC_X9_62_PRIME_239V1},
@@ -1207,19 +1196,20 @@ EC_GROUP *EC_GROUP_new_by_nid(int nid)
        return ret;
        }
 
-const char *EC_GROUP_get0_comment(int nid)
+size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems)
        {
-       size_t i;
+       size_t  i, min;
 
-       for (i=0; i<curve_list_length; i++)
-               if (curve_list[i].nid == nid)
-                       return curve_list[i].data->comment;
-       return NULL;
-       }
+       if (r == NULL || nitems == 0)
+               return curve_list_length;
 
-int ec_group_index2nid(int i)
-       {
-       if (i >= curve_list_length || i < 0)
-               return 0;
-       return curve_list[i].nid;
+       min = nitems < curve_list_length ? nitems : curve_list_length;
+
+       for (i = 0; i < min; i++)
+               {
+               r[i].nid = curve_list[i].nid;
+               r[i].comment = curve_list[i].data->comment;
+               }
+
+       return curve_list_length;
        }