mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-29 18:27:29 +02:00
Small stack for fast math code
Any large stack usages have been changed to dynamic memory allocations when WOLFSSL_SMALL_STACK is defined. Modified functions to return error codes.
This commit is contained in:
@ -23,13 +23,26 @@
|
||||
|
||||
#ifdef TFM_SMALL_MONT_SET
|
||||
/* computes x/R == x (mod N) via Montgomery Reduction */
|
||||
void fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)
|
||||
int fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)
|
||||
{
|
||||
fp_digit c[FP_SIZE], *_c, *tmpm, mu, cy;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit c[FP_SIZE];
|
||||
#else
|
||||
fp_digit *c;
|
||||
#endif
|
||||
fp_digit *_c, *tmpm, mu, cy;
|
||||
int oldused, x, y, pa;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
/* only allocate space for what's needed for window plus res */
|
||||
c = (fp_digit*)XMALLOC(sizeof(fp_digit)*FP_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (c == NULL) {
|
||||
return FP_MEM;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* now zero the buff */
|
||||
XMEMSET(c, 0, sizeof(c));
|
||||
XMEMSET(c, 0, sizeof(fp_digit)*(FP_SIZE));
|
||||
|
||||
pa = m->used;
|
||||
|
||||
@ -3851,6 +3864,11 @@ void fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)
|
||||
if (fp_cmp_mag (a, m) != FP_LT) {
|
||||
s_fp_sub (a, m, a);
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(c, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL12
|
||||
void fp_mul_comba12(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba12(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[24];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[24];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 24, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 12 * sizeof(fp_digit));
|
||||
XMEMCPY(at+12, B->dp, 12 * sizeof(fp_digit));
|
||||
@ -127,5 +138,10 @@ void fp_mul_comba12(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL17
|
||||
void fp_mul_comba17(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba17(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[34];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[34];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 34, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 17 * sizeof(fp_digit));
|
||||
XMEMCPY(at+17, B->dp, 17 * sizeof(fp_digit));
|
||||
@ -167,5 +178,10 @@ void fp_mul_comba17(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -21,10 +21,21 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL20
|
||||
void fp_mul_comba20(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba20(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[40];
|
||||
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[40];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 40, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 20 * sizeof(fp_digit));
|
||||
XMEMCPY(at+20, B->dp, 20 * sizeof(fp_digit));
|
||||
COMBA_START;
|
||||
@ -190,5 +201,10 @@ void fp_mul_comba20(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL24
|
||||
void fp_mul_comba24(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba24(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[48];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[48];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 48, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 24 * sizeof(fp_digit));
|
||||
XMEMCPY(at+24, B->dp, 24 * sizeof(fp_digit));
|
||||
@ -223,5 +234,10 @@ void fp_mul_comba24(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL28
|
||||
void fp_mul_comba28(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba28(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[56];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[56];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 56, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 28 * sizeof(fp_digit));
|
||||
XMEMCPY(at+28, B->dp, 28 * sizeof(fp_digit));
|
||||
@ -255,5 +266,10 @@ void fp_mul_comba28(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL3
|
||||
void fp_mul_comba3(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba3(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[6];
|
||||
|
||||
@ -55,5 +55,7 @@ void fp_mul_comba3(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,10 +22,21 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL32
|
||||
void fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[64];
|
||||
int out_size;
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[64];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 64, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
out_size = A->used + B->used;
|
||||
XMEMCPY(at, A->dp, 32 * sizeof(fp_digit));
|
||||
@ -190,7 +201,7 @@ void fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C)
|
||||
COMBA_STORE(C->dp[38]);
|
||||
|
||||
/* early out at 40 digits, 40*32==1280, or two 640 bit operands */
|
||||
if (out_size <= 40) { COMBA_STORE2(C->dp[39]); C->used = 40; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
|
||||
if (out_size <= 40) { COMBA_STORE2(C->dp[39]); C->used = 40; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return FP_OKAY; }
|
||||
|
||||
/* 39 */
|
||||
COMBA_FORWARD;
|
||||
@ -226,7 +237,7 @@ void fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C)
|
||||
COMBA_STORE(C->dp[46]);
|
||||
|
||||
/* early out at 48 digits, 48*32==1536, or two 768 bit operands */
|
||||
if (out_size <= 48) { COMBA_STORE2(C->dp[47]); C->used = 48; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
|
||||
if (out_size <= 48) { COMBA_STORE2(C->dp[47]); C->used = 48; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return FP_OKAY; }
|
||||
|
||||
/* 47 */
|
||||
COMBA_FORWARD;
|
||||
@ -262,7 +273,7 @@ void fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C)
|
||||
COMBA_STORE(C->dp[54]);
|
||||
|
||||
/* early out at 56 digits, 56*32==1792, or two 896 bit operands */
|
||||
if (out_size <= 56) { COMBA_STORE2(C->dp[55]); C->used = 56; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
|
||||
if (out_size <= 56) { COMBA_STORE2(C->dp[55]); C->used = 56; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return FP_OKAY; }
|
||||
|
||||
/* 55 */
|
||||
COMBA_FORWARD;
|
||||
@ -301,5 +312,10 @@ void fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL4
|
||||
void fp_mul_comba4(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba4(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[8];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[8];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 8, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 4 * sizeof(fp_digit));
|
||||
XMEMCPY(at+4, B->dp, 4 * sizeof(fp_digit));
|
||||
@ -63,5 +74,10 @@ void fp_mul_comba4(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL48
|
||||
void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[96];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[96];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 96, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 48 * sizeof(fp_digit));
|
||||
XMEMCPY(at+48, B->dp, 48 * sizeof(fp_digit));
|
||||
@ -415,5 +426,10 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL6
|
||||
void fp_mul_comba6(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba6(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[12];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[12];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 12, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 6 * sizeof(fp_digit));
|
||||
XMEMCPY(at+6, B->dp, 6 * sizeof(fp_digit));
|
||||
@ -79,5 +90,10 @@ void fp_mul_comba6(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL64
|
||||
void fp_mul_comba64(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba64(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[128];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[128];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 128, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 64 * sizeof(fp_digit));
|
||||
XMEMCPY(at+64, B->dp, 64 * sizeof(fp_digit));
|
||||
@ -543,5 +554,10 @@ void fp_mul_comba64(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL7
|
||||
void fp_mul_comba7(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba7(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[14];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[14];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 14, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 7 * sizeof(fp_digit));
|
||||
XMEMCPY(at+7, B->dp, 7 * sizeof(fp_digit));
|
||||
@ -87,5 +98,10 @@ void fp_mul_comba7(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#ennif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL8
|
||||
void fp_mul_comba8(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba8(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[16];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[16];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 16, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 8 * sizeof(fp_digit));
|
||||
XMEMCPY(at+8, B->dp, 8 * sizeof(fp_digit));
|
||||
@ -95,5 +106,10 @@ void fp_mul_comba8(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,20 @@
|
||||
|
||||
|
||||
#ifdef TFM_MUL9
|
||||
void fp_mul_comba9(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba9(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[18];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[18];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 18, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
XMEMCPY(at, A->dp, 9 * sizeof(fp_digit));
|
||||
XMEMCPY(at+9, B->dp, 9 * sizeof(fp_digit));
|
||||
@ -103,5 +114,10 @@ void fp_mul_comba9(fp_int *A, fp_int *B, fp_int *C)
|
||||
C->sign = A->sign ^ B->sign;
|
||||
fp_clamp(C);
|
||||
COMBA_FINI;
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,21 @@
|
||||
|
||||
|
||||
#if defined(TFM_SMALL_SET)
|
||||
void fp_mul_comba_small(fp_int *A, fp_int *B, fp_int *C)
|
||||
int fp_mul_comba_small(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
fp_digit c0, c1, c2, at[32];
|
||||
fp_digit c0, c1, c2;
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit at[32];
|
||||
#else
|
||||
fp_digit *at;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 32, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (at == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
switch (MAX(A->used, B->used)) {
|
||||
|
||||
case 1:
|
||||
@ -1246,6 +1258,11 @@ void fp_mul_comba_small(fp_int *A, fp_int *B, fp_int *C)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -22,12 +22,24 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR12
|
||||
void fp_sqr_comba12(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba12(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[24], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[24];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 24, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
|
||||
@ -154,6 +166,11 @@ void fp_sqr_comba12(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 24 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR17
|
||||
void fp_sqr_comba17(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba17(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[34], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[34];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 34, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -205,6 +216,11 @@ void fp_sqr_comba17(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 34 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR20
|
||||
void fp_sqr_comba20(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba20(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[40], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[40];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 40, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -235,6 +246,11 @@ void fp_sqr_comba20(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 40 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR24
|
||||
void fp_sqr_comba24(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba24(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[48], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[48];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 48, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -275,6 +286,11 @@ void fp_sqr_comba24(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 48 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR28
|
||||
void fp_sqr_comba28(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba28(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[56], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[56];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 56, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -315,6 +326,11 @@ void fp_sqr_comba28(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 56 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR3
|
||||
void fp_sqr_comba3(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba3(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[6], c0, c1, c2;
|
||||
#ifdef TFM_ISO
|
||||
@ -65,6 +65,8 @@ void fp_sqr_comba3(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 6 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR32
|
||||
void fp_sqr_comba32(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba32(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[64], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[64];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 64, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -355,6 +366,11 @@ void fp_sqr_comba32(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 64 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR4
|
||||
void fp_sqr_comba4(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba4(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[8], c0, c1, c2;
|
||||
fp_digit *a, c0, c1, c2;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[8];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 8, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -75,6 +86,11 @@ void fp_sqr_comba4(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 8 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR48
|
||||
void fp_sqr_comba48(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba48(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[96], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[96];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 96, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -515,6 +526,11 @@ void fp_sqr_comba48(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 96 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR6
|
||||
void fp_sqr_comba6(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba6(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[12], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[12];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 12, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -95,6 +106,11 @@ void fp_sqr_comba6(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 12 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR64
|
||||
void fp_sqr_comba64(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba64(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[128], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[128];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 128, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -675,6 +686,11 @@ void fp_sqr_comba64(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 128 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR7
|
||||
void fp_sqr_comba7(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba7(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[14], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[14];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 14, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -105,6 +116,11 @@ void fp_sqr_comba7(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 14 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR8
|
||||
void fp_sqr_comba8(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba8(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[16], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[16];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 16, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -115,6 +126,11 @@ void fp_sqr_comba8(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 16 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,23 @@
|
||||
|
||||
|
||||
#ifdef TFM_SQR9
|
||||
void fp_sqr_comba9(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba9(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[18], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[18];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 18, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
a = A->dp;
|
||||
COMBA_START;
|
||||
@ -125,6 +136,11 @@ void fp_sqr_comba9(fp_int *A, fp_int *B)
|
||||
B->sign = FP_ZPOS;
|
||||
XMEMCPY(B->dp, b, 18 * sizeof(fp_digit));
|
||||
fp_clamp(B);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -22,12 +22,24 @@
|
||||
|
||||
|
||||
#if defined(TFM_SMALL_SET)
|
||||
void fp_sqr_comba_small(fp_int *A, fp_int *B)
|
||||
int fp_sqr_comba_small(fp_int *A, fp_int *B)
|
||||
{
|
||||
fp_digit *a, b[32], c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
fp_digit *a, c0, c1, c2, sc0 = 0, sc1 = 0, sc2 = 0;
|
||||
#ifdef TFM_ISO
|
||||
fp_word tt;
|
||||
#endif
|
||||
fp_word tt;
|
||||
#endif
|
||||
#ifndef WOLFSSL_SMALL_STACK
|
||||
fp_digit b[32];
|
||||
#else
|
||||
fp_digit *b;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
b = (fp_digit*)XMALLOC(sizeof(fp_digit) * 32, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (b == NULL)
|
||||
return FP_MEM;
|
||||
#endif
|
||||
|
||||
switch (A->used) {
|
||||
case 1:
|
||||
a = A->dp;
|
||||
@ -1535,7 +1547,12 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return FP_OKAY;
|
||||
}
|
||||
|
||||
#endif /* TFM_SMALL_SET */
|
||||
|
1417
wolfcrypt/src/tfm.c
1417
wolfcrypt/src/tfm.c
File diff suppressed because it is too large
Load Diff
@ -467,10 +467,10 @@ void fp_add(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_sub(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* c = a * b */
|
||||
void fp_mul(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* b = a*a */
|
||||
void fp_sqr(fp_int *a, fp_int *b);
|
||||
int fp_sqr(fp_int *a, fp_int *b);
|
||||
|
||||
/* a/b => cb + d == a */
|
||||
int fp_div(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||
@ -485,7 +485,7 @@ int fp_cmp_d(fp_int *a, fp_digit b);
|
||||
void fp_add_d(fp_int *a, fp_digit b, fp_int *c);
|
||||
|
||||
/* c = a - b */
|
||||
void fp_sub_d(fp_int *a, fp_digit b, fp_int *c);
|
||||
int fp_sub_d(fp_int *a, fp_digit b, fp_int *c);
|
||||
|
||||
/* c = a * b */
|
||||
void fp_mul_d(fp_int *a, fp_digit b, fp_int *c);
|
||||
@ -519,10 +519,10 @@ int fp_sqrmod(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_invmod(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
/* c = (a, b) */
|
||||
/*void fp_gcd(fp_int *a, fp_int *b, fp_int *c);*/
|
||||
/*int fp_gcd(fp_int *a, fp_int *b, fp_int *c);*/
|
||||
|
||||
/* c = [a, b] */
|
||||
/*void fp_lcm(fp_int *a, fp_int *b, fp_int *c);*/
|
||||
/*int fp_lcm(fp_int *a, fp_int *b, fp_int *c);*/
|
||||
|
||||
/* setups the montgomery reduction */
|
||||
int fp_montgomery_setup(fp_int *a, fp_digit *mp);
|
||||
@ -533,7 +533,7 @@ int fp_montgomery_setup(fp_int *a, fp_digit *mp);
|
||||
void fp_montgomery_calc_normalization(fp_int *a, fp_int *b);
|
||||
|
||||
/* computes x/R == x (mod N) via Montgomery Reduction */
|
||||
void fp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp);
|
||||
int fp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp);
|
||||
|
||||
/* d = a**b (mod c) */
|
||||
int fp_exptmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||
@ -547,7 +547,7 @@ int fp_exptmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||
/* 256 trial divisions + 8 Miller-Rabins, returns FP_YES if probable prime */
|
||||
/*int fp_isprime(fp_int *a);*/
|
||||
/* extended version of fp_isprime, do 't' Miller-Rabins instead of only 8 */
|
||||
/*int fp_isprime_ex(fp_int *a, int t);*/
|
||||
/*int fp_isprime_ex(fp_int *a, int t, int* result);*/
|
||||
|
||||
/* Primality generation flags */
|
||||
/*#define TFM_PRIME_BBS 0x0001 */ /* BBS style prime */
|
||||
@ -568,7 +568,7 @@ int fp_leading_bit(fp_int *a);
|
||||
|
||||
int fp_unsigned_bin_size(fp_int *a);
|
||||
void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c);
|
||||
void fp_to_unsigned_bin(fp_int *a, unsigned char *b);
|
||||
int fp_to_unsigned_bin(fp_int *a, unsigned char *b);
|
||||
int fp_to_unsigned_bin_at_pos(int x, fp_int *t, unsigned char *b);
|
||||
|
||||
/*int fp_signed_bin_size(fp_int *a);*/
|
||||
@ -585,39 +585,39 @@ void s_fp_add(fp_int *a, fp_int *b, fp_int *c);
|
||||
void s_fp_sub(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_reverse(unsigned char *s, int len);
|
||||
|
||||
void fp_mul_comba(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba(fp_int *a, fp_int *b, fp_int *c);
|
||||
|
||||
void fp_mul_comba_small(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba3(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba4(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba6(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba7(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba8(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba9(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba12(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba17(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba20(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba24(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba28(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba32(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba48(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_mul_comba64(fp_int *a, fp_int *b, fp_int *c);
|
||||
void fp_sqr_comba(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba_small(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba3(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba4(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba6(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba7(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba8(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba9(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba12(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba17(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba20(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba24(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba28(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba32(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba48(fp_int *a, fp_int *b);
|
||||
void fp_sqr_comba64(fp_int *a, fp_int *b);
|
||||
int fp_mul_comba_small(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba3(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba4(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba6(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba7(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba8(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba9(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba12(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba17(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba20(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba24(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba28(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba32(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba48(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_mul_comba64(fp_int *a, fp_int *b, fp_int *c);
|
||||
int fp_sqr_comba(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba_small(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba3(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba4(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba6(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba7(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba8(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba9(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba12(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba17(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba20(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba24(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba28(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba32(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba48(fp_int *a, fp_int *b);
|
||||
int fp_sqr_comba64(fp_int *a, fp_int *b);
|
||||
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user