diff options
| author | Brent Cook <busterb@gmail.com> | 2025-05-18 20:02:27 +0900 |
|---|---|---|
| committer | Brent Cook <busterb@gmail.com> | 2025-05-19 06:19:47 +0900 |
| commit | 57af1184805d44d48c1f6df7e13f1f823dceb6f4 (patch) | |
| tree | dba977b6a5579efd56249da66c57f4c65b0efd32 | |
| parent | 5e98a097cf7fd4469c1281583b2456b08de60f73 (diff) | |
| download | portable-57af1184805d44d48c1f6df7e13f1f823dceb6f4.tar.gz portable-57af1184805d44d48c1f6df7e13f1f823dceb6f4.tar.bz2 portable-57af1184805d44d48c1f6df7e13f1f823dceb6f4.zip | |
create noop and apple cpu_caps checks for aarch64
| -rw-r--r-- | crypto/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | crypto/Makefile.am | 9 | ||||
| -rw-r--r-- | crypto/arch/aarch64/crypto_cpu_caps_apple.c | 60 | ||||
| -rw-r--r-- | crypto/arch/aarch64/crypto_cpu_caps_none.c | 26 | ||||
| -rw-r--r-- | patches/patch-aarch64-crypto-cpu-caps.c.patch | 39 |
5 files changed, 102 insertions, 40 deletions
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index b898296..184fbf6 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt | |||
| @@ -146,7 +146,13 @@ if(HOST_ASM_MINGW64_X86_64) | |||
| 146 | endif() | 146 | endif() |
| 147 | 147 | ||
| 148 | if(HOST_AARCH64) | 148 | if(HOST_AARCH64) |
| 149 | set(CRYPTO_SRC ${CRYPTO_SRC} arch/aarch64/crypto_cpu_caps.c) | 149 | if(APPLE) |
| 150 | set(CRYPTO_SRC ${CRYPTO_SRC} arch/aarch64/crypto_cpu_caps_apple.c) | ||
| 151 | elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") | ||
| 152 | set(CRYPTO_SRC ${CRYPTO_SRC} arch/aarch64/crypto_cpu_caps.c) | ||
| 153 | else() | ||
| 154 | set(CRYPTO_SRC ${CRYPTO_SRC} arch/aarch64/crypto_cpu_caps_none.c) | ||
| 155 | endif() | ||
| 150 | elseif(HOST_X86_64) | 156 | elseif(HOST_X86_64) |
| 151 | set(CRYPTO_SRC ${CRYPTO_SRC} arch/amd64/crypto_cpu_caps.c) | 157 | set(CRYPTO_SRC ${CRYPTO_SRC} arch/amd64/crypto_cpu_caps.c) |
| 152 | elseif(HOST_I386) | 158 | elseif(HOST_I386) |
diff --git a/crypto/Makefile.am b/crypto/Makefile.am index b8628f0..bbce59a 100644 --- a/crypto/Makefile.am +++ b/crypto/Makefile.am | |||
| @@ -210,8 +210,17 @@ endif | |||
| 210 | endif | 210 | endif |
| 211 | 211 | ||
| 212 | if HOST_AARCH64 | 212 | if HOST_AARCH64 |
| 213 | if HOST_DARWIN | ||
| 214 | libcrypto_la_SOURCES += arch/aarch64/crypto_cpu_caps_apple.c | ||
| 215 | else | ||
| 216 | if HOST_OPENBSD | ||
| 213 | libcrypto_la_SOURCES += arch/aarch64/crypto_cpu_caps.c | 217 | libcrypto_la_SOURCES += arch/aarch64/crypto_cpu_caps.c |
| 218 | else | ||
| 219 | libcrypto_la_SOURCES += arch/aarch64/crypto_cpu_caps_none.c | ||
| 220 | endif | ||
| 214 | endif | 221 | endif |
| 222 | endif | ||
| 223 | |||
| 215 | if HOST_X86_64 | 224 | if HOST_X86_64 |
| 216 | libcrypto_la_SOURCES += arch/amd64/crypto_cpu_caps.c | 225 | libcrypto_la_SOURCES += arch/amd64/crypto_cpu_caps.c |
| 217 | endif | 226 | endif |
diff --git a/crypto/arch/aarch64/crypto_cpu_caps_apple.c b/crypto/arch/aarch64/crypto_cpu_caps_apple.c new file mode 100644 index 0000000..1dd91b2 --- /dev/null +++ b/crypto/arch/aarch64/crypto_cpu_caps_apple.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_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/patches/patch-aarch64-crypto-cpu-caps.c.patch b/patches/patch-aarch64-crypto-cpu-caps.c.patch deleted file mode 100644 index dcfbdc0..0000000 --- a/patches/patch-aarch64-crypto-cpu-caps.c.patch +++ /dev/null | |||
| @@ -1,39 +0,0 @@ | |||
| 1 | Disable feature detection until we find a more portable way. | ||
| 2 | |||
| 3 | --- crypto/arch/aarch64/crypto_cpu_caps.c.orig Sat Dec 14 13:45:16 2024 | ||
| 4 | +++ crypto/arch/aarch64/crypto_cpu_caps.c Sat Dec 14 13:54:06 2024 | ||
| 5 | @@ -16,9 +16,12 @@ | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <sys/types.h> | ||
| 9 | + | ||
| 10 | +#if defined(__OpenBSD__) | ||
| 11 | #include <sys/sysctl.h> | ||
| 12 | |||
| 13 | #include <machine/cpu.h> | ||
| 14 | +#endif | ||
| 15 | |||
| 16 | #include <stddef.h> | ||
| 17 | #include <stdio.h> | ||
| 18 | @@ -67,6 +70,7 @@ parse_isar0(uint64_t isar0) | ||
| 19 | return caps; | ||
| 20 | } | ||
| 21 | |||
| 22 | +#if defined(__OpenBSD__) | ||
| 23 | static int | ||
| 24 | read_isar0(uint64_t *isar0) | ||
| 25 | { | ||
| 26 | @@ -84,6 +88,13 @@ read_isar0(uint64_t *isar0) | ||
| 27 | |||
| 28 | return 1; | ||
| 29 | } | ||
| 30 | +#else | ||
| 31 | +static int | ||
| 32 | +read_isar0(uint64_t *isar0) | ||
| 33 | +{ | ||
| 34 | + return 0; | ||
| 35 | +} | ||
| 36 | +#endif | ||
| 37 | |||
| 38 | void | ||
| 39 | crypto_cpu_caps_init(void) | ||
