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 | |
| parent | 4898f9d60bc621cb464faa00fb50146495d76928 (diff) | |
Add hacks for predictable random number and timestamp generation.
Diffstat (limited to 'src')
| -rwxr-xr-x | src/KM_prng.cpp | 23 | ||||
| -rwxr-xr-x | src/KM_prng.h | 1 | ||||
| -rwxr-xr-x | src/KM_util.cpp | 18 | ||||
| -rwxr-xr-x | src/KM_util.h | 6 |
4 files changed, 46 insertions, 2 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 diff --git a/src/KM_prng.h b/src/KM_prng.h index 172af2b..f4497ed 100755 --- a/src/KM_prng.h +++ b/src/KM_prng.h @@ -45,6 +45,7 @@ namespace Kumu ~FortunaRNG(); const byte_t* FillRandom(byte_t* buf, ui32_t len); const byte_t* FillRandom(ByteString&); + void Reset(); }; diff --git a/src/KM_util.cpp b/src/KM_util.cpp index 4c59c78..804abcb 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -40,6 +40,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <map> #include <string> +bool Kumu::dcpomatic_test = false; + const char* Kumu::Version() { @@ -593,6 +595,13 @@ Kumu::GenRandomValue(UUID& ID) ID.Set(tmp_buf); } +void +Kumu::ResetTestRNG() +{ + FortunaRNG RNG; + RNG.Reset(); +} + // void Kumu::GenRandomUUID(byte_t* buf) @@ -749,7 +758,14 @@ Kumu::write_BER(byte_t* buf, ui64_t val, ui32_t ber_len) // Kumu::Timestamp::Timestamp() : m_TZOffsetMinutes(0) { - m_Timestamp.now(); + if (dcpomatic_test) + { + m_Timestamp.x = 42; + } + else + { + m_Timestamp.now(); + } } Kumu::Timestamp::Timestamp(const Timestamp& rhs) { diff --git a/src/KM_util.h b/src/KM_util.h index 9dcf846..a6b2de7 100755 --- a/src/KM_util.h +++ b/src/KM_util.h @@ -40,6 +40,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Kumu { + extern bool dcpomatic_test; + // The version number declaration and explanation are in ../configure.ac const char* Version(); @@ -421,7 +423,9 @@ namespace Kumu void GenRandomUUID(byte_t* buf); // buf must be UUID_Length or longer void GenRandomValue(UUID&); - + + void ResetTestRNG(); + typedef ArchivableList<UUID> UUIDList; // a self-wiping key container |
