aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/rng/system_rng/system_rng.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2015-10-15 09:28:25 -0400
committerJack Lloyd <[email protected]>2015-10-15 09:28:25 -0400
commit83fe87cc13b4dd6285fbc15465c7bd39fdadb53d (patch)
tree8560a2c09cf203ad2f3ddd8d3b84c69c9c635517 /src/lib/rng/system_rng/system_rng.h
parentcf084300d49360d03e1066db005d2cd0abc73f6b (diff)
Add System_RNG which is an instantiatable RNG that uses the system RNG
Previously you couldn't have an unique_ptr<RNG> that might point to either a system rng or an autoseed rng depending on availability. That was already needed in ffi and is useful elsewhere.
Diffstat (limited to 'src/lib/rng/system_rng/system_rng.h')
-rw-r--r--src/lib/rng/system_rng/system_rng.h25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/lib/rng/system_rng/system_rng.h b/src/lib/rng/system_rng/system_rng.h
index cac861618..0f4b94725 100644
--- a/src/lib/rng/system_rng/system_rng.h
+++ b/src/lib/rng/system_rng/system_rng.h
@@ -1,6 +1,6 @@
/*
* System RNG interface
-* (C) 2014 Jack Lloyd
+* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -19,6 +19,29 @@ namespace Botan {
*/
BOTAN_DLL RandomNumberGenerator& system_rng();
+/*
+* Instantiatable reference to the system RNG.
+*/
+class BOTAN_DLL System_RNG : public RandomNumberGenerator
+ {
+ public:
+ System_RNG() : m_rng(system_rng()) {}
+
+ void randomize(Botan::byte out[], size_t len) override { m_rng.randomize(out, len); }
+
+ bool is_seeded() const override { return m_rng.is_seeded(); }
+
+ void clear() override { m_rng.clear(); }
+
+ std::string name() const override { return m_rng.name(); }
+
+ void reseed(size_t poll_bits = 256) override { m_rng.reseed(poll_bits); }
+
+ void add_entropy(const byte in[], size_t len) override { m_rng.add_entropy(in, len); }
+ private:
+ Botan::RandomNumberGenerator& m_rng;
+ };
+
}
#endif