diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-11-23 23:31:36 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-12-27 02:30:45 +0100 |
| commit | b318ce46f90b4f99f08749df8540f58b74962bee (patch) | |
| tree | 9b046bb3978e04fb788c92a14b5d7aa77327ebe1 /src/KM_prng.cpp | |
| parent | a86a6cf14b3966348f4ea08571aacbba4e54013c (diff) | |
Allow predictable random number and date generation during testing.
Diffstat (limited to 'src/KM_prng.cpp')
| -rwxr-xr-x | src/KM_prng.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/KM_prng.cpp b/src/KM_prng.cpp index d11a330..aebc755 100755 --- a/src/KM_prng.cpp +++ b/src/KM_prng.cpp @@ -64,6 +64,7 @@ public: AES_KEY m_Context; byte_t m_ctr_buf[RNG_BLOCK_SIZE]; Mutex m_Lock; + unsigned int m_cth_test_rng_state; h__RNG() { @@ -97,6 +98,7 @@ public: } // end AutoMutex context set_key(rng_key); + reset(); } // @@ -138,7 +140,20 @@ public: AES_encrypt(m_ctr_buf, tmp, &m_Context); memcpy(buf + gen_count, tmp, len - gen_count); } + + if (cth_test) + { +#ifdef __unix__ + for (unsigned int i = 0; i < len; ++i) + buf[i] = rand_r(&m_cth_test_rng_state); +#endif + } } + + void reset() + { + m_cth_test_rng_state = 1; + } }; @@ -192,6 +207,12 @@ Kumu::FortunaRNG::FillRandom(Kumu::ByteString& Buffer) return Buffer.Data(); } +void +Kumu::FortunaRNG::Reset() +{ + s_RNG->reset(); +} + //------------------------------------------------------------------------------------------ // |
