Botan 3.14.1
Crypto and TLS for C&
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
17namespace Botan::HWRNG {
18
22
23BOTAN_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
CPUFeature Feature
Definition cpuid.h:44
std::optional< uint64_t > read_once()
CPUID::Feature feature()