From: Christian Weisgerber Date: Sun, 12 Jun 2022 19:51:16 +0000 (+0200) Subject: Enable runtime arm64 feature detection on openbsd X-Git-Tag: nettle_3.8.1_release_20220727~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a4aa4655a17c649f236c1d69b8bacff6006ddc84;p=thirdparty%2Fnettle.git Enable runtime arm64 feature detection on openbsd (cherry picked from commit b874bdead2903d715c6964b2e8f9ed7d2b61db12) --- 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 # include # endif +#elif defined(__OpenBSD__) +# include +# include +# include #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 } }