Botan
3.14.1
Crypto and TLS for C&
src
lib
entropy
getentropy
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
10
#include <botan/rng.h>
11
#include <unistd.h>
12
13
// macOS and Android include it in sys/random.h instead
14
#if __has_include(<sys/random.h>)
15
#include <sys/random.h>
16
#endif
17
18
namespace
Botan
{
19
20
/**
21
* Gather 256 bytes entropy from getentropy(2). Note that maximum
22
* buffer size is limited to 256 bytes. On OpenBSD this does neither
23
* block nor fail.
24
*/
25
void
Getentropy::gather
(
Entropy_Accumulator
& acc) {
26
secure_vector<uint8_t>
buf(256);
27
28
if
(::getentropy(buf.data(), buf.size()) == 0) {
29
acc.
add
(buf, buf.size() * 8);
30
}
31
}
32
33
}
// namespace Botan
Botan::Entropy_Accumulator
Definition
entropy_src.h:33
Botan::Entropy_Accumulator::add
void add(std::span< const uint8_t > data, size_t estimated_entropy_bits)
Definition
entropy_srcs.cpp:183
Botan::Getentropy::gather
void gather(Entropy_Accumulator &acc) override
Definition
getentropy.cpp:25
Botan
Definition
alg_id.cpp:14
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition
secmem.h:128
Generated by
1.16.1