Add DefaultDecryptorWithMAC using binary file test
Also see https://groups.google.com/d/msg/cryptopp-users/QxPxSHkLM-4/pWmoBRuaBQAJpull/723/head
parent
ac43bee698
commit
4ff34ee329
|
|
@ -388,6 +388,7 @@ TestData/aria.dat
|
||||||
TestData/camellia.dat
|
TestData/camellia.dat
|
||||||
TestData/cast128v.dat
|
TestData/cast128v.dat
|
||||||
TestData/cast256v.dat
|
TestData/cast256v.dat
|
||||||
|
TestData/defdmac.bin
|
||||||
TestData/descert.dat
|
TestData/descert.dat
|
||||||
TestData/dh1024.dat
|
TestData/dh1024.dat
|
||||||
TestData/dh2048.dat
|
TestData/dh2048.dat
|
||||||
|
|
|
||||||
Binary file not shown.
53
validat0.cpp
53
validat0.cpp
|
|
@ -153,13 +153,14 @@ bool TestCompressors()
|
||||||
{
|
{
|
||||||
std::cout << "\nTesting Compressors and Decompressors...\n\n";
|
std::cout << "\nTesting Compressors and Decompressors...\n\n";
|
||||||
bool fail1 = false, fail2 = false, fail3 = false;
|
bool fail1 = false, fail2 = false, fail3 = false;
|
||||||
|
const unsigned int COMP_COUNT = 64;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Gzip uses Adler32 checksums. We expect a failure to to happen on occasion.
|
// Gzip uses Adler32 checksums. We expect a failure to to happen on occasion.
|
||||||
// If we see more than 2 failures in a run of 128, then we need to investigate.
|
// If we see more than 2 failures in a run of 128, then we need to investigate.
|
||||||
unsigned int truncatedCount=0;
|
unsigned int truncatedCount=0;
|
||||||
for (unsigned int i = 0; i<128; ++i)
|
for (unsigned int i = 0; i<COMP_COUNT; ++i)
|
||||||
{
|
{
|
||||||
std::string src, dest, rec;
|
std::string src, dest, rec;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
||||||
|
|
@ -226,7 +227,7 @@ bool TestCompressors()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unzip random data. See if we can induce a crash
|
// Unzip random data. See if we can induce a crash
|
||||||
for (unsigned int i = 0; i<128; i++)
|
for (unsigned int i = 0; i<COMP_COUNT; i++)
|
||||||
{
|
{
|
||||||
SecByteBlock src;
|
SecByteBlock src;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
||||||
|
|
@ -239,7 +240,7 @@ bool TestCompressors()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unzip random data. See if we can induce a crash
|
// Unzip random data. See if we can induce a crash
|
||||||
for (unsigned int i = 0; i<128; i++)
|
for (unsigned int i = 0; i<COMP_COUNT; i++)
|
||||||
{
|
{
|
||||||
SecByteBlock src;
|
SecByteBlock src;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
||||||
|
|
@ -274,13 +275,13 @@ bool TestCompressors()
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
else
|
else
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
std::cout << " 128 zips and unzips" << std::endl;
|
std::cout << " " << COMP_COUNT << " zips and unzips" << std::endl;
|
||||||
|
|
||||||
// **************************************************************
|
// **************************************************************
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i<128; ++i)
|
for (unsigned int i = 0; i<COMP_COUNT; ++i)
|
||||||
{
|
{
|
||||||
std::string src, dest, rec;
|
std::string src, dest, rec;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
||||||
|
|
@ -310,7 +311,7 @@ bool TestCompressors()
|
||||||
// **************************************************************
|
// **************************************************************
|
||||||
|
|
||||||
// Inflate random data. See if we can induce a crash
|
// Inflate random data. See if we can induce a crash
|
||||||
for (unsigned int i = 0; i<128; i++)
|
for (unsigned int i = 0; i<COMP_COUNT; i++)
|
||||||
{
|
{
|
||||||
SecByteBlock src;
|
SecByteBlock src;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
||||||
|
|
@ -337,7 +338,7 @@ bool TestCompressors()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inflate random data. See if we can induce a crash
|
// Inflate random data. See if we can induce a crash
|
||||||
for (unsigned int i = 0; i<128; i++)
|
for (unsigned int i = 0; i<COMP_COUNT; i++)
|
||||||
{
|
{
|
||||||
SecByteBlock src;
|
SecByteBlock src;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
||||||
|
|
@ -353,13 +354,13 @@ bool TestCompressors()
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
else
|
else
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
std::cout << " 128 deflates and inflates\n";
|
std::cout << " " << COMP_COUNT << " deflates and inflates\n";
|
||||||
|
|
||||||
// **************************************************************
|
// **************************************************************
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i<128; ++i)
|
for (unsigned int i = 0; i<COMP_COUNT; ++i)
|
||||||
{
|
{
|
||||||
std::string src, dest, rec;
|
std::string src, dest, rec;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
||||||
|
|
@ -389,7 +390,7 @@ bool TestCompressors()
|
||||||
// **************************************************************
|
// **************************************************************
|
||||||
|
|
||||||
// Decompress random data. See if we can induce a crash
|
// Decompress random data. See if we can induce a crash
|
||||||
for (unsigned int i = 0; i<128; i++)
|
for (unsigned int i = 0; i<COMP_COUNT; i++)
|
||||||
{
|
{
|
||||||
SecByteBlock src;
|
SecByteBlock src;
|
||||||
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
unsigned int len = GlobalRNG().GenerateWord32(4, 0xfff);
|
||||||
|
|
@ -416,7 +417,7 @@ bool TestCompressors()
|
||||||
std::cout << "passed:";
|
std::cout << "passed:";
|
||||||
else
|
else
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
std::cout << " 128 zlib decompress and compress" << std::endl;
|
std::cout << " " << COMP_COUNT << " zlib decompress and compress" << std::endl;
|
||||||
|
|
||||||
// **************************************************************
|
// **************************************************************
|
||||||
|
|
||||||
|
|
@ -426,8 +427,30 @@ 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;
|
static const unsigned int ENCRYPT_COUNT = 64, ENCRYPT_MAC_COUNT = 64;
|
||||||
bool fail1 = false, fail2 = false, fail3 = false, fail4 = false;
|
bool fail0 = false, fail1 = false, fail2 = false, fail3 = false, fail4 = false;
|
||||||
|
|
||||||
|
// **************************************************************
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string password = "super secret password";
|
||||||
|
std::string recovered, message = "Now is the time for all good men to come to the aide of their country.";
|
||||||
|
//StringSource(message, true, new DefaultEncryptorWithMAC(password.c_str(), new FileSink("TestData/defdmac.bin")));
|
||||||
|
FileSource("TestData/defdmac.bin", true, new DefaultDecryptorWithMAC(password.c_str(), new StringSink(recovered)));
|
||||||
|
}
|
||||||
|
catch(const Exception&)
|
||||||
|
{
|
||||||
|
fail0 = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fail0)
|
||||||
|
std::cout << "passed:";
|
||||||
|
else
|
||||||
|
std::cout << "FAILED:";
|
||||||
|
std::cout << " cross-platform decryption with MAC of binary file" << std::endl;
|
||||||
|
|
||||||
|
// **************************************************************
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -614,14 +637,14 @@ bool TestEncryptors()
|
||||||
std::cout << "FAILED:";
|
std::cout << "FAILED:";
|
||||||
std::cout << " " << ENCRYPT_MAC_COUNT << " 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 !fail0 && !fail1 && !fail2 && !fail3 && !fail4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Information Dispesal and Secret Sharing
|
// Information Dispesal and Secret Sharing
|
||||||
bool TestSharing()
|
bool TestSharing()
|
||||||
{
|
{
|
||||||
std::cout << "\nInformation Dispersal and Secret Sharing...\n\n";
|
std::cout << "\nInformation Dispersal and Secret Sharing...\n\n";
|
||||||
static const unsigned int INFORMATION_SHARES = 128;
|
static const unsigned int INFORMATION_SHARES = 64;
|
||||||
static const unsigned int SECRET_SHARES = 64;
|
static const unsigned int SECRET_SHARES = 64;
|
||||||
static const unsigned int CHID_LENGTH = 4;
|
static const unsigned int CHID_LENGTH = 4;
|
||||||
bool pass=true, fail=false;
|
bool pass=true, fail=false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue