from Jeffery Walton: move *.dat files into TestData, make Integer operator<< respect ios::uppercase flag

pull/2/head
weidai 2009-03-12 01:55:02 +00:00
parent 94776a744e
commit 1b88e58600
58 changed files with 53 additions and 47 deletions

1
TestData/dlie1024.dat Normal file
View File

@ -0,0 +1 @@
308201370201003082011706072A8648CE3804013082010A02818100D4EC6B7A18416519C76766726B3D2D5F054D107B30E97691B15EB0DCDF452B77F10E12C14450AB107BE349C2DF3A2DBD9D844A24ABA21B328D568E8EC6B959E70BADE5C49879AE4447F643360523469B55AFDC459B45634F657AA79918772F2BA9508ACD43C95C16650A1251B8173EBA1B9B59FE8C57F6240EA49A4FE8855CEF0281806A7635BD0C20B28CE3B3B339359E96AF82A6883D9874BB48D8AF586E6FA295BBF8870960A22855883DF1A4E16F9D16DECEC2251255D10D9946AB4747635CACF385D6F2E24C3CD72223FB219B0291A34DAAD7EE22CDA2B1A7B2BD53CC8C3B9795D4A84566A1E4AE0B32850928DC0B9F5D0DCDACFF462BFB1207524D27F442AE77020102041702150C9C14EEFA749DCE9A2A4B7065768767BA48BBB62F

1
TestData/dlie2048.dat Normal file
View File

@ -0,0 +1 @@
308202410201003082021906072A8648CE3804013082020C0282010100A8E87254E7F56CB5857786364ACC39F2A0F79FFF8ED6C62C64EE45FC1C775CDDBFD9CBCEF8262DBD2CECE4E5AFECA239B9B4B7D3CBA228366500F5B2203CA6C0CB0AB6698F73921B4831BA598DFA8268A07368A64774C77808AB7CB7978F839304B10567F8C9C34F8DBDB66BB928EDE6327773AA6C20A8F4E9C2AE0C66A0516E057BBC87760CF39270726F1863260CD5ADDAF366318E7029851A6F85B2349DF29629319A3662354DBCAD0789D02AC6BD804C06523900166501041963BD7EFFE0069694A54F4542172A29B1F09D26E3F052AE5274A898058BE549650BC2066DDFDB84D582E6503AF42BCB2B674F2A2A77C54678FD622FFCA2D9718BF8B0525AEF028201005474392A73FAB65AC2BBC31B25661CF9507BCFFFC76B6316327722FE0E3BAE6EDFECE5E77C1316DE96767272D7F6511CDCDA5BE9E5D1141B32807AD9101E536065855B34C7B9C90DA418DD2CC6FD41345039B45323BA63BC0455BE5BCBC7C1C9825882B3FC64E1A7C6DEDB35DC9476F3193BB9D53610547A74E15706335028B702BDDE43BB0679C93839378C3193066AD6ED79B318C73814C28D37C2D91A4EF94B1498CD1B311AA6DE5683C4E815635EC02603291C800B3280820CB1DEBF7FF0034B4A52A7A2A10B9514D8F84E9371F82957293A544C02C5F2A4B285E10336EFEDC26AC173281D7A15E595B3A795153BE2A33C7EB117FE516CB8C5FC58292D77020102041F021D031D7EC405D3E11D031B7B66DF9EFFCC5173B9B1639E4EC920731484EE

View File

