Fix issue with wc_ecc_import_x963_ex() and wc_ecc_import_raw_private() loosing heap pointer. Fixes issue #750.

This commit is contained in:
David Garske 2017-02-21 12:19:48 -08:00
parent db1f205522
commit 7125d16f3e
2 changed files with 8 additions and 3 deletions

View File

@ -3009,7 +3009,6 @@ int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
#endif
XMEMSET(key, 0, sizeof(ecc_key));
key->state = ECC_STATE_NONE;
#ifdef WOLFSSL_ATECC508A
key->slot = atmel_ecc_alloc();
@ -4469,6 +4468,7 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
#ifndef WOLFSSL_ATECC508A
int compressed = 0;
#endif /* !WOLFSSL_ATECC508A */
void* heap;
if (in == NULL || key == NULL)
return BAD_FUNC_ARG;
@ -4478,8 +4478,9 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
return ECC_BAD_ARG_E;
}
heap = key->heap; /* save heap */
XMEMSET(key, 0, sizeof(ecc_key));
key->state = ECC_STATE_NONE;
key->heap = heap; /* restore heap */
#ifdef WOLFSSL_ATECC508A
/* TODO: Implement equiv call to ATECC508A */
@ -4894,13 +4895,17 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
const char* qy, const char* d, int curve_id)
{
int err = MP_OKAY;
void* heap;
/* if d is NULL, only import as public key using Qx,Qy */
if (key == NULL || qx == NULL || qy == NULL) {
return BAD_FUNC_ARG;
}
heap = key->heap; /* save heap */
XMEMSET(key, 0, sizeof(ecc_key));
key->heap = heap; /* restore heap */
/* set curve type and index */
err = wc_ecc_set_curve(key, 0, curve_id);
if (err != 0) {