summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Source/WolfSSL/wolfcrypt/src/fp_sqr_comba_small_set.i
diff options
context:
space:
mode:
Diffstat (limited to 'FreeRTOS-Plus/Source/WolfSSL/wolfcrypt/src/fp_sqr_comba_small_set.i')
-rw-r--r--FreeRTOS-Plus/Source/WolfSSL/wolfcrypt/src/fp_sqr_comba_small_set.i66
1 files changed, 42 insertions, 24 deletions
diff --git a/FreeRTOS-Plus/Source/WolfSSL/wolfcrypt/src/fp_sqr_comba_small_set.i b/FreeRTOS-Plus/Source/WolfSSL/wolfcrypt/src/fp_sqr_comba_small_set.i
index 9918b2ee8..a81ee10e2 100644
--- a/FreeRTOS-Plus/Source/WolfSSL/wolfcrypt/src/fp_sqr_comba_small_set.i
+++ b/FreeRTOS-Plus/Source/WolfSSL/wolfcrypt/src/fp_sqr_comba_small_set.i
@@ -1,8 +1,8 @@
/* fp_sqr_comba_small_set.i
*
- * Copyright (C) 2006-2015 wolfSSL Inc.
+ * Copyright (C) 2006-2020 wolfSSL Inc.
*
- * This file is part of wolfSSL. (formerly known as CyaSSL)
+ * This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,17 +16,30 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
+
#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, sc1, sc2;
+ 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;
@@ -43,7 +56,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 2;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 2 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 2 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -72,7 +85,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 4;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 4 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 4 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -111,7 +124,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 6;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 6 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 6 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -160,7 +173,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 8;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 8 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 8 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -219,7 +232,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 10;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 10 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 10 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -288,7 +301,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 12;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 12 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 12 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -367,7 +380,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 14;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 14 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 14 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -456,7 +469,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 16;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 16 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 16 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -555,7 +568,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 18;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 18 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 18 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -664,7 +677,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 20;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 20 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 20 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -783,7 +796,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 22;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 22 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 22 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -912,7 +925,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 24;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 24 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 24 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -1051,7 +1064,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 26;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 26 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 26 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -1200,7 +1213,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 28;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 28 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 28 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -1359,7 +1372,7 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 30;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 30 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 30 * sizeof(fp_digit));
fp_clamp(B);
break;
@@ -1528,13 +1541,18 @@ void fp_sqr_comba_small(fp_int *A, fp_int *B)
B->used = 32;
B->sign = FP_ZPOS;
- memcpy(B->dp, b, 32 * sizeof(fp_digit));
+ XMEMCPY(B->dp, b, 32 * sizeof(fp_digit));
fp_clamp(B);
break;
default:
break;
-}
+ }
+
+#ifdef WOLFSSL_SMALL_STACK
+ XFREE(b, NULL, DYNAMIC_TYPE_TMP_BUFFER);
+#endif
+ return FP_OKAY;
}
#endif /* TFM_SMALL_SET */