summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornaddy <>2026-08-07 12:17:33 +0000
committernaddy <>2026-08-07 12:17:33 +0000
commite1683307f0e5157e390cc99806f974cc09ff23f0 (patch)
treec27d886c3c3c760102a7dde1a92b84f435ccc1ce /src
parentdb6045dc22a2d82358877e02a66af8fd293c91dc (diff)
downloadopenbsd-e1683307f0e5157e390cc99806f974cc09ff23f0.tar.gz
openbsd-e1683307f0e5157e390cc99806f974cc09ff23f0.tar.bz2
openbsd-e1683307f0e5157e390cc99806f974cc09ff23f0.zip
revert switch to elf_aux_info(); it breaks the install media
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/arch/aarch64/crypto_cpu_caps.c82
1 files changed, 63 insertions, 19 deletions
diff --git a/src/lib/libcrypto/arch/aarch64/crypto_cpu_caps.c b/src/lib/libcrypto/arch/aarch64/crypto_cpu_caps.c
index 4b0074df51..7927fd247c 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.3 2026/08/04 21:21:26 naddy Exp $ */ 1/* $OpenBSD: crypto_cpu_caps.c,v 1.4 2026/08/07 12:17:33 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,7 +15,10 @@
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/auxv.h> 18#include <sys/types.h>
19#include <sys/sysctl.h>
20
21#include <machine/cpu.h>
19 22
20#include <stddef.h> 23#include <stddef.h>
21#include <stdio.h> 24#include <stdio.h>
@@ -25,29 +28,70 @@
25/* Machine dependent CPU capabilities. */ 28/* Machine dependent CPU capabilities. */
26uint64_t crypto_cpu_caps_aarch64; 29uint64_t crypto_cpu_caps_aarch64;
27 30
28void 31static inline uint64_t
29crypto_cpu_caps_init(void) 32extract_bits(uint64_t val, int start, int end)
30{ 33{
31 unsigned long hwcap; 34 return (val >> end) & (1ULL << (1 + start - end)) - 1;
35}
32 36
33 if (elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)) != 0) 37static uint64_t
34 return; 38parse_isar0(uint64_t isar0)
39{
40 uint64_t caps = 0;
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;
35 49
36 if (hwcap & HWCAP_AES) 50 /* SHA1 - bits [11:8] */
37 crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_AES; 51 feature = extract_bits(isar0, 11, 8);
52 if (feature >= 1)
53 caps |= CRYPTO_CPU_CAPS_AARCH64_SHA1;
38 54
39 if (hwcap & HWCAP_PMULL) 55 /* SHA2 - bits [15:12] */
40 crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_PMULL; 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;
41 61
42 if (hwcap & HWCAP_SHA1) 62 /* SHA3 - bits [35:32] */
43 crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA1; 63 feature = extract_bits(isar0, 35, 32);
64 if (feature >= 1)
65 caps |= CRYPTO_CPU_CAPS_AARCH64_SHA3;
44 66
45 if (hwcap & HWCAP_SHA2) 67 return caps;
46 crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA2; 68}
69
70static int
71read_isar0(uint64_t *isar0)
72{
73 uint64_t isar;
74 int mib[2];
75 size_t len;
47 76
48 if (hwcap & HWCAP_SHA512) 77 mib[0] = CTL_MACHDEP;
49 crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA512; 78 mib[1] = CPU_ID_AA64ISAR0;
79 len = sizeof(isar);
80 if (sysctl(mib, 2, &isar, &len, NULL, 0) == -1)
81 return 0;
82
83 *isar0 = isar;
84
85 return 1;
86}
87
88void
89crypto_cpu_caps_init(void)
90{
91 uint64_t isar = 0;
92
93 if (!read_isar0(&isar))
94 return;
50 95
51 if (hwcap & HWCAP_SHA3) 96 crypto_cpu_caps_aarch64 = parse_isar0(isar);
52 crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA3;
53} 97}