summaryrefslogtreecommitdiff
path: root/osrng.h
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 /osrng.h
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 'osrng.h')
-rw-r--r--osrng.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/osrng.h b/osrng.h
index 3a40560..c5814a5 100644
--- a/osrng.h
+++ b/osrng.h
@@ -96,6 +96,8 @@ public:
explicit AutoSeededX917RNG(bool blocking = false)
{Reseed(blocking);}
void Reseed(bool blocking = false);
+ // exposed for testing
+ void Reseed(const byte *key, unsigned int keylength, const byte *seed, unsigned long timeVector);
byte GenerateByte();
@@ -107,6 +109,20 @@ private:
};
template <class BLOCK_CIPHER>
+void AutoSeededX917RNG<BLOCK_CIPHER>::Reseed(const byte *key, unsigned int keylength, const byte *seed, unsigned long timeVector)
+{
+ m_rng.reset(new X917RNG(new typename BLOCK_CIPHER::Encryption(key, keylength), seed, timeVector));
+
+ if (FIPS_140_2_ComplianceEnabled())
+ {
+ m_lastBlock.resize(16);
+ m_rng->GenerateBlock(m_lastBlock, m_lastBlock.size());
+ m_counter = 0;
+ m_isDifferent = false;
+ }
+}
+
+template <class BLOCK_CIPHER>
void AutoSeededX917RNG<BLOCK_CIPHER>::Reseed(bool blocking)
{
SecByteBlock seed(BLOCK_CIPHER::BLOCKSIZE + BLOCK_CIPHER::DEFAULT_KEYLENGTH);
@@ -117,15 +133,8 @@ void AutoSeededX917RNG<BLOCK_CIPHER>::Reseed(bool blocking)
key = seed + BLOCK_CIPHER::BLOCKSIZE;
} // check that seed and key don't have same value
while (memcmp(key, seed, STDMIN((unsigned int)BLOCK_CIPHER::BLOCKSIZE, (unsigned int)BLOCK_CIPHER::DEFAULT_KEYLENGTH)) == 0);
- m_rng.reset(new X917RNG(new typename BLOCK_CIPHER::Encryption(key, BLOCK_CIPHER::DEFAULT_KEYLENGTH), seed));
- if (FIPS_140_2_ComplianceEnabled())
- {
- m_lastBlock.resize(16);
- m_rng->GenerateBlock(m_lastBlock, m_lastBlock.size());
- m_counter = 0;
- m_isDifferent = false;
- }
+ Reseed(key, BLOCK_CIPHER::DEFAULT_KEYLENGTH, seed, 0);
}
template <class BLOCK_CIPHER>