2023-12-05 Niels Möller <nisse@lysator.liu.se>
+ From Tim Kosse:
+ * fat-arm64.c (check_sysctlbyname) [__APPLE__]: New function.
+ (get_arm64_features) [__APPLE__]: Fix feature detection for Apple
+ M1 devices.
+
* configure.ac: In openssl tests, check for the headers actually
used by the benchmarking code, and for a subset of the relevant
functions.
# include <sys/sysctl.h>
# include <machine/cpu.h>
# include <machine/armreg.h>
+#elif defined(__APPLE__)
+# include <sys/sysctl.h>
#endif
#include "nettle-types.h"
#define MATCH(s, slen, literal, llen) \
((slen) == (llen) && memcmp ((s), (literal), llen) == 0)
+#if defined(__APPLE__)
+static int
+check_sysctlbyname(const char* name)
+{
+ int val;
+ size_t s = sizeof(val);
+ return sysctlbyname(name, &val, &s, NULL, 0) ? 0 : val;
+}
+#endif
+
static void
get_arm64_features (struct arm64_features *features)
{
= (ID_AA64ISAR0_SHA1(isar0) >= ID_AA64ISAR0_SHA1_BASE);
features->have_sha2
= (ID_AA64ISAR0_SHA2(isar0) >= ID_AA64ISAR0_SHA2_BASE);
+#elif defined(__APPLE__)
+ /* See https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics */
+ features->have_aes = check_sysctlbyname("hw.optional.arm.FEAT_AES");
+ features->have_pmull = check_sysctlbyname("hw.optional.arm.FEAT_PMULL");
+ features->have_sha1 = check_sysctlbyname("hw.optional.arm.FEAT_SHA1");
+ features->have_sha2 = check_sysctlbyname("hw.optional.arm.FEAT_SHA256");
#endif
}
}