diff --git a/ctaocrypt/src/integer.c b/ctaocrypt/src/integer.c index 2cf2d6dbd..2cf87b923 100644 --- a/ctaocrypt/src/integer.c +++ b/ctaocrypt/src/integer.c @@ -2012,7 +2012,11 @@ mp_montgomery_setup (mp_int * n, mp_digit * rho) int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) { int ix, res, olduse; +#ifdef CYASSL_SMALL_STACK + mp_word* W; /* uses dynamic memory and slower */ +#else mp_word W[MP_WARRAY]; +#endif /* get old used count */ olduse = x->used; @@ -2024,6 +2028,12 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) } } +#ifdef CYASSL_SMALL_STACK + W = (mp_word*)XMALLOC(sizeof(mp_word) * MP_WARRAY, 0, DYNAMIC_TYPE_BIGINT); + if (W == NULL) + return MP_MEM; +#endif + /* first we have to get the digits of the input into * an array of double precision words W[...] */ @@ -2145,6 +2155,10 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) x->used = n->used + 1; mp_clamp (x); +#ifdef CYASSL_SMALL_STACK + XFREE(W, 0, DYNAMIC_TYPE_BIGINT); +#endif + /* if A >= m then A = A - m */ if (mp_cmp_mag (x, n) != MP_LT) { return s_mp_sub (x, n, x);