Botan 3.6.0
Crypto and TLS for C&
cpuid_arm32.cpp
Go to the documentation of this file.
1/*
2* Runtime CPU detection for 32-bit ARM
3* (C) 2009,2010,2013,2017,2024 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/internal/cpuid.h>
9
10#include <botan/internal/os_utils.h>
11
12namespace Botan {
13
14#if defined(BOTAN_TARGET_ARCH_IS_ARM32)
15
16uint32_t CPUID::CPUID_Data::detect_cpu_features(uint32_t allowed) {
17 uint32_t feat = 0;
18
19 if(OS::has_auxval()) {
20 /*
21 * On systems with getauxval these bits should normally be defined
22 * in bits/auxv.h but some buggy? glibc installs seem to miss them.
23 * These following values are all fixed, for the Linux ELF format,
24 * so we just hardcode them in ARM_hwcap_bit enum.
25 */
26
27 enum class ARM_hwcap_bit : uint64_t {
28 NEON_bit = (1 << 12),
29 AES_bit = (1 << 0),
30 PMULL_bit = (1 << 1),
31 SHA1_bit = (1 << 2),
32 SHA2_bit = (1 << 3),
33 };
34
35 const uint64_t hwcap_neon = OS::get_auxval(OS::auxval_hwcap());
36
37 feat |= if_set(hwcap_neon, ARM_hwcap_bit::NEON_bit, CPUID::CPUID_ARM_NEON_BIT, allowed);
38
39 if(feat & CPUID::CPUID_ARM_NEON_BIT) {
40 const uint64_t hwcap_crypto = OS::get_auxval(OS::auxval_hwcap2());
41
42 feat |= if_set(hwcap_crypto, ARM_hwcap_bit::AES_bit, CPUID::CPUID_ARM_AES_BIT, allowed);
43
44 feat |= if_set(hwcap_crypto, ARM_hwcap_bit::PMULL_bit, CPUID::CPUID_ARM_PMULL_BIT, allowed);
45
46 feat |= if_set(hwcap_crypto, ARM_hwcap_bit::SHA1_bit, CPUID::CPUID_ARM_SHA1_BIT, allowed);
47
48 feat |= if_set(hwcap_crypto, ARM_hwcap_bit::SHA2_bit, CPUID::CPUID_ARM_SHA2_BIT, allowed);
49 }
50 }
51
52 return feat;
53}
54
55#endif
56
57} // namespace Botan
unsigned long auxval_hwcap()
Definition os_utils.cpp:136
bool has_auxval()
Definition os_utils.cpp:124
unsigned long get_auxval(unsigned long id)
Definition os_utils.cpp:156
unsigned long auxval_hwcap2()
Definition os_utils.cpp:146