Browse Source

SP C, SP int: improve performance

In SP C: Improve performance of large digit mul and sqr.
In SP int: include optimized 16 digit mul and sqr when compiling SAKKE.
Sean Parkinson 1 year ago
parent
commit
22141faf16
3 changed files with 1077 additions and 1025 deletions
  1. 509 497
      wolfcrypt/src/sp_c32.c
  2. 544 524
      wolfcrypt/src/sp_c64.c
  3. 24 4
      wolfcrypt/src/sp_int.c

File diff suppressed because it is too large
+ 509 - 497
wolfcrypt/src/sp_c32.c


File diff suppressed because it is too large
+ 544 - 524
wolfcrypt/src/sp_c64.c


+ 24 - 4
wolfcrypt/src/sp_int.c

@@ -9193,7 +9193,9 @@ static int _sp_mul_12(const sp_int* a, const sp_int* b, sp_int* r)
 #endif /* SP_WORD_SIZE == 32 */
 #endif /* !WOLFSSL_HAVE_SP_ECC && HAVE_ECC */
 
-#if defined(SQR_MUL_ASM) && defined(WOLFSSL_SP_INT_LARGE_COMBA)
+#if defined(SQR_MUL_ASM) && (defined(WOLFSSL_SP_INT_LARGE_COMBA) || \
+    (!defined(WOLFSSL_SP_MATH) && defined(WOLFCRYPT_HAVE_SAKKE) && \
+    (SP_WORD_SIZE == 64)))
     #if SP_INT_DIGITS >= 32
 /* Multiply a by b and store in r: r = a * b
  *
@@ -9614,7 +9616,10 @@ static int _sp_mul_16(const sp_int* a, const sp_int* b, sp_int* r)
     return err;
 }
     #endif /* SP_INT_DIGITS >= 32 */
+#endif /* SQR_MUL_ASM && (WOLFSSL_SP_INT_LARGE_COMBA || !WOLFSSL_SP_MATH &&
+        * WOLFCRYPT_HAVE_SAKKE && SP_WORD_SIZE == 64 */
 
+#if defined(SQR_MUL_ASM) && defined(WOLFSSL_SP_INT_LARGE_COMBA)
     #if SP_INT_DIGITS >= 48
 /* Multiply a by b and store in r: r = a * b
  *
@@ -11163,13 +11168,18 @@ int sp_mul(const sp_int* a, const sp_int* b, sp_int* r)
 #endif /* SQR_MUL_ASM */
 #endif /* SP_WORD_SIZE == 32 */
 #endif /* !WOLFSSL_HAVE_SP_ECC && HAVE_ECC */
-#if defined(SQR_MUL_ASM) && defined(WOLFSSL_SP_INT_LARGE_COMBA)
+#if defined(SQR_MUL_ASM) && (defined(WOLFSSL_SP_INT_LARGE_COMBA) || \
+    (!defined(WOLFSSL_SP_MATH) && defined(WOLFCRYPT_HAVE_SAKKE) && \
+    (SP_WORD_SIZE == 64)))
     #if SP_INT_DIGITS >= 32
         if ((a->used == 16) && (b->used == 16)) {
             err = _sp_mul_16(a, b, r);
         }
         else
     #endif /* SP_INT_DIGITS >= 32 */
+#endif /* SQR_MUL_ASM && (WOLFSSL_SP_INT_LARGE_COMBA || !WOLFSSL_SP_MATH &&
+        * WOLFCRYPT_HAVE_SAKKE && SP_WORD_SIZE == 64 */
+#if defined(SQR_MUL_ASM) && defined(WOLFSSL_SP_INT_LARGE_COMBA)
     #if SP_INT_DIGITS >= 48
         if ((a->used == 24) && (b->used == 24)) {
             err = _sp_mul_24(a, b, r);
@@ -14374,7 +14384,9 @@ static int _sp_sqr_12(const sp_int* a, sp_int* r)
 #endif /* SP_WORD_SIZE == 32 */
 #endif /* !WOLFSSL_HAVE_SP_ECC && HAVE_ECC */
 
-#if defined(SQR_MUL_ASM) && defined(WOLFSSL_SP_INT_LARGE_COMBA)
+#if defined(SQR_MUL_ASM) && (defined(WOLFSSL_SP_INT_LARGE_COMBA) || \
+    (!defined(WOLFSSL_SP_MATH) && defined(WOLFCRYPT_HAVE_SAKKE) && \
+    (SP_WORD_SIZE == 64)))
     #if SP_INT_DIGITS >= 32
 /* Square a and store in r. r = a * a
  *
@@ -14702,7 +14714,10 @@ static int _sp_sqr_16(const sp_int* a, sp_int* r)
     return err;
 }
     #endif /* SP_INT_DIGITS >= 32 */
+#endif /* SQR_MUL_ASM && (WOLFSSL_SP_INT_LARGE_COMBA || !WOLFSSL_SP_MATH &&
+        * WOLFCRYPT_HAVE_SAKKE && SP_WORD_SIZE == 64 */
 
+#if defined(SQR_MUL_ASM) && defined(WOLFSSL_SP_INT_LARGE_COMBA)
     #if SP_INT_DIGITS >= 48
 /* Square a and store in r. r = a * a
  *
@@ -15903,13 +15918,18 @@ int sp_sqr(const sp_int* a, sp_int* r)
 #endif /* SQR_MUL_ASM */
 #endif /* SP_WORD_SIZE == 32 */
 #endif /* !WOLFSSL_HAVE_SP_ECC && HAVE_ECC */
-#if defined(SQR_MUL_ASM) && defined(WOLFSSL_SP_INT_LARGE_COMBA)
+#if defined(SQR_MUL_ASM) && (defined(WOLFSSL_SP_INT_LARGE_COMBA) || \
+    (!defined(WOLFSSL_SP_MATH) && defined(WOLFCRYPT_HAVE_SAKKE) && \
+    (SP_WORD_SIZE == 64)))
     #if SP_INT_DIGITS >= 32
         if (a->used == 16) {
             err = _sp_sqr_16(a, r);
         }
         else
     #endif /* SP_INT_DIGITS >= 32 */
+#endif /* SQR_MUL_ASM && (WOLFSSL_SP_INT_LARGE_COMBA || !WOLFSSL_SP_MATH &&
+        * WOLFCRYPT_HAVE_SAKKE && SP_WORD_SIZE == 64 */
+#if defined(SQR_MUL_ASM) && defined(WOLFSSL_SP_INT_LARGE_COMBA)
     #if SP_INT_DIGITS >= 48
         if (a->used == 24) {
             err = _sp_sqr_24(a, r);

Some files were not shown because too many files changed in this diff