Fix to "mp_init_multi" so failure ensures a later "mp_clear" won't free on un-initialized pointer. Applies to !USE_FAST_MATH only. No measurable benchmark difference.

This commit is contained in:
David Garske
2016-11-11 20:03:58 -08:00
parent 1aca9a6079
commit 6d5485b88f

View File

@ -100,6 +100,13 @@ int mp_init_multi(mp_int* a, mp_int* b, mp_int* c, mp_int* d, mp_int* e,
{
int res = MP_OKAY;
if (a) XMEMSET(a, 0, sizeof(mp_int));
if (b) XMEMSET(b, 0, sizeof(mp_int));
if (c) XMEMSET(c, 0, sizeof(mp_int));
if (d) XMEMSET(d, 0, sizeof(mp_int));
if (e) XMEMSET(e, 0, sizeof(mp_int));
if (f) XMEMSET(f, 0, sizeof(mp_int));
if (a && ((res = mp_init(a)) != MP_OKAY))
return res;
@ -454,7 +461,7 @@ void mp_zero (mp_int * a)
{
int n;
mp_digit *tmp;
if (a == NULL)
return;
@ -4418,7 +4425,7 @@ int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap)
XMEMSET(buf, 0, len);
XFREE(buf, heap, DYNAMIC_TYPE_RSA);
return MP_OKAY;
}