summaryrefslogtreecommitdiff
path: root/rng.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2005-01-20 04:19:35 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2005-01-20 04:19:35 +0000
commit242d67fb17619670d9b757c442dcf2e26d8478a1 (patch)
tree1f61e8bf59450a028415e5a3f08565a6ceb86afe /rng.cpp
parent4b85e6cac0d84aaf65d0695adb137ae956e4e241 (diff)
downloadcryptopp-242d67fb17619670d9b757c442dcf2e26d8478a1.tar.gz
changes done for FIPS-140 lab code drop
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@195 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'rng.cpp')
-rw-r--r--rng.cpp21
1 files changed, 8 insertions, 13 deletions
diff --git a/rng.cpp b/rng.cpp
index 2cd5db4..11634c6 100644
--- a/rng.cpp
+++ b/rng.cpp
@@ -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