Botan 3.6.1
Crypto and TLS for C&
getentropy.cpp
Go to the documentation of this file.
1/*
2* System Call getentropy(2)
3* (C) 2017 Alexander Bluhm (genua GmbH)
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/internal/getentropy.h>
9#include <unistd.h>
10
11// macOS and Android include it in sys/random.h instead
12#if __has_include(<sys/random.h>)
13 #include <sys/random.h>
14#endif
15
16namespace Botan {
17
18/**
19* Gather 256 bytes entropy from getentropy(2). Note that maximum
20* buffer size is limited to 256 bytes. On OpenBSD this does neither
21* block nor fail.
22*/
25
26 if(::getentropy(buf.data(), buf.size()) == 0) {
27 rng.add_entropy(buf.data(), buf.size());
28 return buf.size() * 8;
29 }
30
31 return 0;
32}
33
34} // namespace Botan
size_t poll(RandomNumberGenerator &rng) override
void add_entropy(std::span< const uint8_t > input)
Definition rng.h:76
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61