group->curve_nid is now set to the real NID of the curve

This commit is contained in:
Juliusz Sosinowicz
2020-03-20 20:41:28 +01:00
parent 4a167c0f2c
commit e131d6be5b
2 changed files with 8 additions and 11 deletions

View File

@ -31855,15 +31855,9 @@ WOLFSSL_EC_KEY *wolfSSL_EC_KEY_new_by_curve_name(int nid)
{
WOLFSSL_EC_KEY *key;
int x;
int eccEnum;
WOLFSSL_ENTER("wolfSSL_EC_KEY_new_by_curve_name");
/* If NID passed in is OpenSSL type, convert it to ecc_curve_id enum */
eccEnum = NIDToEccEnum(nid);
if (eccEnum == -1)
eccEnum = nid;
key = wolfSSL_EC_KEY_new();
if (key == NULL) {
WOLFSSL_MSG("wolfSSL_EC_KEY_new failure");
@ -31871,7 +31865,7 @@ WOLFSSL_EC_KEY *wolfSSL_EC_KEY_new_by_curve_name(int nid)
}
/* set the nid of the curve */
key->group->curve_nid = eccEnum;
key->group->curve_nid = nid;
/* search and set the corresponding internal curve idx */
for (x = 0; ecc_sets[x].size != 0; x++)
@ -32117,8 +32111,11 @@ int wolfSSL_EC_KEY_generate_key(WOLFSSL_EC_KEY *key)
return 0;
}
/* NIDToEccEnum return -1 for invalid NID so if key->group->curve_nid
* is 0 then pass 0 as arg */
if (wc_ecc_make_key_ex(rng, 0, (ecc_key*)key->internal,
key->group->curve_nid) != MP_OKAY) {
key->group->curve_nid ? NIDToEccEnum(key->group->curve_nid) : 0
) != MP_OKAY) {
WOLFSSL_MSG("wolfSSL_EC_KEY_generate_key wc_ecc_make_key failed");
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpRNG, NULL, DYNAMIC_TYPE_RNG);

View File

@ -2136,7 +2136,7 @@ static void test_ECDSA_size_sign(void)
id = wc_ecc_get_curve_id_from_name("SECP256R1");
AssertIntEQ(id, ECC_SECP256R1);
AssertNotNull(key = wolfSSL_EC_KEY_new_by_curve_name(id));
AssertNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
AssertIntEQ(EC_KEY_generate_key(key), 1);
AssertIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
AssertIntGE(ECDSA_size(key), sigSz);
@ -32246,10 +32246,10 @@ static void test_wc_ecc_get_curve_id_from_dp_params(void)
id = wc_ecc_get_curve_id_from_name("SECP256R1");
AssertIntEQ(id, ECC_SECP256R1);
ecKey = wolfSSL_EC_KEY_new_by_curve_name(id);
ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
AssertNotNull(ecKey);
ret = wolfSSL_EC_KEY_generate_key(ecKey);
ret = EC_KEY_generate_key(ecKey);
if (ret == 0) {
/* normal test */