From fabd88e4e47bf7024ce75ad7eca95483e1f2eb9a Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Thu, 17 Jun 2021 17:51:52 -0400 Subject: Use GenerateWord32 impl from Crypto++ 5.4 Also see https://groups.google.com/g/cryptopp-users/c/YOl2FGXSp44 --- randpool.cpp | 12 ++++++------ randpool.h | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/randpool.cpp b/randpool.cpp index b1a4f215..e1286282 100644 --- a/randpool.cpp +++ b/randpool.cpp @@ -105,21 +105,21 @@ void OldRandomPool::IncorporateEntropy(const byte *input, size_t length) } } -// Endian swapped on little-endian machines. This is different -// behavior from Crypto++ 5.4. Provide an override to correct it. -// ConditionalByteReverse performs the correction on full words. -// I am not sure this will affect a ranged word. +// GenerateWord32 is overriden and provides Crypto++ 5.4 behavior. word32 OldRandomPool::GenerateWord32 (word32 min, word32 max) { const word32 range = max-min; + const unsigned int maxBytes = BytePrecision(range); const unsigned int maxBits = BitPrecision(range); word32 value; do { - GenerateBlock((byte *)&value, sizeof(value)); - value = ConditionalByteReverse(BIG_ENDIAN_ORDER, value); + value = 0; + for (int i=0; i range); diff --git a/randpool.h b/randpool.h index 51140145..f5866ed8 100644 --- a/randpool.h +++ b/randpool.h @@ -87,8 +87,7 @@ public: byte GenerateByte(); void GenerateBlock(byte *output, size_t size); - // Endian swapped on little-endian machines. This is different - // behavior from Crypto++ 5.4. Provide an override to correct it. + // GenerateWord32 is overriden and provides Crypto++ 5.4 behavior. word32 GenerateWord32 (word32 min=0, word32 max=0xffffffffUL); protected: -- cgit v1.2.1