Added additional tests
parent
f50a515ce0
commit
0c1f7d30ea
103
validat1.cpp
103
validat1.cpp
|
|
@ -66,6 +66,7 @@ bool ValidateAll(bool thorough)
|
|||
bool pass=TestSettings();
|
||||
pass=TestOS_RNG() && pass;
|
||||
pass=TestAutoSeeded() && pass;
|
||||
pass=TestAutoSeededX917() && pass;
|
||||
|
||||
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
|
||||
pass=TestRDRAND() && pass;
|
||||
|
|
@ -890,6 +891,10 @@ bool TestAutoSeeded()
|
|||
{
|
||||
return true;
|
||||
}
|
||||
bool TestAutoSeededX917()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool TestAutoSeeded()
|
||||
{
|
||||
|
|
@ -897,7 +902,8 @@ bool TestAutoSeeded()
|
|||
cout << "\nTesting AutoSeeded generator...\n\n";
|
||||
|
||||
AutoSeededRandomPool prng;
|
||||
bool generate = true, discard = true;
|
||||
static const unsigned int ENTROPY_SIZE = 32;
|
||||
bool generate = true, discard = true, incorporate = false;
|
||||
|
||||
MeterFilter meter(new Redirector(TheBitBucket()));
|
||||
RandomNumberSource test(prng, 100000, true, new Deflator(new Redirector(meter)));
|
||||
|
|
@ -926,7 +932,96 @@ bool TestAutoSeeded()
|
|||
cout << "passed:";
|
||||
cout << " discarded 10000 bytes" << endl;
|
||||
|
||||
return generate && discard;
|
||||
try
|
||||
{
|
||||
if(prng.CanIncorporateEntropy())
|
||||
{
|
||||
SecByteBlock entropy(ENTROPY_SIZE);
|
||||
OS_GenerateRandomBlock(false, entropy, entropy.SizeInBytes());
|
||||
|
||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||
|
||||
incorporate = true;
|
||||
}
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
}
|
||||
|
||||
if (!incorporate)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << endl;
|
||||
|
||||
return generate && discard && incorporate;
|
||||
}
|
||||
|
||||
bool TestAutoSeededX917()
|
||||
{
|
||||
// This tests Auto-Seeding and GenerateIntoBufferedTransformation.
|
||||
cout << "\nTesting AutoSeeded X917 generator...\n\n";
|
||||
|
||||
AutoSeededX917RNG<AES> prng;
|
||||
static const unsigned int ENTROPY_SIZE = 32;
|
||||
bool generate = true, discard = true, incorporate = false;
|
||||
|
||||
MeterFilter meter(new Redirector(TheBitBucket()));
|
||||
RandomNumberSource test(prng, 100000, true, new Deflator(new Redirector(meter)));
|
||||
|
||||
if (meter.GetTotalBytes() < 100000)
|
||||
{
|
||||
cout << "FAILED:";
|
||||
generate = false;
|
||||
}
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << endl;
|
||||
|
||||
try
|
||||
{
|
||||
prng.DiscardBytes(100000);
|
||||
}
|
||||
catch(const Exception&)
|
||||
{
|
||||
discard = false;
|
||||
}
|
||||
|
||||
if (!discard)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " discarded 10000 bytes" << endl;
|
||||
|
||||
try
|
||||
{
|
||||
if(prng.CanIncorporateEntropy())
|
||||
{
|
||||
SecByteBlock entropy(ENTROPY_SIZE);
|
||||
OS_GenerateRandomBlock(false, entropy, entropy.SizeInBytes());
|
||||
|
||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||
|
||||
incorporate = true;
|
||||
}
|
||||
}
|
||||
catch(const Exception& /*ex*/)
|
||||
{
|
||||
}
|
||||
|
||||
if (!incorporate)
|
||||
cout << "FAILED:";
|
||||
else
|
||||
cout << "passed:";
|
||||
cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << endl;
|
||||
|
||||
return generate && discard && incorporate;
|
||||
}
|
||||
#endif // NO_OS_DEPENDENCE
|
||||
|
||||
|
|
@ -951,7 +1046,7 @@ bool TestRDRAND()
|
|||
chsw.AddDefaultRoute(maurer);
|
||||
|
||||
RandomNumberSource rns(rdrand, SIZE, true, new Redirector(chsw));
|
||||
deflator.Flush(false);
|
||||
deflator.Flush(true);
|
||||
|
||||
assert(0 == maurer.BytesNeeded());
|
||||
const double mv = maurer.GetTestValue();
|
||||
|
|
@ -1028,7 +1123,7 @@ bool TestRDSEED()
|
|||
chsw.AddDefaultRoute(maurer);
|
||||
|
||||
RandomNumberSource rns(rdseed, SIZE, true, new Redirector(chsw));
|
||||
deflator.Flush(false);
|
||||
deflator.Flush(true);
|
||||
|
||||
assert(0 == maurer.BytesNeeded());
|
||||
const double mv = maurer.GetTestValue();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ bool ValidateAll(bool thorough);
|
|||
bool TestSettings();
|
||||
bool TestOS_RNG();
|
||||
bool TestAutoSeeded();
|
||||
bool TestAutoSeededX917();
|
||||
|
||||
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
|
||||
bool TestRDRAND();
|
||||
|
|
|
|||
Loading…
Reference in New Issue