summaryrefslogtreecommitdiff
path: root/asdcplib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-07-17 15:14:14 +0100
committerCarl Hetherington <cth@carlh.net>2012-07-17 15:14:14 +0100
commiteaac013b4e68dea48fb2c3070b7c7ca59dfd1b96 (patch)
tree782b6af4e27104273afb7713c66c9e1d1dbd2fb4 /asdcplib
parentaa1ea57fbbfe775168dacceb707a1dc80dc02dae (diff)
Hack asdcplib to make its RNG repeatable when we are testing.
Diffstat (limited to 'asdcplib')
-rwxr-xr-xasdcplib/src/KM_prng.cpp10
-rwxr-xr-xasdcplib/src/KM_prng.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/asdcplib/src/KM_prng.cpp b/asdcplib/src/KM_prng.cpp
index 5212595f..3c64bdcc 100755
--- a/asdcplib/src/KM_prng.cpp
+++ b/asdcplib/src/KM_prng.cpp
@@ -48,6 +48,7 @@ using namespace Kumu;
const char* DEV_URANDOM = "/dev/urandom";
#endif // KM_WIN32
+bool Kumu::libdcp_test = false;
const ui32_t RNG_KEY_SIZE = 512UL;
const ui32_t RNG_KEY_SIZE_BITS = 256UL;
@@ -64,6 +65,7 @@ public:
AES_KEY m_Context;
byte_t m_ctr_buf[RNG_BLOCK_SIZE];
Mutex m_Lock;
+ unsigned int m_libdcp_test_rng_state;
h__RNG()
{
@@ -97,6 +99,8 @@ public:
} // end AutoMutex context
set_key(rng_key);
+
+ m_libdcp_test_rng_state = 1;
}
//
@@ -138,6 +142,12 @@ public:
AES_encrypt(m_ctr_buf, tmp, &m_Context);
memcpy(buf + gen_count, tmp, len - gen_count);
}
+
+ if (libdcp_test)
+ {
+ for (unsigned int i = 0; i < len; ++i)
+ buf[i] = rand_r(&m_libdcp_test_rng_state);
+ }
}
};
diff --git a/asdcplib/src/KM_prng.h b/asdcplib/src/KM_prng.h
index 2a909d6f..a1f23288 100755
--- a/asdcplib/src/KM_prng.h
+++ b/asdcplib/src/KM_prng.h
@@ -51,6 +51,7 @@ namespace Kumu
// key_len must be <= 64 (larger values will be truncated)
void Gen_FIPS_186_Value(const byte_t* key_in, ui32_t key_len, byte_t* buf, ui32_t buf_len);
+ extern bool libdcp_test;
} // namespace Kumu