diff --git a/asn.cpp b/asn.cpp index 8c0d30ff..2502597f 100644 --- a/asn.cpp +++ b/asn.cpp @@ -1,4 +1,5 @@ // asn.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #include "pch.h" #include "config.h" @@ -11,7 +12,6 @@ #include NAMESPACE_BEGIN(CryptoPP) -USING_NAMESPACE(std) /// DER Length size_t DERLengthEncode(BufferedTransformation &bt, lword length) diff --git a/bench.h b/bench.h index 5f7f3ea7..f393cfde 100644 --- a/bench.h +++ b/bench.h @@ -1,13 +1,33 @@ // bench.h - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #ifndef CRYPTOPP_BENCH_H #define CRYPTOPP_BENCH_H #include "cryptlib.h" -extern const double CLOCK_TICKS_PER_SECOND; +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) + +ANONYMOUS_NAMESPACE_BEGIN +#ifdef CLOCKS_PER_SEC +const double CLOCK_TICKS_PER_SECOND = (double)CLOCKS_PER_SEC; +#elif defined(CLK_TCK) +const double CLOCK_TICKS_PER_SECOND = (double)CLK_TCK; +#else +const double CLOCK_TICKS_PER_SECOND = 1000000.0; +#endif + +static const byte defaultKey[] = "0123456789" // 168 + NULL + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "00000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000"; +NAMESPACE_END void BenchmarkAll(double t, double hertz); void BenchmarkAll2(double t, double hertz); +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP + #endif diff --git a/bench1.cpp b/bench1.cpp index 9b57f7ea..be25f3dd 100644 --- a/bench1.cpp +++ b/bench1.cpp @@ -1,4 +1,5 @@ // bench1.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #include "cryptlib.h" #include "bench.h" @@ -20,79 +21,63 @@ #include #include -// These are noisy enoguh due to test.cpp. Turn them off here. -#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) -USING_NAMESPACE(CryptoPP) -USING_NAMESPACE(std) - -#ifdef CLOCKS_PER_SEC -const double CLOCK_TICKS_PER_SECOND = (double)CLOCKS_PER_SEC; -#elif defined(CLK_TCK) -const double CLOCK_TICKS_PER_SECOND = (double)CLK_TCK; -#else -const double CLOCK_TICKS_PER_SECOND = 1000000.0; -#endif - -double logtotal = 0.0, g_allocatedTime = 0, g_hertz = 0; -unsigned int logcount = 0; - -static const byte defaultKey[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; +double logTotal = 0.0, g_allocatedTime = 0, g_hertz = 0; +unsigned int logCount = 0; void OutputResultBytes(const char *name, double length, double timeTaken) { // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. - StreamState ss(cout); + StreamState ss(std::cout); // Coverity finding if (length < 0.0000000001f) length = 0.000001f; if (timeTaken < 0.0000000001f) timeTaken = 0.000001f; double mbs = length / timeTaken / (1024*1024); - cout << "\n" << name; -// cout << "" << setprecision(3) << length / (1024*1024); - cout << setiosflags(ios::fixed); -// cout << "" << setprecision(3) << timeTaken; - cout << "" << setprecision(0) << setiosflags(ios::fixed) << mbs; + std::cout << "\n" << name; +// std::cout << "" << std::setprecision(3) << length / (1024*1024); + std::cout << std::setiosflags(std::ios::fixed); +// std::cout << "" << std::setprecision(3) << timeTaken; + std::cout << "" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << mbs; if (g_hertz) - cout << "" << setprecision(1) << setiosflags(ios::fixed) << timeTaken * g_hertz / length; - logtotal += log(mbs); - logcount++; + std::cout << "" << std::setprecision(1) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / length; + logTotal += log(mbs); + logCount++; } void OutputResultKeying(double iterations, double timeTaken) { // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. - StreamState ss(cout); + StreamState ss(std::cout); // Coverity finding if (iterations < 0.0000000001f) iterations = 0.000001f; if (timeTaken < 0.0000000001f) timeTaken = 0.000001f; - cout << "" << setprecision(3) << setiosflags(ios::fixed) << (1000*1000*timeTaken/iterations); + std::cout << "" << std::setprecision(3) << std::setiosflags(std::ios::fixed) << (1000*1000*timeTaken/iterations); if (g_hertz) - cout << "" << setprecision(0) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations; + std::cout << "" << std::setprecision(0) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / iterations; } void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken) { // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. - StreamState ss(cout); + StreamState ss(std::cout); // Coverity finding if (!iterations) iterations++; if (timeTaken < 0.0000000001f) timeTaken = 0.000001f; - cout << "\n" << name << " " << operation << (pc ? " with precomputation" : ""); - cout << "" << setprecision(2) << setiosflags(ios::fixed) << (1000*timeTaken/iterations); + std::cout << "\n" << name << " " << operation << (pc ? " with precomputation" : ""); + std::cout << "" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << (1000*timeTaken/iterations); if (g_hertz) - cout << "" << setprecision(2) << setiosflags(ios::fixed) << timeTaken * g_hertz / iterations / 1000000; + std::cout << "" << std::setprecision(2) << std::setiosflags(std::ios::fixed) << timeTaken * g_hertz / iterations / 1000000; - logtotal += log(iterations/timeTaken); - logcount++; + logTotal += log(iterations/timeTaken); + logCount++; } /* @@ -122,7 +107,7 @@ void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal) { const int BUF_SIZE=RoundUpToMultipleOf(2048U, cipher.OptimalBlockSize()); AlignedSecByteBlock buf(BUF_SIZE); - GlobalRNG().GenerateBlock(buf, BUF_SIZE); + Test::GlobalRNG().GenerateBlock(buf, BUF_SIZE); clock_t start = clock(); unsigned long i=0, blocks=1; @@ -151,7 +136,7 @@ void BenchMark(const char *name, HashTransformation &ht, double timeTotal) { const int BUF_SIZE=2048U; AlignedSecByteBlock buf(BUF_SIZE); - GlobalRNG().GenerateBlock(buf, BUF_SIZE); + Test::GlobalRNG().GenerateBlock(buf, BUF_SIZE); clock_t start = clock(); unsigned long i=0, blocks=1; @@ -172,7 +157,7 @@ void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal) { const int BUF_SIZE=2048U; AlignedSecByteBlock buf(BUF_SIZE); - GlobalRNG().GenerateBlock(buf, BUF_SIZE); + Test::GlobalRNG().GenerateBlock(buf, BUF_SIZE); clock_t start = clock(); unsigned long i=0, blocks=1; @@ -248,8 +233,8 @@ void BenchMarkByNameKeyLess(const char *factoryName, const char *displayName=NUL void BenchmarkAll(double t, double hertz) { #if 1 - logtotal = 0; - logcount = 0; + logTotal = 0; + logCount = 0; g_allocatedTime = t; g_hertz = hertz; @@ -258,18 +243,18 @@ void BenchmarkAll(double t, double hertz) { cpb = "Cycles Per Byte"; cpk = "Cycles to
Setup Key and IV"; - cout << "CPU frequency of the test platform is " << g_hertz << " Hz.\n"; + std::cout << "CPU frequency of the test platform is " << g_hertz << " Hz.\n"; } else { cpb = cpk = ""; - cout << "CPU frequency of the test platform was not provided.\n"; + std::cout << "CPU frequency of the test platform was not provided.\n"; } - cout << "" << endl; - cout << "
AlgorithmMiB/Second" << cpb << "Microseconds to
Setup Key and IV" << cpk << endl; + std::cout << "" << std::endl; + std::cout << ""; + std::cout << "\n"; #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE if (HasCLMUL()) BenchMarkByName2("AES/GCM", 0, "AES/GCM"); @@ -286,7 +271,7 @@ void BenchmarkAll(double t, double hertz) BenchMarkByName2("AES/CCM"); BenchMarkByName2("AES/EAX"); - cout << "\n"; + std::cout << "\n"; #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE if (HasCLMUL()) BenchMarkByName2("AES/GCM", 0, "GMAC(AES)"); @@ -308,7 +293,7 @@ void BenchmarkAll(double t, double hertz) BenchMarkByName("SipHash-2-4"); BenchMarkByName("SipHash-4-8"); - cout << "\n"; + std::cout << "\n"; BenchMarkByNameKeyLess("CRC32"); BenchMarkByNameKeyLess("CRC32C"); BenchMarkByNameKeyLess("Adler32"); @@ -333,7 +318,7 @@ void BenchmarkAll(double t, double hertz) BenchMarkByNameKeyLess("BLAKE2s"); BenchMarkByNameKeyLess("BLAKE2b"); - cout << "\n"; + std::cout << "\n"; BenchMarkByName("Panama-LE"); BenchMarkByName("Panama-BE"); BenchMarkByName("Salsa20"); @@ -347,7 +332,7 @@ void BenchmarkAll(double t, double hertz) BenchMarkByName("SEAL-3.0-LE"); BenchMarkByName("WAKE-OFB-LE"); - cout << "\n"; + std::cout << "\n"; BenchMarkByName("AES/CTR", 16); BenchMarkByName("AES/CTR", 24); BenchMarkByName("AES/CTR", 32); @@ -377,10 +362,10 @@ void BenchmarkAll(double t, double hertz) BenchMarkByName("CAST-128/CTR"); BenchMarkByName("SKIPJACK/CTR"); BenchMarkByName("SEED/CTR", 0, "SEED/CTR (1/2 K table)"); - cout << "
AlgorithmMiB/Second" << cpb << "Microseconds to
Setup Key and IV" << cpk << std::endl; - cout << "\n
" << endl; + std::cout << "
" << std::endl; BenchmarkAll2(t, hertz); - cout << "Throughput Geometric Average: " << setiosflags(ios::fixed) << exp(logtotal/(logcount ? logcount : 1)) << endl; + std::cout << "Throughput Geometric Average: " << std::setiosflags(std::ios::fixed) << exp(logTotal/(logCount ? logCount : 1)) << std::endl; // Safer functions on Windows for C&A, https://github.com/weidai11/cryptopp/issues/55 #if (CRYPTOPP_MSC_VERSION >= 1400) @@ -394,10 +379,13 @@ void BenchmarkAll(double t, double hertz) err = asctime_s(timeBuf, sizeof(timeBuf), &localTime); CRYPTOPP_ASSERT(err == 0); - cout << "\nTest ended at " << timeBuf; + std::cout << "\nTest ended at " << timeBuf; #else const time_t endTime = time(NULL); - cout << "\nTest ended at " << asctime(localtime(&endTime)); + std::cout << "\nTest ended at " << asctime(localtime(&endTime)); #endif #endif } + +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP diff --git a/bench2.cpp b/bench2.cpp index c209bff9..f85d05e7 100644 --- a/bench2.cpp +++ b/bench2.cpp @@ -1,4 +1,5 @@ // bench2.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #include "cryptlib.h" #include "bench.h" @@ -34,13 +35,8 @@ #include #include -// These are noisy enoguh due to test.cpp. Turn them off here. -#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -USING_NAMESPACE(CryptoPP) -USING_NAMESPACE(std) +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) void OutputResultOperations(const char *name, const char *operation, bool pc, unsigned long iterations, double timeTaken); @@ -48,13 +44,13 @@ void BenchMarkEncryption(const char *name, PK_Encryptor &key, double timeTotal, { unsigned int len = 16; SecByteBlock plaintext(len), ciphertext(key.CiphertextLength(len)); - GlobalRNG().GenerateBlock(plaintext, len); + Test::GlobalRNG().GenerateBlock(plaintext, len); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) - key.Encrypt(GlobalRNG(), plaintext, len, ciphertext); + key.Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext); OutputResultOperations(name, "Encryption", pc, i, timeTaken); @@ -70,14 +66,14 @@ void BenchMarkDecryption(const char *name, PK_Decryptor &priv, PK_Encryptor &pub unsigned int len = 16; SecByteBlock ciphertext(pub.CiphertextLength(len)); SecByteBlock plaintext(pub.MaxPlaintextLength(ciphertext.size())); - GlobalRNG().GenerateBlock(plaintext, len); - pub.Encrypt(GlobalRNG(), plaintext, len, ciphertext); + Test::GlobalRNG().GenerateBlock(plaintext, len); + pub.Encrypt(Test::GlobalRNG(), plaintext, len, ciphertext); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) - priv.Decrypt(GlobalRNG(), ciphertext, ciphertext.size(), plaintext); + priv.Decrypt(Test::GlobalRNG(), ciphertext, ciphertext.size(), plaintext); OutputResultOperations(name, "Decryption", false, i, timeTaken); } @@ -86,13 +82,13 @@ void BenchMarkSigning(const char *name, PK_Signer &key, double timeTotal, bool p { unsigned int len = 16; AlignedSecByteBlock message(len), signature(key.SignatureLength()); - GlobalRNG().GenerateBlock(message, len); + Test::GlobalRNG().GenerateBlock(message, len); const clock_t start = clock(); unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) - key.SignMessage(GlobalRNG(), message, len, signature); + key.SignMessage(Test::GlobalRNG(), message, len, signature); OutputResultOperations(name, "Signature", pc, i, timeTaken); @@ -107,8 +103,8 @@ void BenchMarkVerification(const char *name, const PK_Signer &priv, PK_Verifier { unsigned int len = 16; AlignedSecByteBlock message(len), signature(pub.SignatureLength()); - GlobalRNG().GenerateBlock(message, len); - priv.SignMessage(GlobalRNG(), message, len, signature); + Test::GlobalRNG().GenerateBlock(message, len); + priv.SignMessage(Test::GlobalRNG(), message, len, signature); const clock_t start = clock(); unsigned int i; @@ -137,7 +133,7 @@ void BenchMarkKeyGen(const char *name, SimpleKeyAgreementDomain &d, double timeT unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) - d.GenerateKeyPair(GlobalRNG(), priv, pub); + d.GenerateKeyPair(Test::GlobalRNG(), priv, pub); OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken); @@ -156,7 +152,7 @@ void BenchMarkKeyGen(const char *name, AuthenticatedKeyAgreementDomain &d, doubl unsigned int i; double timeTaken; for (timeTaken=(double)0, i=0; timeTaken < timeTotal; timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND, i++) - d.GenerateEphemeralKeyPair(GlobalRNG(), priv, pub); + d.GenerateEphemeralKeyPair(Test::GlobalRNG(), priv, pub); OutputResultOperations(name, "Key-Pair Generation", pc, i, timeTaken); @@ -171,8 +167,8 @@ void BenchMarkAgreement(const char *name, SimpleKeyAgreementDomain &d, double ti { SecByteBlock priv1(d.PrivateKeyLength()), priv2(d.PrivateKeyLength()); SecByteBlock pub1(d.PublicKeyLength()), pub2(d.PublicKeyLength()); - d.GenerateKeyPair(GlobalRNG(), priv1, pub1); - d.GenerateKeyPair(GlobalRNG(), priv2, pub2); + d.GenerateKeyPair(Test::GlobalRNG(), priv1, pub1); + d.GenerateKeyPair(Test::GlobalRNG(), priv2, pub2); SecByteBlock val(d.AgreedValueLength()); const clock_t start = clock(); @@ -193,10 +189,10 @@ void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomain &d, do SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength()); SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength()); SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength()); - d.GenerateStaticKeyPair(GlobalRNG(), spriv1, spub1); - d.GenerateStaticKeyPair(GlobalRNG(), spriv2, spub2); - d.GenerateEphemeralKeyPair(GlobalRNG(), epriv1, epub1); - d.GenerateEphemeralKeyPair(GlobalRNG(), epriv2, epub2); + d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv1, spub1); + d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv2, spub2); + d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv1, epub1); + d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv2, epub2); SecByteBlock val(d.AgreedValueLength()); const clock_t start = clock(); @@ -218,10 +214,10 @@ void BenchMarkAgreement(const char *name, AuthenticatedKeyAgreementDomainWithRol SecByteBlock epriv1(d.EphemeralPrivateKeyLength()), epriv2(d.EphemeralPrivateKeyLength()); SecByteBlock spub1(d.StaticPublicKeyLength()), spub2(d.StaticPublicKeyLength()); SecByteBlock epub1(d.EphemeralPublicKeyLength()), epub2(d.EphemeralPublicKeyLength()); - d.GenerateStaticKeyPair(GlobalRNG(), spriv1, spub1); - d.GenerateStaticKeyPair(GlobalRNG(), spriv2, spub2); - d.GenerateEphemeralKeyPair(GlobalRNG(), epriv1, epub1); - d.GenerateEphemeralKeyPair(GlobalRNG(), epriv2, epub2); + d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv1, spub1); + d.GenerateStaticKeyPair(Test::GlobalRNG(), spriv2, spub2); + d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv1, epub1); + d.GenerateEphemeralKeyPair(Test::GlobalRNG(), epriv2, epub2); SecByteBlock val(d.AgreedValueLength()); const clock_t start = clock(); @@ -272,22 +268,22 @@ void BenchmarkAll2(double t, double hertz) { g_hertz = hertz; - cout << "" << endl; - cout << "
OperationMilliseconds/Operation" << (g_hertz ? "Megacycles/Operation" : "") << endl; + std::cout << "" << std::endl; + std::cout << ""; + std::cout << "\n"; BenchMarkCrypto > >(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", "RSA 1024", t); BenchMarkCrypto > >(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", "LUC 1024", t); BenchMarkCrypto >(CRYPTOPP_DATA_DIR "TestData/dlie1024.dat", "DLIES 1024", t); BenchMarkCrypto >(CRYPTOPP_DATA_DIR "TestData/lucc512.dat", "LUCELG 512", t); - cout << "\n"; + std::cout << "\n"; BenchMarkCrypto > >(CRYPTOPP_DATA_DIR "TestData/rsa2048.dat", "RSA 2048", t); BenchMarkCrypto > >(CRYPTOPP_DATA_DIR "TestData/luc2048.dat", "LUC 2048", t); BenchMarkCrypto >(CRYPTOPP_DATA_DIR "TestData/dlie2048.dat", "DLIES 2048", t); BenchMarkCrypto >(CRYPTOPP_DATA_DIR "TestData/lucc1024.dat", "LUCELG 1024", t); - cout << "\n"; + std::cout << "\n"; BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", "RSA 1024", t); BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/rw1024.dat", "RW 1024", t); BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/luc1024.dat", "LUC 1024", t); @@ -297,7 +293,7 @@ void BenchmarkAll2(double t, double hertz) BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/esig1023.dat", "ESIGN 1023", t); BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/esig1536.dat", "ESIGN 1536", t); - cout << "\n"; + std::cout << "\n"; BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/rsa2048.dat", "RSA 2048", t); BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/rw2048.dat", "RW 2048", t); BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/luc2048.dat", "LUC 2048", t); @@ -305,7 +301,7 @@ void BenchmarkAll2(double t, double hertz) BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/lucs1024.dat", "LUC-HMP 1024", t); BenchMarkSignature >(CRYPTOPP_DATA_DIR "TestData/esig2046.dat", "ESIGN 2046", t); - cout << "\n"; + std::cout << "\n"; BenchMarkKeyAgreement(CRYPTOPP_DATA_DIR "TestData/xtrdh171.dat", "XTR-DH 171", t); BenchMarkKeyAgreement(CRYPTOPP_DATA_DIR "TestData/xtrdh342.dat", "XTR-DH 342", t); BenchMarkKeyAgreement(CRYPTOPP_DATA_DIR "TestData/dh1024.dat", "DH 1024", t); @@ -327,15 +323,15 @@ void BenchmarkAll2(double t, double hertz) BenchMarkKeyAgreement(CRYPTOPP_DATA_DIR "TestData/fhmqv512.dat", "FHMQV P-512", t); #endif - cout << "\n"; + std::cout << "\n"; { - ECIES::Decryptor cpriv(GlobalRNG(), ASN1::secp256k1()); + ECIES::Decryptor cpriv(Test::GlobalRNG(), ASN1::secp256k1()); ECIES::Encryptor cpub(cpriv); ECDSA::Signer spriv(cpriv); ECDSA::Verifier spub(spriv); ECDSA_RFC6979::Signer spriv2(cpriv); ECDSA_RFC6979::Verifier spub2(spriv); - ECGDSA::Signer spriv3(GlobalRNG(), ASN1::secp256k1()); + ECGDSA::Signer spriv3(Test::GlobalRNG(), ASN1::secp256k1()); ECGDSA::Verifier spub3(spriv3); ECDH::Domain ecdhc(ASN1::secp256k1()); ECMQV::Domain ecmqvc(ASN1::secp256k1()); @@ -354,15 +350,15 @@ void BenchmarkAll2(double t, double hertz) BenchMarkAgreement("ECMQVC over GF(p) 256", ecmqvc, t); } - cout << "" << endl; + std::cout << "" << std::endl; { - ECIES::Decryptor cpriv(GlobalRNG(), ASN1::sect233r1()); + ECIES::Decryptor cpriv(Test::GlobalRNG(), ASN1::sect233r1()); ECIES::Encryptor cpub(cpriv); ECDSA::Signer spriv(cpriv); ECDSA::Verifier spub(spriv); ECDSA_RFC6979::Signer spriv2(cpriv); ECDSA_RFC6979::Verifier spub2(spriv); - ECGDSA::Signer spriv3(GlobalRNG(), ASN1::sect233r1()); + ECGDSA::Signer spriv3(Test::GlobalRNG(), ASN1::sect233r1()); ECGDSA::Verifier spub3(spriv3); ECDH::Domain ecdhc(ASN1::sect233r1()); ECMQV::Domain ecmqvc(ASN1::sect233r1()); @@ -380,5 +376,8 @@ void BenchmarkAll2(double t, double hertz) BenchMarkKeyGen("ECMQVC over GF(2^n) 233", ecmqvc, t); BenchMarkAgreement("ECMQVC over GF(2^n) 233", ecmqvc, t); } - cout << "
OperationMilliseconds/Operation" << (g_hertz ? "Megacycles/Operation" : "") << std::endl; - cout << "\n
" << endl; + std::cout << "
" << std::endl; } + +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP \ No newline at end of file diff --git a/channels.cpp b/channels.cpp index 2082ad67..318efd70 100644 --- a/channels.cpp +++ b/channels.cpp @@ -1,4 +1,5 @@ // channels.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #include "pch.h" @@ -8,7 +9,6 @@ #include "channels.h" NAMESPACE_BEGIN(CryptoPP) -USING_NAMESPACE(std) #if 0 void MessageSwitch::AddDefaultRoute(BufferedTransformation &destination, const std::string &channel) @@ -37,7 +37,7 @@ public: MessageRouteIterator(MessageSwitch &ms, const std::string &channel) : m_channel(channel) { - pair range = cs.m_routeMap.equal_range(channel); + std::pair range = cs.m_routeMap.equal_range(channel); if (range.first == range.second) { m_useDefault = true; @@ -97,7 +97,7 @@ void MessageSwitch::MessageSeriesEnd(int propagation=-1); void ChannelRouteIterator::Reset(const std::string &channel) { m_channel = channel; - pair range = m_cs.m_routeMap.equal_range(channel); + std::pair range = m_cs.m_routeMap.equal_range(channel); if (range.first == range.second) { m_useDefault = true; @@ -297,7 +297,7 @@ void ChannelSwitch::AddRoute(const std::string &inChannel, BufferedTransformatio void ChannelSwitch::RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel) { typedef ChannelSwitch::RouteMap::iterator MapIterator; - pair range = m_routeMap.equal_range(inChannel); + std::pair range = m_routeMap.equal_range(inChannel); for (MapIterator it = range.first; it != range.second; ++it) if (it->second.first == &destination && it->second.second == outChannel) diff --git a/datatest.cpp b/datatest.cpp index 83431fa5..00764729 100644 --- a/datatest.cpp +++ b/datatest.cpp @@ -1,4 +1,5 @@ // datatest.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #define CRYPTOPP_DEFAULT_NO_DLL #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 @@ -27,8 +28,8 @@ extern "C" void __coverity_tainted_data_sanitize__(void *); #endif -USING_NAMESPACE(CryptoPP) -USING_NAMESPACE(std) +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) typedef std::map TestData; static bool s_thorough = false; @@ -45,7 +46,7 @@ static void OutputTestData(const TestData &v) { for (TestData::const_iterator i = v.begin(); i != v.end(); ++i) { - cerr << i->first << ": " << i->second << endl; + std::cerr << i->first << ": " << i->second << std::endl; } } @@ -86,8 +87,8 @@ void RandomizedTransfer(BufferedTransformation &source, BufferedTransformation & while (source.MaxRetrievable() > (finish ? 0 : 4096)) { byte buf[4096+64]; - size_t start = GlobalRNG().GenerateWord32(0, 63); - size_t len = GlobalRNG().GenerateWord32(1, UnsignedMin(4096U, 3*source.MaxRetrievable()/2)); + size_t start = Test::GlobalRNG().GenerateWord32(0, 63); + size_t len = Test::GlobalRNG().GenerateWord32(1, UnsignedMin(4096U, 3*source.MaxRetrievable()/2)); len = source.Get(buf+start, len); target.ChannelPut(channel, buf+start, len); } @@ -176,7 +177,7 @@ public: if (i == m_data.end()) return false; - m_temp.resize(0); + m_temp.clear(); PutDecodedDatumInto(m_data, i->first.c_str(), StringSink(m_temp).Ref()); *reinterpret_cast(pValue) = (int)m_temp.size(); return true; @@ -193,7 +194,7 @@ public: *reinterpret_cast(pValue) = Integer((std::string(value) + "h").c_str()); else if (valueType == typeid(ConstByteArrayParameter)) { - m_temp.resize(0); + m_temp.clear(); PutDecodedDatumInto(m_data, name, StringSink(m_temp).Ref()); reinterpret_cast(pValue)->Assign((const byte *)m_temp.data(), m_temp.size(), false); } @@ -211,9 +212,9 @@ private: void TestKeyPairValidAndConsistent(CryptoMaterial &pub, const CryptoMaterial &priv) { // "!!" converts between bool <-> integral. - if (!pub.Validate(GlobalRNG(), 2U+!!s_thorough)) + if (!pub.Validate(Test::GlobalRNG(), 2U+!!s_thorough)) SignalTestFailure(); - if (!priv.Validate(GlobalRNG(), 2U+!!s_thorough)) + if (!priv.Validate(Test::GlobalRNG(), 2U+!!s_thorough)) SignalTestFailure(); ByteQueue bq1, bq2; @@ -236,7 +237,7 @@ void TestSignatureScheme(TestData &v) if (test == "GenerateKey") { - signer->AccessPrivateKey().GenerateRandom(GlobalRNG(), pairs); + signer->AccessPrivateKey().GenerateRandom(Test::GlobalRNG(), pairs); verifier->AccessPublicKey().AssignFrom(signer->AccessPrivateKey()); } else @@ -260,7 +261,7 @@ void TestSignatureScheme(TestData &v) } else if (test == "PublicKeyValid") { - if (!verifier->GetMaterial().Validate(GlobalRNG(), 3)) + if (!verifier->GetMaterial().Validate(Test::GlobalRNG(), 3)) SignalTestFailure(); return; } @@ -276,11 +277,11 @@ void TestSignatureScheme(TestData &v) TestKeyPairValidAndConsistent(verifier->AccessMaterial(), signer->GetMaterial()); SignatureVerificationFilter verifierFilter(*verifier, NULL, SignatureVerificationFilter::THROW_EXCEPTION); verifierFilter.Put((const byte *)"abc", 3); - StringSource ss("abc", true, new SignerFilter(GlobalRNG(), *signer, new Redirector(verifierFilter))); + StringSource ss("abc", true, new SignerFilter(Test::GlobalRNG(), *signer, new Redirector(verifierFilter))); } else if (test == "Sign") { - SignerFilter f(GlobalRNG(), *signer, new HexEncoder(new FileSink(cout))); + SignerFilter f(Test::GlobalRNG(), *signer, new HexEncoder(new FileSink(std::cout))); StringSource ss(GetDecodedDatum(v, "Message"), true, new Redirector(f)); SignalTestFailure(); } @@ -290,8 +291,8 @@ void TestSignatureScheme(TestData &v) // for DSA and ECDSA, and access to the seed or secret is not needed. If // additional determinsitic signatures are added, then the test harness will // likely need to be extended. - string signature; - SignerFilter f(GlobalRNG(), *signer, new StringSink(signature)); + std::string signature; + SignerFilter f(Test::GlobalRNG(), *signer, new StringSink(signature)); StringSource ss(GetDecodedDatum(v, "Message"), true, new Redirector(f)); if (GetDecodedDatum(v, "Signature") != signature) @@ -336,7 +337,7 @@ void TestAsymmetricCipher(TestData &v) if (test == "DecryptMatch") { std::string decrypted, expected = GetDecodedDatum(v, "Plaintext"); - StringSource ss(GetDecodedDatum(v, "Ciphertext"), true, new PK_DecryptorFilter(GlobalRNG(), *decryptor, new StringSink(decrypted))); + StringSource ss(GetDecodedDatum(v, "Ciphertext"), true, new PK_DecryptorFilter(Test::GlobalRNG(), *decryptor, new StringSink(decrypted))); if (decrypted != expected) SignalTestFailure(); } @@ -510,7 +511,7 @@ void TestAuthenticatedSymmetricCipher(TestData &v, const NameValuePairs &overrid std::string encrypted, decrypted; AuthenticatedEncryptionFilter ef(*asc1, new StringSink(encrypted)); - bool macAtBegin = !mac.empty() && !GlobalRNG().GenerateBit(); // test both ways randomly + bool macAtBegin = !mac.empty() && !Test::GlobalRNG().GenerateBit(); // test both ways randomly AuthenticatedDecryptionFilter df(*asc2, new StringSink(decrypted), macAtBegin ? AuthenticatedDecryptionFilter::MAC_AT_BEGIN : 0); if (asc1->NeedsPrespecifiedDataLengths()) @@ -646,7 +647,7 @@ void TestKeyDerivationFunction(TestData &v) bool GetField(std::istream &is, std::string &name, std::string &value) { - name.resize(0); // GCC workaround: 2.95.3 doesn't have clear() + name.clear(); is >> name; if (name.empty()) @@ -655,7 +656,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value) if (name[name.size()-1] != ':') { char c; - is >> skipws >> c; + is >> std::skipws >> c; if (c != ':') SignalTestError(); } @@ -667,7 +668,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value) // VC60 workaround: getline bug char buffer[128]; - value.resize(0); // GCC workaround: 2.95.3 doesn't have clear() + value.clear(); bool continueLine, space = false; do @@ -704,7 +705,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value) if (space && (name == "Modulus" || name == "SubgroupOrder" || name == "SubgroupGenerator" || name == "PublicElement" || name == "PrivateExponent" || name == "Signature")) { - string temp; + std::string temp; temp.reserve(value.size()); std::string::const_iterator it; @@ -725,25 +726,25 @@ void OutputPair(const NameValuePairs &v, const char *name) Integer x; bool b = v.GetValue(name, x); CRYPTOPP_UNUSED(b); CRYPTOPP_ASSERT(b); - cout << name << ": \\\n "; - x.Encode(HexEncoder(new FileSink(cout), false, 64, "\\\n ").Ref(), x.MinEncodedSize()); - cout << endl; + std::cout << name << ": \\\n "; + x.Encode(HexEncoder(new FileSink(std::cout), false, 64, "\\\n ").Ref(), x.MinEncodedSize()); + std::cout << std::endl; } void OutputNameValuePairs(const NameValuePairs &v) { std::string names = v.GetValueNames(); - string::size_type i = 0; + std::string::size_type i = 0; while (i < names.size()) { - string::size_type j = names.find_first_of (';', i); + std::string::size_type j = names.find_first_of (';', i); - if (j == string::npos) + if (j == std::string::npos) return; else { std::string name = names.substr(i, j-i); - if (name.find(':') == string::npos) + if (name.find(':') == std::string::npos) OutputPair(v, name.c_str()); } @@ -787,7 +788,7 @@ void TestDataFile(std::string filename, const NameValuePairs &overrideParameters if (lastAlgName != GetRequiredDatum(v, "Name")) { lastAlgName = GetRequiredDatum(v, "Name"); - cout << "\nTesting " << algType.c_str() << " algorithm " << lastAlgName.c_str() << ".\n"; + std::cout << "\nTesting " << algType.c_str() << " algorithm " << lastAlgName.c_str() << ".\n"; } try @@ -814,24 +815,24 @@ void TestDataFile(std::string filename, const NameValuePairs &overrideParameters } catch (const TestFailure &) { - cout << "\nTest failed.\n"; + std::cout << "\nTest failed.\n"; } catch (const CryptoPP::Exception &e) { - cout << "\nCryptoPP::Exception caught: " << e.what() << endl; + std::cout << "\nCryptoPP::Exception caught: " << e.what() << std::endl; } catch (const std::exception &e) { - cout << "\nstd::exception caught: " << e.what() << endl; + std::cout << "\nstd::exception caught: " << e.what() << std::endl; } if (failed) { - cout << "Skipping to next test.\n"; + std::cout << "Skipping to next test.\n"; failedTests++; } else - cout << "." << flush; + std::cout << "." << std::flush; totalTests++; } @@ -843,9 +844,11 @@ bool RunTestDataFile(const char *filename, const NameValuePairs &overrideParamet s_thorough = thorough; unsigned int totalTests = 0, failedTests = 0; TestDataFile((filename ? filename : ""), overrideParameters, totalTests, failedTests); - cout << dec << "\nTests complete. Total tests = " << totalTests << ". Failed tests = " << failedTests << "." << endl; + std::cout << std::dec << "\nTests complete. Total tests = " << totalTests << ". Failed tests = " << failedTests << "." << std::endl; if (failedTests != 0) - cout << "SOME TESTS FAILED!\n"; + std::cout << "SOME TESTS FAILED!\n"; return failedTests == 0; } +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP diff --git a/test.cpp b/test.cpp index c450bf5e..8ed82d54 100644 --- a/test.cpp +++ b/test.cpp @@ -1,4 +1,5 @@ // test.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #define CRYPTOPP_DEFAULT_NO_DLL #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 @@ -66,12 +67,7 @@ # pragma strict_gs_check (on) #endif -#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - USING_NAMESPACE(CryptoPP) -USING_NAMESPACE(std) const int MAX_PHRASE_LENGTH=250; @@ -79,8 +75,8 @@ void RegisterFactories(); void PrintSeedAndThreads(const std::string& seed); void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed); -string RSAEncryptString(const char *pubFilename, const char *seed, const char *message); -string RSADecryptString(const char *privFilename, const char *ciphertext); +std::string RSAEncryptString(const char *pubFilename, const char *seed, const char *message); +std::string RSADecryptString(const char *privFilename, const char *ciphertext); void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename); bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename); @@ -89,8 +85,8 @@ void HmacFile(const char *hexKey, const char *file); void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile); -string EncryptString(const char *plaintext, const char *passPhrase); -string DecryptString(const char *ciphertext, const char *passPhrase); +std::string EncryptString(const char *plaintext, const char *passPhrase); +std::string DecryptString(const char *ciphertext, const char *passPhrase); void EncryptFile(const char *in, const char *out, const char *passPhrase); void DecryptFile(const char *in, const char *out, const char *passPhrase); @@ -119,11 +115,19 @@ void PrintSeedAndThreads(const std::string& seed); int (*AdhocTest)(int argc, char *argv[]) = NULL; -namespace { OFB_Mode::Encryption s_globalRNG; } +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) + +ANONYMOUS_NAMESPACE_BEGIN +OFB_Mode::Encryption s_globalRNG; +NAMESPACE_END + RandomNumberGenerator & GlobalRNG() { return dynamic_cast(s_globalRNG); } +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP // See misc.h and trap.h for comments and usage #if defined(CRYPTOPP_DEBUG) && defined(UNIX_SIGNALS_AVAILABLE) @@ -153,7 +157,7 @@ int CRYPTOPP_API main(int argc, char *argv[]) seed.resize(16, ' '); // Fetch the SymmetricCipher interface, not the RandomNumberGenerator interface, to key the underlying cipher - OFB_Mode::Encryption& aesg = dynamic_cast::Encryption&>(GlobalRNG()); + OFB_Mode::Encryption& aesg = dynamic_cast::Encryption&>(Test::GlobalRNG()); aesg.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data()); std::string command, executableName, macFilename; @@ -168,18 +172,18 @@ int CRYPTOPP_API main(int argc, char *argv[]) char thisSeed[1024], privFilename[128], pubFilename[128]; unsigned int keyLength; - cout << "Key length in bits: "; - cin >> keyLength; + std::cout << "Key length in bits: "; + std::cin >> keyLength; - cout << "\nSave private key to file: "; - cin >> privFilename; + std::cout << "\nSave private key to file: "; + std::cin >> privFilename; - cout << "\nSave public key to file: "; - cin >> pubFilename; + std::cout << "\nSave public key to file: "; + std::cin >> pubFilename; - cout << "\nRandom Seed: "; - ws(cin); - cin.getline(thisSeed, 1024); + std::cout << "\nRandom Seed: "; + std::ws(std::cin); + std::cin.getline(thisSeed, 1024); GenerateRSAKey(keyLength, privFilename, pubFilename, thisSeed); } @@ -188,56 +192,56 @@ int CRYPTOPP_API main(int argc, char *argv[]) else if (command == "rv") { bool verified = RSAVerifyFile(argv[2], argv[3], argv[4]); - cout << (verified ? "valid signature" : "invalid signature") << endl; + std::cout << (verified ? "valid signature" : "invalid signature") << std::endl; } else if (command == "r") { char privFilename[128], pubFilename[128]; char thisSeed[1024], message[1024]; - cout << "Private key file: "; - cin >> privFilename; + std::cout << "Private key file: "; + std::cin >> privFilename; - cout << "\nPublic key file: "; - cin >> pubFilename; + std::cout << "\nPublic key file: "; + std::cin >> pubFilename; - cout << "\nRandom Seed: "; - ws(cin); - cin.getline(thisSeed, 1024); + std::cout << "\nRandom Seed: "; + std::ws(std::cin); + std::cin.getline(thisSeed, 1024); - cout << "\nMessage: "; - cin.getline(message, 1024); + std::cout << "\nMessage: "; + std::cin.getline(message, 1024); - string ciphertext = RSAEncryptString(pubFilename, thisSeed, message); - cout << "\nCiphertext: " << ciphertext << endl; + std::string ciphertext = RSAEncryptString(pubFilename, thisSeed, message); + std::cout << "\nCiphertext: " << ciphertext << std::endl; - string decrypted = RSADecryptString(privFilename, ciphertext.c_str()); - cout << "\nDecrypted: " << decrypted << endl; + std::string decrypted = RSADecryptString(privFilename, ciphertext.c_str()); + std::cout << "\nDecrypted: " << decrypted << std::endl; } else if (command == "mt") { MaurerRandomnessTest mt; FileStore fs(argv[2]); fs.TransferAllTo(mt); - cout << "Maurer Test Value: " << mt.GetTestValue() << endl; + std::cout << "Maurer Test Value: " << mt.GetTestValue() << std::endl; } else if (command == "mac_dll") { std::string fname(argv[2] ? argv[2] : ""); // sanity check on file size - std::fstream dllFile(fname.c_str(), ios::in | ios::out | ios::binary); + std::fstream dllFile(fname.c_str(), std::ios::in | std::ios::out | std::ios::binary); if (!dllFile.good()) { - cerr << "Failed to open file \"" << fname << "\"\n"; + std::cerr << "Failed to open file \"" << fname << "\"\n"; return 1; } std::ifstream::pos_type fileEnd = dllFile.seekg(0, std::ios_base::end).tellg(); if (fileEnd > 20*1000*1000) { - cerr << "Input file " << fname << " is too large"; - cerr << "(size is " << fileEnd << ").\n"; + std::cerr << "Input file " << fname << " is too large"; + std::cerr << "(size is " << fileEnd << ").\n"; return 1; } @@ -253,7 +257,7 @@ int CRYPTOPP_API main(int argc, char *argv[]) word16 optionalHeaderMagic = *(word16 *)(void *)(buf+optionalHeaderPos); if (optionalHeaderMagic != 0x10b && optionalHeaderMagic != 0x20b) { - cerr << "Target file is not a PE32 or PE32+ image.\n"; + std::cerr << "Target file is not a PE32 or PE32+ image.\n"; return 3; } word32 checksumPos = optionalHeaderPos + 64; @@ -261,14 +265,14 @@ int CRYPTOPP_API main(int argc, char *argv[]) word32 certificateTablePos = *(word32 *)(void *)(buf+certificateTableDirectoryPos); word32 certificateTableSize = *(word32 *)(void *)(buf+certificateTableDirectoryPos+4); if (certificateTableSize != 0) - cerr << "Warning: certificate table (IMAGE_DIRECTORY_ENTRY_SECURITY) of target image is not empty.\n"; + std::cerr << "Warning: certificate table (IMAGE_DIRECTORY_ENTRY_SECURITY) of target image is not empty.\n"; // find where to place computed MAC byte mac[] = CRYPTOPP_DUMMY_DLL_MAC; byte *found = std::search(buf.begin(), buf.end(), mac+0, mac+sizeof(mac)); if (found == buf.end()) { - cerr << "MAC placeholder not found. The MAC may already be placed.\n"; + std::cerr << "MAC placeholder not found. The MAC may already be placed.\n"; return 2; } word32 macPos = (unsigned int)(found-buf.begin()); @@ -284,7 +288,7 @@ int CRYPTOPP_API main(int argc, char *argv[]) f.PutMessageEnd(buf.begin(), buf.size()); // Encode MAC - string hexMac; + std::string hexMac; HexEncoder encoder; encoder.Put(mac, sizeof(mac)), encoder.MessageEnd(); hexMac.resize(static_cast(encoder.MaxRetrievable())); @@ -308,24 +312,24 @@ int CRYPTOPP_API main(int argc, char *argv[]) fname = "TestVectors/" + fname + ".txt"; PrintSeedAndThreads(seed); - return !RunTestDataFile(fname.c_str()); + return !Test::RunTestDataFile(fname.c_str()); } else if (command == "t") { // VC60 workaround: use char array instead of std::string to workaround MSVC's getline bug char passPhrase[MAX_PHRASE_LENGTH], plaintext[1024]; - cout << "Passphrase: "; - cin.getline(passPhrase, MAX_PHRASE_LENGTH); + std::cout << "Passphrase: "; + std::cin.getline(passPhrase, MAX_PHRASE_LENGTH); - cout << "\nPlaintext: "; - cin.getline(plaintext, 1024); + std::cout << "\nPlaintext: "; + std::cin.getline(plaintext, 1024); - string ciphertext = EncryptString(plaintext, passPhrase); - cout << "\nCiphertext: " << ciphertext << endl; + std::string ciphertext = EncryptString(plaintext, passPhrase); + std::cout << "\nCiphertext: " << ciphertext << std::endl; - string decrypted = DecryptString(ciphertext.c_str(), passPhrase); - cout << "\nDecrypted: " << decrypted << endl; + std::string decrypted = DecryptString(ciphertext.c_str(), passPhrase); + std::cout << "\nDecrypted: " << decrypted << std::endl; return 0; } @@ -340,8 +344,8 @@ int CRYPTOPP_API main(int argc, char *argv[]) else if (command == "e" || command == "d") { char passPhrase[MAX_PHRASE_LENGTH]; - cout << "Passphrase: "; - cin.getline(passPhrase, MAX_PHRASE_LENGTH); + std::cout << "Passphrase: "; + std::cin.getline(passPhrase, MAX_PHRASE_LENGTH); if (command == "e") EncryptFile(argv[2], argv[3], passPhrase); else @@ -350,23 +354,23 @@ int CRYPTOPP_API main(int argc, char *argv[]) else if (command == "ss") { char thisSeed[1024]; - cout << "\nRandom Seed: "; - ws(cin); - cin.getline(thisSeed, 1024); - SecretShareFile(StringToValue(argv[2]), StringToValue(argv[3]), argv[4], thisSeed); + std::cout << "\nRandom Seed: "; + std::ws(std::cin); + std::cin.getline(thisSeed, 1024); + SecretShareFile(Test::StringToValue(argv[2]), Test::StringToValue(argv[3]), argv[4], thisSeed); } else if (command == "sr") SecretRecoverFile(argc-3, argv[2], argv+3); else if (command == "id") - InformationDisperseFile(StringToValue(argv[2]), StringToValue(argv[3]), argv[4]); + InformationDisperseFile(Test::StringToValue(argv[2]), Test::StringToValue(argv[3]), argv[4]); else if (command == "ir") InformationRecoverFile(argc-3, argv[2], argv+3); else if (command == "v" || command == "vv") - return !Validate(argc>2 ? StringToValue(argv[2]) : 0, argv[1][1] == 'v', argc>3 ? argv[3] : NULL); + return !Validate(argc>2 ? Test::StringToValue(argv[2]) : 0, argv[1][1] == 'v', argc>3 ? argv[3] : NULL); else if (command == "b") - BenchmarkAll(argc<3 ? 1 : StringToValue(argv[2]), argc<4 ? 0.0f : StringToValue(argv[3])*1e9); + Test::BenchmarkAll(argc<3 ? 1 : Test::StringToValue(argv[2]), argc<4 ? 0.0f : Test::StringToValue(argv[3])*1e9); else if (command == "b2") - BenchmarkAll2(argc<3 ? 1 : StringToValue(argv[2]), argc<4 ? 0.0f : StringToValue(argv[3])*1e9); + Test::BenchmarkAll2(argc<3 ? 1 : Test::StringToValue(argv[2]), argc<4 ? 0.0f : Test::StringToValue(argv[3])*1e9); else if (command == "z") GzipFile(argv[3], argv[4], argv[2][0]-'0'); else if (command == "u") @@ -383,7 +387,7 @@ int CRYPTOPP_API main(int argc, char *argv[]) return (*AdhocTest)(argc, argv); else { - cerr << "AdhocTest not defined.\n"; + std::cerr << "AdhocTest not defined.\n"; return 1; } } @@ -393,28 +397,28 @@ int CRYPTOPP_API main(int argc, char *argv[]) AES_CTR_Encrypt(argv[2], argv[3], argv[4], argv[5]); else if (command == "h") { - FileSource usage(CRYPTOPP_DATA_DIR "TestData/usage.dat", true, new FileSink(cout)); + FileSource usage(CRYPTOPP_DATA_DIR "TestData/usage.dat", true, new FileSink(std::cout)); return 1; } else if (command == "V") { - cout << CRYPTOPP_VERSION / 100 << '.' << (CRYPTOPP_VERSION % 100) / 10 << '.' << CRYPTOPP_VERSION % 10 << endl; + std::cout << CRYPTOPP_VERSION / 100 << '.' << (CRYPTOPP_VERSION % 100) / 10 << '.' << CRYPTOPP_VERSION % 10 << std::endl; } else { - cerr << "Unrecognized command. Run \"cryptest h\" to obtain usage information.\n"; + std::cerr << "Unrecognized command. Run \"cryptest h\" to obtain usage information.\n"; return 1; } return 0; } catch(const CryptoPP::Exception &e) { - cout << "\nCryptoPP::Exception caught: " << e.what() << endl; + std::cout << "\nCryptoPP::Exception caught: " << e.what() << std::endl; return -1; } catch(const std::exception &e) { - cout << "\nstd::exception caught: " << e.what() << endl; + std::cout << "\nstd::exception caught: " << e.what() << std::endl; return -2; } } // End main() @@ -428,13 +432,14 @@ void FIPS140_GenerateRandomFiles() for (unsigned int i=0; i<100000; i++) store.TransferTo(FileSink((IntToString(i) + ".rnd").c_str()).Ref(), 20000); #else - cout << "OS provided RNG not available.\n"; + std::cout << "OS provided RNG not available.\n"; exit(-1); #endif } template -T StringToValue(const std::string& str) { +T Test::StringToValue(const std::string& str) +{ std::istringstream iss(str); // Arbitrary, but we need to clear a Coverity finding TAINTED_SCALAR @@ -455,7 +460,7 @@ T StringToValue(const std::string& str) { } template<> -int StringToValue(const std::string& str) +int Test::StringToValue(const std::string& str) { Integer n(str.c_str()); long l = n.ConvertToLong(); @@ -469,7 +474,7 @@ int StringToValue(const std::string& str) void PrintSeedAndThreads(const std::string& seed) { - cout << "Using seed: " << seed << endl; + std::cout << "Using seed: " << seed << std::endl; #ifdef _OPENMP int tc = 0; @@ -506,7 +511,7 @@ void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char pubFile.MessageEnd(); } -string RSAEncryptString(const char *pubFilename, const char *seed, const char *message) +std::string RSAEncryptString(const char *pubFilename, const char *seed, const char *message) { FileSource pubFile(pubFilename, true, new HexDecoder); RSAES_OAEP_SHA_Encryptor pub(pubFile); @@ -514,18 +519,18 @@ string RSAEncryptString(const char *pubFilename, const char *seed, const char *m RandomPool randPool; randPool.IncorporateEntropy((byte *)seed, strlen(seed)); - string result; + std::string result; StringSource(message, true, new PK_EncryptorFilter(randPool, pub, new HexEncoder(new StringSink(result)))); return result; } -string RSADecryptString(const char *privFilename, const char *ciphertext) +std::string RSADecryptString(const char *privFilename, const char *ciphertext) { FileSource privFile(privFilename, true, new HexDecoder); RSAES_OAEP_SHA_Decryptor priv(privFile); - string result; - StringSource(ciphertext, true, new HexDecoder(new PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result)))); + std::string result; + StringSource(ciphertext, true, new HexDecoder(new PK_DecryptorFilter(Test::GlobalRNG(), priv, new StringSink(result)))); return result; } @@ -533,7 +538,7 @@ void RSASignFile(const char *privFilename, const char *messageFilename, const ch { FileSource privFile(privFilename, true, new HexDecoder); RSASS::Signer priv(privFile); - FileSource f(messageFilename, true, new SignerFilter(GlobalRNG(), priv, new HexEncoder(new FileSink(signatureFilename)))); + FileSource f(messageFilename, true, new SignerFilter(Test::GlobalRNG(), priv, new HexEncoder(new FileSink(signatureFilename)))); } bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename) @@ -562,6 +567,7 @@ void DigestFile(const char *filename) Tiger tiger; SHA512 sha512; Whirlpool whirlpool; + vector_member_ptrs filters(6); filters[0].reset(new HashFilter(sha)); filters[1].reset(new HashFilter(ripemd)); @@ -576,12 +582,12 @@ void DigestFile(const char *filename) channelSwitch->AddDefaultRoute(*filters[i]); FileSource(filename, true, channelSwitch.release()); - HexEncoder encoder(new FileSink(cout), false); + HexEncoder encoder(new FileSink(std::cout), false); for (i=0; iAlgorithmName() << ": "; + std::cout << filters[i]->AlgorithmName() << ": "; filters[i]->TransferTo(encoder); - cout << "\n"; + std::cout << "\n"; } } @@ -590,7 +596,7 @@ void HmacFile(const char *hexKey, const char *file) member_ptr mac; if (strcmp(hexKey, "selftest") == 0) { - cerr << "Computing HMAC/SHA1 value for self test.\n"; + std::cerr << "Computing HMAC/SHA1 value for self test.\n"; mac.reset(NewIntegrityCheckingMAC()); } else @@ -599,7 +605,7 @@ void HmacFile(const char *hexKey, const char *file) StringSource(hexKey, true, new HexDecoder(new StringSink(decodedKey))); mac.reset(new HMAC((const byte *)decodedKey.data(), decodedKey.size())); } - FileSource(file, true, new HashFilter(*mac, new HexEncoder(new FileSink(cout)))); + FileSource(file, true, new HashFilter(*mac, new HexEncoder(new FileSink(std::cout)))); } void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile) @@ -610,9 +616,9 @@ void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile))); } -string EncryptString(const char *instr, const char *passPhrase) +std::string EncryptString(const char *instr, const char *passPhrase) { - string outstr; + std::string outstr; DefaultEncryptorWithMAC encryptor(passPhrase, new HexEncoder(new StringSink(outstr))); encryptor.Put((byte *)instr, strlen(instr)); @@ -621,9 +627,9 @@ string EncryptString(const char *instr, const char *passPhrase) return outstr; } -string DecryptString(const char *instr, const char *passPhrase) +std::string DecryptString(const char *instr, const char *passPhrase) { - string outstr; + std::string outstr; HexDecoder decryptor(new DefaultDecryptorWithMAC(passPhrase, new StringSink(outstr))); decryptor.Put((byte *)instr, strlen(instr)); @@ -655,14 +661,14 @@ void SecretShareFile(int threshold, int nShares, const char *filename, const cha FileSource source(filename, false, new SecretSharing(rng, threshold, nShares, channelSwitch = new ChannelSwitch)); vector_member_ptrs fileSinks(nShares); - string channel; + std::string channel; for (int i=0; i(i); fileSinks[i]->Put((const byte *)channel.data(), 4); @@ -688,7 +694,7 @@ void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFi fileSources[i].reset(new FileSource(inFilenames[i], false)); fileSources[i]->Pump(4); fileSources[i]->Get(channel, 4); - fileSources[i]->Attach(new ChannelSwitch(recovery, string((char *)channel.begin(), 4))); + fileSources[i]->Attach(new ChannelSwitch(recovery, std::string((char *)channel.begin(), 4))); } while (fileSources[0]->Pump(256)) @@ -709,14 +715,14 @@ void InformationDisperseFile(int threshold, int nShares, const char *filename) FileSource source(filename, false, new InformationDispersal(threshold, nShares, channelSwitch = new ChannelSwitch)); vector_member_ptrs fileSinks(nShares); - string channel; + std::string channel; for (int i=0; i(i); fileSinks[i]->Put((const byte *)channel.data(), 4); @@ -742,7 +748,7 @@ void InformationRecoverFile(int threshold, const char *outFilename, char *const fileSources[i].reset(new FileSource(inFilenames[i], false)); fileSources[i]->Pump(4); fileSources[i]->Get(channel, 4); - fileSources[i]->Attach(new ChannelSwitch(recovery, string((char *)channel.begin(), 4))); + fileSources[i]->Attach(new ChannelSwitch(recovery, std::string((char *)channel.begin(), 4))); } while (fileSources[0]->Pump(256)) @@ -832,18 +838,18 @@ void ForwardTcpPort(const char *sourcePortName, const char *destinationHost, con if(err != 0) throw Socket::Err(sockListen, "setsockopt", sockListen.GetLastError()); - cout << "Listing on port " << sourcePort << ".\n"; + std::cout << "Listing on port " << sourcePort << ".\n"; sockListen.Listen(); sockListen.Accept(sockSource); - cout << "Connection accepted on port " << sourcePort << ".\n"; + std::cout << "Connection accepted on port " << sourcePort << ".\n"; sockListen.CloseSocket(); - cout << "Making connection to " << destinationHost << ", port " << destinationPort << ".\n"; + std::cout << "Making connection to " << destinationHost << ", port " << destinationPort << ".\n"; sockDestination.Create(); sockDestination.Connect(destinationHost, destinationPort); - cout << "Connection made to " << destinationHost << ", starting to forward.\n"; + std::cout << "Connection made to " << destinationHost << ", starting to forward.\n"; SocketSource out(sockSource, false, new SocketSink(sockDestination)); SocketSource in(sockDestination, false, new SocketSink(sockSource)); @@ -861,22 +867,22 @@ void ForwardTcpPort(const char *sourcePortName, const char *destinationHost, con if (!out.SourceExhausted()) { - cout << "o" << flush; + std::cout << "o" << std::flush; out.PumpAll2(false); if (out.SourceExhausted()) - cout << "EOF received on source socket.\n"; + std::cout << "EOF received on source socket.\n"; } if (!in.SourceExhausted()) { - cout << "i" << flush; + std::cout << "i" << std::flush; in.PumpAll2(false); if (in.SourceExhausted()) - cout << "EOF received on destination socket.\n"; + std::cout << "EOF received on destination socket.\n"; } } #else - cout << "Socket support was not enabled at compile time.\n"; + std::cout << "Socket support was not enabled at compile time.\n"; exit(-1); #endif } @@ -890,106 +896,106 @@ bool Validate(int alg, bool thorough, const char *seedInput) std::string seed = (seedInput ? seedInput : IntToString(time(NULL))); seed.resize(16, ' '); - OFB_Mode::Encryption& prng = dynamic_cast::Encryption&>(GlobalRNG()); + OFB_Mode::Encryption& prng = dynamic_cast::Encryption&>(Test::GlobalRNG()); prng.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data()); PrintSeedAndThreads(seed); switch (alg) { - case 0: result = ValidateAll(thorough); break; - case 1: result = TestSettings(); break; - case 2: result = TestOS_RNG(); break; -// case 3: result = TestSecRandom(); break; - case 4: result = ValidateMD5(); break; - case 5: result = ValidateSHA(); break; - case 6: result = ValidateDES(); break; - case 7: result = ValidateIDEA(); break; - case 8: result = ValidateARC4(); break; - case 9: result = ValidateRC5(); break; - case 10: result = ValidateBlowfish(); break; -// case 11: result = ValidateDiamond2(); break; - case 12: result = ValidateThreeWay(); break; - case 13: result = ValidateBBS(); break; - case 14: result = ValidateDH(); break; - case 15: result = ValidateRSA(); break; - case 16: result = ValidateElGamal(); break; - case 17: result = ValidateDSA(thorough); break; -// case 18: result = ValidateHAVAL(); break; - case 19: result = ValidateSAFER(); break; - case 20: result = ValidateLUC(); break; - case 21: result = ValidateRabin(); break; -// case 22: result = ValidateBlumGoldwasser(); break; - case 23: result = ValidateECP(); break; - case 24: result = ValidateEC2N(); break; -// case 25: result = ValidateMD5MAC(); break; - case 26: result = ValidateGOST(); break; - case 27: result = ValidateTiger(); break; - case 28: result = ValidateRIPEMD(); break; - case 29: result = ValidateHMAC(); break; -// case 30: result = ValidateXMACC(); break; - case 31: result = ValidateSHARK(); break; - case 32: result = ValidateLUC_DH(); break; - case 33: result = ValidateLUC_DL(); break; - case 34: result = ValidateSEAL(); break; - case 35: result = ValidateCAST(); break; - case 36: result = ValidateSquare(); break; - case 37: result = ValidateRC2(); break; - case 38: result = ValidateRC6(); break; - case 39: result = ValidateMARS(); break; - case 40: result = ValidateRW(); break; - case 41: result = ValidateMD2(); break; - case 42: result = ValidateNR(); break; - case 43: result = ValidateMQV(); break; - case 44: result = ValidateRijndael(); break; - case 45: result = ValidateTwofish(); break; - case 46: result = ValidateSerpent(); break; - case 47: result = ValidateCipherModes(); break; - case 48: result = ValidateCRC32(); break; - case 49: result = ValidateCRC32C(); break; - case 50: result = ValidateECDSA(); break; - case 51: result = ValidateECGDSA(); break; - case 52: result = ValidateXTR_DH(); break; - case 53: result = ValidateSKIPJACK(); break; - case 54: result = ValidateSHA2(); break; - case 55: result = ValidatePanama(); break; - case 56: result = ValidateAdler32(); break; - case 57: result = ValidateMD4(); break; - case 58: result = ValidatePBKDF(); break; - case 59: result = ValidateESIGN(); break; - case 60: result = ValidateDLIES(); break; - case 61: result = ValidateBaseCode(); break; - case 62: result = ValidateSHACAL2(); break; - case 63: result = ValidateCamellia(); break; - case 64: result = ValidateWhirlpool(); break; - case 65: result = ValidateTTMAC(); break; - case 66: result = ValidateSalsa(); break; - case 67: result = ValidateSosemanuk(); break; - case 68: result = ValidateVMAC(); break; - case 69: result = ValidateCCM(); break; - case 70: result = ValidateGCM(); break; - case 71: result = ValidateCMAC(); break; - case 72: result = ValidateHKDF(); break; - case 73: result = ValidateBLAKE2s(); break; - case 74: result = ValidateBLAKE2b(); break; - case 75: result = ValidatePoly1305(); break; - case 76: result = ValidateSipHash(); break; - case 77: result = ValidateHashDRBG(); break; - case 78: result = ValidateHmacDRBG(); break; + case 0: result = Test::ValidateAll(thorough); break; + case 1: result = Test::TestSettings(); break; + case 2: result = Test::TestOS_RNG(); break; +// case 3: result = Test::TestSecRandom(); break; + case 4: result = Test::ValidateMD5(); break; + case 5: result = Test::ValidateSHA(); break; + case 6: result = Test::ValidateDES(); break; + case 7: result = Test::ValidateIDEA(); break; + case 8: result = Test::ValidateARC4(); break; + case 9: result = Test::ValidateRC5(); break; + case 10: result = Test::ValidateBlowfish(); break; +// case 11: result = Test::ValidateDiamond2(); break; + case 12: result = Test::ValidateThreeWay(); break; + case 13: result = Test::ValidateBBS(); break; + case 14: result = Test::ValidateDH(); break; + case 15: result = Test::ValidateRSA(); break; + case 16: result = Test::ValidateElGamal(); break; + case 17: result = Test::ValidateDSA(thorough); break; +// case 18: result = Test::ValidateHAVAL(); break; + case 19: result = Test::ValidateSAFER(); break; + case 20: result = Test::ValidateLUC(); break; + case 21: result = Test::ValidateRabin(); break; +// case 22: result = Test::ValidateBlumGoldwasser(); break; + case 23: result = Test::ValidateECP(); break; + case 24: result = Test::ValidateEC2N(); break; +// case 25: result = Test::ValidateMD5MAC(); break; + case 26: result = Test::ValidateGOST(); break; + case 27: result = Test::ValidateTiger(); break; + case 28: result = Test::ValidateRIPEMD(); break; + case 29: result = Test::ValidateHMAC(); break; +// case 30: result = Test::ValidateXMACC(); break; + case 31: result = Test::ValidateSHARK(); break; + case 32: result = Test::ValidateLUC_DH(); break; + case 33: result = Test::ValidateLUC_DL(); break; + case 34: result = Test::ValidateSEAL(); break; + case 35: result = Test::ValidateCAST(); break; + case 36: result = Test::ValidateSquare(); break; + case 37: result = Test::ValidateRC2(); break; + case 38: result = Test::ValidateRC6(); break; + case 39: result = Test::ValidateMARS(); break; + case 40: result = Test::ValidateRW(); break; + case 41: result = Test::ValidateMD2(); break; + case 42: result = Test::ValidateNR(); break; + case 43: result = Test::ValidateMQV(); break; + case 44: result = Test::ValidateRijndael(); break; + case 45: result = Test::ValidateTwofish(); break; + case 46: result = Test::ValidateSerpent(); break; + case 47: result = Test::ValidateCipherModes(); break; + case 48: result = Test::ValidateCRC32(); break; + case 49: result = Test::ValidateCRC32C(); break; + case 50: result = Test::ValidateECDSA(); break; + case 51: result = Test::ValidateECGDSA(); break; + case 52: result = Test::ValidateXTR_DH(); break; + case 53: result = Test::ValidateSKIPJACK(); break; + case 54: result = Test::ValidateSHA2(); break; + case 55: result = Test::ValidatePanama(); break; + case 56: result = Test::ValidateAdler32(); break; + case 57: result = Test::ValidateMD4(); break; + case 58: result = Test::ValidatePBKDF(); break; + case 59: result = Test::ValidateESIGN(); break; + case 60: result = Test::ValidateDLIES(); break; + case 61: result = Test::ValidateBaseCode(); break; + case 62: result = Test::ValidateSHACAL2(); break; + case 63: result = Test::ValidateCamellia(); break; + case 64: result = Test::ValidateWhirlpool(); break; + case 65: result = Test::ValidateTTMAC(); break; + case 66: result = Test::ValidateSalsa(); break; + case 67: result = Test::ValidateSosemanuk(); break; + case 68: result = Test::ValidateVMAC(); break; + case 69: result = Test::ValidateCCM(); break; + case 70: result = Test::ValidateGCM(); break; + case 71: result = Test::ValidateCMAC(); break; + case 72: result = Test::ValidateHKDF(); break; + case 73: result = Test::ValidateBLAKE2s(); break; + case 74: result = Test::ValidateBLAKE2b(); break; + case 75: result = Test::ValidatePoly1305(); break; + case 76: result = Test::ValidateSipHash(); break; + case 77: result = Test::ValidateHashDRBG(); break; + case 78: result = Test::ValidateHmacDRBG(); break; #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS) // http://github.com/weidai11/cryptopp/issues/92 - case 9999: result = TestSecBlock(); break; + case 9999: result = Test::TestSecBlock(); break; // http://github.com/weidai11/cryptopp/issues/64 - case 9998: result = TestPolynomialMod2(); break; + case 9998: result = Test::TestPolynomialMod2(); break; // http://github.com/weidai11/cryptopp/issues/336 - case 9997: result = TestIntegerBitops(); break; + case 9997: result = Test::TestIntegerBitops(); break; // http://github.com/weidai11/cryptopp/issues/360 - case 9996: result = TestRounding(); break; + case 9996: result = Test::TestRounding(); break; // http://github.com/weidai11/cryptopp/issues/242 - case 9995: result = TestHuffmanCodes(); break; + case 9995: result = Test::TestHuffmanCodes(); break; // http://github.com/weidai11/cryptopp/issues/346 - case 9994: result = TestASN1Parse(); break; + case 9994: result = Test::TestASN1Parse(); break; #endif default: return false; @@ -1007,13 +1013,13 @@ bool Validate(int alg, bool thorough, const char *seedInput) err = asctime_s(timeBuf, sizeof(timeBuf), &localTime); CRYPTOPP_ASSERT(err == 0); - cout << "\nTest ended at " << timeBuf; + std::cout << "\nTest ended at " << timeBuf; #else const time_t endTime = time(NULL); - cout << "\nTest ended at " << asctime(localtime(&endTime)); + std::cout << "\nTest ended at " << asctime(localtime(&endTime)); #endif - cout << "Seed used was: " << seed << endl; + std::cout << "Seed used was: " << seed << std::endl; return result; } diff --git a/validat0.cpp b/validat0.cpp index 5a766813..ce1f226b 100644 --- a/validat0.cpp +++ b/validat0.cpp @@ -21,11 +21,8 @@ # pragma strict_gs_check (on) #endif -#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -USING_NAMESPACE(CryptoPP) +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS) bool TestRounding() @@ -735,11 +732,11 @@ bool TestSecBlock() { std::basic_string, AllocatorWithCleanup > s1; - std::basic_string, AllocatorWithCleanup > s2; + std::basic_string, AllocatorWithCleanup > s2; s1.resize(1024); s2.resize(1024); std::vector > v1; - std::vector > v2; + std::vector > v2; v1.resize(1024); v2.resize(1024); } @@ -2366,3 +2363,6 @@ bool TestIntegerBitops() return opa && opo && opx; } #endif + +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP diff --git a/validat1.cpp b/validat1.cpp index bedc4c8b..0e3baf92 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -1,4 +1,5 @@ // validat1.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #include "pch.h" @@ -60,12 +61,8 @@ # pragma strict_gs_check (on) #endif -#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -USING_NAMESPACE(CryptoPP) -USING_NAMESPACE(std) +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) bool ValidateAll(bool thorough) { @@ -179,9 +176,9 @@ bool ValidateAll(bool thorough) pass=ValidateESIGN() && pass; if (pass) - cout << "\nAll tests passed!\n"; + std::cout << "\nAll tests passed!\n"; else - cout << "\nOops! Not all tests passed.\n"; + std::cout << "\nOops! Not all tests passed.\n"; return pass; } @@ -190,7 +187,7 @@ bool TestSettings() { bool pass = true; - cout << "\nTesting Settings...\n\n"; + std::cout << "\nTesting Settings...\n\n"; word32 w; const byte s[] = "\x01\x02\x03\x04"; @@ -205,26 +202,26 @@ bool TestSettings() if (w == 0x04030201L) { #ifdef IS_LITTLE_ENDIAN - cout << "passed: "; + std::cout << "passed: "; #else - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; #endif - cout << "Your machine is little endian.\n"; + std::cout << "Your machine is little endian.\n"; } else if (w == 0x01020304L) { #ifndef IS_LITTLE_ENDIAN - cout << "passed: "; + std::cout << "passed: "; #else - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; #endif - cout << "Your machine is big endian.\n"; + std::cout << "Your machine is big endian.\n"; } else { - cout << "FAILED: Your machine is neither big endian nor little endian.\n"; + std::cout << "FAILED: Your machine is neither big endian nor little endian.\n"; pass = false; } @@ -233,74 +230,74 @@ bool TestSettings() const int v1 = LibraryVersion(); const int v2 = HeaderVersion(); if(v1/10 == v2/10) - cout << "passed: "; + std::cout << "passed: "; else { - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; } - cout << "Library version (library): " << v1 << ", header version (app): " << v2 << "\n"; + std::cout << "Library version (library): " << v1 << ", header version (app): " << v2 << "\n"; #endif #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS // Don't assert the alignment of testvals. That's what this test is for. byte testvals[10] = {1,2,2,3,3,3,3,2,2,1}; if (*(word32 *)(void *)(testvals+3) == 0x03030303 && *(word64 *)(void *)(testvals+1) == W64LIT(0x0202030303030202)) - cout << "passed: Your machine allows unaligned data access.\n"; + std::cout << "passed: Your machine allows unaligned data access.\n"; else { - cout << "FAILED: Unaligned data access gave incorrect results.\n"; + std::cout << "FAILED: Unaligned data access gave incorrect results.\n"; pass = false; } #else - cout << "passed: CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is not defined. Will restrict to aligned data access.\n"; + std::cout << "passed: CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is not defined. Will restrict to aligned data access.\n"; #endif if (sizeof(byte) == 1) - cout << "passed: "; + std::cout << "passed: "; else { - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; } - cout << "sizeof(byte) == " << sizeof(byte) << endl; + std::cout << "sizeof(byte) == " << sizeof(byte) << std::endl; if (sizeof(word16) == 2) - cout << "passed: "; + std::cout << "passed: "; else { - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; } - cout << "sizeof(word16) == " << sizeof(word16) << endl; + std::cout << "sizeof(word16) == " << sizeof(word16) << std::endl; if (sizeof(word32) == 4) - cout << "passed: "; + std::cout << "passed: "; else { - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; } - cout << "sizeof(word32) == " << sizeof(word32) << endl; + std::cout << "sizeof(word32) == " << sizeof(word32) << std::endl; if (sizeof(word64) == 8) - cout << "passed: "; + std::cout << "passed: "; else { - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; } - cout << "sizeof(word64) == " << sizeof(word64) << endl; + std::cout << "sizeof(word64) == " << sizeof(word64) << std::endl; #ifdef CRYPTOPP_WORD128_AVAILABLE if (sizeof(word128) == 16) - cout << "passed: "; + std::cout << "passed: "; else { - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; } - cout << "sizeof(word128) == " << sizeof(word128) << endl; + std::cout << "sizeof(word128) == " << sizeof(word128) << std::endl; #endif if (sizeof(word) == 2*sizeof(hword) @@ -308,17 +305,17 @@ bool TestSettings() && sizeof(dword) == 2*sizeof(word) #endif ) - cout << "passed: "; + std::cout << "passed: "; else { - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; } - cout << "sizeof(hword) == " << sizeof(hword) << ", sizeof(word) == " << sizeof(word); + std::cout << "sizeof(hword) == " << sizeof(hword) << ", sizeof(word) == " << sizeof(word); #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE - cout << ", sizeof(dword) == " << sizeof(dword); + std::cout << ", sizeof(dword) == " << sizeof(dword); #endif - cout << endl; + std::cout << std::endl; #ifdef CRYPTOPP_CPUID_AVAILABLE bool hasMMX = HasMMX(); @@ -331,15 +328,15 @@ bool TestSettings() if ((isP4 && (!hasMMX || !hasSSE2)) || (hasSSE2 && !hasMMX) || (cacheLineSize < 16 || cacheLineSize > 256 || !IsPowerOf2(cacheLineSize))) { - cout << "FAILED: "; + std::cout << "FAILED: "; pass = false; } else - cout << "passed: "; + std::cout << "passed: "; - cout << "hasMMX == " << hasMMX << ", hasISSE == " << hasISSE << ", hasSSE2 == " << hasSSE2 << ", hasSSSE3 == " << hasSSSE3 << ", hasSSE4 == " << hasSSE4; - cout << ", hasAESNI == " << HasAESNI() << ", hasCLMUL == " << HasCLMUL() << ", hasRDRAND == " << HasRDRAND() << ", hasRDSEED == " << HasRDSEED(); - cout << ", hasSHA == " << HasSHA() << ", isP4 == " << isP4 << ", cacheLineSize == " << cacheLineSize << endl; + std::cout << "hasMMX == " << hasMMX << ", hasISSE == " << hasISSE << ", hasSSE2 == " << hasSSE2 << ", hasSSSE3 == " << hasSSSE3 << ", hasSSE4 == " << hasSSE4; + std::cout << ", hasAESNI == " << HasAESNI() << ", hasCLMUL == " << HasCLMUL() << ", hasRDRAND == " << HasRDRAND() << ", hasRDSEED == " << HasRDSEED(); + std::cout << ", hasSHA == " << HasSHA() << ", isP4 == " << isP4 << ", cacheLineSize == " << cacheLineSize << std::endl; #elif (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) bool hasNEON = HasNEON(); @@ -349,13 +346,13 @@ bool TestSettings() bool hasSHA1 = HasSHA1(); bool hasSHA2 = HasSHA2(); - cout << "passed: "; - cout << "hasNEON == " << hasNEON << ", hasPMULL == " << hasPMULL << ", hasCRC32 == " << hasCRC32 << ", hasAES == " << hasAES << ", hasSHA1 == " << hasSHA1 << ", hasSHA2 == " << hasSHA2 << endl; + std::cout << "passed: "; + std::cout << "hasNEON == " << hasNEON << ", hasPMULL == " << hasPMULL << ", hasCRC32 == " << hasCRC32 << ", hasAES == " << hasAES << ", hasSHA1 == " << hasSHA1 << ", hasSHA2 == " << hasSHA2 << std::endl; #endif if (!pass) { - cout << "Some critical setting in config.h is in error. Please fix it and recompile." << endl; + std::cout << "Some critical setting in config.h is in error. Please fix it and recompile." << std::endl; abort(); } return pass; @@ -374,7 +371,7 @@ bool TestOS_RNG() if (rng.get()) { - cout << "\nTesting operating system provided blocking random number generator...\n\n"; + std::cout << "\nTesting operating system provided blocking random number generator...\n\n"; MeterFilter meter(new Redirector(TheBitBucket())); RandomNumberSource test(*rng, UINT_MAX, false, new Deflator(new Redirector(meter))); @@ -392,12 +389,12 @@ bool TestOS_RNG() if (total < 16) { - cout << "FAILED:"; + std::cout << "FAILED:"; pass = false; } else - cout << "passed:"; - cout << " it took " << long(t1) << " seconds to generate " << total << " bytes" << endl; + std::cout << "passed:"; + std::cout << " it took " << long(t1) << " seconds to generate " << total << " bytes" << std::endl; #if 0 // disable this part. it's causing an unpredictable pause during the validation testing if (t1 < 2) @@ -422,12 +419,12 @@ bool TestOS_RNG() } if (length > 1024) { - cout << "FAILED:"; + std::cout << "FAILED:"; pass = false; } else - cout << "passed:"; - cout << " it generated " << length << " bytes in " << long(time(NULL) - t) << " seconds" << endl; + std::cout << "passed:"; + std::cout << " it generated " << length << " bytes in " << long(time(NULL) - t) << " seconds" << std::endl; } #endif @@ -435,15 +432,15 @@ bool TestOS_RNG() if (meter.GetTotalBytes() < total) { - cout << "FAILED:"; + std::cout << "FAILED:"; pass = false; } else - cout << "passed:"; - cout << " " << total << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << endl; + std::cout << "passed:"; + std::cout << " " << total << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << std::endl; } else - cout << "\nNo operating system provided blocking random number generator, skipping test." << endl; + std::cout << "\nNo operating system provided blocking random number generator, skipping test." << std::endl; rng.reset(NULL); #ifdef NONBLOCKING_RNG_AVAILABLE @@ -453,22 +450,22 @@ bool TestOS_RNG() if (rng.get()) { - cout << "\nTesting operating system provided nonblocking random number generator...\n\n"; + std::cout << "\nTesting operating system provided nonblocking random number generator...\n\n"; MeterFilter meter(new Redirector(TheBitBucket())); RandomNumberSource test(*rng, 100000, true, new Deflator(new Redirector(meter))); if (meter.GetTotalBytes() < 100000) { - cout << "FAILED:"; + std::cout << "FAILED:"; pass = false; } else - cout << "passed:"; - cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << endl; + std::cout << "passed:"; + std::cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << std::endl; } else - cout << "\nNo operating system provided nonblocking random number generator, skipping test." << endl; + std::cout << "\nNo operating system provided nonblocking random number generator, skipping test." << std::endl; return pass; } @@ -486,7 +483,7 @@ bool TestAutoSeededX917() bool TestAutoSeeded() { // This tests Auto-Seeding and GenerateIntoBufferedTransformation. - cout << "\nTesting AutoSeeded generator...\n\n"; + std::cout << "\nTesting AutoSeeded generator...\n\n"; AutoSeededRandomPool prng; static const unsigned int ENTROPY_SIZE = 32; @@ -497,12 +494,12 @@ bool TestAutoSeeded() if (meter.GetTotalBytes() < 100000) { - cout << "FAILED:"; + std::cout << "FAILED:"; generate = false; } else - cout << "passed:"; - cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << endl; + std::cout << "passed:"; + std::cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << std::endl; try { @@ -514,10 +511,10 @@ bool TestAutoSeeded() } if (!discard) - cout << "FAILED:"; + std::cout << "FAILED:"; else - cout << "passed:"; - cout << " discarded 10000 bytes" << endl; + std::cout << "passed:"; + std::cout << " discarded 10000 bytes" << std::endl; try { @@ -539,10 +536,10 @@ bool TestAutoSeeded() } if (!incorporate) - cout << "FAILED:"; + std::cout << "FAILED:"; else - cout << "passed:"; - cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << endl; + std::cout << "passed:"; + std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << std::endl; return generate && discard && incorporate; } @@ -550,7 +547,7 @@ bool TestAutoSeeded() bool TestAutoSeededX917() { // This tests Auto-Seeding and GenerateIntoBufferedTransformation. - cout << "\nTesting AutoSeeded X917 generator...\n\n"; + std::cout << "\nTesting AutoSeeded X917 generator...\n\n"; AutoSeededX917RNG prng; static const unsigned int ENTROPY_SIZE = 32; @@ -561,12 +558,12 @@ bool TestAutoSeededX917() if (meter.GetTotalBytes() < 100000) { - cout << "FAILED:"; + std::cout << "FAILED:"; generate = false; } else - cout << "passed:"; - cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << endl; + std::cout << "passed:"; + std::cout << " 100000 generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE" << std::endl; try { @@ -578,10 +575,10 @@ bool TestAutoSeededX917() } if (!discard) - cout << "FAILED:"; + std::cout << "FAILED:"; else - cout << "passed:"; - cout << " discarded 10000 bytes" << endl; + std::cout << "passed:"; + std::cout << " discarded 10000 bytes" << std::endl; try { @@ -603,10 +600,10 @@ bool TestAutoSeededX917() } if (!incorporate) - cout << "FAILED:"; + std::cout << "FAILED:"; else - cout << "passed:"; - cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << endl; + std::cout << "passed:"; + std::cout << " IncorporateEntropy with " << 4*ENTROPY_SIZE << " bytes" << std::endl; return generate && discard && incorporate; } @@ -622,7 +619,7 @@ bool TestRDRAND() if (HasRDRAND()) { - cout << "\nTesting RDRAND generator...\n\n"; + std::cout << "\nTesting RDRAND generator...\n\n"; MeterFilter meter(new Redirector(TheBitBucket())); Deflator deflator(new Redirector(meter)); @@ -639,25 +636,25 @@ bool TestRDRAND() const double mv = maurer.GetTestValue(); if (mv < 0.98f) { - cout << "FAILED:"; + std::cout << "FAILED:"; entropy = false; } else - cout << "passed:"; + std::cout << "passed:"; // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. - StreamState ss(cout); - cout << std::setiosflags(std::ios::fixed) << std::setprecision(6); - cout << " Maurer Randomness Test returned value " << mv << endl; + StreamState ss(std::cout); + std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6); + std::cout << " Maurer Randomness Test returned value " << mv << std::endl; if (meter.GetTotalBytes() < SIZE) { - cout << "FAILED:"; + std::cout << "FAILED:"; compress = false; } else - cout << "passed:"; - cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n"; + std::cout << "passed:"; + std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n"; try { @@ -669,13 +666,13 @@ bool TestRDRAND() } if (!discard) - cout << "FAILED:"; + std::cout << "FAILED:"; else - cout << "passed:"; - cout << " discarded " << SIZE << " bytes\n"; + std::cout << "passed:"; + std::cout << " discarded " << SIZE << " bytes\n"; } else - cout << "\nRDRAND generator not available, skipping test.\n"; + std::cout << "\nRDRAND generator not available, skipping test.\n"; // Squash code coverage warnings on unused functions (void)rdrand.AlgorithmName(); @@ -684,7 +681,7 @@ bool TestRDRAND() rdrand.IncorporateEntropy(NULL, 0); if (!(entropy && compress && discard)) - cout.flush(); + std::cout.flush(); return entropy && compress && discard; } @@ -701,7 +698,7 @@ bool TestRDSEED() if (HasRDSEED()) { - cout << "\nTesting RDSEED generator...\n\n"; + std::cout << "\nTesting RDSEED generator...\n\n"; MeterFilter meter(new Redirector(TheBitBucket())); Deflator deflator(new Redirector(meter)); @@ -718,25 +715,25 @@ bool TestRDSEED() const double mv = maurer.GetTestValue(); if (mv < 0.98f) { - cout << "FAILED:"; + std::cout << "FAILED:"; entropy = false; } else - cout << "passed:"; + std::cout << "passed:"; // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. - StreamState ss(cout); - cout << std::setiosflags(std::ios::fixed) << std::setprecision(6); - cout << " Maurer Randomness Test returned value " << mv << endl; + StreamState ss(std::cout); + std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(6); + std::cout << " Maurer Randomness Test returned value " << mv << std::endl; if (meter.GetTotalBytes() < SIZE) { - cout << "FAILED:"; + std::cout << "FAILED:"; compress = false; } else - cout << "passed:"; - cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n"; + std::cout << "passed:"; + std::cout << " " << SIZE << " generated bytes compressed to " << meter.GetTotalBytes() << " bytes by DEFLATE\n"; try { @@ -748,13 +745,13 @@ bool TestRDSEED() } if (!discard) - cout << "FAILED:"; + std::cout << "FAILED:"; else - cout << "passed:"; - cout << " discarded " << SIZE << " bytes\n"; + std::cout << "passed:"; + std::cout << " discarded " << SIZE << " bytes\n"; } else - cout << "\nRDSEED generator not available, skipping test.\n"; + std::cout << "\nRDSEED generator not available, skipping test.\n"; // Squash code coverage warnings on unused functions (void)rdseed.AlgorithmName(); @@ -763,7 +760,7 @@ bool TestRDSEED() rdseed.IncorporateEntropy(NULL, 0); if (!(entropy && compress && discard)) - cout.flush(); + std::cout.flush(); return entropy && compress && discard; } @@ -771,7 +768,7 @@ bool TestRDSEED() bool ValidateHashDRBG() { - cout << "\nTesting NIST Hash DRBGs...\n\n"; + std::cout << "\nTesting NIST Hash DRBGs...\n\n"; bool pass=true, fail; // # CAVS 14.3 @@ -800,7 +797,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (COUNT=0, E=16, N=8)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (COUNT=0, E=16, N=8)\n"; } { @@ -825,7 +822,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (COUNT=1, E=16, N=8)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (COUNT=1, E=16, N=8)\n"; } { @@ -853,7 +850,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=16)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=16)\n"; } { @@ -881,7 +878,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=16)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=16)\n"; } { @@ -907,7 +904,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=0, P=16)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=0, P=16)\n"; } { @@ -933,7 +930,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=0, P=16)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=0, P=16)\n"; } { @@ -962,7 +959,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=16, P=16)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=16, P=16)\n"; } { @@ -991,7 +988,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=16, P=16)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=16, P=16)\n"; } { @@ -1023,7 +1020,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 1024/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA256/128/440 (C0UNT=0, E=32, N=16, A=32, P=32)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA256/128/440 (C0UNT=0, E=32, N=16, A=32, P=32)\n"; } { @@ -1055,7 +1052,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 1024/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA256/128/440 (C0UNT=1, E=32, N=16, A=32, P=32)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA256/128/440 (C0UNT=1, E=32, N=16, A=32, P=32)\n"; } { @@ -1093,7 +1090,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 2048/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA512/256/888 (C0UNT=0, E=32, N=16, A=32, P=32)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA512/256/888 (C0UNT=0, E=32, N=16, A=32, P=32)\n"; } { @@ -1131,7 +1128,7 @@ bool ValidateHashDRBG() fail = !!memcmp(result, expected, 2048/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA512/256/888 (C0UNT=1, E=32, N=16, A=32, P=32)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA512/256/888 (C0UNT=1, E=32, N=16, A=32, P=32)\n"; } return pass; @@ -1139,7 +1136,7 @@ bool ValidateHashDRBG() bool ValidateHmacDRBG() { - cout << "\nTesting NIST HMAC DRBGs...\n\n"; + std::cout << "\nTesting NIST HMAC DRBGs...\n\n"; bool pass=true, fail; // # CAVS 14.3 @@ -1168,7 +1165,7 @@ bool ValidateHmacDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=0, E=16, N=8)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=0, E=16, N=8)\n"; } { @@ -1193,7 +1190,7 @@ bool ValidateHmacDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=1, E=16, N=8)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=1, E=16, N=8)\n"; } // ***************************************************** @@ -1223,7 +1220,7 @@ bool ValidateHmacDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=0, E=16, N=8, A=16)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=0, E=16, N=8, A=16)\n"; } { @@ -1251,7 +1248,7 @@ bool ValidateHmacDRBG() fail = !!memcmp(result, expected, 640/8); pass = !fail && pass; - cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=1, E=16, N=8, A=16)\n"; + std::cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=1, E=16, N=8, A=16)\n"; } return pass; @@ -1300,7 +1297,7 @@ public: bool BlockTransformationTest(const CipherFactory &cg, BufferedTransformation &valdata, unsigned int tuples = 0xffff) { - HexEncoder output(new FileSink(cout)); + HexEncoder output(new FileSink(std::cout)); SecByteBlock plain(cg.BlockSize()), cipher(cg.BlockSize()), out(cg.BlockSize()), outplain(cg.BlockSize()); SecByteBlock key(cg.KeyLength()); bool pass=true, fail; @@ -1321,13 +1318,13 @@ bool BlockTransformationTest(const CipherFactory &cg, BufferedTransformation &va pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); + std::cout << (fail ? "FAILED " : "passed "); output.Put(key, cg.KeyLength()); - cout << " "; + std::cout << " "; output.Put(outplain, cg.BlockSize()); - cout << " "; + std::cout << " "; output.Put(out, cg.BlockSize()); - cout << endl; + std::cout << std::endl; } return pass; } @@ -1391,12 +1388,12 @@ bool TestFilter(BufferedTransformation &bt, const byte *in, size_t inLen, const bool ValidateDES() { - cout << "\nDES validation suite running...\n\n"; + std::cout << "\nDES validation suite running...\n\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/descert.dat", true, new HexDecoder); bool pass = BlockTransformationTest(FixedRoundsCipherFactory(), valdata); - cout << "\nTesting EDE2, EDE3, and XEX3 variants...\n\n"; + std::cout << "\nTesting EDE2, EDE3, and XEX3 variants...\n\n"; FileSource valdata1(CRYPTOPP_DATA_DIR "TestData/3desval.dat", true, new HexDecoder); pass = BlockTransformationTest(FixedRoundsCipherFactory(), valdata1, 1) && pass; @@ -1437,7 +1434,7 @@ bool TestModeIV(SymmetricCipher &e, SymmetricCipher &d) bool ValidateCipherModes() { - cout << "\nTesting DES modes...\n\n"; + std::cout << "\nTesting DES modes...\n\n"; const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; const byte plain[] = { // "Now is the time for all " without tailing 0 @@ -1459,13 +1456,13 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::NO_PADDING).Ref(), plain, sizeof(plain), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "ECB encryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "ECB encryption" << std::endl; ECB_Mode_ExternalCipher::Decryption modeD(desD); fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::NO_PADDING).Ref(), encrypted, sizeof(encrypted), plain, sizeof(plain)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "ECB decryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "ECB decryption" << std::endl; } { // from FIPS 81 @@ -1478,17 +1475,17 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::NO_PADDING).Ref(), plain, sizeof(plain), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC encryption with no padding" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC encryption with no padding" << std::endl; CBC_Mode_ExternalCipher::Decryption modeD(desD, iv); fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::NO_PADDING).Ref(), encrypted, sizeof(encrypted), plain, sizeof(plain)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC decryption with no padding" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC decryption with no padding" << std::endl; fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC mode IV generation" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC mode IV generation" << std::endl; } { // generated with Crypto++, matches FIPS 81 @@ -1503,13 +1500,13 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE).Ref(), plain, sizeof(plain), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC encryption with PKCS #7 padding" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC encryption with PKCS #7 padding" << std::endl; CBC_Mode_ExternalCipher::Decryption modeD(desD, iv); fail = !TestFilter(StreamTransformationFilter(modeD).Ref(), encrypted, sizeof(encrypted), plain, sizeof(plain)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC decryption with PKCS #7 padding" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC decryption with PKCS #7 padding" << std::endl; } { // generated with Crypto++ 5.2, matches FIPS 81 @@ -1524,13 +1521,13 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ONE_AND_ZEROS_PADDING).Ref(), plain, sizeof(plain), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC encryption with one-and-zeros padding" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC encryption with one-and-zeros padding" << std::endl; CBC_Mode_ExternalCipher::Decryption modeD(desD, iv); fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::ONE_AND_ZEROS_PADDING).Ref(), encrypted, sizeof(encrypted), plain, sizeof(plain)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC decryption with one-and-zeros padding" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC decryption with one-and-zeros padding" << std::endl; } { const byte plain_1[] = {'a', 0, 0, 0, 0, 0, 0, 0}; @@ -1542,13 +1539,13 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(), plain_1, 1, encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC encryption with zeros padding" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC encryption with zeros padding" << std::endl; CBC_Mode_ExternalCipher::Decryption modeD(desD, iv); fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(), encrypted, sizeof(encrypted), plain_1, sizeof(plain_1)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC decryption with zeros padding" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC decryption with zeros padding" << std::endl; } { // generated with Crypto++, matches FIPS 81 @@ -1562,17 +1559,17 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE).Ref(), plain, sizeof(plain), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC encryption with ciphertext stealing (CTS)" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC encryption with ciphertext stealing (CTS)" << std::endl; CBC_CTS_Mode_ExternalCipher::Decryption modeD(desD, iv); fail = !TestFilter(StreamTransformationFilter(modeD).Ref(), encrypted, sizeof(encrypted), plain, sizeof(plain)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC decryption with ciphertext stealing (CTS)" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC decryption with ciphertext stealing (CTS)" << std::endl; fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC CTS IV generation" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC CTS IV generation" << std::endl; } { // generated with Crypto++ @@ -1587,13 +1584,13 @@ bool ValidateCipherModes() plain, 3, encrypted, sizeof(encrypted)); fail = memcmp(stolenIV, decryptionIV, 8) != 0 || fail; pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC encryption with ciphertext and IV stealing" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC encryption with ciphertext and IV stealing" << std::endl; CBC_CTS_Mode_ExternalCipher::Decryption modeD(desD, stolenIV); fail = !TestFilter(StreamTransformationFilter(modeD).Ref(), encrypted, sizeof(encrypted), plain, 3); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC decryption with ciphertext and IV stealing" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC decryption with ciphertext and IV stealing" << std::endl; } { const byte encrypted[] = { // from FIPS 81 @@ -1605,17 +1602,17 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE).Ref(), plain, sizeof(plain), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CFB encryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CFB encryption" << std::endl; CFB_Mode_ExternalCipher::Decryption modeD(desE, iv); fail = !TestFilter(StreamTransformationFilter(modeD).Ref(), encrypted, sizeof(encrypted), plain, sizeof(plain)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CFB decryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CFB decryption" << std::endl; fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CFB mode IV generation" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CFB mode IV generation" << std::endl; } { const byte plain_2[] = { // "Now is the." without tailing 0 @@ -1627,17 +1624,17 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE).Ref(), plain_2, sizeof(plain_2), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) encryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) encryption" << std::endl; CFB_Mode_ExternalCipher::Decryption modeD(desE, iv, 1); fail = !TestFilter(StreamTransformationFilter(modeD).Ref(), encrypted, sizeof(encrypted), plain_2, sizeof(plain_2)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) decryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) decryption" << std::endl; fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) IV generation" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) IV generation" << std::endl; } { const byte encrypted[] = { // from Eric Young's libdes @@ -1649,17 +1646,17 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE).Ref(), plain, sizeof(plain), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "OFB encryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "OFB encryption" << std::endl; OFB_Mode_ExternalCipher::Decryption modeD(desE, iv); fail = !TestFilter(StreamTransformationFilter(modeD).Ref(), encrypted, sizeof(encrypted), plain, sizeof(plain)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "OFB decryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "OFB decryption" << std::endl; fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "OFB IV generation" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "OFB IV generation" << std::endl; } { const byte encrypted[] = { // generated with Crypto++ @@ -1671,17 +1668,17 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE).Ref(), plain, sizeof(plain), encrypted, sizeof(encrypted)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "Counter Mode encryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "Counter Mode encryption" << std::endl; CTR_Mode_ExternalCipher::Decryption modeD(desE, iv); fail = !TestFilter(StreamTransformationFilter(modeD).Ref(), encrypted, sizeof(encrypted), plain, sizeof(plain)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "Counter Mode decryption" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "Counter Mode decryption" << std::endl; fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "Counter Mode IV generation" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "Counter Mode IV generation" << std::endl; } { const byte plain_3[] = { // "7654321 Now is the time for " @@ -1698,41 +1695,41 @@ bool ValidateCipherModes() HashFilter cbcmacFilter(cbcmac); fail = !TestFilter(cbcmacFilter, plain_3, sizeof(plain_3), mac1, sizeof(mac1)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "CBC MAC" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "CBC MAC" << std::endl; DMAC dmac(key); HashFilter dmacFilter(dmac); fail = !TestFilter(dmacFilter, plain_3, sizeof(plain_3), mac2, sizeof(mac2)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "DMAC" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "DMAC" << std::endl; } { CTR_Mode::Encryption modeE(plain, 16, plain); CTR_Mode::Decryption modeD(plain, 16, plain); fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "AES CTR Mode" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "AES CTR Mode" << std::endl; } { OFB_Mode::Encryption modeE(plain, 16, plain); OFB_Mode::Decryption modeD(plain, 16, plain); fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "AES OFB Mode" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "AES OFB Mode" << std::endl; } { CFB_Mode::Encryption modeE(plain, 16, plain); CFB_Mode::Decryption modeD(plain, 16, plain); fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "AES CFB Mode" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "AES CFB Mode" << std::endl; } { CBC_Mode::Encryption modeE(plain, 16, plain); CBC_Mode::Decryption modeD(plain, 16, plain); fail = !TestModeIV(modeE, modeD); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed ") << "AES CBC Mode" << endl; + std::cout << (fail ? "FAILED " : "passed ") << "AES CBC Mode" << std::endl; } return pass; @@ -1740,7 +1737,7 @@ bool ValidateCipherModes() bool ValidateIDEA() { - cout << "\nIDEA validation suite running...\n\n"; + std::cout << "\nIDEA validation suite running...\n\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/ideaval.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata); @@ -1748,7 +1745,7 @@ bool ValidateIDEA() bool ValidateSAFER() { - cout << "\nSAFER validation suite running...\n\n"; + std::cout << "\nSAFER validation suite running...\n\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/saferval.dat", true, new HexDecoder); bool pass = true; @@ -1761,10 +1758,10 @@ bool ValidateSAFER() bool ValidateRC2() { - cout << "\nRC2 validation suite running...\n\n"; + std::cout << "\nRC2 validation suite running...\n\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc2val.dat", true, new HexDecoder); - HexEncoder output(new FileSink(cout)); + HexEncoder output(new FileSink(std::cout)); SecByteBlock plain(RC2Encryption::BLOCKSIZE), cipher(RC2Encryption::BLOCKSIZE), out(RC2Encryption::BLOCKSIZE), outplain(RC2Encryption::BLOCKSIZE); SecByteBlock key(128); bool pass=true, fail; @@ -1789,13 +1786,13 @@ bool ValidateRC2() pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); + std::cout << (fail ? "FAILED " : "passed "); output.Put(key, keyLen); - cout << " "; + std::cout << " "; output.Put(outplain, RC2Encryption::BLOCKSIZE); - cout << " "; + std::cout << " "; output.Put(out, RC2Encryption::BLOCKSIZE); - cout << endl; + std::cout << std::endl; } return pass; } @@ -1930,39 +1927,39 @@ bool ValidateARC4() bool pass=true, fail; unsigned int i; - cout << "\nARC4 validation suite running...\n\n"; + std::cout << "\nARC4 validation suite running...\n\n"; arc4.reset(new Weak::ARC4(Key0, sizeof(Key0))); arc4->ProcessString(Input0, sizeof(Input0)); fail = memcmp(Input0, Output0, sizeof(Input0)) != 0; - cout << (fail ? "FAILED" : "passed") << " Test 0" << endl; + std::cout << (fail ? "FAILED" : "passed") << " Test 0" << std::endl; pass = pass && !fail; arc4.reset(new Weak::ARC4(Key1, sizeof(Key1))); arc4->ProcessString(Key1, Input1, sizeof(Key1)); fail = memcmp(Output1, Key1, sizeof(Key1)) != 0; - cout << (fail ? "FAILED" : "passed") << " Test 1" << endl; + std::cout << (fail ? "FAILED" : "passed") << " Test 1" << std::endl; pass = pass && !fail; arc4.reset(new Weak::ARC4(Key2, sizeof(Key2))); for (i=0, fail=false; iProcessByte(Input2[i]) != Output2[i]) fail = true; - cout << (fail ? "FAILED" : "passed") << " Test 2" << endl; + std::cout << (fail ? "FAILED" : "passed") << " Test 2" << std::endl; pass = pass && !fail; arc4.reset(new Weak::ARC4(Key3, sizeof(Key3))); for (i=0, fail=false; iProcessByte(Input3[i]) != Output3[i]) fail = true; - cout << (fail ? "FAILED" : "passed") << " Test 3" << endl; + std::cout << (fail ? "FAILED" : "passed") << " Test 3" << std::endl; pass = pass && !fail; arc4.reset(new Weak::ARC4(Key4, sizeof(Key4))); for (i=0, fail=false; iProcessByte(Input4[i]) != Output4[i]) fail = true; - cout << (fail ? "FAILED" : "passed") << " Test 4" << endl; + std::cout << (fail ? "FAILED" : "passed") << " Test 4" << std::endl; pass = pass && !fail; return pass; @@ -1970,7 +1967,7 @@ bool ValidateARC4() bool ValidateRC5() { - cout << "\nRC5 validation suite running...\n\n"; + std::cout << "\nRC5 validation suite running...\n\n"; bool pass1 = true, pass2 = true; RC5Encryption enc; // 0 to 2040-bits (255-bytes) @@ -1990,7 +1987,7 @@ bool ValidateRC5() 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"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc5val.dat", true, new HexDecoder); return BlockTransformationTest(VariableRoundsCipherFactory(16, 12), valdata) && pass1 && pass2; @@ -1998,7 +1995,7 @@ bool ValidateRC5() bool ValidateRC6() { - cout << "\nRC6 validation suite running...\n\n"; + std::cout << "\nRC6 validation suite running...\n\n"; bool pass1 = true, pass2 = true, pass3 = true; RC6Encryption enc; @@ -2020,7 +2017,7 @@ bool ValidateRC6() 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"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rc6val.dat", true, new HexDecoder); pass3 = BlockTransformationTest(FixedRoundsCipherFactory(16), valdata, 2) && pass3; @@ -2031,7 +2028,7 @@ bool ValidateRC6() bool ValidateMARS() { - cout << "\nMARS validation suite running...\n\n"; + std::cout << "\nMARS validation suite running...\n\n"; bool pass1 = true, pass2 = true, pass3 = true; MARSEncryption enc; @@ -2053,7 +2050,7 @@ bool ValidateMARS() pass2 = dec.StaticGetValidKeyLength(128) == 56 && 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"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/marsval.dat", true, new HexDecoder); pass3 = BlockTransformationTest(FixedRoundsCipherFactory(16), valdata, 4) && pass3; @@ -2064,7 +2061,7 @@ bool ValidateMARS() bool ValidateRijndael() { - cout << "\nRijndael (AES) validation suite running...\n\n"; + std::cout << "\nRijndael (AES) validation suite running...\n\n"; bool pass1 = true, pass2 = true, pass3 = true; RijndaelEncryption enc; @@ -2086,7 +2083,7 @@ bool ValidateRijndael() 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"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/rijndael.dat", true, new HexDecoder); pass3 = BlockTransformationTest(FixedRoundsCipherFactory(16), valdata, 4) && pass3; @@ -2098,7 +2095,7 @@ bool ValidateRijndael() bool ValidateTwofish() { - cout << "\nTwofish validation suite running...\n\n"; + std::cout << "\nTwofish validation suite running...\n\n"; bool pass1 = true, pass2 = true, pass3 = true; TwofishEncryption enc; @@ -2116,7 +2113,7 @@ bool ValidateTwofish() pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2; pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2; pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/twofishv.dat", true, new HexDecoder); pass3 = BlockTransformationTest(FixedRoundsCipherFactory(16), valdata, 4) && pass3; @@ -2127,7 +2124,7 @@ bool ValidateTwofish() bool ValidateSerpent() { - cout << "\nSerpent validation suite running...\n\n"; + std::cout << "\nSerpent validation suite running...\n\n"; bool pass1 = true, pass2 = true, pass3 = true; SerpentEncryption enc; @@ -2145,7 +2142,7 @@ bool ValidateSerpent() pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2; pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2; pass2 = dec.StaticGetValidKeyLength(128) == 32 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/serpentv.dat", true, new HexDecoder); bool pass = true; @@ -2157,7 +2154,7 @@ bool ValidateSerpent() bool ValidateBlowfish() { - cout << "\nBlowfish validation suite running...\n\n"; + std::cout << "\nBlowfish validation suite running...\n\n"; bool pass1 = true, pass2 = true, pass3 = true, fail; BlowfishEncryption enc1; // 32 to 448-bits (4 to 56-bytes) @@ -2187,9 +2184,9 @@ bool ValidateBlowfish() pass2 = dec1.StaticGetValidKeyLength(60) == 56 && pass2; pass2 = dec1.StaticGetValidKeyLength(64) == 56 && pass2; pass2 = dec1.StaticGetValidKeyLength(128) == 56 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; - HexEncoder output(new FileSink(cout)); + HexEncoder output(new FileSink(std::cout)); const char *key[]={"abcdefghijklmnopqrstuvwxyz", "Who is John Galt?"}; byte *plain[]={(byte *)"BLOWFISH", (byte *)"\xfe\xdc\xba\x98\x76\x54\x32\x10"}; byte *cipher[]={(byte *)"\x32\x4e\xd0\xfe\xf4\x13\xa2\x03", (byte *)"\xcc\x91\x73\x2b\x80\x22\xf6\x84"}; @@ -2206,21 +2203,21 @@ bool ValidateBlowfish() fail = fail || memcmp(outplain, plain[i], 8); pass3 = pass3 && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << '\"' << key[i] << '\"'; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << '\"' << key[i] << '\"'; for (int j=0; j<(signed int)(30-strlen(key[i])); j++) - cout << ' '; + std::cout << ' '; output.Put(outplain, 8); - cout << " "; + std::cout << " "; output.Put(out, 8); - cout << endl; + std::cout << std::endl; } return pass1 && pass2 && pass3; } bool ValidateThreeWay() { - cout << "\n3-WAY validation suite running...\n\n"; + std::cout << "\n3-WAY validation suite running...\n\n"; bool pass1 = true, pass2 = true; ThreeWayEncryption enc; // 96-bit only @@ -2234,7 +2231,7 @@ bool ValidateThreeWay() pass2 = dec.StaticGetValidKeyLength(8) == 12 && pass2; pass2 = dec.StaticGetValidKeyLength(12) == 12 && pass2; pass2 = dec.StaticGetValidKeyLength(16) == 12 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/3wayval.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata) && pass1 && pass2; @@ -2242,7 +2239,7 @@ bool ValidateThreeWay() bool ValidateGOST() { - cout << "\nGOST validation suite running...\n\n"; + std::cout << "\nGOST validation suite running...\n\n"; bool pass1 = true, pass2 = true; GOSTEncryption enc; // 256-bit only @@ -2260,7 +2257,7 @@ bool ValidateGOST() pass2 = dec.StaticGetValidKeyLength(32) == 32 && pass2; pass2 = dec.StaticGetValidKeyLength(40) == 32 && pass2; pass2 = dec.StaticGetValidKeyLength(64) == 32 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/gostval.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata) && pass1 && pass2; @@ -2268,7 +2265,7 @@ bool ValidateGOST() bool ValidateSHARK() { - cout << "\nSHARK validation suite running...\n\n"; + std::cout << "\nSHARK validation suite running...\n\n"; bool pass1 = true, pass2 = true; SHARKEncryption enc; // 128-bit only @@ -2286,7 +2283,7 @@ bool ValidateSHARK() pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2; pass2 = dec.StaticGetValidKeyLength(17) == 16 && pass2; pass2 = dec.StaticGetValidKeyLength(32) == 16 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/sharkval.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata) && pass1 && pass2; @@ -2294,7 +2291,7 @@ bool ValidateSHARK() bool ValidateCAST() { - cout << "\nCAST-128 validation suite running...\n\n"; + std::cout << "\nCAST-128 validation suite running...\n\n"; bool pass1 = true, pass2 = true, pass3 = true; CAST128Encryption enc1; // 40 to 128-bits (5 to 16-bytes) @@ -2312,14 +2309,14 @@ bool ValidateCAST() pass2 = dec1.StaticGetValidKeyLength(15) == 15 && pass2; pass2 = dec1.StaticGetValidKeyLength(16) == 16 && pass2; pass2 = dec1.StaticGetValidKeyLength(17) == 16 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource val128(CRYPTOPP_DATA_DIR "TestData/cast128v.dat", true, new HexDecoder); pass3 = BlockTransformationTest(FixedRoundsCipherFactory(16), val128, 1) && pass3; pass3 = BlockTransformationTest(FixedRoundsCipherFactory(10), val128, 1) && pass3; pass3 = BlockTransformationTest(FixedRoundsCipherFactory(5), val128, 1) && pass3; - cout << "\nCAST-256 validation suite running...\n\n"; + std::cout << "\nCAST-256 validation suite running...\n\n"; bool pass4 = true, pass5 = true, pass6 = true; CAST256Encryption enc2; // 128, 160, 192, 224, or 256-bits (16 to 32-bytes, step 4) @@ -2345,7 +2342,7 @@ bool ValidateCAST() pass5 = dec2.StaticGetValidKeyLength(31) == 32 && pass5; pass5 = dec2.StaticGetValidKeyLength(32) == 32 && pass5; pass5 = dec2.StaticGetValidKeyLength(33) == 32 && pass5; - cout << (pass4 && pass5 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass4 && pass5 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource val256(CRYPTOPP_DATA_DIR "TestData/cast256v.dat", true, new HexDecoder); pass6 = BlockTransformationTest(FixedRoundsCipherFactory(16), val256, 1) && pass6; @@ -2357,7 +2354,7 @@ bool ValidateCAST() bool ValidateSquare() { - cout << "\nSquare validation suite running...\n\n"; + std::cout << "\nSquare validation suite running...\n\n"; bool pass1 = true, pass2 = true; SquareEncryption enc; // 128-bits only @@ -2371,7 +2368,7 @@ bool ValidateSquare() pass2 = dec.StaticGetValidKeyLength(15) == 16 && pass2; pass2 = dec.StaticGetValidKeyLength(16) == 16 && pass2; pass2 = dec.StaticGetValidKeyLength(17) == 16 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/squareva.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata) && pass1 && pass2; @@ -2379,7 +2376,7 @@ bool ValidateSquare() bool ValidateSKIPJACK() { - cout << "\nSKIPJACK validation suite running...\n\n"; + std::cout << "\nSKIPJACK validation suite running...\n\n"; bool pass1 = true, pass2 = true; SKIPJACKEncryption enc; // 80-bits only @@ -2393,7 +2390,7 @@ bool ValidateSKIPJACK() pass2 = dec.StaticGetValidKeyLength(9) == 10 && pass2; pass2 = dec.StaticGetValidKeyLength(10) == 10 && pass2; pass2 = dec.StaticGetValidKeyLength(16) == 10 && pass2; - cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/skipjack.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata) && pass1 && pass2; @@ -2406,7 +2403,7 @@ bool ValidateSEAL() static const byte iv[] = {0x01, 0x35, 0x77, 0xaf}; byte output[32]; - cout << "\nSEAL validation suite running...\n\n"; + std::cout << "\nSEAL validation suite running...\n\n"; SEAL<>::Encryption seal(key, sizeof(key), iv); unsigned int size = sizeof(input); @@ -2423,7 +2420,7 @@ bool ValidateSEAL() seal.ProcessString(output+2, size-2); pass = pass && memcmp(output+1, input+1, size-1) == 0; - cout << (pass ? "passed" : "FAILED") << endl; + std::cout << (pass ? "passed" : "FAILED") << std::endl; return pass; } @@ -2459,36 +2456,36 @@ bool ValidateBaseCode() "39445230745055316462580A324E6E6132397A6433742F6734654C6A354F586D352B6A7036757673" "3765377638504879382F5431397666342B6672372F50332B0A"; - cout << "\nBase64, base32 and hex coding validation suite running...\n\n"; + std::cout << "\nBase64, base32 and hex coding validation suite running...\n\n"; fail = !TestFilter(HexEncoder().Ref(), data, 255, (const byte *)hexEncoded, strlen(hexEncoded)); - cout << (fail ? "FAILED " : "passed "); - cout << "Hex Encoding\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "Hex Encoding\n"; pass = pass && !fail; fail = !TestFilter(HexDecoder().Ref(), (const byte *)hexEncoded, strlen(hexEncoded), data, 255); - cout << (fail ? "FAILED " : "passed "); - cout << "Hex Decoding\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "Hex Decoding\n"; pass = pass && !fail; fail = !TestFilter(Base32Encoder().Ref(), data, 255, (const byte *)base32Encoded, strlen(base32Encoded)); - cout << (fail ? "FAILED " : "passed "); - cout << "Base32 Encoding\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "Base32 Encoding\n"; pass = pass && !fail; fail = !TestFilter(Base32Decoder().Ref(), (const byte *)base32Encoded, strlen(base32Encoded), data, 255); - cout << (fail ? "FAILED " : "passed "); - cout << "Base32 Decoding\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "Base32 Decoding\n"; pass = pass && !fail; fail = !TestFilter(Base64Encoder(new HexEncoder).Ref(), data, 255, (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded)); - cout << (fail ? "FAILED " : "passed "); - cout << "Base64 Encoding\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "Base64 Encoding\n"; pass = pass && !fail; fail = !TestFilter(HexDecoder(new Base64Decoder).Ref(), (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded), data, 255); - cout << (fail ? "FAILED " : "passed "); - cout << "Base64 Decoding\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "Base64 Decoding\n"; pass = pass && !fail; return pass; @@ -2496,7 +2493,7 @@ bool ValidateBaseCode() bool ValidateSHACAL2() { - cout << "\nSHACAL-2 validation suite running...\n\n"; + std::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) @@ -2518,7 +2515,7 @@ bool ValidateSHACAL2() 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"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/shacal2v.dat", true, new HexDecoder); pass3 = BlockTransformationTest(FixedRoundsCipherFactory(16), valdata, 4) && pass3; @@ -2528,7 +2525,7 @@ bool ValidateSHACAL2() bool ValidateCamellia() { - cout << "\nCamellia validation suite running...\n\n"; + std::cout << "\nCamellia validation suite running...\n\n"; bool pass1 = true, pass2 = true, pass3 = true; CamelliaEncryption enc; @@ -2550,7 +2547,7 @@ bool ValidateCamellia() 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"; + std::cout << (pass1 && pass2 ? "passed:" : "FAILED:") << " Algorithm key lengths\n"; FileSource valdata(CRYPTOPP_DATA_DIR "TestData/camellia.dat", true, new HexDecoder); pass3 = BlockTransformationTest(FixedRoundsCipherFactory(16), valdata, 15) && pass3; @@ -2561,40 +2558,43 @@ bool ValidateCamellia() bool ValidateSalsa() { - cout << "\nSalsa validation suite running...\n"; + std::cout << "\nSalsa validation suite running...\n"; return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/salsa.txt"); } bool ValidateSosemanuk() { - cout << "\nSosemanuk validation suite running...\n"; + std::cout << "\nSosemanuk validation suite running...\n"; return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/sosemanuk.txt"); } bool ValidateVMAC() { - cout << "\nVMAC validation suite running...\n"; + std::cout << "\nVMAC validation suite running...\n"; return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/vmac.txt"); } bool ValidateCCM() { - cout << "\nAES/CCM validation suite running...\n"; + std::cout << "\nAES/CCM validation suite running...\n"; return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/ccm.txt"); } bool ValidateGCM() { - cout << "\nAES/GCM validation suite running...\n"; - cout << "\n2K tables:"; + std::cout << "\nAES/GCM validation suite running...\n"; + std::cout << "\n2K tables:"; bool pass = RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)2048)); - cout << "\n64K tables:"; + std::cout << "\n64K tables:"; return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)64*1024)) && pass; } bool ValidateCMAC() { - cout << "\nCMAC validation suite running...\n"; + std::cout << "\nCMAC validation suite running...\n"; return RunTestDataFile(CRYPTOPP_DATA_DIR "TestVectors/cmac.txt"); } + +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP diff --git a/validat2.cpp b/validat2.cpp index 68f2be8a..d37c2c4b 100644 --- a/validat2.cpp +++ b/validat2.cpp @@ -1,4 +1,5 @@ // validat2.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #include "pch.h" @@ -50,12 +51,8 @@ # pragma strict_gs_check (on) #endif -#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -USING_NAMESPACE(CryptoPP) -USING_NAMESPACE(std) +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) class FixedRNG : public RandomNumberGenerator { @@ -73,7 +70,7 @@ private: bool ValidateBBS() { - cout << "\nBlumBlumShub validation suite running...\n\n"; + std::cout << "\nBlumBlumShub validation suite running...\n\n"; Integer p("212004934506826557583707108431463840565872545889679278744389317666981496005411448865750399674653351"); Integer q("100677295735404212434355574418077394581488455772477016953458064183204108039226017738610663984508231"); @@ -90,37 +87,37 @@ bool ValidateBBS() 0xD5,0x0E,0x8E,0x29,0x83,0x75,0x6B,0x27,0x46,0xA1}; // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. - StreamState ss(cout); + StreamState ss(std::cout); byte buf[20]; bbs.GenerateBlock(buf, 20); fail = memcmp(output1, buf, 20) != 0; pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); + std::cout << (fail ? "FAILED " : "passed "); for (j=0;j<20;j++) - cout << setw(2) << setfill('0') << hex << (int)buf[j]; - cout << endl; + std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j]; + std::cout << std::endl; bbs.Seek(10); bbs.GenerateBlock(buf, 10); fail = memcmp(output1+10, buf, 10) != 0; pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); + std::cout << (fail ? "FAILED " : "passed "); for (j=0;j<10;j++) - cout << setw(2) << setfill('0') << hex << (int)buf[j]; - cout << endl; + std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j]; + std::cout << std::endl; bbs.Seek(1234567); bbs.GenerateBlock(buf, 20); fail = memcmp(output2, buf, 20) != 0; pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); + std::cout << (fail ? "FAILED " : "passed "); for (j=0;j<20;j++) - cout << setw(2) << setfill('0') << hex << (int)buf[j]; - cout << endl; + std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)buf[j]; + std::cout << std::endl; return pass; } @@ -132,8 +129,8 @@ bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false) fail = !pub.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2) || !priv.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "signature key validation\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "signature key validation\n"; const byte *message = (byte *)"test message"; const int messageLen = 12; @@ -143,15 +140,15 @@ bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false) fail = !pub.VerifyMessage(message, messageLen, signature, signatureLength); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "signature and verification\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "signature and verification\n"; ++signature[0]; fail = pub.VerifyMessage(message, messageLen, signature, signatureLength); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "checking invalid signature" << endl; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "checking invalid signature" << std::endl; if (priv.MaxRecoverableLength() > 0) { @@ -161,16 +158,16 @@ bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false) fail = !(result.isValidCoding && result.messageLength == messageLen && memcmp(recovered, message, messageLen) == 0); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "signature and verification with recovery" << endl; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "signature and verification with recovery" << std::endl; ++signature[0]; result = pub.RecoverMessage(recovered, NULL, 0, signature, signatureLength); fail = result.isValidCoding; pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "recovery with invalid signature" << endl; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "recovery with invalid signature" << std::endl; } return pass; @@ -183,8 +180,8 @@ bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough = fail = !pub.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2) || !priv.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "cryptosystem key validation\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "cryptosystem key validation\n"; const byte *message = (byte *)"test message"; const int messageLen = 12; @@ -196,8 +193,8 @@ bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough = fail = fail || memcmp(message, plaintext, messageLen); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "encryption and decryption\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "encryption and decryption\n"; return pass; } @@ -205,10 +202,10 @@ bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough = bool SimpleKeyAgreementValidate(SimpleKeyAgreementDomain &d) { if (d.GetCryptoParameters().Validate(GlobalRNG(), 3)) - cout << "passed simple key agreement domain parameters validation" << endl; + std::cout << "passed simple key agreement domain parameters validation" << std::endl; else { - cout << "FAILED simple key agreement domain parameters invalid" << endl; + std::cout << "FAILED simple key agreement domain parameters invalid" << std::endl; return false; } @@ -224,27 +221,27 @@ bool SimpleKeyAgreementValidate(SimpleKeyAgreementDomain &d) if (!(d.Agree(val1, priv1, pub2) && d.Agree(val2, priv2, pub1))) { - cout << "FAILED simple key agreement failed" << endl; + std::cout << "FAILED simple key agreement failed" << std::endl; return false; } if (memcmp(val1.begin(), val2.begin(), d.AgreedValueLength())) { - cout << "FAILED simple agreed values not equal" << endl; + std::cout << "FAILED simple agreed values not equal" << std::endl; return false; } - cout << "passed simple key agreement" << endl; + std::cout << "passed simple key agreement" << std::endl; return true; } bool AuthenticatedKeyAgreementValidate(AuthenticatedKeyAgreementDomain &d) { if (d.GetCryptoParameters().Validate(GlobalRNG(), 3)) - cout << "passed authenticated key agreement domain parameters validation" << endl; + std::cout << "passed authenticated key agreement domain parameters validation" << std::endl; else { - cout << "FAILED authenticated key agreement domain parameters invalid" << endl; + std::cout << "FAILED authenticated key agreement domain parameters invalid" << std::endl; return false; } @@ -264,23 +261,23 @@ bool AuthenticatedKeyAgreementValidate(AuthenticatedKeyAgreementDomain &d) if (!(d.Agree(val1, spriv1, epriv1, spub2, epub2) && d.Agree(val2, spriv2, epriv2, spub1, epub1))) { - cout << "FAILED authenticated key agreement failed" << endl; + std::cout << "FAILED authenticated key agreement failed" << std::endl; return false; } if (memcmp(val1.begin(), val2.begin(), d.AgreedValueLength())) { - cout << "FAILED authenticated agreed values not equal" << endl; + std::cout << "FAILED authenticated agreed values not equal" << std::endl; return false; } - cout << "passed authenticated key agreement" << endl; + std::cout << "passed authenticated key agreement" << std::endl; return true; } bool ValidateRSA() { - cout << "\nRSA validation suite running...\n\n"; + std::cout << "\nRSA validation suite running...\n\n"; byte out[100], outPlain[100]; bool pass = true, fail; @@ -301,21 +298,21 @@ bool ValidateRSA() fail = memcmp(signature, out, 64) != 0; pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "signature check against test vector\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "signature check against test vector\n"; fail = !rsaPub.VerifyMessage((byte *)plain, strlen(plain), out, signatureLength); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "verification check against test vector\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "verification check against test vector\n"; out[10]++; fail = rsaPub.VerifyMessage((byte *)plain, strlen(plain), out, signatureLength); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "invalid signature verification\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "invalid signature verification\n"; } { FileSource keys(CRYPTOPP_DATA_DIR "TestData/rsa1024.dat", true, new HexDecoder); @@ -358,8 +355,8 @@ bool ValidateRSA() fail = !result.isValidCoding || (result.messageLength!=8) || memcmp(out, encrypted, 50) || memcmp(plain, outPlain, 8); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "PKCS 2.0 encryption and decryption\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "PKCS 2.0 encryption and decryption\n"; } return pass; @@ -367,7 +364,7 @@ bool ValidateRSA() bool ValidateDH() { - cout << "\nDH validation suite running...\n\n"; + std::cout << "\nDH validation suite running...\n\n"; FileSource f(CRYPTOPP_DATA_DIR "TestData/dh1024.dat", true, new HexDecoder()); DH dh(f); @@ -376,7 +373,7 @@ bool ValidateDH() bool ValidateMQV() { - cout << "\nMQV validation suite running...\n\n"; + std::cout << "\nMQV validation suite running...\n\n"; FileSource f(CRYPTOPP_DATA_DIR "TestData/mqv1024.dat", true, new HexDecoder()); MQV mqv(f); @@ -444,7 +441,7 @@ bool ValidateHMQV() std::cout << "passed authenticated key agreement" << std::endl; // Now test HMQV with NIST P-384 curve and SHA384 hash - std::cout << endl; + std::cout << std::endl; std::cout << "HMQV with NIST P-384 and SHA-384:" << std::endl; ECHMQV384 hmqvB384(false); @@ -561,7 +558,7 @@ bool ValidateFHMQV() std::cout << "passed authenticated key agreement" << std::endl; // Now test FHMQV with NIST P-384 curve and SHA384 hash - std::cout << endl; + std::cout << std::endl; std::cout << "FHMQV with NIST P-384 and SHA-384:" << std::endl; ECHMQV384 fhmqvB384(false); @@ -619,7 +616,7 @@ bool ValidateFHMQV() bool ValidateLUC_DH() { - cout << "\nLUC-DH validation suite running...\n\n"; + std::cout << "\nLUC-DH validation suite running...\n\n"; FileSource f(CRYPTOPP_DATA_DIR "TestData/lucd512.dat", true, new HexDecoder()); LUC_DH dh(f); @@ -628,7 +625,7 @@ bool ValidateLUC_DH() bool ValidateXTR_DH() { - cout << "\nXTR-DH validation suite running...\n\n"; + std::cout << "\nXTR-DH validation suite running...\n\n"; FileSource f(CRYPTOPP_DATA_DIR "TestData/xtrdh171.dat", true, new HexDecoder()); XTR_DH dh(f); @@ -637,7 +634,7 @@ bool ValidateXTR_DH() bool ValidateElGamal() { - cout << "\nElGamal validation suite running...\n\n"; + std::cout << "\nElGamal validation suite running...\n\n"; bool pass = true; { FileSource fc(CRYPTOPP_DATA_DIR "TestData/elgc1024.dat", true, new HexDecoder); @@ -655,7 +652,7 @@ bool ValidateElGamal() bool ValidateDLIES() { - cout << "\nDLIES validation suite running...\n\n"; + std::cout << "\nDLIES validation suite running...\n\n"; bool pass = true; { FileSource fc(CRYPTOPP_DATA_DIR "TestData/dlie1024.dat", true, new HexDecoder); @@ -664,7 +661,7 @@ bool ValidateDLIES() pass = CryptoSystemValidate(privC, pubC) && pass; } { - cout << "Generating new encryption key..." << endl; + std::cout << "Generating new encryption key..." << std::endl; DLIES<>::GroupParameters gp; gp.GenerateRandomWithKeySize(GlobalRNG(), 128); DLIES<>::Decryptor decryptor; @@ -678,7 +675,7 @@ bool ValidateDLIES() bool ValidateNR() { - cout << "\nNR validation suite running...\n\n"; + std::cout << "\nNR validation suite running...\n\n"; bool pass = true; { FileSource f(CRYPTOPP_DATA_DIR "TestData/nr2048.dat", true, new HexDecoder); @@ -689,7 +686,7 @@ bool ValidateNR() pass = SignatureValidate(privS, pubS) && pass; } { - cout << "Generating new signature key..." << endl; + std::cout << "Generating new signature key..." << std::endl; NR::Signer privS(GlobalRNG(), 256); NR::Verifier pubS(privS); @@ -700,7 +697,7 @@ bool ValidateNR() bool ValidateDSA(bool thorough) { - cout << "\nDSA validation suite running...\n\n"; + std::cout << "\nDSA validation suite running...\n\n"; bool pass = true; FileSource fs1(CRYPTOPP_DATA_DIR "TestData/dsa1024.dat", true, new HexDecoder()); @@ -717,7 +714,7 @@ bool ValidateDSA(bool thorough) bool ValidateLUC() { - cout << "\nLUC validation suite running...\n\n"; + std::cout << "\nLUC validation suite running...\n\n"; bool pass=true; { @@ -736,14 +733,14 @@ bool ValidateLUC() bool ValidateLUC_DL() { - cout << "\nLUC-HMP validation suite running...\n\n"; + std::cout << "\nLUC-HMP validation suite running...\n\n"; FileSource f(CRYPTOPP_DATA_DIR "TestData/lucs512.dat", true, new HexDecoder); LUC_HMP::Signer privS(f); LUC_HMP::Verifier pubS(privS); bool pass = SignatureValidate(privS, pubS); - cout << "\nLUC-IES validation suite running...\n\n"; + std::cout << "\nLUC-IES validation suite running...\n\n"; FileSource fc(CRYPTOPP_DATA_DIR "TestData/lucc512.dat", true, new HexDecoder); LUC_IES<>::Decryptor privC(fc); @@ -755,7 +752,7 @@ bool ValidateLUC_DL() bool ValidateRabin() { - cout << "\nRabin validation suite running...\n\n"; + std::cout << "\nRabin validation suite running...\n\n"; bool pass=true; { @@ -774,7 +771,7 @@ bool ValidateRabin() bool ValidateRW() { - cout << "\nRW validation suite running...\n\n"; + std::cout << "\nRW validation suite running...\n\n"; FileSource f(CRYPTOPP_DATA_DIR "TestData/rw1024.dat", true, new HexDecoder); RWSS::Signer priv(f); @@ -786,7 +783,7 @@ bool ValidateRW() /* bool ValidateBlumGoldwasser() { - cout << "\nBlumGoldwasser validation suite running...\n\n"; + std::cout << "\nBlumGoldwasser validation suite running...\n\n"; FileSource f(CRYPTOPP_DATA_DIR "TestData/blum512.dat", true, new HexDecoder); BlumGoldwasserPrivateKey priv(f); @@ -802,7 +799,7 @@ bool TestPolynomialMod2() { bool pass1 = true, pass2 = true, pass3 = true; - cout << "\nTesting PolynomialMod2 bit operations...\n\n"; + std::cout << "\nTesting PolynomialMod2 bit operations...\n\n"; static const unsigned int start = 0; static const unsigned int stop = 4 * WORD_BITS + 1; @@ -890,21 +887,21 @@ bool TestPolynomialMod2() if (str1 != str2) { - cout << " Oops..." << "\n"; - cout << " random: " << std::hex << n << std::dec << "\n"; - cout << " str1: " << str1 << "\n"; - cout << " str2: " << str2 << "\n"; + std::cout << " Oops..." << "\n"; + std::cout << " random: " << std::hex << n << std::dec << "\n"; + std::cout << " str1: " << str1 << "\n"; + std::cout << " str2: " << str2 << "\n"; } pass3 &= (str1 == str2); } - cout << (!pass1 ? "FAILED" : "passed") << ": " << "1 shifted over range [" << dec << start << "," << stop << "]" << "\n"; - cout << (!pass2 ? "FAILED" : "passed") << ": " << "0x" << hex << word(SIZE_MAX) << dec << " shifted over range [" << start << "," << stop << "]" << "\n"; - cout << (!pass3 ? "FAILED" : "passed") << ": " << "random values shifted over range [" << dec << start << "," << stop << "]" << "\n"; + std::cout << (!pass1 ? "FAILED" : "passed") << ": " << "1 shifted over range [" << std::dec << start << "," << stop << "]" << "\n"; + std::cout << (!pass2 ? "FAILED" : "passed") << ": " << "0x" << std::hex << word(SIZE_MAX) << std::dec << " shifted over range [" << start << "," << stop << "]" << "\n"; + std::cout << (!pass3 ? "FAILED" : "passed") << ": " << "random values shifted over range [" << std::dec << start << "," << stop << "]" << "\n"; if (!(pass1 && pass2 && pass3)) - cout.flush(); + std::cout.flush(); return pass1 && pass2 && pass3; } @@ -912,7 +909,7 @@ bool TestPolynomialMod2() bool ValidateECP() { - cout << "\nECP validation suite running...\n\n"; + std::cout << "\nECP validation suite running...\n\n"; ECIES::Decryptor cpriv(GlobalRNG(), ASN1::secp192r1()); ECIES::Encryptor cpub(cpriv); @@ -937,7 +934,7 @@ bool ValidateECP() pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; - cout << "Turning on point compression..." << endl; + std::cout << "Turning on point compression..." << std::endl; cpriv.AccessKey().AccessGroupParameters().SetPointCompression(true); cpub.AccessKey().AccessGroupParameters().SetPointCompression(true); ecdhc.AccessGroupParameters().SetPointCompression(true); @@ -946,13 +943,13 @@ bool ValidateECP() pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; - cout << "Testing SEC 2, NIST, and Brainpool recommended curves..." << endl; + std::cout << "Testing SEC 2, NIST, and Brainpool recommended curves..." << std::endl; OID oid; while (!(oid = DL_GroupParameters_EC::GetNextRecommendedParametersOID(oid)).m_values.empty()) { DL_GroupParameters_EC params(oid); bool fail = !params.Validate(GlobalRNG(), 2); - cout << (fail ? "FAILED" : "passed") << " " << dec << params.GetCurve().GetField().MaxElementBitLength() << " bits" << endl; + std::cout << (fail ? "FAILED" : "passed") << " " << std::dec << params.GetCurve().GetField().MaxElementBitLength() << " bits" << std::endl; pass = pass && !fail; } @@ -961,7 +958,7 @@ bool ValidateECP() bool ValidateEC2N() { - cout << "\nEC2N validation suite running...\n\n"; + std::cout << "\nEC2N validation suite running...\n\n"; ECIES::Decryptor cpriv(GlobalRNG(), ASN1::sect193r1()); ECIES::Encryptor cpub(cpriv); @@ -984,7 +981,7 @@ bool ValidateEC2N() pass = SimpleKeyAgreementValidate(ecdhc) && pass; pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; - cout << "Turning on point compression..." << endl; + std::cout << "Turning on point compression..." << std::endl; cpriv.AccessKey().AccessGroupParameters().SetPointCompression(true); cpub.AccessKey().AccessGroupParameters().SetPointCompression(true); ecdhc.AccessGroupParameters().SetPointCompression(true); @@ -994,13 +991,13 @@ bool ValidateEC2N() pass = AuthenticatedKeyAgreementValidate(ecmqvc) && pass; #if 0 // TODO: turn this back on when I make EC2N faster for pentanomial basis - cout << "Testing SEC 2 recommended curves..." << endl; + std::cout << "Testing SEC 2 recommended curves..." << std::endl; OID oid; while (!(oid = DL_GroupParameters_EC::GetNextRecommendedParametersOID(oid)).m_values.empty()) { DL_GroupParameters_EC params(oid); bool fail = !params.Validate(GlobalRNG(), 2); - cout << (fail ? "FAILED" : "passed") << " " << params.GetCurve().GetField().MaxElementBitLength() << " bits" << endl; + std::cout << (fail ? "FAILED" : "passed") << " " << params.GetCurve().GetField().MaxElementBitLength() << " bits" << std::endl; pass = pass && !fail; } #endif @@ -1010,7 +1007,7 @@ bool ValidateEC2N() bool ValidateECDSA() { - cout << "\nECDSA validation suite running...\n\n"; + std::cout << "\nECDSA validation suite running...\n\n"; // from Sample Test Vectors for P1363 GF2NT gf2n(191, 9, 0); @@ -1041,14 +1038,14 @@ bool ValidateECDSA() fail = (rOut != r) || (sOut != s); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "signature check against test vector\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "signature check against test vector\n"; fail = !pub.VerifyMessage((byte *)"abc", 3, sig, sizeof(sig)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "verification check against test vector\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "verification check against test vector\n"; fail = pub.VerifyMessage((byte *)"xyz", 3, sig, sizeof(sig)); pass = pass && !fail; @@ -1061,7 +1058,7 @@ bool ValidateECDSA() // from http://www.teletrust.de/fileadmin/files/oid/ecgdsa_final.pdf bool ValidateECGDSA() { - cout << "\nECGDSA validation suite running...\n\n"; + std::cout << "\nECGDSA validation suite running...\n\n"; bool fail, pass=true; @@ -1095,8 +1092,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP192r1 using RIPEMD-160\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP192r1 using RIPEMD-160\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1132,8 +1129,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP256r1 using RIPEMD-160\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP256r1 using RIPEMD-160\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1169,8 +1166,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP320r1 using RIPEMD-160\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP320r1 using RIPEMD-160\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1206,8 +1203,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP192r1 using SHA-1\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP192r1 using SHA-1\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1243,8 +1240,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP256r1 using SHA-224\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP256r1 using SHA-224\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1280,8 +1277,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP320r1 using SHA-224\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP320r1 using SHA-224\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1317,8 +1314,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP320r1 using SHA-256\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP320r1 using SHA-256\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1354,8 +1351,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP512r1 using SHA-384\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP512r1 using SHA-384\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1391,8 +1388,8 @@ bool ValidateECGDSA() fail = !verifier.VerifyMessage(msg, len, signature, sizeof(signature)); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "brainpoolP512r1 using SHA-512\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "brainpoolP512r1 using SHA-512\n"; fail = !SignatureValidate(signer, verifier); pass = pass && !fail; @@ -1403,7 +1400,7 @@ bool ValidateECGDSA() bool ValidateESIGN() { - cout << "\nESIGN validation suite running...\n\n"; + std::cout << "\nESIGN validation suite running...\n\n"; bool pass = true, fail; @@ -1426,10 +1423,10 @@ bool ValidateESIGN() fail = !verifier.VerifyMessage((byte *)plain, strlen(plain), signature, verifier.SignatureLength()); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); - cout << "verification check against test vector\n"; + std::cout << (fail ? "FAILED " : "passed "); + std::cout << "verification check against test vector\n"; - cout << "Generating signature key from seed..." << endl; + std::cout << "Generating signature key from seed..." << std::endl; signer.AccessKey().GenerateRandom(GlobalRNG(), MakeParameters("Seed", ConstByteArrayParameter((const byte *)"test", 4))("KeySize", 3*512)); verifier = signer; @@ -1438,3 +1435,6 @@ bool ValidateESIGN() return pass; } + +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP diff --git a/validat3.cpp b/validat3.cpp index f7f32786..6df1b91d 100644 --- a/validat3.cpp +++ b/validat3.cpp @@ -1,4 +1,5 @@ // validat3.cpp - originally written and placed in the public domain by Wei Dai +// CryptoPP::Test namespace added by JW in February 2017 #include "pch.h" @@ -43,12 +44,8 @@ # pragma strict_gs_check (on) #endif -#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -USING_NAMESPACE(CryptoPP) -USING_NAMESPACE(std) +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) struct HashTestTuple { @@ -69,7 +66,7 @@ bool HashModuleTest(HashTransformation &md, const HashTestTuple *testSet, unsign SecByteBlock digest(md.DigestSize()); // Coverity finding, also see http://stackoverflow.com/a/34509163/608639. - StreamState ss(cout); + StreamState ss(std::cout); for (unsigned int i=0; i pbkdf; - cout << "\nPKCS #12 PBKDF validation suite running...\n\n"; + std::cout << "\nPKCS #12 PBKDF validation suite running...\n\n"; pass = TestPBKDF(pbkdf, testSet, sizeof(testSet)/sizeof(testSet[0])) && pass; } @@ -635,7 +632,7 @@ bool ValidatePBKDF() PKCS5_PBKDF2_HMAC pbkdf; - cout << "\nPKCS #5 PBKDF2 validation suite running...\n\n"; + std::cout << "\nPKCS #5 PBKDF2 validation suite running...\n\n"; pass = TestPBKDF(pbkdf, testSet, sizeof(testSet)/sizeof(testSet[0])) && pass; } @@ -781,12 +778,12 @@ struct Poly1305_TestTuples bool ValidatePoly1305() { - cout << "\nPoly1305 validation suite running...\n\n"; + std::cout << "\nPoly1305 validation suite running...\n\n"; bool fail, pass = true; { fail = (Poly1305::StaticAlgorithmName() != "Poly1305(AES)"); - cout << (fail ? "FAILED " : "passed ") << "algorithm name\n"; + std::cout << (fail ? "FAILED " : "passed ") << "algorithm name\n"; pass = pass && !fail; } @@ -849,7 +846,7 @@ bool ValidatePoly1305() fail = !!memcmp(digest, tests[i].digest, tests[i].dlen) != 0; if (fail) { - cout << "FAILED " << "Poly1305 test set " << count << endl; + std::cout << "FAILED " << "Poly1305 test set " << count << std::endl; } count++; @@ -866,7 +863,7 @@ bool ValidatePoly1305() fail = !!memcmp(digest, tests[i].digest, tests[i].dlen) != 0; if (fail) { - cout << "FAILED " << "Poly1305 test set " << count << endl; + std::cout << "FAILED " << "Poly1305 test set " << count << std::endl; } count++; @@ -885,46 +882,46 @@ bool ValidatePoly1305() fail = !!memcmp(digest, tests[next].digest, tests[next].dlen) == 0; if (fail) { - cout << "FAILED " << "Poly1305 test set " << count << endl; + std::cout << "FAILED " << "Poly1305 test set " << count << std::endl; } count++; pass = pass && !fail; } - cout << (!pass ? "FAILED " : "passed ") << count << " message authentication codes" << endl; + std::cout << (!pass ? "FAILED " : "passed ") << count << " message authentication codes" << std::endl; return pass; } bool ValidateSipHash() { - cout << "\nSipHash validation suite running...\n\n"; + std::cout << "\nSipHash validation suite running...\n\n"; bool fail, pass = true, pass1=true, pass2=true, pass3=true, pass4=true; { fail = (SipHash<2,4>::StaticAlgorithmName() != "SipHash-2-4"); - cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 algorithm name\n"; + std::cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 algorithm name\n"; pass = pass && !fail; fail = (SipHash<2,4, false>::DIGESTSIZE != 8); - cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 64-bit digest size\n"; + std::cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 64-bit digest size\n"; pass = pass && !fail; fail = (SipHash<2,4, true>::DIGESTSIZE != 16); - cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 128-bit digest size\n"; + std::cout << (fail ? "FAILED " : "passed ") << "SipHash-2-4 128-bit digest size\n"; pass = pass && !fail; fail = (SipHash<4,8>::StaticAlgorithmName() != "SipHash-4-8"); - cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 algorithm name\n"; + std::cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 algorithm name\n"; pass = pass && !fail; fail = (SipHash<4,8, false>::DIGESTSIZE != 8); - cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 64-bit digest size\n"; + std::cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 64-bit digest size\n"; pass = pass && !fail; fail = (SipHash<4,8, true>::DIGESTSIZE != 16); - cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 128-bit digest size\n"; + std::cout << (fail ? "FAILED " : "passed ") << "SipHash-4-8 128-bit digest size\n"; pass = pass && !fail; } @@ -959,7 +956,7 @@ bool ValidateSipHash() fail = !!memcmp("\xB0\xE4\xA9\x0B\xDF\x82\x00\x9E", digest, COUNTOF(digest)); pass1 = !fail && pass1; - cout << (pass1 ? "passed " : "FAILED ") << "SipHash-2-4 64-bit MAC\n"; + std::cout << (pass1 ? "passed " : "FAILED ") << "SipHash-2-4 64-bit MAC\n"; pass = pass1 && pass; } @@ -994,7 +991,7 @@ bool ValidateSipHash() fail = !!memcmp("\x26\x44\x99\x06\x0A\xD9\xBA\xAB\xC4\x7F\x8B\x02\xBB\x6D\x71\xED", digest, COUNTOF(digest)); pass3 = !fail && pass3; - cout << (pass3 ? "passed " : "FAILED ") << "SipHash-2-4 128-bit MAC\n"; + std::cout << (pass3 ? "passed " : "FAILED ") << "SipHash-2-4 128-bit MAC\n"; pass = pass3 && pass; } @@ -1029,7 +1026,7 @@ bool ValidateSipHash() fail = !!memcmp("\x36\x31\x9A\xF3\x5E\xE1\x12\x53", digest, COUNTOF(digest)); pass2 = !fail && pass2; - cout << (pass2 ? "passed " : "FAILED ") << "SipHash-4-8 64-bit MAC\n"; + std::cout << (pass2 ? "passed " : "FAILED ") << "SipHash-4-8 64-bit MAC\n"; pass = pass2 && pass; } @@ -1064,7 +1061,7 @@ bool ValidateSipHash() fail = !!memcmp("\x9E\x73\x14\xB7\x54\x5C\xEC\xA3\x8B\x9A\x55\x49\xE4\xFB\x0B\xE8", digest, COUNTOF(digest)); pass4 = !fail && pass4; - cout << (pass4 ? "passed " : "FAILED ") << "SipHash-4-8 128-bit MAC\n"; + std::cout << (pass4 ? "passed " : "FAILED ") << "SipHash-4-8 128-bit MAC\n"; pass = pass4 && pass; } @@ -1079,12 +1076,12 @@ struct BLAKE2_TestTuples bool ValidateBLAKE2s() { - cout << "\nBLAKE2s validation suite running...\n\n"; + std::cout << "\nBLAKE2s validation suite running...\n\n"; bool fail, pass = true; { fail = strcmp(BLAKE2s::StaticAlgorithmName(), "BLAKE2s") != 0; - cout << (fail ? "FAILED " : "passed ") << "algorithm name\n"; + std::cout << (fail ? "FAILED " : "passed ") << "algorithm name\n"; pass = pass && !fail; } @@ -1461,25 +1458,25 @@ bool ValidateBLAKE2s() fail = !!memcmp(digest, tests[i].digest, sizeof(digest)) != 0; if (fail) { - cout << "FAILED " << "BLAKE2s test set " << i << endl; + std::cout << "FAILED " << "BLAKE2s test set " << i << std::endl; } pass = pass && !fail; } - cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << endl; + std::cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << std::endl; return pass; } bool ValidateBLAKE2b() { - cout << "\nBLAKE2b validation suite running...\n\n"; + std::cout << "\nBLAKE2b validation suite running...\n\n"; bool fail, pass = true; { fail = strcmp(BLAKE2b::StaticAlgorithmName(), "BLAKE2b") != 0; - cout << (fail ? "FAILED " : "passed ") << "algorithm name\n"; + std::cout << (fail ? "FAILED " : "passed ") << "algorithm name\n"; pass = pass && !fail; } @@ -1856,13 +1853,16 @@ bool ValidateBLAKE2b() fail = !!memcmp(digest, tests[i].digest, sizeof(digest)) != 0; if (fail) { - cout << "FAILED " << "BLAKE2b test set " << i << endl; + std::cout << "FAILED " << "BLAKE2b test set " << i << std::endl; } pass = pass && !fail; } - cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << endl; + std::cout << (!pass ? "FAILED " : "passed ") << COUNTOF(tests) << " hashes and keyed hashes" << std::endl; return pass; } + +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP diff --git a/validate.h b/validate.h index ffdb2a90..16816299 100644 --- a/validate.h +++ b/validate.h @@ -5,6 +5,9 @@ #include #include +NAMESPACE_BEGIN(CryptoPP) +NAMESPACE_BEGIN(Test) + bool ValidateAll(bool thorough); bool TestSettings(); bool TestOS_RNG(); @@ -146,4 +149,7 @@ CryptoPP::RandomNumberGenerator & GlobalRNG(); bool RunTestDataFile(const char *filename, const CryptoPP::NameValuePairs &overrideParameters=CryptoPP::g_nullNameValuePairs, bool thorough=true); +NAMESPACE_END // Test +NAMESPACE_END // CryptoPP + #endif