diff options
Diffstat (limited to 'crypto/arch/aarch64/crypto_cpu_caps_darwin.c')
-rw-r--r-- | crypto/arch/aarch64/crypto_cpu_caps_darwin.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/crypto/arch/aarch64/crypto_cpu_caps_darwin.c b/crypto/arch/aarch64/crypto_cpu_caps_darwin.c new file mode 100644 index 0000000..1dd91b2 --- /dev/null +++ b/crypto/arch/aarch64/crypto_cpu_caps_darwin.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* $OpenBSD: crypto_cpu_caps.c,v 1.2 2024/11/12 13:52:31 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2025 Brent Cook <bcook@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <sys/sysctl.h> | ||
19 | |||
20 | #include "crypto_arch.h" | ||
21 | |||
22 | /* Machine dependent CPU capabilities. */ | ||
23 | uint64_t crypto_cpu_caps_aarch64; | ||
24 | |||
25 | static uint64_t | ||
26 | check_cpu_cap(const char *cap_name, uint64_t cap_flag) | ||
27 | { | ||
28 | int has_cap = 0; | ||
29 | size_t len = sizeof(has_cap); | ||
30 | |||
31 | sysctlbyname(cap_name, &has_cap, &len, NULL, 0); | ||
32 | |||
33 | return has_cap ? cap_flag : 0; | ||
34 | } | ||
35 | |||
36 | void | ||
37 | crypto_cpu_caps_init(void) | ||
38 | { | ||
39 | crypto_cpu_caps_aarch64 = 0; | ||
40 | |||
41 | /* from https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3918855 */ | ||
42 | |||
43 | crypto_cpu_caps_aarch64 |= check_cpu_cap("hw.optional.arm.FEAT_AES", | ||
44 | CRYPTO_CPU_CAPS_AARCH64_AES); | ||
45 | |||
46 | crypto_cpu_caps_aarch64 |= check_cpu_cap("hw.optional.arm.FEAT_PMULL", | ||
47 | CRYPTO_CPU_CAPS_AARCH64_PMULL); | ||
48 | |||
49 | crypto_cpu_caps_aarch64 |= check_cpu_cap("hw.optional.arm.FEAT_SHA1", | ||
50 | CRYPTO_CPU_CAPS_AARCH64_SHA1); | ||
51 | |||
52 | crypto_cpu_caps_aarch64 |= check_cpu_cap("hw.optional.arm.FEAT_SHA256", | ||
53 | CRYPTO_CPU_CAPS_AARCH64_SHA2); | ||
54 | |||
55 | crypto_cpu_caps_aarch64 |= check_cpu_cap("hw.optional.arm.FEAT_SHA512", | ||
56 | CRYPTO_CPU_CAPS_AARCH64_SHA512); | ||
57 | |||
58 | crypto_cpu_caps_aarch64 |= check_cpu_cap("hw.optional.arm.FEAT_SHA3", | ||
59 | CRYPTO_CPU_CAPS_AARCH64_SHA3); | ||
60 | } | ||