From 68bd19cb320b2023aa892c2de15b419edf3f3086 Mon Sep 17 00:00:00 2001 From: weidai Date: Thu, 17 Oct 2002 16:32:28 +0000 Subject: 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 --- rng.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'rng.cpp') diff --git a/rng.cpp b/rng.cpp index b16e6bd..0119d30 100644 --- a/rng.cpp +++ b/rng.cpp @@ -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 -- cgit v1.2.1