Remove pre-Crypto++ 5.5 interface
Users of OldRandomPool must use the new interface. All that means is they must call IncorporateEntropy instead of Put, and GenerateBlock instead of Getpull/461/head
parent
4da4ece5a5
commit
76ff3fc03b
53
randpool.cpp
53
randpool.cpp
|
|
@ -88,7 +88,21 @@ OldRandomPool::OldRandomPool(unsigned int poolSize)
|
||||||
|
|
||||||
void OldRandomPool::IncorporateEntropy(const byte *input, size_t length)
|
void OldRandomPool::IncorporateEntropy(const byte *input, size_t length)
|
||||||
{
|
{
|
||||||
OldRandomPool::Put(input, length);
|
size_t t;
|
||||||
|
while (length > (t = pool.size() - addPos))
|
||||||
|
{
|
||||||
|
xorbuf(pool+addPos, input, t);
|
||||||
|
input += t;
|
||||||
|
length -= t;
|
||||||
|
Stir();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length)
|
||||||
|
{
|
||||||
|
xorbuf(pool+addPos, input, length);
|
||||||
|
addPos += length;
|
||||||
|
getPos = pool.size(); // Force stir on get
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OldRandomPool::Stir()
|
void OldRandomPool::Stir()
|
||||||
|
|
@ -106,36 +120,8 @@ void OldRandomPool::Stir()
|
||||||
getPos = key.size();
|
getPos = key.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t OldRandomPool::Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
|
void OldRandomPool::GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size)
|
||||||
{
|
{
|
||||||
CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking);
|
|
||||||
|
|
||||||
size_t t;
|
|
||||||
while (length > (t = pool.size() - addPos))
|
|
||||||
{
|
|
||||||
xorbuf(pool+addPos, inString, t);
|
|
||||||
inString += t;
|
|
||||||
length -= t;
|
|
||||||
Stir();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (length)
|
|
||||||
{
|
|
||||||
xorbuf(pool+addPos, inString, length);
|
|
||||||
addPos += length;
|
|
||||||
getPos = pool.size(); // Force stir on get
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t OldRandomPool::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking)
|
|
||||||
{
|
|
||||||
if (!blocking)
|
|
||||||
throw NotImplemented("OldRandomPool: nonblocking transfer is not implemented by this object");
|
|
||||||
|
|
||||||
lword size = transferBytes;
|
|
||||||
|
|
||||||
while (size > 0)
|
while (size > 0)
|
||||||
{
|
{
|
||||||
if (getPos == pool.size())
|
if (getPos == pool.size())
|
||||||
|
|
@ -144,10 +130,7 @@ size_t OldRandomPool::TransferTo2(BufferedTransformation &target, lword &transfe
|
||||||
target.ChannelPut(channel, pool+getPos, t);
|
target.ChannelPut(channel, pool+getPos, t);
|
||||||
size -= t;
|
size -= t;
|
||||||
getPos += t;
|
getPos += t;
|
||||||
}
|
}}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte OldRandomPool::GenerateByte()
|
byte OldRandomPool::GenerateByte()
|
||||||
{
|
{
|
||||||
|
|
@ -160,7 +143,7 @@ byte OldRandomPool::GenerateByte()
|
||||||
void OldRandomPool::GenerateBlock(byte *outString, size_t size)
|
void OldRandomPool::GenerateBlock(byte *outString, size_t size)
|
||||||
{
|
{
|
||||||
ArraySink sink(outString, size);
|
ArraySink sink(outString, size);
|
||||||
TransferTo(sink, size);
|
GenerateIntoBufferedTransformation(sink, DEFAULT_CHANNEL, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
NAMESPACE_END
|
NAMESPACE_END
|
||||||
|
|
|
||||||
20
randpool.h
20
randpool.h
|
|
@ -72,8 +72,7 @@ private:
|
||||||
//! HKDF.
|
//! HKDF.
|
||||||
//! \sa RandomPool, AutoSeededRandomPool, HKDF, P1363_KDF2, PKCS12_PBKDF, PKCS5_PBKDF2_HMAC
|
//! \sa RandomPool, AutoSeededRandomPool, HKDF, P1363_KDF2, PKCS12_PBKDF, PKCS5_PBKDF2_HMAC
|
||||||
//! \since Crypto++ 6.0 (PGP 2.6.x style)
|
//! \since Crypto++ 6.0 (PGP 2.6.x style)
|
||||||
class CRYPTOPP_DLL OldRandomPool : public RandomNumberGenerator,
|
class CRYPTOPP_DLL OldRandomPool : public RandomNumberGenerator
|
||||||
public Bufferless<BufferedTransformation>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! \brief Construct an OldRandomPool
|
//! \brief Construct an OldRandomPool
|
||||||
|
|
@ -84,26 +83,11 @@ public:
|
||||||
// RandomNumberGenerator interface (Crypto++ 5.5 and above)
|
// RandomNumberGenerator interface (Crypto++ 5.5 and above)
|
||||||
bool CanIncorporateEntropy() const {return true;}
|
bool CanIncorporateEntropy() const {return true;}
|
||||||
void IncorporateEntropy(const byte *input, size_t length);
|
void IncorporateEntropy(const byte *input, size_t length);
|
||||||
|
void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword size);
|
||||||
// BufferedTransformation interface (Crypto++ 5.4 and below)
|
|
||||||
size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking);
|
|
||||||
|
|
||||||
bool AnyRetrievable() const {return true;}
|
|
||||||
lword MaxRetrievable() const {return ULONG_MAX;}
|
|
||||||
|
|
||||||
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
|
|
||||||
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
|
|
||||||
{
|
|
||||||
CRYPTOPP_UNUSED(target); CRYPTOPP_UNUSED(begin); CRYPTOPP_UNUSED(end);
|
|
||||||
CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(blocking);
|
|
||||||
throw NotImplemented("OldRandomPool: CopyRangeTo2() is not supported by this store");
|
|
||||||
}
|
|
||||||
|
|
||||||
byte GenerateByte();
|
byte GenerateByte();
|
||||||
void GenerateBlock(byte *output, size_t size);
|
void GenerateBlock(byte *output, size_t size);
|
||||||
|
|
||||||
void IsolatedInitialize(const NameValuePairs ¶meters) {CRYPTOPP_UNUSED(parameters);}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Stir();
|
void Stir();
|
||||||
|
|
||||||
|
|
|
||||||
20
validat1.cpp
20
validat1.cpp
|
|
@ -722,7 +722,7 @@ bool TestRandomPool()
|
||||||
// with it in 2017. The missing functionality was a barrier to upgrades.
|
// with it in 2017. The missing functionality was a barrier to upgrades.
|
||||||
std::cout << "\nTesting OldRandomPool generator...\n\n";
|
std::cout << "\nTesting OldRandomPool generator...\n\n";
|
||||||
{
|
{
|
||||||
OldRandomPool old1;
|
OldRandomPool old;
|
||||||
static const unsigned int ENTROPY_SIZE = 32;
|
static const unsigned int ENTROPY_SIZE = 32;
|
||||||
|
|
||||||
// https://github.com/weidai11/cryptopp/issues/452
|
// https://github.com/weidai11/cryptopp/issues/452
|
||||||
|
|
@ -734,9 +734,9 @@ bool TestRandomPool()
|
||||||
};
|
};
|
||||||
|
|
||||||
SecByteBlock seed(0x00, 384);
|
SecByteBlock seed(0x00, 384);
|
||||||
old1.Put(seed, seed.size());
|
old.IncorporateEntropy(seed, seed.size());
|
||||||
|
|
||||||
old1.GenerateBlock(result, sizeof(result));
|
old.GenerateBlock(result, sizeof(result));
|
||||||
fail = (0 != ::memcmp(result, expected, sizeof(expected)));
|
fail = (0 != ::memcmp(result, expected, sizeof(expected)));
|
||||||
|
|
||||||
pass &= !fail;
|
pass &= !fail;
|
||||||
|
|
@ -746,20 +746,6 @@ bool TestRandomPool()
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " Expected sequence from PGP-style RandomPool (circa 2007)\n";
|
std::cout << " Expected sequence from PGP-style RandomPool (circa 2007)\n";
|
||||||
|
|
||||||
OldRandomPool old2;
|
|
||||||
old2.IncorporateEntropy(seed, seed.size());
|
|
||||||
|
|
||||||
ArraySink sink(result, sizeof(result));
|
|
||||||
old2.GenerateIntoBufferedTransformation(sink, DEFAULT_CHANNEL, sizeof(result));
|
|
||||||
fail = (0 != ::memcmp(result, expected, sizeof(expected)));
|
|
||||||
|
|
||||||
pass &= !fail;
|
|
||||||
if (fail)
|
|
||||||
std::cout << "FAILED:";
|
|
||||||
else
|
|
||||||
std::cout << "passed:";
|
|
||||||
std::cout << " Expected sequence from PGP-style RandomPool new interface (circa 2007)\n";
|
|
||||||
|
|
||||||
OldRandomPool prng;
|
OldRandomPool prng;
|
||||||
MeterFilter meter(new Redirector(TheBitBucket()));
|
MeterFilter meter(new Redirector(TheBitBucket()));
|
||||||
RandomNumberSource test(prng, 100000, true, new Deflator(new Redirector(meter)));
|
RandomNumberSource test(prng, 100000, true, new Deflator(new Redirector(meter)));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue