mirror of
https://github.com/shadps4-emu/ext-cryptopp.git
synced 2025-02-09 22:52:36 +00:00
Add hash static transform test (Issue 455)
This commit is contained in:
parent
662cccce3b
commit
a2cab93117
2
test.cpp
2
test.cpp
@ -958,6 +958,8 @@ bool Validate(int alg, bool thorough, const char *seedInput)
|
||||
case 9995: result = TestHuffmanCodes(); break;
|
||||
// http://github.com/weidai11/cryptopp/issues/346
|
||||
case 9994: result = TestASN1Parse(); break;
|
||||
// TODO: bug report it
|
||||
case 9993: result = TestSHAStaticTransform(); break;
|
||||
#endif
|
||||
|
||||
default: return false;
|
||||
|
@ -115,6 +115,9 @@ bool ValidateAll(bool thorough)
|
||||
pass=ValidateMD4() && pass;
|
||||
#endif
|
||||
pass=ValidateMD5() && pass;
|
||||
#if defined(CRYPTOPP_EXTENDED_VALIDATION)
|
||||
pass=TestSHAStaticTransform() && pass;
|
||||
#endif
|
||||
pass=ValidateSHA() && pass;
|
||||
|
||||
pass=RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/keccak.txt") && pass;
|
||||
|
247
validat3.cpp
247
validat3.cpp
@ -209,15 +209,258 @@ bool ValidateMD5()
|
||||
return HashModuleTest(md5, testSet, COUNTOF(testSet));
|
||||
}
|
||||
|
||||
#if defined(CRYPTOPP_EXTENDED_VALIDATION)
|
||||
bool TestSHAStaticTransform()
|
||||
{
|
||||
std::cout << "\nSHA static transform suite running...\n\n";
|
||||
static const size_t MAX_PARAM = SHA512::BLOCKSIZE;
|
||||
bool pass=true, fail;
|
||||
|
||||
CRYPTOPP_ALIGN_DATA(16)
|
||||
const byte SM1[MAX_PARAM] = {0};
|
||||
|
||||
CRYPTOPP_ALIGN_DATA(16)
|
||||
const byte SM2[MAX_PARAM] = {
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
|
||||
};
|
||||
|
||||
CRYPTOPP_ALIGN_DATA(16)
|
||||
byte SM3[MAX_PARAM] = {
|
||||
0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12,0x14,0x16,0x18,0x1A,0x1C,0x1E,
|
||||
0x20,0x22,0x24,0x26,0x28,0x2A,0x2C,0x2E,0x30,0x32,0x34,0x36,0x38,0x3A,0x3C,0x3E,
|
||||
0x40,0x42,0x44,0x46,0x48,0x4A,0x4C,0x4E,0x50,0x52,0x54,0x56,0x58,0x5A,0x5C,0x5E,
|
||||
0x60,0x62,0x64,0x66,0x68,0x6A,0x6C,0x6E,0x70,0x72,0x74,0x76,0x78,0x7A,0x7C,0x7E,
|
||||
0x80,0x82,0x84,0x86,0x88,0x8A,0x8C,0x8E,0x90,0x92,0x94,0x96,0x98,0x9A,0x9C,0x9E,
|
||||
0xA0,0xA2,0xA4,0xA6,0xA8,0xAA,0xAC,0xAE,0xB0,0xB2,0xB4,0xB6,0xB8,0xBA,0xBC,0xBE,
|
||||
0xC0,0xC2,0xC4,0xC6,0xC8,0xCA,0xCC,0xCE,0xD0,0xD2,0xD4,0xD6,0xD8,0xDA,0xDC,0xDE,
|
||||
0xE0,0xE2,0xE4,0xE6,0xE8,0xEA,0xEC,0xEE,0xF0,0xF2,0xF4,0xF6,0xF8,0xFA,0xFC,0xFE
|
||||
};
|
||||
|
||||
CRYPTOPP_ALIGN_DATA(16)
|
||||
byte result[MAX_PARAM];
|
||||
|
||||
// SHA1, Message 1
|
||||
{
|
||||
std::memcpy(result, SM1, SHA1::BLOCKSIZE);
|
||||
SHA1::Transform(reinterpret_cast<word32*>(result), reinterpret_cast<const word32*>(SM1));
|
||||
const byte expected[SHA1::DIGESTSIZE] = {
|
||||
0xED,0x47,0x15,0x9E,0xC2,0x91,0xEC,0x57,
|
||||
0xC8,0x8B,0xFA,0x30,0x54,0x5A,0x78,0xC7,
|
||||
0xE3,0xA5,0xEF,0xA7
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA1::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA1::Transform, message 1\n";
|
||||
}
|
||||
|
||||
// SHA1, Message 2
|
||||
{
|
||||
std::memcpy(result, SM2, SHA1::BLOCKSIZE);
|
||||
SHA1::Transform(reinterpret_cast<word32*>(result), reinterpret_cast<const word32*>(SM2));
|
||||
const byte expected[SHA1::DIGESTSIZE] = {
|
||||
0x9B,0x15,0x48,0x3F,0xFA,0x51,0xCE,0x2D,
|
||||
0x0A,0x93,0x1E,0x8A,0x68,0x3B,0x08,0x02,
|
||||
0xE8,0xD6,0x70,0xEF
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA1::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA1::Transform, message 2\n";
|
||||
}
|
||||
|
||||
// SHA1, Message 3
|
||||
{
|
||||
std::memcpy(result, SM3, SHA1::BLOCKSIZE);
|
||||
SHA1::Transform(reinterpret_cast<word32*>(result), reinterpret_cast<const word32*>(SM3));
|
||||
const byte expected[SHA1::DIGESTSIZE] = {
|
||||
0x6D,0x65,0x87,0x41,0xB5,0x50,0x66,0x24,
|
||||
0xAB,0x9B,0x08,0xD2,0xED,0x6E,0x32,0xAC,
|
||||
0xDC,0xC5,0x17,0x67
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA1::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA1::Transform, message 3\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
// SHA256, Message 1
|
||||
{
|
||||
std::memcpy(result, SM1, SHA256::BLOCKSIZE);
|
||||
SHA256::Transform(reinterpret_cast<word32*>(result), reinterpret_cast<const word32*>(SM1));
|
||||
const byte expected[SHA256::DIGESTSIZE] = {
|
||||
0x14,0x16,0xA5,0x7C,0xA8,0x3B,0x5C,0x42,
|
||||
0x2F,0xDD,0x54,0xCE,0xE7,0x0A,0x02,0xC2,
|
||||
0xD1,0x74,0xE5,0xB6,0x0F,0x6D,0x13,0x98,
|
||||
0xCC,0x26,0x7E,0xAE,0xA6,0xE7,0x0B,0xBF
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA256::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA256::Transform, message 1\n";
|
||||
}
|
||||
|
||||
// SHA256, Message 2
|
||||
{
|
||||
std::memcpy(result, SM2, SHA256::BLOCKSIZE);
|
||||
SHA256::Transform(reinterpret_cast<word32*>(result), reinterpret_cast<const word32*>(SM2));
|
||||
const byte expected[SHA256::DIGESTSIZE] = {
|
||||
0x7A,0x12,0x98,0x05,0x6E,0x70,0x11,0xAF,
|
||||
0xFF,0x1F,0x40,0x77,0x49,0xC5,0x30,0xD7,
|
||||
0x67,0xC8,0x84,0x0B,0xA3,0x6C,0x8C,0xA9,
|
||||
0xF9,0xC0,0xF3,0xD7,0x79,0x8B,0xA7,0x06
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA256::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA256::Transform, message 2\n";
|
||||
}
|
||||
|
||||
// SHA256, Message 3
|
||||
{
|
||||
std::memcpy(result, SM3, SHA256::BLOCKSIZE);
|
||||
SHA256::Transform(reinterpret_cast<word32*>(result), reinterpret_cast<const word32*>(SM3));
|
||||
const byte expected[SHA256::DIGESTSIZE] = {
|
||||
0xCB,0x8E,0x2A,0xD0,0x39,0x89,0x15,0xE9,
|
||||
0xFF,0x65,0xDA,0xA6,0x84,0x23,0x96,0xB9,
|
||||
0xCD,0xB5,0x51,0xC1,0x1D,0x21,0xF1,0x9E,
|
||||
0x67,0x8A,0xB0,0xD8,0x34,0x1D,0x06,0x11
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA256::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA256::Transform, message 3\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
// SHA512, Message 1
|
||||
{
|
||||
std::memcpy(result, SM1, SHA512::BLOCKSIZE);
|
||||
SHA512::Transform(reinterpret_cast<word64*>(result), reinterpret_cast<const word64*>(SM1));
|
||||
const byte expected[SHA512::DIGESTSIZE] = {
|
||||
0x30,0xF8,0xEB,0x38,0xA8,0x5D,0x3A,0xAD,
|
||||
0xDB,0xBE,0xFC,0x85,0xFF,0x42,0x71,0x5D,
|
||||
0x99,0xCA,0xF7,0xD6,0x86,0xBF,0xA8,0x7F,
|
||||
0xBF,0x0B,0xD7,0x39,0xB0,0x15,0x6B,0x1C,
|
||||
0x18,0x35,0x92,0x89,0x52,0x51,0xF6,0x29,
|
||||
0x3A,0x8F,0x2E,0x5F,0x1D,0x10,0xD7,0x6F,
|
||||
0x50,0x14,0x53,0x76,0x24,0x8D,0x35,0x1C,
|
||||
0x3C,0xDC,0x56,0xD7,0x99,0x0D,0x8C,0x56
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA512::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA512::Transform, message 1\n";
|
||||
}
|
||||
|
||||
// SHA512, Message 2
|
||||
{
|
||||
std::memcpy(result, SM2, SHA512::BLOCKSIZE);
|
||||
SHA512::Transform(reinterpret_cast<word64*>(result), reinterpret_cast<const word64*>(SM2));
|
||||
const byte expected[SHA512::DIGESTSIZE] = {
|
||||
0xEE,0x51,0xE9,0x96,0x16,0x12,0x0F,0x9B,
|
||||
0x68,0xE7,0x41,0xB7,0x67,0xB4,0xD0,0x41,
|
||||
0x84,0x28,0xB7,0xB3,0xEB,0x41,0x4F,0x56,
|
||||
0xC1,0x5B,0xCB,0xCA,0x0F,0xB4,0x05,0xF8,
|
||||
0x00,0xA9,0x02,0xCF,0xFF,0x9C,0x37,0x3C,
|
||||
0x54,0xC5,0x9A,0x80,0x7F,0xA3,0x17,0x9B,
|
||||
0xAB,0xB6,0x83,0x1C,0x2E,0xFD,0xC9,0x79,
|
||||
0x7A,0x2C,0xC0,0x52,0xE2,0xD9,0x48,0xE9
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA512::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA512::Transform, message 2\n";
|
||||
}
|
||||
|
||||
// SHA512, Message 3
|
||||
{
|
||||
std::memcpy(result, SM3, SHA512::BLOCKSIZE);
|
||||
SHA512::Transform(reinterpret_cast<word64*>(result), reinterpret_cast<const word64*>(SM3));
|
||||
const byte expected[SHA512::DIGESTSIZE] = {
|
||||
0x2F,0xA6,0xE7,0x5B,0xB4,0x3D,0xC5,0x22,
|
||||
0x7B,0x29,0x3B,0xBC,0xDB,0xBC,0x00,0xD3,
|
||||
0x4F,0x28,0xF9,0x33,0xB4,0xA8,0x8D,0x3B,
|
||||
0x96,0xF0,0x91,0xC6,0xE6,0x75,0xD0,0x22,
|
||||
0x8D,0x3F,0x26,0x85,0xCF,0x4E,0xC8,0x36,
|
||||
0xE2,0xF4,0xC0,0xEF,0xD9,0x83,0x8D,0x10,
|
||||
0x73,0x60,0x49,0x40,0xDB,0xA2,0x20,0x1F,
|
||||
0x88,0x4A,0xE8,0xBB,0x85,0x92,0xF7,0xD5
|
||||
};
|
||||
|
||||
fail = !!std::memcmp(result, expected, SHA512::DIGESTSIZE);
|
||||
pass = !fail && pass;
|
||||
|
||||
if (!fail)
|
||||
std::cout << "passed: ";
|
||||
else
|
||||
std::cout << "FAILED: ";
|
||||
std::cout << "SHA512::Transform, message 3\n";
|
||||
}
|
||||
|
||||
return pass;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool ValidateSHA()
|
||||
{
|
||||
std::cout << "\nSHA validation suite running...\n\n";
|
||||
std::cout << "\nSHA validation suite running...\n";
|
||||
return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sha.txt");
|
||||
}
|
||||
|
||||
bool ValidateSHA2()
|
||||
{
|
||||
std::cout << "\nSHA validation suite running...\n\n";
|
||||
std::cout << "\nSHA validation suite running...\n";
|
||||
return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sha.txt");
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,8 @@ bool TestRounding();
|
||||
bool TestHuffmanCodes();
|
||||
// http://github.com/weidai11/cryptopp/issues/346
|
||||
bool TestASN1Parse();
|
||||
// TODO: bug report it
|
||||
bool TestSHAStaticTransform();
|
||||
// Additional tests due to no coverage
|
||||
bool TestCompressors();
|
||||
bool TestEncryptors();
|
||||
|
Loading…
x
Reference in New Issue
Block a user