aboutsummaryrefslogtreecommitdiff
path: root/crypto/arch/aarch64/crypto_cpu_caps_linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/arch/aarch64/crypto_cpu_caps_linux.c')
-rw-r--r--crypto/arch/aarch64/crypto_cpu_caps_linux.c62
1 files changed, 62 insertions, 0 deletions
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. */
32uint64_t crypto_cpu_caps_aarch64;
33
34static uint64_t
35check_cpu_cap(unsigned long hwcap, uint64_t cap_flag)
36{
37 return (getauxval(AT_HWCAP) & hwcap) ? cap_flag : 0;
38}
39
40void
41crypto_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}