summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-06-17 17:51:52 -0400
committerJeffrey Walton <noloader@gmail.com>2021-06-17 17:51:52 -0400
commitfabd88e4e47bf7024ce75ad7eca95483e1f2eb9a (patch)
treef5578c0c88f17f49453a630ba10014c944485639
parent89424327e5541ca433de0c332dfb8c0502776fbf (diff)
downloadcryptopp-git-fabd88e4e47bf7024ce75ad7eca95483e1f2eb9a.tar.gz
Use GenerateWord32 impl from Crypto++ 5.4
Also see https://groups.google.com/g/cryptopp-users/c/YOl2FGXSp44
-rw-r--r--randpool.cpp12
-rw-r--r--randpool.h3
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<maxBytes; i++)
+ value = (value << 8) | GenerateByte();
+
value = Crop(value, maxBits);
} while (value > 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: