diff options
author | Karel Miko <karel.miko@gmail.com> | 2018-03-28 01:33:58 +0200 |
---|---|---|
committer | Karel Miko <karel.miko@gmail.com> | 2018-03-28 01:33:58 +0200 |
commit | 0a8f76dd5b1427c5677ab1e106a9397d2aabad00 (patch) | |
tree | 3bf2a9a4c225b9ff444c3cf71046e843b083853c /src/ltc/pk | |
parent | 5fd7132958e36a4a3c259cd44ee278349e522ef2 (diff) |
ltc update
Diffstat (limited to 'src/ltc/pk')
26 files changed, 255 insertions, 240 deletions
diff --git a/src/ltc/pk/ecc/ecc.c b/src/ltc/pk/ecc/ecc.c index b90afc71..f6d69e44 100644 --- a/src/ltc/pk/ecc/ecc.c +++ b/src/ltc/pk/ecc/ecc.c @@ -23,10 +23,10 @@ * - ANS X9.62 (named: PRIMEP*) * - http://www.ecc-brainpool.org/download/Domain-parameters.pdf (named: BRAINPOOLP*) */ -const ltc_ecc_set_type ltc_ecc_sets[] = { +const ltc_ecc_curve ltc_ecc_curves[] = { #if defined(LTC_ECC_SECP112R1) || defined(LTC_ECC112) { - /* curve name */ "SECP112R1", + /* curve name */ { "SECP112R1", "ECC-112", NULL }, /* prime */ "DB7C2ABF62E35E668076BEAD208B", /* A */ "DB7C2ABF62E35E668076BEAD2088", /* B */ "659EF8BA043916EEDE8911702B22", @@ -39,7 +39,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_SECP112R2 { - /* curve name */ "SECP112R2", + /* curve name */ { "SECP112R2", NULL }, /* prime */ "DB7C2ABF62E35E668076BEAD208B", /* A */ "6127C24C05F38A0AAAF65C0EF02C", /* B */ "51DEF1815DB5ED74FCC34C85D709", @@ -52,7 +52,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #if defined(LTC_ECC_SECP128R1) || defined(LTC_ECC128) { - /* curve name */ "SECP128R1", + /* curve name */ { "SECP128R1", "ECC-128", NULL }, /* prime */ "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", /* A */ "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC", /* B */ "E87579C11079F43DD824993C2CEE5ED3", @@ -65,7 +65,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_SECP128R2 { - /* curve name */ "SECP128R2", + /* curve name */ { "SECP128R2", NULL }, /* prime */ "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", /* A */ "D6031998D1B3BBFEBF59CC9BBFF9AEE1", /* B */ "5EEEFCA380D02919DC2C6558BB6D8A5D", @@ -78,7 +78,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #if defined(LTC_ECC_SECP160R1) || defined(LTC_ECC160) { - /* curve name */ "SECP160R1", + /* curve name */ { "SECP160R1", "ECC-160", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF", /* A */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC", /* B */ "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45", @@ -91,7 +91,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_SECP160R2 { - /* curve name */ "SECP160R2", + /* curve name */ { "SECP160R2", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", /* A */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70", /* B */ "B4E134D3FB59EB8BAB57274904664D5AF50388BA", @@ -104,7 +104,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_SECP160K1 { - /* curve name */ "SECP160K1", + /* curve name */ { "SECP160K1", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", /* A */ "0000000000000000000000000000000000000000", /* B */ "0000000000000000000000000000000000000007", @@ -117,7 +117,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #if defined(LTC_ECC_SECP192R1) || defined(LTC_ECC192) { - /* curve name */ "SECP192R1", /* same as: NISTP192 PRIME192V1, old libtomcrypt name: ECC-192 */ + /* curve name */ { "SECP192R1", "NISTP192", "PRIME192V1", "ECC-192", "P-192", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", /* A */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", /* B */ "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", @@ -130,7 +130,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_PRIME192V2 { - /* curve name */ "PRIME192V2", + /* curve name */ { "PRIME192V2", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", /* A */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", /* B */ "CC22D6DFB95C6B25E49C0D6364A4E5980C393AA21668D953", @@ -143,7 +143,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_PRIME192V3 { - /* curve name */ "PRIME192V3", + /* curve name */ { "PRIME192V3", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", /* A */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", /* B */ "22123DC2395A05CAA7423DAECCC94760A7D462256BD56916", @@ -156,7 +156,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_SECP192K1 { - /* curve name */ "SECP192K1", + /* curve name */ { "SECP192K1", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37", /* A */ "000000000000000000000000000000000000000000000000", /* B */ "000000000000000000000000000000000000000000000003", @@ -169,7 +169,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #if defined(LTC_ECC_SECP224R1) || defined(LTC_ECC224) { - /* curve name */ "SECP224R1", /* same as: NISTP224, old libtomcrypt name: ECC-224 */ + /* curve name */ { "SECP224R1", "NISTP224", "ECC-224", "P-224", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", /* A */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", /* B */ "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", @@ -182,7 +182,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_SECP224K1 { - /* curve name */ "SECP224K1", + /* curve name */ { "SECP224K1", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D", /* A */ "00000000000000000000000000000000000000000000000000000000", /* B */ "00000000000000000000000000000000000000000000000000000005", @@ -195,7 +195,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #if defined(LTC_ECC_SECP256R1) || defined(LTC_ECC256) { - /* curve name */ "SECP256R1", /* same as: NISTP256 PRIME256V1, old libtomcrypt name: ECC-256 */ + /* curve name */ { "SECP256R1", "NISTP256", "PRIME256V1", "ECC-256", "P-256", NULL }, /* prime */ "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", /* A */ "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", /* B */ "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", @@ -208,7 +208,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_SECP256K1 { - /* curve name */ "SECP256K1", + /* curve name */ { "SECP256K1", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", /* A */ "0000000000000000000000000000000000000000000000000000000000000000", /* B */ "0000000000000000000000000000000000000000000000000000000000000007", @@ -221,7 +221,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #if defined(LTC_ECC_SECP384R1) || defined(LTC_ECC384) { - /* curve name */ "SECP384R1", /* same as: NISTP384, old libtomcrypt name: ECC-384 */ + /* curve name */ { "SECP384R1", "NISTP384", "ECC-384", "P-384", NULL }, /* prime */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", /* A */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", /* B */ "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", @@ -234,7 +234,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #if defined(LTC_ECC_SECP521R1) || defined(LTC_ECC521) { - /* curve name */ "SECP521R1", /* same as: NISTP521, old libtomcrypt name: ECC-521 */ + /* curve name */ { "SECP521R1", "NISTP521", "ECC-521", "P-521", NULL }, /* prime */ "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", /* A */ "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", /* B */ "0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", @@ -247,7 +247,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_PRIME239V1 { - /* curve name */ "PRIME239V1", + /* curve name */ { "PRIME239V1", NULL }, /* prime */ "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", /* A */ "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", /* B */ "6B016C3BDCF18941D0D654921475CA71A9DB2FB27D1D37796185C2942C0A", @@ -260,7 +260,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_PRIME239V2 { - /* curve name */ "PRIME239V2", + /* curve name */ { "PRIME239V2", NULL }, /* prime */ "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", /* A */ "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", /* B */ "617FAB6832576CBBFED50D99F0249C3FEE58B94BA0038C7AE84C8C832F2C", @@ -273,7 +273,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_PRIME239V3 { - /* curve name */ "PRIME239V3", + /* curve name */ { "PRIME239V3", NULL }, /* prime */ "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", /* A */ "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", /* B */ "255705FA2A306654B1F4CB03D6A750A30C250102D4988717D9BA15AB6D3E", @@ -286,7 +286,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP160R1 { - /* curve name */ "BRAINPOOLP160R1", + /* curve name */ { "BRAINPOOLP160R1", NULL }, /* prime */ "E95E4A5F737059DC60DFC7AD95B3D8139515620F", /* A */ "340E7BE2A280EB74E2BE61BADA745D97E8F7C300", /* B */ "1E589A8595423412134FAA2DBDEC95C8D8675E58", @@ -299,7 +299,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP192R1 { - /* curve name */ "BRAINPOOLP192R1", + /* curve name */ { "BRAINPOOLP192R1", NULL }, /* prime */ "C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297", /* A */ "6A91174076B1E0E19C39C031FE8685C1CAE040E5C69A28EF", /* B */ "469A28EF7C28CCA3DC721D044F4496BCCA7EF4146FBF25C9", @@ -312,7 +312,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP224R1 { - /* curve name */ "BRAINPOOLP224R1", + /* curve name */ { "BRAINPOOLP224R1", NULL }, /* prime */ "D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF", /* A */ "68A5E62CA9CE6C1C299803A6C1530B514E182AD8B0042A59CAD29F43", /* B */ "2580F63CCFE44138870713B1A92369E33E2135D266DBB372386C400B", @@ -325,7 +325,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP256R1 { - /* curve name */ "BRAINPOOLP256R1", + /* curve name */ { "BRAINPOOLP256R1", NULL }, /* prime */ "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* A */ "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* B */ "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", @@ -338,7 +338,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP320R1 { - /* curve name */ "BRAINPOOLP320R1", + /* curve name */ { "BRAINPOOLP320R1", NULL }, /* prime */ "D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E27", /* A */ "3EE30B568FBAB0F883CCEBD46D3F3BB8A2A73513F5EB79DA66190EB085FFA9F492F375A97D860EB4", /* B */ "520883949DFDBC42D3AD198640688A6FE13F41349554B49ACC31DCCD884539816F5EB4AC8FB1F1A6", @@ -351,7 +351,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP384R1 { - /* curve name */ "BRAINPOOLP384R1", + /* curve name */ { "BRAINPOOLP384R1", NULL }, /* prime */ "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53", /* A */ "7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F90F8AA5814A503AD4EB04A8C7DD22CE2826", /* B */ "04A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62D57CB4390295DBC9943AB78696FA504C11", @@ -364,7 +364,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP512R1 { - /* curve name */ "BRAINPOOLP512R1", + /* curve name */ { "BRAINPOOLP512R1", NULL }, /* prime */ "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3", /* A */ "7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA", /* B */ "3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723", @@ -377,7 +377,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP160T1 { - /* curve name */ "BRAINPOOLP160T1", + /* curve name */ { "BRAINPOOLP160T1", NULL }, /* prime */ "E95E4A5F737059DC60DFC7AD95B3D8139515620F", /* A */ "E95E4A5F737059DC60DFC7AD95B3D8139515620C", /* B */ "7A556B6DAE535B7B51ED2C4D7DAA7A0B5C55F380", @@ -390,7 +390,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP192T1 { - /* curve name */ "BRAINPOOLP192T1", + /* curve name */ { "BRAINPOOLP192T1", NULL }, /* prime */ "C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297", /* A */ "C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86294", /* B */ "13D56FFAEC78681E68F9DEB43B35BEC2FB68542E27897B79", @@ -403,7 +403,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP224T1 { - /* curve name */ "BRAINPOOLP224T1", + /* curve name */ { "BRAINPOOLP224T1", NULL }, /* prime */ "D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF", /* A */ "D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FC", /* B */ "4B337D934104CD7BEF271BF60CED1ED20DA14C08B3BB64F18A60888D", @@ -416,7 +416,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP256T1 { - /* curve name */ "BRAINPOOLP256T1", + /* curve name */ { "BRAINPOOLP256T1", NULL }, /* prime */ "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* A */ "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5374", /* B */ "662C61C430D84EA4FE66A7733D0B76B7BF93EBC4AF2F49256AE58101FEE92B04", @@ -429,7 +429,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP320T1 { - /* curve name */ "BRAINPOOLP320T1", + /* curve name */ { "BRAINPOOLP320T1", NULL }, /* prime */ "D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E27", /* A */ "D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E24", /* B */ "A7F561E038EB1ED560B3D147DB782013064C19F27ED27C6780AAF77FB8A547CEB5B4FEF422340353", @@ -442,7 +442,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP384T1 { - /* curve name */ "BRAINPOOLP384T1", + /* curve name */ { "BRAINPOOLP384T1", NULL }, /* prime */ "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53", /* A */ "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC50", /* B */ "7F519EADA7BDA81BD826DBA647910F8C4B9346ED8CCDC64E4B1ABD11756DCE1D2074AA263B88805CED70355A33B471EE", @@ -455,7 +455,7 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { #endif #ifdef LTC_ECC_BRAINPOOLP512T1 { - /* curve name */ "BRAINPOOLP512T1", + /* curve name */ { "BRAINPOOLP512T1", NULL }, /* prime */ "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3", /* A */ "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F0", /* B */ "7CBBBCF9441CFAB76E1890E46884EAE321F70C0BCB4981527897504BEC3E36A62BCDFA2304976540F6450085F2DAE145C22553B465763689180EA2571867423E", @@ -467,7 +467,8 @@ const ltc_ecc_set_type ltc_ecc_sets[] = { }, #endif { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, + { NULL }, + NULL, NULL, NULL, NULL, NULL, NULL, 0, { 0 }, 0 } diff --git a/src/ltc/pk/ecc/ecc_ansi_x963_import.c b/src/ltc/pk/ecc/ecc_ansi_x963_import.c index bcc8575f..12b034da 100644 --- a/src/ltc/pk/ecc/ecc_ansi_x963_import.c +++ b/src/ltc/pk/ecc/ecc_ansi_x963_import.c @@ -26,7 +26,7 @@ int ecc_ansi_x963_import(const unsigned char *in, unsigned long inlen, ecc_key * return ecc_ansi_x963_import_ex(in, inlen, key, NULL); } -int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_set_type *dp) +int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu) { int err; @@ -39,13 +39,13 @@ int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_ke } /* initialize key->dp */ - if (dp == NULL) { + if (cu == NULL) { /* this case works only for uncompressed public keys */ - if ((err = ecc_set_dp_size((inlen-1)>>1, key)) != CRYPT_OK) { return err; } + if ((err = ecc_set_dp_by_size((inlen-1)>>1, key)) != CRYPT_OK) { return err; } } else { /* this one works for both compressed / uncompressed pubkeys */ - if ((err = ecc_set_dp(dp, key)) != CRYPT_OK) { return err; } + if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { return err; } } /* load public key */ diff --git a/src/ltc/pk/ecc/ecc_decrypt_key.c b/src/ltc/pk/ecc/ecc_decrypt_key.c index ebfa5156..b5298d2d 100644 --- a/src/ltc/pk/ecc/ecc_decrypt_key.c +++ b/src/ltc/pk/ecc/ecc_decrypt_key.c @@ -85,7 +85,7 @@ int ecc_decrypt_key(const unsigned char *in, unsigned long inlen, } /* import ECC key from packet */ - if ((err = ecc_set_dp_copy(key, &pubkey)) != CRYPT_OK) { goto LBL_ERR; } + if ((err = ecc_copy_dp(key, &pubkey)) != CRYPT_OK) { goto LBL_ERR; } if ((err = ecc_set_key(decode[1].data, decode[1].size, PK_PUBLIC, &pubkey)) != CRYPT_OK) { goto LBL_ERR; } /* make shared key */ diff --git a/src/ltc/pk/ecc/ecc_encrypt_key.c b/src/ltc/pk/ecc/ecc_encrypt_key.c index 530eadd8..1ccfd714 100644 --- a/src/ltc/pk/ecc/ecc_encrypt_key.c +++ b/src/ltc/pk/ecc/ecc_encrypt_key.c @@ -57,7 +57,7 @@ int ecc_encrypt_key(const unsigned char *in, unsigned long inlen, } /* make a random key and export the public copy */ - if ((err = ecc_set_dp_copy(key, &pubkey)) != CRYPT_OK) { return err; } + if ((err = ecc_copy_dp(key, &pubkey)) != CRYPT_OK) { return err; } if ((err = ecc_generate_key(prng, wprng, &pubkey)) != CRYPT_OK) { return err; } pub_expt = XMALLOC(ECC_BUF_SIZE); @@ -78,12 +78,14 @@ int ecc_encrypt_key(const unsigned char *in, unsigned long inlen, } pubkeysize = ECC_BUF_SIZE; -#ifdef USE_TFM - /* XXX-FIXME: TFM does not support sqrtmod_prime */ - if ((err = ecc_get_key(pub_expt, &pubkeysize, PK_PUBLIC, &pubkey)) != CRYPT_OK) { -#else - if ((err = ecc_get_key(pub_expt, &pubkeysize, PK_PUBLIC|PK_COMPRESSED, &pubkey)) != CRYPT_OK) { -#endif + if (ltc_mp.sqrtmod_prime != NULL) { + /* PK_COMPRESSED requires sqrtmod_prime */ + err = ecc_get_key(pub_expt, &pubkeysize, PK_PUBLIC|PK_COMPRESSED, &pubkey); + } + else { + err = ecc_get_key(pub_expt, &pubkeysize, PK_PUBLIC, &pubkey); + } + if (err != CRYPT_OK) { ecc_free(&pubkey); goto LBL_ERR; } diff --git a/src/ltc/pk/ecc/ecc_free.c b/src/ltc/pk/ecc/ecc_free.c index c8033b3b..47d31297 100644 --- a/src/ltc/pk/ecc/ecc_free.c +++ b/src/ltc/pk/ecc/ecc_free.c @@ -23,14 +23,12 @@ void ecc_free(ecc_key *key) { LTC_ARGCHKVD(key != NULL); - /* clean dp */ + mp_cleanup_multi(&key->dp.prime, &key->dp.order, &key->dp.A, &key->dp.B, &key->dp.base.x, &key->dp.base.y, &key->dp.base.z, - NULL); - - /* clean key */ - mp_cleanup_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, NULL); + &key->pubkey.x, &key->pubkey.y, &key->pubkey.z, + &key->k, NULL); } #endif diff --git a/src/ltc/pk/ecc/ecc_get_curve_by_name.c b/src/ltc/pk/ecc/ecc_get_curve_by_name.c new file mode 100644 index 00000000..48db6d28 --- /dev/null +++ b/src/ltc/pk/ecc/ecc_get_curve_by_name.c @@ -0,0 +1,63 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +#include "tomcrypt.h" + +#ifdef LTC_MECC + +/* case-insensitive match + ignore '-', '_', ' ' */ +static int _name_match(const char *left, const char *right) +{ + char lc_r, lc_l; + + while ((*left != '\0') && (*right != '\0')) { + while ((*left == ' ') || (*left == '-') || (*left == '_')) left++; + while ((*right == ' ') || (*right == '-') || (*right == '_')) right++; + if (*left == '\0' || *right == '\0') break; + lc_r = *right; + lc_l = *left; + if ((lc_r >= 'A') && (lc_r <= 'Z')) lc_r += 32; + if ((lc_l >= 'A') && (lc_l <= 'Z')) lc_l += 32; + if (lc_l != lc_r) return 0; + left++; + right++; + } + + if ((*left == '\0') && (*right == '\0')) + return 1; + else + return 0; +} + +int ecc_get_curve_by_name(const char *name, const ltc_ecc_curve **cu) +{ + int i, j; + + LTC_ARGCHK(cu != NULL); + LTC_ARGCHK(name != NULL); + + *cu = NULL; + + for (i = 0; ltc_ecc_curves[i].prime != NULL; i++) { + for (j = 0; ltc_ecc_curves[i].names[j] != NULL; j++) { + if (_name_match(ltc_ecc_curves[i].names[j], name)) { + *cu = <c_ecc_curves[i]; + return CRYPT_OK; + } + } + } + + return CRYPT_INVALID_ARG; /* not found */ +} + +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/src/ltc/pk/ecc/ecc_get_set.c b/src/ltc/pk/ecc/ecc_get_set.c deleted file mode 100644 index f00cf45f..00000000 --- a/src/ltc/pk/ecc/ecc_get_set.c +++ /dev/null @@ -1,40 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - */ - -#include "tomcrypt.h" - -#ifdef LTC_MECC - -int ecc_get_set_by_name(const char* name, const ltc_ecc_set_type** dp) -{ - int i; - - LTC_ARGCHK(dp != NULL); - LTC_ARGCHK(name != NULL); - - *dp = NULL; - - for (i = 0; ltc_ecc_sets[i].name != NULL; i++) { - if (XSTRCMP(ltc_ecc_sets[i].name, name) == 0) break; - } - - if (ltc_ecc_sets[i].name == NULL) { - /* not found */ - return CRYPT_INVALID_ARG; - } - - *dp = <c_ecc_sets[i]; - return CRYPT_OK; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/src/ltc/pk/ecc/ecc_import.c b/src/ltc/pk/ecc/ecc_import.c index 3a1dcc57..6deea284 100644 --- a/src/ltc/pk/ecc/ecc_import.c +++ b/src/ltc/pk/ecc/ecc_import.c @@ -33,10 +33,10 @@ int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key) @param in The packet to import @param inlen The length of the packet @param key [out] The destination of the import - @param dp pointer to user supplied params; must be the same as the params used when exporting + @param cu pointer to user supplied params; must be the same as the params used when exporting @return CRYPT_OK if successful, upon error all allocated memory will be freed */ -int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_set_type *dp) +int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_curve *cu) { unsigned long key_size; unsigned char flags[1]; @@ -55,10 +55,10 @@ int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, co } /* allocate & initialize the key */ - if (dp == NULL) { - if ((err = ecc_set_dp_size(key_size, key)) != CRYPT_OK) { goto done; } + if (cu == NULL) { + if ((err = ecc_set_dp_by_size(key_size, key)) != CRYPT_OK) { goto done; } } else { - if ((err = ecc_set_dp(dp, key)) != CRYPT_OK) { goto done; } + if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { goto done; } } if (flags[0] == 1) { diff --git a/src/ltc/pk/ecc/ecc_import_openssl.c b/src/ltc/pk/ecc/ecc_import_openssl.c index 18316ee8..489b975b 100644 --- a/src/ltc/pk/ecc/ecc_import_openssl.c +++ b/src/ltc/pk/ecc/ecc_import_openssl.c @@ -31,7 +31,7 @@ int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *ke err = x509_decode_subject_public_key_info(in, inlen, PKA_EC, bin_xy, &len_xy, LTC_ASN1_OBJECT_IDENTIFIER, (void *)curveoid, &len_oid); if (err == CRYPT_OK) { /* load curve parameters for given curve OID */ - if ((err = ecc_set_dp_oid(curveoid, len_oid, key)) != CRYPT_OK) { goto error; } + if ((err = ecc_set_dp_by_oid(curveoid, len_oid, key)) != CRYPT_OK) { goto error; } /* load public key */ if ((err = ecc_set_key(bin_xy, len_xy, PK_PUBLIC, key)) != CRYPT_OK) { goto error; } goto success; @@ -69,7 +69,7 @@ int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *ke if ((err = mp_read_unsigned_bin(b, bin_b, len_b)) != CRYPT_OK) { goto error; } if ((err = ltc_ecc_import_point(bin_g, len_g, prime, a, b, gx, gy)) != CRYPT_OK) { goto error; } /* load curve parameters */ - if ((err = ecc_set_dp_bn(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; } + if ((err = ecc_set_dp_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; } /* load public key */ if ((err = ecc_set_key(bin_xy, len_xy, PK_PUBLIC, key)) != CRYPT_OK) { goto error; } goto success; @@ -89,7 +89,7 @@ int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *ke err = der_decode_sequence(in, inlen, seq_priv, 4); if (err == CRYPT_OK) { /* load curve parameters for given curve OID */ - if ((err = ecc_set_dp_oid(curveoid, custom[0].size, key)) != CRYPT_OK) { goto error; } + if ((err = ecc_set_dp_by_oid(curveoid, custom[0].size, key)) != CRYPT_OK) { goto error; } /* load private+public key */ if ((err = ecc_set_key(bin_k, seq_priv[1].size, PK_PRIVATE, key)) != CRYPT_OK) { goto error; } goto success; @@ -133,7 +133,7 @@ int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *ke if ((err = mp_read_unsigned_bin(b, bin_b, len_b)) != CRYPT_OK) { goto error; } if ((err = ltc_ecc_import_point(bin_g, len_g, prime, a, b, gx, gy)) != CRYPT_OK) { goto error; } /* load curve parameters */ - if ((err = ecc_set_dp_bn(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; } + if ((err = ecc_set_dp_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; } /* load private+public key */ if ((err = ecc_set_key(bin_k, len_k, PK_PRIVATE, key)) != CRYPT_OK) { goto error; } goto success; diff --git a/src/ltc/pk/ecc/ecc_import_pkcs8.c b/src/ltc/pk/ecc/ecc_import_pkcs8.c index 6b5b0c71..01aa5252 100644 --- a/src/ltc/pk/ecc/ecc_import_pkcs8.c +++ b/src/ltc/pk/ecc/ecc_import_pkcs8.c @@ -500,7 +500,7 @@ int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen, * 23:d=1 hl=2 l= 77 prim: OCTET STRING :bytes (== privatekey) */ ltc_asn1_list *loid = lseq->child->next; - if ((err = ecc_set_dp_oid(loid->data, loid->size, key)) != CRYPT_OK) { + if ((err = ecc_set_dp_by_oid(loid->data, loid->size, key)) != CRYPT_OK) { goto LBL_DONE; } } @@ -553,7 +553,7 @@ int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen, if ((err = ltc_ecc_import_point(lg->data, lg->size, lprime->data, a, b, gx, gy)) != CRYPT_OK) { goto LBL_DONE; } - if ((err = ecc_set_dp_bn(a, b, lprime->data, lorder->data, gx, gy, cofactor, key)) != CRYPT_OK) { + if ((err = ecc_set_dp_from_mpis(a, b, lprime->data, lorder->data, gx, gy, cofactor, key)) != CRYPT_OK) { goto LBL_DONE; } } diff --git a/src/ltc/pk/ecc/ecc_make_key.c b/src/ltc/pk/ecc/ecc_make_key.c index 4617befb..16660174 100644 --- a/src/ltc/pk/ecc/ecc_make_key.c +++ b/src/ltc/pk/ecc/ecc_make_key.c @@ -28,15 +28,15 @@ int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key) { int err; - if ((err = ecc_set_dp_size(keysize, key)) != CRYPT_OK) { return err; } + if ((err = ecc_set_dp_by_size(keysize, key)) != CRYPT_OK) { return err; } if ((err = ecc_generate_key(prng, wprng, key)) != CRYPT_OK) { return err; } return CRYPT_OK; } -int ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_set_type *dp) +int ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_curve *cu) { int err; - if ((err = ecc_set_dp(dp, key)) != CRYPT_OK) { return err; } + if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { return err; } if ((err = ecc_generate_key(prng, wprng, key)) != CRYPT_OK) { return err; } return CRYPT_OK; } diff --git a/src/ltc/pk/ecc/ecc_set_dp.c b/src/ltc/pk/ecc/ecc_set_dp.c index 17a0d2aa..52a10dc3 100644 --- a/src/ltc/pk/ecc/ecc_set_dp.c +++ b/src/ltc/pk/ecc/ecc_set_dp.c @@ -11,13 +11,13 @@ #ifdef LTC_MECC -int ecc_set_dp(const ltc_ecc_set_type *set, ecc_key *key) +int ecc_set_dp(const ltc_ecc_curve *curve, ecc_key *key) { unsigned long i; int err; LTC_ARGCHK(key != NULL); - LTC_ARGCHK(set != NULL); + LTC_ARGCHK(curve != NULL); if ((err = mp_init_multi(&key->dp.prime, &key->dp.order, &key->dp.A, &key->dp.B, &key->dp.base.x, &key->dp.base.y, &key->dp.base.z, @@ -27,19 +27,19 @@ int ecc_set_dp(const ltc_ecc_set_type *set, ecc_key *key) } /* A, B, order, prime, Gx, Gy */ - if ((err = mp_read_radix(key->dp.prime, set->prime, 16)) != CRYPT_OK) { goto error; } - if ((err = mp_read_radix(key->dp.order, set->order, 16)) != CRYPT_OK) { goto error; } - if ((err = mp_read_radix(key->dp.A, set->A, 16)) != CRYPT_OK) { goto error; } - if ((err = mp_read_radix(key->dp.B, set->B, 16)) != CRYPT_OK) { goto error; } - if ((err = mp_read_radix(key->dp.base.x, set->Gx, 16)) != CRYPT_OK) { goto error; } - if ((err = mp_read_radix(key->dp.base.y, set->Gy, 16)) != CRYPT_OK) { goto error; } - if ((err = mp_set(key->dp.base.z, 1)) != CRYPT_OK) { goto error; } + if ((err = mp_read_radix(key->dp.prime, curve->prime, 16)) != CRYPT_OK) { goto error; } + if ((err = mp_read_radix(key->dp.order, curve->order, 16)) != CRYPT_OK) { goto error; } + if ((err = mp_read_radix(key->dp.A, curve->A, 16)) != CRYPT_OK) { goto error; } + if ((err = mp_read_radix(key->dp.B, curve->B, 16)) != CRYPT_OK) { goto error; } + if ((err = mp_read_radix(key->dp.base.x, curve->Gx, 16)) != CRYPT_OK) { goto error; } + if ((err = mp_read_radix(key->dp.base.y, curve->Gy, 16)) != CRYPT_OK) { goto error; } + if ((err = mp_set(key->dp.base.z, 1)) != CRYPT_OK) { goto error; } /* cofactor & size */ - key->dp.cofactor = set->cofactor; + key->dp.cofactor = curve->cofactor; key->dp.size = mp_unsigned_bin_size(key->dp.prime); /* OID */ - key->dp.oidlen = set->oidlen; - for (i = 0; i < key->dp.oidlen; i++) key->dp.oid[i] = set->oid[i]; + key->dp.oidlen = curve->oidlen; + for (i = 0; i < key->dp.oidlen; i++) key->dp.oid[i] = curve->oid[i]; /* success */ return CRYPT_OK; @@ -48,45 +48,39 @@ error: return err; } -int ecc_set_dp_size(int size, ecc_key *key) +int ecc_set_dp_by_size(int size, ecc_key *key) { - const ltc_ecc_set_type *dp = NULL; - int err; + const ltc_ecc_curve *cu = NULL; + int err = CRYPT_ERROR; /* for compatibility with libtomcrypt-1.17 the sizes below must match the specific curves */ if (size <= 14) { - if ((err = ecc_get_set_by_name("SECP112R1", &dp)) != CRYPT_OK) return err; - return ecc_set_dp(dp, key); + err = ecc_get_curve_by_name("SECP112R1", &cu); } else if (size <= 16) { - if ((err = ecc_get_set_by_name("SECP128R1", &dp)) != CRYPT_OK) return err; - return ecc_set_dp(dp, key); + err = ecc_get_curve_by_name("SECP128R1", &cu); } else if (size <= 20) { - if ((err = ecc_get_set_by_name("SECP160R1", &dp)) != CRYPT_OK) return err; - return ecc_set_dp(dp, key); + err = ecc_get_curve_by_name("SECP160R1", &cu); } else if (size <= 24) { - if ((err = ecc_get_set_by_name("SECP192R1", &dp)) != CRYPT_OK) return err; - return ecc_set_dp(dp, key); + err = ecc_get_curve_by_name("SECP192R1", &cu); } else if (size <= 28) { - if ((err = ecc_get_set_by_name("SECP224R1", &dp)) != CRYPT_OK) return err; - return ecc_set_dp(dp, key); + err = ecc_get_curve_by_name("SECP224R1", &cu); } else if (size <= 32) { - if ((err = ecc_get_set_by_name("SECP256R1", &dp)) != CRYPT_OK) return err; - return ecc_set_dp(dp, key); + err = ecc_get_curve_by_name("SECP256R1", &cu); } else if (size <= 48) { - if ((err = ecc_get_set_by_name("SECP384R1", &dp)) != CRYPT_OK) return err; - return ecc_set_dp(dp, key); + err = ecc_get_curve_by_name("SECP384R1", &cu); } else if (size <= 66) { - if ((err = ecc_get_set_by_name("SECP521R1", &dp)) != CRYPT_OK) return err; - return ecc_set_dp(dp, key); + err = ecc_get_curve_by_name("SECP521R1", &cu); } + if (err == CRYPT_OK && cu != NULL) return ecc_set_dp(cu, key); + return CRYPT_INVALID_ARG; } diff --git a/src/ltc/pk/ecc/ecc_set_dp_internal.c b/src/ltc/pk/ecc/ecc_set_dp_internal.c index bd7c0403..81140485 100644 --- a/src/ltc/pk/ecc/ecc_set_dp_internal.c +++ b/src/ltc/pk/ecc/ecc_set_dp_internal.c @@ -16,52 +16,52 @@ static void _ecc_oid_lookup(ecc_key *key) int err; unsigned i; void *tmp; - const ltc_ecc_set_type *set; + const ltc_ecc_curve *curve; key->dp.oidlen = 0; if ((err = mp_init(&tmp)) != CRYPT_OK) return; - for (set = ltc_ecc_sets; set->name != NULL; set++) { - if ((err = mp_read_radix(tmp, set->prime, 16)) != CRYPT_OK) continue; + for (curve = ltc_ecc_curves; curve->prime != NULL; curve++) { + if ((err = mp_read_radix(tmp, curve->prime, 16)) != CRYPT_OK) continue; if ((mp_cmp(tmp, key->dp.prime) != LTC_MP_EQ)) continue; - if ((err = mp_read_radix(tmp, set->order, 16)) != CRYPT_OK) continue; + if ((err = mp_read_radix(tmp, curve->order, 16)) != CRYPT_OK) continue; if ((mp_cmp(tmp, key->dp.order) != LTC_MP_EQ)) continue; - if ((err = mp_read_radix(tmp, set->A, 16)) != CRYPT_OK) continue; + if ((err = mp_read_radix(tmp, curve->A, 16)) != CRYPT_OK) continue; if ((mp_cmp(tmp, key->dp.A) != LTC_MP_EQ)) continue; - if ((err = mp_read_radix(tmp, set->B, 16)) != CRYPT_OK) continue; + if ((err = mp_read_radix(tmp, curve->B, 16)) != CRYPT_OK) continue; if ((mp_cmp(tmp, key->dp.B) != LTC_MP_EQ)) continue; - if ((err = mp_read_radix(tmp, set->Gx, 16)) != CRYPT_OK) continue; + if ((err = mp_read_radix(tmp, curve->Gx, 16)) != CRYPT_OK) continue; if ((mp_cmp(tmp, key->dp.base.x) != LTC_MP_EQ)) continue; - if ((err = mp_read_radix(tmp, set->Gy, 16)) != CRYPT_OK) continue; + if ((err = mp_read_radix(tmp, curve->Gy, 16)) != CRYPT_OK) continue; if ((mp_cmp(tmp, key->dp.base.y) != LTC_MP_EQ)) continue; - if (key->dp.cofactor != set->cofactor) continue; + if (key->dp.cofactor != curve->cofactor) continue; break; /* found */ } mp_clear(tmp); - if (set->name != NULL) { + if (curve->prime != NULL) { /* OID found */ - key->dp.oidlen = set->oidlen; - for(i = 0; i < set->oidlen; i++) key->dp.oid[i] = set->oid[i]; + key->dp.oidlen = curve->oidlen; + for(i = 0; i < curve->oidlen; i++) key->dp.oid[i] = curve->oid[i]; } } -int ecc_set_dp_oid(unsigned long *oid, unsigned long oidsize, ecc_key *key) +int ecc_set_dp_by_oid(unsigned long *oid, unsigned long oidsize, ecc_key *key) { int i; LTC_ARGCHK(oid != NULL); LTC_ARGCHK(oidsize > 0); - for(i = 0; ltc_ecc_sets[i].name != NULL; i++) { - if ((oidsize == ltc_ecc_sets[i].oidlen) && - (XMEM_NEQ(oid, ltc_ecc_sets[i].oid, sizeof(unsigned long) * ltc_ecc_sets[i].oidlen) == 0)) { + for(i = 0; ltc_ecc_curves[i].prime != NULL; i++) { + if ((oidsize == ltc_ecc_curves[i].oidlen) && + (XMEM_NEQ(oid, ltc_ecc_curves[i].oid, sizeof(unsigned long) * ltc_ecc_curves[i].oidlen) == 0)) { break; } } - if (ltc_ecc_sets[i].name == NULL) return CRYPT_ERROR; /* not found */ - return ecc_set_dp(<c_ecc_sets[i], key); + if (ltc_ecc_curves[i].prime == NULL) return CRYPT_ERROR; /* not found */ + return ecc_set_dp(<c_ecc_curves[i], key); } -int ecc_set_dp_copy(ecc_key *srckey, ecc_key *key) +int ecc_copy_dp(const ecc_key *srckey, ecc_key *key) { unsigned long i; int err; @@ -81,9 +81,7 @@ int ecc_set_dp_copy(ecc_key *srckey, ecc_key *key) if ((err = mp_copy(srckey->dp.order, key->dp.order )) != CRYPT_OK) { goto error; } if ((err = mp_copy(srckey->dp.A, key->dp.A )) != CRYPT_OK) { goto error; } if ((err = mp_copy(srckey->dp.B, key->dp.B )) != CRYPT_OK) { goto error; } - if ((err = mp_copy(srckey->dp.base.x, key->dp.base.x)) != CRYPT_OK) { goto error; } - if ((err = mp_copy(srckey->dp.base.y, key->dp.base.y)) != CRYPT_OK) { goto error; } - if ((err = mp_copy(srckey->dp.base.z, key->dp.base.z)) != CRYPT_OK) { goto error; } + if ((err = ltc_ecc_copy_point(&srckey->dp.base, &key->dp.base)) != CRYPT_OK) { goto error; } /* cofactor & size */ key->dp.cofactor = srckey->dp.cofactor; key->dp.size = srckey->dp.size; @@ -93,7 +91,7 @@ int ecc_set_dp_copy(ecc_key *srckey, ecc_key *key) for (i = 0; i < key->dp.oidlen; i++) key->dp.oid[i] = srckey->dp.oid[i]; } else { - _ecc_oid_lookup(key); /* try to find OID in ltc_ecc_sets */ + _ecc_oid_lookup(key); /* try to find OID in ltc_ecc_curves */ } /* success */ return CRYPT_OK; @@ -103,7 +101,7 @@ error: return err; } -int ecc_set_dp_bn(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key) +int ecc_set_dp_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key) { int err; @@ -133,7 +131,7 @@ int ecc_set_dp_bn(void *a, void *b, void *prime, void *order, void *gx, void *gy /* cofactor & size */ key->dp.cofactor = cofactor; key->dp.size = mp_unsigned_bin_size(prime); - /* try to find OID in ltc_ecc_sets */ + /* try to find OID in ltc_ecc_curves */ _ecc_oid_lookup(key); /* success */ return CRYPT_OK; diff --git a/src/ltc/pk/ecc/ecc_sign_hash.c b/src/ltc/pk/ecc/ecc_sign_hash.c index 87e95060..f17e96c2 100644 --- a/src/ltc/pk/ecc/ecc_sign_hash.c +++ b/src/ltc/pk/ecc/ecc_sign_hash.c @@ -67,7 +67,7 @@ static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen, /* make up a key and export the public copy */ do { - if ((err = ecc_set_dp_copy(key, &pubkey)) != CRYPT_OK) { goto errnokey; } + if ((err = ecc_copy_dp(key, &pubkey)) != CRYPT_OK) { goto errnokey; } if ((err = ecc_generate_key(prng, wprng, &pubkey)) != CRYPT_OK) { goto errnokey; } /* find r = x1 mod n */ diff --git a/src/ltc/pk/ecc/ecc_sizes.c b/src/ltc/pk/ecc/ecc_sizes.c index dcd310c8..165c849c 100644 --- a/src/ltc/pk/ecc/ecc_sizes.c +++ b/src/ltc/pk/ecc/ecc_sizes.c @@ -28,8 +28,8 @@ void ecc_sizes(int *low, int *high) *high = 0; if (mp_init(&prime) == CRYPT_OK) { - for (i = 0; ltc_ecc_sets[i].name != NULL; i++) { - if (mp_read_radix(prime, ltc_ecc_sets[i].prime, 16) == CRYPT_OK) { + for (i = 0; ltc_ecc_curves[i].prime != NULL; i++) { + if (mp_read_radix(prime, ltc_ecc_curves[i].prime, 16) == CRYPT_OK) { size = mp_unsigned_bin_size(prime); if (size < *low) *low = size; if (size > *high) *high = size; diff --git a/src/ltc/pk/ecc/ecc_verify_hash.c b/src/ltc/pk/ecc/ecc_verify_hash.c index 34a49041..3dd2abb3 100644 --- a/src/ltc/pk/ecc/ecc_verify_hash.c +++ b/src/ltc/pk/ecc/ecc_verify_hash.c @@ -109,12 +109,8 @@ static int _ecc_verify_hash(const unsigned char *sig, unsigned long siglen, if ((err = mp_mulmod(r, w, p, u2)) != CRYPT_OK) { goto error; } /* find mG and mQ */ - if ((err = mp_copy(key->dp.base.x, mG->x)) != CRYPT_OK) { goto error; } - if ((err = mp_copy(key->dp.base.y, mG->y)) != CRYPT_OK) { goto error; } - if ((err = mp_copy(key->dp.base.z, mG->z)) != CRYPT_OK) { goto error; } - if ((err = mp_copy(key->pubkey.x, mQ->x)) != CRYPT_OK) { goto error; } - if ((err = mp_copy(key->pubkey.y, mQ->y)) != CRYPT_OK) { goto error; } - if ((err = mp_copy(key->pubkey.z, mQ->z)) != CRYPT_OK) { goto error; } + if ((err = ltc_ecc_copy_point(&key->dp.base, mG)) != CRYPT_OK) { goto error; } + if ((err = ltc_ecc_copy_point(&key->pubkey, mQ)) != CRYPT_OK) { goto error; } /* find the montgomery mp */ if ((err = mp_montgomery_setup(m, &mp)) != CRYPT_OK) { goto error; } diff --git a/src/ltc/pk/ecc/ltc_ecc_import_point.c b/src/ltc/pk/ecc/ltc_ecc_import_point.c index 6c8107c8..7e103f47 100644 --- a/src/ltc/pk/ecc/ltc_ecc_import_point.c +++ b/src/ltc/pk/ecc/ltc_ecc_import_point.c @@ -31,8 +31,8 @@ int ltc_ecc_import_point(const unsigned char *in, unsigned long inlen, void *pri /* load y */ if ((err = mp_read_unsigned_bin(y, (unsigned char *)in+1+size, size)) != CRYPT_OK) { goto cleanup; } } - else if ((in[0] == 0x02 || in[0] == 0x03) && (inlen-1) == size) { - /* read compressed point */ + else if ((in[0] == 0x02 || in[0] == 0x03) && (inlen-1) == size && ltc_mp.sqrtmod_prime != NULL) { + /* read compressed point - BEWARE: requires sqrtmod_prime */ /* load x */ if ((err = mp_read_unsigned_bin(x, (unsigned char *)in+1, size)) != CRYPT_OK) { goto cleanup; } /* compute x^3 */ diff --git a/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c b/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c index 87f3b0c3..faf7631d 100644 --- a/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c +++ b/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c @@ -15,16 +15,22 @@ * a point at infinity is any point (x,y,0) such that y^2 == x^3, except (0,0,0) */ -int ltc_ecc_is_point_at_infinity(const ecc_point *P, void *modulus) +int ltc_ecc_is_point_at_infinity(const ecc_point *P, void *modulus, int *retval) { - int err, retval = 0; + int err; void *x3, *y2; /* trivial case */ - if (!mp_iszero(P->z)) goto done; + if (!mp_iszero(P->z)) { + *retval = 0; + return CRYPT_OK; + } /* point (0,0,0) is not at infinity */ - if (mp_iszero(P->x) && mp_iszero(P->y)) goto done; + if (mp_iszero(P->x) && mp_iszero(P->y)) { + *retval = 0; + return CRYPT_OK; + } /* initialize */ if ((err = mp_init_multi(&x3, &y2, NULL)) != CRYPT_OK) goto done; @@ -37,12 +43,16 @@ int ltc_ecc_is_point_at_infinity(const ecc_point *P, void *modulus) if ((err = mp_mulmod(P->x, x3, modulus, x3)) != CRYPT_OK) goto cleanup; /* test y^2 == x^3 */ - if ((mp_cmp(x3, y2) == LTC_MP_EQ) && !mp_iszero(y2)) retval = 1; + err = CRYPT_OK; + if ((mp_cmp(x3, y2) == LTC_MP_EQ) && !mp_iszero(y2)) + *retval = 1; + else + *retval = 0; cleanup: mp_clear_multi(x3, y2, NULL); done: - return retval; + return err; } #endif diff --git a/src/ltc/pk/ecc/ltc_ecc_map.c b/src/ltc/pk/ecc/ltc_ecc_map.c index 92d059d1..3c57019f 100644 --- a/src/ltc/pk/ecc/ltc_ecc_map.c +++ b/src/ltc/pk/ecc/ltc_ecc_map.c @@ -33,10 +33,7 @@ int ltc_ecc_map(ecc_point *P, void *modulus, void *mp) LTC_ARGCHK(mp != NULL); if (mp_iszero(P->z)) { - if ((err = mp_set(P->x, 0)) != CRYPT_OK) { return err; } - if ((err = mp_set(P->y, 0)) != CRYPT_OK) { return err; } - if ((err = mp_set(P->z, 1)) != CRYPT_OK) { return err; } - return CRYPT_OK; + return ltc_ecc_set_point_xyz(0, 0, 1, P); } if ((err = mp_init_multi(&t1, &t2, NULL)) != CRYPT_OK) { diff --git a/src/ltc/pk/ecc/ltc_ecc_mul2add.c b/src/ltc/pk/ecc/ltc_ecc_mul2add.c index 80ceb863..a2dcf5f2 100644 --- a/src/ltc/pk/ecc/ltc_ecc_mul2add.c +++ b/src/ltc/pk/ecc/ltc_ecc_mul2add.c @@ -163,9 +163,7 @@ int ltc_ecc_mul2add(const ecc_point *A, void *kA, if (first == 1) { /* if first, copy from table */ first = 0; - if ((err = mp_copy(precomp[nA + (nB<<2)]->x, C->x)) != CRYPT_OK) { goto ERR_MU; } - if ((err = mp_copy(precomp[nA + (nB<<2)]->y, C->y)) != CRYPT_OK) { goto ERR_MU; } - if ((err = mp_copy(precomp[nA + (nB<<2)]->z, C->z)) != CRYPT_OK) { goto ERR_MU; } + if ((err = ltc_ecc_copy_point(precomp[nA + (nB<<2)], C)) != CRYPT_OK) { goto ERR_MU; } } else { /* if not first, add from table */ if ((err = ltc_mp.ecc_ptadd(C, precomp[nA + (nB<<2)], C, ma, modulus, mp)) != CRYPT_OK) { goto ERR_MU; } diff --git a/src/ltc/pk/ecc/ltc_ecc_mulmod.c b/src/ltc/pk/ecc/ltc_ecc_mulmod.c index 50dedc16..ec8ba9cf 100644 --- a/src/ltc/pk/ecc/ltc_ecc_mulmod.c +++ b/src/ltc/pk/ecc/ltc_ecc_mulmod.c @@ -32,7 +32,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *modulus, int map) { ecc_point *tG, *M[8]; - int i, j, err; + int i, j, err, inf; void *mp = NULL, *mu = NULL, *ma = NULL, *a_plus3 = NULL; ltc_mp_digit buf; int first, bitbuf, bitcpy, bitcnt, mode, digidx; @@ -42,12 +42,10 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod LTC_ARGCHK(R != NULL); LTC_ARGCHK(modulus != NULL); - if (ltc_ecc_is_point_at_infinity(G, modulus)) { + if ((err = ltc_ecc_is_point_at_infinity(G, modulus, &inf)) != CRYPT_OK) return err; + if (inf) { /* return the point at infinity */ - if ((err = mp_set(R->x, 1)) != CRYPT_OK) { return err; } - if ((err = mp_set(R->y, 1)) != CRYPT_OK) { return err; } - if ((err = mp_set(R->z, 0)) != CRYPT_OK) { return err; } - return CRYPT_OK; + return ltc_ecc_set_point_xyz(1, 1, 0, R); } /* init montgomery reduction */ @@ -81,9 +79,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod /* tG = G and convert to montgomery */ if (mp_cmp_d(mu, 1) == LTC_MP_EQ) { - if ((err = mp_copy(G->x, tG->x)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(G->y, tG->y)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(G->z, tG->z)) != CRYPT_OK) { goto done; } + if ((err = ltc_ecc_copy_point(G, tG)) != CRYPT_OK) { goto done; } } else { if ((err = mp_mulmod(G->x, mu, modulus, tG->x)) != CRYPT_OK) { goto done; } if ((err = mp_mulmod(G->y, mu, modulus, tG->y)) != CRYPT_OK) { goto done; } @@ -146,9 +142,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod /* if this is the first window we do a simple copy */ if (first == 1) { /* R = kG [k = first window] */ - if ((err = mp_copy(M[bitbuf-8]->x, R->x)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(M[bitbuf-8]->y, R->y)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(M[bitbuf-8]->z, R->z)) != CRYPT_OK) { goto done; } + if ((err = ltc_ecc_copy_point(M[bitbuf-8], R)) != CRYPT_OK) { goto done; } first = 0; } else { /* normal window */ @@ -180,9 +174,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod if ((bitbuf & (1 << WINSIZE)) != 0) { if (first == 1){ /* first add, so copy */ - if ((err = mp_copy(tG->x, R->x)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(tG->y, R->y)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(tG->z, R->z)) != CRYPT_OK) { goto done; } + if ((err = ltc_ecc_copy_point(tG, R)) != CRYPT_OK) { goto done; } first = 0; } else { /* then add */ diff --git a/src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c b/src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c index 068240ae..9ff37d83 100644 --- a/src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c +++ b/src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c @@ -31,7 +31,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *modulus, int map) { ecc_point *tG, *M[3]; - int i, j, err; + int i, j, err, inf; void *mp = NULL, *mu = NULL, *ma = NULL, *a_plus3 = NULL; ltc_mp_digit buf; int bitcnt, mode, digidx; @@ -41,12 +41,10 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod LTC_ARGCHK(R != NULL); LTC_ARGCHK(modulus != NULL); - if (ltc_ecc_is_point_at_infinity(G, modulus)) { + if ((err = ltc_ecc_is_point_at_infinity(G, modulus, &inf)) != CRYPT_OK) return err; + if (inf) { /* return the point at infinity */ - if ((err = mp_set(R->x, 1)) != CRYPT_OK) { return err; } - if ((err = mp_set(R->y, 1)) != CRYPT_OK) { return err; } - if ((err = mp_set(R->z, 0)) != CRYPT_OK) { return err; } - return CRYPT_OK; + return ltc_ecc_set_point_xyz(1, 1, 0, R); } /* init montgomery reduction */ @@ -88,9 +86,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod /* calc the M tab */ /* M[0] == G */ - if ((err = mp_copy(tG->x, M[0]->x)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(tG->y, M[0]->y)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(tG->z, M[0]->z)) != CRYPT_OK) { goto done; } + if ((err = ltc_ecc_copy_point(tG, M[0])) != CRYPT_OK) { goto done; } /* M[1] == 2G */ if ((err = ltc_mp.ecc_ptdbl(tG, M[1], ma, modulus, mp)) != CRYPT_OK) { goto done; } @@ -136,9 +132,7 @@ int ltc_ecc_mulmod(void *k, const ecc_point *G, ecc_point *R, void *a, void *mod } /* copy result out */ - if ((err = mp_copy(M[0]->x, R->x)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(M[0]->y, R->y)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(M[0]->z, R->z)) != CRYPT_OK) { goto done; } + if ((err = ltc_ecc_copy_point(M[0], R)) != CRYPT_OK) { goto done; } /* map R back from projective space */ if (map) { diff --git a/src/ltc/pk/ecc/ltc_ecc_points.c b/src/ltc/pk/ecc/ltc_ecc_points.c index 772e8efd..4a890fdc 100644 --- a/src/ltc/pk/ecc/ltc_ecc_points.c +++ b/src/ltc/pk/ecc/ltc_ecc_points.c @@ -46,6 +46,24 @@ void ltc_ecc_del_point(ecc_point *p) } } +int ltc_ecc_set_point_xyz(ltc_mp_digit x, ltc_mp_digit y, ltc_mp_digit z, ecc_point *p) +{ + int err; + if ((err = ltc_mp.set_int(p->x, x)) != CRYPT_OK) return err; + if ((err = ltc_mp.set_int(p->y, y)) != CRYPT_OK) return err; + if ((err = ltc_mp.set_int(p->z, z)) != CRYPT_OK) return err; + return CRYPT_OK; +} + +int ltc_ecc_copy_point(const ecc_point *src, ecc_point *dst) +{ + int err; + if ((err = ltc_mp.copy(src->x, dst->x)) != CRYPT_OK) return err; + if ((err = ltc_mp.copy(src->y, dst->y)) != CRYPT_OK) return err; + if ((err = ltc_mp.copy(src->z, dst->z)) != CRYPT_OK) return err; + return CRYPT_OK; +} + #endif /* ref: $Format:%D$ */ /* git commit: $Format:%H$ */ diff --git a/src/ltc/pk/ecc/ltc_ecc_projective_add_point.c b/src/ltc/pk/ecc/ltc_ecc_projective_add_point.c index 0182d0a8..eff35c93 100644 --- a/src/ltc/pk/ecc/ltc_ecc_projective_add_point.c +++ b/src/ltc/pk/ecc/ltc_ecc_projective_add_point.c @@ -29,7 +29,7 @@ int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_point *R, void *ma, void *modulus, void *mp) { void *t1, *t2, *x, *y, *z; - int err; + int err, inf; LTC_ARGCHK(P != NULL); LTC_ARGCHK(Q != NULL); @@ -41,20 +41,18 @@ int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_poi return err; } - if (ltc_ecc_is_point_at_infinity(P, modulus)) { + if ((err = ltc_ecc_is_point_at_infinity(P, modulus, &inf)) != CRYPT_OK) return err; + if (inf) { /* P is point at infinity >> Result = Q */ - if ((err = ltc_mp.copy(Q->x, R->x)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.copy(Q->y, R->y)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.copy(Q->z, R->z)) != CRYPT_OK) { goto done; } - goto done; /* CRYPT_OK */ + err = ltc_ecc_copy_point(Q, R); + goto done; } - if (ltc_ecc_is_point_at_infinity(Q, modulus)) { + if ((err = ltc_ecc_is_point_at_infinity(Q, modulus, &inf)) != CRYPT_OK) return err; + if (inf) { /* Q is point at infinity >> Result = P */ - if ((err = ltc_mp.copy(P->x, R->x)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.copy(P->y, R->y)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.copy(P->z, R->z)) != CRYPT_OK) { goto done; } - goto done; /* CRYPT_OK */ + err = ltc_ecc_copy_point(P, R); + goto done; } if ((mp_cmp(P->x, Q->x) == LTC_MP_EQ) && (mp_cmp(P->z, Q->z) == LTC_MP_EQ)) { @@ -66,10 +64,8 @@ int ltc_ecc_projective_add_point(const ecc_point *P, const ecc_point *Q, ecc_poi if ((err = mp_sub(modulus, Q->y, t1)) != CRYPT_OK) { goto done; } if (mp_cmp(P->y, t1) == LTC_MP_EQ) { /* here Q = -P >>> Result = the point at infinity */ - if ((err = ltc_mp.set_int(R->x, 1)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.set_int(R->y, 1)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.set_int(R->z, 0)) != CRYPT_OK) { goto done; } - goto done; /* CRYPT_OK */ + err = ltc_ecc_set_point_xyz(1, 1, 0, R); + goto done; } } diff --git a/src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c b/src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c index 57cfd6fd..1b46457b 100644 --- a/src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c +++ b/src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c @@ -46,7 +46,7 @@ int ltc_ecc_projective_dbl_point(const ecc_point *P, ecc_point *R, void *ma, void *modulus, void *mp) { void *t1, *t2; - int err; + int err, inf; LTC_ARGCHK(P != NULL); LTC_ARGCHK(R != NULL); @@ -58,17 +58,14 @@ int ltc_ecc_projective_dbl_point(const ecc_point *P, ecc_point *R, void *ma, voi } if (P != R) { - if ((err = mp_copy(P->x, R->x)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(P->y, R->y)) != CRYPT_OK) { goto done; } - if ((err = mp_copy(P->z, R->z)) != CRYPT_OK) { goto done; } + if ((err = ltc_ecc_copy_point(P, R)) != CRYPT_OK) { goto done; } } - if (ltc_ecc_is_point_at_infinity(P, modulus)) { + if ((err = ltc_ecc_is_point_at_infinity(P, modulus, &inf)) != CRYPT_OK) return err; + if (inf) { /* if P is point at infinity >> Result = point at infinity */ - if ((err = ltc_mp.set_int(R->x, 1)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.set_int(R->y, 1)) != CRYPT_OK) { goto done; } - if ((err = ltc_mp.set_int(R->z, 0)) != CRYPT_OK) { goto done; } - goto done; /* CRYPT_OK */ + err = ltc_ecc_set_point_xyz(1, 1, 0, R); + goto done; } /* t1 = Z * Z */ diff --git a/src/ltc/pk/ecc/ltc_ecc_verify_key.c b/src/ltc/pk/ecc/ltc_ecc_verify_key.c index b417465b..b04df5d1 100644 --- a/src/ltc/pk/ecc/ltc_ecc_verify_key.c +++ b/src/ltc/pk/ecc/ltc_ecc_verify_key.c @@ -21,7 +21,7 @@ int ltc_ecc_verify_key(ecc_key *key) { - int err; + int err, inf; void *prime = NULL; void *order = NULL; void *a = NULL; @@ -52,7 +52,8 @@ int ltc_ecc_verify_key(ecc_key *key) point = ltc_ecc_new_point(); if ((err = ltc_ecc_mulmod(order, &(key->pubkey), point, a, prime, 1)) != CRYPT_OK) { goto done1; } - if (ltc_ecc_is_point_at_infinity(point, prime)) { + err = ltc_ecc_is_point_at_infinity(point, prime, &inf); + if (err != CRYPT_OK || inf) { err = CRYPT_ERROR; } else { |