Testing of RandomNumberGenerator::GenerateWord32 revealed a bug in 
GenerateBlock.

GenerateBlock calls GenerateIntoBufferedTransformation. 
GenerateIntoBufferedTransformation, in turn, calls, GenerateBlock. Ad 
infinitum.

This patch fixes the circularity by calling OS_GenerateRandomBlock using 
the OS's default entropy pool for userspace in a non-blocking mode.

Another way to address t is to have GenerateIntoBufferedTransformation 
throw an Exception with type set to NOT_IMPLEMENTED. But I think that 
course will be less useful.

Any comments or suggestions?

**********

$ cat cryptlib.diff 
diff --git a/cryptlib.cpp b/cryptlib.cpp
index a9ed290..ad173e2 100644
--- a/cryptlib.cpp
+++ b/cryptlib.cpp
@@ -277,13 +277,15 @@ void RandomNumberGenerator::DiscardBytes(size_t n)
     GenerateIntoBufferedTransformation(TheBitBucket(), DEFAULT_CHANNEL, n);
 }
 
+// Avoid bringing in <osrng.h>, which depends on <cryptlib.h>
+extern void OS_GenerateRandomBlock(bool, byte*, size_t);
 void 
RandomNumberGenerator::GenerateIntoBufferedTransformation(BufferedTransformation
 
&target, const std::string &channel, lword length)
 {
     FixedSizeSecBlock<byte, 256> buffer;
     while (length)
     {
         size_t len = UnsignedMin(buffer.size(), length);
-        GenerateBlock(buffer, len);
+        OS_GenerateRandomBlock(false, buffer, len);
         target.ChannelPut(channel, buffer, len);
         length -= len;
     }


-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to