diff --git a/src/ssl.c b/src/ssl.c index 8ac38b8f3..0809d58a5 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -17521,9 +17521,9 @@ WOLFSSL_ECDSA_SIG *wolfSSL_ECDSA_do_sign(const unsigned char *d, int dlen, sig = NULL; } - mp_clear(&sig_r); - mp_clear(&sig_s); } + mp_clear(&sig_r); + mp_clear(&sig_s); } } diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 257242d47..01f932274 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -3462,9 +3462,12 @@ int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx, #ifdef HAVE_COMP_KEY if (err == MP_OKAY && compressed == 1) { /* build y */ mp_int t1, t2, prime, a, b; + int did_init = 0; if (mp_init_multi(&t1, &t2, &prime, &a, &b, NULL) != MP_OKAY) err = MEMORY_E; + else + did_init = 1; /* read in the specs for this curve */ if (err == MP_OKAY) @@ -3505,13 +3508,15 @@ int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx, } } + if (did_init) { #ifndef USE_FAST_MATH - mp_clear(&a); - mp_clear(&b); - mp_clear(&prime); - mp_clear(&t2); - mp_clear(&t1); + mp_clear(&a); + mp_clear(&b); + mp_clear(&prime); + mp_clear(&t2); + mp_clear(&t1); #endif + } } #endif @@ -3891,6 +3896,8 @@ int wc_ecc_check_key(ecc_key* key) return ECC_INF_E; err = mp_init_multi(&prime, &a, &order, NULL, NULL, NULL); + if (err != MP_OKAY) + return err; /* read in the specs for this curve */ if (err == MP_OKAY) @@ -3985,9 +3992,12 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key, #ifdef HAVE_COMP_KEY if (err == MP_OKAY && compressed == 1) { /* build y */ mp_int t1, t2, prime, a, b; + int did_init = 0; if (mp_init_multi(&t1, &t2, &prime, &a, &b, NULL) != MP_OKAY) err = MEMORY_E; + else + did_init = 1; /* read in the specs for this curve */ if (err == MP_OKAY) @@ -4029,13 +4039,15 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key, mp_copy(&t2, key->pubkey.y); } + if (did_init) { #ifndef USE_FAST_MATH - mp_clear(&a); - mp_clear(&b); - mp_clear(&prime); - mp_clear(&t2); - mp_clear(&t1); + mp_clear(&a); + mp_clear(&b); + mp_clear(&prime); + mp_clear(&t2); + mp_clear(&t1); #endif + } } #endif /* HAVE_COMP_KEY */ diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index 030d3fa01..7e0c59820 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -1074,6 +1074,12 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c) /* init rest of tmps temps */ if ((res = mp_init_multi(&C, &D, 0, 0, 0, 0)) != MP_OKAY) { + mp_clear(&x); + mp_clear(&y); + mp_clear(&u); + mp_clear(&v); + mp_clear(&A); + mp_clear(&B); return res; }