diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-03-16 22:03:56 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-03-21 20:29:50 +0100 |
| commit | 067ac061ce1ade925d64a7c411403455e97d1c38 (patch) | |
| tree | 4bc30038195fa9a8a0c7b2f4987664ca2eeb9ea8 /src/KM_prng.cpp | |
| parent | 4898f9d60bc621cb464faa00fb50146495d76928 (diff) | |
Add hacks for predictable random number and timestamp generation.
Diffstat (limited to 'src/KM_prng.cpp')
| -rwxr-xr-x | src/KM_prng.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/KM_prng.cpp b/src/KM_prng.cpp index f9ec0c0..872bc48 100755 --- a/src/KM_prng.cpp +++ b/src/KM_prng.cpp @@ -36,6 +36,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <KM_mutex.h> #include <string.h> #include <assert.h> +#include <boost/random.hpp> #ifdef HAVE_OPENSSL # define ENABLE_FIPS_186 @@ -69,8 +70,11 @@ namespace{ AES_ctx m_Context; byte_t m_ctr_buf[RNG_BLOCK_SIZE]; Mutex m_Lock; + boost::random::mt19937 _test_rng; + boost::random::uniform_int_distribution<> _test_dist; h__RNG() + : _test_dist(0, 255) { memset(m_ctr_buf, 0, RNG_BLOCK_SIZE); byte_t rng_key[RNG_KEY_SIZE]; @@ -102,6 +106,7 @@ namespace{ } // end AutoMutex context set_key(rng_key); + reset(); } // @@ -145,7 +150,19 @@ namespace{ AES_encrypt(&m_Context, tmp); memcpy(buf + gen_count, tmp, len - gen_count); } + + if (dcpomatic_test) + { + for (unsigned int i = 0; i < len; ++i) + buf[i] = _test_dist(_test_rng); + } } + + void reset() + { + _test_rng.seed(1); + _test_dist.reset(); + } }; } @@ -201,6 +218,12 @@ Kumu::FortunaRNG::FillRandom(Kumu::ByteString& Buffer) } +void +Kumu::FortunaRNG::Reset() +{ + s_RNG->reset(); +} + //------------------------------------------------------------------------------------------ #ifdef ENABLE_FIPS_186 |
