From e7577bc2e9a7beacfa01dcf0c0a8bb1781b62b35 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Sat, 12 Apr 2025 00:35:49 -0500 Subject: [PATCH] wolfssl/wolfcrypt/libwolfssl_sources*.h: check if the other libwolfssl_sources*.h was included before concluding that "#error settings.h included before libwolfssl_sources.h.", and add WC_CONFIG_H_INCLUDED to inhibit multiple inclusions of config.h; wolfcrypt/src/port/kcapi/kcapi_aes.c: restore #include removed incorrectly in ed5d8f8e6b; wolfcrypt/src/port/liboqs/liboqs.c: include libwolfssl_sources.h; wolfcrypt/src/port/riscv/*.c: include libwolfssl_sources.h; wolfcrypt/test/test.c: fix use of WC_TEST_RET_ENC_I() where WC_TEST_RET_ENC_EC() was required. --- wolfcrypt/src/port/kcapi/kcapi_aes.c | 2 ++ wolfcrypt/src/port/liboqs/liboqs.c | 11 ++--------- wolfcrypt/src/port/riscv/riscv-64-aes.c | 8 +------- wolfcrypt/src/port/riscv/riscv-64-chacha.c | 9 ++------- wolfcrypt/src/port/riscv/riscv-64-poly1305.c | 12 +++--------- wolfcrypt/src/port/riscv/riscv-64-sha256.c | 9 +-------- wolfcrypt/src/port/riscv/riscv-64-sha3.c | 6 +----- wolfcrypt/src/port/riscv/riscv-64-sha512.c | 9 +-------- wolfcrypt/test/test.c | 2 +- wolfssl/wolfcrypt/libwolfssl_sources.h | 6 ++++-- wolfssl/wolfcrypt/libwolfssl_sources_asm.h | 6 ++++-- 11 files changed, 22 insertions(+), 58 deletions(-) diff --git a/wolfcrypt/src/port/kcapi/kcapi_aes.c b/wolfcrypt/src/port/kcapi/kcapi_aes.c index 71c74fec1..d6c7875c9 100644 --- a/wolfcrypt/src/port/kcapi/kcapi_aes.c +++ b/wolfcrypt/src/port/kcapi/kcapi_aes.c @@ -23,6 +23,8 @@ #if !defined(NO_AES) && defined(WOLFSSL_KCAPI_AES) +#include + #if defined(HAVE_FIPS) && \ defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2) diff --git a/wolfcrypt/src/port/liboqs/liboqs.c b/wolfcrypt/src/port/liboqs/liboqs.c index 520349ecf..90d3dbbd4 100644 --- a/wolfcrypt/src/port/liboqs/liboqs.c +++ b/wolfcrypt/src/port/liboqs/liboqs.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ +#include + /* DESCRIPTION @@ -27,15 +29,6 @@ implementations for Post-Quantum cryptography algorithms. */ -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include -#include -#include - #include #if defined(HAVE_LIBOQS) diff --git a/wolfcrypt/src/port/riscv/riscv-64-aes.c b/wolfcrypt/src/port/riscv/riscv-64-aes.c index c116f17da..39969ccb8 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-aes.c +++ b/wolfcrypt/src/port/riscv/riscv-64-aes.c @@ -19,20 +19,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ -#ifdef HAVE_CONFIG_H - #include -#endif +#include -#include #include -#include #if !defined(NO_AES) #include -#include - #ifdef NO_INLINE #include #else diff --git a/wolfcrypt/src/port/riscv/riscv-64-chacha.c b/wolfcrypt/src/port/riscv/riscv-64-chacha.c index 8240e863d..776b1b620 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-chacha.c +++ b/wolfcrypt/src/port/riscv/riscv-64-chacha.c @@ -19,24 +19,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ +#include + /* The paper NEON crypto by Daniel J. Bernstein and Peter Schwabe was used to * optimize for ARM: * https://cryptojedi.org/papers/veccrypto-20120320.pdf */ -#ifdef HAVE_CONFIG_H - #include -#endif - -#include #include #ifdef WOLFSSL_RISCV_ASM #ifdef HAVE_CHACHA #include -#include -#include #include #ifdef NO_INLINE #include diff --git a/wolfcrypt/src/port/riscv/riscv-64-poly1305.c b/wolfcrypt/src/port/riscv/riscv-64-poly1305.c index e25d75fa0..3d5a8bd1a 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-poly1305.c +++ b/wolfcrypt/src/port/riscv/riscv-64-poly1305.c @@ -19,25 +19,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ +#include + /* - * Based off the public domain implementations by Andrew Moon + * Based on the public domain implementations by Andrew Moon * and Daniel J. Bernstein */ -#ifdef HAVE_CONFIG_H - #include -#endif - -#include -#include #include #ifdef WOLFSSL_RISCV_ASM #ifdef HAVE_POLY1305 #include -#include -#include #include #ifdef NO_INLINE #include diff --git a/wolfcrypt/src/port/riscv/riscv-64-sha256.c b/wolfcrypt/src/port/riscv/riscv-64-sha256.c index 27c5f3ff2..9eb6d4e12 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-sha256.c +++ b/wolfcrypt/src/port/riscv/riscv-64-sha256.c @@ -19,12 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include +#include #ifdef WOLFSSL_RISCV_ASM #if !defined(NO_SHA256) || defined(WOLFSSL_SHA224) @@ -47,8 +42,6 @@ return 0; } #endif -#include -#include #include diff --git a/wolfcrypt/src/port/riscv/riscv-64-sha3.c b/wolfcrypt/src/port/riscv/riscv-64-sha3.c index dd9000c09..ad8650a1b 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-sha3.c +++ b/wolfcrypt/src/port/riscv/riscv-64-sha3.c @@ -19,12 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ +#include -#ifdef HAVE_CONFIG_H - #include -#endif - -#include #include #ifdef WOLFSSL_RISCV_ASM diff --git a/wolfcrypt/src/port/riscv/riscv-64-sha512.c b/wolfcrypt/src/port/riscv/riscv-64-sha512.c index afe326c3b..3922617ef 100644 --- a/wolfcrypt/src/port/riscv/riscv-64-sha512.c +++ b/wolfcrypt/src/port/riscv/riscv-64-sha512.c @@ -19,12 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include +#include #ifdef WOLFSSL_RISCV_ASM #if !defined(NO_SHA512) || defined(WOLFSSL_SHA384) @@ -47,8 +42,6 @@ return 0; } #endif -#include -#include #include diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index bb85a3f4a..70c658135 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -6363,7 +6363,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void) } if (ret != 0) { - ERROR_OUT(WC_TEST_RET_ENC_I(BAD_FUNC_ARG), out); + ERROR_OUT(WC_TEST_RET_ENC_EC(BAD_FUNC_ARG), out); } #endif ret = wc_HashInit(hash, typesGood[i]); diff --git a/wolfssl/wolfcrypt/libwolfssl_sources.h b/wolfssl/wolfcrypt/libwolfssl_sources.h index 01735a400..474cbe18d 100644 --- a/wolfssl/wolfcrypt/libwolfssl_sources.h +++ b/wolfssl/wolfcrypt/libwolfssl_sources.h @@ -29,7 +29,8 @@ #define LIBWOLFSSL_SOURCES_H #if defined(TEST_LIBWOLFSSL_SOURCES_INCLUSION_SEQUENCE) && \ - defined(WOLF_CRYPT_SETTINGS_H) + defined(WOLF_CRYPT_SETTINGS_H) && \ + !defined(LIBWOLFSSL_SOURCES_ASM_H) #error settings.h included before libwolfssl_sources.h. #endif @@ -37,8 +38,9 @@ #define BUILDING_WOLFSSL #endif -#ifdef HAVE_CONFIG_H +#if defined(HAVE_CONFIG_H) && !defined(WC_CONFIG_H_INCLUDED) #include + #define WC_CONFIG_H_INCLUDED #endif #include diff --git a/wolfssl/wolfcrypt/libwolfssl_sources_asm.h b/wolfssl/wolfcrypt/libwolfssl_sources_asm.h index 518040a36..a3d85c9fb 100644 --- a/wolfssl/wolfcrypt/libwolfssl_sources_asm.h +++ b/wolfssl/wolfcrypt/libwolfssl_sources_asm.h @@ -29,7 +29,8 @@ #define LIBWOLFSSL_SOURCES_ASM_H #if defined(TEST_LIBWOLFSSL_SOURCES_INCLUSION_SEQUENCE) && \ - defined(WOLF_CRYPT_SETTINGS_H) + defined(WOLF_CRYPT_SETTINGS_H) && \ + !defined(LIBWOLFSSL_SOURCES_H) #error settings.h included before libwolfssl_sources_asm.h. #endif @@ -37,8 +38,9 @@ #define BUILDING_WOLFSSL #endif -#ifdef HAVE_CONFIG_H +#if defined(HAVE_CONFIG_H) && !defined(WC_CONFIG_H_INCLUDED) #include + #define WC_CONFIG_H_INCLUDED #endif #include