diff --git a/library/constant_time_impl.h b/library/constant_time_impl.h index 8570928070..1fa655d663 100644 --- a/library/constant_time_impl.h +++ b/library/constant_time_impl.h @@ -37,6 +37,17 @@ #include "mbedtls/bignum.h" #endif +/* constant_time_impl.h contains all the static inline implementations, + * so that constant_time_internal.h is more readable. + * + * gcc generates warnings about duplicate declarations, so disable this + * warning. + */ +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wredundant-decls" +#endif + /* Disable asm under Memsan because it confuses Memsan and generates false errors */ #if defined(MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN) #define MBEDTLS_CT_NO_ASM @@ -288,4 +299,8 @@ static inline mbedtls_ct_condition_t mbedtls_ct_bool_not(mbedtls_ct_condition_t return (mbedtls_ct_condition_t) (~x); } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif + #endif /* MBEDTLS_CONSTANT_TIME_IMPL_H */ diff --git a/library/constant_time_internal.h b/library/constant_time_internal.h index 1411e14921..6d549f16ff 100644 --- a/library/constant_time_internal.h +++ b/library/constant_time_internal.h @@ -68,6 +68,9 @@ * architectures, it uses a plain C fallback designed to yield constant-time code * (this has been observed to be constant-time on latest gcc, clang and MSVC * as of May 2023). + * + * For readability, the static inline definitions are separated out into + * constant_time_impl.h. */ #if (SIZE_MAX > 0xffffffffffffffffULL) @@ -91,19 +94,6 @@ typedef int32_t mbedtls_ct_int_t; #endif #define MBEDTLS_CT_FALSE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0)) -/* constant_time_impl.h contains all the static inline implementations, - * so that constant_time_internal.h is more readable. - * - * gcc generates warnings about duplicate declarations, so disable this - * warning. - */ -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wredundant-decls" -#endif - -#include "constant_time_impl.h" - /* ============================================================================ * Boolean operations */ @@ -483,8 +473,7 @@ void mbedtls_ct_memcpy_offset(unsigned char *dest, size_t n); */ -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif +/* Include the implementation of static inline functions above. */ +#include "constant_time_impl.h" #endif /* MBEDTLS_CONSTANT_TIME_INTERNAL_H */