From e3ced9f9ae96e4d887221e9673f5486af901a5f9 Mon Sep 17 00:00:00 2001 From: Hayden Roche Date: Tue, 18 Oct 2022 09:20:06 -0700 Subject: [PATCH] Make some improvements to user_settings_asm.h. For the CMake and autotools flows, enabling user_settings.h will define the macro WOLFSSL_USER_SETTINGS_ASM. This will cause the generated user_settings_asm.h to be included in the .S assembly files. If the user is building without autotools or CMake, these files will include user_settings.h directly, unless WOLFSSL_USER_SETTINGS_ASM is defined. --- CMakeLists.txt | 3 ++- configure.ac | 21 +++++++++++---------- wolfcrypt/src/aes_gcm_asm.S | 17 ++++++++++++++++- wolfcrypt/src/chacha_asm.S | 18 ++++++++++++++++-- wolfcrypt/src/fe_x25519_asm.S | 17 ++++++++++++++++- wolfcrypt/src/poly1305_asm.S | 17 ++++++++++++++++- wolfcrypt/src/sha256_asm.S | 17 ++++++++++++++++- wolfcrypt/src/sha3_asm.S | 17 ++++++++++++++++- wolfcrypt/src/sha512_asm.S | 17 ++++++++++++++++- wolfcrypt/src/sp_x86_64_asm.S | 17 ++++++++++++++++- 10 files changed, 141 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6724d03dd..121fffff9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1796,7 +1796,8 @@ generate_build_flags() # USER SETTINGS if(WOLFSSL_USER_SETTINGS) # Replace all options and just use WOLFSSL_USER_SETTINGS - set(WOLFSSL_DEFINITIONS "-DWOLFSSL_USER_SETTINGS") + set(WOLFSSL_DEFINITIONS "-DWOLFSSL_USER_SETTINGS + -DWOLFSSL_USER_SETTINGS_ASM") # Create user_settings_asm.h for use in assembly files (e.g. .S files). execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/user_settings_asm.sh diff --git a/configure.ac b/configure.ac index d401392e8..f9885b633 100644 --- a/configure.ac +++ b/configure.ac @@ -7965,9 +7965,17 @@ fi # USER SETTINGS if test "x$ENABLED_USERSETTINGS" = "xyes" then - # Replace all options and just use WOLFSSL_USER_SETTINGS - AM_CFLAGS="-DWOLFSSL_USER_SETTINGS" - AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_USER_SETTINGS" + # Replace all options and just use WOLFSSL_USER_SETTINGS and + # WOLFSSL_USER_SETTINGS_ASM. + AM_CFLAGS="-DWOLFSSL_USER_SETTINGS -DWOLFSSL_USER_SETTINGS_ASM" + AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_USER_SETTINGS -DWOLFSSL_USER_SETTINGS_ASM" + + # Generate assembly-safe user_settings_asm.h (just preprocessor directives + # from user_settings.h). + $srcdir/scripts/user_settings_asm.sh "$CPPFLAGS $CFLAGS $CXXFLAGS" + if test $? -ne 0; then + AC_MSG_ERROR([$srcdir/scripts/user_settings_asm.sh failed.]) + fi fi # OPTIMIZE FLAGS @@ -8437,13 +8445,6 @@ esac rm cyassl/options.h.bak -if test "x$ENABLED_USERSETTINGS" = "xyes"; then - $srcdir/scripts/user_settings_asm.sh "$CPPFLAGS $CFLAGS $CXXFLAGS" - if test $? -ne 0; then - AC_MSG_ERROR([$srcdir/scripts/user_settings_asm.sh failed.]) - fi -fi - if test "$silent" != "yes"; then # output config summary diff --git a/wolfcrypt/src/aes_gcm_asm.S b/wolfcrypt/src/aes_gcm_asm.S index d217597e7..3fcf89fe5 100644 --- a/wolfcrypt/src/aes_gcm_asm.S +++ b/wolfcrypt/src/aes_gcm_asm.S @@ -20,8 +20,23 @@ */ #ifdef WOLFSSL_USER_SETTINGS +#ifdef WOLFSSL_USER_SETTINGS_ASM +/* + * user_settings_asm.h is a file generated by the script user_settings_asm.sh. + * The script takes in a user_settings.h and produces user_settings_asm.h, which + * is a stripped down version of user_settings.h containing only preprocessor + * directives. This makes the header safe to include in assembly (.S) files. + */ #include "user_settings_asm.h" -#endif +#else +/* + * Note: if user_settings.h contains any C code (e.g. a typedef or function + * prototype), including it here in an assembly (.S) file will cause an + * assembler failure. See user_settings_asm.h above. + */ +#include "user_settings.h" +#endif /* WOLFSSL_USER_SETTINGS_ASM */ +#endif /* WOLFSSL_USER_SETTINGS */ #ifndef HAVE_INTEL_AVX1 #define HAVE_INTEL_AVX1 diff --git a/wolfcrypt/src/chacha_asm.S b/wolfcrypt/src/chacha_asm.S index 49fb1ec3e..9ac1efeda 100644 --- a/wolfcrypt/src/chacha_asm.S +++ b/wolfcrypt/src/chacha_asm.S @@ -18,10 +18,24 @@ * 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 +/* + * user_settings_asm.h is a file generated by the script user_settings_asm.sh. + * The script takes in a user_settings.h and produces user_settings_asm.h, which + * is a stripped down version of user_settings.h containing only preprocessor + * directives. This makes the header safe to include in assembly (.S) files. + */ #include "user_settings_asm.h" -#endif +#else +/* + * Note: if user_settings.h contains any C code (e.g. a typedef or function + * prototype), including it here in an assembly (.S) file will cause an + * assembler failure. See user_settings_asm.h above. + */ +#include "user_settings.h" +#endif /* WOLFSSL_USER_SETTINGS_ASM */ +#endif /* WOLFSSL_USER_SETTINGS */ #ifndef HAVE_INTEL_AVX1 #define HAVE_INTEL_AVX1 diff --git a/wolfcrypt/src/fe_x25519_asm.S b/wolfcrypt/src/fe_x25519_asm.S index 6ff99d3e1..6ddaa176a 100644 --- a/wolfcrypt/src/fe_x25519_asm.S +++ b/wolfcrypt/src/fe_x25519_asm.S @@ -20,8 +20,23 @@ */ #ifdef WOLFSSL_USER_SETTINGS +#ifdef WOLFSSL_USER_SETTINGS_ASM +/* + * user_settings_asm.h is a file generated by the script user_settings_asm.sh. + * The script takes in a user_settings.h and produces user_settings_asm.h, which + * is a stripped down version of user_settings.h containing only preprocessor + * directives. This makes the header safe to include in assembly (.S) files. + */ #include "user_settings_asm.h" -#endif +#else +/* + * Note: if user_settings.h contains any C code (e.g. a typedef or function + * prototype), including it here in an assembly (.S) file will cause an + * assembler failure. See user_settings_asm.h above. + */ +#include "user_settings.h" +#endif /* WOLFSSL_USER_SETTINGS_ASM */ +#endif /* WOLFSSL_USER_SETTINGS */ #ifndef HAVE_INTEL_AVX1 #define HAVE_INTEL_AVX1 diff --git a/wolfcrypt/src/poly1305_asm.S b/wolfcrypt/src/poly1305_asm.S index b0dcbe660..a6980fb5e 100644 --- a/wolfcrypt/src/poly1305_asm.S +++ b/wolfcrypt/src/poly1305_asm.S @@ -20,8 +20,23 @@ */ #ifdef WOLFSSL_USER_SETTINGS +#ifdef WOLFSSL_USER_SETTINGS_ASM +/* + * user_settings_asm.h is a file generated by the script user_settings_asm.sh. + * The script takes in a user_settings.h and produces user_settings_asm.h, which + * is a stripped down version of user_settings.h containing only preprocessor + * directives. This makes the header safe to include in assembly (.S) files. + */ #include "user_settings_asm.h" -#endif +#else +/* + * Note: if user_settings.h contains any C code (e.g. a typedef or function + * prototype), including it here in an assembly (.S) file will cause an + * assembler failure. See user_settings_asm.h above. + */ +#include "user_settings.h" +#endif /* WOLFSSL_USER_SETTINGS_ASM */ +#endif /* WOLFSSL_USER_SETTINGS */ #ifndef HAVE_INTEL_AVX1 #define HAVE_INTEL_AVX1 diff --git a/wolfcrypt/src/sha256_asm.S b/wolfcrypt/src/sha256_asm.S index 402e6eac1..3070ca3eb 100644 --- a/wolfcrypt/src/sha256_asm.S +++ b/wolfcrypt/src/sha256_asm.S @@ -20,8 +20,23 @@ */ #ifdef WOLFSSL_USER_SETTINGS +#ifdef WOLFSSL_USER_SETTINGS_ASM +/* + * user_settings_asm.h is a file generated by the script user_settings_asm.sh. + * The script takes in a user_settings.h and produces user_settings_asm.h, which + * is a stripped down version of user_settings.h containing only preprocessor + * directives. This makes the header safe to include in assembly (.S) files. + */ #include "user_settings_asm.h" -#endif +#else +/* + * Note: if user_settings.h contains any C code (e.g. a typedef or function + * prototype), including it here in an assembly (.S) file will cause an + * assembler failure. See user_settings_asm.h above. + */ +#include "user_settings.h" +#endif /* WOLFSSL_USER_SETTINGS_ASM */ +#endif /* WOLFSSL_USER_SETTINGS */ #ifndef HAVE_INTEL_AVX1 #define HAVE_INTEL_AVX1 diff --git a/wolfcrypt/src/sha3_asm.S b/wolfcrypt/src/sha3_asm.S index aa18be68d..761d206b6 100644 --- a/wolfcrypt/src/sha3_asm.S +++ b/wolfcrypt/src/sha3_asm.S @@ -20,8 +20,23 @@ */ #ifdef WOLFSSL_USER_SETTINGS +#ifdef WOLFSSL_USER_SETTINGS_ASM +/* + * user_settings_asm.h is a file generated by the script user_settings_asm.sh. + * The script takes in a user_settings.h and produces user_settings_asm.h, which + * is a stripped down version of user_settings.h containing only preprocessor + * directives. This makes the header safe to include in assembly (.S) files. + */ #include "user_settings_asm.h" -#endif +#else +/* + * Note: if user_settings.h contains any C code (e.g. a typedef or function + * prototype), including it here in an assembly (.S) file will cause an + * assembler failure. See user_settings_asm.h above. + */ +#include "user_settings.h" +#endif /* WOLFSSL_USER_SETTINGS_ASM */ +#endif /* WOLFSSL_USER_SETTINGS */ #ifndef HAVE_INTEL_AVX1 #define HAVE_INTEL_AVX1 diff --git a/wolfcrypt/src/sha512_asm.S b/wolfcrypt/src/sha512_asm.S index 9471cf448..a79632150 100644 --- a/wolfcrypt/src/sha512_asm.S +++ b/wolfcrypt/src/sha512_asm.S @@ -20,8 +20,23 @@ */ #ifdef WOLFSSL_USER_SETTINGS +#ifdef WOLFSSL_USER_SETTINGS_ASM +/* + * user_settings_asm.h is a file generated by the script user_settings_asm.sh. + * The script takes in a user_settings.h and produces user_settings_asm.h, which + * is a stripped down version of user_settings.h containing only preprocessor + * directives. This makes the header safe to include in assembly (.S) files. + */ #include "user_settings_asm.h" -#endif +#else +/* + * Note: if user_settings.h contains any C code (e.g. a typedef or function + * prototype), including it here in an assembly (.S) file will cause an + * assembler failure. See user_settings_asm.h above. + */ +#include "user_settings.h" +#endif /* WOLFSSL_USER_SETTINGS_ASM */ +#endif /* WOLFSSL_USER_SETTINGS */ #ifndef HAVE_INTEL_AVX1 #define HAVE_INTEL_AVX1 diff --git a/wolfcrypt/src/sp_x86_64_asm.S b/wolfcrypt/src/sp_x86_64_asm.S index e5f5fe0cb..7bbe1ff40 100644 --- a/wolfcrypt/src/sp_x86_64_asm.S +++ b/wolfcrypt/src/sp_x86_64_asm.S @@ -20,8 +20,23 @@ */ #ifdef WOLFSSL_USER_SETTINGS +#ifdef WOLFSSL_USER_SETTINGS_ASM +/* + * user_settings_asm.h is a file generated by the script user_settings_asm.sh. + * The script takes in a user_settings.h and produces user_settings_asm.h, which + * is a stripped down version of user_settings.h containing only preprocessor + * directives. This makes the header safe to include in assembly (.S) files. + */ #include "user_settings_asm.h" -#endif +#else +/* + * Note: if user_settings.h contains any C code (e.g. a typedef or function + * prototype), including it here in an assembly (.S) file will cause an + * assembler failure. See user_settings_asm.h above. + */ +#include "user_settings.h" +#endif /* WOLFSSL_USER_SETTINGS_ASM */ +#endif /* WOLFSSL_USER_SETTINGS */ #ifndef HAVE_INTEL_AVX1 #define HAVE_INTEL_AVX1