forked from wolfSSL/wolfssl
group->curve_nid is now set to the real NID of the curve
This commit is contained in:
13
src/ssl.c
13
src/ssl.c
@ -31855,15 +31855,9 @@ WOLFSSL_EC_KEY *wolfSSL_EC_KEY_new_by_curve_name(int nid)
|
|||||||
{
|
{
|
||||||
WOLFSSL_EC_KEY *key;
|
WOLFSSL_EC_KEY *key;
|
||||||
int x;
|
int x;
|
||||||
int eccEnum;
|
|
||||||
|
|
||||||
WOLFSSL_ENTER("wolfSSL_EC_KEY_new_by_curve_name");
|
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();
|
key = wolfSSL_EC_KEY_new();
|
||||||
if (key == NULL) {
|
if (key == NULL) {
|
||||||
WOLFSSL_MSG("wolfSSL_EC_KEY_new failure");
|
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 */
|
/* set the nid of the curve */
|
||||||
key->group->curve_nid = eccEnum;
|
key->group->curve_nid = nid;
|
||||||
|
|
||||||
/* search and set the corresponding internal curve idx */
|
/* search and set the corresponding internal curve idx */
|
||||||
for (x = 0; ecc_sets[x].size != 0; x++)
|
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;
|
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,
|
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");
|
WOLFSSL_MSG("wolfSSL_EC_KEY_generate_key wc_ecc_make_key failed");
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
XFREE(tmpRNG, NULL, DYNAMIC_TYPE_RNG);
|
XFREE(tmpRNG, NULL, DYNAMIC_TYPE_RNG);
|
||||||
|
@ -2136,7 +2136,7 @@ static void test_ECDSA_size_sign(void)
|
|||||||
id = wc_ecc_get_curve_id_from_name("SECP256R1");
|
id = wc_ecc_get_curve_id_from_name("SECP256R1");
|
||||||
AssertIntEQ(id, ECC_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(EC_KEY_generate_key(key), 1);
|
||||||
AssertIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
|
AssertIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
|
||||||
AssertIntGE(ECDSA_size(key), sigSz);
|
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");
|
id = wc_ecc_get_curve_id_from_name("SECP256R1");
|
||||||
AssertIntEQ(id, ECC_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);
|
AssertNotNull(ecKey);
|
||||||
|
|
||||||
ret = wolfSSL_EC_KEY_generate_key(ecKey);
|
ret = EC_KEY_generate_key(ecKey);
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
/* normal test */
|
/* normal test */
|
||||||
|
Reference in New Issue
Block a user