From a35f5326f5f2f5582807e72230a840beed5d5db9 Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Thu, 15 Jan 2026 15:09:10 +0000 Subject: [PATCH] drivers sha256|512: Adjusted tf_psa_crypto_common.h inclusion This patch adjusts the include order so that some ACLE intrinsics macros are configured before the inclusion of `neon.h`. This fixes issues with older clang compilers but has no effect in modern versions. Signed-off-by: Minos Galanakis --- library/sha256.c | 17 ++++++++++------- library/sha512.c | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/library/sha256.c b/library/sha256.c index c2a5f9c93b..4f1ac3e0fb 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -15,10 +15,6 @@ #define _GNU_SOURCE #endif -#include "common.h" - -#if defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA224_C) - #if defined(__clang__) && (__clang_major__ >= 4) /* Ideally, we would simply use MBEDTLS_ARCH_IS_ARMV8_A in the following #if, @@ -30,15 +26,18 @@ #endif #if defined(MBEDTLS_SHA256_ARCH_IS_ARMV8_A) && !defined(__ARM_FEATURE_CRYPTO) -/* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged. - * +/* * The intrinsic declaration are guarded by predefined ACLE macros in clang: * these are normally only enabled by the -march option on the command line. * By defining the macros ourselves we gain access to those declarations without * requiring -march on the command line. * * `arm_neon.h` is included by common.h, so we put these defines - * at the top of this file, before any includes. + * at the top of this file, before any includes but after the intrinsic + * declaration. This is necessary with + * Clang <=15.x. With Clang 16.0 and above, these macro definitions are + * no longer required, but they're harmless. See + * https://reviews.llvm.org/D131064 */ #define __ARM_FEATURE_CRYPTO 1 /* See: https://arm-software.github.io/acle/main/acle.html#cryptographic-extensions @@ -52,6 +51,10 @@ #endif /* defined(__clang__) && (__clang_major__ >= 4) */ +#include "common.h" + +#if defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA224_C) + #include "mbedtls/sha256.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h" diff --git a/library/sha512.c b/library/sha512.c index c7c2d92aef..286cbdf9f0 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -10,26 +10,29 @@ * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf */ -#include "common.h" - -#if defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_SHA384_C) - #if defined(__aarch64__) && !defined(__ARM_FEATURE_SHA512) && \ defined(__clang__) && __clang_major__ >= 7 -/* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged. - * +/* * The intrinsic declaration are guarded by predefined ACLE macros in clang: * these are normally only enabled by the -march option on the command line. * By defining the macros ourselves we gain access to those declarations without * requiring -march on the command line. * * `arm_neon.h` is included by common.h, so we put these defines - * at the top of this file, before any includes. + * at the top of this file, before any includes but after the intrinsic + * declaration. This is necessary with + * Clang <=15.x. With Clang 16.0 and above, these macro definitions are + * no longer required, but they're harmless. See + * https://reviews.llvm.org/D131064 */ #define __ARM_FEATURE_SHA512 1 #define MBEDTLS_ENABLE_ARM_SHA3_EXTENSIONS_COMPILER_FLAG #endif +#include "common.h" + +#if defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_SHA384_C) + #include "mbedtls/sha512.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h"