diff options
Diffstat (limited to '')
-rw-r--r-- | crypto/arch/aarch64/crypto_cpu_caps_darwin.c | 60 | ||||
-rw-r--r-- | crypto/arch/aarch64/crypto_cpu_caps_linux.c | 62 | ||||
-rw-r--r-- | crypto/arch/aarch64/crypto_cpu_caps_none.c | 26 | ||||
-rw-r--r-- | crypto/arch/aarch64/crypto_cpu_caps_windows.c | 36 |
4 files changed, 184 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 | } | ||
diff --git a/crypto/arch/aarch64/crypto_cpu_caps_linux.c b/crypto/arch/aarch64/crypto_cpu_caps_linux.c new file mode 100644 index 0000000..ae28120 --- /dev/null +++ b/crypto/arch/aarch64/crypto_cpu_caps_linux.c | |||
@@ -0,0 +1,62 @@ | |||
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/auxv.h> | ||
19 | |||
20 | /* from arch/arm64/include/uapi/asm/hwcap.h */ | ||
21 | #define HWCAP_AES (1 << 3) | ||
22 | #define HWCAP_PMULL (1 << 4) | ||
23 | #define HWCAP_SHA1 (1 << 5) | ||
24 | #define HWCAP_SHA2 (1 << 6) | ||
25 | #define HWCAP_CRC32 (1 << 7) | ||
26 | #define HWCAP_SHA3 (1 << 17) | ||
27 | #define HWCAP_SHA512 (1 << 21) | ||
28 | |||
29 | #include "crypto_arch.h" | ||
30 | |||
31 | /* Machine dependent CPU capabilities. */ | ||
32 | uint64_t crypto_cpu_caps_aarch64; | ||
33 | |||
34 | static uint64_t | ||
35 | check_cpu_cap(unsigned long hwcap, uint64_t cap_flag) | ||
36 | { | ||
37 | return (getauxval(AT_HWCAP) & hwcap) ? cap_flag : 0; | ||
38 | } | ||
39 | |||
40 | void | ||
41 | crypto_cpu_caps_init(void) | ||
42 | { | ||
43 | crypto_cpu_caps_aarch64 = 0; | ||
44 | |||
45 | crypto_cpu_caps_aarch64 |= check_cpu_cap(HWCAP_AES, | ||
46 | CRYPTO_CPU_CAPS_AARCH64_AES); | ||
47 | |||
48 | crypto_cpu_caps_aarch64 |= check_cpu_cap(HWCAP_PMULL, | ||
49 | CRYPTO_CPU_CAPS_AARCH64_PMULL); | ||
50 | |||
51 | crypto_cpu_caps_aarch64 |= check_cpu_cap(HWCAP_SHA1, | ||
52 | CRYPTO_CPU_CAPS_AARCH64_SHA1); | ||
53 | |||
54 | crypto_cpu_caps_aarch64 |= check_cpu_cap(HWCAP_SHA2, | ||
55 | CRYPTO_CPU_CAPS_AARCH64_SHA2); | ||
56 | |||
57 | crypto_cpu_caps_aarch64 |= check_cpu_cap(HWCAP_SHA512, | ||
58 | CRYPTO_CPU_CAPS_AARCH64_SHA512); | ||
59 | |||
60 | crypto_cpu_caps_aarch64 |= check_cpu_cap(HWCAP_SHA3, | ||
61 | CRYPTO_CPU_CAPS_AARCH64_SHA3); | ||
62 | } | ||
diff --git a/crypto/arch/aarch64/crypto_cpu_caps_none.c b/crypto/arch/aarch64/crypto_cpu_caps_none.c new file mode 100644 index 0000000..dcd96b7 --- /dev/null +++ b/crypto/arch/aarch64/crypto_cpu_caps_none.c | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2025 Brent Cook <bcook@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "crypto_arch.h" | ||
18 | |||
19 | /* Machine dependent CPU capabilities. */ | ||
20 | uint64_t crypto_cpu_caps_aarch64; | ||
21 | |||
22 | void | ||
23 | crypto_cpu_caps_init(void) | ||
24 | { | ||
25 | crypto_cpu_caps_aarch64 = 0; | ||
26 | } | ||
diff --git a/crypto/arch/aarch64/crypto_cpu_caps_windows.c b/crypto/arch/aarch64/crypto_cpu_caps_windows.c new file mode 100644 index 0000000..e7cdded --- /dev/null +++ b/crypto/arch/aarch64/crypto_cpu_caps_windows.c | |||
@@ -0,0 +1,36 @@ | |||
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 <windows.h> | ||
19 | |||
20 | #include "crypto_arch.h" | ||
21 | |||
22 | /* Machine dependent CPU capabilities. */ | ||
23 | uint64_t crypto_cpu_caps_aarch64; | ||
24 | |||
25 | void | ||
26 | crypto_cpu_caps_init(void) | ||
27 | { | ||
28 | crypto_cpu_caps_aarch64 = 0; | ||
29 | |||
30 | if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) { | ||
31 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_AES; | ||
32 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_PMULL; | ||
33 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA1; | ||
34 | crypto_cpu_caps_aarch64 |= CRYPTO_CPU_CAPS_AARCH64_SHA2; | ||
35 | } | ||
36 | } | ||