Merge pull request #5851 from SparkiDev/sp_enable_asm_fix
SP: --enable-sp-asm now enables SP if not set
This commit is contained in:
commit
f6cb13b11b
11
configure.ac
11
configure.ac
@ -566,6 +566,17 @@ AC_ARG_ENABLE([sp-asm],
|
||||
[ ENABLED_SP_ASM=$SP_ASM_DEFAULT ],
|
||||
)
|
||||
|
||||
if test "$ENABLED_SP_ASM" != "no"
|
||||
then
|
||||
if test "$ENABLED_SP" = "no"
|
||||
then
|
||||
AC_MSG_ERROR([--enable-sp-asm requries SP to be enabled.])
|
||||
fi
|
||||
if test "$ENABLED_SP" = ""
|
||||
then
|
||||
ENABLED_SP=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
# fastmath
|
||||
AC_ARG_ENABLE([fastmath],
|
||||
|
@ -72159,18 +72159,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 8 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -72191,6 +72204,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -72563,18 +72579,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 8 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -72595,6 +72624,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -89573,18 +89605,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 12 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -89605,6 +89650,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -89993,18 +90041,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 12 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -90025,6 +90086,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -116426,18 +116490,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 17 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -116458,6 +116535,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -116866,18 +116946,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 17 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -116898,6 +116991,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -143507,11 +143603,14 @@ static const uint8_t p1024_mod_minus_2[] = {
|
||||
static void sp_1024_mont_inv_32(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
sp_digit* t = td;
|
||||
sp_digit* t = &td[32 * 2 * 32];
|
||||
int i;
|
||||
int j;
|
||||
sp_digit table[32][2 * 32];
|
||||
sp_digit* table[32];
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
table[i] = &td[2 * 32 * i];
|
||||
}
|
||||
XMEMCPY(table[0], a, sizeof(sp_digit) * 32);
|
||||
for (i = 1; i < 6; i++) {
|
||||
sp_1024_mont_sqr_32(table[0], table[0], p1024_mod, p1024_mp_mod);
|
||||
@ -145392,7 +145491,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[16 + 1];
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
sp_digit tmp[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* rt = NULL;
|
||||
sp_digit n;
|
||||
@ -145411,7 +145510,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -145492,7 +145591,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (tmp != NULL)
|
||||
#endif
|
||||
{
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 6);
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 37);
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
@ -145833,7 +145932,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 32 * 6];
|
||||
sp_digit t[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -145854,7 +145953,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -146019,17 +146118,30 @@ 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
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 32 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -146050,6 +146162,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -146172,7 +146287,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 32 * 6];
|
||||
sp_digit t[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -146193,7 +146308,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -146358,17 +146473,30 @@ 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
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 32 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -146389,6 +146517,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -150106,7 +150237,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
sp_digit* k = NULL;
|
||||
#else
|
||||
sp_point_1024 point[2];
|
||||
sp_digit k[32 + 32 * 2 * 6];
|
||||
sp_digit k[32 + 32 * 2 * 37];
|
||||
#endif
|
||||
sp_point_1024* addP = NULL;
|
||||
sp_digit* tmp = NULL;
|
||||
@ -150119,7 +150250,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
k = (sp_digit*)XMALLOC(
|
||||
sizeof(sp_digit) * (32 + 32 * 2 * 6),
|
||||
sizeof(sp_digit) * (32 + 32 * 2 * 37),
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (k == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -150183,7 +150314,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 point[1];
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[38 * 2 * 32];
|
||||
#endif
|
||||
int err = MP_OKAY;
|
||||
|
||||
@ -150207,7 +150338,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
err = MEMORY_E;
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 2 * 32, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 2 * 32, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -150403,7 +150534,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* b;
|
||||
sp_digit* e;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit tx[2 * 32];
|
||||
sp_digit ty[2 * 32];
|
||||
sp_digit b[2 * 32];
|
||||
@ -150416,7 +150547,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -150427,10 +150558,10 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 32 * 2;
|
||||
ty = td + 5 * 32 * 2;
|
||||
b = td + 6 * 32 * 2;
|
||||
e = td + 7 * 32 * 2;
|
||||
tx = td + 36 * 32 * 2;
|
||||
ty = td + 37 * 32 * 2;
|
||||
b = td + 38 * 32 * 2;
|
||||
e = td + 39 * 32 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -152300,7 +152431,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* tx;
|
||||
sp_digit* ty;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit tx[2 * 32];
|
||||
sp_digit ty[2 * 32];
|
||||
#endif
|
||||
@ -152314,7 +152445,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -152325,8 +152456,8 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 32 * 2;
|
||||
ty = td + 5 * 32 * 2;
|
||||
tx = td + 36 * 32 * 2;
|
||||
ty = td + 37 * 32 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -152645,7 +152776,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit* vy;
|
||||
sp_digit* qx_px;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit qx_px[2 * 32];
|
||||
@ -152670,7 +152801,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -152682,9 +152813,9 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
qx_px = td + 8 * 32 * 2;
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
qx_px = td + 38 * 32 * 2;
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -153026,7 +153157,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit (*pre_nvy)[64];
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit pre_vx[16][64];
|
||||
@ -153055,7 +153186,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -153067,12 +153198,12 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 8 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 24 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 40 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 56 * 32 * 2);
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 38 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 54 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 70 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 86 * 32 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -153247,10 +153378,9 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
static void sp_1024_accum_dbl_calc_lc_32(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 32;
|
||||
sp_digit* t2 = t + 2 * 2 * 32;
|
||||
sp_digit* l = t + 4 * 2 * 32;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 32;
|
||||
sp_digit* t2 = t + 34 * 2 * 32;
|
||||
sp_digit* l = t + 35 * 2 * 32;
|
||||
|
||||
/* l = 1 / 2 * p.y */
|
||||
sp_1024_mont_dbl_32(l, py, p1024_mod);
|
||||
@ -153292,10 +153422,9 @@ static void sp_1024_accum_add_calc_lc_32(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, const sp_digit* cx,
|
||||
const sp_digit* cy, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 32;
|
||||
sp_digit* c = t + 2 * 2 * 32;
|
||||
sp_digit* l = t + 4 * 2 * 32;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 32;
|
||||
sp_digit* c = t + 34 * 2 * 32;
|
||||
sp_digit* l = t + 35 * 2 * 32;
|
||||
|
||||
/* l = 1 / (c.x - p.x) */
|
||||
sp_1024_mont_sub_32(l, cx, px, p1024_mod);
|
||||
@ -153412,7 +153541,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
sp_digit* t;
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_point_1024 pre_p[16];
|
||||
sp_point_1024 pd;
|
||||
sp_point_1024 cd;
|
||||
@ -153449,8 +153578,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 32 * 2 + 16 *
|
||||
sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
@ -153461,7 +153590,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
pre_p = (sp_point_1024*)(td + 6 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 36 * 32 * 2);
|
||||
#endif
|
||||
|
||||
sp_1024_point_from_ecc_point_32(p, pm);
|
||||
@ -153492,7 +153621,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_32(c, c, t);
|
||||
sp_1024_mont_map_32(c, t);
|
||||
@ -153521,7 +153651,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
}
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_32(c, c, t);
|
||||
sp_1024_mont_map_32(c, t);
|
||||
@ -153576,7 +153707,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
sp_digit (*pre_vy)[64];
|
||||
sp_digit (*pre_nvy)[64];
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit pre_vx[16][64];
|
||||
@ -153612,7 +153743,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -153624,11 +153755,11 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 8 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 24 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 40 * 32 * 2);
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 38 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 54 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 70 * 32 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
|
@ -24884,18 +24884,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 4 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 4 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -24916,6 +24929,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -25276,18 +25292,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 4 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 4 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -25308,6 +25337,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -45066,18 +45098,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 6 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 6 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -45098,6 +45143,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -45466,18 +45514,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 6 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 6 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -45498,6 +45559,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -73341,18 +73405,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 9 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -73373,6 +73450,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -73753,18 +73833,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 9 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -73785,6 +73878,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -115024,11 +115120,14 @@ static const uint8_t p1024_mod_minus_2[] = {
|
||||
static void sp_1024_mont_inv_16(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
sp_digit* t = td;
|
||||
sp_digit* t = &td[32 * 2 * 16];
|
||||
int i;
|
||||
int j;
|
||||
sp_digit table[32][2 * 16];
|
||||
sp_digit* table[32];
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
table[i] = &td[2 * 16 * i];
|
||||
}
|
||||
XMEMCPY(table[0], a, sizeof(sp_digit) * 16);
|
||||
for (i = 1; i < 6; i++) {
|
||||
sp_1024_mont_sqr_16(table[0], table[0], p1024_mod, p1024_mp_mod);
|
||||
@ -116714,7 +116813,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_10
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[65+2];
|
||||
sp_digit tmp[2 * 16 * 6];
|
||||
sp_digit tmp[2 * 16 * 37];
|
||||
#endif
|
||||
sp_point_1024* rt = NULL;
|
||||
sp_point_1024* p = NULL;
|
||||
@ -116733,7 +116832,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_10
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 6,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 37,
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -117063,7 +117162,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 16 * 6];
|
||||
sp_digit t[2 * 16 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -117084,7 +117183,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -117249,17 +117348,30 @@ 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
|
||||
sp_digit tmp[2 * 16 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 16 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -117280,6 +117392,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -120759,7 +120874,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
sp_digit* k = NULL;
|
||||
#else
|
||||
sp_point_1024 point[2];
|
||||
sp_digit k[16 + 16 * 2 * 6];
|
||||
sp_digit k[16 + 16 * 2 * 37];
|
||||
#endif
|
||||
sp_point_1024* addP = NULL;
|
||||
sp_digit* tmp = NULL;
|
||||
@ -120772,7 +120887,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
k = (sp_digit*)XMALLOC(
|
||||
sizeof(sp_digit) * (16 + 16 * 2 * 6),
|
||||
sizeof(sp_digit) * (16 + 16 * 2 * 37),
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (k == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -120836,7 +120951,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 point[1];
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[38 * 2 * 16];
|
||||
#endif
|
||||
int err = MP_OKAY;
|
||||
|
||||
@ -120860,7 +120975,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
err = MEMORY_E;
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 2 * 16, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 2 * 16, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -121056,7 +121171,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* b;
|
||||
sp_digit* e;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit tx[2 * 16];
|
||||
sp_digit ty[2 * 16];
|
||||
sp_digit b[2 * 16];
|
||||
@ -121069,7 +121184,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -121080,10 +121195,10 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 16 * 2;
|
||||
ty = td + 5 * 16 * 2;
|
||||
b = td + 6 * 16 * 2;
|
||||
e = td + 7 * 16 * 2;
|
||||
tx = td + 36 * 16 * 2;
|
||||
ty = td + 37 * 16 * 2;
|
||||
b = td + 38 * 16 * 2;
|
||||
e = td + 39 * 16 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -122697,7 +122812,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* tx;
|
||||
sp_digit* ty;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit tx[2 * 16];
|
||||
sp_digit ty[2 * 16];
|
||||
#endif
|
||||
@ -122711,7 +122826,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -122722,8 +122837,8 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 16 * 2;
|
||||
ty = td + 5 * 16 * 2;
|
||||
tx = td + 36 * 16 * 2;
|
||||
ty = td + 37 * 16 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -123042,7 +123157,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit* vy;
|
||||
sp_digit* qx_px;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit qx_px[2 * 16];
|
||||
@ -123067,7 +123182,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -123079,9 +123194,9 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
qx_px = td + 8 * 16 * 2;
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
qx_px = td + 38 * 16 * 2;
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -123423,7 +123538,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit (*pre_nvy)[32];
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit pre_vx[16][32];
|
||||
@ -123452,7 +123567,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -123464,12 +123579,12 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 8 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 24 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 40 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 56 * 16 * 2);
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 38 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 54 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 70 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 86 * 16 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -123644,10 +123759,9 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
static void sp_1024_accum_dbl_calc_lc_16(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 16;
|
||||
sp_digit* t2 = t + 2 * 2 * 16;
|
||||
sp_digit* l = t + 4 * 2 * 16;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 16;
|
||||
sp_digit* t2 = t + 34 * 2 * 16;
|
||||
sp_digit* l = t + 35 * 2 * 16;
|
||||
|
||||
/* l = 1 / 2 * p.y */
|
||||
sp_1024_mont_dbl_16(l, py, p1024_mod);
|
||||
@ -123689,10 +123803,9 @@ static void sp_1024_accum_add_calc_lc_16(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, const sp_digit* cx,
|
||||
const sp_digit* cy, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 16;
|
||||
sp_digit* c = t + 2 * 2 * 16;
|
||||
sp_digit* l = t + 4 * 2 * 16;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 16;
|
||||
sp_digit* c = t + 34 * 2 * 16;
|
||||
sp_digit* l = t + 35 * 2 * 16;
|
||||
|
||||
/* l = 1 / (c.x - p.x) */
|
||||
sp_1024_mont_sub_16(l, cx, px, p1024_mod);
|
||||
@ -123809,7 +123922,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
sp_digit* t;
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_point_1024 pre_p[16];
|
||||
sp_point_1024 pd;
|
||||
sp_point_1024 cd;
|
||||
@ -123846,8 +123959,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 16 * 2 + 16 *
|
||||
sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
@ -123858,7 +123971,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
pre_p = (sp_point_1024*)(td + 6 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 36 * 16 * 2);
|
||||
#endif
|
||||
|
||||
sp_1024_point_from_ecc_point_16(p, pm);
|
||||
@ -123889,7 +124002,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_16(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_16(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_16(c, c, t);
|
||||
sp_1024_mont_map_16(c, t);
|
||||
@ -123918,7 +124032,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
}
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_16(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_16(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_16(c, c, t);
|
||||
sp_1024_mont_map_16(c, t);
|
||||
@ -123973,7 +124088,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
sp_digit (*pre_vy)[32];
|
||||
sp_digit (*pre_nvy)[32];
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit pre_vx[16][32];
|
||||
@ -124009,7 +124124,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -124021,11 +124136,11 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 8 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 24 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 40 * 16 * 2);
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 38 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 54 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 70 * 16 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
|
@ -101796,18 +101796,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 8 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -101828,6 +101841,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -102200,18 +102216,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 8 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -102232,6 +102261,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -112470,18 +112502,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 12 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -112502,6 +112547,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -112890,18 +112938,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 12 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -112922,6 +112983,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -126321,18 +126385,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 17 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -126353,6 +126430,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -126761,18 +126841,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 17 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -126793,6 +126886,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -203719,11 +203815,14 @@ static const uint8_t p1024_mod_minus_2[] = {
|
||||
static void sp_1024_mont_inv_32(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
sp_digit* t = td;
|
||||
sp_digit* t = &td[32 * 2 * 32];
|
||||
int i;
|
||||
int j;
|
||||
sp_digit table[32][2 * 32];
|
||||
sp_digit* table[32];
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
table[i] = &td[2 * 32 * i];
|
||||
}
|
||||
XMEMCPY(table[0], a, sizeof(sp_digit) * 32);
|
||||
for (i = 1; i < 6; i++) {
|
||||
sp_1024_mont_sqr_32(table[0], table[0], p1024_mod, p1024_mp_mod);
|
||||
@ -210401,7 +210500,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[16 + 1];
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
sp_digit tmp[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* rt = NULL;
|
||||
sp_digit n;
|
||||
@ -210420,7 +210519,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -210501,7 +210600,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (tmp != NULL)
|
||||
#endif
|
||||
{
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 6);
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 37);
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
@ -210842,7 +210941,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 32 * 6];
|
||||
sp_digit t[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -210863,7 +210962,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -211028,17 +211127,30 @@ 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
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 32 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -211059,6 +211171,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -211181,7 +211296,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 32 * 6];
|
||||
sp_digit t[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -211202,7 +211317,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -211367,17 +211482,30 @@ 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
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 32 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -211398,6 +211526,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -215115,7 +215246,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
sp_digit* k = NULL;
|
||||
#else
|
||||
sp_point_1024 point[2];
|
||||
sp_digit k[32 + 32 * 2 * 6];
|
||||
sp_digit k[32 + 32 * 2 * 37];
|
||||
#endif
|
||||
sp_point_1024* addP = NULL;
|
||||
sp_digit* tmp = NULL;
|
||||
@ -215128,7 +215259,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
k = (sp_digit*)XMALLOC(
|
||||
sizeof(sp_digit) * (32 + 32 * 2 * 6),
|
||||
sizeof(sp_digit) * (32 + 32 * 2 * 37),
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (k == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -215192,7 +215323,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 point[1];
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[38 * 2 * 32];
|
||||
#endif
|
||||
int err = MP_OKAY;
|
||||
|
||||
@ -215216,7 +215347,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
err = MEMORY_E;
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 2 * 32, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 2 * 32, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -215412,7 +215543,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* b;
|
||||
sp_digit* e;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit tx[2 * 32];
|
||||
sp_digit ty[2 * 32];
|
||||
sp_digit b[2 * 32];
|
||||
@ -215425,7 +215556,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -215436,10 +215567,10 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 32 * 2;
|
||||
ty = td + 5 * 32 * 2;
|
||||
b = td + 6 * 32 * 2;
|
||||
e = td + 7 * 32 * 2;
|
||||
tx = td + 36 * 32 * 2;
|
||||
ty = td + 37 * 32 * 2;
|
||||
b = td + 38 * 32 * 2;
|
||||
e = td + 39 * 32 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -217309,7 +217440,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* tx;
|
||||
sp_digit* ty;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit tx[2 * 32];
|
||||
sp_digit ty[2 * 32];
|
||||
#endif
|
||||
@ -217323,7 +217454,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -217334,8 +217465,8 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 32 * 2;
|
||||
ty = td + 5 * 32 * 2;
|
||||
tx = td + 36 * 32 * 2;
|
||||
ty = td + 37 * 32 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -217654,7 +217785,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit* vy;
|
||||
sp_digit* qx_px;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit qx_px[2 * 32];
|
||||
@ -217679,7 +217810,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -217691,9 +217822,9 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
qx_px = td + 8 * 32 * 2;
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
qx_px = td + 38 * 32 * 2;
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -218035,7 +218166,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit (*pre_nvy)[64];
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit pre_vx[16][64];
|
||||
@ -218064,7 +218195,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -218076,12 +218207,12 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 8 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 24 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 40 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 56 * 32 * 2);
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 38 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 54 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 70 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 86 * 32 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -218256,10 +218387,9 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
static void sp_1024_accum_dbl_calc_lc_32(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 32;
|
||||
sp_digit* t2 = t + 2 * 2 * 32;
|
||||
sp_digit* l = t + 4 * 2 * 32;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 32;
|
||||
sp_digit* t2 = t + 34 * 2 * 32;
|
||||
sp_digit* l = t + 35 * 2 * 32;
|
||||
|
||||
/* l = 1 / 2 * p.y */
|
||||
sp_1024_mont_dbl_32(l, py, p1024_mod);
|
||||
@ -218301,10 +218431,9 @@ static void sp_1024_accum_add_calc_lc_32(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, const sp_digit* cx,
|
||||
const sp_digit* cy, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 32;
|
||||
sp_digit* c = t + 2 * 2 * 32;
|
||||
sp_digit* l = t + 4 * 2 * 32;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 32;
|
||||
sp_digit* c = t + 34 * 2 * 32;
|
||||
sp_digit* l = t + 35 * 2 * 32;
|
||||
|
||||
/* l = 1 / (c.x - p.x) */
|
||||
sp_1024_mont_sub_32(l, cx, px, p1024_mod);
|
||||
@ -218421,7 +218550,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
sp_digit* t;
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_point_1024 pre_p[16];
|
||||
sp_point_1024 pd;
|
||||
sp_point_1024 cd;
|
||||
@ -218458,8 +218587,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 32 * 2 + 16 *
|
||||
sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
@ -218470,7 +218599,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
pre_p = (sp_point_1024*)(td + 6 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 36 * 32 * 2);
|
||||
#endif
|
||||
|
||||
sp_1024_point_from_ecc_point_32(p, pm);
|
||||
@ -218501,7 +218630,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_32(c, c, t);
|
||||
sp_1024_mont_map_32(c, t);
|
||||
@ -218530,7 +218660,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
}
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_32(c, c, t);
|
||||
sp_1024_mont_map_32(c, t);
|
||||
@ -218585,7 +218716,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
sp_digit (*pre_vy)[64];
|
||||
sp_digit (*pre_nvy)[64];
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit pre_vx[16][64];
|
||||
@ -218621,7 +218752,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -218633,11 +218764,11 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 8 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 24 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 40 * 32 * 2);
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 38 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 54 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 70 * 32 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
|
@ -23191,18 +23191,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 9 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -23223,6 +23236,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -30727,18 +30743,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 15 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 15 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -30759,6 +30788,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -38316,18 +38348,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 21 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 21 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -38348,6 +38393,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -44903,11 +44951,14 @@ static const uint8_t p1024_mod_minus_2[] = {
|
||||
static void sp_1024_mont_inv_42(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
sp_digit* t = td;
|
||||
sp_digit* t = &td[32 * 2 * 42];
|
||||
int i;
|
||||
int j;
|
||||
sp_digit table[32][2 * 42];
|
||||
sp_digit* table[32];
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
table[i] = &td[2 * 42 * i];
|
||||
}
|
||||
XMEMCPY(table[0], a, sizeof(sp_digit) * 42);
|
||||
for (i = 1; i < 6; i++) {
|
||||
sp_1024_mont_sqr_42(table[0], table[0], p1024_mod, p1024_mp_mod);
|
||||
@ -45677,7 +45728,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g,
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[3];
|
||||
sp_digit tmp[2 * 42 * 6];
|
||||
sp_digit tmp[2 * 42 * 37];
|
||||
#endif
|
||||
sp_digit n;
|
||||
int i;
|
||||
@ -45695,7 +45746,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 42 * 6, heap,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 42 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -45754,7 +45805,7 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (tmp != NULL)
|
||||
#endif
|
||||
{
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 42 * 6);
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 42 * 37);
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
@ -45780,7 +45831,7 @@ typedef struct sp_1024_ecc_mulmod_42_ctx {
|
||||
sp_1024_proj_point_add_42_ctx add_ctx;
|
||||
};
|
||||
sp_point_1024 t[3];
|
||||
sp_digit tmp[2 * 42 * 6];
|
||||
sp_digit tmp[2 * 42 * 37];
|
||||
sp_digit n;
|
||||
int i;
|
||||
int c;
|
||||
@ -46352,7 +46403,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_42(sp_point_1024* r, const sp_point_10
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[65+2];
|
||||
sp_digit tmp[2 * 42 * 6];
|
||||
sp_digit tmp[2 * 42 * 37];
|
||||
#endif
|
||||
sp_point_1024* rt = NULL;
|
||||
sp_point_1024* p = NULL;
|
||||
@ -46371,7 +46422,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_42(sp_point_1024* r, const sp_point_10
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 42 * 6,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 42 * 37,
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -46695,7 +46746,7 @@ static int sp_1024_ecc_mulmod_stripe_42(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 42 * 6];
|
||||
sp_digit t[2 * 42 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -46716,7 +46767,7 @@ static int sp_1024_ecc_mulmod_stripe_42(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 42 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 42 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -46881,17 +46932,30 @@ 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
|
||||
sp_digit tmp[2 * 42 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 42 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 42 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -46912,6 +46976,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -50936,7 +51003,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
sp_digit* k = NULL;
|
||||
#else
|
||||
sp_point_1024 point[2];
|
||||
sp_digit k[42 + 42 * 2 * 6];
|
||||
sp_digit k[42 + 42 * 2 * 37];
|
||||
#endif
|
||||
sp_point_1024* addP = NULL;
|
||||
sp_digit* tmp = NULL;
|
||||
@ -50949,7 +51016,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
k = (sp_digit*)XMALLOC(
|
||||
sizeof(sp_digit) * (42 + 42 * 2 * 6),
|
||||
sizeof(sp_digit) * (42 + 42 * 2 * 37),
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (k == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -51013,7 +51080,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 point[1];
|
||||
sp_digit t[6 * 2 * 42];
|
||||
sp_digit t[38 * 2 * 42];
|
||||
#endif
|
||||
int err = MP_OKAY;
|
||||
|
||||
@ -51037,7 +51104,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
err = MEMORY_E;
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 2 * 42, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 2 * 42, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -51233,7 +51300,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* b;
|
||||
sp_digit* e;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 42];
|
||||
sp_digit t[36 * 2 * 42];
|
||||
sp_digit tx[2 * 42];
|
||||
sp_digit ty[2 * 42];
|
||||
sp_digit b[2 * 42];
|
||||
@ -51246,7 +51313,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 42 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 42 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -51257,10 +51324,10 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 42 * 2;
|
||||
ty = td + 5 * 42 * 2;
|
||||
b = td + 6 * 42 * 2;
|
||||
e = td + 7 * 42 * 2;
|
||||
tx = td + 36 * 42 * 2;
|
||||
ty = td + 37 * 42 * 2;
|
||||
b = td + 38 * 42 * 2;
|
||||
e = td + 39 * 42 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -53130,7 +53197,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* tx;
|
||||
sp_digit* ty;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 42];
|
||||
sp_digit t[36 * 2 * 42];
|
||||
sp_digit tx[2 * 42];
|
||||
sp_digit ty[2 * 42];
|
||||
#endif
|
||||
@ -53144,7 +53211,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 42 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 42 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -53155,8 +53222,8 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 42 * 2;
|
||||
ty = td + 5 * 42 * 2;
|
||||
tx = td + 36 * 42 * 2;
|
||||
ty = td + 37 * 42 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -53475,7 +53542,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit* vy;
|
||||
sp_digit* qx_px;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 42];
|
||||
sp_digit t[36 * 2 * 42];
|
||||
sp_digit vx[2 * 42];
|
||||
sp_digit vy[2 * 42];
|
||||
sp_digit qx_px[2 * 42];
|
||||
@ -53500,7 +53567,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 42 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 42 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -53512,9 +53579,9 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 42 * 2;
|
||||
vy = td + 7 * 42 * 2;
|
||||
qx_px = td + 8 * 42 * 2;
|
||||
vx = td + 36 * 42 * 2;
|
||||
vy = td + 37 * 42 * 2;
|
||||
qx_px = td + 38 * 42 * 2;
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -53856,7 +53923,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit (*pre_nvy)[84];
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 42];
|
||||
sp_digit t[36 * 2 * 42];
|
||||
sp_digit vx[2 * 42];
|
||||
sp_digit vy[2 * 42];
|
||||
sp_digit pre_vx[16][84];
|
||||
@ -53885,7 +53952,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 42 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 42 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -53897,12 +53964,12 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 42 * 2;
|
||||
vy = td + 7 * 42 * 2;
|
||||
pre_vx = (sp_digit(*)[84])(td + 8 * 42 * 2);
|
||||
pre_vy = (sp_digit(*)[84])(td + 24 * 42 * 2);
|
||||
pre_nvy = (sp_digit(*)[84])(td + 40 * 42 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 56 * 42 * 2);
|
||||
vx = td + 36 * 42 * 2;
|
||||
vy = td + 37 * 42 * 2;
|
||||
pre_vx = (sp_digit(*)[84])(td + 38 * 42 * 2);
|
||||
pre_vy = (sp_digit(*)[84])(td + 54 * 42 * 2);
|
||||
pre_nvy = (sp_digit(*)[84])(td + 70 * 42 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 86 * 42 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -54077,10 +54144,9 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
static void sp_1024_accum_dbl_calc_lc_42(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 42;
|
||||
sp_digit* t2 = t + 2 * 2 * 42;
|
||||
sp_digit* l = t + 4 * 2 * 42;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 42;
|
||||
sp_digit* t2 = t + 34 * 2 * 42;
|
||||
sp_digit* l = t + 35 * 2 * 42;
|
||||
|
||||
/* l = 1 / 2 * p.y */
|
||||
sp_1024_mont_dbl_42(l, py, p1024_mod);
|
||||
@ -54122,10 +54188,9 @@ static void sp_1024_accum_add_calc_lc_42(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, const sp_digit* cx,
|
||||
const sp_digit* cy, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 42;
|
||||
sp_digit* c = t + 2 * 2 * 42;
|
||||
sp_digit* l = t + 4 * 2 * 42;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 42;
|
||||
sp_digit* c = t + 34 * 2 * 42;
|
||||
sp_digit* l = t + 35 * 2 * 42;
|
||||
|
||||
/* l = 1 / (c.x - p.x) */
|
||||
sp_1024_mont_sub_42(l, cx, px, p1024_mod);
|
||||
@ -54242,7 +54307,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
sp_digit* t;
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 42];
|
||||
sp_digit t[36 * 2 * 42];
|
||||
sp_point_1024 pre_p[16];
|
||||
sp_point_1024 pd;
|
||||
sp_point_1024 cd;
|
||||
@ -54279,8 +54344,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 42 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 42 * 2 + 16 *
|
||||
sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
@ -54291,7 +54356,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
pre_p = (sp_point_1024*)(td + 6 * 42 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 36 * 42 * 2);
|
||||
#endif
|
||||
|
||||
sp_1024_point_from_ecc_point_42(p, pm);
|
||||
@ -54322,7 +54387,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_42(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_42(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_42(c, c, t);
|
||||
sp_1024_mont_map_42(c, t);
|
||||
@ -54351,7 +54417,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
}
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_42(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_42(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_42(c, c, t);
|
||||
sp_1024_mont_map_42(c, t);
|
||||
@ -54406,7 +54473,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
sp_digit (*pre_vy)[84];
|
||||
sp_digit (*pre_nvy)[84];
|
||||
#else
|
||||
sp_digit t[6 * 2 * 42];
|
||||
sp_digit t[36 * 2 * 42];
|
||||
sp_digit vx[2 * 42];
|
||||
sp_digit vy[2 * 42];
|
||||
sp_digit pre_vx[16][84];
|
||||
@ -54442,7 +54509,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 42 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 42 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -54454,11 +54521,11 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 42 * 2;
|
||||
vy = td + 7 * 42 * 2;
|
||||
pre_vx = (sp_digit(*)[84])(td + 8 * 42 * 2);
|
||||
pre_vy = (sp_digit(*)[84])(td + 24 * 42 * 2);
|
||||
pre_nvy = (sp_digit(*)[84])(td + 40 * 42 * 2);
|
||||
vx = td + 36 * 42 * 2;
|
||||
vy = td + 37 * 42 * 2;
|
||||
pre_vx = (sp_digit(*)[84])(td + 38 * 42 * 2);
|
||||
pre_vy = (sp_digit(*)[84])(td + 54 * 42 * 2);
|
||||
pre_nvy = (sp_digit(*)[84])(td + 70 * 42 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
|
@ -24098,18 +24098,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 5 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 5 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -24130,6 +24143,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -31061,18 +31077,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 7 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 7 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -31093,6 +31122,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -38488,18 +38520,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 9 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -38520,6 +38565,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -44340,11 +44388,14 @@ static const uint8_t p1024_mod_minus_2[] = {
|
||||
static void sp_1024_mont_inv_18(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
sp_digit* t = td;
|
||||
sp_digit* t = &td[32 * 2 * 18];
|
||||
int i;
|
||||
int j;
|
||||
sp_digit table[32][2 * 18];
|
||||
sp_digit* table[32];
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
table[i] = &td[2 * 18 * i];
|
||||
}
|
||||
XMEMCPY(table[0], a, sizeof(sp_digit) * 18);
|
||||
for (i = 1; i < 6; i++) {
|
||||
sp_1024_mont_sqr_18(table[0], table[0], p1024_mod, p1024_mp_mod);
|
||||
@ -45079,7 +45130,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g,
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[3];
|
||||
sp_digit tmp[2 * 18 * 6];
|
||||
sp_digit tmp[2 * 18 * 37];
|
||||
#endif
|
||||
sp_digit n;
|
||||
int i;
|
||||
@ -45097,7 +45148,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 6, heap,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -45156,7 +45207,7 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (tmp != NULL)
|
||||
#endif
|
||||
{
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 18 * 6);
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 18 * 37);
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
@ -45182,7 +45233,7 @@ typedef struct sp_1024_ecc_mulmod_18_ctx {
|
||||
sp_1024_proj_point_add_18_ctx add_ctx;
|
||||
};
|
||||
sp_point_1024 t[3];
|
||||
sp_digit tmp[2 * 18 * 6];
|
||||
sp_digit tmp[2 * 18 * 37];
|
||||
sp_digit n;
|
||||
int i;
|
||||
int c;
|
||||
@ -45706,7 +45757,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_18(sp_point_1024* r, const sp_point_10
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[65+2];
|
||||
sp_digit tmp[2 * 18 * 6];
|
||||
sp_digit tmp[2 * 18 * 37];
|
||||
#endif
|
||||
sp_point_1024* rt = NULL;
|
||||
sp_point_1024* p = NULL;
|
||||
@ -45725,7 +45776,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_18(sp_point_1024* r, const sp_point_10
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 6,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 37,
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -46049,7 +46100,7 @@ static int sp_1024_ecc_mulmod_stripe_18(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 18 * 6];
|
||||
sp_digit t[2 * 18 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -46070,7 +46121,7 @@ static int sp_1024_ecc_mulmod_stripe_18(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -46235,17 +46286,30 @@ 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
|
||||
sp_digit tmp[2 * 18 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 18 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 18 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -46266,6 +46330,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -49776,7 +49843,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
sp_digit* k = NULL;
|
||||
#else
|
||||
sp_point_1024 point[2];
|
||||
sp_digit k[18 + 18 * 2 * 6];
|
||||
sp_digit k[18 + 18 * 2 * 37];
|
||||
#endif
|
||||
sp_point_1024* addP = NULL;
|
||||
sp_digit* tmp = NULL;
|
||||
@ -49789,7 +49856,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
k = (sp_digit*)XMALLOC(
|
||||
sizeof(sp_digit) * (18 + 18 * 2 * 6),
|
||||
sizeof(sp_digit) * (18 + 18 * 2 * 37),
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (k == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -49853,7 +49920,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 point[1];
|
||||
sp_digit t[6 * 2 * 18];
|
||||
sp_digit t[38 * 2 * 18];
|
||||
#endif
|
||||
int err = MP_OKAY;
|
||||
|
||||
@ -49877,7 +49944,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
err = MEMORY_E;
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 2 * 18, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 2 * 18, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -50073,7 +50140,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* b;
|
||||
sp_digit* e;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 18];
|
||||
sp_digit t[36 * 2 * 18];
|
||||
sp_digit tx[2 * 18];
|
||||
sp_digit ty[2 * 18];
|
||||
sp_digit b[2 * 18];
|
||||
@ -50086,7 +50153,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 18 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 18 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -50097,10 +50164,10 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 18 * 2;
|
||||
ty = td + 5 * 18 * 2;
|
||||
b = td + 6 * 18 * 2;
|
||||
e = td + 7 * 18 * 2;
|
||||
tx = td + 36 * 18 * 2;
|
||||
ty = td + 37 * 18 * 2;
|
||||
b = td + 38 * 18 * 2;
|
||||
e = td + 39 * 18 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -51714,7 +51781,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* tx;
|
||||
sp_digit* ty;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 18];
|
||||
sp_digit t[36 * 2 * 18];
|
||||
sp_digit tx[2 * 18];
|
||||
sp_digit ty[2 * 18];
|
||||
#endif
|
||||
@ -51728,7 +51795,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 18 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 18 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -51739,8 +51806,8 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 18 * 2;
|
||||
ty = td + 5 * 18 * 2;
|
||||
tx = td + 36 * 18 * 2;
|
||||
ty = td + 37 * 18 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -52059,7 +52126,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit* vy;
|
||||
sp_digit* qx_px;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 18];
|
||||
sp_digit t[36 * 2 * 18];
|
||||
sp_digit vx[2 * 18];
|
||||
sp_digit vy[2 * 18];
|
||||
sp_digit qx_px[2 * 18];
|
||||
@ -52084,7 +52151,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 18 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 18 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -52096,9 +52163,9 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 18 * 2;
|
||||
vy = td + 7 * 18 * 2;
|
||||
qx_px = td + 8 * 18 * 2;
|
||||
vx = td + 36 * 18 * 2;
|
||||
vy = td + 37 * 18 * 2;
|
||||
qx_px = td + 38 * 18 * 2;
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -52440,7 +52507,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit (*pre_nvy)[36];
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 18];
|
||||
sp_digit t[36 * 2 * 18];
|
||||
sp_digit vx[2 * 18];
|
||||
sp_digit vy[2 * 18];
|
||||
sp_digit pre_vx[16][36];
|
||||
@ -52469,7 +52536,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 18 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 18 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -52481,12 +52548,12 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 18 * 2;
|
||||
vy = td + 7 * 18 * 2;
|
||||
pre_vx = (sp_digit(*)[36])(td + 8 * 18 * 2);
|
||||
pre_vy = (sp_digit(*)[36])(td + 24 * 18 * 2);
|
||||
pre_nvy = (sp_digit(*)[36])(td + 40 * 18 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 56 * 18 * 2);
|
||||
vx = td + 36 * 18 * 2;
|
||||
vy = td + 37 * 18 * 2;
|
||||
pre_vx = (sp_digit(*)[36])(td + 38 * 18 * 2);
|
||||
pre_vy = (sp_digit(*)[36])(td + 54 * 18 * 2);
|
||||
pre_nvy = (sp_digit(*)[36])(td + 70 * 18 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 86 * 18 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -52661,10 +52728,9 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
static void sp_1024_accum_dbl_calc_lc_18(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 18;
|
||||
sp_digit* t2 = t + 2 * 2 * 18;
|
||||
sp_digit* l = t + 4 * 2 * 18;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 18;
|
||||
sp_digit* t2 = t + 34 * 2 * 18;
|
||||
sp_digit* l = t + 35 * 2 * 18;
|
||||
|
||||
/* l = 1 / 2 * p.y */
|
||||
sp_1024_mont_dbl_18(l, py, p1024_mod);
|
||||
@ -52706,10 +52772,9 @@ static void sp_1024_accum_add_calc_lc_18(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, const sp_digit* cx,
|
||||
const sp_digit* cy, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 18;
|
||||
sp_digit* c = t + 2 * 2 * 18;
|
||||
sp_digit* l = t + 4 * 2 * 18;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 18;
|
||||
sp_digit* c = t + 34 * 2 * 18;
|
||||
sp_digit* l = t + 35 * 2 * 18;
|
||||
|
||||
/* l = 1 / (c.x - p.x) */
|
||||
sp_1024_mont_sub_18(l, cx, px, p1024_mod);
|
||||
@ -52826,7 +52891,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
sp_digit* t;
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 18];
|
||||
sp_digit t[36 * 2 * 18];
|
||||
sp_point_1024 pre_p[16];
|
||||
sp_point_1024 pd;
|
||||
sp_point_1024 cd;
|
||||
@ -52863,8 +52928,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 18 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 18 * 2 + 16 *
|
||||
sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
@ -52875,7 +52940,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
pre_p = (sp_point_1024*)(td + 6 * 18 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 36 * 18 * 2);
|
||||
#endif
|
||||
|
||||
sp_1024_point_from_ecc_point_18(p, pm);
|
||||
@ -52906,7 +52971,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_18(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_18(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_18(c, c, t);
|
||||
sp_1024_mont_map_18(c, t);
|
||||
@ -52935,7 +53001,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
}
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_18(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_18(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_18(c, c, t);
|
||||
sp_1024_mont_map_18(c, t);
|
||||
@ -52990,7 +53057,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
sp_digit (*pre_vy)[36];
|
||||
sp_digit (*pre_nvy)[36];
|
||||
#else
|
||||
sp_digit t[6 * 2 * 18];
|
||||
sp_digit t[36 * 2 * 18];
|
||||
sp_digit vx[2 * 18];
|
||||
sp_digit vy[2 * 18];
|
||||
sp_digit pre_vx[16][36];
|
||||
@ -53026,7 +53093,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 18 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 18 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -53038,11 +53105,11 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 18 * 2;
|
||||
vy = td + 7 * 18 * 2;
|
||||
pre_vx = (sp_digit(*)[36])(td + 8 * 18 * 2);
|
||||
pre_vy = (sp_digit(*)[36])(td + 24 * 18 * 2);
|
||||
pre_nvy = (sp_digit(*)[36])(td + 40 * 18 * 2);
|
||||
vx = td + 36 * 18 * 2;
|
||||
vy = td + 37 * 18 * 2;
|
||||
pre_vx = (sp_digit(*)[36])(td + 38 * 18 * 2);
|
||||
pre_vy = (sp_digit(*)[36])(td + 54 * 18 * 2);
|
||||
pre_nvy = (sp_digit(*)[36])(td + 70 * 18 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
|
@ -20516,18 +20516,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 8 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -20548,6 +20561,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -20920,18 +20936,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 8 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 8 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -20952,6 +20981,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -27796,18 +27828,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 12 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -27828,6 +27873,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -28216,18 +28264,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 12 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 12 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -28248,6 +28309,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -35678,18 +35742,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 17 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -35710,6 +35787,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -36118,18 +36198,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 17 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 17 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -36150,6 +36243,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -43164,11 +43260,14 @@ static const uint8_t p1024_mod_minus_2[] = {
|
||||
static void sp_1024_mont_inv_32(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
sp_digit* t = td;
|
||||
sp_digit* t = &td[32 * 2 * 32];
|
||||
int i;
|
||||
int j;
|
||||
sp_digit table[32][2 * 32];
|
||||
sp_digit* table[32];
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
table[i] = &td[2 * 32 * i];
|
||||
}
|
||||
XMEMCPY(table[0], a, sizeof(sp_digit) * 32);
|
||||
for (i = 1; i < 6; i++) {
|
||||
sp_1024_mont_sqr_32(table[0], table[0], p1024_mod, p1024_mp_mod);
|
||||
@ -44925,7 +45024,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[16 + 1];
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
sp_digit tmp[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* rt = NULL;
|
||||
sp_digit n;
|
||||
@ -44944,7 +45043,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -45025,7 +45124,7 @@ static int sp_1024_ecc_mulmod_fast_32(sp_point_1024* r, const sp_point_1024* g,
|
||||
if (tmp != NULL)
|
||||
#endif
|
||||
{
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 6);
|
||||
ForceZero(tmp, sizeof(sp_digit) * 2 * 32 * 37);
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
@ -45366,7 +45465,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 32 * 6];
|
||||
sp_digit t[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -45387,7 +45486,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -45552,17 +45651,30 @@ 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
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 32 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -45583,6 +45695,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -45705,7 +45820,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 32 * 6];
|
||||
sp_digit t[2 * 32 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -45726,7 +45841,7 @@ static int sp_1024_ecc_mulmod_stripe_32(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -45891,17 +46006,30 @@ 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
|
||||
sp_digit tmp[2 * 32 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 32 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 32 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -45922,6 +46050,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -49639,7 +49770,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
sp_digit* k = NULL;
|
||||
#else
|
||||
sp_point_1024 point[2];
|
||||
sp_digit k[32 + 32 * 2 * 6];
|
||||
sp_digit k[32 + 32 * 2 * 37];
|
||||
#endif
|
||||
sp_point_1024* addP = NULL;
|
||||
sp_digit* tmp = NULL;
|
||||
@ -49652,7 +49783,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
k = (sp_digit*)XMALLOC(
|
||||
sizeof(sp_digit) * (32 + 32 * 2 * 6),
|
||||
sizeof(sp_digit) * (32 + 32 * 2 * 37),
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (k == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -49716,7 +49847,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 point[1];
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[38 * 2 * 32];
|
||||
#endif
|
||||
int err = MP_OKAY;
|
||||
|
||||
@ -49740,7 +49871,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
err = MEMORY_E;
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 2 * 32, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 2 * 32, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -49936,7 +50067,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* b;
|
||||
sp_digit* e;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit tx[2 * 32];
|
||||
sp_digit ty[2 * 32];
|
||||
sp_digit b[2 * 32];
|
||||
@ -49949,7 +50080,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -49960,10 +50091,10 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 32 * 2;
|
||||
ty = td + 5 * 32 * 2;
|
||||
b = td + 6 * 32 * 2;
|
||||
e = td + 7 * 32 * 2;
|
||||
tx = td + 36 * 32 * 2;
|
||||
ty = td + 37 * 32 * 2;
|
||||
b = td + 38 * 32 * 2;
|
||||
e = td + 39 * 32 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -51833,7 +51964,7 @@ int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp, mp_int* res)
|
||||
sp_digit* tx;
|
||||
sp_digit* ty;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit tx[2 * 32];
|
||||
sp_digit ty[2 * 32];
|
||||
#endif
|
||||
@ -51847,7 +51978,7 @@ 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)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -51858,8 +51989,8 @@ 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)
|
||||
t = td;
|
||||
tx = td + 4 * 32 * 2;
|
||||
ty = td + 5 * 32 * 2;
|
||||
tx = td + 36 * 32 * 2;
|
||||
ty = td + 37 * 32 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -52178,7 +52309,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit* vy;
|
||||
sp_digit* qx_px;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit qx_px[2 * 32];
|
||||
@ -52203,7 +52334,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -52215,9 +52346,9 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
qx_px = td + 8 * 32 * 2;
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
qx_px = td + 38 * 32 * 2;
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -52559,7 +52690,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
sp_digit (*pre_nvy)[64];
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit pre_vx[16][64];
|
||||
@ -52588,7 +52719,7 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -52600,12 +52731,12 @@ int sp_Pairing_1024(const ecc_point* pm, const ecc_point* qm, mp_int* res)
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 8 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 24 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 40 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 56 * 32 * 2);
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 38 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 54 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 70 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 86 * 32 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -52780,10 +52911,9 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
static void sp_1024_accum_dbl_calc_lc_32(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 32;
|
||||
sp_digit* t2 = t + 2 * 2 * 32;
|
||||
sp_digit* l = t + 4 * 2 * 32;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 32;
|
||||
sp_digit* t2 = t + 34 * 2 * 32;
|
||||
sp_digit* l = t + 35 * 2 * 32;
|
||||
|
||||
/* l = 1 / 2 * p.y */
|
||||
sp_1024_mont_dbl_32(l, py, p1024_mod);
|
||||
@ -52825,10 +52955,9 @@ static void sp_1024_accum_add_calc_lc_32(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, const sp_digit* cx,
|
||||
const sp_digit* cy, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 32;
|
||||
sp_digit* c = t + 2 * 2 * 32;
|
||||
sp_digit* l = t + 4 * 2 * 32;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 32;
|
||||
sp_digit* c = t + 34 * 2 * 32;
|
||||
sp_digit* l = t + 35 * 2 * 32;
|
||||
|
||||
/* l = 1 / (c.x - p.x) */
|
||||
sp_1024_mont_sub_32(l, cx, px, p1024_mod);
|
||||
@ -52945,7 +53074,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
sp_digit* t;
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_point_1024 pre_p[16];
|
||||
sp_point_1024 pd;
|
||||
sp_point_1024 cd;
|
||||
@ -52982,8 +53111,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 32 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 32 * 2 + 16 *
|
||||
sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
@ -52994,7 +53123,7 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
pre_p = (sp_point_1024*)(td + 6 * 32 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 36 * 32 * 2);
|
||||
#endif
|
||||
|
||||
sp_1024_point_from_ecc_point_32(p, pm);
|
||||
@ -53025,7 +53154,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_32(c, c, t);
|
||||
sp_1024_mont_map_32(c, t);
|
||||
@ -53054,7 +53184,8 @@ int sp_Pairing_gen_precomp_1024(const ecc_point* pm, byte* table,
|
||||
}
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_32(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_32(c, c, t);
|
||||
sp_1024_mont_map_32(c, t);
|
||||
@ -53109,7 +53240,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
sp_digit (*pre_vy)[64];
|
||||
sp_digit (*pre_nvy)[64];
|
||||
#else
|
||||
sp_digit t[6 * 2 * 32];
|
||||
sp_digit t[36 * 2 * 32];
|
||||
sp_digit vx[2 * 32];
|
||||
sp_digit vy[2 * 32];
|
||||
sp_digit pre_vx[16][64];
|
||||
@ -53145,7 +53276,7 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 32 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 32 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -53157,11 +53288,11 @@ int sp_Pairing_precomp_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 32 * 2;
|
||||
vy = td + 7 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 8 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 24 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 40 * 32 * 2);
|
||||
vx = td + 36 * 32 * 2;
|
||||
vy = td + 37 * 32 * 2;
|
||||
pre_vx = (sp_digit(*)[64])(td + 38 * 32 * 2);
|
||||
pre_vy = (sp_digit(*)[64])(td + 54 * 32 * 2);
|
||||
pre_nvy = (sp_digit(*)[64])(td + 70 * 32 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
|
@ -11052,18 +11052,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 4 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 4 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -11084,6 +11097,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -11417,18 +11433,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 4 * 6];
|
||||
#endif
|
||||
sp_cache_256_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 4 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_256 == 0) {
|
||||
wc_InitMutex(&sp_cache_256_lock);
|
||||
initCacheMutex_256 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_256_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -11449,6 +11478,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -30240,18 +30272,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 6 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 6 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -30272,6 +30317,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -30606,18 +30654,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 6 * 7];
|
||||
#endif
|
||||
sp_cache_384_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 6 * 7, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_384 == 0) {
|
||||
wc_InitMutex(&sp_cache_384_lock);
|
||||
initCacheMutex_384 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_384_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -30638,6 +30699,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -55098,18 +55162,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 9 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -55130,6 +55207,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -55464,18 +55544,31 @@ 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)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 9 * 6];
|
||||
#endif
|
||||
sp_cache_521_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 9 * 6, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_521 == 0) {
|
||||
wc_InitMutex(&sp_cache_521_lock);
|
||||
initCacheMutex_521 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_521_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -55496,6 +55589,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -93697,11 +93793,14 @@ static const uint8_t p1024_mod_minus_2[] = {
|
||||
static void sp_1024_mont_inv_16(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
sp_digit* t = td;
|
||||
sp_digit* t = &td[32 * 2 * 16];
|
||||
int i;
|
||||
int j;
|
||||
sp_digit table[32][2 * 16];
|
||||
sp_digit* table[32];
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
table[i] = &td[2 * 16 * i];
|
||||
}
|
||||
XMEMCPY(table[0], a, sizeof(sp_digit) * 16);
|
||||
for (i = 1; i < 6; i++) {
|
||||
sp_1024_mont_sqr_16(table[0], table[0], p1024_mod, p1024_mp_mod);
|
||||
@ -94691,7 +94790,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_10
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[65+2];
|
||||
sp_digit tmp[2 * 16 * 6];
|
||||
sp_digit tmp[2 * 16 * 37];
|
||||
#endif
|
||||
sp_point_1024* rt = NULL;
|
||||
sp_point_1024* p = NULL;
|
||||
@ -94710,7 +94809,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_16(sp_point_1024* r, const sp_point_10
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 6,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 37,
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -94867,11 +94966,14 @@ SP_NOINLINE static void sp_1024_mont_sqr_avx2_16(sp_digit* r, const sp_digit* a,
|
||||
static void sp_1024_mont_inv_avx2_16(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
sp_digit* t = td;
|
||||
sp_digit* t = &td[32 * 2 * 16];
|
||||
int i;
|
||||
int j;
|
||||
sp_digit table[32][2 * 16];
|
||||
sp_digit* table[32];
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
table[i] = &td[2 * 16 * i];
|
||||
}
|
||||
XMEMCPY(table[0], a, sizeof(sp_digit) * 16);
|
||||
for (i = 1; i < 6; i++) {
|
||||
sp_1024_mont_sqr_avx2_16(table[0], table[0], p1024_mod, p1024_mp_mod);
|
||||
@ -95740,7 +95842,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_avx2_16(sp_point_1024* r, const sp_poi
|
||||
sp_digit* tmp = NULL;
|
||||
#else
|
||||
sp_point_1024 t[65+2];
|
||||
sp_digit tmp[2 * 16 * 6];
|
||||
sp_digit tmp[2 * 16 * 37];
|
||||
#endif
|
||||
sp_point_1024* rt = NULL;
|
||||
sp_point_1024* p = NULL;
|
||||
@ -95759,7 +95861,7 @@ static int sp_1024_ecc_mulmod_win_add_sub_avx2_16(sp_point_1024* r, const sp_poi
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 6,
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 37,
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -96090,7 +96192,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 16 * 6];
|
||||
sp_digit t[2 * 16 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -96111,7 +96213,7 @@ static int sp_1024_ecc_mulmod_stripe_16(sp_point_1024* r, const sp_point_1024* g
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -96276,17 +96378,30 @@ 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
|
||||
sp_digit tmp[2 * 16 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 16 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -96307,6 +96422,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -96532,7 +96650,7 @@ static int sp_1024_ecc_mulmod_stripe_avx2_16(sp_point_1024* r, const sp_point_10
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 rt[2];
|
||||
sp_digit t[2 * 16 * 6];
|
||||
sp_digit t[2 * 16 * 37];
|
||||
#endif
|
||||
sp_point_1024* p = NULL;
|
||||
int i;
|
||||
@ -96553,7 +96671,7 @@ static int sp_1024_ecc_mulmod_stripe_avx2_16(sp_point_1024* r, const sp_point_10
|
||||
if (rt == NULL)
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 6, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 37, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -96625,17 +96743,30 @@ 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
|
||||
sp_digit tmp[2 * 16 * 6];
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
sp_digit* tmp;
|
||||
#else
|
||||
sp_digit tmp[2 * 16 * 38];
|
||||
#endif
|
||||
sp_cache_1024_t* cache;
|
||||
int err = MP_OKAY;
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SP_NO_MALLOC)
|
||||
tmp = (sp_digit*)XMALLOC(sizeof(sp_digit) * 2 * 16 * 38, heap, DYNAMIC_TYPE_ECC);
|
||||
if (tmp == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
#endif
|
||||
#ifndef HAVE_THREAD_LS
|
||||
if (err == MP_OKAY) {
|
||||
if (initCacheMutex_1024 == 0) {
|
||||
wc_InitMutex(&sp_cache_1024_lock);
|
||||
initCacheMutex_1024 = 1;
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0) {
|
||||
err = BAD_MUTEX_E;
|
||||
}
|
||||
}
|
||||
if (wc_LockMutex(&sp_cache_1024_lock) != 0)
|
||||
err = BAD_MUTEX_E;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
@ -96656,6 +96787,9 @@ 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)
|
||||
XFREE(tmp, heap, DYNAMIC_TYPE_ECC);
|
||||
#endif
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
@ -100176,7 +100310,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
sp_digit* k = NULL;
|
||||
#else
|
||||
sp_point_1024 point[2];
|
||||
sp_digit k[16 + 16 * 2 * 6];
|
||||
sp_digit k[16 + 16 * 2 * 37];
|
||||
#endif
|
||||
sp_point_1024* addP = NULL;
|
||||
sp_digit* tmp = NULL;
|
||||
@ -100192,7 +100326,7 @@ int sp_ecc_mulmod_base_add_1024(const mp_int* km, const ecc_point* am,
|
||||
err = MEMORY_E;
|
||||
if (err == MP_OKAY) {
|
||||
k = (sp_digit*)XMALLOC(
|
||||
sizeof(sp_digit) * (16 + 16 * 2 * 6),
|
||||
sizeof(sp_digit) * (16 + 16 * 2 * 37),
|
||||
heap, DYNAMIC_TYPE_ECC);
|
||||
if (k == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -100271,7 +100405,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
sp_digit* t = NULL;
|
||||
#else
|
||||
sp_point_1024 point[1];
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[38 * 2 * 16];
|
||||
#endif
|
||||
int err = MP_OKAY;
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
@ -100298,7 +100432,7 @@ int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table, word32* len,
|
||||
err = MEMORY_E;
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 2 * 16, heap,
|
||||
t = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 2 * 16, heap,
|
||||
DYNAMIC_TYPE_ECC);
|
||||
if (t == NULL)
|
||||
err = MEMORY_E;
|
||||
@ -100509,7 +100643,7 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r
|
||||
sp_digit* b;
|
||||
sp_digit* e;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit tx[2 * 16];
|
||||
sp_digit ty[2 * 16];
|
||||
sp_digit b[2 * 16];
|
||||
@ -100522,7 +100656,7 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r
|
||||
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -100533,10 +100667,10 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
tx = td + 4 * 16 * 2;
|
||||
ty = td + 5 * 16 * 2;
|
||||
b = td + 6 * 16 * 2;
|
||||
e = td + 7 * 16 * 2;
|
||||
tx = td + 36 * 16 * 2;
|
||||
ty = td + 37 * 16 * 2;
|
||||
b = td + 38 * 16 * 2;
|
||||
e = td + 39 * 16 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -102150,7 +102284,7 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r
|
||||
sp_digit* tx;
|
||||
sp_digit* ty;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit tx[2 * 16];
|
||||
sp_digit ty[2 * 16];
|
||||
#endif
|
||||
@ -102164,7 +102298,7 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r
|
||||
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -102175,8 +102309,8 @@ static int sp_ModExp_Fp_star_x64_1024(const mp_int* base, mp_int* exp, mp_int* r
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
tx = td + 4 * 16 * 2;
|
||||
ty = td + 5 * 16 * 2;
|
||||
tx = td + 36 * 16 * 2;
|
||||
ty = td + 37 * 16 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -102301,7 +102435,7 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int*
|
||||
sp_digit* b;
|
||||
sp_digit* e;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit tx[2 * 16];
|
||||
sp_digit ty[2 * 16];
|
||||
sp_digit b[2 * 16];
|
||||
@ -102314,7 +102448,7 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int*
|
||||
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 8 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 40 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -102325,10 +102459,10 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int*
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
tx = td + 4 * 16 * 2;
|
||||
ty = td + 5 * 16 * 2;
|
||||
b = td + 6 * 16 * 2;
|
||||
e = td + 7 * 16 * 2;
|
||||
tx = td + 36 * 16 * 2;
|
||||
ty = td + 37 * 16 * 2;
|
||||
b = td + 38 * 16 * 2;
|
||||
e = td + 39 * 16 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -102399,7 +102533,7 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int*
|
||||
sp_digit* tx;
|
||||
sp_digit* ty;
|
||||
#else
|
||||
sp_digit t[4 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit tx[2 * 16];
|
||||
sp_digit ty[2 * 16];
|
||||
#endif
|
||||
@ -102413,7 +102547,7 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int*
|
||||
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 38 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -102424,8 +102558,8 @@ static int sp_ModExp_Fp_star_avx2_1024(const mp_int* base, mp_int* exp, mp_int*
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
tx = td + 4 * 16 * 2;
|
||||
ty = td + 5 * 16 * 2;
|
||||
tx = td + 36 * 16 * 2;
|
||||
ty = td + 37 * 16 * 2;
|
||||
#endif
|
||||
r = ty;
|
||||
|
||||
@ -102775,7 +102909,7 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int*
|
||||
sp_digit* vy;
|
||||
sp_digit* qx_px;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit qx_px[2 * 16];
|
||||
@ -102800,7 +102934,7 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int*
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -102812,9 +102946,9 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int*
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
qx_px = td + 8 * 16 * 2;
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
qx_px = td + 38 * 16 * 2;
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -103156,7 +103290,7 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int*
|
||||
sp_digit (*pre_nvy)[32];
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit pre_vx[16][32];
|
||||
@ -103185,7 +103319,7 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int*
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -103197,12 +103331,12 @@ static int sp_Pairing_x64_1024(const ecc_point* pm, const ecc_point* qm, mp_int*
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 8 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 24 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 40 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 56 * 16 * 2);
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 38 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 54 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 70 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 86 * 16 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -103576,7 +103710,7 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int
|
||||
sp_digit* vy;
|
||||
sp_digit* qx_px;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit qx_px[2 * 16];
|
||||
@ -103601,7 +103735,7 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 9 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 39 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -103613,9 +103747,9 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
qx_px = td + 8 * 16 * 2;
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
qx_px = td + 38 * 16 * 2;
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -103930,7 +104064,7 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int
|
||||
sp_digit (*pre_nvy)[32];
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit pre_vx[16][32];
|
||||
@ -103959,7 +104093,7 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -103971,12 +104105,12 @@ static int sp_Pairing_avx2_1024(const ecc_point* pm, const ecc_point* qm, mp_int
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 8 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 24 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 40 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 56 * 16 * 2);
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 38 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 54 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 70 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 86 * 16 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -104187,10 +104321,9 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
static void sp_1024_accum_dbl_calc_lc_16(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 16;
|
||||
sp_digit* t2 = t + 2 * 2 * 16;
|
||||
sp_digit* l = t + 4 * 2 * 16;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 16;
|
||||
sp_digit* t2 = t + 34 * 2 * 16;
|
||||
sp_digit* l = t + 35 * 2 * 16;
|
||||
|
||||
/* l = 1 / 2 * p.y */
|
||||
sp_1024_mont_dbl_16(l, py, p1024_mod);
|
||||
@ -104232,10 +104365,9 @@ static void sp_1024_accum_add_calc_lc_16(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, const sp_digit* cx,
|
||||
const sp_digit* cy, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 16;
|
||||
sp_digit* c = t + 2 * 2 * 16;
|
||||
sp_digit* l = t + 4 * 2 * 16;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 16;
|
||||
sp_digit* c = t + 34 * 2 * 16;
|
||||
sp_digit* l = t + 35 * 2 * 16;
|
||||
|
||||
/* l = 1 / (c.x - p.x) */
|
||||
sp_1024_mont_sub_16(l, cx, px, p1024_mod);
|
||||
@ -104352,7 +104484,7 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table,
|
||||
sp_digit* t;
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_point_1024 pre_p[16];
|
||||
sp_point_1024 pd;
|
||||
sp_point_1024 cd;
|
||||
@ -104389,8 +104521,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 16 * 2 + 16 *
|
||||
sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
@ -104401,7 +104533,7 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
pre_p = (sp_point_1024*)(td + 6 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 36 * 16 * 2);
|
||||
#endif
|
||||
|
||||
sp_1024_point_from_ecc_point_16(p, pm);
|
||||
@ -104432,7 +104564,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table,
|
||||
XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_16(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_16(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_16(c, c, t);
|
||||
sp_1024_mont_map_16(c, t);
|
||||
@ -104461,7 +104594,8 @@ static int sp_Pairing_gen_precomp_x64_1024(const ecc_point* pm, byte* table,
|
||||
}
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_16(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_16(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_16(c, c, t);
|
||||
sp_1024_mont_map_16(c, t);
|
||||
@ -104516,7 +104650,7 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
sp_digit (*pre_vy)[32];
|
||||
sp_digit (*pre_nvy)[32];
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit pre_vx[16][32];
|
||||
@ -104552,7 +104686,7 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -104564,11 +104698,11 @@ static int sp_Pairing_precomp_x64_1024(const ecc_point* pm, const ecc_point* qm,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 8 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 24 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 40 * 16 * 2);
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 38 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 54 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 70 * 16 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
@ -104751,10 +104885,9 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm
|
||||
static void sp_1024_accum_dbl_calc_lc_avx2_16(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 16;
|
||||
sp_digit* t2 = t + 2 * 2 * 16;
|
||||
sp_digit* l = t + 4 * 2 * 16;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 16;
|
||||
sp_digit* t2 = t + 34 * 2 * 16;
|
||||
sp_digit* l = t + 35 * 2 * 16;
|
||||
|
||||
/* l = 1 / 2 * p.y */
|
||||
sp_1024_mont_dbl_avx2_16(l, py, p1024_mod);
|
||||
@ -104796,10 +104929,9 @@ static void sp_1024_accum_add_calc_lc_avx2_16(sp_digit* lr, sp_digit* cr,
|
||||
const sp_digit* px, const sp_digit* py, const sp_digit* cx,
|
||||
const sp_digit* cy, sp_digit* t)
|
||||
{
|
||||
sp_digit* t1 = t + 0 * 2 * 16;
|
||||
sp_digit* c = t + 2 * 2 * 16;
|
||||
sp_digit* l = t + 4 * 2 * 16;
|
||||
|
||||
sp_digit* t1 = t + 33 * 2 * 16;
|
||||
sp_digit* c = t + 34 * 2 * 16;
|
||||
sp_digit* l = t + 35 * 2 * 16;
|
||||
|
||||
/* l = 1 / (c.x - p.x) */
|
||||
sp_1024_mont_sub_avx2_16(l, cx, px, p1024_mod);
|
||||
@ -104889,7 +105021,7 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table,
|
||||
sp_digit* t;
|
||||
sp_point_1024* pre_p;
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_point_1024 pre_p[16];
|
||||
sp_point_1024 pd;
|
||||
sp_point_1024 cd;
|
||||
@ -104926,8 +105058,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 6 * 16 * 2 + 16 * sizeof(sp_point_1024), NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 36 * 16 * 2 + 16 *
|
||||
sizeof(sp_point_1024), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
}
|
||||
@ -104938,7 +105070,7 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table,
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
pre_p = (sp_point_1024*)(td + 6 * 16 * 2);
|
||||
pre_p = (sp_point_1024*)(td + 36 * 16 * 2);
|
||||
#endif
|
||||
|
||||
sp_1024_point_from_ecc_point_16(p, pm);
|
||||
@ -104969,7 +105101,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table,
|
||||
XMEMCPY(c, &pre_p[j], sizeof(sp_point_1024));
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_avx2_16(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_avx2_16(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_avx2_16(c, c, t);
|
||||
sp_1024_mont_map_avx2_16(c, t);
|
||||
@ -104998,7 +105131,8 @@ static int sp_Pairing_gen_precomp_avx2_1024(const ecc_point* pm, byte* table,
|
||||
}
|
||||
|
||||
for (j = 0; j < sp_1024_order_op_pre[i + 1]; j++) {
|
||||
sp_1024_accum_dbl_calc_lc_avx2_16(precomp[k].x, precomp[k].y, c->x, c->y, t);
|
||||
sp_1024_accum_dbl_calc_lc_avx2_16(precomp[k].x, precomp[k].y, c->x,
|
||||
c->y, t);
|
||||
k++;
|
||||
sp_1024_proj_point_dbl_avx2_16(c, c, t);
|
||||
sp_1024_mont_map_avx2_16(c, t);
|
||||
@ -105053,7 +105187,7 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm
|
||||
sp_digit (*pre_vy)[32];
|
||||
sp_digit (*pre_nvy)[32];
|
||||
#else
|
||||
sp_digit t[6 * 2 * 16];
|
||||
sp_digit t[36 * 2 * 16];
|
||||
sp_digit vx[2 * 16];
|
||||
sp_digit vy[2 * 16];
|
||||
sp_digit pre_vx[16][32];
|
||||
@ -105089,7 +105223,7 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
if (err == MP_OKAY) {
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 56 * 16 * 2, NULL,
|
||||
td = (sp_digit*)XMALLOC(sizeof(sp_digit) * 86 * 16 * 2, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (td == NULL) {
|
||||
err = MEMORY_E;
|
||||
@ -105101,11 +105235,11 @@ static int sp_Pairing_precomp_avx2_1024(const ecc_point* pm, const ecc_point* qm
|
||||
#if (defined(WOLFSSL_SP_SMALL) || defined(WOLFSSL_SMALL_STACK)) && \
|
||||
!defined(WOLFSSL_SP_NO_MALLOC)
|
||||
t = td;
|
||||
vx = td + 6 * 16 * 2;
|
||||
vy = td + 7 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 8 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 24 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 40 * 16 * 2);
|
||||
vx = td + 36 * 16 * 2;
|
||||
vy = td + 37 * 16 * 2;
|
||||
pre_vx = (sp_digit(*)[32])(td + 38 * 16 * 2);
|
||||
pre_vy = (sp_digit(*)[32])(td + 54 * 16 * 2);
|
||||
pre_nvy = (sp_digit(*)[32])(td + 70 * 16 * 2);
|
||||
#endif
|
||||
r = vy;
|
||||
|
||||
|
@ -17507,11 +17507,13 @@ static int dh_ffdhe_test(WC_RNG *rng, int name)
|
||||
ERROR_OUT(-8057, done);
|
||||
}
|
||||
|
||||
#ifndef HAVE_SELFTEST
|
||||
ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
|
||||
if (ret != MP_VAL && ret != MP_EXPTMOD_E && ret != MP_CMP_E &&
|
||||
ret != ASYNC_OP_E) {
|
||||
ERROR_OUT(-8057, done);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Getting here means success - set ret to 0. */
|
||||
ret = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user