From 4aaf4ad9fa4eb35edb73d364a05bb6dbaba24f02 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Tue, 4 Feb 2025 09:56:15 -0500 Subject: [PATCH] Validate or define ARM HWCAP2_XXX macros --- crypto/fipsmodule/cpucap/cpu_arm_linux.h | 33 ++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/crypto/fipsmodule/cpucap/cpu_arm_linux.h b/crypto/fipsmodule/cpucap/cpu_arm_linux.h index fa8c60a621..fdb1cf3f87 100644 --- a/crypto/fipsmodule/cpucap/cpu_arm_linux.h +++ b/crypto/fipsmodule/cpucap/cpu_arm_linux.h @@ -28,14 +28,37 @@ extern "C" { // The cpuinfo parser lives in a header file so it may be accessible from // cross-platform fuzzers without adding code to those platforms normally. -#define HWCAP_NEON (1 << 12) +#if defined(HWCAP_NEON) && HWCAP_NEON != 4096 + #error "HWCAP_NEON is defined but has wrong value (expected 4096)" +#elif !defined(HWCAP_NEON) + #define HWCAP_NEON 4096 +#endif // See /usr/include/asm/hwcap.h on an ARM installation for the source of // these values. -#define HWCAP2_AES (1 << 0) -#define HWCAP2_PMULL (1 << 1) -#define HWCAP2_SHA1 (1 << 2) -#define HWCAP2_SHA2 (1 << 3) +#if defined(HWCAP2_AES) && HWCAP2_AES != 1 + #error "HWCAP2_AES is defined but has wrong value (expected 1)" +#elif !defined(HWCAP2_AES) + #define HWCAP2_AES 1 +#endif + +#if defined(HWCAP2_PMULL) && HWCAP2_PMULL != 2 + #error "HWCAP2_PMULL is defined but has wrong value (expected 2)" +#elif !defined(HWCAP2_PMULL) + #define HWCAP2_PMULL 2 +#endif + +#if defined(HWCAP2_SHA1) && HWCAP2_SHA1 != 4 + #error "HWCAP2_SHA1 is defined but has wrong value (expected 4)" +#elif !defined(HWCAP2_SHA1) + #define HWCAP2_SHA1 4 +#endif + +#if defined(HWCAP2_SHA2) && HWCAP2_SHA2 != 8 + #error "HWCAP2_SHA2 is defined but has wrong value (expected 8)" +#elif !defined(HWCAP2_SHA2) + #define HWCAP2_SHA2 8 +#endif typedef struct { const char *data;