Botan 3.8.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/target_info.h>
11
12#if defined(BOTAN_HAS_OS_UTILS)
13 #include <botan/internal/os_utils.h>
14#endif
15
16namespace Botan {
17
18uint32_t CPUID::CPUID_Data::detect_cpu_features(uint32_t allowed) {
19 uint32_t feat = 0;
20
21#if defined(BOTAN_HAS_OS_UTILS)
22
23 if(auto auxval = OS::get_auxval_hwcap()) {
24 const auto [hwcap_neon, hwcap_crypto] = *auxval;
25
26 /*
27 * On systems with getauxval these bits should normally be defined
28 * in bits/auxv.h but some buggy? glibc installs seem to miss them.
29 * These following values are all fixed, for the Linux ELF format,
30 * so we just hardcode them in ARM_hwcap_bit enum.
31 */
32
33 enum class ARM_hwcap_bit : uint64_t {
34 NEON_bit = (1 << 12),
35 AES_bit = (1 << 0),
36 PMULL_bit = (1 << 1),
37 SHA1_bit = (1 << 2),
38 SHA2_bit = (1 << 3),
39 };
40
41 feat |= if_set(hwcap_neon, ARM_hwcap_bit::NEON_bit, CPUFeature::Bit::NEON, allowed);
42
43 if(feat & CPUFeature::Bit::NEON) {
44 feat |= if_set(hwcap_crypto, ARM_hwcap_bit::AES_bit, CPUFeature::Bit::AES, allowed);
45 feat |= if_set(hwcap_crypto, ARM_hwcap_bit::PMULL_bit, CPUFeature::Bit::PMULL, allowed);
46 feat |= if_set(hwcap_crypto, ARM_hwcap_bit::SHA1_bit, CPUFeature::Bit::SHA1, allowed);
47 feat |= if_set(hwcap_crypto, ARM_hwcap_bit::SHA2_bit, CPUFeature::Bit::SHA2, allowed);
48 }
49 }
50#endif
51
52 return feat;
53}
54
55} // namespace Botan
static uint32_t if_set(uint64_t cpuid, T flag, CPUID::Feature bit, uint32_t allowed)
Definition cpuid.h:117
std::optional< std::pair< unsigned long, unsigned long > > get_auxval_hwcap()
Definition os_utils.cpp:136