From 6d5485b88f19f736f6082ad78b1ba36fb5193d0e Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 11 Nov 2016 20:03:58 -0800 Subject: [PATCH] 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. --- wolfcrypt/src/integer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index be7bd5fcb..030d3fa01 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -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; }