diff --git a/validat1.cpp b/validat1.cpp index 15d5d442..7bf3a353 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -46,7 +46,9 @@ #include "validate.h" USING_NAMESPACE(CryptoPP) -USING_NAMESPACE(std) + +// using CryptoPP::auto_ptr; +using std::auto_ptr; bool ValidateAll(bool thorough) { @@ -122,9 +124,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; } @@ -133,7 +135,7 @@ bool TestSettings() { bool pass = true; - cout << "\nTesting Settings...\n\n"; + std::cout << "\nTesting Settings...\n\n"; word32 w; memcpy_s(&w, sizeof(w), "\x01\x02\x03\x04", 4); @@ -141,87 +143,87 @@ 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; } #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS byte testvals[10] = {1,2,2,3,3,3,3,2,2,1}; if (*(word32 *)(testvals+3) == 0x03030303 && *(word64 *)(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) @@ -229,17 +231,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(); @@ -251,19 +253,19 @@ 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 << ", hasAESNI == " << HasAESNI() << ", hasCLMUL == " << HasCLMUL() << ", isP4 == " << isP4 << ", cacheLineSize == " << cacheLineSize; - cout << ", AESNI_INTRINSICS == " << CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE << endl; + std::cout << "hasMMX == " << hasMMX << ", hasISSE == " << hasISSE << ", hasSSE2 == " << hasSSE2 << ", hasSSSE3 == " << hasSSSE3 << ", hasAESNI == " << HasAESNI() << ", hasCLMUL == " << HasCLMUL() << ", isP4 == " << isP4 << ", cacheLineSize == " << cacheLineSize; + std::cout << ", AESNI_INTRINSICS == " << CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE << 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; @@ -281,7 +283,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; RandomNumberSource test(*rng, UINT_MAX, false, new Deflator(new Redirector(meter))); @@ -299,12 +301,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) @@ -329,12 +331,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 @@ -342,15 +344,15 @@ bool TestOS_RNG() if (meter.GetTotalBytes() < total) { - cout << "FAILED:"; + std::cout << "FAILED:"; pass = false; } else - cout << "passed:"; - cout << " " << total << " generated bytes compressed to " << (size_t)meter.GetTotalBytes() << " bytes by DEFLATE" << endl; + std::cout << "passed:"; + std::cout << " " << total << " generated bytes compressed to " << (size_t)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 @@ -360,37 +362,34 @@ 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; 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 " << (size_t)meter.GetTotalBytes() << " bytes by DEFLATE" << endl; + std::cout << "passed:"; + std::cout << " 100000 generated bytes compressed to " << (size_t)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; } -// VC50 workaround -typedef auto_ptr apbt; - class CipherFactory { public: virtual unsigned int BlockSize() const =0; virtual unsigned int KeyLength() const =0; - virtual apbt NewEncryption(const byte *key) const =0; - virtual apbt NewDecryption(const byte *key) const =0; + virtual auto_ptr NewEncryption(const byte *key) const =0; + virtual auto_ptr NewDecryption(const byte *key) const =0; }; template class FixedRoundsCipherFactory : public CipherFactory @@ -400,10 +399,10 @@ public: unsigned int BlockSize() const {return E::BLOCKSIZE;} unsigned int KeyLength() const {return m_keylen;} - apbt NewEncryption(const byte *key) const - {return apbt(new E(key, m_keylen));} - apbt NewDecryption(const byte *key) const - {return apbt(new D(key, m_keylen));} + auto_ptr NewEncryption(const byte *key) const + {return auto_ptr(new E(key, m_keylen));} + auto_ptr NewDecryption(const byte *key) const + {return auto_ptr(new D(key, m_keylen));} unsigned int m_keylen; }; @@ -416,17 +415,17 @@ public: unsigned int BlockSize() const {return E::BLOCKSIZE;} unsigned int KeyLength() const {return m_keylen;} - apbt NewEncryption(const byte *key) const - {return apbt(new E(key, m_keylen, m_rounds));} - apbt NewDecryption(const byte *key) const - {return apbt(new D(key, m_keylen, m_rounds));} + auto_ptr NewEncryption(const byte *key) const + {return auto_ptr(new E(key, m_keylen, m_rounds));} + auto_ptr NewDecryption(const byte *key) const + {return auto_ptr(new D(key, m_keylen, m_rounds));} unsigned int m_keylen, m_rounds; }; 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; @@ -437,23 +436,23 @@ bool BlockTransformationTest(const CipherFactory &cg, BufferedTransformation &va valdata.Get(plain, cg.BlockSize()); valdata.Get(cipher, cg.BlockSize()); - apbt transE = cg.NewEncryption(key); + auto_ptr transE = cg.NewEncryption(key); transE->ProcessBlock(plain, out); fail = !VerifyBufsEqual(out, cipher, cg.BlockSize()); - apbt transD = cg.NewDecryption(key); + auto_ptr transD = cg.NewDecryption(key); transD->ProcessBlock(out, outplain); fail=fail || !VerifyBufsEqual(outplain, plain, cg.BlockSize()); 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; } @@ -515,12 +514,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("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("TestData/3desval.dat", true, new HexDecoder); pass = BlockTransformationTest(FixedRoundsCipherFactory(), valdata1, 1) && pass; @@ -559,7 +558,7 @@ bool TestModeIV(SymmetricCipher &e, SymmetricCipher &d) bool ValidateCipherModes() { - cout << "\nTesting DES modes...\n\n"; + std::cout << "\nTesting DES modes...\n\n"; static const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; static const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; static const byte plain[] = { // "Now is the time for all " without tailing 0 @@ -581,13 +580,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 @@ -600,17 +599,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 @@ -625,13 +624,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 @@ -646,13 +645,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; } { static const byte plain[] = {'a', 0, 0, 0, 0, 0, 0, 0}; @@ -664,13 +663,13 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(), plain, 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, sizeof(plain)); 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 @@ -684,17 +683,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++ @@ -709,13 +708,13 @@ bool ValidateCipherModes() plain, 3, encrypted, sizeof(encrypted)); fail = !VerifyBufsEqual(stolenIV, decryptionIV, 8) || 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; } { static const byte encrypted[] = { // from FIPS 81 @@ -727,17 +726,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; } { static const byte plain[] = { // "Now is the." without tailing 0 @@ -749,17 +748,17 @@ bool ValidateCipherModes() fail = !TestFilter(StreamTransformationFilter(modeE).Ref(), plain, sizeof(plain), 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, sizeof(plain)); 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; } { static const byte encrypted[] = { // from Eric Young's libdes @@ -771,17 +770,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; } { static const byte encrypted[] = { // generated with Crypto++ @@ -793,17 +792,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; } { static const byte plain[] = { // "7654321 Now is the time for " @@ -820,41 +819,41 @@ bool ValidateCipherModes() HashFilter cbcmacFilter(cbcmac); fail = !TestFilter(cbcmacFilter, plain, sizeof(plain), 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, sizeof(plain), 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; @@ -862,7 +861,7 @@ bool ValidateCipherModes() bool ValidateIDEA() { - cout << "\nIDEA validation suite running...\n\n"; + std::cout << "\nIDEA validation suite running...\n\n"; FileSource valdata("TestData/ideaval.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata); @@ -870,7 +869,7 @@ bool ValidateIDEA() bool ValidateSAFER() { - cout << "\nSAFER validation suite running...\n\n"; + std::cout << "\nSAFER validation suite running...\n\n"; FileSource valdata("TestData/saferval.dat", true, new HexDecoder); bool pass = true; @@ -883,10 +882,10 @@ bool ValidateSAFER() bool ValidateRC2() { - cout << "\nRC2 validation suite running...\n\n"; + std::cout << "\nRC2 validation suite running...\n\n"; FileSource valdata("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; @@ -901,23 +900,23 @@ bool ValidateRC2() valdata.Get(plain, RC2Encryption::BLOCKSIZE); valdata.Get(cipher, RC2Encryption::BLOCKSIZE); - apbt transE(new RC2Encryption(key, keyLen, effectiveLen)); + auto_ptr transE(new RC2Encryption(key, keyLen, effectiveLen)); transE->ProcessBlock(plain, out); fail = !VerifyBufsEqual(out, cipher, RC2Encryption::BLOCKSIZE); - apbt transD(new RC2Decryption(key, keyLen, effectiveLen)); + auto_ptr transD(new RC2Decryption(key, keyLen, effectiveLen)); transD->ProcessBlock(out, outplain); fail=fail || !VerifyBufsEqual(outplain, plain, RC2Encryption::BLOCKSIZE); 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; } @@ -1048,44 +1047,43 @@ bool ValidateARC4() 0x9e,0x27,0x55,0xab,0x18,0x1a,0xb7,0xe9,0x40,0xb0, 0xc0}; - // VC60 workaround: auto_ptr lacks reset() - member_ptr arc4; + auto_ptr arc4; bool pass=true, fail; size_t 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 = !VerifyBufsEqual(Input0, Output0, sizeof(Input0)); - 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 = !VerifyBufsEqual(Output1, Key1, sizeof(Key1)); - 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; @@ -1093,7 +1091,7 @@ bool ValidateARC4() bool ValidateRC5() { - cout << "\nRC5 validation suite running...\n\n"; + std::cout << "\nRC5 validation suite running...\n\n"; FileSource valdata("TestData/rc5val.dat", true, new HexDecoder); return BlockTransformationTest(VariableRoundsCipherFactory(16, 12), valdata); @@ -1101,7 +1099,7 @@ bool ValidateRC5() bool ValidateRC6() { - cout << "\nRC6 validation suite running...\n\n"; + std::cout << "\nRC6 validation suite running...\n\n"; FileSource valdata("TestData/rc6val.dat", true, new HexDecoder); bool pass = true; @@ -1113,7 +1111,7 @@ bool ValidateRC6() bool ValidateMARS() { - cout << "\nMARS validation suite running...\n\n"; + std::cout << "\nMARS validation suite running...\n\n"; FileSource valdata("TestData/marsval.dat", true, new HexDecoder); bool pass = true; @@ -1125,7 +1123,7 @@ bool ValidateMARS() bool ValidateRijndael() { - cout << "\nRijndael (AES) validation suite running...\n\n"; + std::cout << "\nRijndael (AES) validation suite running...\n\n"; FileSource valdata("TestData/rijndael.dat", true, new HexDecoder); bool pass = true; @@ -1138,7 +1136,7 @@ bool ValidateRijndael() bool ValidateTwofish() { - cout << "\nTwofish validation suite running...\n\n"; + std::cout << "\nTwofish validation suite running...\n\n"; FileSource valdata("TestData/twofishv.dat", true, new HexDecoder); bool pass = true; @@ -1150,7 +1148,7 @@ bool ValidateTwofish() bool ValidateSerpent() { - cout << "\nSerpent validation suite running...\n\n"; + std::cout << "\nSerpent validation suite running...\n\n"; FileSource valdata("TestData/serpentv.dat", true, new HexDecoder); bool pass = true; @@ -1162,9 +1160,9 @@ bool ValidateSerpent() bool ValidateBlowfish() { - cout << "\nBlowfish validation suite running...\n\n"; + std::cout << "\nBlowfish validation suite running...\n\n"; - HexEncoder output(new FileSink(cout)); + HexEncoder output(new FileSink(std::cout)); static 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"}; @@ -1182,21 +1180,21 @@ bool ValidateBlowfish() fail = fail || !VerifyBufsEqual(outplain, plain[i], 8); pass = pass && !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 pass; } bool ValidateThreeWay() { - cout << "\n3-WAY validation suite running...\n\n"; + std::cout << "\n3-WAY validation suite running...\n\n"; FileSource valdata("TestData/3wayval.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata); @@ -1204,7 +1202,7 @@ bool ValidateThreeWay() bool ValidateGOST() { - cout << "\nGOST validation suite running...\n\n"; + std::cout << "\nGOST validation suite running...\n\n"; FileSource valdata("TestData/gostval.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata); @@ -1212,7 +1210,7 @@ bool ValidateGOST() bool ValidateSHARK() { - cout << "\nSHARK validation suite running...\n\n"; + std::cout << "\nSHARK validation suite running...\n\n"; FileSource valdata("TestData/sharkval.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata); @@ -1222,14 +1220,14 @@ bool ValidateCAST() { bool pass = true; - cout << "\nCAST-128 validation suite running...\n\n"; + std::cout << "\nCAST-128 validation suite running...\n\n"; FileSource val128("TestData/cast128v.dat", true, new HexDecoder); pass = BlockTransformationTest(FixedRoundsCipherFactory(16), val128, 1) && pass; pass = BlockTransformationTest(FixedRoundsCipherFactory(10), val128, 1) && pass; pass = BlockTransformationTest(FixedRoundsCipherFactory(5), val128, 1) && pass; - cout << "\nCAST-256 validation suite running...\n\n"; + std::cout << "\nCAST-256 validation suite running...\n\n"; FileSource val256("TestData/cast256v.dat", true, new HexDecoder); pass = BlockTransformationTest(FixedRoundsCipherFactory(16), val256, 1) && pass; @@ -1241,7 +1239,7 @@ bool ValidateCAST() bool ValidateSquare() { - cout << "\nSquare validation suite running...\n\n"; + std::cout << "\nSquare validation suite running...\n\n"; FileSource valdata("TestData/squareva.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata); @@ -1249,7 +1247,7 @@ bool ValidateSquare() bool ValidateSKIPJACK() { - cout << "\nSKIPJACK validation suite running...\n\n"; + std::cout << "\nSKIPJACK validation suite running...\n\n"; FileSource valdata("TestData/skipjack.dat", true, new HexDecoder); return BlockTransformationTest(FixedRoundsCipherFactory(), valdata); @@ -1262,7 +1260,7 @@ bool ValidateSEAL() byte key[] = {0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0}; byte iv[] = {0x01, 0x35, 0x77, 0xaf}; - 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); @@ -1279,7 +1277,7 @@ bool ValidateSEAL() seal.ProcessString(output+2, size-2); pass = pass && VerifyBufsEqual(output+1, input+1, size-1); - cout << (pass ? "passed" : "FAILED") << endl; + std::cout << (pass ? "passed" : "FAILED") << std::endl; return pass; } @@ -1315,36 +1313,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; @@ -1352,7 +1350,7 @@ bool ValidateBaseCode() bool ValidateSHACAL2() { - cout << "\nSHACAL-2 validation suite running...\n\n"; + std::cout << "\nSHACAL-2 validation suite running...\n\n"; bool pass = true; FileSource valdata("TestData/shacal2v.dat", true, new HexDecoder); @@ -1363,7 +1361,7 @@ bool ValidateSHACAL2() bool ValidateCamellia() { - cout << "\nCamellia validation suite running...\n\n"; + std::cout << "\nCamellia validation suite running...\n\n"; bool pass = true; FileSource valdata("TestData/camellia.dat", true, new HexDecoder); @@ -1375,40 +1373,40 @@ bool ValidateCamellia() bool ValidateSalsa() { - cout << "\nSalsa validation suite running...\n"; + std::cout << "\nSalsa validation suite running...\n"; return RunTestDataFile("TestVectors/salsa.txt"); } bool ValidateSosemanuk() { - cout << "\nSosemanuk validation suite running...\n"; + std::cout << "\nSosemanuk validation suite running...\n"; return RunTestDataFile("TestVectors/sosemanuk.txt"); } bool ValidateVMAC() { - cout << "\nVMAC validation suite running...\n"; + std::cout << "\nVMAC validation suite running...\n"; return RunTestDataFile("TestVectors/vmac.txt"); } bool ValidateCCM() { - cout << "\nAES/CCM validation suite running...\n"; + std::cout << "\nAES/CCM validation suite running...\n"; return RunTestDataFile("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("TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)2048)); - cout << "\n64K tables:"; + std::cout << "\n64K tables:"; return RunTestDataFile("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("TestVectors/cmac.txt"); } diff --git a/validat2.cpp b/validat2.cpp index 1197fe5f..0180ee74 100644 --- a/validat2.cpp +++ b/validat2.cpp @@ -52,7 +52,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"); @@ -74,30 +74,30 @@ bool ValidateBBS() fail = !VerifyBufsEqual(output1, buf, 20); 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 << setw(2) << setfill('0') << hex << (int)buf[j]; + std::cout << std::endl; bbs.Seek(10); bbs.GenerateBlock(buf, 10); fail = !VerifyBufsEqual(output1+10, buf, 10); 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 << setw(2) << setfill('0') << hex << (int)buf[j]; + std::cout << std::endl; bbs.Seek(1234567); bbs.GenerateBlock(buf, 20); fail = !VerifyBufsEqual(output2, buf, 20); 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 << setw(2) << setfill('0') << hex << (int)buf[j]; + std::cout << std::endl; return pass; } @@ -109,8 +109,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"; static const byte message[] = "test message"; const unsigned int messageLen = COUNTOF(message); @@ -120,15 +120,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) { @@ -138,16 +138,16 @@ bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false) fail = !(result.isValidCoding && result.messageLength == messageLen && VerifyBufsEqual(recovered, message, messageLen)); 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; @@ -160,8 +160,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"; static const byte message[] = "test message"; const int messageLen = COUNTOF(message); @@ -174,8 +174,8 @@ bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough = fail = fail || !VerifyBufsEqual(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; } @@ -183,10 +183,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; } @@ -202,27 +202,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 (!VerifyBufsEqual(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; } @@ -242,23 +242,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 (!VerifyBufsEqual(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; @@ -279,21 +279,21 @@ bool ValidateRSA() fail = !VerifyBufsEqual(signature, out, 64); 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("TestData/rsa1024.dat", true, new HexDecoder); @@ -336,8 +336,8 @@ bool ValidateRSA() fail = !result.isValidCoding || (result.messageLength!=8) || !VerifyBufsEqual(out, encrypted, 50) || !VerifyBufsEqual(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; @@ -345,7 +345,7 @@ bool ValidateRSA() bool ValidateDH() { - cout << "\nDH validation suite running...\n\n"; + std::cout << "\nDH validation suite running...\n\n"; FileSource f("TestData/dh1024.dat", true, new HexDecoder()); DH dh(f); @@ -354,7 +354,7 @@ bool ValidateDH() bool ValidateMQV() { - cout << "\nMQV validation suite running...\n\n"; + std::cout << "\nMQV validation suite running...\n\n"; FileSource f("TestData/mqv1024.dat", true, new HexDecoder()); MQV mqv(f); @@ -363,7 +363,7 @@ bool ValidateMQV() bool ValidateLUC_DH() { - cout << "\nLUC-DH validation suite running...\n\n"; + std::cout << "\nLUC-DH validation suite running...\n\n"; FileSource f("TestData/lucd512.dat", true, new HexDecoder()); LUC_DH dh(f); @@ -372,7 +372,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("TestData/xtrdh171.dat", true, new HexDecoder()); XTR_DH dh(f); @@ -381,7 +381,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("TestData/elgc1024.dat", true, new HexDecoder); @@ -399,7 +399,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("TestData/dlie1024.dat", true, new HexDecoder); @@ -408,7 +408,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; @@ -422,7 +422,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("TestData/nr2048.dat", true, new HexDecoder); @@ -433,7 +433,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); @@ -444,7 +444,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("TestData/dsa1024.dat", true, new HexDecoder()); @@ -460,7 +460,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; { @@ -479,14 +479,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("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("TestData/lucc512.dat", true, new HexDecoder); LUC_IES<>::Decryptor privC(fc); @@ -498,7 +498,7 @@ bool ValidateLUC_DL() bool ValidateRabin() { - cout << "\nRabin validation suite running...\n\n"; + std::cout << "\nRabin validation suite running...\n\n"; bool pass=true; { @@ -517,7 +517,7 @@ bool ValidateRabin() bool ValidateRW() { - cout << "\nRW validation suite running...\n\n"; + std::cout << "\nRW validation suite running...\n\n"; bool pass=true; FileSource f("TestData/rw1024.dat", true, new HexDecoder); @@ -531,7 +531,7 @@ bool ValidateRW() /* bool ValidateBlumGoldwasser() { - cout << "\nBlumGoldwasser validation suite running...\n\n"; + std::cout << "\nBlumGoldwasser validation suite running...\n\n"; FileSource f("TestData/blum512.dat", true, new HexDecoder); BlumGoldwasserPrivateKey priv(f); @@ -543,7 +543,7 @@ bool ValidateBlumGoldwasser() 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); @@ -568,7 +568,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); @@ -577,13 +577,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") << " " << dec << params.GetCurve().GetField().MaxElementBitLength() << " bits" << std::endl; pass = pass && !fail; } @@ -592,7 +592,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); @@ -615,7 +615,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); @@ -625,13 +625,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 @@ -641,7 +641,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); @@ -672,14 +672,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; @@ -691,7 +691,7 @@ bool ValidateECDSA() bool ValidateESIGN() { - cout << "\nESIGN validation suite running...\n\n"; + std::cout << "\nESIGN validation suite running...\n\n"; bool pass = true, fail; @@ -713,10 +713,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; diff --git a/validat3.cpp b/validat3.cpp index 1258af19..eb82aa5c 100644 --- a/validat3.cpp +++ b/validat3.cpp @@ -61,13 +61,13 @@ bool HashModuleTest(HashTransformation &md, const HashTestTuple *testSet, unsign fail = !VerifyBufsEqual(digest, testSet[i].output, md.DigestSize()); pass = pass && !fail; - cout << (fail ? "FAILED " : "passed "); + std::cout << (fail ? "FAILED " : "passed "); for (j=0; j(derivedKey.data()), derived.size()); pass = pass && !fail; - HexEncoder enc(new FileSink(cout)); - cout << (fail ? "FAILED " : "passed "); + HexEncoder enc(new FileSink(std::cout)); + std::cout << (fail ? "FAILED " : "passed "); enc.Put(tuple.purpose); - cout << " " << tuple.iterations; - cout << " " << tuple.hexPassword << " " << tuple.hexSalt << " "; + std::cout << " " << tuple.iterations; + std::cout << " " << tuple.hexPassword << " " << tuple.hexSalt << " "; enc.Put(derived, derived.size()); - cout << endl; + std::cout << std::endl; } return pass; @@ -573,7 +573,7 @@ bool ValidatePBKDF() PKCS12_PBKDF pbkdf; - cout << "\nPKCS #12 PBKDF validation suite running...\n\n"; + std::cout << "\nPKCS #12 PBKDF validation suite running...\n\n"; pass = TestPBKDF(pbkdf, testSet, COUNTOF(testSet)) && pass; } @@ -587,7 +587,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, COUNTOF(testSet)) && pass; } @@ -608,7 +608,7 @@ bool TestHKDF(KeyDerivationFunction &kdf, const HKDF_TestTuple *testSet, unsigne { const HKDF_TestTuple &tuple = testSet[i]; - string secret, context, salt, derivedKey; + std::string secret, context, salt, derivedKey; StringSource(tuple.hexSecret, true, new HexDecoder(new StringSink(secret))); StringSource(tuple.hexSalt ? tuple.hexSalt : "", true, new HexDecoder(new StringSink(salt))); StringSource(tuple.hexContext ? tuple.hexContext : "", true, new HexDecoder(new StringSink(context))); @@ -624,12 +624,12 @@ bool TestHKDF(KeyDerivationFunction &kdf, const HKDF_TestTuple *testSet, unsigne bool fail = !VerifyBufsEqual(derived, reinterpret_cast(derivedKey.data()), derived.size()); pass = pass && !fail; - HexEncoder enc(new FileSink(cout)); - cout << (fail ? "FAILED " : "passed "); - cout << " " << tuple.hexSecret << " " << (tuple.hexSalt ? tuple.hexSalt : ""); - cout << " " << (tuple.hexContext ? tuple.hexContext : "") << " "; + HexEncoder enc(new FileSink(std::cout)); + std::cout << (fail ? "FAILED " : "passed "); + std::cout << " " << tuple.hexSecret << " " << (tuple.hexSalt ? tuple.hexSalt : ""); + std::cout << " " << (tuple.hexContext ? tuple.hexContext : "") << " "; enc.Put(derived, derived.size()); - cout << endl; + std::cout << std::endl; } return pass; @@ -653,7 +653,7 @@ bool ValidateHKDF() HKDF hkdf; - cout << "\nRFC 5869 HKDF(SHA-1) validation suite running...\n\n"; + std::cout << "\nRFC 5869 HKDF(SHA-1) validation suite running...\n\n"; pass = TestHKDF(hkdf, testSet, COUNTOF(testSet)) && pass; } @@ -671,7 +671,7 @@ bool ValidateHKDF() HKDF hkdf; - cout << "\nRFC 5869 HKDF(SHA-256) validation suite running...\n\n"; + std::cout << "\nRFC 5869 HKDF(SHA-256) validation suite running...\n\n"; pass = TestHKDF(hkdf, testSet, COUNTOF(testSet)) && pass; } @@ -690,7 +690,7 @@ bool ValidateHKDF() HKDF hkdf; - cout << "\nRFC 5869 HKDF(SHA-512) validation suite running...\n\n"; + std::cout << "\nRFC 5869 HKDF(SHA-512) validation suite running...\n\n"; pass = TestHKDF(hkdf, testSet, COUNTOF(testSet)) && pass; }