diff --git a/libtomcrypt_VS2008.vcproj b/libtomcrypt_VS2008.vcproj index da4fccab7..70d25ceae 100644 --- a/libtomcrypt_VS2008.vcproj +++ b/libtomcrypt_VS2008.vcproj @@ -2283,11 +2283,11 @@ > dp */ if (cu == NULL) { /* this case works only for uncompressed public keys */ - if ((err = ecc_set_dp_by_size((inlen-1)>>1, key)) != CRYPT_OK) { return err; } + if ((err = ecc_set_curve_by_size((inlen-1)>>1, key)) != CRYPT_OK) { return err; } } else { /* this one works for both compressed / uncompressed pubkeys */ - if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { return err; } + if ((err = ecc_set_curve(cu, key)) != CRYPT_OK) { return err; } } /* load public key */ diff --git a/src/pk/ecc/ecc_decrypt_key.c b/src/pk/ecc/ecc_decrypt_key.c index 8c29a1744..d6b825e8e 100644 --- a/src/pk/ecc/ecc_decrypt_key.c +++ b/src/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_copy_dp(key, &pubkey)) != CRYPT_OK) { goto LBL_ERR; } + if ((err = ecc_copy_curve(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/pk/ecc/ecc_encrypt_key.c b/src/pk/ecc/ecc_encrypt_key.c index 17201df6e..2ea7e35db 100644 --- a/src/pk/ecc/ecc_encrypt_key.c +++ b/src/pk/ecc/ecc_encrypt_key.c @@ -52,7 +52,7 @@ int ecc_encrypt_key(const unsigned char *in, unsigned long inlen, } /* make a random key and export the public copy */ - if ((err = ecc_copy_dp(key, &pubkey)) != CRYPT_OK) { return err; } + if ((err = ecc_copy_curve(key, &pubkey)) != CRYPT_OK) { return err; } if ((err = ecc_generate_key(prng, wprng, &pubkey)) != CRYPT_OK) { return err; } pub_expt = XMALLOC(ECC_BUF_SIZE); diff --git a/src/pk/ecc/ecc_get_curve.c b/src/pk/ecc/ecc_find_curve.c similarity index 98% rename from src/pk/ecc/ecc_get_curve.c rename to src/pk/ecc/ecc_find_curve.c index a9246793f..d9544fd8e 100644 --- a/src/pk/ecc/ecc_get_curve.c +++ b/src/pk/ecc/ecc_find_curve.c @@ -212,7 +212,7 @@ static int _name_match(const char *left, const char *right) return 0; } -int ecc_get_curve(const char *name_or_oid, const ltc_ecc_curve **cu) +int ecc_find_curve(const char *name_or_oid, const ltc_ecc_curve **cu) { int i, j; const char *OID = NULL; diff --git a/src/pk/ecc/ecc_import.c b/src/pk/ecc/ecc_import.c index e691add59..74097a7d6 100644 --- a/src/pk/ecc/ecc_import.c +++ b/src/pk/ecc/ecc_import.c @@ -56,9 +56,9 @@ int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, co /* allocate & initialize the key */ if (cu == NULL) { - if ((err = ecc_set_dp_by_size(key_size, key)) != CRYPT_OK) { goto done; } + if ((err = ecc_set_curve_by_size(key_size, key)) != CRYPT_OK) { goto done; } } else { - if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { goto done; } + if ((err = ecc_set_curve(cu, key)) != CRYPT_OK) { goto done; } } if (flags[0] == 1) { diff --git a/src/pk/ecc/ecc_import_openssl.c b/src/pk/ecc/ecc_import_openssl.c index a4b2cf509..e7650912d 100644 --- a/src/pk/ecc/ecc_import_openssl.c +++ b/src/pk/ecc/ecc_import_openssl.c @@ -36,8 +36,8 @@ static int _ecc_import_private_with_oid(const unsigned char *in, unsigned long i /* load curve parameters for given curve OID */ len = sizeof(OID); if ((err = pk_oid_num_to_str(curveoid, custom[0].size, OID, &len)) != CRYPT_OK) { goto error; } - if ((err = ecc_get_curve(OID, &curve)) != CRYPT_OK) { goto error; } - if ((err = ecc_set_dp(curve, key)) != CRYPT_OK) { goto error; } + if ((err = ecc_find_curve(OID, &curve)) != CRYPT_OK) { goto error; } + if ((err = ecc_set_curve(curve, key)) != CRYPT_OK) { goto error; } /* load private+public key */ err = ecc_set_key(bin_k, seq_priv[1].size, PK_PRIVATE, key); } @@ -96,7 +96,7 @@ static int _ecc_import_private_with_curve(const unsigned char *in, unsigned long 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_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; } + if ((err = ecc_set_curve_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; } /* load private+public key */ err = ecc_set_key(bin_k, len_k, PK_PRIVATE, key); } diff --git a/src/pk/ecc/ecc_import_x509.c b/src/pk/ecc/ecc_import_x509.c index 2e7eb10c5..99a27507d 100644 --- a/src/pk/ecc/ecc_import_x509.c +++ b/src/pk/ecc/ecc_import_x509.c @@ -27,8 +27,8 @@ static int _ecc_import_x509_with_oid(const unsigned char *in, unsigned long inle /* load curve parameters for given curve OID */ len = sizeof(OID); if ((err = pk_oid_num_to_str(curveoid, len_oid, OID, &len)) != CRYPT_OK) { goto error; } - if ((err = ecc_get_curve(OID, &curve)) != CRYPT_OK) { goto error; } - if ((err = ecc_set_dp(curve, key)) != CRYPT_OK) { goto error; } + if ((err = ecc_find_curve(OID, &curve)) != CRYPT_OK) { goto error; } + if ((err = ecc_set_curve(curve, key)) != CRYPT_OK) { goto error; } /* load public key */ err = ecc_set_key(bin_xy, len_xy, PK_PUBLIC, key); } @@ -80,7 +80,7 @@ static int _ecc_import_x509_with_curve(const unsigned char *in, unsigned long in 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_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; } + if ((err = ecc_set_curve_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; } /* load public key */ err = ecc_set_key(bin_xy, len_xy, PK_PUBLIC, key); } diff --git a/src/pk/ecc/ecc_make_key.c b/src/pk/ecc/ecc_make_key.c index da595850c..4a8f91efd 100644 --- a/src/pk/ecc/ecc_make_key.c +++ b/src/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_by_size(keysize, key)) != CRYPT_OK) { return err; } - if ((err = ecc_generate_key(prng, wprng, key)) != CRYPT_OK) { return err; } + if ((err = ecc_set_curve_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_curve *cu) { int err; - if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { return err; } + if ((err = ecc_set_curve(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/pk/ecc/ecc_set_dp.c b/src/pk/ecc/ecc_set_curve.c similarity index 80% rename from src/pk/ecc/ecc_set_dp.c rename to src/pk/ecc/ecc_set_curve.c index 83ad30ac6..9fa44fdd2 100644 --- a/src/pk/ecc/ecc_set_dp.c +++ b/src/pk/ecc/ecc_set_curve.c @@ -11,7 +11,7 @@ #ifdef LTC_MECC -int ecc_set_dp(const ltc_ecc_curve *cu, ecc_key *key) +int ecc_set_curve(const ltc_ecc_curve *cu, ecc_key *key) { int err; @@ -47,38 +47,38 @@ int ecc_set_dp(const ltc_ecc_curve *cu, ecc_key *key) return err; } -int ecc_set_dp_by_size(int size, ecc_key *key) +int ecc_set_curve_by_size(int size, ecc_key *key) { 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) { - err = ecc_get_curve("SECP112R1", &cu); + err = ecc_find_curve("SECP112R1", &cu); } else if (size <= 16) { - err = ecc_get_curve("SECP128R1", &cu); + err = ecc_find_curve("SECP128R1", &cu); } else if (size <= 20) { - err = ecc_get_curve("SECP160R1", &cu); + err = ecc_find_curve("SECP160R1", &cu); } else if (size <= 24) { - err = ecc_get_curve("SECP192R1", &cu); + err = ecc_find_curve("SECP192R1", &cu); } else if (size <= 28) { - err = ecc_get_curve("SECP224R1", &cu); + err = ecc_find_curve("SECP224R1", &cu); } else if (size <= 32) { - err = ecc_get_curve("SECP256R1", &cu); + err = ecc_find_curve("SECP256R1", &cu); } else if (size <= 48) { - err = ecc_get_curve("SECP384R1", &cu); + err = ecc_find_curve("SECP384R1", &cu); } else if (size <= 66) { - err = ecc_get_curve("SECP521R1", &cu); + err = ecc_find_curve("SECP521R1", &cu); } - if (err == CRYPT_OK && cu != NULL) return ecc_set_dp(cu, key); + if (err == CRYPT_OK && cu != NULL) return ecc_set_curve(cu, key); return CRYPT_INVALID_ARG; } diff --git a/src/pk/ecc/ecc_set_dp_internal.c b/src/pk/ecc/ecc_set_curve_internal.c similarity index 95% rename from src/pk/ecc/ecc_set_dp_internal.c rename to src/pk/ecc/ecc_set_curve_internal.c index cf9020bf0..aed515ca4 100644 --- a/src/pk/ecc/ecc_set_dp_internal.c +++ b/src/pk/ecc/ecc_set_curve_internal.c @@ -42,7 +42,7 @@ static void _ecc_oid_lookup(ecc_key *key) } } -int ecc_copy_dp(const ecc_key *srckey, ecc_key *key) +int ecc_copy_curve(const ecc_key *srckey, ecc_key *key) { unsigned long i; int err; @@ -82,7 +82,7 @@ int ecc_copy_dp(const ecc_key *srckey, ecc_key *key) return err; } -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 ecc_set_curve_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key) { int err; diff --git a/src/pk/ecc/ecc_sign_hash.c b/src/pk/ecc/ecc_sign_hash.c index bad5286ce..3302b0772 100644 --- a/src/pk/ecc/ecc_sign_hash.c +++ b/src/pk/ecc/ecc_sign_hash.c @@ -63,7 +63,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_copy_dp(key, &pubkey)) != CRYPT_OK) { goto errnokey; } + if ((err = ecc_copy_curve(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/tests/ecc_test.c b/tests/ecc_test.c index d5241597f..55d6f541f 100644 --- a/tests/ecc_test.c +++ b/tests/ecc_test.c @@ -130,7 +130,7 @@ static int _ecc_issue108(void) Result = ltc_ecc_new_point(); /* ECC-224 AKA SECP224R1 */ - if ((err = ecc_get_curve("SECP224R1", &dp)) != CRYPT_OK) { goto done; } + if ((err = ecc_find_curve("SECP224R1", &dp)) != CRYPT_OK) { goto done; } /* read A */ if ((err = mp_read_radix(a, (char *)dp->A, 16)) != CRYPT_OK) { goto done; } /* read modulus */ @@ -446,7 +446,7 @@ int _ecc_new_api(void) unsigned long len16; for (i = 0; i < (int)(sizeof(names)/sizeof(names[0])); i++) { - DO(ecc_get_curve(names[i], &dp)); + DO(ecc_find_curve(names[i], &dp)); /* make new key */ DO(ecc_make_key_ex(&yarrow_prng, find_prng ("yarrow"), &key, dp)); len = sizeof(buf); @@ -464,14 +464,14 @@ int _ecc_new_api(void) ecc_free(&pubkey); /* generate new key */ - DO(ecc_set_dp(dp, &key)); + DO(ecc_set_curve(dp, &key)); DO(ecc_generate_key(&yarrow_prng, find_prng ("yarrow"), &key)); len = sizeof(buf); DO(ecc_get_key(buf, &len, PK_PRIVATE, &key)); ecc_free(&key); /* load exported private key */ - DO(ecc_set_dp(dp, &privkey)); + DO(ecc_set_curve(dp, &privkey)); DO(ecc_set_key(buf, len, PK_PRIVATE, &privkey)); #ifndef USE_TFM @@ -481,7 +481,7 @@ int _ecc_new_api(void) DO(ecc_get_key(buf, &len, PK_PUBLIC|PK_COMPRESSED, &privkey)); if (len != 1 + (unsigned)ecc_get_size(&privkey)) return CRYPT_FAIL_TESTVECTOR; /* load exported public+compressed key */ - DO(ecc_set_dp(dp, &pubkey)); + DO(ecc_set_curve(dp, &pubkey)); DO(ecc_set_key(buf, len, PK_PUBLIC, &pubkey)); ecc_free(&pubkey); #endif @@ -491,7 +491,7 @@ int _ecc_new_api(void) DO(ecc_get_key(buf, &len, PK_PUBLIC, &privkey)); if (len != 1 + 2 * (unsigned)ecc_get_size(&privkey)) return CRYPT_FAIL_TESTVECTOR; /* load exported public key */ - DO(ecc_set_dp(dp, &pubkey)); + DO(ecc_set_curve(dp, &pubkey)); DO(ecc_set_key(buf, len, PK_PUBLIC, &pubkey)); /* test signature */ @@ -798,18 +798,18 @@ int _ecc_import_export(void) { DO(ecc_import_openssl(short_pub, sizeof(short_pub), &pub)); DO(ecc_import_openssl(short_pri, sizeof(short_pri), &pri)); - DO(ecc_get_curve("SECP256K1", &cu)); + DO(ecc_find_curve("SECP256K1", &cu)); /* import - raw keys */ - DO(ecc_set_dp(cu, &key)); + DO(ecc_set_curve(cu, &key)); DO(ecc_set_key(raw_pri, sizeof(raw_pri), PK_PRIVATE, &key)); DO(_ecc_key_cmp(PK_PRIVATE, &pri, &key)); ecc_free(&key); - DO(ecc_set_dp(cu, &key)); + DO(ecc_set_curve(cu, &key)); DO(ecc_set_key(raw_pub, sizeof(raw_pub), PK_PUBLIC, &key)); DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key)); ecc_free(&key); - DO(ecc_set_dp(cu, &key)); + DO(ecc_set_curve(cu, &key)); DO(ecc_set_key(raw_pubc, sizeof(raw_pubc), PK_PUBLIC, &key)); DO(_ecc_key_cmp(PK_PUBLIC, &pub, &key)); ecc_free(&key);