Botan
3.14.1
Crypto and TLS for C&
src
lib
utils
hwrng
hwrng_aarch64
hwrng_aarch64.cpp
Go to the documentation of this file.
1
/*
2
* (C) 2026 Mika Tammi
3
* 2026 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#include <botan/internal/hwrng.h>
9
10
#include <botan/internal/isa_extn.h>
11
#include <botan/internal/target_info.h>
12
13
#if !defined(BOTAN_USE_GCC_INLINE_ASM)
14
#include <arm_acle.h>
15
#endif
16
17
namespace
Botan::HWRNG
{
18
19
CPUID::Feature
feature
() {
20
return
CPUID::Feature::RNG
;
21
}
22
23
BOTAN_FN_ISA_RNG std::optional<uint64_t>
read_once
() {
24
uint64_t output = 0;
// NOLINT(*-const-correctness) clang-tidy doesn't understand inline asm
25
26
#if defined(BOTAN_USE_GCC_INLINE_ASM)
27
uint64_t ok = 0;
// NOLINT(*-const-correctness) clang-tidy doesn't understand inline asm
28
// RNDR sets the Z flag if it could not produce a random number
29
// NOLINTNEXTLINE(*-no-assembler)
30
asm
volatile
(
"mrs %0, rndr; cset %1, ne"
:
"=r"
(output),
"=r"
(ok) : :
"cc"
);
31
#else
32
const
bool
ok = (__rndr(&output) == 0);
33
#endif
34
35
if
(ok) {
36
return
output;
37
}
else
{
38
return
std::nullopt;
39
}
40
}
41
42
}
// namespace Botan::HWRNG
Botan::CPUFeature::RNG
@ RNG
Definition
cpuid_features.h:31
Botan::CPUID::Feature
CPUFeature Feature
Definition
cpuid.h:44
Botan::HWRNG
Definition
hwrng.cpp:9
Botan::HWRNG::read_once
std::optional< uint64_t > read_once()
Definition
hwrng_aarch64.cpp:23
Botan::HWRNG::feature
CPUID::Feature feature()
Definition
hwrng_aarch64.cpp:19
Generated by
1.16.1