9#include <botan/internal/rdseed.h>
11#include <botan/compiler.h>
13#include <botan/internal/cpuid.h>
14#include <botan/internal/target_info.h>
16#if !defined(BOTAN_USE_GCC_INLINE_ASM)
17 #include <immintrin.h>
37 const size_t RDSEED_RETRIES = 1024;
39 for(
size_t i = 0; i != RDSEED_RETRIES; ++i) {
43#if defined(BOTAN_USE_GCC_INLINE_ASM)
44 asm(
"rdseed %0; adcl $0,%1" :
"=r"(r),
"=r"(cf) :
"0"(r),
"1"(cf) :
"cc");
46 cf = _rdseed32_step(&r);
55#if defined(BOTAN_USE_GCC_INLINE_ASM)
56 asm volatile(
"pause");
68 const size_t RDSEED_BYTES = 1024;
69 static_assert(RDSEED_BYTES % 4 == 0,
"Bad RDSEED configuration");
73 seed.reserve(RDSEED_BYTES / 4);
75 for(
size_t p = 0; p != RDSEED_BYTES / 4; ++p) {
84 if(!read_rdseed(seed)) {
90 rng.
add_entropy(
reinterpret_cast<const uint8_t*
>(seed.data()), seed.size() *
sizeof(uint32_t));
static bool has(CPUID::Feature feat)
size_t poll(RandomNumberGenerator &rng) override
void add_entropy(std::span< const uint8_t > input)
#define BOTAN_FUNC_ISA(isa)
std::vector< T, secure_allocator< T > > secure_vector