diff --git a/configure.ac b/configure.ac index 7f0090833..ebd4f8800 100644 --- a/configure.ac +++ b/configure.ac @@ -6783,6 +6783,10 @@ do ENABLED_SP_FF_4096=yes ;; + smallstack) + ENABLED_SP_SMALL_STACK=yes + ;; + nomalloc) ENABLED_SP_NO_MALLOC=yes ;; @@ -6867,6 +6871,10 @@ if test "$ENABLED_SP_SMALL" = "yes"; then AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_SMALL" AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_SMALL" fi +if test "$ENABLED_SP_SMALL_STACK" = "yes"; then + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_SMALL_STACK" + AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_SMALL_STACK" +fi if test "$ENABLED_SP_NO_MALLOC" = "yes"; then AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_NO_MALLOC" AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_NO_MALLOC" diff --git a/wolfcrypt/src/sp_arm32.c b/wolfcrypt/src/sp_arm32.c index 8a2f2c178..a1b68dc82 100644 --- a/wolfcrypt/src/sp_arm32.c +++ b/wolfcrypt/src/sp_arm32.c @@ -45,6 +45,11 @@ #endif #endif +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#undef WOLFSSL_SP_SMALL_STACK +#define WOLFSSL_SP_SMALL_STACK +#endif + #include #ifdef WOLFSSL_SP_ARM32_ASM @@ -11970,7 +11975,7 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_dig static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 64]; @@ -11989,7 +11994,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -12100,7 +12105,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -12122,7 +12127,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 64]; @@ -12141,7 +12146,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -12269,7 +12274,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -16205,7 +16210,7 @@ static WC_INLINE int sp_2048_mod_64(sp_digit* r, const sp_digit* a, const sp_dig static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 128]; @@ -16224,7 +16229,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -16326,7 +16331,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -16348,7 +16353,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 128]; @@ -16367,7 +16372,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -16478,7 +16483,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -16505,7 +16510,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[64 * 5]; @@ -16527,7 +16532,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -16642,7 +16647,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -16852,7 +16857,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[64 * 4]; @@ -16886,7 +16891,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -16911,21 +16916,21 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 64); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[32 * 11]; @@ -16960,7 +16965,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -17008,12 +17013,12 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 32 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -17555,7 +17560,7 @@ static void sp_2048_lshift_64(sp_digit* r_p, const sp_digit* a_p, byte n_p) static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[193]; @@ -17575,7 +17580,7 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -17660,7 +17665,7 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -37273,7 +37278,7 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_dig static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 96]; @@ -37292,7 +37297,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -37403,7 +37408,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -37425,7 +37430,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 96]; @@ -37444,7 +37449,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -37572,7 +37577,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -43154,7 +43159,7 @@ static WC_INLINE int sp_3072_mod_96(sp_digit* r, const sp_digit* a, const sp_dig static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 192]; @@ -43173,7 +43178,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -43275,7 +43280,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -43297,7 +43302,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 192]; @@ -43316,7 +43321,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -43427,7 +43432,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -43454,7 +43459,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[96 * 5]; @@ -43476,7 +43481,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 96 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -43591,7 +43596,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -43857,7 +43862,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[96 * 4]; @@ -43891,7 +43896,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 96 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -43916,21 +43921,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 96); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[48 * 11]; @@ -43965,7 +43970,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 48 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -44013,12 +44018,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 48 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -44752,7 +44757,7 @@ static void sp_3072_lshift_96(sp_digit* r_p, const sp_digit* a_p, byte n_p) static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[289]; @@ -44772,7 +44777,7 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -44857,7 +44862,7 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -58478,7 +58483,7 @@ static WC_INLINE int sp_4096_mod_128(sp_digit* r, const sp_digit* a, const sp_di static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 256]; @@ -58497,7 +58502,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -58599,7 +58604,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -58621,7 +58626,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 256]; @@ -58640,7 +58645,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -58751,7 +58756,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -58778,7 +58783,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[128 * 5]; @@ -58800,7 +58805,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 128 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -58915,7 +58920,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -59237,7 +59242,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[128 * 4]; @@ -59271,7 +59276,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 128 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -59296,21 +59301,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 128); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[64 * 11]; @@ -59345,7 +59350,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -59393,12 +59398,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 64 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -60324,7 +60329,7 @@ static void sp_4096_lshift_128(sp_digit* r_p, const sp_digit* a_p, byte n_p) static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[385]; @@ -60344,7 +60349,7 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -60429,7 +60434,7 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -71426,7 +71431,7 @@ static void sp_256_get_point_16_8(sp_point_256* r, const sp_point_256* table, static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -71435,7 +71440,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons #endif sp_point_256* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* p = NULL; #else sp_point_256 p[1]; @@ -71451,7 +71456,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -71562,32 +71567,32 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 8 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_256) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -71814,7 +71819,7 @@ static void sp_256_proj_point_add_qz1_8(sp_point_256* r, static int sp_256_gen_stripe_table_8(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -71827,7 +71832,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -71882,7 +71887,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -71961,7 +71966,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -71981,7 +71986,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -72047,7 +72052,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -72167,7 +72172,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 8 * 6]; @@ -72175,7 +72180,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -72211,7 +72216,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -72234,7 +72239,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ static int sp_256_gen_stripe_table_8(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -72247,7 +72252,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -72302,7 +72307,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -72381,7 +72386,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -72401,7 +72406,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -72467,7 +72472,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -72587,7 +72592,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 8 * 6]; @@ -72595,7 +72600,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -72631,7 +72636,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -72652,7 +72657,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -72661,7 +72666,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -72684,7 +72689,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -72709,7 +72714,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -72720,7 +72725,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -72764,7 +72769,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -74203,7 +74208,7 @@ static int sp_256_ecc_mulmod_base_8(sp_point_256* r, const sp_digit* k, */ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -74212,7 +74217,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -74234,7 +74239,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -74258,7 +74263,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -74269,7 +74274,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -74312,7 +74317,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -74428,7 +74433,7 @@ static int sp_256_ecc_gen_k_8(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -74447,7 +74452,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -74492,7 +74497,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_256_point_to_ecc_point_8(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -74617,7 +74622,7 @@ static void sp_256_to_bin_8(sp_digit* r, byte* a) int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -74630,7 +74635,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -74655,7 +74660,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 32; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -75771,7 +75776,7 @@ static int sp_256_calc_s_8(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_256* point = NULL; #else @@ -75789,7 +75794,7 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -75868,21 +75873,21 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_256_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 8); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -76863,7 +76868,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_256* p1 = NULL; #else @@ -76878,7 +76883,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -76949,7 +76954,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -77121,7 +77126,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_256_ecc_is_point_8(const sp_point_256* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[8 * 4]; @@ -77129,7 +77134,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -77157,7 +77162,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -77174,7 +77179,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, */ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* pub = NULL; #else sp_point_256 pub[1]; @@ -77182,7 +77187,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -77197,7 +77202,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) err = sp_256_ecc_is_point_8(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -77219,7 +77224,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_256* pub = NULL; #else @@ -77240,7 +77245,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -77306,7 +77311,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -77335,7 +77340,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -77345,7 +77350,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_256* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -77388,7 +77393,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -77412,7 +77417,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -77421,7 +77426,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -77456,7 +77461,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -77476,7 +77481,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -77486,7 +77491,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -77520,7 +77525,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_256_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -77538,7 +77543,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_256_mont_sqrt_8(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 8]; @@ -77546,7 +77551,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 8, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) { err = MEMORY_E; @@ -77589,7 +77594,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -77607,7 +77612,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) */ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 8]; @@ -77615,7 +77620,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 8, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -77655,7 +77660,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) err = sp_256_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -86721,7 +86726,7 @@ static sp_digit sp_384_sub_12(sp_digit* r_p, const sp_digit* a_p, const sp_digit */ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[12]; @@ -86731,7 +86736,7 @@ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 12, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) { err = MEMORY_E; @@ -86806,7 +86811,7 @@ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit r[11] = t[11]; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -88842,7 +88847,7 @@ static void sp_384_get_point_16_12(sp_point_384* r, const sp_point_384* table, static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -88851,7 +88856,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con #endif sp_point_384* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* p = NULL; #else sp_point_384 p[1]; @@ -88867,7 +88872,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -88978,32 +88983,32 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 12 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_384) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -89230,7 +89235,7 @@ static void sp_384_proj_point_add_qz1_12(sp_point_384* r, static int sp_384_gen_stripe_table_12(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -89243,7 +89248,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -89298,7 +89303,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -89393,7 +89398,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -89413,7 +89418,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -89479,7 +89484,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -89599,7 +89604,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp #ifndef FP_ECC return sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 12 * 7]; @@ -89607,7 +89612,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -89643,7 +89648,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -89666,7 +89671,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp static int sp_384_gen_stripe_table_12(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -89679,7 +89684,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -89734,7 +89739,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -89829,7 +89834,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -89849,7 +89854,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -89915,7 +89920,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -90035,7 +90040,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp #ifndef FP_ECC return sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 12 * 7]; @@ -90043,7 +90048,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -90079,7 +90084,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -90100,7 +90105,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -90109,7 +90114,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -90132,7 +90137,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -90157,7 +90162,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -90168,7 +90173,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -90212,7 +90217,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -91651,7 +91656,7 @@ static int sp_384_ecc_mulmod_base_12(sp_point_384* r, const sp_digit* k, */ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -91660,7 +91665,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -91682,7 +91687,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -91706,7 +91711,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -91717,7 +91722,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -91760,7 +91765,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -91882,7 +91887,7 @@ static int sp_384_ecc_gen_k_12(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -91901,7 +91906,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -91946,7 +91951,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_384_point_to_ecc_point_12(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -92071,7 +92076,7 @@ static void sp_384_to_bin_12(sp_digit* r, byte* a) int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -92084,7 +92089,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -92109,7 +92114,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 48; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -93367,7 +93372,7 @@ static int sp_384_calc_s_12(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_384* point = NULL; #else @@ -93385,7 +93390,7 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -93464,21 +93469,21 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_384_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 12); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -94719,7 +94724,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_384* p1 = NULL; #else @@ -94734,7 +94739,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -94805,7 +94810,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -94977,7 +94982,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_384_ecc_is_point_12(const sp_point_384* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[12 * 4]; @@ -94985,7 +94990,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 12 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -95013,7 +95018,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -95030,7 +95035,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, */ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* pub = NULL; #else sp_point_384 pub[1]; @@ -95038,7 +95043,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -95053,7 +95058,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) err = sp_384_ecc_is_point_12(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -95075,7 +95080,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_384* pub = NULL; #else @@ -95096,7 +95101,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -95162,7 +95167,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -95191,7 +95196,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -95201,7 +95206,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_384* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -95244,7 +95249,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -95268,7 +95273,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -95277,7 +95282,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -95312,7 +95317,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -95332,7 +95337,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -95342,7 +95347,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -95376,7 +95381,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_384_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -95394,7 +95399,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_384_mont_sqrt_12(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[5 * 2 * 12]; @@ -95405,7 +95410,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) sp_digit* t5 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 2 * 12, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -95475,7 +95480,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -95493,7 +95498,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) */ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 12]; @@ -95501,7 +95506,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 12, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -95541,7 +95546,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) err = sp_384_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -115689,7 +115694,7 @@ static void sp_521_get_point_16_17(sp_point_521* r, const sp_point_521* table, static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -115698,7 +115703,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con #endif sp_point_521* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* p = NULL; #else sp_point_521 p[1]; @@ -115714,7 +115719,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -115829,32 +115834,32 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 17 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_521) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -116081,7 +116086,7 @@ static void sp_521_proj_point_add_qz1_17(sp_point_521* r, static int sp_521_gen_stripe_table_17(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -116094,7 +116099,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -116149,7 +116154,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -116264,7 +116269,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -116284,7 +116289,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -116350,7 +116355,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -116470,7 +116475,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp #ifndef FP_ECC return sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 17 * 6]; @@ -116478,7 +116483,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -116514,7 +116519,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -116537,7 +116542,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp static int sp_521_gen_stripe_table_17(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -116550,7 +116555,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -116605,7 +116610,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -116720,7 +116725,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -116740,7 +116745,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -116806,7 +116811,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -116926,7 +116931,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp #ifndef FP_ECC return sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 17 * 6]; @@ -116934,7 +116939,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -116970,7 +116975,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -116991,7 +116996,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -117000,7 +117005,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -117023,7 +117028,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -117048,7 +117053,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -117059,7 +117064,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -117103,7 +117108,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -119086,7 +119091,7 @@ static int sp_521_ecc_mulmod_base_17(sp_point_521* r, const sp_digit* k, */ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -119095,7 +119100,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -119117,7 +119122,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -119141,7 +119146,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -119152,7 +119157,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -119195,7 +119200,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -119327,7 +119332,7 @@ static int sp_521_ecc_gen_k_17(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -119346,7 +119351,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -119391,7 +119396,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_521_point_to_ecc_point_17(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -119518,7 +119523,7 @@ static void sp_521_to_bin_17(sp_digit* r, byte* a) int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -119531,7 +119536,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -119556,7 +119561,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 66; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -121491,7 +121496,7 @@ static int sp_521_calc_s_17(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_521* point = NULL; #else @@ -121509,7 +121514,7 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -121593,21 +121598,21 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_521_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -123281,7 +123286,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_521* p1 = NULL; #else @@ -123296,7 +123301,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -123371,7 +123376,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -123546,7 +123551,7 @@ int sp_ecc_verify_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_521_ecc_is_point_17(const sp_point_521* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[17 * 4]; @@ -123554,7 +123559,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -123582,7 +123587,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -123599,7 +123604,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, */ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* pub = NULL; #else sp_point_521 pub[1]; @@ -123607,7 +123612,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -123622,7 +123627,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) err = sp_521_ecc_is_point_17(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -123644,7 +123649,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_521* pub = NULL; #else @@ -123665,7 +123670,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -123731,7 +123736,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -123760,7 +123765,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -123770,7 +123775,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_521* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -123813,7 +123818,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -123837,7 +123842,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -123846,7 +123851,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -123881,7 +123886,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -123901,7 +123906,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -123911,7 +123916,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -123945,7 +123950,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_521_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -123970,14 +123975,14 @@ static const uint32_t p521_sqrt_power[17] = { */ static int sp_521_mont_sqrt_17(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t = NULL; #else sp_digit t[2 * 17]; #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -123998,7 +124003,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -124016,7 +124021,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) */ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 17]; @@ -124024,7 +124029,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 17, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -124064,7 +124069,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) err = sp_521_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -142105,7 +142110,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, { int ret = MP_OKAY; (void)heap; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) (void)sp; *p = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); #else @@ -142117,7 +142123,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, return ret; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* Allocate memory for point and return error. */ #define sp_1024_point_new_32(heap, sp, p) sp_1024_point_new_ex_32((heap), NULL, &(p)) #else @@ -142134,7 +142141,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, */ static void sp_1024_point_free_32(sp_point_1024* p, int clear, void* heap) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* If valid pointer then clear point data if requested and free data. */ if (p != NULL) { if (clear != 0) { @@ -145454,7 +145462,7 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -145472,7 +145480,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -145555,21 +145563,21 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 37); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_1024) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -145796,7 +145804,7 @@ static void sp_1024_proj_point_add_qz1_32(sp_point_1024* r, static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -145809,7 +145817,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -145864,7 +145872,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -145893,7 +145901,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -145913,7 +145921,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -145964,7 +145972,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -146084,7 +146092,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 32 * 38]; @@ -146092,7 +146100,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -146128,7 +146136,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -146151,7 +146159,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -146164,7 +146172,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -146219,7 +146227,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -146248,7 +146256,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -146268,7 +146276,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -146319,7 +146327,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -146439,7 +146447,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 32 * 38]; @@ -146447,7 +146455,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -146483,7 +146491,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -146504,7 +146512,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -146513,7 +146521,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -146536,7 +146544,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -150143,7 +150151,7 @@ static int sp_1024_ecc_mulmod_base_32(sp_point_1024* r, const sp_digit* k, */ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -150152,7 +150160,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -150174,7 +150182,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -150198,7 +150206,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -150209,7 +150217,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -150252,7 +150260,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -150275,7 +150283,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* t = NULL; #else @@ -150296,7 +150304,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); @@ -150320,7 +150328,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, *len = sizeof(sp_table_entry_1024) * 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -150378,7 +150386,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -150387,7 +150395,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) { @@ -150416,7 +150424,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -150491,8 +150499,8 @@ static void sp_1024_proj_sqr_32(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -150511,8 +150519,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -150521,8 +150529,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 32 * 2; ty = td + 37 * 32 * 2; @@ -150565,8 +150573,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -152390,8 +152398,8 @@ static const sp_digit sp_1024_g_table[256][32] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -152409,8 +152417,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -152419,8 +152427,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 32 * 2; ty = td + 37 * 32 * 2; @@ -152463,8 +152471,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -152734,8 +152742,8 @@ static void sp_1024_accumulate_line_add_one_32(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -152764,8 +152772,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -152776,8 +152784,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -152833,8 +152841,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -153112,8 +153120,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -153149,8 +153157,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -153161,8 +153169,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -153260,8 +153268,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -153501,8 +153509,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -153541,8 +153549,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_32(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -153553,8 +153561,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; pre_p = (sp_point_1024*)(td + 36 * 32 * 2); #endif @@ -153628,8 +153636,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -153663,8 +153671,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -153706,8 +153714,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -153718,8 +153726,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -153823,8 +153831,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -153885,7 +153893,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) static int sp_1024_ecc_is_point_32(const sp_point_1024* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[32 * 4]; @@ -153894,7 +153902,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, sp_int32 n; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -153925,7 +153933,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -153942,7 +153950,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, */ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* pub = NULL; #else sp_point_1024 pub[1]; @@ -153950,7 +153958,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -153965,7 +153973,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) err = sp_1024_ecc_is_point_32(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -153987,7 +153995,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_1024* pub = NULL; #else @@ -154008,7 +154016,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); @@ -154074,7 +154082,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) diff --git a/wolfcrypt/src/sp_arm64.c b/wolfcrypt/src/sp_arm64.c index 6a33f1c89..ff0beb589 100644 --- a/wolfcrypt/src/sp_arm64.c +++ b/wolfcrypt/src/sp_arm64.c @@ -45,6 +45,11 @@ #endif #endif +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#undef WOLFSSL_SP_SMALL_STACK +#define WOLFSSL_SP_SMALL_STACK +#endif + #include #ifdef WOLFSSL_SP_ARM64_ASM @@ -4023,7 +4028,7 @@ static WC_INLINE int sp_2048_mod_16(sp_digit* r, const sp_digit* a, const sp_dig static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 32]; @@ -4042,7 +4047,7 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 32), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4153,7 +4158,7 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_16(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4175,7 +4180,7 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 32]; @@ -4194,7 +4199,7 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 32), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4322,7 +4327,7 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_16(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -5632,7 +5637,7 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_dig static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 64]; @@ -5651,7 +5656,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5779,7 +5784,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -5801,7 +5806,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[64 * 64]; @@ -5820,7 +5825,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (64 * 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5981,7 +5986,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -6008,7 +6013,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[32 * 5]; @@ -6030,7 +6035,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -6145,7 +6150,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -6212,7 +6217,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[32 * 4]; @@ -6246,7 +6251,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -6271,21 +6276,21 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 32); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[16 * 11]; @@ -6320,7 +6325,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 16 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -6368,12 +6373,12 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 16 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -6720,7 +6725,7 @@ static void sp_2048_lshift_32(sp_digit* r, const sp_digit* a, byte n) static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[97]; @@ -6740,7 +6745,7 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 97, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -6826,7 +6831,7 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -13214,7 +13219,7 @@ static WC_INLINE int sp_3072_mod_24(sp_digit* r, const sp_digit* a, const sp_dig static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 48]; @@ -13233,7 +13238,7 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 48), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -13344,7 +13349,7 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_24(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -13366,7 +13371,7 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 48]; @@ -13385,7 +13390,7 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 48), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -13513,7 +13518,7 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_24(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -15215,7 +15220,7 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_dig static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 96]; @@ -15234,7 +15239,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15336,7 +15341,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -15358,7 +15363,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 96]; @@ -15377,7 +15382,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15488,7 +15493,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -15515,7 +15520,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[48 * 5]; @@ -15537,7 +15542,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 48 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -15652,7 +15657,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -15719,7 +15724,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[48 * 4]; @@ -15753,7 +15758,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 48 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -15778,21 +15783,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 48); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[24 * 11]; @@ -15827,7 +15832,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 24 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -15875,12 +15880,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 24 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -16323,7 +16328,7 @@ static void sp_3072_lshift_48(sp_digit* r, const sp_digit* a, byte n) static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[145]; @@ -16343,7 +16348,7 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 145, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -16429,7 +16434,7 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -20326,7 +20331,7 @@ static WC_INLINE int sp_4096_mod_64(sp_digit* r, const sp_digit* a, const sp_dig static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 128]; @@ -20345,7 +20350,7 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -20447,7 +20452,7 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_4096_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -20469,7 +20474,7 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 128]; @@ -20488,7 +20493,7 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -20599,7 +20604,7 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_4096_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -20626,7 +20631,7 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[64 * 5]; @@ -20648,7 +20653,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -20763,7 +20768,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -20830,7 +20835,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[64 * 4]; @@ -20864,7 +20869,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -20889,21 +20894,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 64); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[32 * 11]; @@ -20938,7 +20943,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -20986,12 +20991,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 32 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -21530,7 +21535,7 @@ static void sp_4096_lshift_64(sp_digit* r, const sp_digit* a, byte n) static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[193]; @@ -21550,7 +21555,7 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -21636,7 +21641,7 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, sp_4096_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -24399,7 +24404,7 @@ static void sp_256_get_point_33_4(sp_point_256* r, const sp_point_256* table, static int sp_256_ecc_mulmod_win_add_sub_4(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -24417,7 +24422,7 @@ static int sp_256_ecc_mulmod_win_add_sub_4(sp_point_256* r, const sp_point_256* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -24513,7 +24518,7 @@ static int sp_256_ecc_mulmod_win_add_sub_4(sp_point_256* r, const sp_point_256* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -24646,7 +24651,7 @@ static void sp_256_proj_to_affine_4(sp_point_256* a, sp_digit* t) static int sp_256_gen_stripe_table_4(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -24659,7 +24664,7 @@ static int sp_256_gen_stripe_table_4(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -24714,7 +24719,7 @@ static int sp_256_gen_stripe_table_4(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -24778,7 +24783,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -24798,7 +24803,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -24864,7 +24869,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -24985,7 +24990,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_win_add_sub_4(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 4 * 6]; @@ -24993,7 +24998,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 4 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -25029,7 +25034,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -25054,7 +25059,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ static int sp_256_gen_stripe_table_4(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -25067,7 +25072,7 @@ static int sp_256_gen_stripe_table_4(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -25122,7 +25127,7 @@ static int sp_256_gen_stripe_table_4(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -25186,7 +25191,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -25206,7 +25211,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -25272,7 +25277,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -25393,7 +25398,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_win_add_sub_4(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 4 * 6]; @@ -25401,7 +25406,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 4 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -25437,7 +25442,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -25458,7 +25463,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -25467,7 +25472,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -25490,7 +25495,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_256_point_to_ecc_point_4(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -25515,7 +25520,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -25526,7 +25531,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -25570,7 +25575,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, err = sp_256_point_to_ecc_point_4(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -39318,7 +39323,7 @@ static int sp_256_ecc_mulmod_add_only_4(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* tmp = NULL; #else @@ -39336,7 +39341,7 @@ static int sp_256_ecc_mulmod_add_only_4(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -39397,16 +39402,16 @@ static int sp_256_ecc_mulmod_add_only_4(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 4 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -39443,7 +39448,7 @@ static int sp_256_ecc_mulmod_base_4(sp_point_256* r, const sp_digit* k, */ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -39452,7 +39457,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -39474,7 +39479,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_256_point_to_ecc_point_4(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -39498,7 +39503,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -39509,7 +39514,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -39552,7 +39557,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, err = sp_256_point_to_ecc_point_4(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -39738,7 +39743,7 @@ static int sp_256_ecc_gen_k_4(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -39757,7 +39762,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -39802,7 +39807,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_256_point_to_ecc_point_4(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -39933,7 +39938,7 @@ static void sp_256_to_bin_4(sp_digit* r, byte* a) int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -39946,7 +39951,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -39971,7 +39976,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 32; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -40517,7 +40522,7 @@ static int sp_256_calc_s_4(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_256* point = NULL; #else @@ -40535,7 +40540,7 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -40614,21 +40619,21 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_256_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 4); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -41175,7 +41180,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_256* p1 = NULL; #else @@ -41190,7 +41195,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, sp_int64 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -41261,7 +41266,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -41433,7 +41438,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_256_ecc_is_point_4(const sp_point_256* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 4]; @@ -41441,7 +41446,7 @@ static int sp_256_ecc_is_point_4(const sp_point_256* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -41469,7 +41474,7 @@ static int sp_256_ecc_is_point_4(const sp_point_256* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -41486,7 +41491,7 @@ static int sp_256_ecc_is_point_4(const sp_point_256* point, */ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* pub = NULL; #else sp_point_256 pub[1]; @@ -41494,7 +41499,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -41509,7 +41514,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) err = sp_256_ecc_is_point_4(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -41531,7 +41536,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_256* pub = NULL; #else @@ -41552,7 +41557,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -41618,7 +41623,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -41647,7 +41652,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -41657,7 +41662,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_256* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -41700,7 +41705,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -41724,7 +41729,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -41733,7 +41738,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -41768,7 +41773,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -41788,7 +41793,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -41798,7 +41803,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -41832,7 +41837,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_256_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -41850,7 +41855,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_256_mont_sqrt_4(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 4]; @@ -41858,7 +41863,7 @@ static int sp_256_mont_sqrt_4(sp_digit* y) sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 4, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) { err = MEMORY_E; @@ -41901,7 +41906,7 @@ static int sp_256_mont_sqrt_4(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -41919,7 +41924,7 @@ static int sp_256_mont_sqrt_4(sp_digit* y) */ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 4]; @@ -41927,7 +41932,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 4, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -41967,7 +41972,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) err = sp_256_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -42656,7 +42661,7 @@ static sp_digit sp_384_sub_6(sp_digit* r, const sp_digit* a, */ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[2 * 12]; @@ -42667,7 +42672,7 @@ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit* (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 2 * 12, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -42750,7 +42755,7 @@ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit* r[5] = (t[11] << 32) | t[10]; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -44625,7 +44630,7 @@ static void sp_384_get_point_33_6(sp_point_384* r, const sp_point_384* table, static int sp_384_ecc_mulmod_win_add_sub_6(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -44643,7 +44648,7 @@ static int sp_384_ecc_mulmod_win_add_sub_6(sp_point_384* r, const sp_point_384* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -44739,7 +44744,7 @@ static int sp_384_ecc_mulmod_win_add_sub_6(sp_point_384* r, const sp_point_384* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -44873,7 +44878,7 @@ static void sp_384_proj_to_affine_6(sp_point_384* a, sp_digit* t) static int sp_384_gen_stripe_table_6(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -44886,7 +44891,7 @@ static int sp_384_gen_stripe_table_6(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -44941,7 +44946,7 @@ static int sp_384_gen_stripe_table_6(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -45013,7 +45018,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -45033,7 +45038,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -45099,7 +45104,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -45220,7 +45225,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ #ifndef FP_ECC return sp_384_ecc_mulmod_win_add_sub_6(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 6 * 7]; @@ -45228,7 +45233,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 6 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -45264,7 +45269,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -45289,7 +45294,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ static int sp_384_gen_stripe_table_6(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -45302,7 +45307,7 @@ static int sp_384_gen_stripe_table_6(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -45357,7 +45362,7 @@ static int sp_384_gen_stripe_table_6(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -45429,7 +45434,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -45449,7 +45454,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -45515,7 +45520,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -45636,7 +45641,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ #ifndef FP_ECC return sp_384_ecc_mulmod_win_add_sub_6(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 6 * 7]; @@ -45644,7 +45649,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 6 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -45680,7 +45685,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -45701,7 +45706,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -45710,7 +45715,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -45733,7 +45738,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_384_point_to_ecc_point_6(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -45758,7 +45763,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -45769,7 +45774,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -45813,7 +45818,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, err = sp_384_point_to_ecc_point_6(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -65383,7 +65388,7 @@ static int sp_384_ecc_mulmod_add_only_6(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* tmp = NULL; #else @@ -65401,7 +65406,7 @@ static int sp_384_ecc_mulmod_add_only_6(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -65462,16 +65467,16 @@ static int sp_384_ecc_mulmod_add_only_6(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 6 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -65508,7 +65513,7 @@ static int sp_384_ecc_mulmod_base_6(sp_point_384* r, const sp_digit* k, */ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -65517,7 +65522,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -65539,7 +65544,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_384_point_to_ecc_point_6(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -65563,7 +65568,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -65574,7 +65579,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -65617,7 +65622,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, err = sp_384_point_to_ecc_point_6(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -65807,7 +65812,7 @@ static int sp_384_ecc_gen_k_6(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -65826,7 +65831,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -65871,7 +65876,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_384_point_to_ecc_point_6(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -66002,7 +66007,7 @@ static void sp_384_to_bin_6(sp_digit* r, byte* a) int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -66015,7 +66020,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -66040,7 +66045,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 48; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -66622,7 +66627,7 @@ static int sp_384_calc_s_6(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_384* point = NULL; #else @@ -66640,7 +66645,7 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -66719,21 +66724,21 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_384_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -67182,7 +67187,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_384* p1 = NULL; #else @@ -67197,7 +67202,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, sp_int64 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -67268,7 +67273,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -67440,7 +67445,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_384_ecc_is_point_6(const sp_point_384* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[6 * 4]; @@ -67448,7 +67453,7 @@ static int sp_384_ecc_is_point_6(const sp_point_384* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -67476,7 +67481,7 @@ static int sp_384_ecc_is_point_6(const sp_point_384* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -67493,7 +67498,7 @@ static int sp_384_ecc_is_point_6(const sp_point_384* point, */ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* pub = NULL; #else sp_point_384 pub[1]; @@ -67501,7 +67506,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -67516,7 +67521,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) err = sp_384_ecc_is_point_6(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -67538,7 +67543,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_384* pub = NULL; #else @@ -67559,7 +67564,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -67625,7 +67630,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -67654,7 +67659,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -67664,7 +67669,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_384* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -67707,7 +67712,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -67731,7 +67736,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -67740,7 +67745,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -67775,7 +67780,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -67795,7 +67800,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -67805,7 +67810,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -67839,7 +67844,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_384_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -67857,7 +67862,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_384_mont_sqrt_6(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[5 * 2 * 6]; @@ -67868,7 +67873,7 @@ static int sp_384_mont_sqrt_6(sp_digit* y) sp_digit* t5 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 2 * 6, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -67938,7 +67943,7 @@ static int sp_384_mont_sqrt_6(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -67956,7 +67961,7 @@ static int sp_384_mont_sqrt_6(sp_digit* y) */ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 6]; @@ -67964,7 +67969,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 6, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -68004,7 +68009,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) err = sp_384_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -72941,7 +72946,7 @@ static void sp_521_get_point_33_9(sp_point_521* r, const sp_point_521* table, static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -72959,7 +72964,7 @@ static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -73055,7 +73060,7 @@ static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -73189,7 +73194,7 @@ static void sp_521_proj_to_affine_9(sp_point_521* a, sp_digit* t) static int sp_521_gen_stripe_table_9(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -73202,7 +73207,7 @@ static int sp_521_gen_stripe_table_9(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -73257,7 +73262,7 @@ static int sp_521_gen_stripe_table_9(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -73341,7 +73346,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -73361,7 +73366,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -73427,7 +73432,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -73548,7 +73553,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ #ifndef FP_ECC return sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 9 * 6]; @@ -73556,7 +73561,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -73592,7 +73597,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -73617,7 +73622,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ static int sp_521_gen_stripe_table_9(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -73630,7 +73635,7 @@ static int sp_521_gen_stripe_table_9(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -73685,7 +73690,7 @@ static int sp_521_gen_stripe_table_9(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -73769,7 +73774,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -73789,7 +73794,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -73855,7 +73860,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -73976,7 +73981,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ #ifndef FP_ECC return sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 9 * 6]; @@ -73984,7 +73989,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -74020,7 +74025,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -74041,7 +74046,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -74050,7 +74055,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -74073,7 +74078,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -74098,7 +74103,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -74109,7 +74114,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -74153,7 +74158,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -110431,7 +110436,7 @@ static int sp_521_ecc_mulmod_add_only_9(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* tmp = NULL; #else @@ -110449,7 +110454,7 @@ static int sp_521_ecc_mulmod_add_only_9(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -110510,16 +110515,16 @@ static int sp_521_ecc_mulmod_add_only_9(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 9 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -110556,7 +110561,7 @@ static int sp_521_ecc_mulmod_base_9(sp_point_521* r, const sp_digit* k, */ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -110565,7 +110570,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -110587,7 +110592,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -110611,7 +110616,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -110622,7 +110627,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -110665,7 +110670,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -110864,7 +110869,7 @@ static int sp_521_ecc_gen_k_9(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -110883,7 +110888,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -110928,7 +110933,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_521_point_to_ecc_point_9(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -111061,7 +111066,7 @@ static void sp_521_to_bin_9(sp_digit* r, byte* a) int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -111074,7 +111079,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -111099,7 +111104,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 66; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -111425,7 +111430,7 @@ static int sp_521_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_521* point = NULL; #else @@ -111443,7 +111448,7 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -111527,21 +111532,21 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_521_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 9); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -112011,7 +112016,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_521* p1 = NULL; #else @@ -112026,7 +112031,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, sp_int64 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -112101,7 +112106,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -112276,7 +112281,7 @@ int sp_ecc_verify_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_521_ecc_is_point_9(const sp_point_521* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[9 * 4]; @@ -112284,7 +112289,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -112312,7 +112317,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -112329,7 +112334,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, */ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* pub = NULL; #else sp_point_521 pub[1]; @@ -112337,7 +112342,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -112352,7 +112357,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) err = sp_521_ecc_is_point_9(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -112374,7 +112379,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_521* pub = NULL; #else @@ -112395,7 +112400,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -112461,7 +112466,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -112490,7 +112495,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -112500,7 +112505,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_521* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -112543,7 +112548,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -112567,7 +112572,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -112576,7 +112581,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -112611,7 +112616,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -112631,7 +112636,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -112641,7 +112646,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -112675,7 +112680,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_521_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -112700,14 +112705,14 @@ static const uint64_t p521_sqrt_power[9] = { */ static int sp_521_mont_sqrt_9(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t = NULL; #else sp_digit t[2 * 9]; #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -112728,7 +112733,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -112746,7 +112751,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) */ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 9]; @@ -112754,7 +112759,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 9, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -112794,7 +112799,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) err = sp_521_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -114698,7 +114703,8 @@ static int sp_1024_point_new_ex_16(void* heap, sp_point_1024* sp, { int ret = MP_OKAY; (void)heap; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) (void)sp; *p = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); #else @@ -114710,7 +114716,8 @@ static int sp_1024_point_new_ex_16(void* heap, sp_point_1024* sp, return ret; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* Allocate memory for point and return error. */ #define sp_1024_point_new_16(heap, sp, p) sp_1024_point_new_ex_16((heap), NULL, &(p)) #else @@ -114727,7 +114734,8 @@ static int sp_1024_point_new_ex_16(void* heap, sp_point_1024* sp, */ static void sp_1024_point_free_16(sp_point_1024* p, int clear, void* heap) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* If valid pointer then clear point data if requested and free data. */ if (p != NULL) { if (clear != 0) { @@ -116973,7 +116981,7 @@ static void sp_1024_ecc_recode_7_16(const sp_digit* k, ecc_recode_1024* v) static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -116991,7 +116999,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_10 (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (65+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -117091,7 +117099,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_10 } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -117224,7 +117232,7 @@ static void sp_1024_proj_to_affine_16(sp_point_1024* a, sp_digit* t) static int sp_1024_gen_stripe_table_16(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -117237,7 +117245,7 @@ static int sp_1024_gen_stripe_table_16(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -117292,7 +117300,7 @@ static int sp_1024_gen_stripe_table_16(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -117321,7 +117329,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -117341,7 +117349,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -117392,7 +117400,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -117512,7 +117520,7 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_win_add_sub_16(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 16 * 38]; @@ -117520,7 +117528,7 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -117556,7 +117564,7 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -117576,7 +117584,7 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, const int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -117585,7 +117593,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -117608,7 +117616,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_1024_point_to_ecc_point_16(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -120978,7 +120986,7 @@ static int sp_1024_ecc_mulmod_base_16(sp_point_1024* r, const sp_digit* k, */ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -120987,7 +120995,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -121009,7 +121017,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_1024_point_to_ecc_point_16(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -121033,7 +121041,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -121044,7 +121052,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -121087,7 +121095,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, err = sp_1024_point_to_ecc_point_16(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -121110,7 +121118,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* t = NULL; #else @@ -121131,7 +121139,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); @@ -121155,7 +121163,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, *len = sizeof(sp_table_entry_1024) * 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -121213,7 +121221,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -121222,7 +121230,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) { @@ -121251,7 +121259,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, err = sp_1024_point_to_ecc_point_16(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -121326,8 +121334,8 @@ static void sp_1024_proj_sqr_16(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -121346,8 +121354,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -121356,8 +121364,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 16 * 2; ty = td + 37 * 16 * 2; @@ -121400,8 +121408,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -122969,8 +122977,8 @@ static const sp_digit sp_1024_g_table[256][16] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -122988,8 +122996,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -122998,8 +123006,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 16 * 2; ty = td + 37 * 16 * 2; @@ -123042,8 +123050,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -123313,8 +123321,8 @@ static void sp_1024_accumulate_line_add_one_16(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -123343,8 +123351,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -123355,8 +123363,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -123412,8 +123420,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -123691,8 +123699,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -123728,8 +123736,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -123740,8 +123748,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -123839,8 +123847,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -124080,8 +124088,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -124120,8 +124128,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_16(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -124132,8 +124140,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; pre_p = (sp_point_1024*)(td + 36 * 16 * 2); #endif @@ -124207,8 +124215,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -124242,8 +124250,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -124285,8 +124293,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -124297,8 +124305,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -124402,8 +124410,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -124539,7 +124547,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) static int sp_1024_ecc_is_point_16(const sp_point_1024* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[16 * 4]; @@ -124548,7 +124556,7 @@ static int sp_1024_ecc_is_point_16(const sp_point_1024* point, sp_int64 n; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 16 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -124579,7 +124587,7 @@ static int sp_1024_ecc_is_point_16(const sp_point_1024* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -124596,7 +124604,7 @@ static int sp_1024_ecc_is_point_16(const sp_point_1024* point, */ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* pub = NULL; #else sp_point_1024 pub[1]; @@ -124604,7 +124612,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -124619,7 +124627,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) err = sp_1024_ecc_is_point_16(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -124641,7 +124649,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_1024* pub = NULL; #else @@ -124662,7 +124670,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); @@ -124728,7 +124736,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) diff --git a/wolfcrypt/src/sp_armthumb.c b/wolfcrypt/src/sp_armthumb.c index 959b37806..2861ef4c6 100644 --- a/wolfcrypt/src/sp_armthumb.c +++ b/wolfcrypt/src/sp_armthumb.c @@ -45,6 +45,11 @@ #endif #endif +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#undef WOLFSSL_SP_SMALL_STACK +#define WOLFSSL_SP_SMALL_STACK +#endif + #include #ifdef WOLFSSL_SP_ARM_THUMB_ASM @@ -23992,7 +23997,7 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_dig static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 64]; @@ -24011,7 +24016,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -24122,7 +24127,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -24144,7 +24149,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 64]; @@ -24163,7 +24168,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -24291,7 +24296,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -27581,7 +27586,7 @@ static WC_INLINE int sp_2048_mod_64(sp_digit* r, const sp_digit* a, const sp_dig static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 128]; @@ -27600,7 +27605,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -27702,7 +27707,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -27724,7 +27729,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 128]; @@ -27743,7 +27748,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -27854,7 +27859,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -27881,7 +27886,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[64 * 5]; @@ -27903,7 +27908,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -28018,7 +28023,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -28118,7 +28123,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[64 * 4]; @@ -28152,7 +28157,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -28177,21 +28182,21 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 64); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[32 * 11]; @@ -28226,7 +28231,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -28274,12 +28279,12 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 32 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -30014,7 +30019,7 @@ static void sp_2048_lshift_64(sp_digit* r, const sp_digit* a, byte n) static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[193]; @@ -30034,7 +30039,7 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -30119,7 +30124,7 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -75452,7 +75457,7 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_dig static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 96]; @@ -75471,7 +75476,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -75582,7 +75587,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -75604,7 +75609,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 96]; @@ -75623,7 +75628,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -75751,7 +75756,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -79872,7 +79877,7 @@ static WC_INLINE int sp_3072_mod_96(sp_digit* r, const sp_digit* a, const sp_dig static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 192]; @@ -79891,7 +79896,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -79993,7 +79998,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -80015,7 +80020,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 192]; @@ -80034,7 +80039,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -80145,7 +80150,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -80172,7 +80177,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[96 * 5]; @@ -80194,7 +80199,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 96 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -80309,7 +80314,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -80409,7 +80414,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[96 * 4]; @@ -80443,7 +80448,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 96 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -80468,21 +80473,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 96); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[48 * 11]; @@ -80517,7 +80522,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 48 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -80565,12 +80570,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 48 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -83103,7 +83108,7 @@ static void sp_3072_lshift_96(sp_digit* r, const sp_digit* a, byte n) static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[289]; @@ -83123,7 +83128,7 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -83208,7 +83213,7 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -92420,7 +92425,7 @@ static WC_INLINE int sp_4096_mod_128(sp_digit* r, const sp_digit* a, const sp_di static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 256]; @@ -92439,7 +92444,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -92541,7 +92546,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -92563,7 +92568,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 256]; @@ -92582,7 +92587,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -92693,7 +92698,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -92720,7 +92725,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[128 * 5]; @@ -92742,7 +92747,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 128 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -92857,7 +92862,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -92962,7 +92967,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[128 * 4]; @@ -92996,7 +93001,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 128 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -93021,21 +93026,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 128); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[64 * 11]; @@ -93070,7 +93075,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -93118,12 +93123,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 64 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -96444,7 +96449,7 @@ static void sp_4096_lshift_128(sp_digit* r, const sp_digit* a, byte n) static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[385]; @@ -96464,7 +96469,7 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -96549,7 +96554,7 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -101050,7 +101055,7 @@ static void sp_256_get_point_16_8(sp_point_256* r, const sp_point_256* table, static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -101059,7 +101064,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons #endif sp_point_256* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* p = NULL; #else sp_point_256 p[1]; @@ -101075,7 +101080,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -101186,32 +101191,32 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 8 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_256) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -101438,7 +101443,7 @@ static void sp_256_proj_point_add_qz1_8(sp_point_256* r, static int sp_256_gen_stripe_table_8(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -101451,7 +101456,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -101506,7 +101511,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -101585,7 +101590,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -101605,7 +101610,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -101671,7 +101676,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -101791,7 +101796,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 8 * 6]; @@ -101799,7 +101804,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -101835,7 +101840,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -101858,7 +101863,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ static int sp_256_gen_stripe_table_8(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -101871,7 +101876,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -101926,7 +101931,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -102005,7 +102010,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -102025,7 +102030,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -102091,7 +102096,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -102211,7 +102216,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 8 * 6]; @@ -102219,7 +102224,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -102255,7 +102260,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -102276,7 +102281,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -102285,7 +102290,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -102308,7 +102313,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -102333,7 +102338,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -102344,7 +102349,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -102388,7 +102393,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -103827,7 +103832,7 @@ static int sp_256_ecc_mulmod_base_8(sp_point_256* r, const sp_digit* k, */ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -103836,7 +103841,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -103858,7 +103863,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -103882,7 +103887,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -103893,7 +103898,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -103936,7 +103941,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -104110,7 +104115,7 @@ static int sp_256_ecc_gen_k_8(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -104129,7 +104134,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -104174,7 +104179,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_256_point_to_ecc_point_8(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -104299,7 +104304,7 @@ static void sp_256_to_bin_8(sp_digit* r, byte* a) int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -104312,7 +104317,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -104337,7 +104342,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 32; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -105731,7 +105736,7 @@ static int sp_256_calc_s_8(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_256* point = NULL; #else @@ -105749,7 +105754,7 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -105828,21 +105833,21 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_256_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 8); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -107392,7 +107397,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_256* p1 = NULL; #else @@ -107407,7 +107412,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -107478,7 +107483,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -107650,7 +107655,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_256_ecc_is_point_8(const sp_point_256* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[8 * 4]; @@ -107658,7 +107663,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -107686,7 +107691,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -107703,7 +107708,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, */ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* pub = NULL; #else sp_point_256 pub[1]; @@ -107711,7 +107716,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -107726,7 +107731,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) err = sp_256_ecc_is_point_8(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -107748,7 +107753,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_256* pub = NULL; #else @@ -107769,7 +107774,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -107835,7 +107840,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -107864,7 +107869,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -107874,7 +107879,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_256* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -107917,7 +107922,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -107941,7 +107946,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -107950,7 +107955,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -107985,7 +107990,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -108005,7 +108010,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -108015,7 +108020,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -108049,7 +108054,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_256_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -108067,7 +108072,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_256_mont_sqrt_8(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 8]; @@ -108075,7 +108080,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 8, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) { err = MEMORY_E; @@ -108118,7 +108123,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -108136,7 +108141,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) */ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 8]; @@ -108144,7 +108149,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 8, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -108184,7 +108189,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) err = sp_256_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -109350,7 +109355,7 @@ SP_NOINLINE static sp_digit sp_384_sub_12(sp_digit* r, const sp_digit* a, */ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[12]; @@ -109360,7 +109365,7 @@ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 12, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) { err = MEMORY_E; @@ -109435,7 +109440,7 @@ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit r[11] = t[11]; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -111726,7 +111731,7 @@ static void sp_384_get_point_16_12(sp_point_384* r, const sp_point_384* table, static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -111735,7 +111740,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con #endif sp_point_384* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* p = NULL; #else sp_point_384 p[1]; @@ -111751,7 +111756,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -111862,32 +111867,32 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 12 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_384) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -112114,7 +112119,7 @@ static void sp_384_proj_point_add_qz1_12(sp_point_384* r, static int sp_384_gen_stripe_table_12(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -112127,7 +112132,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -112182,7 +112187,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -112277,7 +112282,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -112297,7 +112302,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -112363,7 +112368,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -112483,7 +112488,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp #ifndef FP_ECC return sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 12 * 7]; @@ -112491,7 +112496,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -112527,7 +112532,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -112550,7 +112555,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp static int sp_384_gen_stripe_table_12(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -112563,7 +112568,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -112618,7 +112623,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -112713,7 +112718,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -112733,7 +112738,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -112799,7 +112804,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -112919,7 +112924,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp #ifndef FP_ECC return sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 12 * 7]; @@ -112927,7 +112932,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -112963,7 +112968,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -112984,7 +112989,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -112993,7 +112998,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -113016,7 +113021,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -113041,7 +113046,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -113052,7 +113057,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -113096,7 +113101,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -114535,7 +114540,7 @@ static int sp_384_ecc_mulmod_base_12(sp_point_384* r, const sp_digit* k, */ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -114544,7 +114549,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -114566,7 +114571,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -114590,7 +114595,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -114601,7 +114606,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -114644,7 +114649,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -114854,7 +114859,7 @@ static int sp_384_ecc_gen_k_12(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -114873,7 +114878,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -114918,7 +114923,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_384_point_to_ecc_point_12(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -115043,7 +115048,7 @@ static void sp_384_to_bin_12(sp_digit* r, byte* a) int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -115056,7 +115061,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -115081,7 +115086,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 48; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -116486,7 +116491,7 @@ static int sp_384_calc_s_12(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_384* point = NULL; #else @@ -116504,7 +116509,7 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -116583,21 +116588,21 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_384_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 12); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -118576,7 +118581,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_384* p1 = NULL; #else @@ -118591,7 +118596,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -118662,7 +118667,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -118834,7 +118839,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_384_ecc_is_point_12(const sp_point_384* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[12 * 4]; @@ -118842,7 +118847,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 12 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -118870,7 +118875,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -118887,7 +118892,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, */ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* pub = NULL; #else sp_point_384 pub[1]; @@ -118895,7 +118900,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -118910,7 +118915,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) err = sp_384_ecc_is_point_12(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -118932,7 +118937,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_384* pub = NULL; #else @@ -118953,7 +118958,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -119019,7 +119024,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -119048,7 +119053,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -119058,7 +119063,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_384* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -119101,7 +119106,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -119125,7 +119130,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -119134,7 +119139,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -119169,7 +119174,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -119189,7 +119194,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -119199,7 +119204,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -119233,7 +119238,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_384_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -119251,7 +119256,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_384_mont_sqrt_12(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[5 * 2 * 12]; @@ -119262,7 +119267,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) sp_digit* t5 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 2 * 12, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -119332,7 +119337,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -119350,7 +119355,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) */ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 12]; @@ -119358,7 +119363,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 12, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -119398,7 +119403,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) err = sp_384_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -125571,7 +125576,7 @@ static void sp_521_get_point_16_17(sp_point_521* r, const sp_point_521* table, static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -125580,7 +125585,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con #endif sp_point_521* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* p = NULL; #else sp_point_521 p[1]; @@ -125596,7 +125601,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -125711,32 +125716,32 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 17 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_521) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -125963,7 +125968,7 @@ static void sp_521_proj_point_add_qz1_17(sp_point_521* r, static int sp_521_gen_stripe_table_17(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -125976,7 +125981,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -126031,7 +126036,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -126146,7 +126151,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -126166,7 +126171,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -126232,7 +126237,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -126352,7 +126357,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp #ifndef FP_ECC return sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 17 * 6]; @@ -126360,7 +126365,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -126396,7 +126401,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -126419,7 +126424,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp static int sp_521_gen_stripe_table_17(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -126432,7 +126437,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -126487,7 +126492,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -126602,7 +126607,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -126622,7 +126627,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -126688,7 +126693,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -126808,7 +126813,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp #ifndef FP_ECC return sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 17 * 6]; @@ -126816,7 +126821,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -126852,7 +126857,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -126873,7 +126878,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -126882,7 +126887,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -126905,7 +126910,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -126930,7 +126935,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -126941,7 +126946,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -126985,7 +126990,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -128968,7 +128973,7 @@ static int sp_521_ecc_mulmod_base_17(sp_point_521* r, const sp_digit* k, */ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -128977,7 +128982,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -128999,7 +129004,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -129023,7 +129028,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -129034,7 +129039,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -129077,7 +129082,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -129333,7 +129338,7 @@ static int sp_521_ecc_gen_k_17(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -129352,7 +129357,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -129397,7 +129402,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_521_point_to_ecc_point_17(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -129524,7 +129529,7 @@ static void sp_521_to_bin_17(sp_digit* r, byte* a) int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -129537,7 +129542,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -129562,7 +129567,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 66; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -132671,7 +132676,7 @@ static int sp_521_calc_s_17(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_521* point = NULL; #else @@ -132689,7 +132694,7 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -132773,21 +132778,21 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_521_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -135499,7 +135504,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_521* p1 = NULL; #else @@ -135514,7 +135519,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -135589,7 +135594,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -135764,7 +135769,7 @@ int sp_ecc_verify_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_521_ecc_is_point_17(const sp_point_521* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[17 * 4]; @@ -135772,7 +135777,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -135800,7 +135805,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -135817,7 +135822,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, */ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* pub = NULL; #else sp_point_521 pub[1]; @@ -135825,7 +135830,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -135840,7 +135845,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) err = sp_521_ecc_is_point_17(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -135862,7 +135867,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_521* pub = NULL; #else @@ -135883,7 +135888,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -135949,7 +135954,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -135978,7 +135983,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -135988,7 +135993,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_521* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -136031,7 +136036,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -136055,7 +136060,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -136064,7 +136069,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -136099,7 +136104,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -136119,7 +136124,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -136129,7 +136134,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -136163,7 +136168,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_521_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -136188,14 +136193,14 @@ static const uint32_t p521_sqrt_power[17] = { */ static int sp_521_mont_sqrt_17(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t = NULL; #else sp_digit t[2 * 17]; #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -136216,7 +136221,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -136234,7 +136239,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) */ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 17]; @@ -136242,7 +136247,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 17, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -136282,7 +136287,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) err = sp_521_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -202395,7 +202400,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, { int ret = MP_OKAY; (void)heap; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) (void)sp; *p = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); #else @@ -202407,7 +202413,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, return ret; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* Allocate memory for point and return error. */ #define sp_1024_point_new_32(heap, sp, p) sp_1024_point_new_ex_32((heap), NULL, &(p)) #else @@ -202424,7 +202431,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, */ static void sp_1024_point_free_32(sp_point_1024* p, int clear, void* heap) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* If valid pointer then clear point data if requested and free data. */ if (p != NULL) { if (clear != 0) { @@ -210450,7 +210458,7 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -210468,7 +210476,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -210551,21 +210559,21 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 37); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_1024) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -210792,7 +210800,7 @@ static void sp_1024_proj_point_add_qz1_32(sp_point_1024* r, static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -210805,7 +210813,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -210860,7 +210868,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -210889,7 +210897,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -210909,7 +210917,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -210960,7 +210968,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -211080,7 +211088,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 32 * 38]; @@ -211088,7 +211096,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -211124,7 +211132,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -211147,7 +211155,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -211160,7 +211168,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -211215,7 +211223,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -211244,7 +211252,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -211264,7 +211272,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -211315,7 +211323,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -211435,7 +211443,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 32 * 38]; @@ -211443,7 +211451,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -211479,7 +211487,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -211500,7 +211508,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -211509,7 +211517,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -211532,7 +211540,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -215139,7 +215147,7 @@ static int sp_1024_ecc_mulmod_base_32(sp_point_1024* r, const sp_digit* k, */ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -215148,7 +215156,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -215170,7 +215178,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -215194,7 +215202,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -215205,7 +215213,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -215248,7 +215256,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -215271,7 +215279,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* t = NULL; #else @@ -215292,7 +215300,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); @@ -215316,7 +215324,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, *len = sizeof(sp_table_entry_1024) * 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -215374,7 +215382,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -215383,7 +215391,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) { @@ -215412,7 +215420,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -215487,8 +215495,8 @@ static void sp_1024_proj_sqr_32(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -215507,8 +215515,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -215517,8 +215525,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 32 * 2; ty = td + 37 * 32 * 2; @@ -215561,8 +215569,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -217386,8 +217394,8 @@ static const sp_digit sp_1024_g_table[256][32] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -217405,8 +217413,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -217415,8 +217423,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 32 * 2; ty = td + 37 * 32 * 2; @@ -217459,8 +217467,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -217730,8 +217738,8 @@ static void sp_1024_accumulate_line_add_one_32(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -217760,8 +217768,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -217772,8 +217780,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -217829,8 +217837,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -218108,8 +218116,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -218145,8 +218153,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -218157,8 +218165,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -218256,8 +218264,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -218497,8 +218505,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -218537,8 +218545,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_32(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -218549,8 +218557,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; pre_p = (sp_point_1024*)(td + 36 * 32 * 2); #endif @@ -218624,8 +218632,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -218659,8 +218667,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -218702,8 +218710,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -218714,8 +218722,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -218819,8 +218827,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -218881,7 +218889,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) static int sp_1024_ecc_is_point_32(const sp_point_1024* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[32 * 4]; @@ -218890,7 +218898,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, sp_int32 n; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -218921,7 +218929,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -218938,7 +218946,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, */ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* pub = NULL; #else sp_point_1024 pub[1]; @@ -218946,7 +218954,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -218961,7 +218969,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) err = sp_1024_ecc_is_point_32(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -218983,7 +218991,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_1024* pub = NULL; #else @@ -219004,7 +219012,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); @@ -219070,7 +219078,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) diff --git a/wolfcrypt/src/sp_c32.c b/wolfcrypt/src/sp_c32.c index e6bdcfb52..c9821829d 100644 --- a/wolfcrypt/src/sp_c32.c +++ b/wolfcrypt/src/sp_c32.c @@ -49,6 +49,11 @@ #endif #endif +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#undef WOLFSSL_SP_SMALL_STACK +#define WOLFSSL_SP_SMALL_STACK +#endif + #include #ifndef WOLFSSL_SP_ASM @@ -82,7 +87,8 @@ static const size_t addr_mask[2] = { 0, (size_t)-1 }; #endif -#if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || !defined(WOLFSSL_SP_SMALL)) +#if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || \ + !defined(WOLFSSL_SP_SMALL)) #error SP non-blocking requires small and no-malloc (WOLFSSL_SP_SMALL and WOLFSSL_SP_NO_MALLOC) #endif @@ -2023,7 +2029,7 @@ static int sp_2048_div_36(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 36 + 3]; @@ -2034,7 +2040,7 @@ static int sp_2048_div_36(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 36 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -2085,7 +2091,7 @@ static int sp_2048_div_36(const sp_digit* a, const sp_digit* d, sp_2048_rshift_36(r, r, 20); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -2120,7 +2126,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 72]; @@ -2138,7 +2144,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 36 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -2204,14 +2210,14 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 72]; @@ -2229,7 +2235,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 36 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -2294,14 +2300,14 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 36 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 72) + 72]; @@ -2320,7 +2326,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 72) + 72), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -2440,7 +2446,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 72); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -3085,7 +3091,7 @@ static int sp_2048_div_72(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 72 + 3]; @@ -3096,7 +3102,7 @@ static int sp_2048_div_72(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 72 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -3147,7 +3153,7 @@ static int sp_2048_div_72(const sp_digit* a, const sp_digit* d, r[71] = 0; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -3185,7 +3191,7 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 144]; @@ -3203,7 +3209,7 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 72 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3269,14 +3275,14 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 144]; @@ -3294,7 +3300,7 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 72 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3359,14 +3365,14 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 72 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 144) + 144]; @@ -3385,7 +3391,7 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 144) + 144), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3488,7 +3494,7 @@ static int sp_2048_mod_exp_72(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 144); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -3517,7 +3523,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[72 * 5]; @@ -3549,7 +3555,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 72 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -3610,14 +3616,14 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[72 * 5]; @@ -3646,7 +3652,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 72 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -3722,7 +3728,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -3757,7 +3763,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[72 * 4]; @@ -3791,7 +3797,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 72 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -3816,21 +3822,21 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 72); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[72 * 4]; @@ -3864,7 +3870,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 72 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -3889,14 +3895,14 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 72); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -3905,7 +3911,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[36 * 8]; @@ -3943,7 +3949,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -3991,19 +3997,19 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 36 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[36 * 13]; @@ -4042,7 +4048,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -4093,12 +4099,12 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 36 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -4194,7 +4200,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[72 * 4]; @@ -4217,7 +4223,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 72 * 4, NULL, DYNAMIC_TYPE_DH); @@ -4242,20 +4248,20 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_2048_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 72U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[72 * 4]; @@ -4279,7 +4285,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 72 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -4304,14 +4310,14 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 72U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -4497,7 +4503,7 @@ SP_NOINLINE static void sp_2048_lshift_72(sp_digit* r, const sp_digit* a, */ static int sp_2048_mod_exp_2_72(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[217]; @@ -4516,7 +4522,7 @@ static int sp_2048_mod_exp_2_72(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 217, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4595,7 +4601,7 @@ static int sp_2048_mod_exp_2_72(sp_digit* r, const sp_digit* e, int bits, const sp_2048_cond_sub_72(r, r, m, ~(n >> 31)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4620,7 +4626,7 @@ static int sp_2048_mod_exp_2_72(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[72 * 4]; @@ -4644,7 +4650,7 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 72 * 4, NULL, DYNAMIC_TYPE_DH); @@ -4685,14 +4691,14 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 72U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -4715,7 +4721,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[36 * 4]; @@ -4738,7 +4744,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL, DYNAMIC_TYPE_DH); @@ -4764,20 +4770,20 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_2048_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 72U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[36 * 4]; @@ -4801,7 +4807,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -4827,14 +4833,14 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 72U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -5708,7 +5714,7 @@ static int sp_3072_div_53(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 53 + 3]; @@ -5719,7 +5725,7 @@ static int sp_3072_div_53(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 53 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -5770,7 +5776,7 @@ static int sp_3072_div_53(const sp_digit* a, const sp_digit* d, sp_3072_rshift_53(r, r, 1); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -5805,7 +5811,7 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 106]; @@ -5823,7 +5829,7 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 53 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5889,14 +5895,14 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 106]; @@ -5914,7 +5920,7 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 53 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5979,14 +5985,14 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 53 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 106) + 106]; @@ -6005,7 +6011,7 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 106) + 106), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -6125,7 +6131,7 @@ static int sp_3072_mod_exp_53(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 106); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -6547,7 +6553,7 @@ static int sp_3072_div_106(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 106 + 3]; @@ -6558,7 +6564,7 @@ static int sp_3072_div_106(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 106 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -6609,7 +6615,7 @@ static int sp_3072_div_106(const sp_digit* a, const sp_digit* d, sp_3072_rshift_106(r, r, 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -6645,7 +6651,7 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 212]; @@ -6663,7 +6669,7 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 106 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -6729,14 +6735,14 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 212]; @@ -6754,7 +6760,7 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 106 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -6819,14 +6825,14 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e XMEMCPY(r, t[0], sizeof(*r) * 106 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 212) + 212]; @@ -6845,7 +6851,7 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 212) + 212), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -6948,7 +6954,7 @@ static int sp_3072_mod_exp_106(sp_digit* r, const sp_digit* a, const sp_digit* e XMEMCPY(r, rt, sizeof(sp_digit) * 212); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -6975,7 +6981,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[106 * 5]; @@ -7007,7 +7013,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 106 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -7068,14 +7074,14 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[106 * 5]; @@ -7104,7 +7110,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 106 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -7180,7 +7186,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -7215,7 +7221,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[106 * 4]; @@ -7249,7 +7255,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 106 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -7274,21 +7280,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 106); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[106 * 4]; @@ -7322,7 +7328,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 106 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -7347,14 +7353,14 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 106); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -7363,7 +7369,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[53 * 8]; @@ -7401,7 +7407,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 53 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -7449,19 +7455,19 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 53 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[53 * 13]; @@ -7500,7 +7506,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 53 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -7551,12 +7557,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 53 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -7652,7 +7658,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[106 * 4]; @@ -7675,7 +7681,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 106 * 4, NULL, DYNAMIC_TYPE_DH); @@ -7700,20 +7706,20 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 106U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[106 * 4]; @@ -7737,7 +7743,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 106 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -7762,14 +7768,14 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 106U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -7805,7 +7811,7 @@ SP_NOINLINE static void sp_3072_lshift_106(sp_digit* r, const sp_digit* a, */ static int sp_3072_mod_exp_2_106(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[319]; @@ -7824,7 +7830,7 @@ static int sp_3072_mod_exp_2_106(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 319, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -7903,7 +7909,7 @@ static int sp_3072_mod_exp_2_106(sp_digit* r, const sp_digit* e, int bits, const sp_3072_cond_sub_106(r, r, m, ~(n >> 31)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -7928,7 +7934,7 @@ static int sp_3072_mod_exp_2_106(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[106 * 4]; @@ -7952,7 +7958,7 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 106 * 4, NULL, DYNAMIC_TYPE_DH); @@ -7993,14 +7999,14 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 106U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -8023,7 +8029,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[53 * 4]; @@ -8046,7 +8052,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 53 * 4, NULL, DYNAMIC_TYPE_DH); @@ -8072,20 +8078,20 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 106U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[53 * 4]; @@ -8109,7 +8115,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 53 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -8135,14 +8141,14 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 106U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -9742,7 +9748,7 @@ static int sp_3072_div_56(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 56 + 3]; @@ -9753,7 +9759,7 @@ static int sp_3072_div_56(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 56 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -9804,7 +9810,7 @@ static int sp_3072_div_56(const sp_digit* a, const sp_digit* d, r[55] = 0; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -9839,7 +9845,7 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 112]; @@ -9857,7 +9863,7 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 56 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -9923,14 +9929,14 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 112]; @@ -9948,7 +9954,7 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 56 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -10013,14 +10019,14 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 56 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 112) + 112]; @@ -10039,7 +10045,7 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 112) + 112), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -10159,7 +10165,7 @@ static int sp_3072_mod_exp_56(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 112); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -10660,7 +10666,7 @@ static int sp_3072_div_112(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 112 + 3]; @@ -10671,7 +10677,7 @@ static int sp_3072_div_112(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 112 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -10723,7 +10729,7 @@ static int sp_3072_div_112(const sp_digit* a, const sp_digit* d, r[111] = 0; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -10761,7 +10767,7 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 224]; @@ -10779,7 +10785,7 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 112 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -10845,14 +10851,14 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 224]; @@ -10870,7 +10876,7 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 112 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -10935,14 +10941,14 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e XMEMCPY(r, t[0], sizeof(*r) * 112 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 224) + 224]; @@ -10961,7 +10967,7 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 224) + 224), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -11064,7 +11070,7 @@ static int sp_3072_mod_exp_112(sp_digit* r, const sp_digit* a, const sp_digit* e XMEMCPY(r, rt, sizeof(sp_digit) * 224); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -11093,7 +11099,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[112 * 5]; @@ -11125,7 +11131,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 112 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -11186,14 +11192,14 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[112 * 5]; @@ -11222,7 +11228,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 112 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -11298,7 +11304,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -11333,7 +11339,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[112 * 4]; @@ -11367,7 +11373,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 112 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -11392,21 +11398,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 112); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[112 * 4]; @@ -11440,7 +11446,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 112 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -11465,14 +11471,14 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 112); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -11481,7 +11487,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[56 * 8]; @@ -11519,7 +11525,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -11567,19 +11573,19 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 56 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[56 * 13]; @@ -11618,7 +11624,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -11669,12 +11675,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 56 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -11770,7 +11776,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[112 * 4]; @@ -11793,7 +11799,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 112 * 4, NULL, DYNAMIC_TYPE_DH); @@ -11818,20 +11824,20 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 112U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[112 * 4]; @@ -11855,7 +11861,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 112 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -11880,14 +11886,14 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 112U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -12144,7 +12150,7 @@ SP_NOINLINE static void sp_3072_lshift_112(sp_digit* r, const sp_digit* a, */ static int sp_3072_mod_exp_2_112(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[337]; @@ -12163,7 +12169,7 @@ static int sp_3072_mod_exp_2_112(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 337, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -12242,7 +12248,7 @@ static int sp_3072_mod_exp_2_112(sp_digit* r, const sp_digit* e, int bits, const sp_3072_cond_sub_112(r, r, m, ~(n >> 31)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -12267,7 +12273,7 @@ static int sp_3072_mod_exp_2_112(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[112 * 4]; @@ -12291,7 +12297,7 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 112 * 4, NULL, DYNAMIC_TYPE_DH); @@ -12332,14 +12338,14 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 112U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -12362,7 +12368,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[56 * 4]; @@ -12385,7 +12391,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 4, NULL, DYNAMIC_TYPE_DH); @@ -12411,20 +12417,20 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 112U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[56 * 4]; @@ -12448,7 +12454,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -12474,14 +12480,14 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 112U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -13365,7 +13371,7 @@ static int sp_4096_div_71(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 71 + 3]; @@ -13376,7 +13382,7 @@ static int sp_4096_div_71(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 71 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -13427,7 +13433,7 @@ static int sp_4096_div_71(const sp_digit* a, const sp_digit* d, sp_4096_rshift_71(r, r, 11); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -13462,7 +13468,7 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 142]; @@ -13480,7 +13486,7 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 71 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -13546,14 +13552,14 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 142]; @@ -13571,7 +13577,7 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 71 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -13636,14 +13642,14 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 71 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 142) + 142]; @@ -13662,7 +13668,7 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 142) + 142), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -13782,7 +13788,7 @@ static int sp_4096_mod_exp_71(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 142); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -14205,7 +14211,7 @@ static int sp_4096_div_142(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 142 + 3]; @@ -14216,7 +14222,7 @@ static int sp_4096_div_142(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 142 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -14267,7 +14273,7 @@ static int sp_4096_div_142(const sp_digit* a, const sp_digit* d, sp_4096_rshift_142(r, r, 22); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -14303,7 +14309,7 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 284]; @@ -14321,7 +14327,7 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 142 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -14387,14 +14393,14 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 284]; @@ -14412,7 +14418,7 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 142 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -14477,14 +14483,14 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e XMEMCPY(r, t[0], sizeof(*r) * 142 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 284) + 284]; @@ -14503,7 +14509,7 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 284) + 284), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -14606,7 +14612,7 @@ static int sp_4096_mod_exp_142(sp_digit* r, const sp_digit* a, const sp_digit* e XMEMCPY(r, rt, sizeof(sp_digit) * 284); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -14633,7 +14639,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[142 * 5]; @@ -14665,7 +14671,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 142 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -14726,14 +14732,14 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[142 * 5]; @@ -14762,7 +14768,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 142 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -14838,7 +14844,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -14873,7 +14879,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[142 * 4]; @@ -14907,7 +14913,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 142 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -14932,21 +14938,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 142); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[142 * 4]; @@ -14980,7 +14986,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 142 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -15005,14 +15011,14 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 142); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -15021,7 +15027,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[71 * 8]; @@ -15059,7 +15065,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 71 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -15107,19 +15113,19 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 71 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[71 * 13]; @@ -15158,7 +15164,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 71 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -15209,12 +15215,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 71 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -15310,7 +15316,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[142 * 4]; @@ -15333,7 +15339,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 142 * 4, NULL, DYNAMIC_TYPE_DH); @@ -15358,20 +15364,20 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_4096_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 142U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[142 * 4]; @@ -15395,7 +15401,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 142 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -15420,14 +15426,14 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 142U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -15463,7 +15469,7 @@ SP_NOINLINE static void sp_4096_lshift_142(sp_digit* r, const sp_digit* a, */ static int sp_4096_mod_exp_2_142(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[427]; @@ -15482,7 +15488,7 @@ static int sp_4096_mod_exp_2_142(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 427, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15561,7 +15567,7 @@ static int sp_4096_mod_exp_2_142(sp_digit* r, const sp_digit* e, int bits, const sp_4096_cond_sub_142(r, r, m, ~(n >> 31)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -15586,7 +15592,7 @@ static int sp_4096_mod_exp_2_142(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[142 * 4]; @@ -15610,7 +15616,7 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 142 * 4, NULL, DYNAMIC_TYPE_DH); @@ -15651,14 +15657,14 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 142U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -17279,7 +17285,7 @@ static int sp_4096_div_81(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 81 + 3]; @@ -17290,7 +17296,7 @@ static int sp_4096_div_81(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 81 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -17342,7 +17348,7 @@ static int sp_4096_div_81(const sp_digit* a, const sp_digit* d, r[80] = 0; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -17377,7 +17383,7 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 162]; @@ -17395,7 +17401,7 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 81 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -17461,14 +17467,14 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 162]; @@ -17486,7 +17492,7 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 81 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -17551,14 +17557,14 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 81 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 162) + 162]; @@ -17577,7 +17583,7 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 162) + 162), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -17697,7 +17703,7 @@ static int sp_4096_mod_exp_81(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 162); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -18183,7 +18189,7 @@ static int sp_4096_div_162(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 162 + 3]; @@ -18194,7 +18200,7 @@ static int sp_4096_div_162(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 162 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -18248,7 +18254,7 @@ static int sp_4096_div_162(const sp_digit* a, const sp_digit* d, r[161] = 0; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -18286,7 +18292,7 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 324]; @@ -18304,7 +18310,7 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 162 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -18370,14 +18376,14 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 324]; @@ -18395,7 +18401,7 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 162 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -18460,14 +18466,14 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e XMEMCPY(r, t[0], sizeof(*r) * 162 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 324) + 324]; @@ -18486,7 +18492,7 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 324) + 324), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -18589,7 +18595,7 @@ static int sp_4096_mod_exp_162(sp_digit* r, const sp_digit* a, const sp_digit* e XMEMCPY(r, rt, sizeof(sp_digit) * 324); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -18618,7 +18624,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[162 * 5]; @@ -18650,7 +18656,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 162 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -18711,14 +18717,14 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[162 * 5]; @@ -18747,7 +18753,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 162 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -18823,7 +18829,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -18858,7 +18864,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[162 * 4]; @@ -18892,7 +18898,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 162 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -18917,21 +18923,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 162); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[162 * 4]; @@ -18965,7 +18971,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 162 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -18990,14 +18996,14 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 162); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -19006,7 +19012,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[81 * 8]; @@ -19044,7 +19050,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 81 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -19092,19 +19098,19 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 81 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[81 * 13]; @@ -19143,7 +19149,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 81 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -19194,12 +19200,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 81 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -19295,7 +19301,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[162 * 4]; @@ -19318,7 +19324,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 162 * 4, NULL, DYNAMIC_TYPE_DH); @@ -19343,20 +19349,20 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_4096_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 162U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[162 * 4]; @@ -19380,7 +19386,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 162 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -19405,14 +19411,14 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 162U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -19769,7 +19775,7 @@ SP_NOINLINE static void sp_4096_lshift_162(sp_digit* r, const sp_digit* a, */ static int sp_4096_mod_exp_2_162(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[487]; @@ -19788,7 +19794,7 @@ static int sp_4096_mod_exp_2_162(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 487, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -19867,7 +19873,7 @@ static int sp_4096_mod_exp_2_162(sp_digit* r, const sp_digit* e, int bits, const sp_4096_cond_sub_162(r, r, m, ~(n >> 31)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -19892,7 +19898,7 @@ static int sp_4096_mod_exp_2_162(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[162 * 4]; @@ -19916,7 +19922,7 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 162 * 4, NULL, DYNAMIC_TYPE_DH); @@ -19957,14 +19963,14 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 162U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -21770,7 +21776,7 @@ static int sp_256_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r, */ static int sp_256_mod_mul_norm_9(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[2 * 8]; @@ -21781,7 +21787,7 @@ static int sp_256_mod_mul_norm_9(sp_digit* r, const sp_digit* a, const sp_digit* (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 2 * 8, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) return MEMORY_E; @@ -21877,7 +21883,7 @@ static int sp_256_mod_mul_norm_9(sp_digit* r, const sp_digit* a, const sp_digit* r[8] = (sp_digit)(t[7] >> 8U); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -21904,7 +21910,7 @@ static int sp_256_mod_mul_norm_9(sp_digit* r, const sp_digit* a, const sp_digit* static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -21921,7 +21927,7 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -21982,21 +21988,21 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 9 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_256) * 3); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -22575,7 +22581,7 @@ static void sp_256_get_point_33_9(sp_point_256* r, const sp_point_256* table, static int sp_256_ecc_mulmod_win_add_sub_9(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -22593,7 +22599,7 @@ static int sp_256_ecc_mulmod_win_add_sub_9(sp_point_256* r, const sp_point_256* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -22689,7 +22695,7 @@ static int sp_256_ecc_mulmod_win_add_sub_9(sp_point_256* r, const sp_point_256* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -22816,7 +22822,7 @@ static void sp_256_proj_to_affine_9(sp_point_256* a, sp_digit* t) static int sp_256_gen_stripe_table_9(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -22829,7 +22835,7 @@ static int sp_256_gen_stripe_table_9(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -22884,7 +22890,7 @@ static int sp_256_gen_stripe_table_9(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -22967,7 +22973,7 @@ static int sp_256_ecc_mulmod_stripe_9(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -22987,7 +22993,7 @@ static int sp_256_ecc_mulmod_stripe_9(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -23053,7 +23059,7 @@ static int sp_256_ecc_mulmod_stripe_9(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -23173,7 +23179,7 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 9 * 6]; @@ -23181,7 +23187,7 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -23217,7 +23223,7 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -23238,7 +23244,7 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, const sp_ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -23247,7 +23253,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -23270,7 +23276,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_256_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -23295,7 +23301,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -23306,7 +23312,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -23350,7 +23356,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, err = sp_256_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -24708,7 +24714,7 @@ static int sp_256_ecc_mulmod_base_9(sp_point_256* r, const sp_digit* k, */ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24717,7 +24723,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -24739,7 +24745,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_256_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -24763,7 +24769,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24774,7 +24780,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -24817,7 +24823,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, err = sp_256_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -24914,7 +24920,7 @@ static int sp_256_ecc_gen_k_9(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24933,7 +24939,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -24978,7 +24984,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_256_point_to_ecc_point_9(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -25128,7 +25134,7 @@ static void sp_256_to_bin_9(sp_digit* r, byte* a) int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -25141,7 +25147,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -25166,7 +25172,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 32; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -25371,7 +25377,7 @@ static int sp_256_div_9(const sp_digit* a, const sp_digit* d, int i; sp_digit r1; sp_digit mask; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 9 + 3]; @@ -25382,7 +25388,7 @@ static int sp_256_div_9(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 9 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -25414,7 +25420,7 @@ static int sp_256_div_9(const sp_digit* a, const sp_digit* d, sp_256_rshift_9(r, t1, 5); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -25710,7 +25716,7 @@ static int sp_256_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_256* point = NULL; #else @@ -25728,7 +25734,7 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -25807,21 +25813,21 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_256_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 9); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -26037,7 +26043,7 @@ static int sp_256_num_bits_9(const sp_digit* a) static int sp_256_mod_inv_9(sp_digit* r, const sp_digit* a, const sp_digit* m) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u = NULL; #else sp_digit u[9 * 4]; @@ -26048,7 +26054,7 @@ static int sp_256_mod_inv_9(sp_digit* r, const sp_digit* a, const sp_digit* m) int ut; int vt; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 4, NULL, DYNAMIC_TYPE_ECC); if (u == NULL) @@ -26136,7 +26142,7 @@ static int sp_256_mod_inv_9(sp_digit* r, const sp_digit* a, const sp_digit* m) else XMEMCPY(r, d, sizeof(sp_digit) * 9); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u != NULL) XFREE(u, NULL, DYNAMIC_TYPE_ECC); #endif @@ -26259,7 +26265,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_256* p1 = NULL; #else @@ -26274,7 +26280,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -26345,7 +26351,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -26517,7 +26523,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_256_ecc_is_point_9(const sp_point_256* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[9 * 4]; @@ -26525,7 +26531,7 @@ static int sp_256_ecc_is_point_9(const sp_point_256* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -26553,7 +26559,7 @@ static int sp_256_ecc_is_point_9(const sp_point_256* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -26570,7 +26576,7 @@ static int sp_256_ecc_is_point_9(const sp_point_256* point, */ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* pub = NULL; #else sp_point_256 pub[1]; @@ -26578,7 +26584,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -26593,7 +26599,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) err = sp_256_ecc_is_point_9(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -26615,7 +26621,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_256* pub = NULL; #else @@ -26636,7 +26642,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -26702,7 +26708,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -26731,7 +26737,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -26741,7 +26747,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_256* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -26784,7 +26790,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -26808,7 +26814,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -26817,7 +26823,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -26852,7 +26858,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -26872,7 +26878,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -26882,7 +26888,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -26916,7 +26922,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_256_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -26934,7 +26940,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_256_mont_sqrt_9(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 9]; @@ -26942,7 +26948,7 @@ static int sp_256_mont_sqrt_9(sp_digit* y) sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 9, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) { err = MEMORY_E; @@ -26985,7 +26991,7 @@ static int sp_256_mont_sqrt_9(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -27003,7 +27009,7 @@ static int sp_256_mont_sqrt_9(sp_digit* y) */ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 9]; @@ -27011,7 +27017,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 9, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -27051,7 +27057,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) err = sp_256_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -29191,7 +29197,7 @@ static int sp_384_proj_point_add_15_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r, */ static int sp_384_mod_mul_norm_15(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[2 * 12]; @@ -29202,7 +29208,7 @@ static int sp_384_mod_mul_norm_15(sp_digit* r, const sp_digit* a, const sp_digit (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 2 * 12, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -29342,7 +29348,7 @@ static int sp_384_mod_mul_norm_15(sp_digit* r, const sp_digit* a, const sp_digit r[14] = (sp_digit)(t[11] >> 12U); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -29369,7 +29375,7 @@ static int sp_384_mod_mul_norm_15(sp_digit* r, const sp_digit* a, const sp_digit static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -29386,7 +29392,7 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -29447,21 +29453,21 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 15 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_384) * 3); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -30088,7 +30094,7 @@ static void sp_384_get_point_33_15(sp_point_384* r, const sp_point_384* table, static int sp_384_ecc_mulmod_win_add_sub_15(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -30106,7 +30112,7 @@ static int sp_384_ecc_mulmod_win_add_sub_15(sp_point_384* r, const sp_point_384* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -30202,7 +30208,7 @@ static int sp_384_ecc_mulmod_win_add_sub_15(sp_point_384* r, const sp_point_384* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -30329,7 +30335,7 @@ static void sp_384_proj_to_affine_15(sp_point_384* a, sp_digit* t) static int sp_384_gen_stripe_table_15(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -30342,7 +30348,7 @@ static int sp_384_gen_stripe_table_15(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -30397,7 +30403,7 @@ static int sp_384_gen_stripe_table_15(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -30504,7 +30510,7 @@ static int sp_384_ecc_mulmod_stripe_15(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -30524,7 +30530,7 @@ static int sp_384_ecc_mulmod_stripe_15(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -30590,7 +30596,7 @@ static int sp_384_ecc_mulmod_stripe_15(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -30710,7 +30716,7 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, const sp #ifndef FP_ECC return sp_384_ecc_mulmod_win_add_sub_15(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 15 * 7]; @@ -30718,7 +30724,7 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, const sp sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 15 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -30754,7 +30760,7 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -30775,7 +30781,7 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, const sp int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -30784,7 +30790,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -30807,7 +30813,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_384_point_to_ecc_point_15(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -30832,7 +30838,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -30843,7 +30849,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -30887,7 +30893,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, err = sp_384_point_to_ecc_point_15(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -32757,7 +32763,7 @@ static int sp_384_ecc_mulmod_base_15(sp_point_384* r, const sp_digit* k, */ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -32766,7 +32772,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -32788,7 +32794,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_384_point_to_ecc_point_15(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -32812,7 +32818,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -32823,7 +32829,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -32866,7 +32872,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, err = sp_384_point_to_ecc_point_15(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -32963,7 +32969,7 @@ static int sp_384_ecc_gen_k_15(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -32982,7 +32988,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -33027,7 +33033,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_384_point_to_ecc_point_15(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -33177,7 +33183,7 @@ static void sp_384_to_bin_15(sp_digit* r, byte* a) int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -33190,7 +33196,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -33215,7 +33221,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 48; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -33462,7 +33468,7 @@ static int sp_384_div_15(const sp_digit* a, const sp_digit* d, int i; sp_digit r1; sp_digit mask; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 15 + 3]; @@ -33473,7 +33479,7 @@ static int sp_384_div_15(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 15 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -33505,7 +33511,7 @@ static int sp_384_div_15(const sp_digit* a, const sp_digit* d, sp_384_rshift_15(r, t1, 6); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -33772,7 +33778,7 @@ static int sp_384_calc_s_15(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_384* point = NULL; #else @@ -33790,7 +33796,7 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -33869,21 +33875,21 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_384_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 15); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -34099,7 +34105,7 @@ static int sp_384_num_bits_15(const sp_digit* a) static int sp_384_mod_inv_15(sp_digit* r, const sp_digit* a, const sp_digit* m) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u = NULL; #else sp_digit u[15 * 4]; @@ -34110,7 +34116,7 @@ static int sp_384_mod_inv_15(sp_digit* r, const sp_digit* a, const sp_digit* m) int ut; int vt; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 15 * 4, NULL, DYNAMIC_TYPE_ECC); if (u == NULL) @@ -34198,7 +34204,7 @@ static int sp_384_mod_inv_15(sp_digit* r, const sp_digit* a, const sp_digit* m) else XMEMCPY(r, d, sizeof(sp_digit) * 15); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u != NULL) XFREE(u, NULL, DYNAMIC_TYPE_ECC); #endif @@ -34327,7 +34333,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_384* p1 = NULL; #else @@ -34342,7 +34348,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -34413,7 +34419,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -34585,7 +34591,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_384_ecc_is_point_15(const sp_point_384* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[15 * 4]; @@ -34593,7 +34599,7 @@ static int sp_384_ecc_is_point_15(const sp_point_384* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 15 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -34621,7 +34627,7 @@ static int sp_384_ecc_is_point_15(const sp_point_384* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -34638,7 +34644,7 @@ static int sp_384_ecc_is_point_15(const sp_point_384* point, */ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* pub = NULL; #else sp_point_384 pub[1]; @@ -34646,7 +34652,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -34661,7 +34667,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) err = sp_384_ecc_is_point_15(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -34683,7 +34689,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_384* pub = NULL; #else @@ -34704,7 +34710,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -34770,7 +34776,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -34799,7 +34805,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -34809,7 +34815,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_384* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -34852,7 +34858,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -34876,7 +34882,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -34885,7 +34891,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -34920,7 +34926,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -34940,7 +34946,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -34950,7 +34956,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -34984,7 +34990,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_384_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -35002,7 +35008,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_384_mont_sqrt_15(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[5 * 2 * 15]; @@ -35013,7 +35019,7 @@ static int sp_384_mont_sqrt_15(sp_digit* y) sp_digit* t5 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 2 * 15, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -35083,7 +35089,7 @@ static int sp_384_mont_sqrt_15(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -35101,7 +35107,7 @@ static int sp_384_mont_sqrt_15(sp_digit* y) */ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 15]; @@ -35109,7 +35115,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 15, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -35149,7 +35155,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) err = sp_384_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -36887,7 +36893,7 @@ static int sp_521_mod_mul_norm_21(sp_digit* r, const sp_digit* a, const sp_digit static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -36904,7 +36910,7 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -36965,21 +36971,21 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 21 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_521) * 3); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -37654,7 +37660,7 @@ static void sp_521_get_point_33_21(sp_point_521* r, const sp_point_521* table, static int sp_521_ecc_mulmod_win_add_sub_21(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -37672,7 +37678,7 @@ static int sp_521_ecc_mulmod_win_add_sub_21(sp_point_521* r, const sp_point_521* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -37768,7 +37774,7 @@ static int sp_521_ecc_mulmod_win_add_sub_21(sp_point_521* r, const sp_point_521* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -37895,7 +37901,7 @@ static void sp_521_proj_to_affine_21(sp_point_521* a, sp_digit* t) static int sp_521_gen_stripe_table_21(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -37908,7 +37914,7 @@ static int sp_521_gen_stripe_table_21(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -37963,7 +37969,7 @@ static int sp_521_gen_stripe_table_21(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -38094,7 +38100,7 @@ static int sp_521_ecc_mulmod_stripe_21(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -38114,7 +38120,7 @@ static int sp_521_ecc_mulmod_stripe_21(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -38180,7 +38186,7 @@ static int sp_521_ecc_mulmod_stripe_21(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -38300,7 +38306,7 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, const sp #ifndef FP_ECC return sp_521_ecc_mulmod_win_add_sub_21(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 21 * 6]; @@ -38308,7 +38314,7 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, const sp sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 21 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -38344,7 +38350,7 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -38365,7 +38371,7 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, const sp int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -38374,7 +38380,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -38397,7 +38403,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_521_point_to_ecc_point_21(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -38422,7 +38428,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -38433,7 +38439,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -38477,7 +38483,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, err = sp_521_point_to_ecc_point_21(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -40857,7 +40863,7 @@ static int sp_521_ecc_mulmod_base_21(sp_point_521* r, const sp_digit* k, */ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -40866,7 +40872,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -40888,7 +40894,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_521_point_to_ecc_point_21(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -40912,7 +40918,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -40923,7 +40929,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -40966,7 +40972,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, err = sp_521_point_to_ecc_point_21(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -41064,7 +41070,7 @@ static int sp_521_ecc_gen_k_21(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -41083,7 +41089,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -41128,7 +41134,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_521_point_to_ecc_point_21(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -41278,7 +41284,7 @@ static void sp_521_to_bin_21(sp_digit* r, byte* a) int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -41291,7 +41297,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -41316,7 +41322,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 66; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -41583,7 +41589,7 @@ static int sp_521_div_21(const sp_digit* a, const sp_digit* d, int i; sp_digit r1; sp_digit mask; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 21 + 3]; @@ -41594,7 +41600,7 @@ static int sp_521_div_21(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 21 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -41626,7 +41632,7 @@ static int sp_521_div_21(const sp_digit* a, const sp_digit* d, sp_521_rshift_21(r, t1, 4); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -41908,7 +41914,7 @@ static int sp_521_calc_s_21(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_521* point = NULL; #else @@ -41926,7 +41932,7 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -42011,21 +42017,21 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_521_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 21); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -42245,7 +42251,7 @@ static int sp_521_num_bits_21(const sp_digit* a) static int sp_521_mod_inv_21(sp_digit* r, const sp_digit* a, const sp_digit* m) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u = NULL; #else sp_digit u[21 * 4]; @@ -42256,7 +42262,7 @@ static int sp_521_mod_inv_21(sp_digit* r, const sp_digit* a, const sp_digit* m) int ut; int vt; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 21 * 4, NULL, DYNAMIC_TYPE_ECC); if (u == NULL) @@ -42344,7 +42350,7 @@ static int sp_521_mod_inv_21(sp_digit* r, const sp_digit* a, const sp_digit* m) else XMEMCPY(r, d, sizeof(sp_digit) * 21); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u != NULL) XFREE(u, NULL, DYNAMIC_TYPE_ECC); #endif @@ -42479,7 +42485,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_521* p1 = NULL; #else @@ -42494,7 +42500,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -42570,7 +42576,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -42746,7 +42752,7 @@ int sp_ecc_verify_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_521_ecc_is_point_21(const sp_point_521* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[21 * 4]; @@ -42754,7 +42760,7 @@ static int sp_521_ecc_is_point_21(const sp_point_521* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 21 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -42782,7 +42788,7 @@ static int sp_521_ecc_is_point_21(const sp_point_521* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -42799,7 +42805,7 @@ static int sp_521_ecc_is_point_21(const sp_point_521* point, */ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* pub = NULL; #else sp_point_521 pub[1]; @@ -42807,7 +42813,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -42822,7 +42828,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) err = sp_521_ecc_is_point_21(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -42844,7 +42850,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_521* pub = NULL; #else @@ -42865,7 +42871,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -42931,7 +42937,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -42960,7 +42966,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -42970,7 +42976,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_521* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -43013,7 +43019,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -43037,7 +43043,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -43046,7 +43052,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -43081,7 +43087,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -43101,7 +43107,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -43111,7 +43117,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -43145,7 +43151,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_521_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -43170,14 +43176,14 @@ static const uint32_t p521_sqrt_power[17] = { */ static int sp_521_mont_sqrt_21(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t = NULL; #else sp_digit t[2 * 21]; #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 21, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -43198,7 +43204,7 @@ static int sp_521_mont_sqrt_21(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -43216,7 +43222,7 @@ static int sp_521_mont_sqrt_21(sp_digit* y) */ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 21]; @@ -43224,7 +43230,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 21, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -43264,7 +43270,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) err = sp_521_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -44245,7 +44251,7 @@ static int sp_1024_div_42(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 42 + 3]; @@ -44256,7 +44262,7 @@ static int sp_1024_div_42(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 42 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -44307,7 +44313,7 @@ static int sp_1024_div_42(const sp_digit* a, const sp_digit* d, r[41] = 0; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -44355,7 +44361,8 @@ static int sp_1024_point_new_ex_42(void* heap, sp_point_1024* sp, { int ret = MP_OKAY; (void)heap; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) (void)sp; *p = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); #else @@ -44367,7 +44374,8 @@ static int sp_1024_point_new_ex_42(void* heap, sp_point_1024* sp, return ret; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* Allocate memory for point and return error. */ #define sp_1024_point_new_42(heap, sp, p) sp_1024_point_new_ex_42((heap), NULL, &(p)) #else @@ -44384,7 +44392,8 @@ static int sp_1024_point_new_ex_42(void* heap, sp_point_1024* sp, */ static void sp_1024_point_free_42(sp_point_1024* p, int clear, void* heap) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* If valid pointer then clear point data if requested and free data. */ if (p != NULL) { if (clear != 0) { @@ -45663,7 +45672,7 @@ static int sp_1024_proj_point_add_42_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -45680,7 +45689,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -45741,21 +45750,21 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 42 * 37); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_1024) * 3); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -46336,7 +46345,7 @@ static void sp_1024_ecc_recode_7_42(const sp_digit* k, ecc_recode_1024* v) static int sp_1024_ecc_mulmod_win_add_sub_42(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -46354,7 +46363,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_42(sp_point_1024* r, const sp_point_10 (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (65+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -46454,7 +46463,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_42(sp_point_1024* r, const sp_point_10 } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -46581,7 +46590,7 @@ static void sp_1024_proj_to_affine_42(sp_point_1024* a, sp_digit* t) static int sp_1024_gen_stripe_table_42(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -46594,7 +46603,7 @@ static int sp_1024_gen_stripe_table_42(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -46649,7 +46658,7 @@ static int sp_1024_gen_stripe_table_42(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -46678,7 +46687,7 @@ static int sp_1024_ecc_mulmod_stripe_42(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -46698,7 +46707,7 @@ static int sp_1024_ecc_mulmod_stripe_42(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -46749,7 +46758,7 @@ static int sp_1024_ecc_mulmod_stripe_42(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -46869,7 +46878,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_win_add_sub_42(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 42 * 38]; @@ -46877,7 +46886,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 42 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -46913,7 +46922,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -46934,7 +46943,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, const int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -46943,7 +46952,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -46966,7 +46975,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_1024_point_to_ecc_point_42(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -50880,7 +50889,7 @@ static int sp_1024_ecc_mulmod_base_42(sp_point_1024* r, const sp_digit* k, */ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -50889,7 +50898,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -50911,7 +50920,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_1024_point_to_ecc_point_42(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -50935,7 +50944,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -50946,7 +50955,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -50989,7 +50998,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, err = sp_1024_point_to_ecc_point_42(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -51012,7 +51021,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* t = NULL; #else @@ -51033,7 +51042,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); @@ -51057,7 +51066,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, *len = sizeof(sp_table_entry_1024) * 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -51115,7 +51124,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -51124,7 +51133,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) { @@ -51153,7 +51162,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, err = sp_1024_point_to_ecc_point_42(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -51228,8 +51237,8 @@ static void sp_1024_proj_sqr_42(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -51248,8 +51257,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 42 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -51258,8 +51267,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 42 * 2; ty = td + 37 * 42 * 2; @@ -51302,8 +51311,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -53127,8 +53136,8 @@ static const sp_digit sp_1024_g_table[256][42] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -53146,8 +53155,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 42 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -53156,8 +53165,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 42 * 2; ty = td + 37 * 42 * 2; @@ -53200,8 +53209,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -53471,8 +53480,8 @@ static void sp_1024_accumulate_line_add_one_42(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -53501,8 +53510,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_42(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 42 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -53513,8 +53522,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 42 * 2; vy = td + 37 * 42 * 2; @@ -53570,8 +53579,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -53849,8 +53858,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -53886,8 +53895,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_42(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 42 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -53898,8 +53907,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 42 * 2; vy = td + 37 * 42 * 2; @@ -53997,8 +54006,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -54238,8 +54247,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -54278,8 +54287,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_42(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 42 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -54290,8 +54299,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; pre_p = (sp_point_1024*)(td + 36 * 42 * 2); #endif @@ -54365,8 +54374,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -54400,8 +54409,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -54443,8 +54452,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_42(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 42 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -54455,8 +54464,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 42 * 2; vy = td + 37 * 42 * 2; @@ -54560,8 +54569,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -54619,7 +54628,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) static int sp_1024_ecc_is_point_42(const sp_point_1024* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[42 * 4]; @@ -54628,7 +54637,7 @@ static int sp_1024_ecc_is_point_42(const sp_point_1024* point, sp_int32 n; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 42 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -54659,7 +54668,7 @@ static int sp_1024_ecc_is_point_42(const sp_point_1024* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -54676,7 +54685,7 @@ static int sp_1024_ecc_is_point_42(const sp_point_1024* point, */ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* pub = NULL; #else sp_point_1024 pub[1]; @@ -54684,7 +54693,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -54699,7 +54708,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) err = sp_1024_ecc_is_point_42(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -54721,7 +54730,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_1024* pub = NULL; #else @@ -54742,7 +54751,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); @@ -54808,7 +54817,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) diff --git a/wolfcrypt/src/sp_c64.c b/wolfcrypt/src/sp_c64.c index 47a494a99..ebd668f24 100644 --- a/wolfcrypt/src/sp_c64.c +++ b/wolfcrypt/src/sp_c64.c @@ -49,6 +49,11 @@ #endif #endif +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#undef WOLFSSL_SP_SMALL_STACK +#define WOLFSSL_SP_SMALL_STACK +#endif + #include #ifndef WOLFSSL_SP_ASM @@ -82,7 +87,8 @@ static const size_t addr_mask[2] = { 0, (size_t)-1 }; #endif -#if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || !defined(WOLFSSL_SP_SMALL)) +#if defined(WOLFSSL_SP_NONBLOCK) && (!defined(WOLFSSL_SP_NO_MALLOC) || \ + !defined(WOLFSSL_SP_SMALL)) #error SP non-blocking requires small and no-malloc (WOLFSSL_SP_SMALL and WOLFSSL_SP_NO_MALLOC) #endif @@ -935,7 +941,7 @@ static int sp_2048_div_17(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 17 + 3]; @@ -946,7 +952,7 @@ static int sp_2048_div_17(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 17 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -997,7 +1003,7 @@ static int sp_2048_div_17(const sp_digit* a, const sp_digit* d, sp_2048_rshift_17(r, r, 13); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -1032,7 +1038,7 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 34]; @@ -1050,7 +1056,7 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 17 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -1116,14 +1122,14 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 34]; @@ -1141,7 +1147,7 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 17 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -1206,14 +1212,14 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 17 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 34) + 34]; @@ -1232,7 +1238,7 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 34) + 34), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -1352,7 +1358,7 @@ static int sp_2048_mod_exp_17(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 34); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -1760,7 +1766,7 @@ static int sp_2048_div_34(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 34 + 3]; @@ -1771,7 +1777,7 @@ static int sp_2048_div_34(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 34 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -1822,7 +1828,7 @@ static int sp_2048_div_34(const sp_digit* a, const sp_digit* d, sp_2048_rshift_34(r, r, 26); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -1858,7 +1864,7 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 68]; @@ -1876,7 +1882,7 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 34 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -1942,14 +1948,14 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 68]; @@ -1967,7 +1973,7 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 34 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -2032,14 +2038,14 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 34 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 68) + 68]; @@ -2058,7 +2064,7 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 68) + 68), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -2161,7 +2167,7 @@ static int sp_2048_mod_exp_34(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 68); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -2188,7 +2194,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[34 * 5]; @@ -2220,7 +2226,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -2281,14 +2287,14 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[34 * 5]; @@ -2317,7 +2323,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -2393,7 +2399,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -2428,7 +2434,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[34 * 4]; @@ -2462,7 +2468,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -2487,21 +2493,21 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 34); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[34 * 4]; @@ -2535,7 +2541,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -2560,14 +2566,14 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 34); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -2576,7 +2582,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[17 * 8]; @@ -2614,7 +2620,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -2662,19 +2668,19 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 17 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[17 * 13]; @@ -2713,7 +2719,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -2764,12 +2770,12 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 17 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -2865,7 +2871,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[34 * 4]; @@ -2888,7 +2894,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL, DYNAMIC_TYPE_DH); @@ -2913,20 +2919,20 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_2048_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 34U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[34 * 4]; @@ -2950,7 +2956,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -2975,14 +2981,14 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 34U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -3018,7 +3024,7 @@ SP_NOINLINE static void sp_2048_lshift_34(sp_digit* r, const sp_digit* a, */ static int sp_2048_mod_exp_2_34(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[103]; @@ -3037,7 +3043,7 @@ static int sp_2048_mod_exp_2_34(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 103, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3117,7 +3123,7 @@ static int sp_2048_mod_exp_2_34(sp_digit* r, const sp_digit* e, int bits, const sp_2048_cond_sub_34(r, r, m, ~(n >> 63)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -3142,7 +3148,7 @@ static int sp_2048_mod_exp_2_34(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[34 * 4]; @@ -3166,7 +3172,7 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 34 * 4, NULL, DYNAMIC_TYPE_DH); @@ -3207,14 +3213,14 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 34U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -3237,7 +3243,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[17 * 4]; @@ -3260,7 +3266,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 4, NULL, DYNAMIC_TYPE_DH); @@ -3286,20 +3292,20 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_2048_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 34U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[17 * 4]; @@ -3323,7 +3329,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -3349,14 +3355,14 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 34U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -4470,7 +4476,7 @@ static int sp_2048_div_18(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 18 + 3]; @@ -4481,7 +4487,7 @@ static int sp_2048_div_18(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 18 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -4532,7 +4538,7 @@ static int sp_2048_div_18(const sp_digit* a, const sp_digit* d, sp_2048_rshift_18(r, r, 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4567,7 +4573,7 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 36]; @@ -4585,7 +4591,7 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4651,14 +4657,14 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 36]; @@ -4676,7 +4682,7 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4741,14 +4747,14 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 18 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 36) + 36]; @@ -4767,7 +4773,7 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 36) + 36), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4887,7 +4893,7 @@ static int sp_2048_mod_exp_18(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 36); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -5356,7 +5362,7 @@ static int sp_2048_div_36(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 36 + 3]; @@ -5367,7 +5373,7 @@ static int sp_2048_div_36(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 36 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -5418,7 +5424,7 @@ static int sp_2048_div_36(const sp_digit* a, const sp_digit* d, sp_2048_rshift_36(r, r, 4); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -5456,7 +5462,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 72]; @@ -5474,7 +5480,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 36 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5540,14 +5546,14 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 72]; @@ -5565,7 +5571,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 36 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5630,14 +5636,14 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 36 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 72) + 72]; @@ -5656,7 +5662,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 72) + 72), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5759,7 +5765,7 @@ static int sp_2048_mod_exp_36(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 72); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -5788,7 +5794,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[36 * 5]; @@ -5820,7 +5826,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -5881,14 +5887,14 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[36 * 5]; @@ -5917,7 +5923,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -5993,7 +5999,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -6028,7 +6034,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[36 * 4]; @@ -6062,7 +6068,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -6087,21 +6093,21 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 36); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[36 * 4]; @@ -6135,7 +6141,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -6160,14 +6166,14 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 36); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -6176,7 +6182,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[18 * 8]; @@ -6214,7 +6220,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -6262,19 +6268,19 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 18 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[18 * 13]; @@ -6313,7 +6319,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -6364,12 +6370,12 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 18 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -6465,7 +6471,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[36 * 4]; @@ -6488,7 +6494,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL, DYNAMIC_TYPE_DH); @@ -6513,20 +6519,20 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_2048_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 36U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[36 * 4]; @@ -6550,7 +6556,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -6575,14 +6581,14 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 36U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -6687,7 +6693,7 @@ SP_NOINLINE static void sp_2048_lshift_36(sp_digit* r, const sp_digit* a, */ static int sp_2048_mod_exp_2_36(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[109]; @@ -6706,7 +6712,7 @@ static int sp_2048_mod_exp_2_36(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 109, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -6786,7 +6792,7 @@ static int sp_2048_mod_exp_2_36(sp_digit* r, const sp_digit* e, int bits, const sp_2048_cond_sub_36(r, r, m, ~(n >> 63)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -6811,7 +6817,7 @@ static int sp_2048_mod_exp_2_36(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[36 * 4]; @@ -6835,7 +6841,7 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 4, NULL, DYNAMIC_TYPE_DH); @@ -6876,14 +6882,14 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 36U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -6906,7 +6912,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[18 * 4]; @@ -6929,7 +6935,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 4, NULL, DYNAMIC_TYPE_DH); @@ -6955,20 +6961,20 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_2048_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 36U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[18 * 4]; @@ -6992,7 +6998,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -7018,14 +7024,14 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 36U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -7812,7 +7818,7 @@ static int sp_3072_div_26(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 26 + 3]; @@ -7823,7 +7829,7 @@ static int sp_3072_div_26(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 26 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -7874,7 +7880,7 @@ static int sp_3072_div_26(const sp_digit* a, const sp_digit* d, sp_3072_rshift_26(r, r, 24); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -7909,7 +7915,7 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 52]; @@ -7927,7 +7933,7 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 26 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -7993,14 +7999,14 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 52]; @@ -8018,7 +8024,7 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 26 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -8083,14 +8089,14 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 26 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 52) + 52]; @@ -8109,7 +8115,7 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 52) + 52), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -8229,7 +8235,7 @@ static int sp_3072_mod_exp_26(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 52); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -8643,7 +8649,7 @@ static int sp_3072_div_52(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 52 + 3]; @@ -8654,7 +8660,7 @@ static int sp_3072_div_52(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 52 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -8705,7 +8711,7 @@ static int sp_3072_div_52(const sp_digit* a, const sp_digit* d, sp_3072_rshift_52(r, r, 48); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -8741,7 +8747,7 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 104]; @@ -8759,7 +8765,7 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 52 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -8825,14 +8831,14 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 104]; @@ -8850,7 +8856,7 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 52 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -8915,14 +8921,14 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 52 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 104) + 104]; @@ -8941,7 +8947,7 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 104) + 104), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -9044,7 +9050,7 @@ static int sp_3072_mod_exp_52(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 104); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -9071,7 +9077,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[52 * 5]; @@ -9103,7 +9109,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -9164,14 +9170,14 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[52 * 5]; @@ -9200,7 +9206,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -9276,7 +9282,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -9311,7 +9317,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[52 * 4]; @@ -9345,7 +9351,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -9370,21 +9376,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 52); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[52 * 4]; @@ -9418,7 +9424,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -9443,14 +9449,14 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 52); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -9459,7 +9465,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[26 * 8]; @@ -9497,7 +9503,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 26 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -9545,19 +9551,19 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 26 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[26 * 13]; @@ -9596,7 +9602,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 26 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -9647,12 +9653,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 26 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -9748,7 +9754,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[52 * 4]; @@ -9771,7 +9777,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL, DYNAMIC_TYPE_DH); @@ -9796,20 +9802,20 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 52U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[52 * 4]; @@ -9833,7 +9839,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -9858,14 +9864,14 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 52U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -9901,7 +9907,7 @@ SP_NOINLINE static void sp_3072_lshift_52(sp_digit* r, const sp_digit* a, */ static int sp_3072_mod_exp_2_52(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[157]; @@ -9920,7 +9926,7 @@ static int sp_3072_mod_exp_2_52(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 157, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -10000,7 +10006,7 @@ static int sp_3072_mod_exp_2_52(sp_digit* r, const sp_digit* e, int bits, const sp_3072_cond_sub_52(r, r, m, ~(n >> 63)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -10025,7 +10031,7 @@ static int sp_3072_mod_exp_2_52(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[52 * 4]; @@ -10049,7 +10055,7 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 52 * 4, NULL, DYNAMIC_TYPE_DH); @@ -10090,14 +10096,14 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 52U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -10120,7 +10126,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[26 * 4]; @@ -10143,7 +10149,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 26 * 4, NULL, DYNAMIC_TYPE_DH); @@ -10169,20 +10175,20 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 52U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[26 * 4]; @@ -10206,7 +10212,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 26 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -10232,14 +10238,14 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 52U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -11491,7 +11497,7 @@ static int sp_3072_div_27(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 27 + 3]; @@ -11502,7 +11508,7 @@ static int sp_3072_div_27(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 27 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -11553,7 +11559,7 @@ static int sp_3072_div_27(const sp_digit* a, const sp_digit* d, sp_3072_rshift_27(r, r, 3); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -11588,7 +11594,7 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 54]; @@ -11606,7 +11612,7 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 27 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -11672,14 +11678,14 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 54]; @@ -11697,7 +11703,7 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 27 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -11762,14 +11768,14 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 27 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 54) + 54]; @@ -11788,7 +11794,7 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 54) + 54), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -11908,7 +11914,7 @@ static int sp_3072_mod_exp_27(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 54); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -12388,7 +12394,7 @@ static int sp_3072_div_54(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 54 + 3]; @@ -12399,7 +12405,7 @@ static int sp_3072_div_54(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 54 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -12450,7 +12456,7 @@ static int sp_3072_div_54(const sp_digit* a, const sp_digit* d, sp_3072_rshift_54(r, r, 6); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -12488,7 +12494,7 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 108]; @@ -12506,7 +12512,7 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 54 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -12572,14 +12578,14 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 108]; @@ -12597,7 +12603,7 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 54 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -12662,14 +12668,14 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 54 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 108) + 108]; @@ -12688,7 +12694,7 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 108) + 108), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -12791,7 +12797,7 @@ static int sp_3072_mod_exp_54(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 108); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -12820,7 +12826,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[54 * 5]; @@ -12852,7 +12858,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -12913,14 +12919,14 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[54 * 5]; @@ -12949,7 +12955,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -13025,7 +13031,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -13060,7 +13066,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[54 * 4]; @@ -13094,7 +13100,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -13119,21 +13125,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 54); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[54 * 4]; @@ -13167,7 +13173,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -13192,14 +13198,14 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 54); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -13208,7 +13214,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[27 * 8]; @@ -13246,7 +13252,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 27 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -13294,19 +13300,19 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 27 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[27 * 13]; @@ -13345,7 +13351,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 27 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -13396,12 +13402,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 27 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -13497,7 +13503,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[54 * 4]; @@ -13520,7 +13526,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL, DYNAMIC_TYPE_DH); @@ -13545,20 +13551,20 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 54U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[54 * 4]; @@ -13582,7 +13588,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -13607,14 +13613,14 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 54U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -13755,7 +13761,7 @@ SP_NOINLINE static void sp_3072_lshift_54(sp_digit* r, const sp_digit* a, */ static int sp_3072_mod_exp_2_54(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[163]; @@ -13774,7 +13780,7 @@ static int sp_3072_mod_exp_2_54(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 163, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -13854,7 +13860,7 @@ static int sp_3072_mod_exp_2_54(sp_digit* r, const sp_digit* e, int bits, const sp_3072_cond_sub_54(r, r, m, ~(n >> 63)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -13879,7 +13885,7 @@ static int sp_3072_mod_exp_2_54(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[54 * 4]; @@ -13903,7 +13909,7 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 54 * 4, NULL, DYNAMIC_TYPE_DH); @@ -13944,14 +13950,14 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 54U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -13974,7 +13980,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[27 * 4]; @@ -13997,7 +14003,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 27 * 4, NULL, DYNAMIC_TYPE_DH); @@ -14023,20 +14029,20 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 54U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[27 * 4]; @@ -14060,7 +14066,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 27 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -14086,14 +14092,14 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 54U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -14886,7 +14892,7 @@ static int sp_4096_div_35(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 35 + 3]; @@ -14897,7 +14903,7 @@ static int sp_4096_div_35(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 35 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -14948,7 +14954,7 @@ static int sp_4096_div_35(const sp_digit* a, const sp_digit* d, sp_4096_rshift_35(r, r, 17); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -14983,7 +14989,7 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 70]; @@ -15001,7 +15007,7 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 35 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15067,14 +15073,14 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 70]; @@ -15092,7 +15098,7 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 35 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15157,14 +15163,14 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 35 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 70) + 70]; @@ -15183,7 +15189,7 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 70) + 70), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15303,7 +15309,7 @@ static int sp_4096_mod_exp_35(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 70); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -15712,7 +15718,7 @@ static int sp_4096_div_70(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 70 + 3]; @@ -15723,7 +15729,7 @@ static int sp_4096_div_70(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 70 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -15774,7 +15780,7 @@ static int sp_4096_div_70(const sp_digit* a, const sp_digit* d, sp_4096_rshift_70(r, r, 34); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -15810,7 +15816,7 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 140]; @@ -15828,7 +15834,7 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 70 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15894,14 +15900,14 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 140]; @@ -15919,7 +15925,7 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 70 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15984,14 +15990,14 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 70 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 140) + 140]; @@ -16010,7 +16016,7 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 140) + 140), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -16113,7 +16119,7 @@ static int sp_4096_mod_exp_70(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 140); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -16140,7 +16146,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[70 * 5]; @@ -16172,7 +16178,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -16233,14 +16239,14 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[70 * 5]; @@ -16269,7 +16275,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -16345,7 +16351,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -16380,7 +16386,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[70 * 4]; @@ -16414,7 +16420,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -16439,21 +16445,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 70); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[70 * 4]; @@ -16487,7 +16493,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -16512,14 +16518,14 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 70); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -16528,7 +16534,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[35 * 8]; @@ -16566,7 +16572,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 35 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -16614,19 +16620,19 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 35 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[35 * 13]; @@ -16665,7 +16671,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 35 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -16716,12 +16722,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 35 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -16817,7 +16823,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[70 * 4]; @@ -16840,7 +16846,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL, DYNAMIC_TYPE_DH); @@ -16865,20 +16871,20 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_4096_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 70U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[70 * 4]; @@ -16902,7 +16908,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -16927,14 +16933,14 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 70U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -16970,7 +16976,7 @@ SP_NOINLINE static void sp_4096_lshift_70(sp_digit* r, const sp_digit* a, */ static int sp_4096_mod_exp_2_70(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[211]; @@ -16989,7 +16995,7 @@ static int sp_4096_mod_exp_2_70(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 211, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -17069,7 +17075,7 @@ static int sp_4096_mod_exp_2_70(sp_digit* r, const sp_digit* e, int bits, const sp_4096_cond_sub_70(r, r, m, ~(n >> 63)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -17094,7 +17100,7 @@ static int sp_4096_mod_exp_2_70(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[70 * 4]; @@ -17118,7 +17124,7 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 70 * 4, NULL, DYNAMIC_TYPE_DH); @@ -17159,14 +17165,14 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 70U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -18615,7 +18621,7 @@ static int sp_4096_div_39(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 39 + 3]; @@ -18626,7 +18632,7 @@ static int sp_4096_div_39(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 39 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -18677,7 +18683,7 @@ static int sp_4096_div_39(const sp_digit* a, const sp_digit* d, sp_4096_rshift_39(r, r, 19); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -18712,7 +18718,7 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 78]; @@ -18730,7 +18736,7 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 39 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -18796,14 +18802,14 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 78]; @@ -18821,7 +18827,7 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 39 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -18886,14 +18892,14 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 39 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(32 * 78) + 78]; @@ -18912,7 +18918,7 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((32 * 78) + 78), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -19032,7 +19038,7 @@ static int sp_4096_mod_exp_39(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 78); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -19513,7 +19519,7 @@ static int sp_4096_div_78(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 78 + 3]; @@ -19524,7 +19530,7 @@ static int sp_4096_div_78(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 78 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -19575,7 +19581,7 @@ static int sp_4096_div_78(const sp_digit* a, const sp_digit* d, sp_4096_rshift_78(r, r, 38); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -19613,7 +19619,7 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { #if defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_FAST_MODEXP) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 156]; @@ -19631,7 +19637,7 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 78 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -19697,14 +19703,14 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #elif !defined(WC_NO_CACHE_RESISTANT) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[3 * 156]; @@ -19722,7 +19728,7 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 3 * 78 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -19787,14 +19793,14 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, t[0], sizeof(*r) * 78 * 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(16 * 156) + 156]; @@ -19813,7 +19819,7 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * ((16 * 156) + 156), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -19916,7 +19922,7 @@ static int sp_4096_mod_exp_78(sp_digit* r, const sp_digit* a, const sp_digit* e, XMEMCPY(r, rt, sizeof(sp_digit) * 156); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -19945,7 +19951,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { #ifdef WOLFSSL_SP_SMALL -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[78 * 5]; @@ -19977,7 +19983,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -20038,14 +20044,14 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[78 * 5]; @@ -20074,7 +20080,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -20150,7 +20156,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif @@ -20185,7 +20191,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[78 * 4]; @@ -20219,7 +20225,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -20244,21 +20250,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 78); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[78 * 4]; @@ -20292,7 +20298,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -20317,14 +20323,14 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 78); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -20333,7 +20339,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, #endif /* WOLFSSL_SP_SMALL */ #else #if defined(WOLFSSL_SP_SMALL) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[39 * 8]; @@ -20371,7 +20377,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 8, NULL, DYNAMIC_TYPE_RSA); @@ -20419,19 +20425,19 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 39 * 8); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[39 * 13]; @@ -20470,7 +20476,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 13, NULL, DYNAMIC_TYPE_RSA); @@ -20521,12 +20527,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 39 * 13); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -20622,7 +20628,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, { #ifdef WOLFSSL_SP_SMALL int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[78 * 4]; @@ -20645,7 +20651,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL, DYNAMIC_TYPE_DH); @@ -20670,20 +20676,20 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_4096_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 78U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[78 * 4]; @@ -20707,7 +20713,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL, DYNAMIC_TYPE_DH); if (b == NULL) @@ -20732,14 +20738,14 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 78U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -20928,7 +20934,7 @@ SP_NOINLINE static void sp_4096_lshift_78(sp_digit* r, const sp_digit* a, */ static int sp_4096_mod_exp_2_78(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[235]; @@ -20947,7 +20953,7 @@ static int sp_4096_mod_exp_2_78(sp_digit* r, const sp_digit* e, int bits, const err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 235, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -21027,7 +21033,7 @@ static int sp_4096_mod_exp_2_78(sp_digit* r, const sp_digit* e, int bits, const sp_4096_cond_sub_78(r, r, m, ~(n >> 63)); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -21052,7 +21058,7 @@ static int sp_4096_mod_exp_2_78(sp_digit* r, const sp_digit* e, int bits, const int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* b = NULL; #else sp_digit b[78 * 4]; @@ -21076,7 +21082,7 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { b = (sp_digit*)XMALLOC(sizeof(sp_digit) * 78 * 4, NULL, DYNAMIC_TYPE_DH); @@ -21117,14 +21123,14 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) #endif { /* only "e" is sensitive and needs zeroized */ if (e != NULL) ForceZero(e, sizeof(sp_digit) * 78U); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(b, NULL, DYNAMIC_TYPE_DH); #endif } @@ -22740,7 +22746,7 @@ static int sp_256_proj_point_add_5_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r, */ static int sp_256_mod_mul_norm_5(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[2 * 8]; @@ -22751,7 +22757,7 @@ static int sp_256_mod_mul_norm_5(sp_digit* r, const sp_digit* a, const sp_digit* (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 2 * 8, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) return MEMORY_E; @@ -22832,7 +22838,7 @@ static int sp_256_mod_mul_norm_5(sp_digit* r, const sp_digit* a, const sp_digit* r[4] |= t[7] << 16U; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -22859,7 +22865,7 @@ static int sp_256_mod_mul_norm_5(sp_digit* r, const sp_digit* a, const sp_digit* static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -22876,7 +22882,7 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -22937,21 +22943,21 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 5 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_256) * 3); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -23498,7 +23504,7 @@ static void sp_256_get_point_33_5(sp_point_256* r, const sp_point_256* table, static int sp_256_ecc_mulmod_win_add_sub_5(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -23516,7 +23522,7 @@ static int sp_256_ecc_mulmod_win_add_sub_5(sp_point_256* r, const sp_point_256* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -23612,7 +23618,7 @@ static int sp_256_ecc_mulmod_win_add_sub_5(sp_point_256* r, const sp_point_256* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -23739,7 +23745,7 @@ static void sp_256_proj_to_affine_5(sp_point_256* a, sp_digit* t) static int sp_256_gen_stripe_table_5(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -23752,7 +23758,7 @@ static int sp_256_gen_stripe_table_5(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -23807,7 +23813,7 @@ static int sp_256_gen_stripe_table_5(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -23874,7 +23880,7 @@ static int sp_256_ecc_mulmod_stripe_5(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -23894,7 +23900,7 @@ static int sp_256_ecc_mulmod_stripe_5(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -23960,7 +23966,7 @@ static int sp_256_ecc_mulmod_stripe_5(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -24080,7 +24086,7 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_win_add_sub_5(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 5 * 6]; @@ -24088,7 +24094,7 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -24124,7 +24130,7 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -24145,7 +24151,7 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, const sp_ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24154,7 +24160,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -24177,7 +24183,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_256_point_to_ecc_point_5(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -24202,7 +24208,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24213,7 +24219,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -24257,7 +24263,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, err = sp_256_point_to_ecc_point_5(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -25615,7 +25621,7 @@ static int sp_256_ecc_mulmod_base_5(sp_point_256* r, const sp_digit* k, */ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -25624,7 +25630,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -25646,7 +25652,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_256_point_to_ecc_point_5(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -25670,7 +25676,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -25681,7 +25687,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -25724,7 +25730,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, err = sp_256_point_to_ecc_point_5(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -25821,7 +25827,7 @@ static int sp_256_ecc_gen_k_5(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -25840,7 +25846,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -25885,7 +25891,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_256_point_to_ecc_point_5(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -26035,7 +26041,7 @@ static void sp_256_to_bin_5(sp_digit* r, byte* a) int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -26048,7 +26054,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -26073,7 +26079,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 32; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -26258,7 +26264,7 @@ static int sp_256_div_5(const sp_digit* a, const sp_digit* d, int i; sp_digit r1; sp_digit mask; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 5 + 3]; @@ -26269,7 +26275,7 @@ static int sp_256_div_5(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 5 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -26307,7 +26313,7 @@ static int sp_256_div_5(const sp_digit* a, const sp_digit* d, sp_256_rshift_5(r, t1, 4); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -26603,7 +26609,7 @@ static int sp_256_calc_s_5(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_256* point = NULL; #else @@ -26621,7 +26627,7 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -26700,21 +26706,21 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_256_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 5); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -26935,7 +26941,7 @@ static int sp_256_num_bits_5(const sp_digit* a) static int sp_256_mod_inv_5(sp_digit* r, const sp_digit* a, const sp_digit* m) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u = NULL; #else sp_digit u[5 * 4]; @@ -26946,7 +26952,7 @@ static int sp_256_mod_inv_5(sp_digit* r, const sp_digit* a, const sp_digit* m) int ut; int vt; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 4, NULL, DYNAMIC_TYPE_ECC); if (u == NULL) @@ -27034,7 +27040,7 @@ static int sp_256_mod_inv_5(sp_digit* r, const sp_digit* a, const sp_digit* m) else XMEMCPY(r, d, sizeof(sp_digit) * 5); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u != NULL) XFREE(u, NULL, DYNAMIC_TYPE_ECC); #endif @@ -27153,7 +27159,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_256* p1 = NULL; #else @@ -27168,7 +27174,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, sp_int64 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -27239,7 +27245,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -27411,7 +27417,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_256_ecc_is_point_5(const sp_point_256* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[5 * 4]; @@ -27419,7 +27425,7 @@ static int sp_256_ecc_is_point_5(const sp_point_256* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -27447,7 +27453,7 @@ static int sp_256_ecc_is_point_5(const sp_point_256* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -27464,7 +27470,7 @@ static int sp_256_ecc_is_point_5(const sp_point_256* point, */ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* pub = NULL; #else sp_point_256 pub[1]; @@ -27472,7 +27478,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -27487,7 +27493,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) err = sp_256_ecc_is_point_5(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -27509,7 +27515,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_256* pub = NULL; #else @@ -27530,7 +27536,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -27596,7 +27602,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -27625,7 +27631,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -27635,7 +27641,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_256* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -27678,7 +27684,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -27702,7 +27708,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -27711,7 +27717,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -27746,7 +27752,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -27766,7 +27772,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -27776,7 +27782,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -27810,7 +27816,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_256_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -27828,7 +27834,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_256_mont_sqrt_5(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 5]; @@ -27836,7 +27842,7 @@ static int sp_256_mont_sqrt_5(sp_digit* y) sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 5, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) { err = MEMORY_E; @@ -27879,7 +27885,7 @@ static int sp_256_mont_sqrt_5(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -27897,7 +27903,7 @@ static int sp_256_mont_sqrt_5(sp_digit* y) */ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 5]; @@ -27905,7 +27911,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 5, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -27945,7 +27951,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) err = sp_256_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -29648,7 +29654,7 @@ static int sp_384_proj_point_add_7_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r, */ static int sp_384_mod_mul_norm_7(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[2 * 12]; @@ -29659,7 +29665,7 @@ static int sp_384_mod_mul_norm_7(sp_digit* r, const sp_digit* a, const sp_digit* (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 2 * 12, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -29772,7 +29778,7 @@ static int sp_384_mod_mul_norm_7(sp_digit* r, const sp_digit* a, const sp_digit* r[6] |= t[11] << 22U; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -29799,7 +29805,7 @@ static int sp_384_mod_mul_norm_7(sp_digit* r, const sp_digit* a, const sp_digit* static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -29816,7 +29822,7 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -29877,21 +29883,21 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 7 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_384) * 3); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -30454,7 +30460,7 @@ static void sp_384_get_point_33_7(sp_point_384* r, const sp_point_384* table, static int sp_384_ecc_mulmod_win_add_sub_7(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -30472,7 +30478,7 @@ static int sp_384_ecc_mulmod_win_add_sub_7(sp_point_384* r, const sp_point_384* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -30568,7 +30574,7 @@ static int sp_384_ecc_mulmod_win_add_sub_7(sp_point_384* r, const sp_point_384* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -30695,7 +30701,7 @@ static void sp_384_proj_to_affine_7(sp_point_384* a, sp_digit* t) static int sp_384_gen_stripe_table_7(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -30708,7 +30714,7 @@ static int sp_384_gen_stripe_table_7(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -30763,7 +30769,7 @@ static int sp_384_gen_stripe_table_7(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -30838,7 +30844,7 @@ static int sp_384_ecc_mulmod_stripe_7(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -30858,7 +30864,7 @@ static int sp_384_ecc_mulmod_stripe_7(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -30924,7 +30930,7 @@ static int sp_384_ecc_mulmod_stripe_7(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -31044,7 +31050,7 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, const sp_ #ifndef FP_ECC return sp_384_ecc_mulmod_win_add_sub_7(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 7 * 7]; @@ -31052,7 +31058,7 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, const sp_ sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -31088,7 +31094,7 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -31109,7 +31115,7 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, const sp_ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -31118,7 +31124,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -31141,7 +31147,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_384_point_to_ecc_point_7(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -31166,7 +31172,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -31177,7 +31183,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -31221,7 +31227,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, err = sp_384_point_to_ecc_point_7(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -33089,7 +33095,7 @@ static int sp_384_ecc_mulmod_base_7(sp_point_384* r, const sp_digit* k, */ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -33098,7 +33104,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -33120,7 +33126,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_384_point_to_ecc_point_7(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -33144,7 +33150,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -33155,7 +33161,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -33198,7 +33204,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, err = sp_384_point_to_ecc_point_7(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -33295,7 +33301,7 @@ static int sp_384_ecc_gen_k_7(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -33314,7 +33320,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -33359,7 +33365,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_384_point_to_ecc_point_7(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -33509,7 +33515,7 @@ static void sp_384_to_bin_7(sp_digit* r, byte* a) int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -33522,7 +33528,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -33547,7 +33553,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 48; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -33746,7 +33752,7 @@ static int sp_384_div_7(const sp_digit* a, const sp_digit* d, int i; sp_digit r1; sp_digit mask; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 7 + 3]; @@ -33757,7 +33763,7 @@ static int sp_384_div_7(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 7 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -33789,7 +33795,7 @@ static int sp_384_div_7(const sp_digit* a, const sp_digit* d, sp_384_rshift_7(r, t1, 1); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -34056,7 +34062,7 @@ static int sp_384_calc_s_7(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_384* point = NULL; #else @@ -34074,7 +34080,7 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -34153,21 +34159,21 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_384_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 7); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -34388,7 +34394,7 @@ static int sp_384_num_bits_7(const sp_digit* a) static int sp_384_mod_inv_7(sp_digit* r, const sp_digit* a, const sp_digit* m) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u = NULL; #else sp_digit u[7 * 4]; @@ -34399,7 +34405,7 @@ static int sp_384_mod_inv_7(sp_digit* r, const sp_digit* a, const sp_digit* m) int ut; int vt; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7 * 4, NULL, DYNAMIC_TYPE_ECC); if (u == NULL) @@ -34487,7 +34493,7 @@ static int sp_384_mod_inv_7(sp_digit* r, const sp_digit* a, const sp_digit* m) else XMEMCPY(r, d, sizeof(sp_digit) * 7); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u != NULL) XFREE(u, NULL, DYNAMIC_TYPE_ECC); #endif @@ -34608,7 +34614,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_384* p1 = NULL; #else @@ -34623,7 +34629,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, sp_int64 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -34694,7 +34700,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -34866,7 +34872,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_384_ecc_is_point_7(const sp_point_384* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[7 * 4]; @@ -34874,7 +34880,7 @@ static int sp_384_ecc_is_point_7(const sp_point_384* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 7 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -34902,7 +34908,7 @@ static int sp_384_ecc_is_point_7(const sp_point_384* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -34919,7 +34925,7 @@ static int sp_384_ecc_is_point_7(const sp_point_384* point, */ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* pub = NULL; #else sp_point_384 pub[1]; @@ -34927,7 +34933,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -34942,7 +34948,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) err = sp_384_ecc_is_point_7(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -34964,7 +34970,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_384* pub = NULL; #else @@ -34985,7 +34991,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -35051,7 +35057,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -35080,7 +35086,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -35090,7 +35096,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_384* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -35133,7 +35139,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -35157,7 +35163,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -35166,7 +35172,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -35201,7 +35207,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -35221,7 +35227,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -35231,7 +35237,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -35265,7 +35271,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_384_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -35283,7 +35289,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_384_mont_sqrt_7(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[5 * 2 * 7]; @@ -35294,7 +35300,7 @@ static int sp_384_mont_sqrt_7(sp_digit* y) sp_digit* t5 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 2 * 7, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -35364,7 +35370,7 @@ static int sp_384_mont_sqrt_7(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -35382,7 +35388,7 @@ static int sp_384_mont_sqrt_7(sp_digit* y) */ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 7]; @@ -35390,7 +35396,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 7, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -35430,7 +35436,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) err = sp_384_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -37203,7 +37209,7 @@ static int sp_521_mod_mul_norm_9(sp_digit* r, const sp_digit* a, const sp_digit* static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -37220,7 +37226,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -37281,21 +37287,21 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 9 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_521) * 3); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -37874,7 +37880,7 @@ static void sp_521_get_point_33_9(sp_point_521* r, const sp_point_521* table, static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -37892,7 +37898,7 @@ static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -37988,7 +37994,7 @@ static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -38115,7 +38121,7 @@ static void sp_521_proj_to_affine_9(sp_point_521* a, sp_digit* t) static int sp_521_gen_stripe_table_9(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -38128,7 +38134,7 @@ static int sp_521_gen_stripe_table_9(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -38183,7 +38189,7 @@ static int sp_521_gen_stripe_table_9(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -38266,7 +38272,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -38286,7 +38292,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -38352,7 +38358,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -38472,7 +38478,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ #ifndef FP_ECC return sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 9 * 6]; @@ -38480,7 +38486,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -38516,7 +38522,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -38537,7 +38543,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -38546,7 +38552,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -38569,7 +38575,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -38594,7 +38600,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -38605,7 +38611,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -38649,7 +38655,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -40517,7 +40523,7 @@ static int sp_521_ecc_mulmod_base_9(sp_point_521* r, const sp_digit* k, */ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -40526,7 +40532,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -40548,7 +40554,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -40572,7 +40578,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -40583,7 +40589,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -40626,7 +40632,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -40724,7 +40730,7 @@ static int sp_521_ecc_gen_k_9(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -40743,7 +40749,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -40788,7 +40794,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_521_point_to_ecc_point_9(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -40938,7 +40944,7 @@ static void sp_521_to_bin_9(sp_digit* r, byte* a) int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -40951,7 +40957,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -40976,7 +40982,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 66; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -41181,7 +41187,7 @@ static int sp_521_div_9(const sp_digit* a, const sp_digit* d, int i; sp_digit r1; sp_digit mask; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 9 + 3]; @@ -41192,7 +41198,7 @@ static int sp_521_div_9(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 9 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -41224,7 +41230,7 @@ static int sp_521_div_9(const sp_digit* a, const sp_digit* d, sp_521_rshift_9(r, t1, 1); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -41506,7 +41512,7 @@ static int sp_521_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_521* point = NULL; #else @@ -41524,7 +41530,7 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -41609,21 +41615,21 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_521_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 9); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -41848,7 +41854,7 @@ static int sp_521_num_bits_9(const sp_digit* a) static int sp_521_mod_inv_9(sp_digit* r, const sp_digit* a, const sp_digit* m) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u = NULL; #else sp_digit u[9 * 4]; @@ -41859,7 +41865,7 @@ static int sp_521_mod_inv_9(sp_digit* r, const sp_digit* a, const sp_digit* m) int ut; int vt; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK u = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 4, NULL, DYNAMIC_TYPE_ECC); if (u == NULL) @@ -41947,7 +41953,7 @@ static int sp_521_mod_inv_9(sp_digit* r, const sp_digit* a, const sp_digit* m) else XMEMCPY(r, d, sizeof(sp_digit) * 9); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u != NULL) XFREE(u, NULL, DYNAMIC_TYPE_ECC); #endif @@ -42070,7 +42076,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_521* p1 = NULL; #else @@ -42085,7 +42091,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, sp_int64 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -42161,7 +42167,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -42337,7 +42343,7 @@ int sp_ecc_verify_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_521_ecc_is_point_9(const sp_point_521* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[9 * 4]; @@ -42345,7 +42351,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -42373,7 +42379,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -42390,7 +42396,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, */ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* pub = NULL; #else sp_point_521 pub[1]; @@ -42398,7 +42404,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -42413,7 +42419,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) err = sp_521_ecc_is_point_9(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -42435,7 +42441,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_521* pub = NULL; #else @@ -42456,7 +42462,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -42522,7 +42528,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -42551,7 +42557,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -42561,7 +42567,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_521* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -42604,7 +42610,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -42628,7 +42634,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -42637,7 +42643,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -42672,7 +42678,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -42692,7 +42698,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -42702,7 +42708,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -42736,7 +42742,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_521_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -42761,14 +42767,14 @@ static const uint64_t p521_sqrt_power[9] = { */ static int sp_521_mont_sqrt_9(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t = NULL; #else sp_digit t[2 * 9]; #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -42789,7 +42795,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -42807,7 +42813,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) */ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 9]; @@ -42815,7 +42821,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 9, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -42855,7 +42861,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) err = sp_521_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -43710,7 +43716,7 @@ static int sp_1024_div_18(const sp_digit* a, const sp_digit* d, #endif sp_digit dv; sp_digit r1; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 18 + 3]; @@ -43721,7 +43727,7 @@ static int sp_1024_div_18(const sp_digit* a, const sp_digit* d, (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * (4 * 18 + 3), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (t1 == NULL) @@ -43772,7 +43778,7 @@ static int sp_1024_div_18(const sp_digit* a, const sp_digit* d, sp_1024_rshift_18(r, r, 2); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -43820,7 +43826,8 @@ static int sp_1024_point_new_ex_18(void* heap, sp_point_1024* sp, { int ret = MP_OKAY; (void)heap; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) (void)sp; *p = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); #else @@ -43832,7 +43839,8 @@ static int sp_1024_point_new_ex_18(void* heap, sp_point_1024* sp, return ret; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* Allocate memory for point and return error. */ #define sp_1024_point_new_18(heap, sp, p) sp_1024_point_new_ex_18((heap), NULL, &(p)) #else @@ -43849,7 +43857,8 @@ static int sp_1024_point_new_ex_18(void* heap, sp_point_1024* sp, */ static void sp_1024_point_free_18(sp_point_1024* p, int clear, void* heap) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* If valid pointer then clear point data if requested and free data. */ if (p != NULL) { if (clear != 0) { @@ -45065,7 +45074,7 @@ static int sp_1024_proj_point_add_18_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -45082,7 +45091,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -45143,21 +45152,21 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 18 * 37); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_1024) * 3); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -45690,7 +45699,7 @@ static void sp_1024_ecc_recode_7_18(const sp_digit* k, ecc_recode_1024* v) static int sp_1024_ecc_mulmod_win_add_sub_18(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -45708,7 +45717,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_18(sp_point_1024* r, const sp_point_10 (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (65+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -45808,7 +45817,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_18(sp_point_1024* r, const sp_point_10 } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -45935,7 +45944,7 @@ static void sp_1024_proj_to_affine_18(sp_point_1024* a, sp_digit* t) static int sp_1024_gen_stripe_table_18(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -45948,7 +45957,7 @@ static int sp_1024_gen_stripe_table_18(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -46003,7 +46012,7 @@ static int sp_1024_gen_stripe_table_18(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -46032,7 +46041,7 @@ static int sp_1024_ecc_mulmod_stripe_18(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -46052,7 +46061,7 @@ static int sp_1024_ecc_mulmod_stripe_18(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -46103,7 +46112,7 @@ static int sp_1024_ecc_mulmod_stripe_18(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -46223,7 +46232,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_win_add_sub_18(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 18 * 38]; @@ -46231,7 +46240,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -46267,7 +46276,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -46288,7 +46297,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, const int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -46297,7 +46306,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -46320,7 +46329,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_1024_point_to_ecc_point_18(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -49720,7 +49729,7 @@ static int sp_1024_ecc_mulmod_base_18(sp_point_1024* r, const sp_digit* k, */ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -49729,7 +49738,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -49751,7 +49760,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_1024_point_to_ecc_point_18(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -49775,7 +49784,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -49786,7 +49795,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -49829,7 +49838,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, err = sp_1024_point_to_ecc_point_18(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -49852,7 +49861,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* t = NULL; #else @@ -49873,7 +49882,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); @@ -49897,7 +49906,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, *len = sizeof(sp_table_entry_1024) * 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -49955,7 +49964,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -49964,7 +49973,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) { @@ -49993,7 +50002,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, err = sp_1024_point_to_ecc_point_18(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -50068,8 +50077,8 @@ static void sp_1024_proj_sqr_18(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -50088,8 +50097,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -50098,8 +50107,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 18 * 2; ty = td + 37 * 18 * 2; @@ -50142,8 +50151,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -51711,8 +51720,8 @@ static const sp_digit sp_1024_g_table[256][18] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -51730,8 +51739,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -51740,8 +51749,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 18 * 2; ty = td + 37 * 18 * 2; @@ -51784,8 +51793,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -52055,8 +52064,8 @@ static void sp_1024_accumulate_line_add_one_18(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -52085,8 +52094,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_18(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -52097,8 +52106,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 18 * 2; vy = td + 37 * 18 * 2; @@ -52154,8 +52163,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -52433,8 +52442,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -52470,8 +52479,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_18(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 18 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -52482,8 +52491,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 18 * 2; vy = td + 37 * 18 * 2; @@ -52581,8 +52590,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -52822,8 +52831,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -52862,8 +52871,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_18(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 18 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -52874,8 +52883,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; pre_p = (sp_point_1024*)(td + 36 * 18 * 2); #endif @@ -52949,8 +52958,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -52984,8 +52993,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -53027,8 +53036,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_18(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 18 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -53039,8 +53048,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 18 * 2; vy = td + 37 * 18 * 2; @@ -53144,8 +53153,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -53203,7 +53212,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) static int sp_1024_ecc_is_point_18(const sp_point_1024* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[18 * 4]; @@ -53212,7 +53221,7 @@ static int sp_1024_ecc_is_point_18(const sp_point_1024* point, sp_int64 n; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 18 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -53243,7 +53252,7 @@ static int sp_1024_ecc_is_point_18(const sp_point_1024* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -53260,7 +53269,7 @@ static int sp_1024_ecc_is_point_18(const sp_point_1024* point, */ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* pub = NULL; #else sp_point_1024 pub[1]; @@ -53268,7 +53277,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -53283,7 +53292,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) err = sp_1024_ecc_is_point_18(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -53305,7 +53314,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_1024* pub = NULL; #else @@ -53326,7 +53335,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); @@ -53392,7 +53401,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) diff --git a/wolfcrypt/src/sp_cortexm.c b/wolfcrypt/src/sp_cortexm.c index f5539226d..6f51ba053 100644 --- a/wolfcrypt/src/sp_cortexm.c +++ b/wolfcrypt/src/sp_cortexm.c @@ -45,6 +45,11 @@ #endif #endif +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#undef WOLFSSL_SP_SMALL_STACK +#define WOLFSSL_SP_SMALL_STACK +#endif + #include #ifdef __IAR_SYSTEMS_ICC__ @@ -3425,7 +3430,7 @@ static WC_INLINE int sp_2048_mod_32(sp_digit* r, const sp_digit* a, const sp_dig static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 64]; @@ -3444,7 +3449,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3555,7 +3560,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -3577,7 +3582,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 64]; @@ -3596,7 +3601,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3724,7 +3729,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4423,7 +4428,7 @@ static WC_INLINE int sp_2048_mod_64(sp_digit* r, const sp_digit* a, const sp_dig static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 128]; @@ -4442,7 +4447,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4544,7 +4549,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4566,7 +4571,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 128]; @@ -4585,7 +4590,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4696,7 +4701,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4723,7 +4728,7 @@ static int sp_2048_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[64 * 5]; @@ -4745,7 +4750,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -4860,7 +4865,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -4932,7 +4937,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[64 * 4]; @@ -4966,7 +4971,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -4991,21 +4996,21 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 64); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[32 * 11]; @@ -5040,7 +5045,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -5088,12 +5093,12 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 32 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -5640,7 +5645,7 @@ static void sp_2048_lshift_64(sp_digit* r, const sp_digit* a, byte n) static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[193]; @@ -5660,7 +5665,7 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 193, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5745,7 +5750,7 @@ static int sp_2048_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, sp_2048_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -8955,7 +8960,7 @@ static WC_INLINE int sp_3072_mod_48(sp_digit* r, const sp_digit* a, const sp_dig static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 96]; @@ -8974,7 +8979,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -9085,7 +9090,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -9107,7 +9112,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[32 * 96]; @@ -9126,7 +9131,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (32 * 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -9254,7 +9259,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -10037,7 +10042,7 @@ static WC_INLINE int sp_3072_mod_96(sp_digit* r, const sp_digit* a, const sp_dig static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 192]; @@ -10056,7 +10061,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 192), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -10158,7 +10163,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -10180,7 +10185,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 192]; @@ -10199,7 +10204,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 192), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -10310,7 +10315,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -10337,7 +10342,7 @@ static int sp_3072_mod_exp_96(sp_digit* r, const sp_digit* a, const sp_digit* e, int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[96 * 5]; @@ -10359,7 +10364,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 96 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -10474,7 +10479,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -10546,7 +10551,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[96 * 4]; @@ -10580,7 +10585,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 96 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -10605,21 +10610,21 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 96); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[48 * 11]; @@ -10654,7 +10659,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 48 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -10702,12 +10707,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 48 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -11450,7 +11455,7 @@ static void sp_3072_lshift_96(sp_digit* r, const sp_digit* a, byte n) static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[289]; @@ -11470,7 +11475,7 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 289, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -11555,7 +11560,7 @@ static int sp_3072_mod_exp_2_96(sp_digit* r, const sp_digit* e, int bits, sp_3072_cond_sub_96(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -13828,7 +13833,7 @@ static WC_INLINE int sp_4096_mod_128(sp_digit* r, const sp_digit* a, const sp_di static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[8 * 256]; @@ -13847,7 +13852,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (8 * 256), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -13949,7 +13954,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -13971,7 +13976,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[16 * 256]; @@ -13990,7 +13995,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (16 * 256), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -14101,7 +14106,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -14128,7 +14133,7 @@ static int sp_4096_mod_exp_128(sp_digit* r, const sp_digit* a, const sp_digit* e int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[128 * 5]; @@ -14150,7 +14155,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 128 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -14265,7 +14270,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -14338,7 +14343,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { #if defined(SP_RSA_PRIVATE_EXP_D) || defined(RSA_LOW_MEM) -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[128 * 4]; @@ -14372,7 +14377,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 128 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -14397,21 +14402,21 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only "a" and "r" are sensitive and need zeroized (same pointer) */ if (a != NULL) ForceZero(a, sizeof(sp_digit) * 128); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } return err; #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[64 * 11]; @@ -14446,7 +14451,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -14494,12 +14499,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 64 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -15438,7 +15443,7 @@ static void sp_4096_lshift_128(sp_digit* r, const sp_digit* a, byte n) static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[385]; @@ -15458,7 +15463,7 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 385, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -15543,7 +15548,7 @@ static int sp_4096_mod_exp_2_128(sp_digit* r, const sp_digit* e, int bits, sp_4096_cond_sub_128(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -19783,7 +19788,7 @@ static void sp_256_get_point_16_8(sp_point_256* r, const sp_point_256* table, static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -19792,7 +19797,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons #endif sp_point_256* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* p = NULL; #else sp_point_256 p[1]; @@ -19808,7 +19813,7 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -19919,32 +19924,32 @@ static int sp_256_ecc_mulmod_fast_8(sp_point_256* r, const sp_point_256* g, cons } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 8 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_256) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -20171,7 +20176,7 @@ static void sp_256_proj_point_add_qz1_8(sp_point_256* r, static int sp_256_gen_stripe_table_8(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -20184,7 +20189,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -20239,7 +20244,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -20318,7 +20323,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -20338,7 +20343,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -20404,7 +20409,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -20524,7 +20529,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 8 * 6]; @@ -20532,7 +20537,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -20568,7 +20573,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -20591,7 +20596,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ static int sp_256_gen_stripe_table_8(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -20604,7 +20609,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -20659,7 +20664,7 @@ static int sp_256_gen_stripe_table_8(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -20738,7 +20743,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -20758,7 +20763,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -20824,7 +20829,7 @@ static int sp_256_ecc_mulmod_stripe_8(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -20944,7 +20949,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 8 * 6]; @@ -20952,7 +20957,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -20988,7 +20993,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -21009,7 +21014,7 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, const sp_ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -21018,7 +21023,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -21041,7 +21046,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -21066,7 +21071,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -21077,7 +21082,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -21121,7 +21126,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -22560,7 +22565,7 @@ static int sp_256_ecc_mulmod_base_8(sp_point_256* r, const sp_digit* k, */ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -22569,7 +22574,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -22591,7 +22596,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -22615,7 +22620,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -22626,7 +22631,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -22669,7 +22674,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, err = sp_256_point_to_ecc_point_8(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -22797,7 +22802,7 @@ static int sp_256_ecc_gen_k_8(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -22816,7 +22821,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -22861,7 +22866,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_256_point_to_ecc_point_8(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -22986,7 +22991,7 @@ static void sp_256_to_bin_8(sp_digit* r, byte* a) int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -22999,7 +23004,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -23024,7 +23029,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 32; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -23625,7 +23630,7 @@ static int sp_256_calc_s_8(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_256* point = NULL; #else @@ -23643,7 +23648,7 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -23722,21 +23727,21 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_256_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 8); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -24308,7 +24313,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_256* p1 = NULL; #else @@ -24323,7 +24328,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -24394,7 +24399,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -24566,7 +24571,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_256_ecc_is_point_8(const sp_point_256* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[8 * 4]; @@ -24574,7 +24579,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -24602,7 +24607,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -24619,7 +24624,7 @@ static int sp_256_ecc_is_point_8(const sp_point_256* point, */ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* pub = NULL; #else sp_point_256 pub[1]; @@ -24627,7 +24632,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -24642,7 +24647,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) err = sp_256_ecc_is_point_8(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -24664,7 +24669,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_256* pub = NULL; #else @@ -24685,7 +24690,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -24751,7 +24756,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -24780,7 +24785,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -24790,7 +24795,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_256* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -24833,7 +24838,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -24857,7 +24862,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -24866,7 +24871,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -24901,7 +24906,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -24921,7 +24926,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -24931,7 +24936,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -24965,7 +24970,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_256_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -24983,7 +24988,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_256_mont_sqrt_8(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 8]; @@ -24991,7 +24996,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 8, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) { err = MEMORY_E; @@ -25034,7 +25039,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -25052,7 +25057,7 @@ static int sp_256_mont_sqrt_8(sp_digit* y) */ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 8]; @@ -25060,7 +25065,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 8, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -25100,7 +25105,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) err = sp_256_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -25602,7 +25607,7 @@ SP_NOINLINE static sp_digit sp_384_sub_12(sp_digit* r, const sp_digit* a, */ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[12]; @@ -25612,7 +25617,7 @@ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 12, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) { err = MEMORY_E; @@ -25687,7 +25692,7 @@ static int sp_384_mod_mul_norm_12(sp_digit* r, const sp_digit* a, const sp_digit r[11] = t[11]; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -27065,7 +27070,7 @@ static void sp_384_get_point_16_12(sp_point_384* r, const sp_point_384* table, static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -27074,7 +27079,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con #endif sp_point_384* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* p = NULL; #else sp_point_384 p[1]; @@ -27090,7 +27095,7 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -27201,32 +27206,32 @@ static int sp_384_ecc_mulmod_fast_12(sp_point_384* r, const sp_point_384* g, con } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 12 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_384) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -27453,7 +27458,7 @@ static void sp_384_proj_point_add_qz1_12(sp_point_384* r, static int sp_384_gen_stripe_table_12(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -27466,7 +27471,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -27521,7 +27526,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -27616,7 +27621,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -27636,7 +27641,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -27702,7 +27707,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -27822,7 +27827,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp #ifndef FP_ECC return sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 12 * 7]; @@ -27830,7 +27835,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -27866,7 +27871,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -27889,7 +27894,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp static int sp_384_gen_stripe_table_12(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -27902,7 +27907,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -27957,7 +27962,7 @@ static int sp_384_gen_stripe_table_12(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -28052,7 +28057,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -28072,7 +28077,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -28138,7 +28143,7 @@ static int sp_384_ecc_mulmod_stripe_12(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -28258,7 +28263,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp #ifndef FP_ECC return sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 12 * 7]; @@ -28266,7 +28271,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -28302,7 +28307,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -28323,7 +28328,7 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, const sp int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -28332,7 +28337,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -28355,7 +28360,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -28380,7 +28385,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -28391,7 +28396,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -28435,7 +28440,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -29874,7 +29879,7 @@ static int sp_384_ecc_mulmod_base_12(sp_point_384* r, const sp_digit* k, */ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -29883,7 +29888,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -29905,7 +29910,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -29929,7 +29934,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -29940,7 +29945,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -29983,7 +29988,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, err = sp_384_point_to_ecc_point_12(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -30123,7 +30128,7 @@ static int sp_384_ecc_gen_k_12(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -30142,7 +30147,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -30187,7 +30192,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_384_point_to_ecc_point_12(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -30312,7 +30317,7 @@ static void sp_384_to_bin_12(sp_digit* r, byte* a) int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -30325,7 +30330,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -30350,7 +30355,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 48; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -30936,7 +30941,7 @@ static int sp_384_calc_s_12(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_384* point = NULL; #else @@ -30954,7 +30959,7 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -31033,21 +31038,21 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_384_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 12); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -31667,7 +31672,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_384* p1 = NULL; #else @@ -31682,7 +31687,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -31753,7 +31758,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -31925,7 +31930,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_384_ecc_is_point_12(const sp_point_384* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[12 * 4]; @@ -31933,7 +31938,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 12 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -31961,7 +31966,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -31978,7 +31983,7 @@ static int sp_384_ecc_is_point_12(const sp_point_384* point, */ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* pub = NULL; #else sp_point_384 pub[1]; @@ -31986,7 +31991,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -32001,7 +32006,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) err = sp_384_ecc_is_point_12(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -32023,7 +32028,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_384* pub = NULL; #else @@ -32044,7 +32049,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -32110,7 +32115,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -32139,7 +32144,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -32149,7 +32154,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_384* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -32192,7 +32197,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -32216,7 +32221,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -32225,7 +32230,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -32260,7 +32265,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -32280,7 +32285,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -32290,7 +32295,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -32324,7 +32329,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_384_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -32342,7 +32347,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_384_mont_sqrt_12(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[5 * 2 * 12]; @@ -32353,7 +32358,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) sp_digit* t5 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 2 * 12, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -32423,7 +32428,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -32441,7 +32446,7 @@ static int sp_384_mont_sqrt_12(sp_digit* y) */ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 12]; @@ -32449,7 +32454,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 12, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -32489,7 +32494,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) err = sp_384_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -34941,7 +34946,7 @@ static void sp_521_get_point_16_17(sp_point_521* r, const sp_point_521* table, static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -34950,7 +34955,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con #endif sp_point_521* rt = NULL; #ifndef WC_NO_CACHE_RESISTANT -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* p = NULL; #else sp_point_521 p[1]; @@ -34966,7 +34971,7 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -35081,32 +35086,32 @@ static int sp_521_ecc_mulmod_fast_17(sp_point_521* r, const sp_point_521* g, con } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 17 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } #ifndef WC_NO_CACHE_RESISTANT - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK if (p != NULL) #endif { ForceZero(p, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(p, heap, DYNAMIC_TYPE_ECC); #endif } #endif /* !WC_NO_CACHE_RESISTANT */ -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_521) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -35333,7 +35338,7 @@ static void sp_521_proj_point_add_qz1_17(sp_point_521* r, static int sp_521_gen_stripe_table_17(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -35346,7 +35351,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -35401,7 +35406,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -35516,7 +35521,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -35536,7 +35541,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -35602,7 +35607,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -35722,7 +35727,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp #ifndef FP_ECC return sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 17 * 6]; @@ -35730,7 +35735,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -35766,7 +35771,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -35789,7 +35794,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp static int sp_521_gen_stripe_table_17(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -35802,7 +35807,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -35857,7 +35862,7 @@ static int sp_521_gen_stripe_table_17(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -35972,7 +35977,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -35992,7 +35997,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -36058,7 +36063,7 @@ static int sp_521_ecc_mulmod_stripe_17(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -36178,7 +36183,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp #ifndef FP_ECC return sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 17 * 6]; @@ -36186,7 +36191,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -36222,7 +36227,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -36243,7 +36248,7 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, const sp int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -36252,7 +36257,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -36275,7 +36280,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -36300,7 +36305,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -36311,7 +36316,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -36355,7 +36360,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -38338,7 +38343,7 @@ static int sp_521_ecc_mulmod_base_17(sp_point_521* r, const sp_digit* k, */ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -38347,7 +38352,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -38369,7 +38374,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -38393,7 +38398,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -38404,7 +38409,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -38447,7 +38452,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, err = sp_521_point_to_ecc_point_17(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -38603,7 +38608,7 @@ static int sp_521_ecc_gen_k_17(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -38622,7 +38627,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -38667,7 +38672,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_521_point_to_ecc_point_17(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -38794,7 +38799,7 @@ static void sp_521_to_bin_17(sp_digit* r, byte* a) int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -38807,7 +38812,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -38832,7 +38837,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 66; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -39874,7 +39879,7 @@ static int sp_521_calc_s_17(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_521* point = NULL; #else @@ -39892,7 +39897,7 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -39976,21 +39981,21 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_521_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -40706,7 +40711,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_521* p1 = NULL; #else @@ -40721,7 +40726,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, sp_int32 c = 0; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -40796,7 +40801,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -40971,7 +40976,7 @@ int sp_ecc_verify_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_521_ecc_is_point_17(const sp_point_521* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[17 * 4]; @@ -40979,7 +40984,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 17 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -41007,7 +41012,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -41024,7 +41029,7 @@ static int sp_521_ecc_is_point_17(const sp_point_521* point, */ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* pub = NULL; #else sp_point_521 pub[1]; @@ -41032,7 +41037,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -41047,7 +41052,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) err = sp_521_ecc_is_point_17(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -41069,7 +41074,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_521* pub = NULL; #else @@ -41090,7 +41095,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -41156,7 +41161,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -41185,7 +41190,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -41195,7 +41200,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, sp_point_521* q = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -41238,7 +41243,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -41262,7 +41267,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -41271,7 +41276,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -41306,7 +41311,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -41326,7 +41331,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -41336,7 +41341,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -41370,7 +41375,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_521_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -41395,14 +41400,14 @@ static const uint32_t p521_sqrt_power[17] = { */ static int sp_521_mont_sqrt_17(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t = NULL; #else sp_digit t[2 * 17]; #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -41423,7 +41428,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -41441,7 +41446,7 @@ static int sp_521_mont_sqrt_17(sp_digit* y) */ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 17]; @@ -41449,7 +41454,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) sp_digit* y = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 17, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -41489,7 +41494,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) err = sp_521_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -42832,7 +42837,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, { int ret = MP_OKAY; (void)heap; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) (void)sp; *p = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); #else @@ -42844,7 +42850,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, return ret; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* Allocate memory for point and return error. */ #define sp_1024_point_new_32(heap, sp, p) sp_1024_point_new_ex_32((heap), NULL, &(p)) #else @@ -42861,7 +42868,8 @@ static int sp_1024_point_new_ex_32(void* heap, sp_point_1024* sp, */ static void sp_1024_point_free_32(sp_point_1024* p, int clear, void* heap) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* If valid pointer then clear point data if requested and free data. */ if (p != NULL) { if (clear != 0) { @@ -44987,7 +44995,7 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r, static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -45005,7 +45013,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (16 + 1), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -45088,21 +45096,21 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 37); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) #endif { ForceZero(t, sizeof(sp_point_1024) * 17); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif } @@ -45329,7 +45337,7 @@ static void sp_1024_proj_point_add_qz1_32(sp_point_1024* r, static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -45342,7 +45350,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -45397,7 +45405,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -45426,7 +45434,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -45446,7 +45454,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -45497,7 +45505,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -45617,7 +45625,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 32 * 38]; @@ -45625,7 +45633,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -45661,7 +45669,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -45684,7 +45692,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -45697,7 +45705,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -45752,7 +45760,7 @@ static int sp_1024_gen_stripe_table_32(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -45781,7 +45789,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -45801,7 +45809,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -45852,7 +45860,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -45972,7 +45980,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 32 * 38]; @@ -45980,7 +45988,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -46016,7 +46024,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -46037,7 +46045,7 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, const int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -46046,7 +46054,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -46069,7 +46077,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -49676,7 +49684,7 @@ static int sp_1024_ecc_mulmod_base_32(sp_point_1024* r, const sp_digit* k, */ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -49685,7 +49693,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -49707,7 +49715,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -49731,7 +49739,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -49742,7 +49750,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, sp_digit* tmp = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -49785,7 +49793,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -49808,7 +49816,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* t = NULL; #else @@ -49829,7 +49837,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); @@ -49853,7 +49861,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, *len = sizeof(sp_table_entry_1024) * 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -49911,7 +49919,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -49920,7 +49928,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, #endif int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) { @@ -49949,7 +49957,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, err = sp_1024_point_to_ecc_point_32(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -50024,8 +50032,8 @@ static void sp_1024_proj_sqr_32(sp_digit* px, sp_digit* py, sp_digit* t) */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -50044,8 +50052,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -50054,8 +50062,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 32 * 2; ty = td + 37 * 32 * 2; @@ -50098,8 +50106,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -51923,8 +51931,8 @@ static const sp_digit sp_1024_g_table[256][32] = { */ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -51942,8 +51950,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -51952,8 +51960,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 32 * 2; ty = td + 37 * 32 * 2; @@ -51996,8 +52004,8 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -52267,8 +52275,8 @@ static void sp_1024_accumulate_line_add_one_32(sp_digit* vx, sp_digit* vy, int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -52297,8 +52305,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -52309,8 +52317,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -52366,8 +52374,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -52645,8 +52653,8 @@ static const signed char sp_1024_order_op[] = { int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -52682,8 +52690,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -52694,8 +52702,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -52793,8 +52801,8 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -53034,8 +53042,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -53074,8 +53082,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_32(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -53086,8 +53094,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; pre_p = (sp_point_1024*)(td + 36 * 32 * 2); #endif @@ -53161,8 +53169,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -53196,8 +53204,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -53239,8 +53247,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_32(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -53251,8 +53259,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 32 * 2; vy = td + 37 * 32 * 2; @@ -53356,8 +53364,8 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -53418,7 +53426,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) static int sp_1024_ecc_is_point_32(const sp_point_1024* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[32 * 4]; @@ -53427,7 +53435,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, sp_int32 n; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -53458,7 +53466,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -53475,7 +53483,7 @@ static int sp_1024_ecc_is_point_32(const sp_point_1024* point, */ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* pub = NULL; #else sp_point_1024 pub[1]; @@ -53483,7 +53491,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -53498,7 +53506,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) err = sp_1024_ecc_is_point_32(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -53520,7 +53528,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_1024* pub = NULL; #else @@ -53541,7 +53549,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); @@ -53607,7 +53615,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) diff --git a/wolfcrypt/src/sp_x86_64.c b/wolfcrypt/src/sp_x86_64.c index a33e3653d..862d17316 100644 --- a/wolfcrypt/src/sp_x86_64.c +++ b/wolfcrypt/src/sp_x86_64.c @@ -45,6 +45,11 @@ #endif #endif +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#undef WOLFSSL_SP_SMALL_STACK +#define WOLFSSL_SP_SMALL_STACK +#endif + #include #ifdef WOLFSSL_SP_X86_64_ASM @@ -626,7 +631,7 @@ extern void sp_2048_get_from_table_16(sp_digit* r, sp_digit** table, int idx); static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(33 * 32) + 32]; @@ -648,7 +653,7 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 * 32) + 32, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -795,7 +800,7 @@ static int sp_2048_mod_exp_16(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_16(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -867,7 +872,7 @@ extern void sp_2048_get_from_table_avx2_16(sp_digit* r, sp_digit** table, int id static int sp_2048_mod_exp_avx2_16(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(33 * 32) + 32]; @@ -889,7 +894,7 @@ static int sp_2048_mod_exp_avx2_16(sp_digit* r, const sp_digit* a, const sp_digi err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 * 32) + 32, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -1036,7 +1041,7 @@ static int sp_2048_mod_exp_avx2_16(sp_digit* r, const sp_digit* a, const sp_digi sp_2048_cond_sub_avx2_16(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -1405,7 +1410,7 @@ extern void sp_2048_get_from_table_32(sp_digit* r, sp_digit** table, int idx); static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(65 * 64) + 64]; @@ -1427,7 +1432,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (65 * 64) + 64, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -1607,7 +1612,7 @@ static int sp_2048_mod_exp_32(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -1681,7 +1686,7 @@ extern void sp_2048_get_from_table_avx2_32(sp_digit* r, sp_digit** table, int id static int sp_2048_mod_exp_avx2_32(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(65 * 64) + 64]; @@ -1703,7 +1708,7 @@ static int sp_2048_mod_exp_avx2_32(sp_digit* r, const sp_digit* a, const sp_digi err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (65 * 64) + 64, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -1883,7 +1888,7 @@ static int sp_2048_mod_exp_avx2_32(sp_digit* r, const sp_digit* a, const sp_digi sp_2048_cond_sub_avx2_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -1909,7 +1914,7 @@ static int sp_2048_mod_exp_avx2_32(sp_digit* r, const sp_digit* a, const sp_digi int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[32 * 5]; @@ -1936,7 +1941,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -2089,7 +2094,7 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, const mp_int* em, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -2120,7 +2125,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, const mp_int* pm, const mp_int* qm,const mp_int* dpm, const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[32 * 4]; @@ -2156,7 +2161,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -2183,13 +2188,13 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only zeroing private "d" */ ForceZero(d, sizeof(sp_digit) * 32); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -2233,7 +2238,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[16 * 11]; @@ -2273,7 +2278,7 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 16 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -2356,12 +2361,12 @@ int sp_RsaPrivate_2048(const byte* in, word32 inLen, const mp_int* dm, *outLen = 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 16 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -2454,7 +2459,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, mp_int* res) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit *b = NULL; sp_digit *e = NULL; sp_digit *m = NULL; @@ -2485,7 +2490,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { if (((b = (sp_digit *)XMALLOC(64 * sizeof(*b), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || ((e = (sp_digit *)XMALLOC(32 * sizeof(*e), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || @@ -2515,7 +2520,7 @@ int sp_ModExp_2048(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_2048_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (e != NULL) { @@ -2554,7 +2559,7 @@ extern void sp_2048_lshift_32(sp_digit* r, const sp_digit* a, int n); static int sp_2048_mod_exp_2_avx2_32(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[33 + 64]; @@ -2576,7 +2581,7 @@ static int sp_2048_mod_exp_2_avx2_32(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 + 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -2588,7 +2593,7 @@ static int sp_2048_mod_exp_2_avx2_32(sp_digit* r, const sp_digit* e, int bits, if (err == MP_OKAY) { norm = td; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = td + 64; #else tmp = &td[64]; @@ -2671,7 +2676,7 @@ static int sp_2048_mod_exp_2_avx2_32(sp_digit* r, const sp_digit* e, int bits, sp_2048_cond_sub_avx2_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -2693,7 +2698,7 @@ static int sp_2048_mod_exp_2_avx2_32(sp_digit* r, const sp_digit* e, int bits, static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[33 + 64]; @@ -2715,7 +2720,7 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 + 64), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -2727,7 +2732,7 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, if (err == MP_OKAY) { norm = td; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = td + 64; #else tmp = &td[64]; @@ -2810,7 +2815,7 @@ static int sp_2048_mod_exp_2_32(sp_digit* r, const sp_digit* e, int bits, sp_2048_cond_sub_32(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -2836,7 +2841,7 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit *b = NULL; sp_digit *e = NULL; sp_digit *m = NULL; @@ -2867,7 +2872,7 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { if (((b = (sp_digit *)XMALLOC(64 * sizeof(*b), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || ((e = (sp_digit *)XMALLOC(32 * sizeof(*e), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || @@ -2916,7 +2921,7 @@ int sp_DhExp_2048(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (e != NULL) { @@ -2945,7 +2950,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, mp_int* res) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit *b = NULL; sp_digit *e = NULL; sp_digit *m = NULL; @@ -2976,7 +2981,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { if (((b = (sp_digit *)XMALLOC(32 * sizeof(*b), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || ((e = (sp_digit *)XMALLOC(16 * sizeof(*e), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || @@ -3007,7 +3012,7 @@ int sp_ModExp_1024(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_2048_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (e != NULL) { @@ -3628,7 +3633,7 @@ extern void sp_3072_get_from_table_24(sp_digit* r, sp_digit** table, int idx); static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(33 * 48) + 48]; @@ -3650,7 +3655,7 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 * 48) + 48, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -3797,7 +3802,7 @@ static int sp_3072_mod_exp_24(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_24(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -3869,7 +3874,7 @@ extern void sp_3072_get_from_table_avx2_24(sp_digit* r, sp_digit** table, int id static int sp_3072_mod_exp_avx2_24(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(33 * 48) + 48]; @@ -3891,7 +3896,7 @@ static int sp_3072_mod_exp_avx2_24(sp_digit* r, const sp_digit* a, const sp_digi err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (33 * 48) + 48, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4038,7 +4043,7 @@ static int sp_3072_mod_exp_avx2_24(sp_digit* r, const sp_digit* a, const sp_digi sp_3072_cond_sub_avx2_24(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4407,7 +4412,7 @@ extern void sp_3072_get_from_table_48(sp_digit* r, sp_digit** table, int idx); static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(17 * 96) + 96]; @@ -4429,7 +4434,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 96) + 96, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4557,7 +4562,7 @@ static int sp_3072_mod_exp_48(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4631,7 +4636,7 @@ extern void sp_3072_get_from_table_avx2_48(sp_digit* r, sp_digit** table, int id static int sp_3072_mod_exp_avx2_48(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(17 * 96) + 96]; @@ -4653,7 +4658,7 @@ static int sp_3072_mod_exp_avx2_48(sp_digit* r, const sp_digit* a, const sp_digi err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 96) + 96, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -4781,7 +4786,7 @@ static int sp_3072_mod_exp_avx2_48(sp_digit* r, const sp_digit* a, const sp_digi sp_3072_cond_sub_avx2_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -4807,7 +4812,7 @@ static int sp_3072_mod_exp_avx2_48(sp_digit* r, const sp_digit* a, const sp_digi int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[48 * 5]; @@ -4834,7 +4839,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 48 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -4987,7 +4992,7 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, const mp_int* em, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -5018,7 +5023,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, const mp_int* pm, const mp_int* qm,const mp_int* dpm, const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[48 * 4]; @@ -5054,7 +5059,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 48 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -5081,13 +5086,13 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only zeroing private "d" */ ForceZero(d, sizeof(sp_digit) * 48); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -5131,7 +5136,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[24 * 11]; @@ -5171,7 +5176,7 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 24 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -5254,12 +5259,12 @@ int sp_RsaPrivate_3072(const byte* in, word32 inLen, const mp_int* dm, *outLen = 384; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 24 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -5352,7 +5357,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, mp_int* res) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit *b = NULL; sp_digit *e = NULL; sp_digit *m = NULL; @@ -5383,7 +5388,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { if (((b = (sp_digit *)XMALLOC(96 * sizeof(*b), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || ((e = (sp_digit *)XMALLOC(48 * sizeof(*e), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || @@ -5413,7 +5418,7 @@ int sp_ModExp_3072(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (e != NULL) { @@ -5452,7 +5457,7 @@ extern void sp_3072_lshift_48(sp_digit* r, const sp_digit* a, int n); static int sp_3072_mod_exp_2_avx2_48(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[49 + 96]; @@ -5474,7 +5479,7 @@ static int sp_3072_mod_exp_2_avx2_48(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (49 + 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5486,7 +5491,7 @@ static int sp_3072_mod_exp_2_avx2_48(sp_digit* r, const sp_digit* e, int bits, if (err == MP_OKAY) { norm = td; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = td + 96; #else tmp = &td[96]; @@ -5569,7 +5574,7 @@ static int sp_3072_mod_exp_2_avx2_48(sp_digit* r, const sp_digit* e, int bits, sp_3072_cond_sub_avx2_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -5591,7 +5596,7 @@ static int sp_3072_mod_exp_2_avx2_48(sp_digit* r, const sp_digit* e, int bits, static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[49 + 96]; @@ -5613,7 +5618,7 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (49 + 96), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -5625,7 +5630,7 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, if (err == MP_OKAY) { norm = td; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = td + 96; #else tmp = &td[96]; @@ -5708,7 +5713,7 @@ static int sp_3072_mod_exp_2_48(sp_digit* r, const sp_digit* e, int bits, sp_3072_cond_sub_48(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -5734,7 +5739,7 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit *b = NULL; sp_digit *e = NULL; sp_digit *m = NULL; @@ -5765,7 +5770,7 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { if (((b = (sp_digit *)XMALLOC(96 * sizeof(*b), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || ((e = (sp_digit *)XMALLOC(48 * sizeof(*e), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || @@ -5814,7 +5819,7 @@ int sp_DhExp_3072(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (e != NULL) { @@ -5843,7 +5848,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, mp_int* res) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit *b = NULL; sp_digit *e = NULL; sp_digit *m = NULL; @@ -5874,7 +5879,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { if (((b = (sp_digit *)XMALLOC(48 * sizeof(*b), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || ((e = (sp_digit *)XMALLOC(24 * sizeof(*e), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || @@ -5905,7 +5910,7 @@ int sp_ModExp_1536(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_3072_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (e != NULL) { @@ -6531,7 +6536,7 @@ extern void sp_4096_get_from_table_64(sp_digit* r, sp_digit** table, int idx); static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(17 * 128) + 128]; @@ -6553,7 +6558,7 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 128) + 128, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -6681,7 +6686,7 @@ static int sp_4096_mod_exp_64(sp_digit* r, const sp_digit* a, const sp_digit* e, sp_4096_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -6755,7 +6760,7 @@ extern void sp_4096_get_from_table_avx2_64(sp_digit* r, sp_digit** table, int id static int sp_4096_mod_exp_avx2_64(sp_digit* r, const sp_digit* a, const sp_digit* e, int bits, const sp_digit* m, int reduceA) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[(17 * 128) + 128]; @@ -6777,7 +6782,7 @@ static int sp_4096_mod_exp_avx2_64(sp_digit* r, const sp_digit* a, const sp_digi err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (17 * 128) + 128, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -6905,7 +6910,7 @@ static int sp_4096_mod_exp_avx2_64(sp_digit* r, const sp_digit* a, const sp_digi sp_4096_cond_sub_avx2_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -6931,7 +6936,7 @@ static int sp_4096_mod_exp_avx2_64(sp_digit* r, const sp_digit* a, const sp_digi int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[64 * 5]; @@ -6958,7 +6963,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 5, NULL, DYNAMIC_TYPE_RSA); @@ -7111,7 +7116,7 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, const mp_int* em, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif @@ -7142,7 +7147,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, const mp_int* pm, const mp_int* qm,const mp_int* dpm, const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* d = NULL; #else sp_digit d[64 * 4]; @@ -7178,7 +7183,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { d = (sp_digit*)XMALLOC(sizeof(sp_digit) * 64 * 4, NULL, DYNAMIC_TYPE_RSA); @@ -7205,13 +7210,13 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (d != NULL) #endif { /* only zeroing private "d" */ ForceZero(d, sizeof(sp_digit) * 64); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(d, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -7255,7 +7260,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, const mp_int* pm, const mp_int* qm, const mp_int* dpm, const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out, word32* outLen) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* a = NULL; #else sp_digit a[32 * 11]; @@ -7295,7 +7300,7 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { a = (sp_digit*)XMALLOC(sizeof(sp_digit) * 32 * 11, NULL, DYNAMIC_TYPE_RSA); @@ -7378,12 +7383,12 @@ int sp_RsaPrivate_4096(const byte* in, word32 inLen, const mp_int* dm, *outLen = 512; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (a != NULL) #endif { ForceZero(a, sizeof(sp_digit) * 32 * 11); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(a, NULL, DYNAMIC_TYPE_RSA); #endif } @@ -7476,7 +7481,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, mp_int* res) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit *b = NULL; sp_digit *e = NULL; sp_digit *m = NULL; @@ -7507,7 +7512,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { if (((b = (sp_digit *)XMALLOC(128 * sizeof(*b), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || ((e = (sp_digit *)XMALLOC(64 * sizeof(*e), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || @@ -7537,7 +7542,7 @@ int sp_ModExp_4096(const mp_int* base, const mp_int* exp, const mp_int* mod, err = sp_4096_to_mp(r, res); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (e != NULL) { @@ -7576,7 +7581,7 @@ extern void sp_4096_lshift_64(sp_digit* r, const sp_digit* a, int n); static int sp_4096_mod_exp_2_avx2_64(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[65 + 128]; @@ -7598,7 +7603,7 @@ static int sp_4096_mod_exp_2_avx2_64(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (65 + 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -7610,7 +7615,7 @@ static int sp_4096_mod_exp_2_avx2_64(sp_digit* r, const sp_digit* e, int bits, if (err == MP_OKAY) { norm = td; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = td + 128; #else tmp = &td[128]; @@ -7693,7 +7698,7 @@ static int sp_4096_mod_exp_2_avx2_64(sp_digit* r, const sp_digit* e, int bits, sp_4096_cond_sub_avx2_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -7715,7 +7720,7 @@ static int sp_4096_mod_exp_2_avx2_64(sp_digit* r, const sp_digit* e, int bits, static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* td = NULL; #else sp_digit td[65 + 128]; @@ -7737,7 +7742,7 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * (65 + 128), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -7749,7 +7754,7 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, if (err == MP_OKAY) { norm = td; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = td + 128; #else tmp = &td[128]; @@ -7832,7 +7837,7 @@ static int sp_4096_mod_exp_2_64(sp_digit* r, const sp_digit* e, int bits, sp_4096_cond_sub_64(r, r, m, mask); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (td != NULL) XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -7858,7 +7863,7 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, const mp_int* mod, byte* out, word32* outLen) { int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit *b = NULL; sp_digit *e = NULL; sp_digit *m = NULL; @@ -7889,7 +7894,7 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, err = MP_VAL; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { if (((b = (sp_digit *)XMALLOC(128 * sizeof(*b), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || ((e = (sp_digit *)XMALLOC(64 * sizeof(*e), NULL, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) || @@ -7938,7 +7943,7 @@ int sp_DhExp_4096(const mp_int* base, const byte* exp, word32 expLen, XMEMMOVE(out, out + i, *outLen); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (b != NULL) XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (e != NULL) { @@ -9464,7 +9469,7 @@ extern void sp_256_get_point_33_avx2_4(sp_point_256* r, const sp_point_256* tabl static int sp_256_ecc_mulmod_win_add_sub_4(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -9482,7 +9487,7 @@ static int sp_256_ecc_mulmod_win_add_sub_4(sp_point_256* r, const sp_point_256* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -9578,7 +9583,7 @@ static int sp_256_ecc_mulmod_win_add_sub_4(sp_point_256* r, const sp_point_256* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -10500,7 +10505,7 @@ static void sp_256_proj_point_add_sub_avx2_4(sp_point_256* ra, static int sp_256_ecc_mulmod_win_add_sub_avx2_4(sp_point_256* r, const sp_point_256* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; sp_digit* tmp = NULL; #else @@ -10518,7 +10523,7 @@ static int sp_256_ecc_mulmod_win_add_sub_avx2_4(sp_point_256* r, const sp_point_ (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -10614,7 +10619,7 @@ static int sp_256_ecc_mulmod_win_add_sub_avx2_4(sp_point_256* r, const sp_point_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -10747,7 +10752,7 @@ static void sp_256_proj_to_affine_4(sp_point_256* a, sp_digit* t) static int sp_256_gen_stripe_table_4(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -10760,7 +10765,7 @@ static int sp_256_gen_stripe_table_4(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -10815,7 +10820,7 @@ static int sp_256_gen_stripe_table_4(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -10859,7 +10864,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -10879,7 +10884,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -10945,7 +10950,7 @@ static int sp_256_ecc_mulmod_stripe_4(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -11066,7 +11071,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ #ifndef FP_ECC return sp_256_ecc_mulmod_win_add_sub_4(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 4 * 6]; @@ -11074,7 +11079,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 4 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -11110,7 +11115,7 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -11234,7 +11239,7 @@ static void sp_256_proj_to_affine_avx2_4(sp_point_256* a, sp_digit* t) static int sp_256_gen_stripe_table_avx2_4(const sp_point_256* a, sp_table_entry_256* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* t = NULL; #else sp_point_256 t[3]; @@ -11247,7 +11252,7 @@ static int sp_256_gen_stripe_table_avx2_4(const sp_point_256* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -11302,7 +11307,7 @@ static int sp_256_gen_stripe_table_avx2_4(const sp_point_256* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -11332,7 +11337,7 @@ static int sp_256_ecc_mulmod_stripe_avx2_4(sp_point_256* r, const sp_point_256* const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* t = NULL; #else @@ -11352,7 +11357,7 @@ static int sp_256_ecc_mulmod_stripe_avx2_4(sp_point_256* r, const sp_point_256* (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -11418,7 +11423,7 @@ static int sp_256_ecc_mulmod_stripe_avx2_4(sp_point_256* r, const sp_point_256* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -11446,7 +11451,7 @@ static int sp_256_ecc_mulmod_avx2_4(sp_point_256* r, const sp_point_256* g, cons #ifndef FP_ECC return sp_256_ecc_mulmod_win_add_sub_avx2_4(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 4 * 6]; @@ -11454,7 +11459,7 @@ static int sp_256_ecc_mulmod_avx2_4(sp_point_256* r, const sp_point_256* g, cons sp_cache_256_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 4 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -11490,7 +11495,7 @@ static int sp_256_ecc_mulmod_avx2_4(sp_point_256* r, const sp_point_256* g, cons } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -11511,7 +11516,7 @@ static int sp_256_ecc_mulmod_avx2_4(sp_point_256* r, const sp_point_256* g, cons int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -11523,7 +11528,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -11551,7 +11556,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_256_point_to_ecc_point_4(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -11576,7 +11581,7 @@ int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -11590,7 +11595,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -11649,7 +11654,7 @@ int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm, err = sp_256_point_to_ecc_point_4(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -24091,7 +24096,7 @@ static int sp_256_ecc_mulmod_add_only_4(sp_point_256* r, const sp_point_256* g, const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* tmp = NULL; #else @@ -24109,7 +24114,7 @@ static int sp_256_ecc_mulmod_add_only_4(sp_point_256* r, const sp_point_256* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -24170,16 +24175,16 @@ static int sp_256_ecc_mulmod_add_only_4(sp_point_256* r, const sp_point_256* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 4 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -24225,7 +24230,7 @@ static int sp_256_ecc_mulmod_add_only_avx2_4(sp_point_256* r, const sp_point_256 const sp_table_entry_256* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* rt = NULL; sp_digit* tmp = NULL; #else @@ -24243,7 +24248,7 @@ static int sp_256_ecc_mulmod_add_only_avx2_4(sp_point_256* r, const sp_point_256 (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -24304,16 +24309,16 @@ static int sp_256_ecc_mulmod_add_only_avx2_4(sp_point_256* r, const sp_point_256 } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 4 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -24351,7 +24356,7 @@ static int sp_256_ecc_mulmod_base_avx2_4(sp_point_256* r, const sp_digit* k, */ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24363,7 +24368,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -24390,7 +24395,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_256_point_to_ecc_point_4(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -24414,7 +24419,7 @@ int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24428,7 +24433,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -24486,7 +24491,7 @@ int sp_ecc_mulmod_base_add_256(const mp_int* km, const ecc_point* am, err = sp_256_point_to_ecc_point_4(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -24580,7 +24585,7 @@ static int sp_256_ecc_gen_k_4(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24602,7 +24607,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -24659,7 +24664,7 @@ int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_256_point_to_ecc_point_4(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -24800,7 +24805,7 @@ static void sp_256_to_bin_4(sp_digit* r, byte* a) int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* point = NULL; sp_digit* k = NULL; #else @@ -24816,7 +24821,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -24846,7 +24851,7 @@ int sp_ecc_secret_gen_256(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 32; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -25652,7 +25657,7 @@ static int sp_256_calc_s_4(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_256* point = NULL; #else @@ -25673,7 +25678,7 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_256*)XMALLOC(sizeof(sp_point_256), heap, DYNAMIC_TYPE_ECC); @@ -25757,21 +25762,21 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_256_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 8 * 2 * 4); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_256)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -26127,7 +26132,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_256* p1 = NULL; #else @@ -26145,7 +26150,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -26233,7 +26238,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -26405,7 +26410,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_256_ecc_is_point_4(const sp_point_256* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 4]; @@ -26413,7 +26418,7 @@ static int sp_256_ecc_is_point_4(const sp_point_256* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -26441,7 +26446,7 @@ static int sp_256_ecc_is_point_4(const sp_point_256* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -26458,7 +26463,7 @@ static int sp_256_ecc_is_point_4(const sp_point_256* point, */ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_256* pub = NULL; #else sp_point_256 pub[1]; @@ -26466,7 +26471,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -26481,7 +26486,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) err = sp_256_ecc_is_point_4(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -26503,7 +26508,7 @@ int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_256* pub = NULL; #else @@ -26527,7 +26532,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, heap, DYNAMIC_TYPE_ECC); @@ -26603,7 +26608,7 @@ int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -26632,7 +26637,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -26645,7 +26650,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -26693,7 +26698,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -26717,7 +26722,7 @@ int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -26729,7 +26734,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -26769,7 +26774,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_256_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -26789,7 +26794,7 @@ int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_256* p = NULL; #else @@ -26802,7 +26807,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_256*)XMALLOC(sizeof(sp_point_256), NULL, DYNAMIC_TYPE_ECC); @@ -26841,7 +26846,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_256_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -26859,7 +26864,7 @@ int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_256_mont_sqrt_4(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[4 * 4]; @@ -26870,7 +26875,7 @@ static int sp_256_mont_sqrt_4(sp_digit* y) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 4, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) { err = MEMORY_E; @@ -26947,7 +26952,7 @@ static int sp_256_mont_sqrt_4(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -26965,7 +26970,7 @@ static int sp_256_mont_sqrt_4(sp_digit* y) */ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 4]; @@ -26976,7 +26981,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 4, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -27023,7 +27028,7 @@ int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym) err = sp_256_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -27172,7 +27177,7 @@ extern sp_digit sp_384_sub_6(sp_digit* r, const sp_digit* a, const sp_digit* b); */ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit* m) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK int64_t* t = NULL; #else int64_t t[2 * 12]; @@ -27183,7 +27188,7 @@ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit* (void)m; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (int64_t*)XMALLOC(sizeof(int64_t) * 2 * 12, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -27266,7 +27271,7 @@ static int sp_384_mod_mul_norm_6(sp_digit* r, const sp_digit* a, const sp_digit* r[5] = (t[11] << 32) | t[10]; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -28604,7 +28609,7 @@ extern void sp_384_get_point_33_avx2_6(sp_point_384* r, const sp_point_384* tabl static int sp_384_ecc_mulmod_win_add_sub_6(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -28622,7 +28627,7 @@ static int sp_384_ecc_mulmod_win_add_sub_6(sp_point_384* r, const sp_point_384* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -28718,7 +28723,7 @@ static int sp_384_ecc_mulmod_win_add_sub_6(sp_point_384* r, const sp_point_384* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -29685,7 +29690,7 @@ static void sp_384_proj_point_add_sub_avx2_6(sp_point_384* ra, static int sp_384_ecc_mulmod_win_add_sub_avx2_6(sp_point_384* r, const sp_point_384* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; sp_digit* tmp = NULL; #else @@ -29703,7 +29708,7 @@ static int sp_384_ecc_mulmod_win_add_sub_avx2_6(sp_point_384* r, const sp_point_ (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -29799,7 +29804,7 @@ static int sp_384_ecc_mulmod_win_add_sub_avx2_6(sp_point_384* r, const sp_point_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -29933,7 +29938,7 @@ static void sp_384_proj_to_affine_6(sp_point_384* a, sp_digit* t) static int sp_384_gen_stripe_table_6(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -29946,7 +29951,7 @@ static int sp_384_gen_stripe_table_6(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -30001,7 +30006,7 @@ static int sp_384_gen_stripe_table_6(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -30045,7 +30050,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -30065,7 +30070,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -30131,7 +30136,7 @@ static int sp_384_ecc_mulmod_stripe_6(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -30252,7 +30257,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ #ifndef FP_ECC return sp_384_ecc_mulmod_win_add_sub_6(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 6 * 7]; @@ -30260,7 +30265,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 6 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -30296,7 +30301,7 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -30421,7 +30426,7 @@ static void sp_384_proj_to_affine_avx2_6(sp_point_384* a, sp_digit* t) static int sp_384_gen_stripe_table_avx2_6(const sp_point_384* a, sp_table_entry_384* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* t = NULL; #else sp_point_384 t[3]; @@ -30434,7 +30439,7 @@ static int sp_384_gen_stripe_table_avx2_6(const sp_point_384* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -30489,7 +30494,7 @@ static int sp_384_gen_stripe_table_avx2_6(const sp_point_384* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -30519,7 +30524,7 @@ static int sp_384_ecc_mulmod_stripe_avx2_6(sp_point_384* r, const sp_point_384* const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* t = NULL; #else @@ -30539,7 +30544,7 @@ static int sp_384_ecc_mulmod_stripe_avx2_6(sp_point_384* r, const sp_point_384* (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -30605,7 +30610,7 @@ static int sp_384_ecc_mulmod_stripe_avx2_6(sp_point_384* r, const sp_point_384* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -30633,7 +30638,7 @@ static int sp_384_ecc_mulmod_avx2_6(sp_point_384* r, const sp_point_384* g, cons #ifndef FP_ECC return sp_384_ecc_mulmod_win_add_sub_avx2_6(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 6 * 7]; @@ -30641,7 +30646,7 @@ static int sp_384_ecc_mulmod_avx2_6(sp_point_384* r, const sp_point_384* g, cons sp_cache_384_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 6 * 7, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -30677,7 +30682,7 @@ static int sp_384_ecc_mulmod_avx2_6(sp_point_384* r, const sp_point_384* g, cons } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -30698,7 +30703,7 @@ static int sp_384_ecc_mulmod_avx2_6(sp_point_384* r, const sp_point_384* g, cons int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -30710,7 +30715,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -30738,7 +30743,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_384_point_to_ecc_point_6(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -30763,7 +30768,7 @@ int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -30777,7 +30782,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -30836,7 +30841,7 @@ int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm, err = sp_384_point_to_ecc_point_6(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -49092,7 +49097,7 @@ static int sp_384_ecc_mulmod_add_only_6(sp_point_384* r, const sp_point_384* g, const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* tmp = NULL; #else @@ -49110,7 +49115,7 @@ static int sp_384_ecc_mulmod_add_only_6(sp_point_384* r, const sp_point_384* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -49171,16 +49176,16 @@ static int sp_384_ecc_mulmod_add_only_6(sp_point_384* r, const sp_point_384* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 6 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -49226,7 +49231,7 @@ static int sp_384_ecc_mulmod_add_only_avx2_6(sp_point_384* r, const sp_point_384 const sp_table_entry_384* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* rt = NULL; sp_digit* tmp = NULL; #else @@ -49244,7 +49249,7 @@ static int sp_384_ecc_mulmod_add_only_avx2_6(sp_point_384* r, const sp_point_384 (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -49305,16 +49310,16 @@ static int sp_384_ecc_mulmod_add_only_avx2_6(sp_point_384* r, const sp_point_384 } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 6 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -49352,7 +49357,7 @@ static int sp_384_ecc_mulmod_base_avx2_6(sp_point_384* r, const sp_digit* k, */ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -49364,7 +49369,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -49391,7 +49396,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_384_point_to_ecc_point_6(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -49415,7 +49420,7 @@ int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -49429,7 +49434,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -49487,7 +49492,7 @@ int sp_ecc_mulmod_base_add_384(const mp_int* km, const ecc_point* am, err = sp_384_point_to_ecc_point_6(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -49581,7 +49586,7 @@ static int sp_384_ecc_gen_k_6(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -49603,7 +49608,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -49660,7 +49665,7 @@ int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_384_point_to_ecc_point_6(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -49801,7 +49806,7 @@ static void sp_384_to_bin_6(sp_digit* r, byte* a) int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* point = NULL; sp_digit* k = NULL; #else @@ -49817,7 +49822,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -49847,7 +49852,7 @@ int sp_ecc_secret_gen_384(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 48; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -50511,7 +50516,7 @@ static int sp_384_calc_s_6(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_384* point = NULL; #else @@ -50532,7 +50537,7 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_384*)XMALLOC(sizeof(sp_point_384), heap, DYNAMIC_TYPE_ECC); @@ -50616,21 +50621,21 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_384_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_384)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -51070,7 +51075,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_384* p1 = NULL; #else @@ -51088,7 +51093,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -51176,7 +51181,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -51348,7 +51353,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_384_ecc_is_point_6(const sp_point_384* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[6 * 4]; @@ -51356,7 +51361,7 @@ static int sp_384_ecc_is_point_6(const sp_point_384* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -51384,7 +51389,7 @@ static int sp_384_ecc_is_point_6(const sp_point_384* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -51401,7 +51406,7 @@ static int sp_384_ecc_is_point_6(const sp_point_384* point, */ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_384* pub = NULL; #else sp_point_384 pub[1]; @@ -51409,7 +51414,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -51424,7 +51429,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) err = sp_384_ecc_is_point_6(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -51446,7 +51451,7 @@ int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_384* pub = NULL; #else @@ -51470,7 +51475,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, heap, DYNAMIC_TYPE_ECC); @@ -51546,7 +51551,7 @@ int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -51575,7 +51580,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -51588,7 +51593,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -51636,7 +51641,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -51660,7 +51665,7 @@ int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -51672,7 +51677,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -51712,7 +51717,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_384_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -51732,7 +51737,7 @@ int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_384* p = NULL; #else @@ -51745,7 +51750,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_384*)XMALLOC(sizeof(sp_point_384), NULL, DYNAMIC_TYPE_ECC); @@ -51784,7 +51789,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_384_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -51802,7 +51807,7 @@ int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ) */ static int sp_384_mont_sqrt_6(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[5 * 2 * 6]; @@ -51816,7 +51821,7 @@ static int sp_384_mont_sqrt_6(sp_digit* y) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 5 * 2 * 6, NULL, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -51945,7 +51950,7 @@ static int sp_384_mont_sqrt_6(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, NULL, DYNAMIC_TYPE_ECC); #endif @@ -51963,7 +51968,7 @@ static int sp_384_mont_sqrt_6(sp_digit* y) */ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 6]; @@ -51974,7 +51979,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 6, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -52021,7 +52026,7 @@ int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym) err = sp_384_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -53483,7 +53488,7 @@ extern void sp_521_get_point_33_avx2_9(sp_point_521* r, const sp_point_521* tabl static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -53501,7 +53506,7 @@ static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -53597,7 +53602,7 @@ static int sp_521_ecc_mulmod_win_add_sub_9(sp_point_521* r, const sp_point_521* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -54541,7 +54546,7 @@ static void sp_521_proj_point_add_sub_avx2_9(sp_point_521* ra, static int sp_521_ecc_mulmod_win_add_sub_avx2_9(sp_point_521* r, const sp_point_521* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; sp_digit* tmp = NULL; #else @@ -54559,7 +54564,7 @@ static int sp_521_ecc_mulmod_win_add_sub_avx2_9(sp_point_521* r, const sp_point_ (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * (33+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -54655,7 +54660,7 @@ static int sp_521_ecc_mulmod_win_add_sub_avx2_9(sp_point_521* r, const sp_point_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -54789,7 +54794,7 @@ static void sp_521_proj_to_affine_9(sp_point_521* a, sp_digit* t) static int sp_521_gen_stripe_table_9(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -54802,7 +54807,7 @@ static int sp_521_gen_stripe_table_9(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -54857,7 +54862,7 @@ static int sp_521_gen_stripe_table_9(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -54901,7 +54906,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -54921,7 +54926,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -54987,7 +54992,7 @@ static int sp_521_ecc_mulmod_stripe_9(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -55108,7 +55113,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ #ifndef FP_ECC return sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 9 * 6]; @@ -55116,7 +55121,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -55152,7 +55157,7 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, const sp_ } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -55277,7 +55282,7 @@ static void sp_521_proj_to_affine_avx2_9(sp_point_521* a, sp_digit* t) static int sp_521_gen_stripe_table_avx2_9(const sp_point_521* a, sp_table_entry_521* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* t = NULL; #else sp_point_521 t[3]; @@ -55290,7 +55295,7 @@ static int sp_521_gen_stripe_table_avx2_9(const sp_point_521* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -55345,7 +55350,7 @@ static int sp_521_gen_stripe_table_avx2_9(const sp_point_521* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -55375,7 +55380,7 @@ static int sp_521_ecc_mulmod_stripe_avx2_9(sp_point_521* r, const sp_point_521* const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* t = NULL; #else @@ -55395,7 +55400,7 @@ static int sp_521_ecc_mulmod_stripe_avx2_9(sp_point_521* r, const sp_point_521* (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -55461,7 +55466,7 @@ static int sp_521_ecc_mulmod_stripe_avx2_9(sp_point_521* r, const sp_point_521* } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -55489,7 +55494,7 @@ static int sp_521_ecc_mulmod_avx2_9(sp_point_521* r, const sp_point_521* g, cons #ifndef FP_ECC return sp_521_ecc_mulmod_win_add_sub_avx2_9(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 9 * 6]; @@ -55497,7 +55502,7 @@ static int sp_521_ecc_mulmod_avx2_9(sp_point_521* r, const sp_point_521* g, cons sp_cache_521_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -55533,7 +55538,7 @@ static int sp_521_ecc_mulmod_avx2_9(sp_point_521* r, const sp_point_521* g, cons } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -55554,7 +55559,7 @@ static int sp_521_ecc_mulmod_avx2_9(sp_point_521* r, const sp_point_521* g, cons int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -55566,7 +55571,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -55594,7 +55599,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -55619,7 +55624,7 @@ int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm, ecc_point* r, int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -55633,7 +55638,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -55692,7 +55697,7 @@ int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -90134,7 +90139,7 @@ static int sp_521_ecc_mulmod_add_only_9(sp_point_521* r, const sp_point_521* g, const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* tmp = NULL; #else @@ -90152,7 +90157,7 @@ static int sp_521_ecc_mulmod_add_only_9(sp_point_521* r, const sp_point_521* g, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -90213,16 +90218,16 @@ static int sp_521_ecc_mulmod_add_only_9(sp_point_521* r, const sp_point_521* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 9 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -90268,7 +90273,7 @@ static int sp_521_ecc_mulmod_add_only_avx2_9(sp_point_521* r, const sp_point_521 const sp_table_entry_521* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* rt = NULL; sp_digit* tmp = NULL; #else @@ -90286,7 +90291,7 @@ static int sp_521_ecc_mulmod_add_only_avx2_9(sp_point_521* r, const sp_point_521 (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -90347,16 +90352,16 @@ static int sp_521_ecc_mulmod_add_only_avx2_9(sp_point_521* r, const sp_point_521 } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) #endif { ForceZero(tmp, sizeof(sp_digit) * 2 * 9 * 6); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (rt != NULL) XFREE(rt, heap, DYNAMIC_TYPE_ECC); #endif @@ -90394,7 +90399,7 @@ static int sp_521_ecc_mulmod_base_avx2_9(sp_point_521* r, const sp_digit* k, */ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -90406,7 +90411,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -90433,7 +90438,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -90457,7 +90462,7 @@ int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -90471,7 +90476,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -90529,7 +90534,7 @@ int sp_ecc_mulmod_base_add_521(const mp_int* km, const ecc_point* am, err = sp_521_point_to_ecc_point_9(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -90624,7 +90629,7 @@ static int sp_521_ecc_gen_k_9(WC_RNG* rng, sp_digit* k) */ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -90646,7 +90651,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK #ifdef WOLFSSL_VALIDATE_ECC_KEYGEN point = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); #else @@ -90703,7 +90708,7 @@ int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap) err = sp_521_point_to_ecc_point_9(point, pub); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) { @@ -90844,7 +90849,7 @@ static void sp_521_to_bin_9(sp_digit* r, byte* a) int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* point = NULL; sp_digit* k = NULL; #else @@ -90860,7 +90865,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -90890,7 +90895,7 @@ int sp_ecc_secret_gen_521(const mp_int* priv, const ecc_point* pub, byte* out, *outLen = 66; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -91609,7 +91614,7 @@ static int sp_521_calc_s_9(sp_digit* s, const sp_digit* r, sp_digit* k, int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* e = NULL; sp_point_521* point = NULL; #else @@ -91630,7 +91635,7 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_521*)XMALLOC(sizeof(sp_point_521), heap, DYNAMIC_TYPE_ECC); @@ -91719,21 +91724,21 @@ int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng, err = sp_521_to_mp(s, sm); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (e != NULL) #endif { ForceZero(e, sizeof(sp_digit) * 7 * 2 * 9); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(e, heap, DYNAMIC_TYPE_ECC); #endif } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (point != NULL) #endif { ForceZero(point, sizeof(sp_point_521)); - #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) + #ifdef WOLFSSL_SP_SMALL_STACK XFREE(point, heap, DYNAMIC_TYPE_ECC); #endif } @@ -92179,7 +92184,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* rm, const mp_int* sm, int* res, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* u1 = NULL; sp_point_521* p1 = NULL; #else @@ -92197,7 +92202,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p1 = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -92289,7 +92294,7 @@ int sp_ecc_verify_521(const byte* hash, word32 hashLen, const mp_int* pX, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (u1 != NULL) XFREE(u1, heap, DYNAMIC_TYPE_ECC); if (p1 != NULL) @@ -92464,7 +92469,7 @@ int sp_ecc_verify_521_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, static int sp_521_ecc_is_point_9(const sp_point_521* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[9 * 4]; @@ -92472,7 +92477,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, sp_digit* t2 = NULL; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -92500,7 +92505,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -92517,7 +92522,7 @@ static int sp_521_ecc_is_point_9(const sp_point_521* point, */ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_521* pub = NULL; #else sp_point_521 pub[1]; @@ -92525,7 +92530,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -92540,7 +92545,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) err = sp_521_ecc_is_point_9(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -92562,7 +92567,7 @@ int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_521* pub = NULL; #else @@ -92586,7 +92591,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, heap, DYNAMIC_TYPE_ECC); @@ -92662,7 +92667,7 @@ int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL) @@ -92691,7 +92696,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -92704,7 +92709,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521) * 2, NULL, DYNAMIC_TYPE_ECC); @@ -92752,7 +92757,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -92776,7 +92781,7 @@ int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -92788,7 +92793,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -92828,7 +92833,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, err = sp_521_to_mp(p->z, rZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -92848,7 +92853,7 @@ int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ, */ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp = NULL; sp_point_521* p = NULL; #else @@ -92861,7 +92866,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { p = (sp_point_521*)XMALLOC(sizeof(sp_point_521), NULL, DYNAMIC_TYPE_ECC); @@ -92900,7 +92905,7 @@ int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ) err = sp_521_to_mp(p->z, pZ); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (tmp != NULL) XFREE(tmp, NULL, DYNAMIC_TYPE_ECC); if (p != NULL) @@ -92925,7 +92930,7 @@ static const uint64_t p521_sqrt_power[9] = { */ static int sp_521_mont_sqrt_9(sp_digit* y) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t = NULL; #else sp_digit t[2 * 9]; @@ -92935,7 +92940,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9, NULL, DYNAMIC_TYPE_ECC); if (t == NULL) err = MEMORY_E; @@ -92970,7 +92975,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, NULL, DYNAMIC_TYPE_ECC); #endif @@ -92988,7 +92993,7 @@ static int sp_521_mont_sqrt_9(sp_digit* y) */ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* x = NULL; #else sp_digit x[4 * 9]; @@ -92999,7 +93004,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK x = (sp_digit*)XMALLOC(sizeof(sp_digit) * 4 * 9, NULL, DYNAMIC_TYPE_ECC); if (x == NULL) err = MEMORY_E; @@ -93046,7 +93051,7 @@ int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym) err = sp_521_to_mp(y, ym); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (x != NULL) XFREE(x, NULL, DYNAMIC_TYPE_ECC); #endif @@ -93423,7 +93428,8 @@ static int sp_1024_point_new_ex_16(void* heap, sp_point_1024* sp, { int ret = MP_OKAY; (void)heap; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) (void)sp; *p = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); #else @@ -93435,7 +93441,8 @@ static int sp_1024_point_new_ex_16(void* heap, sp_point_1024* sp, return ret; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* Allocate memory for point and return error. */ #define sp_1024_point_new_16(heap, sp, p) sp_1024_point_new_ex_16((heap), NULL, &(p)) #else @@ -93452,7 +93459,8 @@ static int sp_1024_point_new_ex_16(void* heap, sp_point_1024* sp, */ static void sp_1024_point_free_16(sp_point_1024* p, int clear, void* heap) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) /* If valid pointer then clear point data if requested and free data. */ if (p != NULL) { if (clear != 0) { @@ -94716,7 +94724,7 @@ static void sp_1024_ecc_recode_7_16(const sp_digit* k, ecc_recode_1024* v) static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -94734,7 +94742,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_10 (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (65+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -94834,7 +94842,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_10 } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -95750,7 +95758,7 @@ static void sp_1024_proj_point_add_sub_avx2_16(sp_point_1024* ra, static int sp_1024_ecc_mulmod_win_add_sub_avx2_16(sp_point_1024* r, const sp_point_1024* g, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; sp_digit* tmp = NULL; #else @@ -95768,7 +95776,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_avx2_16(sp_point_1024* r, const sp_poi (void)ct; (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * (65+2), heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -95868,7 +95876,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_avx2_16(sp_point_1024* r, const sp_poi } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (tmp != NULL) @@ -96002,7 +96010,7 @@ static void sp_1024_proj_to_affine_16(sp_point_1024* a, sp_digit* t) static int sp_1024_gen_stripe_table_16(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -96015,7 +96023,7 @@ static int sp_1024_gen_stripe_table_16(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -96070,7 +96078,7 @@ static int sp_1024_gen_stripe_table_16(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -96099,7 +96107,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -96119,7 +96127,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -96170,7 +96178,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -96290,7 +96298,7 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, const #ifndef FP_ECC return sp_1024_ecc_mulmod_win_add_sub_16(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 16 * 38]; @@ -96298,7 +96306,7 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, const sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -96334,7 +96342,7 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, const } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -96459,7 +96467,7 @@ static void sp_1024_proj_to_affine_avx2_16(sp_point_1024* a, sp_digit* t) static int sp_1024_gen_stripe_table_avx2_16(const sp_point_1024* a, sp_table_entry_1024* table, sp_digit* tmp, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* t = NULL; #else sp_point_1024 t[3]; @@ -96472,7 +96480,7 @@ static int sp_1024_gen_stripe_table_avx2_16(const sp_point_1024* a, (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 3, heap, DYNAMIC_TYPE_ECC); if (t == NULL) @@ -96527,7 +96535,7 @@ static int sp_1024_gen_stripe_table_avx2_16(const sp_point_1024* a, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); #endif @@ -96556,7 +96564,7 @@ static int sp_1024_ecc_mulmod_stripe_avx2_16(sp_point_1024* r, const sp_point_10 const sp_table_entry_1024* table, const sp_digit* k, int map, int ct, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* rt = NULL; sp_digit* t = NULL; #else @@ -96576,7 +96584,7 @@ static int sp_1024_ecc_mulmod_stripe_avx2_16(sp_point_1024* r, const sp_point_10 (void)heap; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK rt = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (rt == NULL) @@ -96627,7 +96635,7 @@ static int sp_1024_ecc_mulmod_stripe_avx2_16(sp_point_1024* r, const sp_point_10 } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (rt != NULL) @@ -96654,7 +96662,7 @@ static int sp_1024_ecc_mulmod_avx2_16(sp_point_1024* r, const sp_point_1024* g, #ifndef FP_ECC return sp_1024_ecc_mulmod_win_add_sub_avx2_16(r, g, k, map, ct, heap); #else -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* tmp; #else sp_digit tmp[2 * 16 * 38]; @@ -96662,7 +96670,7 @@ static int sp_1024_ecc_mulmod_avx2_16(sp_point_1024* r, const sp_point_1024* g, sp_cache_1024_t* cache; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 38, heap, DYNAMIC_TYPE_ECC); if (tmp == NULL) { err = MEMORY_E; @@ -96698,7 +96706,7 @@ static int sp_1024_ecc_mulmod_avx2_16(sp_point_1024* r, const sp_point_1024* g, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK XFREE(tmp, heap, DYNAMIC_TYPE_ECC); #endif return err; @@ -96719,7 +96727,7 @@ static int sp_1024_ecc_mulmod_avx2_16(sp_point_1024* r, const sp_point_1024* g, int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -96731,7 +96739,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -96759,7 +96767,7 @@ int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm, ecc_point* r, err = sp_1024_point_to_ecc_point_16(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -100153,7 +100161,7 @@ static int sp_1024_ecc_mulmod_base_avx2_16(sp_point_1024* r, const sp_digit* k, */ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -100165,7 +100173,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -100192,7 +100200,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) err = sp_1024_point_to_ecc_point_16(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -100216,7 +100224,7 @@ int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* r, int map, void* heap) int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int inMont, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -100230,7 +100238,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); if (point == NULL) @@ -100288,7 +100296,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, err = sp_1024_point_to_ecc_point_16(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point) @@ -100311,7 +100319,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am, int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* t = NULL; #else @@ -100335,7 +100343,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, err = BUFFER_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); @@ -100365,7 +100373,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, *len = sizeof(sp_table_entry_1024) * 256; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t != NULL) XFREE(t, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -100423,7 +100431,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len, int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, ecc_point* r, int map, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* point = NULL; sp_digit* k = NULL; #else @@ -100435,7 +100443,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, word32 cpuid_flags = cpuid_get_flags(); #endif -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK point = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), heap, DYNAMIC_TYPE_ECC); if (point == NULL) { @@ -100470,7 +100478,7 @@ int sp_ecc_mulmod_table_1024(const mp_int* km, const ecc_point* gm, byte* table, err = sp_1024_point_to_ecc_point_16(point, r); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (k != NULL) XFREE(k, heap, DYNAMIC_TYPE_ECC); if (point != NULL) @@ -100545,8 +100553,8 @@ static void sp_1024_proj_sqr_16(sp_digit* px, sp_digit* py, sp_digit* t) */ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -100565,8 +100573,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -100575,8 +100583,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 16 * 2; ty = td + 37 * 16 * 2; @@ -100619,8 +100627,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -102188,8 +102196,8 @@ static const sp_digit sp_1024_g_table[256][16] = { */ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -102207,8 +102215,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -102217,8 +102225,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 16 * 2; ty = td + 37 * 16 * 2; @@ -102261,8 +102269,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -102337,8 +102345,8 @@ static void sp_1024_proj_sqr_avx2_16(sp_digit* px, sp_digit* py, sp_digit* t) */ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -102357,8 +102365,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* int bits; int i; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -102367,8 +102375,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 16 * 2; ty = td + 37 * 16 * 2; @@ -102411,8 +102419,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -102437,8 +102445,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* */ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* res) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td; sp_digit* t; sp_digit* tx; @@ -102456,8 +102464,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* (void)base; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (td == NULL) { @@ -102466,8 +102474,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; tx = td + 36 * 16 * 2; ty = td + 37 * 16 * 2; @@ -102510,8 +102518,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int* err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -102812,8 +102820,8 @@ static void sp_1024_accumulate_line_add_one_16(sp_digit* vx, sp_digit* vy, static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -102842,8 +102850,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -102854,8 +102862,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -102911,8 +102919,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -103190,8 +103198,8 @@ static const signed char sp_1024_order_op[] = { static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -103227,8 +103235,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -103239,8 +103247,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -103338,8 +103346,8 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -103613,8 +103621,8 @@ static void sp_1024_accumulate_line_add_one_avx2_16(sp_digit* vx, sp_digit* vy, static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err = MP_OKAY; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -103643,8 +103651,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -103655,8 +103663,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -103712,8 +103720,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -103964,8 +103972,8 @@ static void sp_1024_accumulate_line_dbl_n_avx2_16(sp_digit* vx, sp_digit* vy, static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res) { int err; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -104001,8 +104009,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -104013,8 +104021,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -104112,8 +104120,8 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -104389,8 +104397,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -104429,8 +104437,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_16(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -104441,8 +104449,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; pre_p = (sp_point_1024*)(td + 36 * 16 * 2); #endif @@ -104516,8 +104524,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -104551,8 +104559,8 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -104594,8 +104602,8 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -104606,8 +104614,8 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -104711,8 +104719,8 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm, err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -104926,8 +104934,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table, word32* len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_point_1024* pre_p; @@ -104966,8 +104974,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table, err = sp_1024_point_new_16(NULL, negd, neg); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -104978,8 +104986,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table, #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; pre_p = (sp_point_1024*)(td + 36 * 16 * 2); #endif @@ -105053,8 +105061,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table, *len = sizeof(sp_table_entry_1024) * 1167; } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -105088,8 +105096,8 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm mp_int* res, const byte* table, word32 len) { int err = 0; -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) sp_digit* td = NULL; sp_digit* t; sp_digit* vx; @@ -105131,8 +105139,8 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm err = sp_1024_point_new_16(NULL, cd, c); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (err == MP_OKAY) { td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2, NULL, DYNAMIC_TYPE_TMP_BUFFER); @@ -105143,8 +105151,8 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm #endif if (err == MP_OKAY) { -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) t = td; vx = td + 36 * 16 * 2; vy = td + 37 * 16 * 2; @@ -105248,8 +105256,8 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm err = sp_1024_to_mp(r, res); } -#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \ - !defined(WOLFSSL_SP_NO_MALLOC) +#if (defined(WOLFSSL_SP_SMALL) && !defined(WOLFSSL_SP_NO_MALLOC)) || \ + defined(WOLFSSL_SP_SMALL_STACK) if (td != NULL) { XFREE(td, NULL, DYNAMIC_TYPE_TMP_BUFFER); } @@ -105377,7 +105385,7 @@ static void sp_1024_from_bin(sp_digit* r, int size, const byte* a, int n) static int sp_1024_ecc_is_point_16(const sp_point_1024* point, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* t1 = NULL; #else sp_digit t1[16 * 4]; @@ -105386,7 +105394,7 @@ static int sp_1024_ecc_is_point_16(const sp_point_1024* point, sp_int64 n; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK t1 = (sp_digit*)XMALLOC(sizeof(sp_digit) * 16 * 4, heap, DYNAMIC_TYPE_ECC); if (t1 == NULL) err = MEMORY_E; @@ -105417,7 +105425,7 @@ static int sp_1024_ecc_is_point_16(const sp_point_1024* point, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (t1 != NULL) XFREE(t1, heap, DYNAMIC_TYPE_ECC); #endif @@ -105434,7 +105442,7 @@ static int sp_1024_ecc_is_point_16(const sp_point_1024* point, */ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_point_1024* pub = NULL; #else sp_point_1024 pub[1]; @@ -105442,7 +105450,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) const byte one[1] = { 1 }; int err = MP_OKAY; -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_ECC); if (pub == NULL) @@ -105457,7 +105465,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) err = sp_1024_ecc_is_point_16(pub, NULL); } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, NULL, DYNAMIC_TYPE_ECC); #endif @@ -105479,7 +105487,7 @@ int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY) int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, const mp_int* privm, void* heap) { -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK sp_digit* priv = NULL; sp_point_1024* pub = NULL; #else @@ -105503,7 +105511,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, err = ECC_OUT_OF_RANGE_E; } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (err == MP_OKAY) { pub = (sp_point_1024*)XMALLOC(sizeof(sp_point_1024) * 2, heap, DYNAMIC_TYPE_ECC); @@ -105579,7 +105587,7 @@ int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY, } } -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC) +#ifdef WOLFSSL_SP_SMALL_STACK if (pub != NULL) XFREE(pub, heap, DYNAMIC_TYPE_ECC); if (priv != NULL)