aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/entropy/getentropy/getentropy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/entropy/getentropy/getentropy.cpp')
-rw-r--r--src/lib/entropy/getentropy/getentropy.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/entropy/getentropy/getentropy.cpp b/src/lib/entropy/getentropy/getentropy.cpp
new file mode 100644
index 000000000..56c356eba
--- /dev/null
+++ b/src/lib/entropy/getentropy/getentropy.cpp
@@ -0,0 +1,30 @@
+/*
+* System Call getentropy(2)
+* (C) 2017 Alexander Bluhm (genua GmbH)
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/internal/getentropy.h>
+
+#include <unistd.h>
+
+namespace Botan {
+
+/**
+* Gather BOTAN_SYSTEM_RNG_POLL_REQUEST bytes entropy from getentropy(2).
+* This is 64 bytes, note that maximum buffer size is limited to 256 bytes.
+*/
+size_t Getentropy::poll(RandomNumberGenerator& rng)
+ {
+ secure_vector<uint8_t> buf(BOTAN_SYSTEM_RNG_POLL_REQUEST);
+
+ if(::getentropy(buf.data(), buf.size()) == 0)
+ {
+ rng.add_entropy(buf.data(), buf.size());
+ return buf.size() * 8;
+ }
+
+ return 0;
+ }
+}