Skip to content

Commit

Permalink
Merge pull request wolfSSL#7624 from gasbytes/stack-on-calcdx
Browse files Browse the repository at this point in the history
update CalcDX with small-stack support
  • Loading branch information
douzzer authored and jefferyq2 committed Jun 9, 2024
1 parent 9028be7 commit ae5b099
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions wolfcrypt/src/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -5156,17 +5156,27 @@ int wc_RsaSetNonBlockTime(RsaKey* key, word32 maxBlockUs, word32 cpuMHz)
*/
static int CalcDX(mp_int* y, mp_int* x, mp_int* d)
{
mp_int m;
int err;
#ifndef WOLFSSL_SMALL_STACK
mp_int m[1];
#else
mp_int* m = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_WOLF_BIGINT);
if (m == NULL)
return MEMORY_E;
#endif

err = mp_init(&m);
err = mp_init(m);
if (err == MP_OKAY) {
err = mp_sub_d(x, 1, &m);
err = mp_sub_d(x, 1, m);
if (err == MP_OKAY)
err = mp_mod(d, &m, y);
mp_forcezero(&m);
err = mp_mod(d, m, y);
mp_forcezero(m);
}

#ifdef WOLFSSL_SMALL_STACK
XFREE(m, NULL, DYNAMIC_TYPE_WOLF_BIGINT);
#endif

return err;
}
#endif
Expand Down

0 comments on commit ae5b099

Please sign in to comment.