From d0f31d4a30e5b84c88921544f1fa68cfce8f4692 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 11 Apr 2017 15:57:09 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20issue=20with=20`wc=5Fecc=5Fmake=5Fkey`=20?= =?UTF-8?q?where=20state=20failure=20can=20occur=20if=20the=20`wc=5Fecc=5F?= =?UTF-8?q?init`=20hasn=E2=80=99t=20been=20called=20on=20key=20prior.=20No?= =?UTF-8?q?w=20`wc=5Fecc=5Fmake=5Fkey`=20and=20`wc=5Fecc=5Fimport=5Fprivat?= =?UTF-8?q?e=5Fkey`=20(and=20=5Fex=20versions)=20can=20be=20called=20witho?= =?UTF-8?q?ut=20having=20to=20call=20`wc=5Fecc=5Finit`=20first.=20This=20k?= =?UTF-8?q?eeps=20backwards=20compatibility.=20If=20async=20or=20static=20?= =?UTF-8?q?memory=20is=20desired=20then=20`wc=5Fecc=5Finit=5Fex`=20must=20?= =?UTF-8?q?be=20called=20first.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wolfcrypt/src/ecc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 64824626f..e256d72b4 100755 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -3005,6 +3005,11 @@ int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key, int curve_id) return BAD_FUNC_ARG; } + /* make sure required key variables are reset */ + key->state = ECC_STATE_NONE; + key->idx = 0; + key->dp = NULL; + err = wc_ecc_set_curve(key, keysize, curve_id); if (err != 0) { return err; @@ -3255,6 +3260,7 @@ 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(); @@ -5083,7 +5089,6 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, int curve_id) { int ret; - void* heap; /* public optional, NULL if only importing private */ if (pub != NULL) { @@ -5095,15 +5100,10 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, if (key == NULL || priv == NULL) return BAD_FUNC_ARG; - /* init key */ - heap = key->heap; - ret = wc_ecc_init_ex(key, NULL, INVALID_DEVID); - key->heap = heap; - + /* make sure required key variables are reset */ key->state = ECC_STATE_NONE; - - if (ret != 0) - return ret; + key->idx = 0; + key->dp = NULL; /* set key size */ ret = wc_ecc_set_curve(key, privSz, curve_id);