diff options
| author | naddy <> | 2026-08-08 21:37:19 +0000 |
|---|---|---|
| committer | naddy <> | 2026-08-08 21:37:19 +0000 |
| commit | 43c64b4581f5552444b2f466a8aabcb274054e79 (patch) | |
| tree | f9d497fe851d234517b4eb1a80599984501be26d /src | |
| parent | 33336ca96029d7f4f2077d4f39573e29c748a5b6 (diff) | |
| download | openbsd-43c64b4581f5552444b2f466a8aabcb274054e79.tar.gz openbsd-43c64b4581f5552444b2f466a8aabcb274054e79.tar.bz2 openbsd-43c64b4581f5552444b2f466a8aabcb274054e79.zip | |
switch aarch64 CPU feature detection to elf_aux_info()
ok kettenis@ tb@
Restore commit; install media build error is not reproducible (deraadt@)
or was operator error (naddy@)
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/arch/aarch64/crypto_cpu_caps.c | 82 |
1 files changed, 19 insertions, 63 deletions
diff --git a/src/lib/libcrypto/arch/aarch64/crypto_cpu_caps.c b/src/lib/libcrypto/arch/aarch64/crypto_cpu_caps.c index 7927fd247c..5022bed262 100644 --- a/src/lib/libcrypto/arch/aarch64/crypto_cpu_caps.c +++ b/src/lib/libcrypto/arch/aarch64/crypto_cpu_caps.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: crypto_cpu_caps.c,v 1.4 2026/08/07 12:17:33 naddy Exp $ */ | 1 | /* $OpenBSD: crypto_cpu_caps.c,v 1.5 2026/08/08 21:37:19 naddy Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -15,10 +15,7 @@ | |||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #include <sys/types.h> | 18 | #include <sys/auxv.h> |
| 19 | #include <sys/sysctl.h> | ||
| 20 | |||
| 21 | #include <machine/cpu.h> | ||
| 22 | 19 | ||
| 23 | #include <stddef.h> | 20 | #include <stddef.h> |
| 24 | #include <stdio.h> | 21 | #include <stdio.h> |
| @@ -28,70 +25,29 @@ | |||
| 28 | /* Machine dependent CPU capabilities. */ | 25 | /* Machine dependent CPU capabilities. */ |
| 29 | uint64_t crypto_cpu_caps_aarch64; | 26 | uint64_t crypto_cpu_caps_aarch64; |
| 30 | 27 | ||
| 31 | static inline uint64_t | 28 | void |
| 32 | extract_bits(uint64_t val, int start, int end) | 29 | crypto_cpu_caps_init(void) |
| 33 | { | ||
| 34 | return (val >> end) & (1ULL << (1 + start - end)) - 1; | ||
| 35 | } | ||
| 36 | |||
| 37 | static uint64_t | ||
| 38 | parse_isar0(uint64_t isar0) | ||
| 39 | { | 30 | { |
| 40 | uint64_t caps = 0; | 31 | unsigned long hwcap; |
| 41 | uint64_t feature; | ||
| 42 | |||
| 43 | /* AES - bits [7:4] */ | ||
| 44 | feature = extract_bits(isar0, 7, 4); | ||
| 45 | if (feature >= 1) | ||
| 46 | caps |= CRYPTO_CPU_CAPS_AARCH64_AES; | ||
| 47 | if (feature >= 2) | ||
| 48 | caps |= CRYPTO_CPU_CAPS_AARCH64_PMULL; | ||
| 49 | |||
| 50 | /* SHA1 - bits [11:8] */ | ||
| 51 | feature = extract_bits(isar0, 11, 8); | ||
| 52 | if (feature >= 1) | ||
| 53 | caps |= CRYPTO_CPU_CAPS_AARCH64_SHA1; | ||
| 54 | |||
| 55 | /* SHA2 - bits [15:12] */ | ||
| 56 | feature = extract_bits(isar0, 15, 12); | ||
| 57 | if (feature >= 1) | ||
| 58 | caps |= CRYPTO_CPU_CAPS_AARCH64_SHA2; | ||
| 59 | if (feature >= 2) | ||
| 60 | caps |= CRYPTO_CPU_CAPS_AARCH64_SHA512; | ||
| 61 | |||
| 62 | /* SHA3 - bits [35:32] */ | ||
| 63 | feature = extract_bits(isar0, 35, 32); | ||
| 64 | if (feature >= 1) | ||
| 65 | caps |= CRYPTO_CPU_CAPS_AARCH64_SHA3; | ||
| 66 | 32 | ||
| 67 | return caps; | 33 | if (elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)) != 0) |
| 68 | } | 34 | return; |
| 69 | 35 | ||
| 70 | static int | 36 | if (hwcap & HWCAP_AES) |
| 71 | read_isar0(uint64_t *isar0) | 37 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_AES; |
| 72 | { | ||
| 73 | uint64_t isar; | ||
| 74 | int mib[2]; | ||
| 75 | size_t len; | ||
| 76 | 38 | ||
| 77 | mib[0] = CTL_MACHDEP; | 39 | if (hwcap & HWCAP_PMULL) |
| 78 | mib[1] = CPU_ID_AA64ISAR0; | 40 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_PMULL; |
| 79 | len = sizeof(isar); | ||
| 80 | if (sysctl(mib, 2, &isar, &len, NULL, 0) == -1) | ||
| 81 | return 0; | ||
| 82 | 41 | ||
| 83 | *isar0 = isar; | 42 | if (hwcap & HWCAP_SHA1) |
| 43 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA1; | ||
| 84 | 44 | ||
| 85 | return 1; | 45 | if (hwcap & HWCAP_SHA2) |
| 86 | } | 46 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA2; |
| 87 | 47 | ||
| 88 | void | 48 | if (hwcap & HWCAP_SHA512) |
| 89 | crypto_cpu_caps_init(void) | 49 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA512; |
| 90 | { | ||
| 91 | uint64_t isar = 0; | ||
| 92 | |||
| 93 | if (!read_isar0(&isar)) | ||
| 94 | return; | ||
| 95 | 50 | ||
| 96 | crypto_cpu_caps_aarch64 = parse_isar0(isar); | 51 | if (hwcap & HWCAP_SHA3) |
| 52 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA3; | ||
| 97 | } | 53 | } |
