Add additional tests
parent
4904a951ce
commit
151ec518e8
29
validat0.cpp
29
validat0.cpp
|
|
@ -233,14 +233,15 @@ bool TestCompressors()
|
||||||
bool TestEncryptors()
|
bool TestEncryptors()
|
||||||
{
|
{
|
||||||
std::cout << "\nTesting Default Encryptors and Decryptors...\n\n";
|
std::cout << "\nTesting Default Encryptors and Decryptors...\n\n";
|
||||||
|
static const unsigned int ENCRYPT_COUNT = 128, ENCRYPT_MAC_COUNT = 64;
|
||||||
bool fail1 = false, fail2 = false, fail3 = false, fail4 = false;
|
bool fail1 = false, fail2 = false, fail3 = false, fail4 = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<128; ++i)
|
for (unsigned int i=0; i<ENCRYPT_COUNT; ++i)
|
||||||
{
|
{
|
||||||
std::string pwd, src, dest, rec;
|
std::string pwd, src, dest, rec;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(0, 0xffff) + 8;
|
unsigned int len = GlobalRNG().GenerateWord32(16, 0xffff);
|
||||||
|
|
||||||
src.resize(len);
|
src.resize(len);
|
||||||
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
|
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
|
||||||
|
|
@ -264,16 +265,16 @@ bool TestEncryptors()
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
else
|
else
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
std::cout << " 128 default encryptions and decryptions" << std::endl;
|
std::cout << " " << ENCRYPT_COUNT << " default encryptions and decryptions" << std::endl;
|
||||||
|
|
||||||
// **************************************************************
|
// **************************************************************
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<128; ++i)
|
for (unsigned int i=0; i<ENCRYPT_MAC_COUNT; ++i)
|
||||||
{
|
{
|
||||||
std::string pwd, src, dest, rec;
|
std::string pwd, src, dest, rec;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(0, 0xffff) + 8;
|
unsigned int len = GlobalRNG().GenerateWord32(16, 0xffff);
|
||||||
|
|
||||||
src.resize(len);
|
src.resize(len);
|
||||||
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
|
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
|
||||||
|
|
@ -329,16 +330,16 @@ bool TestEncryptors()
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
else
|
else
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
std::cout << " 128 default encryptions and decryptions with MAC" << std::endl;
|
std::cout << " " << ENCRYPT_MAC_COUNT << " default encryptions and decryptions with MAC" << std::endl;
|
||||||
|
|
||||||
// **************************************************************
|
// **************************************************************
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<128; ++i)
|
for (unsigned int i=0; i<ENCRYPT_COUNT; ++i)
|
||||||
{
|
{
|
||||||
std::string pwd, src, dest, rec;
|
std::string pwd, src, dest, rec;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(0, 0xffff) + 8;
|
unsigned int len = GlobalRNG().GenerateWord32(16, 0xffff);
|
||||||
|
|
||||||
src.resize(len);
|
src.resize(len);
|
||||||
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
|
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
|
||||||
|
|
@ -362,16 +363,16 @@ bool TestEncryptors()
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
else
|
else
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
std::cout << " 128 legacy encryptions and decryptions" << std::endl;
|
std::cout << " " << ENCRYPT_COUNT << " legacy encryptions and decryptions" << std::endl;
|
||||||
|
|
||||||
// **************************************************************
|
// **************************************************************
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<128; ++i)
|
for (unsigned int i=0; i<ENCRYPT_MAC_COUNT; ++i)
|
||||||
{
|
{
|
||||||
std::string pwd, src, dest, rec;
|
std::string pwd, src, dest, rec;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(0, 0xffff) + 8;
|
unsigned int len = GlobalRNG().GenerateWord32(16, 0xffff);
|
||||||
|
|
||||||
src.resize(len);
|
src.resize(len);
|
||||||
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
|
GlobalRNG().GenerateBlock(reinterpret_cast<byte*>(&src[0]), src.size());
|
||||||
|
|
@ -427,7 +428,7 @@ bool TestEncryptors()
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
else
|
else
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
std::cout << " 128 legacy encryptions and decryptions with MAC" << std::endl;
|
std::cout << " " << ENCRYPT_MAC_COUNT << " legacy encryptions and decryptions with MAC" << std::endl;
|
||||||
|
|
||||||
return !fail1 && !fail2 && !fail3 && !fail4;
|
return !fail1 && !fail2 && !fail3 && !fail4;
|
||||||
}
|
}
|
||||||
|
|
@ -508,7 +509,7 @@ bool TestSharing()
|
||||||
pass &= !fail;
|
pass &= !fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << (fail ? "FAILED:" : "passed:") << " 64 information dispersals\n";
|
std::cout << (fail ? "FAILED:" : "passed:") << " " << INFORMATION_SHARES << " information dispersals\n";
|
||||||
|
|
||||||
// ********** Secret Sharing **********//
|
// ********** Secret Sharing **********//
|
||||||
|
|
||||||
|
|
@ -577,7 +578,7 @@ bool TestSharing()
|
||||||
pass &= !fail;
|
pass &= !fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << (fail ? "FAILED:" : "passed:") << " 64 secret sharings\n";
|
std::cout << (fail ? "FAILED:" : "passed:") << " " << SECRET_SHARES << " secret sharings\n";
|
||||||
|
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
320
validat1.cpp
320
validat1.cpp
|
|
@ -70,7 +70,7 @@ bool ValidateAll(bool thorough)
|
||||||
{
|
{
|
||||||
bool pass=TestSettings();
|
bool pass=TestSettings();
|
||||||
pass=TestOS_RNG() && pass;
|
pass=TestOS_RNG() && pass;
|
||||||
pass=TestAutoSeeded() && pass;
|
pass=TestRandomPool() && pass;
|
||||||
pass=TestAutoSeededX917() && pass;
|
pass=TestAutoSeededX917() && pass;
|
||||||
// pass=TestSecRandom() && pass;
|
// pass=TestSecRandom() && pass;
|
||||||
#if defined(CRYPTOPP_EXTENDED_VALIDATION)
|
#if defined(CRYPTOPP_EXTENDED_VALIDATION)
|
||||||
|
|
@ -459,7 +459,7 @@ bool TestOS_RNG()
|
||||||
RandomNumberGenerator& prng = *rng.get();
|
RandomNumberGenerator& prng = *rng.get();
|
||||||
(void)prng.AlgorithmName();
|
(void)prng.AlgorithmName();
|
||||||
word32 result = prng.GenerateWord32();
|
word32 result = prng.GenerateWord32();
|
||||||
result = prng.GenerateWord32(21, 0xffffffff - 21);
|
result = prng.GenerateWord32((result & 0xff), 0xffffffff - (result & 0xff));
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
|
|
@ -509,7 +509,7 @@ bool TestOS_RNG()
|
||||||
RandomNumberGenerator& prng = *rng.get();
|
RandomNumberGenerator& prng = *rng.get();
|
||||||
(void)prng.AlgorithmName();
|
(void)prng.AlgorithmName();
|
||||||
word32 result = prng.GenerateWord32();
|
word32 result = prng.GenerateWord32();
|
||||||
result = prng.GenerateWord32(21, 0xffffffff - 21);
|
result = prng.GenerateWord32((result & 0xff), 0xffffffff - (result & 0xff));
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
|
|
@ -534,47 +534,41 @@ bool TestOS_RNG()
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(NO_OS_DEPENDENCE) || !defined(OS_RNG_AVAILABLE)
|
#if !defined(NO_OS_DEPENDENCE)
|
||||||
bool TestAutoSeeded()
|
bool TestRandomPool()
|
||||||
{
|
{
|
||||||
return true;
|
std::cout << "\nTesting RandomPool generator...\n\n";
|
||||||
}
|
bool pass=true, fail;
|
||||||
bool TestAutoSeededX917()
|
|
||||||
{
|
{
|
||||||
return true;
|
RandomPool prng;
|
||||||
}
|
|
||||||
#else
|
|
||||||
bool TestAutoSeeded()
|
|
||||||
{
|
|
||||||
// This tests Auto-Seeding and GenerateIntoBufferedTransformation.
|
|
||||||
std::cout << "\nTesting AutoSeeded generator...\n\n";
|
|
||||||
|
|
||||||
AutoSeededRandomPool prng;
|
|
||||||
static const unsigned int ENTROPY_SIZE = 32;
|
static const unsigned int ENTROPY_SIZE = 32;
|
||||||
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)));
|
||||||
|
|
||||||
|
fail = false;
|
||||||
if (meter.GetTotalBytes() < 100000)
|
if (meter.GetTotalBytes() < 100000)
|
||||||
{
|
fail = true;
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
generate = false;
|
|
||||||
}
|
|
||||||
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
|
try
|
||||||
{
|
{
|
||||||
|
fail = false;
|
||||||
prng.DiscardBytes(100000);
|
prng.DiscardBytes(100000);
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
discard = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!discard)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -582,6 +576,7 @@ bool TestAutoSeeded()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
fail = false;
|
||||||
if(prng.CanIncorporateEntropy())
|
if(prng.CanIncorporateEntropy())
|
||||||
{
|
{
|
||||||
SecByteBlock entropy(ENTROPY_SIZE);
|
SecByteBlock entropy(ENTROPY_SIZE);
|
||||||
|
|
@ -591,15 +586,15 @@ bool TestAutoSeeded()
|
||||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
prng.IncorporateEntropy(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*/)
|
catch (const Exception& /*ex*/)
|
||||||
{
|
{
|
||||||
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!incorporate)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -608,28 +603,116 @@ bool TestAutoSeeded()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Miscellaneous for code coverage
|
// Miscellaneous for code coverage
|
||||||
(void)prng.AlgorithmName();
|
(void)prng.AlgorithmName(); // "unknown"
|
||||||
word32 result = prng.GenerateWord32();
|
word32 result = prng.GenerateWord32();
|
||||||
result = prng.GenerateWord32(21, 0xffffffff - 21);
|
result = prng.GenerateWord32((result & 0xff), 0xffffffff - (result & 0xff));
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 0);
|
|
||||||
crop = true;
|
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
crop = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!crop)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " GenerateWord32 and Crop\n";
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
}
|
||||||
|
|
||||||
return generate && discard && incorporate && crop;
|
std::cout << "\nTesting AutoSeeded RandomPool generator...\n\n";
|
||||||
|
{
|
||||||
|
AutoSeededRandomPool prng;
|
||||||
|
static const unsigned int ENTROPY_SIZE = 32;
|
||||||
|
|
||||||
|
MeterFilter meter(new Redirector(TheBitBucket()));
|
||||||
|
RandomNumberSource test(prng, 100000, true, new Deflator(new Redirector(meter)));
|
||||||
|
|
||||||
|
fail = false;
|
||||||
|
if (meter.GetTotalBytes() < 100000)
|
||||||
|
fail = true;
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fail = false;
|
||||||
|
prng.DiscardBytes(100000);
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
fail = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " discarded 10000 bytes" << std::endl;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fail = false;
|
||||||
|
if(prng.CanIncorporateEntropy())
|
||||||
|
{
|
||||||
|
SecByteBlock entropy(ENTROPY_SIZE);
|
||||||
|
GlobalRNG().GenerateBlock(entropy, entropy.SizeInBytes());
|
||||||
|
|
||||||
|
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||||
|
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||||
|
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||||
|
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const Exception& /*ex*/)
|
||||||
|
{
|
||||||
|
fail = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes\n";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Miscellaneous for code coverage
|
||||||
|
fail = false;
|
||||||
|
(void)prng.AlgorithmName(); // "unknown"
|
||||||
|
word32 result = prng.GenerateWord32();
|
||||||
|
result = prng.GenerateWord32((result & 0xff), 0xffffffff - (result & 0xff));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
catch (const Exception&)
|
||||||
|
{
|
||||||
|
fail = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout.flush();
|
||||||
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TestAutoSeededX917()
|
bool TestAutoSeededX917()
|
||||||
|
|
@ -638,31 +721,35 @@ bool TestAutoSeededX917()
|
||||||
std::cout << "\nTesting AutoSeeded X917 generator...\n\n";
|
std::cout << "\nTesting AutoSeeded X917 generator...\n\n";
|
||||||
|
|
||||||
AutoSeededX917RNG<AES> prng;
|
AutoSeededX917RNG<AES> prng;
|
||||||
|
bool pass = true, fail;
|
||||||
static const unsigned int ENTROPY_SIZE = 32;
|
static const unsigned int ENTROPY_SIZE = 32;
|
||||||
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)));
|
||||||
|
|
||||||
|
fail = false;
|
||||||
if (meter.GetTotalBytes() < 100000)
|
if (meter.GetTotalBytes() < 100000)
|
||||||
{
|
fail = true;
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
generate = false;
|
|
||||||
}
|
|
||||||
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
|
try
|
||||||
{
|
{
|
||||||
|
fail = false;
|
||||||
prng.DiscardBytes(100000);
|
prng.DiscardBytes(100000);
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
discard = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!discard)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -670,6 +757,7 @@ bool TestAutoSeededX917()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
fail = false;
|
||||||
if(prng.CanIncorporateEntropy())
|
if(prng.CanIncorporateEntropy())
|
||||||
{
|
{
|
||||||
SecByteBlock entropy(ENTROPY_SIZE);
|
SecByteBlock entropy(ENTROPY_SIZE);
|
||||||
|
|
@ -679,15 +767,15 @@ bool TestAutoSeededX917()
|
||||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
prng.IncorporateEntropy(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*/)
|
catch (const Exception& /*ex*/)
|
||||||
{
|
{
|
||||||
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!incorporate)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -696,28 +784,29 @@ bool TestAutoSeededX917()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Miscellaneous for code coverage
|
// Miscellaneous for code coverage
|
||||||
(void)prng.AlgorithmName();
|
fail = false;
|
||||||
|
(void)prng.AlgorithmName(); // "unknown"
|
||||||
word32 result = prng.GenerateWord32();
|
word32 result = prng.GenerateWord32();
|
||||||
result = prng.GenerateWord32(21, 0xffffffff - 21);
|
result = prng.GenerateWord32((result & 0xff), 0xffffffff - (result & 0xff));
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result), 0);
|
|
||||||
crop = true;
|
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
crop = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!crop)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " GenerateWord32 and Crop\n";
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
|
||||||
return generate && discard && incorporate && crop;
|
std::cout.flush();
|
||||||
|
return pass;
|
||||||
}
|
}
|
||||||
#endif // NO_OS_DEPENDENCE
|
#endif // NO_OS_DEPENDENCE
|
||||||
|
|
||||||
|
|
@ -727,7 +816,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, crop = false;
|
bool pass = true, fail = 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,
|
||||||
|
|
@ -736,41 +825,41 @@ bool TestMersenne()
|
||||||
|
|
||||||
MT19937ar prng;
|
MT19937ar prng;
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(result), sizeof(result));
|
prng.GenerateBlock(reinterpret_cast<byte*>(result), sizeof(result));
|
||||||
equal = (0 == ::memcmp(result, expected, sizeof(expected)));
|
fail = (0 != ::memcmp(result, expected, sizeof(expected)));
|
||||||
|
|
||||||
if (equal)
|
pass &= !fail;
|
||||||
{
|
if (fail)
|
||||||
std::cout << "passed:";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
equal = false;
|
else
|
||||||
}
|
std::cout << "passed:";
|
||||||
std::cout << " Expected sequence from MT19937ar (2002 version)\n";
|
std::cout << " Expected sequence from MT19937ar (2002 version)\n";
|
||||||
|
|
||||||
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)));
|
||||||
|
|
||||||
|
fail = false;
|
||||||
if (meter.GetTotalBytes() < 100000)
|
if (meter.GetTotalBytes() < 100000)
|
||||||
{
|
fail = true;
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
generate = false;
|
|
||||||
}
|
|
||||||
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
|
try
|
||||||
{
|
{
|
||||||
|
fail = false;
|
||||||
prng.DiscardBytes(100000);
|
prng.DiscardBytes(100000);
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
discard = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!discard)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -778,6 +867,7 @@ bool TestMersenne()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
fail = false;
|
||||||
if(prng.CanIncorporateEntropy())
|
if(prng.CanIncorporateEntropy())
|
||||||
{
|
{
|
||||||
SecByteBlock entropy(ENTROPY_SIZE);
|
SecByteBlock entropy(ENTROPY_SIZE);
|
||||||
|
|
@ -787,15 +877,15 @@ bool TestMersenne()
|
||||||
prng.IncorporateEntropy(entropy, entropy.SizeInBytes());
|
prng.IncorporateEntropy(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*/)
|
catch (const Exception& /*ex*/)
|
||||||
{
|
{
|
||||||
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!incorporate)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -805,27 +895,29 @@ bool TestMersenne()
|
||||||
{
|
{
|
||||||
// Miscellaneous for code coverage
|
// Miscellaneous for code coverage
|
||||||
(void)prng.AlgorithmName();
|
(void)prng.AlgorithmName();
|
||||||
result[0] = prng.GenerateWord32();
|
word32 temp = prng.GenerateWord32();
|
||||||
result[0] = prng.GenerateWord32(21, 0xffffffff - 21);
|
temp = prng.GenerateWord32((temp & 0xff), 0xffffffff - (temp & 0xff));
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 4);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 4);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 3);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 3);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 2);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 2);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 1);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 1);
|
||||||
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 0);
|
prng.GenerateBlock(reinterpret_cast<byte*>(&result[0]), 0);
|
||||||
crop = true;
|
fail = false;
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
crop = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!crop)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " GenerateWord32 and Crop\n";
|
std::cout << " GenerateWord32 and Crop\n";
|
||||||
|
|
||||||
return equal && generate && discard && incorporate && crop;
|
std::cout.flush();
|
||||||
|
return pass;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -834,7 +926,7 @@ bool TestRDRAND()
|
||||||
{
|
{
|
||||||
std::cout << "\nTesting RDRAND generator...\n\n";
|
std::cout << "\nTesting RDRAND generator...\n\n";
|
||||||
|
|
||||||
bool entropy = true, compress = true, discard = true, crop = true;
|
bool pass = true, fail = false;
|
||||||
member_ptr<RandomNumberGenerator> rng;
|
member_ptr<RandomNumberGenerator> rng;
|
||||||
|
|
||||||
try {rng.reset(new RDRAND);}
|
try {rng.reset(new RDRAND);}
|
||||||
|
|
@ -858,37 +950,42 @@ bool TestRDRAND()
|
||||||
CRYPTOPP_ASSERT(0 == maurer.BytesNeeded());
|
CRYPTOPP_ASSERT(0 == maurer.BytesNeeded());
|
||||||
const double mv = maurer.GetTestValue();
|
const double mv = maurer.GetTestValue();
|
||||||
if (mv < 0.98f)
|
if (mv < 0.98f)
|
||||||
{
|
fail = true;
|
||||||
std::cout << "FAILED:";
|
|
||||||
entropy = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
std::cout << "passed:";
|
|
||||||
|
|
||||||
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
||||||
StreamState ss(std::cout);
|
StreamState ss(std::cout);
|
||||||
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
|
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
std::cout << " Maurer Randomness Test returned value " << mv << "\n";
|
std::cout << " Maurer Randomness Test returned value " << mv << "\n";
|
||||||
|
|
||||||
|
fail = false;
|
||||||
if (meter.GetTotalBytes() < SIZE)
|
if (meter.GetTotalBytes() < SIZE)
|
||||||
{
|
fail = true;
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
compress = false;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
fail = false;
|
||||||
rdrand.DiscardBytes(SIZE);
|
rdrand.DiscardBytes(SIZE);
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
discard = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!discard)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -902,19 +999,20 @@ bool TestRDRAND()
|
||||||
rdrand.IncorporateEntropy(NULLPTR, 0);
|
rdrand.IncorporateEntropy(NULLPTR, 0);
|
||||||
|
|
||||||
word32 result = rdrand.GenerateWord32();
|
word32 result = rdrand.GenerateWord32();
|
||||||
result = rdrand.GenerateWord32(21, 0xffffffff - 21);
|
result = rdrand.GenerateWord32((result & 0xff), 0xffffffff - (result & 0xff));
|
||||||
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
rdrand.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
crop = true;
|
fail = false;
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
crop = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!crop)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -923,7 +1021,8 @@ bool TestRDRAND()
|
||||||
else
|
else
|
||||||
std::cout << "RDRAND generator not available, skipping test.\n";
|
std::cout << "RDRAND generator not available, skipping test.\n";
|
||||||
|
|
||||||
return entropy && compress && discard && crop;
|
std::cout.flush();
|
||||||
|
return pass;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -932,7 +1031,7 @@ bool TestRDSEED()
|
||||||
{
|
{
|
||||||
std::cout << "\nTesting RDSEED generator...\n\n";
|
std::cout << "\nTesting RDSEED generator...\n\n";
|
||||||
|
|
||||||
bool entropy = true, compress = true, discard = true, crop = true;
|
bool pass = true, fail = false;
|
||||||
member_ptr<RandomNumberGenerator> rng;
|
member_ptr<RandomNumberGenerator> rng;
|
||||||
|
|
||||||
try {rng.reset(new RDSEED);}
|
try {rng.reset(new RDSEED);}
|
||||||
|
|
@ -956,37 +1055,42 @@ bool TestRDSEED()
|
||||||
CRYPTOPP_ASSERT(0 == maurer.BytesNeeded());
|
CRYPTOPP_ASSERT(0 == maurer.BytesNeeded());
|
||||||
const double mv = maurer.GetTestValue();
|
const double mv = maurer.GetTestValue();
|
||||||
if (mv < 0.98f)
|
if (mv < 0.98f)
|
||||||
{
|
fail = true;
|
||||||
std::cout << "FAILED:";
|
|
||||||
entropy = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
std::cout << "passed:";
|
|
||||||
|
|
||||||
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
// Coverity finding, also see http://stackoverflow.com/a/34509163/608639.
|
||||||
StreamState ss(std::cout);
|
StreamState ss(std::cout);
|
||||||
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
|
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6);
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
else
|
||||||
|
std::cout << "passed:";
|
||||||
std::cout << " Maurer Randomness Test returned value " << mv << "\n";
|
std::cout << " Maurer Randomness Test returned value " << mv << "\n";
|
||||||
|
|
||||||
|
fail = false;
|
||||||
if (meter.GetTotalBytes() < SIZE)
|
if (meter.GetTotalBytes() < SIZE)
|
||||||
{
|
fail = true;
|
||||||
|
|
||||||
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
compress = false;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
fail = false;
|
||||||
rdseed.DiscardBytes(SIZE);
|
rdseed.DiscardBytes(SIZE);
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
discard = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!discard)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -1000,19 +1104,20 @@ bool TestRDSEED()
|
||||||
rdseed.IncorporateEntropy(NULLPTR, 0);
|
rdseed.IncorporateEntropy(NULLPTR, 0);
|
||||||
|
|
||||||
word32 result = rdseed.GenerateWord32();
|
word32 result = rdseed.GenerateWord32();
|
||||||
result = rdseed.GenerateWord32(21, 0xffffffff - 21);
|
result = rdseed.GenerateWord32((result & 0xff), 0xffffffff - (result & 0xff));
|
||||||
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 4);
|
||||||
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 3);
|
||||||
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 2);
|
||||||
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
rdseed.GenerateBlock(reinterpret_cast<byte*>(&result), 1);
|
||||||
crop = true;
|
fail = false;
|
||||||
}
|
}
|
||||||
catch (const Exception&)
|
catch (const Exception&)
|
||||||
{
|
{
|
||||||
crop = false;
|
fail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!crop)
|
pass &= !fail;
|
||||||
|
if (fail)
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
else
|
else
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
|
|
@ -1021,7 +1126,8 @@ bool TestRDSEED()
|
||||||
else
|
else
|
||||||
std::cout << "RDSEED generator not available, skipping test.\n";
|
std::cout << "RDSEED generator not available, skipping test.\n";
|
||||||
|
|
||||||
return entropy && compress && discard && crop;
|
std::cout.flush();
|
||||||
|
return pass;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ bool ValidateAll(bool thorough);
|
||||||
bool TestSettings();
|
bool TestSettings();
|
||||||
bool TestOS_RNG();
|
bool TestOS_RNG();
|
||||||
// bool TestSecRandom();
|
// bool TestSecRandom();
|
||||||
bool TestAutoSeeded();
|
bool TestRandomPool();
|
||||||
bool TestAutoSeededX917();
|
bool TestAutoSeededX917();
|
||||||
|
|
||||||
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
|
#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue