]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Enable runtime arm64 feature detection on openbsd
authorChristian Weisgerber <naddy@mips.inka.de>
Sun, 12 Jun 2022 19:51:16 +0000 (21:51 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Sun, 12 Jun 2022 19:51:16 +0000 (21:51 +0200)
fat-arm64.c

index ef3c33f44942c4e2fa2ebe95e005d3bea382fad3..f2b8493d03d283233344aff710498d5c22ff0318 100644 (file)
 #  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
     }
 }