Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 <unistd.h>
11
12 namespace Botan {
13
14 /**
15 * Gather 256 bytes entropy from getentropy(2). Note that maximum
16 * buffer size is limited to 256 bytes. On OpenBSD this does neither
17 * block nor fail.
18 */
19 size_t Getentropy::poll(RandomNumberGenerator& rng)
20 {
21 secure_vector<uint8_t> buf(256);
22
23 if(::getentropy(buf.data(), buf.size()) == 0)
24 {
25 rng.add_entropy(buf.data(), buf.size());
26 return buf.size() * 8;
27 }
28
29 return 0;
30 }
31 }
Botan::RandomNumberGenerator::add_entropy
virtual void add_entropy(const uint8_t input[], size_t length)=0
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan
Definition: alg_id.cpp:13
Botan::Getentropy::poll
size_t poll(RandomNumberGenerator &rng) override
Definition: getentropy.cpp:19