From cbb9caead4c4ba5d80d6cb01386518ef6d05eaaa Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 16 Feb 2023 23:40:40 +0100 Subject: [PATCH 1/2] Changelog for building SHA-256 and 512 with old libc Linux/Aarch64: support SHA acceleration detection with older libc On Linux on aarch64 (64-bit ARMv8) processors, we use getauxval() to detect whether the runtime environment supports SHA-256 or SHA-512 acceleration. Some libc do not define the necessary HWCAP_xxx constants to analyze the result of getauxval(), either because they don't bother or because they're too old to recognize the values we need (for example, HWCAP_SHA2 appeared in Glibc 2.24 and HWCAP_SHA512 appeared in Glibc 2.27). In such cases, assume that the values are the same as in the kernel ABI and define the constants manually. Signed-off-by: Gilles Peskine Signed-off-by: Dave Rodgman --- ChangeLog.d/linux-aarch64-hwcap.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ChangeLog.d/linux-aarch64-hwcap.txt diff --git a/ChangeLog.d/linux-aarch64-hwcap.txt b/ChangeLog.d/linux-aarch64-hwcap.txt new file mode 100644 index 000000000..23af87824 --- /dev/null +++ b/ChangeLog.d/linux-aarch64-hwcap.txt @@ -0,0 +1,4 @@ +Bugfix + * On Linux on ARMv8, fix a build error with SHA-256 and SHA-512 + acceleration detection when the libc headers do not define the + corresponding constant. Reported by valord577. From dae21d3808be93c30fda318b19657b4db6ad2b5d Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 30 Jan 2024 15:31:42 +0000 Subject: [PATCH 2/2] Support SHA-512 hwcap detection on old libc Signed-off-by: Dave Rodgman --- library/sha512.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/sha512.c b/library/sha512.c index 601125445..6dcea8da5 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -102,6 +102,14 @@ # if defined(__linux__) /* Our preferred method of detection is getauxval() */ # include +# if !defined(HWCAP_SHA512) +/* The same header that declares getauxval() should provide the HWCAP_xxx + * constants to analyze its return value. However, the libc may be too + * old to have the constant that we need. So if it's missing, assume that + * the value is the same one used by the Linux kernel ABI. + */ +# define HWCAP_SHA512 (1 << 21) +# endif # endif /* Use SIGILL on Unix, and fall back to it on Linux */ # include