Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/api/test_ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ int test_wc_ecc_make_key(void)
#endif
ExpectIntEQ(ret, 0);

/* Generate again into the same key; the first private scalar and public
* point must be released, not orphaned. */
ret = wc_ecc_make_key(&rng, KEY14, &key);
#if defined(WOLFSSL_ASYNC_CRYPT)
ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
#endif
ExpectIntEQ(ret, 0);

/* Pass in bad args. */
ExpectIntEQ(wc_ecc_make_key(NULL, KEY14, &key),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
Expand Down
10 changes: 10 additions & 0 deletions wolfcrypt/src/ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5996,6 +5996,13 @@ static int ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curve,
ECC_PRIVATEKEY_ONLY */
pub = &key->pubkey;
key->type = ECC_PRIVATEKEY_ONLY;
#ifndef ALT_ECC_SIZE
/* wc_ecc_init() set up key->pubkey; free any digits a previous call
* grew before mp_init_multi() below drops them. */
mp_clear(pub->x);
mp_clear(pub->y);
mp_clear(pub->z);
#endif
}

if (err == MP_OKAY) {
Expand Down Expand Up @@ -6451,6 +6458,9 @@ static int _ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key,

/* setup the key variables */
#ifndef ALT_ECC_SIZE
/* wc_ecc_init() set up key->k; wipe and free any earlier private
* scalar before mp_init() below drops it. */
mp_forcezero(key->k);
err = mp_init(key->k);
#else
err = 0;
Expand Down
Loading