Whoops, I made a typo in the constant for SHA256, please use this
revised patch instead.
Regards,
Tim
--- nettle-3.9.1_orig/fat-arm64.c 2023-12-05 02:16:50
+++ nettle-3.9.1/fat-arm64.c 2023-12-05 02:15:23
@@ -50,6 +50,8 @@
# include <sys/sysctl.h>
# include <machine/cpu.h>
# include <machine/armreg.h>
+#elif defined(__APPLE__)
+# include <sys/sysctl.h>
#endif
#include "nettle-types.h"
@@ -85,6 +87,16 @@
#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)
@@ -141,6 +153,12 @@
= (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
}
}
_______________________________________________
nettle-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]