diff options
author | lloyd <[email protected]> | 2013-12-25 20:30:16 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2013-12-25 20:30:16 +0000 |
commit | 94b7b07b34057474122a091b2b81b1cdcd9ee8db (patch) | |
tree | a4f11b0385fd8685d8ccb4563b72fe169a8923a4 /src/rng | |
parent | a4a59c29500bbae02273bfb75ddb8318a449e851 (diff) |
Make Serialized_RNG public
Diffstat (limited to 'src/rng')
-rw-r--r-- | src/rng/rng.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/rng/rng.h b/src/rng/rng.h index a8d8ebf28..8664ccbf7 100644 --- a/src/rng/rng.h +++ b/src/rng/rng.h @@ -12,6 +12,7 @@ #include <botan/exceptn.h> #include <string> #include <memory> +#include <mutex> namespace Botan { @@ -120,6 +121,54 @@ class BOTAN_DLL Null_RNG : public RandomNumberGenerator void add_entropy(const byte[], size_t) override {} }; +/** +* Wraps access to a RNG in a mutex +*/ +class BOTAN_DLL Serialized_RNG : public RandomNumberGenerator + { + public: + void randomize(byte out[], size_t len) + { + std::lock_guard<std::mutex> lock(m_mutex); + m_rng->randomize(out, len); + } + + bool is_seeded() const + { + std::lock_guard<std::mutex> lock(m_mutex); + return m_rng->is_seeded(); + } + + void clear() + { + std::lock_guard<std::mutex> lock(m_mutex); + m_rng->clear(); + } + + std::string name() const + { + std::lock_guard<std::mutex> lock(m_mutex); + return m_rng->name(); + } + + void reseed(size_t poll_bits) + { + std::lock_guard<std::mutex> lock(m_mutex); + m_rng->reseed(poll_bits); + } + + void add_entropy(const byte in[], size_t len) + { + std::lock_guard<std::mutex> lock(m_mutex); + m_rng->add_entropy(in, len); + } + + Serialized_RNG() : m_rng(RandomNumberGenerator::make_rng()) {} + private: + mutable std::mutex m_mutex; + std::unique_ptr<RandomNumberGenerator> m_rng; + }; + } #endif |