From 3e58c63647330e3f9a32d330914c438b0f3781e4 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Wed, 9 Nov 2022 11:43:13 +1000 Subject: [PATCH] SP P521 small HAVE_COMP_KEY: sp_521_mont_sqr_n* Specific compress key code for P521 doesn't need a n square function. Fixing generation of x86_64 ASM scripts resulted in adding carriage return to chacha_asm.S. --- wolfcrypt/src/chacha_asm.S | 1 + wolfcrypt/src/sp_arm32.c | 8 ++++---- wolfcrypt/src/sp_arm64.c | 8 ++++---- wolfcrypt/src/sp_armthumb.c | 8 ++++---- wolfcrypt/src/sp_c32.c | 8 ++++---- wolfcrypt/src/sp_c64.c | 8 ++++---- wolfcrypt/src/sp_cortexm.c | 8 ++++---- wolfcrypt/src/sp_x86_64.c | 16 ++++++++-------- 8 files changed, 33 insertions(+), 32 deletions(-) diff --git a/wolfcrypt/src/chacha_asm.S b/wolfcrypt/src/chacha_asm.S index 9ac1efeda..42a0971a9 100644 --- a/wolfcrypt/src/chacha_asm.S +++ b/wolfcrypt/src/chacha_asm.S @@ -18,6 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ + #ifdef WOLFSSL_USER_SETTINGS #ifdef WOLFSSL_USER_SETTINGS_ASM /* diff --git a/wolfcrypt/src/sp_arm32.c b/wolfcrypt/src/sp_arm32.c index c44616d55..963149a0d 100644 --- a/wolfcrypt/src/sp_arm32.c +++ b/wolfcrypt/src/sp_arm32.c @@ -69386,7 +69386,7 @@ static void sp_256_mont_sqr_n_8(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P256 curve. */ static const uint32_t p256_mod_minus_2[8] = { @@ -87597,7 +87597,7 @@ static void sp_384_mont_sqr_n_12(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P384 curve. */ static const uint32_t p384_mod_minus_2[12] = { @@ -114145,7 +114145,7 @@ SP_NOINLINE static void sp_521_mont_sqr_17(sp_digit* r, const sp_digit* a, sp_521_mont_reduce_17(r, m, mp); } -#if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY) +#ifndef WOLFSSL_SP_SMALL /* Square the Montgomery form number a number of times. (r = a ^ n mod m) * * r Result of squaring. @@ -114163,7 +114163,7 @@ static void sp_521_mont_sqr_n_17(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P521 curve. */ static const uint32_t p521_mod_minus_2[17] = { diff --git a/wolfcrypt/src/sp_arm64.c b/wolfcrypt/src/sp_arm64.c index d7c313383..5dfe63eb6 100644 --- a/wolfcrypt/src/sp_arm64.c +++ b/wolfcrypt/src/sp_arm64.c @@ -22645,7 +22645,7 @@ static void sp_256_mont_sqr_n_4(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P256 curve. */ static const uint64_t p256_mod_minus_2[4] = { @@ -43102,7 +43102,7 @@ static void sp_384_mont_sqr_n_6(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P384 curve. */ static const uint64_t p384_mod_minus_2[6] = { @@ -71148,7 +71148,7 @@ SP_NOINLINE static void sp_521_mont_sqr_9(sp_digit* r, const sp_digit* a, const ); } -#if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY) +#ifndef WOLFSSL_SP_SMALL /* Square the Montgomery form number a number of times. (r = a ^ n mod m) * * r Result of squaring. @@ -71166,7 +71166,7 @@ static void sp_521_mont_sqr_n_9(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P521 curve. */ static const uint64_t p521_mod_minus_2[9] = { diff --git a/wolfcrypt/src/sp_armthumb.c b/wolfcrypt/src/sp_armthumb.c index a56b47be5..01c892bf9 100644 --- a/wolfcrypt/src/sp_armthumb.c +++ b/wolfcrypt/src/sp_armthumb.c @@ -99062,7 +99062,7 @@ static void sp_256_mont_sqr_n_8(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P256 curve. */ static const uint32_t p256_mod_minus_2[8] = { @@ -110447,7 +110447,7 @@ static void sp_384_mont_sqr_n_12(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P384 curve. */ static const uint32_t p384_mod_minus_2[12] = { @@ -122727,7 +122727,7 @@ SP_NOINLINE static void sp_521_mont_sqr_17(sp_digit* r, const sp_digit* a, sp_521_mont_reduce_17(r, m, mp); } -#if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY) +#ifndef WOLFSSL_SP_SMALL /* Square the Montgomery form number a number of times. (r = a ^ n mod m) * * r Result of squaring. @@ -122745,7 +122745,7 @@ static void sp_521_mont_sqr_n_17(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P521 curve. */ static const uint32_t p521_mod_minus_2[17] = { diff --git a/wolfcrypt/src/sp_c32.c b/wolfcrypt/src/sp_c32.c index 846be62f6..a2f1b5e9f 100644 --- a/wolfcrypt/src/sp_c32.c +++ b/wolfcrypt/src/sp_c32.c @@ -20946,7 +20946,7 @@ static void sp_256_mont_sqr_n_9(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P256 curve. */ static const uint32_t p256_mod_minus_2[8] = { @@ -28328,7 +28328,7 @@ static void sp_384_mont_sqr_n_15(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P384 curve. */ static const uint32_t p384_mod_minus_2[12] = { @@ -35969,7 +35969,7 @@ SP_NOINLINE static void sp_521_mont_sqr_21(sp_digit* r, const sp_digit* a, sp_521_mont_reduce_21(r, m, mp); } -#if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY) +#ifndef WOLFSSL_SP_SMALL /* Square the Montgomery form number a number of times. (r = a ^ n mod m) * * r Result of squaring. @@ -35987,7 +35987,7 @@ static void sp_521_mont_sqr_n_21(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P521 curve. */ static const uint32_t p521_mod_minus_2[17] = { diff --git a/wolfcrypt/src/sp_c64.c b/wolfcrypt/src/sp_c64.c index 971543824..6630662e6 100644 --- a/wolfcrypt/src/sp_c64.c +++ b/wolfcrypt/src/sp_c64.c @@ -21934,7 +21934,7 @@ static void sp_256_mont_sqr_n_5(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P256 curve. */ static const uint64_t p256_mod_minus_2[4] = { @@ -28820,7 +28820,7 @@ static void sp_384_mont_sqr_n_7(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P384 curve. */ static const uint64_t p384_mod_minus_2[6] = { @@ -36318,7 +36318,7 @@ SP_NOINLINE static void sp_521_mont_sqr_9(sp_digit* r, const sp_digit* a, sp_521_mont_reduce_9(r, m, mp); } -#if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY) +#ifndef WOLFSSL_SP_SMALL /* Square the Montgomery form number a number of times. (r = a ^ n mod m) * * r Result of squaring. @@ -36336,7 +36336,7 @@ static void sp_521_mont_sqr_n_9(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P521 curve. */ static const uint64_t p521_mod_minus_2[9] = { diff --git a/wolfcrypt/src/sp_cortexm.c b/wolfcrypt/src/sp_cortexm.c index 5549a22bf..8e313c449 100644 --- a/wolfcrypt/src/sp_cortexm.c +++ b/wolfcrypt/src/sp_cortexm.c @@ -18359,7 +18359,7 @@ static void sp_256_mont_sqr_n_8(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P256 curve. */ static const uint32_t p256_mod_minus_2[8] = { @@ -26040,7 +26040,7 @@ static void sp_384_mont_sqr_n_12(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P384 curve. */ static const uint32_t p384_mod_minus_2[12] = { @@ -33528,7 +33528,7 @@ SP_NOINLINE static void sp_521_mont_sqr_17(sp_digit* r, const sp_digit* a, sp_521_mont_reduce_17(r, m, mp); } -#if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY) +#ifndef WOLFSSL_SP_SMALL /* Square the Montgomery form number a number of times. (r = a ^ n mod m) * * r Result of squaring. @@ -33546,7 +33546,7 @@ static void sp_521_mont_sqr_n_17(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P521 curve. */ static const uint32_t p521_mod_minus_2[17] = { diff --git a/wolfcrypt/src/sp_x86_64.c b/wolfcrypt/src/sp_x86_64.c index 67c8a23de..4b8bedcca 100644 --- a/wolfcrypt/src/sp_x86_64.c +++ b/wolfcrypt/src/sp_x86_64.c @@ -8351,7 +8351,7 @@ static void sp_256_mont_sqr_n_4(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P256 curve. */ static const uint64_t p256_mod_minus_2[4] = { @@ -9589,7 +9589,7 @@ static void sp_256_mont_sqr_n_avx2_4(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ /* Invert the number, in Montgomery form, modulo the modulus (prime) of the * P256 curve. (r = 1 / a mod m) @@ -27497,7 +27497,7 @@ static void sp_384_mont_sqr_n_6(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P384 curve. */ static const uint64_t p384_mod_minus_2[6] = { @@ -28760,7 +28760,7 @@ static void sp_384_mont_sqr_n_avx2_6(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL || HAVE_COMP_KEY */ /* Invert the number, in Montgomery form, modulo the modulus (prime) of the * P384 curve. (r = 1 / a mod m) @@ -52358,7 +52358,7 @@ extern void sp_521_mont_sqr_9(sp_digit* r, const sp_digit* a, const sp_digit* m, #ifdef __cplusplus } #endif -#if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY) +#ifndef WOLFSSL_SP_SMALL /* Square the Montgomery form number a number of times. (r = a ^ n mod m) * * r Result of squaring. @@ -52376,7 +52376,7 @@ static void sp_521_mont_sqr_n_9(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL */ #ifdef WOLFSSL_SP_SMALL /* Mod-2 for the P521 curve. */ static const uint64_t p521_mod_minus_2[9] = { @@ -53595,7 +53595,7 @@ extern void sp_521_mont_sqr_avx2_9(sp_digit* r, const sp_digit* a, const sp_digi #ifdef __cplusplus } #endif -#if !defined(WOLFSSL_SP_SMALL) || defined(HAVE_COMP_KEY) +#ifndef WOLFSSL_SP_SMALL /* Square the Montgomery form number a number of times. (r = a ^ n mod m) * * r Result of squaring. @@ -53613,7 +53613,7 @@ static void sp_521_mont_sqr_n_avx2_9(sp_digit* r, const sp_digit* a, int n, } } -#endif /* !WOLFSSL_SP_SMALL | HAVE_COMP_KEY */ +#endif /* !WOLFSSL_SP_SMALL */ /* Invert the number, in Montgomery form, modulo the modulus (prime) of the * P521 curve. (r = 1 / a mod m)