@ -3402,11 +3402,8 @@ std::ostream& operator<<(std::ostream& out, const Integer &a)
suffix = '.';
}
SecBlock<char> s(a.BitCount() / (BitPrecision(base)-1) + 1);
Integer temp1=a, temp2;
unsigned i=0;
const char vec[]="0123456789ABCDEF";
if (a.IsNegative())
{
out << '-';
@ -3416,12 +3413,19 @@ std::ostream& operator<<(std::ostream& out, const Integer &a)
if (!a)
out << '0';
static const char upper[]="0123456789ABCDEF";
static const char lower[]="0123456789abcdef";
const char* vec = (out.flags() & std::ios::uppercase) ? upper : lower;
unsigned i=0;
SecBlock<char> s(a.BitCount() / (BitPrecision(base)-1) + 1);
while (!!temp1)
{
word digit;
Integer::Divide(digit, temp2, temp1, base);
s[i++]=vec[digit];
temp1=temp2;
temp1.swap(temp2);
}
while (i--)

View File

@ -507,12 +507,12 @@ bool ValidateDES()
{
cout << "\nDES validation suite running...\n\n";
FileSource valdata("descert.dat", true, new HexDecoder);
FileSource valdata("TestData/descert.dat", true, new HexDecoder);
bool pass = BlockTransformationTest(FixedRoundsCipherFactory<DESEncryption, DESDecryption>(), valdata);
cout << "\nTesting EDE2, EDE3, and XEX3 variants...\n\n";
FileSource valdata1("3desval.dat", true, new HexDecoder);
FileSource valdata1("TestData/3desval.dat", true, new HexDecoder);
pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_EDE2_Encryption, DES_EDE2_Decryption>(), valdata1, 1) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_EDE3_Encryption, DES_EDE3_Decryption>(), valdata1, 1) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_XEX3_Encryption, DES_XEX3_Decryption>(), valdata1, 1) && pass;
@ -826,7 +826,7 @@ bool ValidateIDEA()
{
cout << "\nIDEA validation suite running...\n\n";
FileSource valdata("ideaval.dat", true, new HexDecoder);
FileSource valdata("TestData/ideaval.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<IDEAEncryption, IDEADecryption>(), valdata);
}
@ -834,7 +834,7 @@ bool ValidateSAFER()
{
cout << "\nSAFER validation suite running...\n\n";
FileSource valdata("saferval.dat", true, new HexDecoder);
FileSource valdata("TestData/saferval.dat", true, new HexDecoder);
bool pass = true;
pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_K_Encryption, SAFER_K_Decryption>(8,6), valdata, 4) && pass;
pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_K_Encryption, SAFER_K_Decryption>(16,12), valdata, 4) && pass;
@ -847,7 +847,7 @@ bool ValidateRC2()
{
cout << "\nRC2 validation suite running...\n\n";
FileSource valdata("rc2val.dat", true, new HexDecoder);
FileSource valdata("TestData/rc2val.dat", true, new HexDecoder);
HexEncoder output(new FileSink(cout));
SecByteBlock plain(RC2Encryption::BLOCKSIZE), cipher(RC2Encryption::BLOCKSIZE), out(RC2Encryption::BLOCKSIZE), outplain(RC2Encryption::BLOCKSIZE);
SecByteBlock key(128);
@ -1057,7 +1057,7 @@ bool ValidateRC5()
{
cout << "\nRC5 validation suite running...\n\n";
FileSource valdata("rc5val.dat", true, new HexDecoder);
FileSource valdata("TestData/rc5val.dat", true, new HexDecoder);
return BlockTransformationTest(VariableRoundsCipherFactory<RC5Encryption, RC5Decryption>(16, 12), valdata);
}
@ -1065,7 +1065,7 @@ bool ValidateRC6()
{
cout << "\nRC6 validation suite running...\n\n";
FileSource valdata("rc6val.dat", true, new HexDecoder);
FileSource valdata("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;
@ -1077,7 +1077,7 @@ bool ValidateMARS()
{
cout << "\nMARS validation suite running...\n\n";
FileSource valdata("marsval.dat", true, new HexDecoder);
FileSource valdata("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;
@ -1089,7 +1089,7 @@ bool ValidateRijndael()
{
cout << "\nRijndael (AES) validation suite running...\n\n";
FileSource valdata("rijndael.dat", true, new HexDecoder);
FileSource valdata("TestData/rijndael.dat", true, new HexDecoder);
bool pass = true;
pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(16), valdata, 4) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(24), valdata, 3) && pass;
@ -1102,7 +1102,7 @@ bool ValidateTwofish()
{
cout << "\nTwofish validation suite running...\n\n";
FileSource valdata("twofishv.dat", true, new HexDecoder);
FileSource valdata("TestData/twofishv.dat", true, new HexDecoder);
bool pass = true;
pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(16), valdata, 4) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(24), valdata, 3) && pass;
@ -1114,7 +1114,7 @@ bool ValidateSerpent()
{
cout << "\nSerpent validation suite running...\n\n";
FileSource valdata("serpentv.dat", true, new HexDecoder);
FileSource valdata("TestData/serpentv.dat", true, new HexDecoder);
bool pass = true;
pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(16), valdata, 4) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(24), valdata, 3) && pass;
@ -1160,7 +1160,7 @@ bool ValidateThreeWay()
{
cout << "\n3-WAY validation suite running...\n\n";
FileSource valdata("3wayval.dat", true, new HexDecoder);
FileSource valdata("TestData/3wayval.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<ThreeWayEncryption, ThreeWayDecryption>(), valdata);
}
@ -1168,7 +1168,7 @@ bool ValidateGOST()
{
cout << "\nGOST validation suite running...\n\n";
FileSource valdata("gostval.dat", true, new HexDecoder);
FileSource valdata("TestData/gostval.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<GOSTEncryption, GOSTDecryption>(), valdata);
}
@ -1176,7 +1176,7 @@ bool ValidateSHARK()
{
cout << "\nSHARK validation suite running...\n\n";
FileSource valdata("sharkval.dat", true, new HexDecoder);
FileSource valdata("TestData/sharkval.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SHARKEncryption, SHARKDecryption>(), valdata);
}
@ -1186,14 +1186,14 @@ bool ValidateCAST()
cout << "\nCAST-128 validation suite running...\n\n";
FileSource val128("cast128v.dat", true, new HexDecoder);
FileSource val128("TestData/cast128v.dat", true, new HexDecoder);
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(16), val128, 1) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(10), val128, 1) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(5), val128, 1) && pass;
cout << "\nCAST-256 validation suite running...\n\n";
FileSource val256("cast256v.dat", true, new HexDecoder);
FileSource val256("TestData/cast256v.dat", true, new HexDecoder);
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(16), val256, 1) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(24), val256, 1) && pass;
pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(32), val256, 1) && pass;
@ -1205,7 +1205,7 @@ bool ValidateSquare()
{
cout << "\nSquare validation suite running...\n\n";
FileSource valdata("squareva.dat", true, new HexDecoder);
FileSource valdata("TestData/squareva.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SquareEncryption, SquareDecryption>(), valdata);
}
@ -1213,7 +1213,7 @@ bool ValidateSKIPJACK()
{
cout << "\nSKIPJACK validation suite running...\n\n";
FileSource valdata("skipjack.dat", true, new HexDecoder);
FileSource valdata("TestData/skipjack.dat", true, new HexDecoder);
return BlockTransformationTest(FixedRoundsCipherFactory<SKIPJACKEncryption, SKIPJACKDecryption>(), valdata);
}
@ -1317,7 +1317,7 @@ bool ValidateSHACAL2()
cout << "\nSHACAL-2 validation suite running...\n\n";
bool pass = true;
FileSource valdata("shacal2v.dat", true, new HexDecoder);
FileSource valdata("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;
@ -1328,7 +1328,7 @@ bool ValidateCamellia()
cout << "\nCamellia validation suite running...\n\n";
bool pass = true;
FileSource valdata("camellia.dat", true, new HexDecoder);
FileSource valdata("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;

View File

@ -268,7 +268,7 @@ bool ValidateRSA()
"\x69\x94\xac\x04\xf3\x41\xb5\x7d\x05\x20\x2d\x42\x8f\xb2\xa2\x7b"
"\x5c\x77\xdf\xd9\xb1\x5b\xfc\x3d\x55\x93\x53\x50\x34\x10\xc1\xe1";
FileSource keys("rsa512a.dat", true, new HexDecoder);
FileSource keys("TestData/rsa512a.dat", true, new HexDecoder);
Weak::RSASSA_PKCS1v15_MD2_Signer rsaPriv(keys);
Weak::RSASSA_PKCS1v15_MD2_Verifier rsaPub(rsaPriv);
@ -293,7 +293,7 @@ bool ValidateRSA()
cout << "invalid signature verification\n";
}
{
FileSource keys("rsa1024.dat", true, new HexDecoder);
FileSource keys("TestData/rsa1024.dat", true, new HexDecoder);
RSAES_PKCS1v15_Decryptor rsaPriv(keys);
RSAES_PKCS1v15_Encryptor rsaPub(rsaPriv);
@ -320,8 +320,8 @@ bool ValidateRSA()
bq.Put(oaepSeed, 20);
FixedRNG rng(bq);
FileSource privFile("rsa400pv.dat", true, new HexDecoder);
FileSource pubFile("rsa400pb.dat", true, new HexDecoder);
FileSource privFile("TestData/rsa400pv.dat", true, new HexDecoder);
FileSource pubFile("TestData/rsa400pb.dat", true, new HexDecoder);
RSAES_OAEP_SHA_Decryptor rsaPriv;
rsaPriv.AccessKey().BERDecodePrivateKey(privFile, false, 0);
RSAES_OAEP_SHA_Encryptor rsaPub(pubFile);
@ -344,7 +344,7 @@ bool ValidateDH()
{
cout << "\nDH validation suite running...\n\n";
FileSource f("dh1024.dat", true, new HexDecoder());
FileSource f("TestData/dh1024.dat", true, new HexDecoder());
DH dh(f);
return SimpleKeyAgreementValidate(dh);
}
@ -353,7 +353,7 @@ bool ValidateMQV()
{
cout << "\nMQV validation suite running...\n\n";
FileSource f("mqv1024.dat", true, new HexDecoder());
FileSource f("TestData/mqv1024.dat", true, new HexDecoder());
MQV mqv(f);
return AuthenticatedKeyAgreementValidate(mqv);
}
@ -362,7 +362,7 @@ bool ValidateLUC_DH()
{
cout << "\nLUC-DH validation suite running...\n\n";
FileSource f("lucd512.dat", true, new HexDecoder());
FileSource f("TestData/lucd512.dat", true, new HexDecoder());
LUC_DH dh(f);
return SimpleKeyAgreementValidate(dh);
}
@ -371,7 +371,7 @@ bool ValidateXTR_DH()
{
cout << "\nXTR-DH validation suite running...\n\n";
FileSource f("xtrdh171.dat", true, new HexDecoder());
FileSource f("TestData/xtrdh171.dat", true, new HexDecoder());
XTR_DH dh(f);
return SimpleKeyAgreementValidate(dh);
}
@ -381,7 +381,7 @@ bool ValidateElGamal()
cout << "\nElGamal validation suite running...\n\n";
bool pass = true;
{
FileSource fc("elgc1024.dat", true, new HexDecoder);
FileSource fc("TestData/elgc1024.dat", true, new HexDecoder);
ElGamalDecryptor privC(fc);
ElGamalEncryptor pubC(privC);
privC.AccessKey().Precompute();
@ -399,7 +399,7 @@ bool ValidateDLIES()
cout << "\nDLIES validation suite running...\n\n";
bool pass = true;
{
FileSource fc("dlie1024.dat", true, new HexDecoder);
FileSource fc("TestData/dlie1024.dat", true, new HexDecoder);
DLIES<>::Decryptor privC(fc);
DLIES<>::Encryptor pubC(privC);
pass = CryptoSystemValidate(privC, pubC) && pass;
@ -422,7 +422,7 @@ bool ValidateNR()
cout << "\nNR validation suite running...\n\n";
bool pass = true;
{
FileSource f("nr2048.dat", true, new HexDecoder);
FileSource f("TestData/nr2048.dat", true, new HexDecoder);
NR<SHA>::Signer privS(f);
privS.AccessKey().Precompute();
NR<SHA>::Verifier pubS(privS);
@ -445,7 +445,7 @@ bool ValidateDSA(bool thorough)
bool pass = true, fail;
{
FileSource fs("dsa512.dat", true, new HexDecoder());
FileSource fs("TestData/dsa512.dat", true, new HexDecoder());
GDSA<SHA>::Signer priv(fs);
priv.AccessKey().Precompute(16);
GDSA<SHA>::Verifier pub(priv);
@ -487,10 +487,10 @@ bool ValidateDSA(bool thorough)
fail = pub.VerifyMessage((byte *)"xyz", 3, sig, sizeof(sig));
pass = pass && !fail;
}
FileSource fs1("dsa1024.dat", true, new HexDecoder());
FileSource fs1("TestData/dsa1024.dat", true, new HexDecoder());
DSA::Signer priv(fs1);
DSA::Verifier pub(priv);
FileSource fs2("dsa1024b.dat", true, new HexDecoder());
FileSource fs2("TestData/dsa1024b.dat", true, new HexDecoder());
DSA::Verifier pub1(fs2);
assert(pub.GetKey() == pub1.GetKey());
pass = SignatureValidate(priv, pub, thorough) && pass;
@ -503,7 +503,7 @@ bool ValidateLUC()
bool pass=true;
{
FileSource f("luc1024.dat", true, new HexDecoder);
FileSource f("TestData/luc1024.dat", true, new HexDecoder);
LUCSSA_PKCS1v15_SHA_Signer priv(f);
LUCSSA_PKCS1v15_SHA_Verifier pub(priv);
pass = SignatureValidate(priv, pub) && pass;
@ -520,14 +520,14 @@ bool ValidateLUC_DL()
{
cout << "\nLUC-HMP validation suite running...\n\n";
FileSource f("lucs512.dat", true, new HexDecoder);
FileSource f("TestData/lucs512.dat", true, new HexDecoder);
LUC_HMP<SHA>::Signer privS(f);
LUC_HMP<SHA>::Verifier pubS(privS);
bool pass = SignatureValidate(privS, pubS);
cout << "\nLUC-IES validation suite running...\n\n";
FileSource fc("lucc512.dat", true, new HexDecoder);
FileSource fc("TestData/lucc512.dat", true, new HexDecoder);
LUC_IES<>::Decryptor privC(fc);
LUC_IES<>::Encryptor pubC(privC);
pass = CryptoSystemValidate(privC, pubC) && pass;
@ -541,7 +541,7 @@ bool ValidateRabin()
bool pass=true;
{
FileSource f("rabi1024.dat", true, new HexDecoder);
FileSource f("TestData/rabi1024.dat", true, new HexDecoder);
RabinSS<PSSR, SHA>::Signer priv(f);
RabinSS<PSSR, SHA>::Verifier pub(priv);
pass = SignatureValidate(priv, pub) && pass;
@ -558,7 +558,7 @@ bool ValidateRW()
{
cout << "\nRW validation suite running...\n\n";
FileSource f("rw1024.dat", true, new HexDecoder);
FileSource f("TestData/rw1024.dat", true, new HexDecoder);
RWSS<PSSR, SHA>::Signer priv(f);
RWSS<PSSR, SHA>::Verifier pub(priv);
@ -570,7 +570,7 @@ bool ValidateBlumGoldwasser()
{
cout << "\nBlumGoldwasser validation suite running...\n\n";
FileSource f("blum512.dat", true, new HexDecoder);
FileSource f("TestData/blum512.dat", true, new HexDecoder);
BlumGoldwasserPrivateKey priv(f);
BlumGoldwasserPublicKey pub(priv);
@ -614,7 +614,7 @@ bool ValidateECP()
pass = SimpleKeyAgreementValidate(ecdhc) && pass;
pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass;
cout << "Testing SEC 2 recommended curves..." << endl;
cout << "Testing SEC 2, NIST, and Brainpool recommended curves..." << endl;
OID oid;
while (!(oid = DL_GroupParameters_EC<ECP>::GetNextRecommendedParametersOID(oid)).m_values.empty())
{
@ -740,7 +740,7 @@ bool ValidateESIGN()
"\x74\x02\x37\x0E\xED\x0A\x06\xAD\xF4\x15\x65\xB8\xE1\xD1\x45\xAE\x39\x19\xB4\xFF\x5D\xF1\x45\x7B\xE0\xFE\x72\xED\x11\x92\x8F\x61\x41\x4F\x02\x00\xF2\x76\x6F\x7C"
"\x79\xA2\xE5\x52\x20\x5D\x97\x5E\xFE\x39\xAE\x21\x10\xFB\x35\xF4\x80\x81\x41\x13\xDD\xE8\x5F\xCA\x1E\x4F\xF8\x9B\xB2\x68\xFB\x28";
FileSource keys("esig1536.dat", true, new HexDecoder);
FileSource keys("TestData/esig1536.dat", true, new HexDecoder);
ESIGN<SHA>::Signer signer(keys);
ESIGN<SHA>::Verifier verifier(signer);