#pragma once #ifndef MESSMER_CPPUTILS_DATA_THREADSAFEPSEUDORANDOMPOOL_H #define MESSMER_CPPUTILS_DATA_THREADSAFEPSEUDORANDOMPOOL_H #include "../macros.h" namespace cpputils { //TODO Store a static CryptoPP::AutoSeededRandomPool (or multiple ones) and make constructor of // ThreadsafeRandomPool() be lightweight (i.e. not do seeding), so it can be called on each callsite. // Alternatively, use a singleton factory. //TODO Test class ThreadsafePseudoRandomPool { public: ThreadsafePseudoRandomPool() { } void GenerateBlock(byte *data, size_t size) { // TODO Provide multiple randomPools for parallelity instead of locking the only available one std::unique_lock lock(_mutex); _pool.GenerateBlock(data, size); } private: //TODO Make seeding use blocking=true (aka /dev/random instead of /dev/urandom) or offer a configuration option? CryptoPP::AutoSeededRandomPool _pool; std::mutex _mutex; DISALLOW_COPY_AND_ASSIGN(ThreadsafePseudoRandomPool); }; } #endif