Added additional tests
parent
3ea8e0655f
commit
374b8a419f
206
validat1.cpp
206
validat1.cpp
|
|
@ -453,6 +453,31 @@ bool TestOS_RNG()
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " " << total << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
std::cout << " " << total << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Miscellaneous for code coverage
|
||||||
|
RandomNumberGenerator& prng = *rng.get();
|
||||||
|
(void)prng.AlgorithmName();
|
||||||
|
word32 result = prng.GenerateWord32();
|
||||||
|
result = prng.GenerateWord32(21, 0xffffffff - 21);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 0);
|
||||||
|
pass = true;
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
pass = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pass)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout << "\nNo operating system provided blocking random number generator, skipping test." << std::endl;
|
std::cout << "\nNo operating system provided blocking random number generator, skipping test." << std::endl;
|
||||||
|
|
@ -478,6 +503,31 @@ bool TestOS_RNG()
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
std::cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Miscellaneous for code coverage
|
||||||
|
RandomNumberGenerator& prng = *rng.get();
|
||||||
|
(void)prng.AlgorithmName();
|
||||||
|
word32 result = prng.GenerateWord32();
|
||||||
|
result = prng.GenerateWord32(21, 0xffffffff - 21);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 0);
|
||||||
|
pass = true;
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
pass = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pass)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout << "\nNo operating system provided nonblocking random number generator, skipping test." << std::endl;
|
std::cout << "\nNo operating system provided nonblocking random number generator, skipping test." << std::endl;
|
||||||
|
|
@ -502,7 +552,7 @@ bool TestAutoSeeded()
|
||||||
|
|
||||||
AutoSeededRandomPool prng;
|
AutoSeededRandomPool prng;
|
||||||
static const unsigned int ENTROPY_SIZE = 32;
|
static const unsigned int ENTROPY_SIZE = 32;
|
||||||
bool generate = true, discard = true, incorporate = false;
|
bool generate = true, discard = true, incorporate = false, crop = false;
|
||||||
|
|
||||||
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)));
|
||||||
|
|
@ -554,9 +604,33 @@ bool TestAutoSeeded()
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << std::endl;
|
std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes\n";
|
||||||
|
|
||||||
return generate && discard && incorporate;
|
try
|
||||||
|
{
|
||||||
|
// Miscellaneous for code coverage
|
||||||
|
(void)prng.AlgorithmName();
|
||||||
|
word32 result = prng.GenerateWord32();
|
||||||
|
result = prng.GenerateWord32(21, 0xffffffff - 21);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 0);
|
||||||
|
crop = true;
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
crop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!crop)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
|
||||||
|
return generate && discard && incorporate && crop;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TestAutoSeededX917()
|
bool TestAutoSeededX917()
|
||||||
|
|
@ -566,7 +640,7 @@ bool TestAutoSeededX917()
|
||||||
|
|
||||||
AutoSeededX917RNG<AES> prng;
|
AutoSeededX917RNG<AES> prng;
|
||||||
static const unsigned int ENTROPY_SIZE = 32;
|
static const unsigned int ENTROPY_SIZE = 32;
|
||||||
bool generate = true, discard = true, incorporate = false;
|
bool generate = true, discard = true, incorporate = false, crop = false;
|
||||||
|
|
||||||
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)));
|
||||||
|
|
@ -618,9 +692,33 @@ bool TestAutoSeededX917()
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << std::endl;
|
std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes\n";
|
||||||
|
|
||||||
return generate && discard && incorporate;
|
try
|
||||||
|
{
|
||||||
|
// Miscellaneous for code coverage
|
||||||
|
(void)prng.AlgorithmName();
|
||||||
|
word32 result = prng.GenerateWord32();
|
||||||
|
result = prng.GenerateWord32(21, 0xffffffff - 21);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 0);
|
||||||
|
crop = true;
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
crop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!crop)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
|
||||||
|
return generate && discard && incorporate && crop;
|
||||||
}
|
}
|
||||||
#endif // NO_OS_DEPENDENCE
|
#endif // NO_OS_DEPENDENCE
|
||||||
|
|
||||||
|
|
@ -630,7 +728,7 @@ bool TestMersenne()
|
||||||
std::cout << "\nTesting Mersenne Twister...\n\n";
|
std::cout << "\nTesting Mersenne Twister...\n\n";
|
||||||
|
|
||||||
static const unsigned int ENTROPY_SIZE = 32;
|
static const unsigned int ENTROPY_SIZE = 32;
|
||||||
bool equal = true, generate = true, discard = true, incorporate = false;
|
bool equal = true, generate = true, discard = true, incorporate = false, crop = false;
|
||||||
|
|
||||||
// First 10; http://create.stephan-brumme.com/mersenne-twister/
|
// First 10; http://create.stephan-brumme.com/mersenne-twister/
|
||||||
word32 result[10], expected[10] = {0xD091BB5C, 0x22AE9EF6,
|
word32 result[10], expected[10] = {0xD091BB5C, 0x22AE9EF6,
|
||||||
|
|
@ -702,9 +800,33 @@ bool TestMersenne()
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << std::endl;
|
std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes\n";
|
||||||
|
|
||||||
return equal && generate && discard && incorporate;
|
try
|
||||||
|
{
|
||||||
|
// Miscellaneous for code coverage
|
||||||
|
(void)prng.AlgorithmName();
|
||||||
|
result[0] = prng.GenerateWord32();
|
||||||
|
result[0] = prng.GenerateWord32(21, 0xffffffff - 21);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 4);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 3);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 2);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 1);
|
||||||
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 0);
|
||||||
|
crop = true;
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
crop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!crop)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
|
||||||
|
return equal && generate && discard && incorporate && crop;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -713,7 +835,7 @@ bool TestRDRAND()
|
||||||
{
|
{
|
||||||
// Testing on 6th generation i7 shows RDRAND needs less than 8 retries for 10K bytes.
|
// Testing on 6th generation i7 shows RDRAND needs less than 8 retries for 10K bytes.
|
||||||
RDRAND rdrand;
|
RDRAND rdrand;
|
||||||
bool entropy = true, compress = true, discard = true;
|
bool entropy = true, compress = true, discard = true, crop = true;
|
||||||
static const unsigned int SIZE = 10000;
|
static const unsigned int SIZE = 10000;
|
||||||
|
|
||||||
if (HasRDRAND())
|
if (HasRDRAND())
|
||||||
|
|
@ -773,12 +895,34 @@ bool TestRDRAND()
|
||||||
else
|
else
|
||||||
std::cout << "\nRDRAND generator not available, skipping test.\n";
|
std::cout << "\nRDRAND generator not available, skipping test.\n";
|
||||||
|
|
||||||
// Squash code coverage warnings on unused functions
|
try
|
||||||
(void)rdrand.AlgorithmName();
|
{
|
||||||
(void)rdrand.CanIncorporateEntropy();
|
// Miscellaneous for code coverage
|
||||||
rdrand.IncorporateEntropy(NULLPTR, 0);
|
(void)rdrand.AlgorithmName();
|
||||||
|
(void)rdrand.CanIncorporateEntropy();
|
||||||
|
rdrand.IncorporateEntropy(NULLPTR, 0);
|
||||||
|
|
||||||
return entropy && compress && discard;
|
word32 result = rdrand.GenerateWord32();
|
||||||
|
result = rdrand.GenerateWord32(21, 0xffffffff - 21);
|
||||||
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 0);
|
||||||
|
crop = true;
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
crop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!crop)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
|
||||||
|
return entropy && compress && discard && crop;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -788,7 +932,7 @@ bool TestRDSEED()
|
||||||
// Testing on 5th generation i5 shows RDSEED needs about 128 retries for 10K bytes
|
// Testing on 5th generation i5 shows RDSEED needs about 128 retries for 10K bytes
|
||||||
// on 64-bit/amd64 VM, and it needs more for an 32-bit/i686 VM.
|
// on 64-bit/amd64 VM, and it needs more for an 32-bit/i686 VM.
|
||||||
RDSEED rdseed;
|
RDSEED rdseed;
|
||||||
bool entropy = true, compress = true, discard = true;
|
bool entropy = true, compress = true, discard = true, crop = true;
|
||||||
static const unsigned int SIZE = 10000;
|
static const unsigned int SIZE = 10000;
|
||||||
|
|
||||||
if (HasRDSEED())
|
if (HasRDSEED())
|
||||||
|
|
@ -848,10 +992,32 @@ bool TestRDSEED()
|
||||||
else
|
else
|
||||||
std::cout << "\nRDSEED generator not available, skipping test.\n";
|
std::cout << "\nRDSEED generator not available, skipping test.\n";
|
||||||
|
|
||||||
// Squash code coverage warnings on unused functions
|
try
|
||||||
(void)rdseed.AlgorithmName();
|
{
|
||||||
(void)rdseed.CanIncorporateEntropy();
|
// Miscellaneous for code coverage
|
||||||
rdseed.IncorporateEntropy(NULLPTR, 0);
|
(void)rdseed.AlgorithmName();
|
||||||
|
(void)rdseed.CanIncorporateEntropy();
|
||||||
|
rdseed.IncorporateEntropy(NULLPTR, 0);
|
||||||
|
|
||||||
|
word32 result = rdseed.GenerateWord32();
|
||||||
|
result = rdseed.GenerateWord32(21, 0xffffffff - 21);
|
||||||
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 0);
|
||||||
|
crop = true;
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
crop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!crop)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
|
||||||
return entropy && compress && discard;
|
return entropy && compress && discard;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue