summaryrefslogtreecommitdiff
path: root/rng.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-17 16:32:28 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-17 16:32:28 +0000
commit68bd19cb320b2023aa892c2de15b419edf3f3086 (patch)
treee508ea100a61e22b1f3d56c3aa2b4479e93da51e /rng.cpp
parent9242d66857d0199765f58148ea33821438f864e2 (diff)
downloadcryptopp-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.cpp37
1 files changed, 27 insertions, 10 deletions
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