Botan 3.14.1
Crypto and TLS for C&
hwrng.h
Go to the documentation of this file.
1/*
2* (C) 2026 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_HWRNG_H_
8#define BOTAN_HWRNG_H_
9
10#include <botan/types.h>
11#include <botan/internal/cpuid.h>
12#include <optional>
13
14namespace Botan::HWRNG {
15
16/**
17* Return true if the current CPU supports the hardware RNG instruction
18*/
20
21/**
22* Read 64 bits from the hardware RNG
23*
24* Returns nullopt if the instruction repeatedly failed to produce an output,
25* which indicates a hardware fault.
26*
27* Must only be called if available() returns true
28*/
29BOTAN_TEST_API std::optional<uint64_t> read();
30
31/*
32* The following functions are implemented by the architecture specific submodule
33*/
34
35/**
36* Return the CPUID feature which indicates the hardware RNG is available
37*/
39
40/**
41* Make a single attempt to read 64 bits from the hardware RNG
42*
43* Returns nullopt if the instruction indicated failure
44*
45* Must only be called if available() returns true
46*/
47std::optional<uint64_t> read_once();
48
49} // namespace Botan::HWRNG
50
51#endif
#define BOTAN_TEST_API
Definition api.h:41
CPUFeature Feature
Definition cpuid.h:44
std::optional< uint64_t > read_once()
CPUID::Feature feature()
bool available()
Definition hwrng.cpp:11
std::optional< uint64_t > read()
Definition hwrng.cpp:15