diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index 42f5848f2..d2aa4372f 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -3335,6 +3335,12 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b) if (pa > (int)MP_WARRAY) return MP_RANGE; /* TAO range check */ + if (pa == 0) { + /* Nothing to do. Zero result and return. */ + mp_zero(b); + return MP_OKAY; + } + #ifdef WOLFSSL_SMALL_STACK W = (mp_digit*)XMALLOC(sizeof(mp_digit) * pa, NULL, DYNAMIC_TYPE_BIGINT); if (W == NULL) @@ -3454,6 +3460,12 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) if (pa > (int)MP_WARRAY) return MP_RANGE; /* TAO range check */ + if (pa == 0) { + /* Nothing to do. Zero result and return. */ + mp_zero(c); + return MP_OKAY; + } + #ifdef WOLFSSL_SMALL_STACK W = (mp_digit*)XMALLOC(sizeof(mp_digit) * pa, NULL, DYNAMIC_TYPE_BIGINT); if (W == NULL)