summaryrefslogtreecommitdiff
path: root/fat-arm64.c
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@mips.inka.de>2022-06-12 21:51:16 +0200
committerNiels Möller <nisse@lysator.liu.se>2022-06-12 21:51:16 +0200
commitb874bdead2903d715c6964b2e8f9ed7d2b61db12 (patch)
tree7c43db186582e92e6eee9cad7521ca86850c90b3 /fat-arm64.c
parentfde7c534529c1762df1295d0452fe3cc81fdf3fe (diff)
downloadnettle-b874bdead2903d715c6964b2e8f9ed7d2b61db12.tar.gz
Enable runtime arm64 feature detection on openbsd
Diffstat (limited to 'fat-arm64.c')
-rw-r--r--fat-arm64.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/fat-arm64.c b/fat-arm64.c
index ef3c33f4..f2b8493d 100644
--- a/fat-arm64.c
+++ b/fat-arm64.c
@@ -46,6 +46,10 @@
# include <asm/hwcap.h>
# include <sys/auxv.h>
# endif
+#elif defined(__OpenBSD__)
+# include <sys/sysctl.h>
+# include <machine/cpu.h>
+# include <machine/armreg.h>
#endif
#include "nettle-types.h"
@@ -122,6 +126,21 @@ get_arm64_features (struct arm64_features *features)
= ((hwcap & (HWCAP_ASIMD | HWCAP_SHA1)) == (HWCAP_ASIMD | HWCAP_SHA1));
features->have_sha2
= ((hwcap & (HWCAP_ASIMD | HWCAP_SHA2)) == (HWCAP_ASIMD | HWCAP_SHA2));
+#elif defined(__OpenBSD__)
+ const int isar0_mib[] = { CTL_MACHDEP, CPU_ID_AA64ISAR0 };
+ uint64_t isar0;
+ size_t len = sizeof(isar0);
+
+ if (sysctl(isar0_mib, 2, &isar0, &len, NULL, 0) < 0)
+ return;
+ features->have_aes
+ = (ID_AA64ISAR0_AES(isar0) >= ID_AA64ISAR0_AES_BASE);
+ features->have_pmull
+ = (ID_AA64ISAR0_AES(isar0) >= ID_AA64ISAR0_AES_PMULL);
+ features->have_sha1
+ = (ID_AA64ISAR0_SHA1(isar0) >= ID_AA64ISAR0_SHA1_BASE);
+ features->have_sha2
+ = (ID_AA64ISAR0_SHA2(isar0) >= ID_AA64ISAR0_SHA2_BASE);
#endif
}
}