Add StaticGetValidKeyLength tests for MARS, RC5 and RC6 block ciphers (Issue 252)
parent
9767221125
commit
edf7bd8fa6
146
validat1.cpp
146
validat1.cpp
|
|
@ -1966,33 +1966,93 @@ bool ValidateARC4()
|
|||
bool ValidateRC5()
|
||||
{
|
||||
cout << "\nRC5 validation suite running...\n\n";
|
||||
bool pass1 = true, pass2 = true;
|
||||
|
||||
RC5Encryption enc; // 0 to 2040-bits (255-bytes)
|
||||
pass1 = enc.StaticGetValidKeyLength(0) == 0 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(254) == 254 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(255) == 255 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(256) == 255 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
|
||||
|
||||
RC5Decryption dec;
|
||||
pass2 = dec.StaticGetValidKeyLength(0) == 0 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(254) == 254 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(255) == 255 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(256) == 255 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
|
||||
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
|
||||
|
||||
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc5val.dat", true, new HexDecoder);
|
||||
return BlockTransformationTest(VariableRoundsCipherFactory<RC5Encryption, RC5Decryption>(16, 12), valdata);
|
||||
return BlockTransformationTest(VariableRoundsCipherFactory<RC5Encryption, RC5Decryption>(16, 12), valdata) && pass1 && pass2;
|
||||
}
|
||||
|
||||
bool ValidateRC6()
|
||||
{
|
||||
cout << "\nRC6 validation suite running...\n\n";
|
||||
bool pass1 = true, pass2 = true, pass3 = true;
|
||||
|
||||
RC6Encryption enc;
|
||||
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
|
||||
|
||||
RC6Decryption dec;
|
||||
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
|
||||
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
|
||||
|
||||
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc6val.dat", true, new HexDecoder);
|
||||
bool pass = true;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(16), valdata, 2) && pass;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(24), valdata, 2) && pass;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(32), valdata, 2) && pass;
|
||||
return pass;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(16), valdata, 2) && pass3;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(24), valdata, 2) && pass3;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(32), valdata, 2) && pass3;
|
||||
return pass1 && pass2 && pass3;
|
||||
}
|
||||
|
||||
bool ValidateMARS()
|
||||
{
|
||||
cout << "\nMARS validation suite running...\n\n";
|
||||
bool pass1 = true, pass2 = true, pass3 = true;
|
||||
|
||||
MARSEncryption enc;
|
||||
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
|
||||
|
||||
MARSDecryption dec;
|
||||
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
|
||||
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
|
||||
|
||||
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/marsval.dat", true, new HexDecoder);
|
||||
bool pass = true;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(16), valdata, 4) && pass;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(24), valdata, 3) && pass;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(32), valdata, 2) && pass;
|
||||
return pass;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(16), valdata, 4) && pass3;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(24), valdata, 3) && pass3;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(32), valdata, 2) && pass3;
|
||||
return pass1 && pass2 && pass3;
|
||||
}
|
||||
|
||||
bool ValidateRijndael()
|
||||
|
|
@ -2007,6 +2067,8 @@ bool ValidateRijndael()
|
|||
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
|
||||
|
||||
RijndaelDecryption dec;
|
||||
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
|
||||
|
|
@ -2015,6 +2077,8 @@ bool ValidateRijndael()
|
|||
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
|
||||
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
|
||||
|
||||
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rijndael.dat", true, new HexDecoder);
|
||||
|
|
@ -2416,24 +2480,66 @@ bool ValidateBaseCode()
|
|||
bool ValidateSHACAL2()
|
||||
{
|
||||
cout << "\nSHACAL-2 validation suite running...\n\n";
|
||||
bool pass1 = true, pass2 = true, pass3 = true;
|
||||
|
||||
SHACAL2Encryption enc; // 128 to 512-bits (16 to 64-bytes)
|
||||
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(15) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(64) == 64 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(65) == 64 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(128) == 64 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
|
||||
|
||||
SHACAL2Decryption dec; // 128 to 512-bits (16 to 64-bytes)
|
||||
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(15) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(64) == 64 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(65) == 64 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(128) == 64 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
|
||||
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
|
||||
|
||||
bool pass = true;
|
||||
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/shacal2v.dat", true, new HexDecoder);
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(16), valdata, 4) && pass;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(64), valdata, 10) && pass;
|
||||
return pass;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(16), valdata, 4) && pass3;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(64), valdata, 10) && pass3;
|
||||
return pass1 && pass2 && pass3;
|
||||
}
|
||||
|
||||
bool ValidateCamellia()
|
||||
{
|
||||
cout << "\nCamellia validation suite running...\n\n";
|
||||
bool pass1 = true, pass2 = true, pass3 = true;
|
||||
|
||||
CamelliaEncryption enc;
|
||||
pass1 = enc.StaticGetValidKeyLength(8) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(16) == 16 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(24) == 24 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(32) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(64) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(128) == 32 && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(0) == enc.MinKeyLength() && pass1;
|
||||
pass1 = enc.StaticGetValidKeyLength(SIZE_MAX) == enc.MaxKeyLength() && pass1;
|
||||
|
||||
CamelliaDecryption dec;
|
||||
pass2 = dec.StaticGetValidKeyLength(8) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(24) == 24 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(0) == dec.MinKeyLength() && pass2;
|
||||
pass2 = dec.StaticGetValidKeyLength(SIZE_MAX) == dec.MaxKeyLength() && pass2;
|
||||
cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n";
|
||||
|
||||
bool pass = true;
|
||||
FileSource valdata(CRYPTOPP_DATA_DIR "TestData/camellia.dat", true, new HexDecoder);
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(16), valdata, 15) && pass;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(24), valdata, 15) && pass;
|
||||
pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(32), valdata, 15) && pass;
|
||||
return pass;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(16), valdata, 15) && pass3;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(24), valdata, 15) && pass3;
|
||||
pass3 = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(32), valdata, 15) && pass3;
|
||||
return pass1 && pass2 && pass3;
|
||||
}
|
||||
|
||||
bool ValidateSalsa()
|
||||
|
|
|
|||
Loading…
Reference in New Issue