diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2002-10-17 16:32:28 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2002-10-17 16:32:28 +0000 |
commit | 68bd19cb320b2023aa892c2de15b419edf3f3086 (patch) | |
tree | e508ea100a61e22b1f3d56c3aa2b4479e93da51e /rng.cpp | |
parent | 9242d66857d0199765f58148ea33821438f864e2 (diff) | |
download | cryptopp-68bd19cb320b2023aa892c2de15b419edf3f3086.tar.gz |
bug fixes and KAT for X9.17 RNG
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@11 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'rng.cpp')
-rw-r--r-- | rng.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
@@ -51,20 +51,29 @@ byte LC_RNG::GenerateByte() // ******************************************************** -X917RNG::X917RNG(BlockTransformation *c, const byte *seed) +X917RNG::X917RNG(BlockTransformation *c, const byte *seed, unsigned long deterministicTimeVector) : cipher(c), S(cipher->BlockSize()), dtbuf(S), randseed(seed, S), randbuf(S), - randbuf_counter(0) + randbuf_counter(0), + m_deterministicTimeVector(deterministicTimeVector) { - time_t tstamp1 = time(0); - xorbuf(dtbuf, (byte *)&tstamp1, STDMIN((int)sizeof(tstamp1), S)); - cipher->ProcessBlock(dtbuf); - clock_t tstamp2 = clock(); - xorbuf(dtbuf, (byte *)&tstamp2, STDMIN((int)sizeof(tstamp2), S)); - cipher->ProcessBlock(dtbuf); + if (m_deterministicTimeVector) + { + memset(dtbuf, 0, S); + memcpy(dtbuf, (byte *)&m_deterministicTimeVector, STDMIN((int)sizeof(m_deterministicTimeVector), S)); + } + else + { + time_t tstamp1 = time(0); + xorbuf(dtbuf, (byte *)&tstamp1, STDMIN((int)sizeof(tstamp1), S)); + cipher->ProcessBlock(dtbuf); + clock_t tstamp2 = clock(); + xorbuf(dtbuf, (byte *)&tstamp2, STDMIN((int)sizeof(tstamp2), S)); + cipher->ProcessBlock(dtbuf); + } } byte X917RNG::GenerateByte() @@ -72,8 +81,16 @@ byte X917RNG::GenerateByte() if (randbuf_counter==0) { // calculate new enciphered timestamp - clock_t tstamp = clock(); - xorbuf(dtbuf, (byte *)&tstamp, STDMIN((int)sizeof(tstamp), S)); + if (m_deterministicTimeVector) + { + xorbuf(dtbuf, (byte *)&m_deterministicTimeVector, STDMIN((int)sizeof(m_deterministicTimeVector), S)); + while (++m_deterministicTimeVector == 0) {} // skip 0 + } + else + { + clock_t tstamp = clock(); + xorbuf(dtbuf, (byte *)&tstamp, STDMIN((int)sizeof(tstamp), S)); + } cipher->ProcessBlock(dtbuf); // combine enciphered timestamp with seed |