diff options
| author | weidai <weidai11@users.noreply.github.com> | 2005-01-20 04:19:35 +0000 |
|---|---|---|
| committer | weidai <weidai11@users.noreply.github.com> | 2005-01-20 04:19:35 +0000 |
| commit | b3924f2108c0b0825060e91f6fde8202ce35624d (patch) | |
| tree | 1f61e8bf59450a028415e5a3f08565a6ceb86afe /rng.cpp | |
| parent | 79e29d0de49969af44474cc890cffd7b1d6b1a4b (diff) | |
| download | cryptopp-git-b3924f2108c0b0825060e91f6fde8202ce35624d.tar.gz | |
changes done for FIPS-140 lab code drop
Diffstat (limited to 'rng.cpp')
| -rw-r--r-- | rng.cpp | 21 |
1 files changed, 8 insertions, 13 deletions
@@ -54,21 +54,16 @@ byte LC_RNG::GenerateByte() #ifndef CRYPTOPP_IMPORTS -X917RNG::X917RNG(BlockTransformation *c, const byte *seed, unsigned long deterministicTimeVector) +X917RNG::X917RNG(BlockTransformation *c, const byte *seed, const byte *deterministicTimeVector) : cipher(c), S(cipher->BlockSize()), dtbuf(S), randseed(seed, S), randbuf(S), randbuf_counter(0), - m_deterministicTimeVector(deterministicTimeVector) + m_deterministicTimeVector(deterministicTimeVector, deterministicTimeVector ? S : 0) { - if (m_deterministicTimeVector) - { - memset(dtbuf, 0, S); - memcpy(dtbuf, (byte *)&m_deterministicTimeVector, STDMIN((int)sizeof(m_deterministicTimeVector), S)); - } - else + if (!deterministicTimeVector) { time_t tstamp1 = time(0); xorbuf(dtbuf, (byte *)&tstamp1, STDMIN((int)sizeof(tstamp1), S)); @@ -84,17 +79,17 @@ byte X917RNG::GenerateByte() if (randbuf_counter==0) { // calculate new enciphered timestamp - if (m_deterministicTimeVector) + if (m_deterministicTimeVector.size()) { - xorbuf(dtbuf, (byte *)&m_deterministicTimeVector, STDMIN((int)sizeof(m_deterministicTimeVector), S)); - while (++m_deterministicTimeVector == 0) {} // skip 0 + cipher->ProcessBlock(m_deterministicTimeVector, dtbuf); + IncrementCounterByOne(m_deterministicTimeVector, S); } else { clock_t tstamp = clock(); xorbuf(dtbuf, (byte *)&tstamp, STDMIN((int)sizeof(tstamp), S)); + cipher->ProcessBlock(dtbuf); } - cipher->ProcessBlock(dtbuf); // combine enciphered timestamp with seed xorbuf(randseed, dtbuf, S); @@ -109,7 +104,7 @@ byte X917RNG::GenerateByte() randbuf_counter=S; } - return(randbuf[--randbuf_counter]); + return(randbuf[S-randbuf_counter--]); } #endif |
