forked from wolfSSL/wolfssl
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:
@ -3009,7 +3009,6 @@ int wc_ecc_init_ex(ecc_key* key, void* heap, int devId)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
XMEMSET(key, 0, sizeof(ecc_key));
|
XMEMSET(key, 0, sizeof(ecc_key));
|
||||||
key->state = ECC_STATE_NONE;
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
#ifdef WOLFSSL_ATECC508A
|
||||||
key->slot = atmel_ecc_alloc();
|
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
|
#ifndef WOLFSSL_ATECC508A
|
||||||
int compressed = 0;
|
int compressed = 0;
|
||||||
#endif /* !WOLFSSL_ATECC508A */
|
#endif /* !WOLFSSL_ATECC508A */
|
||||||
|
void* heap;
|
||||||
|
|
||||||
if (in == NULL || key == NULL)
|
if (in == NULL || key == NULL)
|
||||||
return BAD_FUNC_ARG;
|
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;
|
return ECC_BAD_ARG_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heap = key->heap; /* save heap */
|
||||||
XMEMSET(key, 0, sizeof(ecc_key));
|
XMEMSET(key, 0, sizeof(ecc_key));
|
||||||
key->state = ECC_STATE_NONE;
|
key->heap = heap; /* restore heap */
|
||||||
|
|
||||||
#ifdef WOLFSSL_ATECC508A
|
#ifdef WOLFSSL_ATECC508A
|
||||||
/* TODO: Implement equiv call to 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)
|
const char* qy, const char* d, int curve_id)
|
||||||
{
|
{
|
||||||
int err = MP_OKAY;
|
int err = MP_OKAY;
|
||||||
|
void* heap;
|
||||||
|
|
||||||
/* if d is NULL, only import as public key using Qx,Qy */
|
/* if d is NULL, only import as public key using Qx,Qy */
|
||||||
if (key == NULL || qx == NULL || qy == NULL) {
|
if (key == NULL || qx == NULL || qy == NULL) {
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heap = key->heap; /* save heap */
|
||||||
XMEMSET(key, 0, sizeof(ecc_key));
|
XMEMSET(key, 0, sizeof(ecc_key));
|
||||||
|
key->heap = heap; /* restore heap */
|
||||||
|
|
||||||
/* set curve type and index */
|
/* set curve type and index */
|
||||||
err = wc_ecc_set_curve(key, 0, curve_id);
|
err = wc_ecc_set_curve(key, 0, curve_id);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
@ -262,7 +262,7 @@ typedef struct ecc_key {
|
|||||||
int idx; /* Index into the ecc_sets[] for the parameters of
|
int idx; /* Index into the ecc_sets[] for the parameters of
|
||||||
this curve if -1, this key is using user supplied
|
this curve if -1, this key is using user supplied
|
||||||
curve in dp */
|
curve in dp */
|
||||||
int state;
|
int state;
|
||||||
word32 flags;
|
word32 flags;
|
||||||
const ecc_set_type* dp; /* domain parameters, either points to NIST
|
const ecc_set_type* dp; /* domain parameters, either points to NIST
|
||||||
curves (idx >= 0) or user supplied */
|
curves (idx >= 0) or user supplied */
|
||||||
|
Reference in New Issue
Block a user