• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

validat1.cpp

00001 // validat1.cpp - written and placed in the public domain by Wei Dai
00002 
00003 #include "pch.h"
00004 
00005 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
00006 #include "files.h"
00007 #include "hex.h"
00008 #include "base32.h"
00009 #include "base64.h"
00010 #include "modes.h"
00011 #include "cbcmac.h"
00012 #include "dmac.h"
00013 #include "idea.h"
00014 #include "des.h"
00015 #include "rc2.h"
00016 #include "arc4.h"
00017 #include "rc5.h"
00018 #include "blowfish.h"
00019 #include "3way.h"
00020 #include "safer.h"
00021 #include "gost.h"
00022 #include "shark.h"
00023 #include "cast.h"
00024 #include "square.h"
00025 #include "seal.h"
00026 #include "rc6.h"
00027 #include "mars.h"
00028 #include "rijndael.h"
00029 #include "twofish.h"
00030 #include "serpent.h"
00031 #include "skipjack.h"
00032 #include "shacal2.h"
00033 #include "camellia.h"
00034 #include "osrng.h"
00035 #include "zdeflate.h"
00036 #include "cpu.h"
00037 
00038 #include <time.h>
00039 #include <memory>
00040 #include <iostream>
00041 #include <iomanip>
00042 
00043 #include "validate.h"
00044 
00045 USING_NAMESPACE(CryptoPP)
00046 USING_NAMESPACE(std)
00047 
00048 bool ValidateAll(bool thorough)
00049 {
00050         bool pass=TestSettings();
00051         pass=TestOS_RNG() && pass;
00052 
00053         pass=ValidateCRC32() && pass;
00054         pass=ValidateAdler32() && pass;
00055         pass=ValidateMD2() && pass;
00056         pass=ValidateMD5() && pass;
00057         pass=ValidateSHA() && pass;
00058         pass=ValidateTiger() && pass;
00059         pass=ValidateRIPEMD() && pass;
00060         pass=ValidatePanama() && pass;
00061         pass=ValidateWhirlpool() && pass;
00062 
00063         pass=ValidateHMAC() && pass;
00064         pass=ValidateTTMAC() && pass;
00065 
00066         pass=ValidatePBKDF() && pass;
00067 
00068         pass=ValidateDES() && pass;
00069         pass=ValidateCipherModes() && pass;
00070         pass=ValidateIDEA() && pass;
00071         pass=ValidateSAFER() && pass;
00072         pass=ValidateRC2() && pass;
00073         pass=ValidateARC4() && pass;
00074         pass=ValidateRC5() && pass;
00075         pass=ValidateBlowfish() && pass;
00076         pass=ValidateThreeWay() && pass;
00077         pass=ValidateGOST() && pass;
00078         pass=ValidateSHARK() && pass;
00079         pass=ValidateCAST() && pass;
00080         pass=ValidateSquare() && pass;
00081         pass=ValidateSKIPJACK() && pass;
00082         pass=ValidateSEAL() && pass;
00083         pass=ValidateRC6() && pass;
00084         pass=ValidateMARS() && pass;
00085         pass=ValidateRijndael() && pass;
00086         pass=ValidateTwofish() && pass;
00087         pass=ValidateSerpent() && pass;
00088         pass=ValidateSHACAL2() && pass;
00089         pass=ValidateCamellia() && pass;
00090         pass=ValidateSalsa() && pass;
00091         pass=ValidateSosemanuk() && pass;
00092         pass=ValidateVMAC() && pass;
00093         pass=ValidateCCM() && pass;
00094         pass=ValidateGCM() && pass;
00095         pass=ValidateCMAC() && pass;
00096         pass=RunTestDataFile("TestVectors/eax.txt") && pass;
00097         pass=RunTestDataFile("TestVectors/seed.txt") && pass;
00098 
00099         pass=ValidateBBS() && pass;
00100         pass=ValidateDH() && pass;
00101         pass=ValidateMQV() && pass;
00102         pass=ValidateRSA() && pass;
00103         pass=ValidateElGamal() && pass;
00104         pass=ValidateDLIES() && pass;
00105         pass=ValidateNR() && pass;
00106         pass=ValidateDSA(thorough) && pass;
00107         pass=ValidateLUC() && pass;
00108         pass=ValidateLUC_DH() && pass;
00109         pass=ValidateLUC_DL() && pass;
00110         pass=ValidateXTR_DH() && pass;
00111         pass=ValidateRabin() && pass;
00112         pass=ValidateRW() && pass;
00113 //      pass=ValidateBlumGoldwasser() && pass;
00114         pass=ValidateECP() && pass;
00115         pass=ValidateEC2N() && pass;
00116         pass=ValidateECDSA() && pass;
00117         pass=ValidateESIGN() && pass;
00118 
00119         if (pass)
00120                 cout << "\nAll tests passed!\n";
00121         else
00122                 cout << "\nOops!  Not all tests passed.\n";
00123 
00124         return pass;
00125 }
00126 
00127 bool TestSettings()
00128 {
00129         bool pass = true;
00130 
00131         cout << "\nTesting Settings...\n\n";
00132 
00133         word32 w;
00134         memcpy_s(&w, sizeof(w), "\x01\x02\x03\x04", 4);
00135 
00136         if (w == 0x04030201L)
00137         {
00138 #ifdef IS_LITTLE_ENDIAN
00139                 cout << "passed:  ";
00140 #else
00141                 cout << "FAILED:  ";
00142                 pass = false;
00143 #endif
00144                 cout << "Your machine is little endian.\n";
00145         }
00146         else if (w == 0x01020304L)
00147         {
00148 #ifndef IS_LITTLE_ENDIAN
00149                 cout << "passed:  ";
00150 #else
00151                 cout << "FAILED:  ";
00152                 pass = false;
00153 #endif
00154                 cout << "Your machine is big endian.\n";
00155         }
00156         else
00157         {
00158                 cout << "FAILED:  Your machine is neither big endian nor little endian.\n";
00159                 pass = false;
00160         }
00161 
00162 #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
00163         byte testvals[10] = {1,2,2,3,3,3,3,2,2,1};
00164         if (*(word32 *)(testvals+3) == 0x03030303 && *(word64 *)(testvals+1) == W64LIT(0x0202030303030202))
00165                 cout << "passed:  Your machine allows unaligned data access.\n";
00166         else
00167         {
00168                 cout << "FAILED:  Unaligned data access gave incorrect results.\n";
00169                 pass = false;
00170         }
00171 #else
00172         cout << "passed:  CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is not defined. Will restrict to aligned data access.\n";
00173 #endif
00174 
00175         if (sizeof(byte) == 1)
00176                 cout << "passed:  ";
00177         else
00178         {
00179                 cout << "FAILED:  ";
00180                 pass = false;
00181         }
00182         cout << "sizeof(byte) == " << sizeof(byte) << endl;
00183 
00184         if (sizeof(word16) == 2)
00185                 cout << "passed:  ";
00186         else
00187         {
00188                 cout << "FAILED:  ";
00189                 pass = false;
00190         }
00191         cout << "sizeof(word16) == " << sizeof(word16) << endl;
00192 
00193         if (sizeof(word32) == 4)
00194                 cout << "passed:  ";
00195         else
00196         {
00197                 cout << "FAILED:  ";
00198                 pass = false;
00199         }
00200         cout << "sizeof(word32) == " << sizeof(word32) << endl;
00201 
00202         if (sizeof(word64) == 8)
00203                 cout << "passed:  ";
00204         else
00205         {
00206                 cout << "FAILED:  ";
00207                 pass = false;
00208         }
00209         cout << "sizeof(word64) == " << sizeof(word64) << endl;
00210 
00211 #ifdef CRYPTOPP_WORD128_AVAILABLE
00212         if (sizeof(word128) == 16)
00213                 cout << "passed:  ";
00214         else
00215         {
00216                 cout << "FAILED:  ";
00217                 pass = false;
00218         }
00219         cout << "sizeof(word128) == " << sizeof(word128) << endl;
00220 #endif
00221 
00222         if (sizeof(word) == 2*sizeof(hword)
00223 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
00224                 && sizeof(dword) == 2*sizeof(word)
00225 #endif
00226                 )
00227                 cout << "passed:  ";
00228         else
00229         {
00230                 cout << "FAILED:  ";
00231                 pass = false;
00232         }
00233         cout << "sizeof(hword) == " << sizeof(hword) << ", sizeof(word) == " << sizeof(word);
00234 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
00235         cout << ", sizeof(dword) == " << sizeof(dword);
00236 #endif
00237         cout << endl;
00238 
00239 #ifdef CRYPTOPP_CPUID_AVAILABLE
00240         bool hasMMX = HasMMX();
00241         bool hasISSE = HasISSE();
00242         bool hasSSE2 = HasSSE2();
00243         bool hasSSSE3 = HasSSSE3();
00244         bool isP4 = IsP4();
00245         int cacheLineSize = GetCacheLineSize();
00246 
00247         if ((isP4 && (!hasMMX || !hasSSE2)) || (hasSSE2 && !hasMMX) || (cacheLineSize < 16 || cacheLineSize > 256 || !IsPowerOf2(cacheLineSize)))
00248         {
00249                 cout << "FAILED:  ";
00250                 pass = false;
00251         }
00252         else
00253                 cout << "passed:  ";
00254 
00255         cout << "hasMMX == " << hasMMX << ", hasISSE == " << hasISSE << ", hasSSE2 == " << hasSSE2 << ", hasSSSE3 == " << hasSSSE3 << ", hasAESNI == " << HasAESNI() << ", hasCLMUL == " << HasCLMUL() << ", isP4 == " << isP4 << ", cacheLineSize == " << cacheLineSize;
00256         cout << ", AESNI_INTRINSICS == " << CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE << endl;
00257 #endif
00258 
00259         if (!pass)
00260         {
00261                 cout << "Some critical setting in config.h is in error.  Please fix it and recompile." << endl;
00262                 abort();
00263         }
00264         return pass;
00265 }
00266 
00267 bool TestOS_RNG()
00268 {
00269         bool pass = true;
00270 
00271         member_ptr<RandomNumberGenerator> rng;
00272 #ifdef BLOCKING_RNG_AVAILABLE
00273         try {rng.reset(new BlockingRng);}
00274         catch (OS_RNG_Err &) {}
00275 #endif
00276 
00277         if (rng.get())
00278         {
00279                 cout << "\nTesting operating system provided blocking random number generator...\n\n";
00280 
00281                 ArraySink *sink;
00282                 RandomNumberSource test(*rng, UINT_MAX, false, new Deflator(sink=new ArraySink(NULL,0)));
00283                 unsigned long total=0, length=0;
00284                 time_t t = time(NULL), t1 = 0;
00285 
00286                 // check that it doesn't take too long to generate a reasonable amount of randomness
00287                 while (total < 16 && (t1 < 10 || total*8 > (unsigned long)t1))
00288                 {
00289                         test.Pump(1);
00290                         total += 1;
00291                         t1 = time(NULL) - t;
00292                 }
00293 
00294                 if (total < 16)
00295                 {
00296                         cout << "FAILED:";
00297                         pass = false;
00298                 }
00299                 else
00300                         cout << "passed:";
00301                 cout << "  it took " << long(t1) << " seconds to generate " << total << " bytes" << endl;
00302 
00303 #if 0   // disable this part. it's causing an unpredictable pause during the validation testing
00304                 if (t1 < 2)
00305                 {
00306                         // that was fast, are we really blocking?
00307                         // first exhaust the extropy reserve
00308                         t = time(NULL);
00309                         while (time(NULL) - t < 2)
00310                         {
00311                                 test.Pump(1);
00312                                 total += 1;
00313                         }
00314 
00315                         // if it generates too many bytes in a certain amount of time,
00316                         // something's probably wrong
00317                         t = time(NULL);
00318                         while (time(NULL) - t < 2)
00319                         {
00320                                 test.Pump(1);
00321                                 total += 1;
00322                                 length += 1;
00323                         }
00324                         if (length > 1024)
00325                         {
00326                                 cout << "FAILED:";
00327                                 pass = false;
00328                         }
00329                         else
00330                                 cout << "passed:";
00331                         cout << "  it generated " << length << " bytes in " << long(time(NULL) - t) << " seconds" << endl;
00332                 }
00333 #endif
00334 
00335                 test.AttachedTransformation()->MessageEnd();
00336 
00337                 if (sink->TotalPutLength() < total)
00338                 {
00339                         cout << "FAILED:";
00340                         pass = false;
00341                 }
00342                 else
00343                         cout << "passed:";
00344                 cout << "  " << total << " generated bytes compressed to " << (size_t)sink->TotalPutLength() << " bytes by DEFLATE" << endl;
00345         }
00346         else
00347                 cout << "\nNo operating system provided blocking random number generator, skipping test." << endl;
00348 
00349         rng.reset(NULL);
00350 #ifdef NONBLOCKING_RNG_AVAILABLE
00351         try {rng.reset(new NonblockingRng);}
00352         catch (OS_RNG_Err &) {}
00353 #endif
00354 
00355         if (rng.get())
00356         {
00357                 cout << "\nTesting operating system provided nonblocking random number generator...\n\n";
00358 
00359                 ArraySink *sink;
00360                 RandomNumberSource test(*rng, 100000, true, new Deflator(sink=new ArraySink(NULL, 0)));
00361                 
00362                 if (sink->TotalPutLength() < 100000)
00363                 {
00364                         cout << "FAILED:";
00365                         pass = false;
00366                 }
00367                 else
00368                         cout << "passed:";
00369                 cout << "  100000 generated bytes compressed to " << (size_t)sink->TotalPutLength() << " bytes by DEFLATE" << endl;
00370         }
00371         else
00372                 cout << "\nNo operating system provided nonblocking random number generator, skipping test." << endl;
00373 
00374         return pass;
00375 }
00376 
00377 // VC50 workaround
00378 typedef auto_ptr<BlockTransformation> apbt;
00379 
00380 class CipherFactory
00381 {
00382 public:
00383         virtual unsigned int BlockSize() const =0;
00384         virtual unsigned int KeyLength() const =0;
00385 
00386         virtual apbt NewEncryption(const byte *key) const =0;
00387         virtual apbt NewDecryption(const byte *key) const =0;
00388 };
00389 
00390 template <class E, class D> class FixedRoundsCipherFactory : public CipherFactory
00391 {
00392 public:
00393         FixedRoundsCipherFactory(unsigned int keylen=0) : m_keylen(keylen?keylen:E::DEFAULT_KEYLENGTH) {}
00394         unsigned int BlockSize() const {return E::BLOCKSIZE;}
00395         unsigned int KeyLength() const {return m_keylen;}
00396 
00397         apbt NewEncryption(const byte *key) const
00398                 {return apbt(new E(key, m_keylen));}
00399         apbt NewDecryption(const byte *key) const
00400                 {return apbt(new D(key, m_keylen));}
00401 
00402         unsigned int m_keylen;
00403 };
00404 
00405 template <class E, class D> class VariableRoundsCipherFactory : public CipherFactory
00406 {
00407 public:
00408         VariableRoundsCipherFactory(unsigned int keylen=0, unsigned int rounds=0)
00409                 : m_keylen(keylen ? keylen : E::DEFAULT_KEYLENGTH), m_rounds(rounds ? rounds : E::DEFAULT_ROUNDS) {}
00410         unsigned int BlockSize() const {return E::BLOCKSIZE;}
00411         unsigned int KeyLength() const {return m_keylen;}
00412 
00413         apbt NewEncryption(const byte *key) const
00414                 {return apbt(new E(key, m_keylen, m_rounds));}
00415         apbt NewDecryption(const byte *key) const
00416                 {return apbt(new D(key, m_keylen, m_rounds));}
00417 
00418         unsigned int m_keylen, m_rounds;
00419 };
00420 
00421 bool BlockTransformationTest(const CipherFactory &cg, BufferedTransformation &valdata, unsigned int tuples = 0xffff)
00422 {
00423         HexEncoder output(new FileSink(cout));
00424         SecByteBlock plain(cg.BlockSize()), cipher(cg.BlockSize()), out(cg.BlockSize()), outplain(cg.BlockSize());
00425         SecByteBlock key(cg.KeyLength());
00426         bool pass=true, fail;
00427 
00428         while (valdata.MaxRetrievable() && tuples--)
00429         {
00430                 valdata.Get(key, cg.KeyLength());
00431                 valdata.Get(plain, cg.BlockSize());
00432                 valdata.Get(cipher, cg.BlockSize());
00433 
00434                 apbt transE = cg.NewEncryption(key);
00435                 transE->ProcessBlock(plain, out);
00436                 fail = memcmp(out, cipher, cg.BlockSize()) != 0;
00437 
00438                 apbt transD = cg.NewDecryption(key);
00439                 transD->ProcessBlock(out, outplain);
00440                 fail=fail || memcmp(outplain, plain, cg.BlockSize());
00441 
00442                 pass = pass && !fail;
00443 
00444                 cout << (fail ? "FAILED   " : "passed   ");
00445                 output.Put(key, cg.KeyLength());
00446                 cout << "   ";
00447                 output.Put(outplain, cg.BlockSize());
00448                 cout << "   ";
00449                 output.Put(out, cg.BlockSize());
00450                 cout << endl;
00451         }
00452         return pass;
00453 }
00454 
00455 class FilterTester : public Unflushable<Sink>
00456 {
00457 public:
00458         FilterTester(const byte *validOutput, size_t outputLen)
00459                 : validOutput(validOutput), outputLen(outputLen), counter(0), fail(false) {}
00460         void PutByte(byte inByte)
00461         {
00462                 if (counter >= outputLen || validOutput[counter] != inByte)
00463                 {
00464                         std::cerr << "incorrect output " << counter << ", " << (word16)validOutput[counter] << ", " << (word16)inByte << "\n";
00465                         fail = true;
00466                         assert(false);
00467                 }
00468                 counter++;
00469         }
00470         size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
00471         {
00472                 while (length--)
00473                         FilterTester::PutByte(*inString++);
00474 
00475                 if (messageEnd)
00476                         if (counter != outputLen)
00477                         {
00478                                 fail = true;
00479                                 assert(false);
00480                         }
00481 
00482                 return 0;
00483         }
00484         bool GetResult()
00485         {
00486                 return !fail;
00487         }
00488 
00489         const byte *validOutput;
00490         size_t outputLen, counter;
00491         bool fail;
00492 };
00493 
00494 bool TestFilter(BufferedTransformation &bt, const byte *in, size_t inLen, const byte *out, size_t outLen)
00495 {
00496         FilterTester *ft;
00497         bt.Attach(ft = new FilterTester(out, outLen));
00498 
00499         while (inLen)
00500         {
00501                 size_t randomLen = GlobalRNG().GenerateWord32(0, (word32)inLen);
00502                 bt.Put(in, randomLen);
00503                 in += randomLen;
00504                 inLen -= randomLen;
00505         }
00506         bt.MessageEnd();
00507         return ft->GetResult();
00508 }
00509 
00510 bool ValidateDES()
00511 {
00512         cout << "\nDES validation suite running...\n\n";
00513 
00514         FileSource valdata("TestData/descert.dat", true, new HexDecoder);
00515         bool pass = BlockTransformationTest(FixedRoundsCipherFactory<DESEncryption, DESDecryption>(), valdata);
00516 
00517         cout << "\nTesting EDE2, EDE3, and XEX3 variants...\n\n";
00518 
00519         FileSource valdata1("TestData/3desval.dat", true, new HexDecoder);
00520         pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_EDE2_Encryption, DES_EDE2_Decryption>(), valdata1, 1) && pass;
00521         pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_EDE3_Encryption, DES_EDE3_Decryption>(), valdata1, 1) && pass;
00522         pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_XEX3_Encryption, DES_XEX3_Decryption>(), valdata1, 1) && pass;
00523 
00524         return pass;
00525 }
00526 
00527 bool TestModeIV(SymmetricCipher &e, SymmetricCipher &d)
00528 {
00529         SecByteBlock lastIV, iv(e.IVSize());
00530         StreamTransformationFilter filter(e, new StreamTransformationFilter(d));
00531         byte plaintext[20480];
00532 
00533         for (unsigned int i=1; i<sizeof(plaintext); i*=2)
00534         {
00535                 e.GetNextIV(GlobalRNG(), iv);
00536                 if (iv == lastIV)
00537                         return false;
00538                 else
00539                         lastIV = iv;
00540 
00541                 e.Resynchronize(iv);
00542                 d.Resynchronize(iv);
00543 
00544                 unsigned int length = STDMAX(GlobalRNG().GenerateWord32(0, i), (word32)e.MinLastBlockSize());
00545                 GlobalRNG().GenerateBlock(plaintext, length);
00546 
00547                 if (!TestFilter(filter, plaintext, length, plaintext, length))
00548                         return false;
00549         }
00550 
00551         return true;
00552 }
00553 
00554 bool ValidateCipherModes()
00555 {
00556         cout << "\nTesting DES modes...\n\n";
00557         const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
00558         const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
00559         const byte plain[] = {  // "Now is the time for all " without tailing 0
00560                 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
00561                 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
00562                 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};
00563         DESEncryption desE(key);
00564         DESDecryption desD(key);
00565         bool pass=true, fail;
00566 
00567         {
00568                 // from FIPS 81
00569                 const byte encrypted[] = {
00570                         0x3f, 0xa4, 0x0e, 0x8a, 0x98, 0x4d, 0x48, 0x15,
00571                         0x6a, 0x27, 0x17, 0x87, 0xab, 0x88, 0x83, 0xf9,
00572                         0x89, 0x3d, 0x51, 0xec, 0x4b, 0x56, 0x3b, 0x53};
00573 
00574                 ECB_Mode_ExternalCipher::Encryption modeE(desE);
00575                 fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
00576                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00577                 pass = pass && !fail;
00578                 cout << (fail ? "FAILED   " : "passed   ") << "ECB encryption" << endl;
00579                 
00580                 ECB_Mode_ExternalCipher::Decryption modeD(desD);
00581                 fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
00582                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00583                 pass = pass && !fail;
00584                 cout << (fail ? "FAILED   " : "passed   ") << "ECB decryption" << endl;
00585         }
00586         {
00587                 // from FIPS 81
00588                 const byte encrypted[] = {
00589                         0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C, 
00590                         0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F, 
00591                         0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6};
00592 
00593                 CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
00594                 fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
00595                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00596                 pass = pass && !fail;
00597                 cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with no padding" << endl;
00598                 
00599                 CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
00600                 fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
00601                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00602                 pass = pass && !fail;
00603                 cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with no padding" << endl;
00604 
00605                 fail = !TestModeIV(modeE, modeD);
00606                 pass = pass && !fail;
00607                 cout << (fail ? "FAILED   " : "passed   ") << "CBC mode IV generation" << endl;
00608         }
00609         {
00610                 // generated with Crypto++, matches FIPS 81
00611                 // but has extra 8 bytes as result of padding
00612                 const byte encrypted[] = {
00613                         0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C, 
00614                         0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F, 
00615                         0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6, 
00616                         0x62, 0xC1, 0x6A, 0x27, 0xE4, 0xFC, 0xF2, 0x77};
00617 
00618                 CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
00619                 fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
00620                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00621                 pass = pass && !fail;
00622                 cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with PKCS #7 padding" << endl;
00623                 
00624                 CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
00625                 fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
00626                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00627                 pass = pass && !fail;
00628                 cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with PKCS #7 padding" << endl;
00629         }
00630         {
00631                 // generated with Crypto++ 5.2, matches FIPS 81
00632                 // but has extra 8 bytes as result of padding
00633                 const byte encrypted[] = {
00634                         0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C, 
00635                         0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F, 
00636                         0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6, 
00637                         0xcf, 0xb7, 0xc7, 0x64, 0x0e, 0x7c, 0xd9, 0xa7};
00638 
00639                 CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
00640                 fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ONE_AND_ZEROS_PADDING).Ref(),
00641                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00642                 pass = pass && !fail;
00643                 cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with one-and-zeros padding" << endl;
00644 
00645                 CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
00646                 fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::ONE_AND_ZEROS_PADDING).Ref(),
00647                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00648                 pass = pass && !fail;
00649                 cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with one-and-zeros padding" << endl;
00650         }
00651         {
00652                 const byte plain[] = {'a', 0, 0, 0, 0, 0, 0, 0};
00653                 // generated with Crypto++
00654                 const byte encrypted[] = {
00655                         0x9B, 0x47, 0x57, 0x59, 0xD6, 0x9C, 0xF6, 0xD0};
00656 
00657                 CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
00658                 fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(),
00659                         plain, 1, encrypted, sizeof(encrypted));
00660                 pass = pass && !fail;
00661                 cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with zeros padding" << endl;
00662 
00663                 CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
00664                 fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(),
00665                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00666                 pass = pass && !fail;
00667                 cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with zeros padding" << endl;
00668         }
00669         {
00670                 // generated with Crypto++, matches FIPS 81
00671                 // but with last two blocks swapped as result of CTS
00672                 const byte encrypted[] = {
00673                         0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C, 
00674                         0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6, 
00675                         0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F};
00676 
00677                 CBC_CTS_Mode_ExternalCipher::Encryption modeE(desE, iv);
00678                 fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
00679                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00680                 pass = pass && !fail;
00681                 cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with ciphertext stealing (CTS)" << endl;
00682                 
00683                 CBC_CTS_Mode_ExternalCipher::Decryption modeD(desD, iv);
00684                 fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
00685                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00686                 pass = pass && !fail;
00687                 cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with ciphertext stealing (CTS)" << endl;
00688 
00689                 fail = !TestModeIV(modeE, modeD);
00690                 pass = pass && !fail;
00691                 cout << (fail ? "FAILED   " : "passed   ") << "CBC CTS IV generation" << endl;
00692         }
00693         {
00694                 // generated with Crypto++
00695                 const byte decryptionIV[] = {0x4D, 0xD0, 0xAC, 0x8F, 0x47, 0xCF, 0x79, 0xCE};
00696                 const byte encrypted[] = {0x12, 0x34, 0x56};
00697 
00698                 byte stolenIV[8];
00699 
00700                 CBC_CTS_Mode_ExternalCipher::Encryption modeE(desE, iv);
00701                 modeE.SetStolenIV(stolenIV);
00702                 fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
00703                         plain, 3, encrypted, sizeof(encrypted));
00704                 fail = memcmp(stolenIV, decryptionIV, 8) != 0 || fail;
00705                 pass = pass && !fail;
00706                 cout << (fail ? "FAILED   " : "passed   ") << "CBC encryption with ciphertext and IV stealing" << endl;
00707                 
00708                 CBC_CTS_Mode_ExternalCipher::Decryption modeD(desD, stolenIV);
00709                 fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
00710                         encrypted, sizeof(encrypted), plain, 3);
00711                 pass = pass && !fail;
00712                 cout << (fail ? "FAILED   " : "passed   ") << "CBC decryption with ciphertext and IV stealing" << endl;
00713         }
00714         {
00715                 const byte encrypted[] = {      // from FIPS 81
00716                         0xF3,0x09,0x62,0x49,0xC7,0xF4,0x6E,0x51,
00717                         0xA6,0x9E,0x83,0x9B,0x1A,0x92,0xF7,0x84,
00718                         0x03,0x46,0x71,0x33,0x89,0x8E,0xA6,0x22};
00719 
00720                 CFB_Mode_ExternalCipher::Encryption modeE(desE, iv);
00721                 fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
00722                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00723                 pass = pass && !fail;
00724                 cout << (fail ? "FAILED   " : "passed   ") << "CFB encryption" << endl;
00725 
00726                 CFB_Mode_ExternalCipher::Decryption modeD(desE, iv);
00727                 fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
00728                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00729                 pass = pass && !fail;
00730                 cout << (fail ? "FAILED   " : "passed   ") << "CFB decryption" << endl;
00731 
00732                 fail = !TestModeIV(modeE, modeD);
00733                 pass = pass && !fail;
00734                 cout << (fail ? "FAILED   " : "passed   ") << "CFB mode IV generation" << endl;
00735         }
00736         {
00737                 const byte plain[] = {  // "Now is the." without tailing 0
00738                         0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,0x68,0x65};
00739                 const byte encrypted[] = {      // from FIPS 81
00740                         0xf3,0x1f,0xda,0x07,0x01,0x14,0x62,0xee,0x18,0x7f};
00741 
00742                 CFB_Mode_ExternalCipher::Encryption modeE(desE, iv, 1);
00743                 fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
00744                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00745                 pass = pass && !fail;
00746                 cout << (fail ? "FAILED   " : "passed   ") << "CFB (8-bit feedback) encryption" << endl;
00747 
00748                 CFB_Mode_ExternalCipher::Decryption modeD(desE, iv, 1);
00749                 fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
00750                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00751                 pass = pass && !fail;
00752                 cout << (fail ? "FAILED   " : "passed   ") << "CFB (8-bit feedback) decryption" << endl;
00753 
00754                 fail = !TestModeIV(modeE, modeD);
00755                 pass = pass && !fail;
00756                 cout << (fail ? "FAILED   " : "passed   ") << "CFB (8-bit feedback) IV generation" << endl;
00757         }
00758         {
00759                 const byte encrypted[] = {      // from Eric Young's libdes
00760                         0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
00761                         0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
00762                         0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3};
00763 
00764                 OFB_Mode_ExternalCipher::Encryption modeE(desE, iv);
00765                 fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
00766                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00767                 pass = pass && !fail;
00768                 cout << (fail ? "FAILED   " : "passed   ") << "OFB encryption" << endl;
00769 
00770                 OFB_Mode_ExternalCipher::Decryption modeD(desE, iv);
00771                 fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
00772                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00773                 pass = pass && !fail;
00774                 cout << (fail ? "FAILED   " : "passed   ") << "OFB decryption" << endl;
00775 
00776                 fail = !TestModeIV(modeE, modeD);
00777                 pass = pass && !fail;
00778                 cout << (fail ? "FAILED   " : "passed   ") << "OFB IV generation" << endl;
00779         }
00780         {
00781                 const byte encrypted[] = {      // generated with Crypto++
00782                         0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4, 0x6E, 0x51, 
00783                         0x16, 0x3A, 0x8C, 0xA0, 0xFF, 0xC9, 0x4C, 0x27, 
00784                         0xFA, 0x2F, 0x80, 0xF4, 0x80, 0xB8, 0x6F, 0x75};
00785 
00786                 CTR_Mode_ExternalCipher::Encryption modeE(desE, iv);
00787                 fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
00788                         plain, sizeof(plain), encrypted, sizeof(encrypted));
00789                 pass = pass && !fail;
00790                 cout << (fail ? "FAILED   " : "passed   ") << "Counter Mode encryption" << endl;
00791 
00792                 CTR_Mode_ExternalCipher::Decryption modeD(desE, iv);
00793                 fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
00794                         encrypted, sizeof(encrypted), plain, sizeof(plain));
00795                 pass = pass && !fail;
00796                 cout << (fail ? "FAILED   " : "passed   ") << "Counter Mode decryption" << endl;
00797 
00798                 fail = !TestModeIV(modeE, modeD);
00799                 pass = pass && !fail;
00800                 cout << (fail ? "FAILED   " : "passed   ") << "Counter Mode IV generation" << endl;
00801         }
00802         {
00803                 const byte plain[] = {  // "7654321 Now is the time for "
00804                         0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, 
00805                         0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, 
00806                         0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20, 
00807                         0x66, 0x6f, 0x72, 0x20};
00808                 const byte mac1[] = {   // from FIPS 113
00809                         0xf1, 0xd3, 0x0f, 0x68, 0x49, 0x31, 0x2c, 0xa4};
00810                 const byte mac2[] = {   // generated with Crypto++
00811                         0x35, 0x80, 0xC5, 0xC4, 0x6B, 0x81, 0x24, 0xE2};
00812 
00813                 CBC_MAC<DES> cbcmac(key);
00814                 HashFilter cbcmacFilter(cbcmac);
00815                 fail = !TestFilter(cbcmacFilter, plain, sizeof(plain), mac1, sizeof(mac1));
00816                 pass = pass && !fail;
00817                 cout << (fail ? "FAILED   " : "passed   ") << "CBC MAC" << endl;
00818 
00819                 DMAC<DES> dmac(key);
00820                 HashFilter dmacFilter(dmac);
00821                 fail = !TestFilter(dmacFilter, plain, sizeof(plain), mac2, sizeof(mac2));
00822                 pass = pass && !fail;
00823                 cout << (fail ? "FAILED   " : "passed   ") << "DMAC" << endl;
00824         }
00825         {
00826                 CTR_Mode<AES>::Encryption modeE(plain, 16, plain);
00827                 CTR_Mode<AES>::Decryption modeD(plain, 16, plain);
00828                 fail = !TestModeIV(modeE, modeD);
00829                 pass = pass && !fail;
00830                 cout << (fail ? "FAILED   " : "passed   ") << "AES CTR Mode" << endl;
00831         }
00832         {
00833                 OFB_Mode<AES>::Encryption modeE(plain, 16, plain);
00834                 OFB_Mode<AES>::Decryption modeD(plain, 16, plain);
00835                 fail = !TestModeIV(modeE, modeD);
00836                 pass = pass && !fail;
00837                 cout << (fail ? "FAILED   " : "passed   ") << "AES OFB Mode" << endl;
00838         }
00839         {
00840                 CFB_Mode<AES>::Encryption modeE(plain, 16, plain);
00841                 CFB_Mode<AES>::Decryption modeD(plain, 16, plain);
00842                 fail = !TestModeIV(modeE, modeD);
00843                 pass = pass && !fail;
00844                 cout << (fail ? "FAILED   " : "passed   ") << "AES CFB Mode" << endl;
00845         }
00846         {
00847                 CBC_Mode<AES>::Encryption modeE(plain, 16, plain);
00848                 CBC_Mode<AES>::Decryption modeD(plain, 16, plain);
00849                 fail = !TestModeIV(modeE, modeD);
00850                 pass = pass && !fail;
00851                 cout << (fail ? "FAILED   " : "passed   ") << "AES CBC Mode" << endl;
00852         }
00853 
00854         return pass;
00855 }
00856 
00857 bool ValidateIDEA()
00858 {
00859         cout << "\nIDEA validation suite running...\n\n";
00860 
00861         FileSource valdata("TestData/ideaval.dat", true, new HexDecoder);
00862         return BlockTransformationTest(FixedRoundsCipherFactory<IDEAEncryption, IDEADecryption>(), valdata);
00863 }
00864 
00865 bool ValidateSAFER()
00866 {
00867         cout << "\nSAFER validation suite running...\n\n";
00868 
00869         FileSource valdata("TestData/saferval.dat", true, new HexDecoder);
00870         bool pass = true;
00871         pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_K_Encryption, SAFER_K_Decryption>(8,6), valdata, 4) && pass;
00872         pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_K_Encryption, SAFER_K_Decryption>(16,12), valdata, 4) && pass;
00873         pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_SK_Encryption, SAFER_SK_Decryption>(8,6), valdata, 4) && pass;
00874         pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_SK_Encryption, SAFER_SK_Decryption>(16,10), valdata, 4) && pass;
00875         return pass;
00876 }
00877 
00878 bool ValidateRC2()
00879 {
00880         cout << "\nRC2 validation suite running...\n\n";
00881 
00882         FileSource valdata("TestData/rc2val.dat", true, new HexDecoder);
00883         HexEncoder output(new FileSink(cout));
00884         SecByteBlock plain(RC2Encryption::BLOCKSIZE), cipher(RC2Encryption::BLOCKSIZE), out(RC2Encryption::BLOCKSIZE), outplain(RC2Encryption::BLOCKSIZE);
00885         SecByteBlock key(128);
00886         bool pass=true, fail;
00887 
00888         while (valdata.MaxRetrievable())
00889         {
00890                 byte keyLen, effectiveLen;
00891 
00892                 valdata.Get(keyLen);
00893                 valdata.Get(effectiveLen);
00894                 valdata.Get(key, keyLen);
00895                 valdata.Get(plain, RC2Encryption::BLOCKSIZE);
00896                 valdata.Get(cipher, RC2Encryption::BLOCKSIZE);
00897 
00898                 apbt transE(new RC2Encryption(key, keyLen, effectiveLen));
00899                 transE->ProcessBlock(plain, out);
00900                 fail = memcmp(out, cipher, RC2Encryption::BLOCKSIZE) != 0;
00901 
00902                 apbt transD(new RC2Decryption(key, keyLen, effectiveLen));
00903                 transD->ProcessBlock(out, outplain);
00904                 fail=fail || memcmp(outplain, plain, RC2Encryption::BLOCKSIZE);
00905 
00906                 pass = pass && !fail;
00907 
00908                 cout << (fail ? "FAILED   " : "passed   ");
00909                 output.Put(key, keyLen);
00910                 cout << "   ";
00911                 output.Put(outplain, RC2Encryption::BLOCKSIZE);
00912                 cout << "   ";
00913                 output.Put(out, RC2Encryption::BLOCKSIZE);
00914                 cout << endl;
00915         }
00916         return pass;
00917 }
00918 
00919 bool ValidateARC4()
00920 {
00921         unsigned char Key0[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef };
00922         unsigned char Input0[]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
00923         unsigned char Output0[] = {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96};
00924 
00925         unsigned char Key1[]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
00926         unsigned char Input1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
00927         unsigned char Output1[]={0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79};
00928 
00929         unsigned char Key2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
00930         unsigned char Input2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
00931         unsigned char Output2[]={0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a};
00932 
00933         unsigned char Key3[]={0xef,0x01,0x23,0x45};
00934         unsigned char Input3[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
00935         unsigned char Output3[]={0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61};
00936 
00937         unsigned char Key4[]={ 0x01,0x23,0x45,0x67,0x89,0xab, 0xcd,0xef };
00938         unsigned char Input4[] =
00939         {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00940         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00941         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00942         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00943         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00944         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00945         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00946         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00947         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00948         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00949         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00950         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00951         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00952         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00953         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00954         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00955         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00956         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00957         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00958         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00959         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00960         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00961         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00962         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00963         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00964         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00965         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00966         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00967         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00968         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00969         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00970         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00971         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00972         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00973         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00974         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00975         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00976         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00977         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00978         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00979         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00980         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00981         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00982         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00983         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00984         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00985         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00986         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00987         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00988         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00989         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
00990         0x01};
00991         unsigned char Output4[]= {
00992         0x75,0x95,0xc3,0xe6,0x11,0x4a,0x09,0x78,0x0c,0x4a,0xd4,
00993         0x52,0x33,0x8e,0x1f,0xfd,0x9a,0x1b,0xe9,0x49,0x8f,
00994         0x81,0x3d,0x76,0x53,0x34,0x49,0xb6,0x77,0x8d,0xca,
00995         0xd8,0xc7,0x8a,0x8d,0x2b,0xa9,0xac,0x66,0x08,0x5d,
00996         0x0e,0x53,0xd5,0x9c,0x26,0xc2,0xd1,0xc4,0x90,0xc1,
00997         0xeb,0xbe,0x0c,0xe6,0x6d,0x1b,0x6b,0x1b,0x13,0xb6,
00998         0xb9,0x19,0xb8,0x47,0xc2,0x5a,0x91,0x44,0x7a,0x95,
00999         0xe7,0x5e,0x4e,0xf1,0x67,0x79,0xcd,0xe8,0xbf,0x0a,
01000         0x95,0x85,0x0e,0x32,0xaf,0x96,0x89,0x44,0x4f,0xd3,
01001         0x77,0x10,0x8f,0x98,0xfd,0xcb,0xd4,0xe7,0x26,0x56,
01002         0x75,0x00,0x99,0x0b,0xcc,0x7e,0x0c,0xa3,0xc4,0xaa,
01003         0xa3,0x04,0xa3,0x87,0xd2,0x0f,0x3b,0x8f,0xbb,0xcd,
01004         0x42,0xa1,0xbd,0x31,0x1d,0x7a,0x43,0x03,0xdd,0xa5,
01005         0xab,0x07,0x88,0x96,0xae,0x80,0xc1,0x8b,0x0a,0xf6,
01006         0x6d,0xff,0x31,0x96,0x16,0xeb,0x78,0x4e,0x49,0x5a,
01007         0xd2,0xce,0x90,0xd7,0xf7,0x72,0xa8,0x17,0x47,0xb6,
01008         0x5f,0x62,0x09,0x3b,0x1e,0x0d,0xb9,0xe5,0xba,0x53,
01009         0x2f,0xaf,0xec,0x47,0x50,0x83,0x23,0xe6,0x71,0x32,
01010         0x7d,0xf9,0x44,0x44,0x32,0xcb,0x73,0x67,0xce,0xc8,
01011         0x2f,0x5d,0x44,0xc0,0xd0,0x0b,0x67,0xd6,0x50,0xa0,
01012         0x75,0xcd,0x4b,0x70,0xde,0xdd,0x77,0xeb,0x9b,0x10,
01013         0x23,0x1b,0x6b,0x5b,0x74,0x13,0x47,0x39,0x6d,0x62,
01014         0x89,0x74,0x21,0xd4,0x3d,0xf9,0xb4,0x2e,0x44,0x6e,
01015         0x35,0x8e,0x9c,0x11,0xa9,0xb2,0x18,0x4e,0xcb,0xef,
01016         0x0c,0xd8,0xe7,0xa8,0x77,0xef,0x96,0x8f,0x13,0x90,
01017         0xec,0x9b,0x3d,0x35,0xa5,0x58,0x5c,0xb0,0x09,0x29,
01018         0x0e,0x2f,0xcd,0xe7,0xb5,0xec,0x66,0xd9,0x08,0x4b,
01019         0xe4,0x40,0x55,0xa6,0x19,0xd9,0xdd,0x7f,0xc3,0x16,
01020         0x6f,0x94,0x87,0xf7,0xcb,0x27,0x29,0x12,0x42,0x64,
01021         0x45,0x99,0x85,0x14,0xc1,0x5d,0x53,0xa1,0x8c,0x86,
01022         0x4c,0xe3,0xa2,0xb7,0x55,0x57,0x93,0x98,0x81,0x26,
01023         0x52,0x0e,0xac,0xf2,0xe3,0x06,0x6e,0x23,0x0c,0x91,
01024         0xbe,0xe4,0xdd,0x53,0x04,0xf5,0xfd,0x04,0x05,0xb3,
01025         0x5b,0xd9,0x9c,0x73,0x13,0x5d,0x3d,0x9b,0xc3,0x35,
01026         0xee,0x04,0x9e,0xf6,0x9b,0x38,0x67,0xbf,0x2d,0x7b,
01027         0xd1,0xea,0xa5,0x95,0xd8,0xbf,0xc0,0x06,0x6f,0xf8,
01028         0xd3,0x15,0x09,0xeb,0x0c,0x6c,0xaa,0x00,0x6c,0x80,
01029         0x7a,0x62,0x3e,0xf8,0x4c,0x3d,0x33,0xc1,0x95,0xd2,
01030         0x3e,0xe3,0x20,0xc4,0x0d,0xe0,0x55,0x81,0x57,0xc8,
01031         0x22,0xd4,0xb8,0xc5,0x69,0xd8,0x49,0xae,0xd5,0x9d,
01032         0x4e,0x0f,0xd7,0xf3,0x79,0x58,0x6b,0x4b,0x7f,0xf6,
01033         0x84,0xed,0x6a,0x18,0x9f,0x74,0x86,0xd4,0x9b,0x9c,
01034         0x4b,0xad,0x9b,0xa2,0x4b,0x96,0xab,0xf9,0x24,0x37,
01035         0x2c,0x8a,0x8f,0xff,0xb1,0x0d,0x55,0x35,0x49,0x00,
01036         0xa7,0x7a,0x3d,0xb5,0xf2,0x05,0xe1,0xb9,0x9f,0xcd,
01037         0x86,0x60,0x86,0x3a,0x15,0x9a,0xd4,0xab,0xe4,0x0f,
01038         0xa4,0x89,0x34,0x16,0x3d,0xdd,0xe5,0x42,0xa6,0x58,
01039         0x55,0x40,0xfd,0x68,0x3c,0xbf,0xd8,0xc0,0x0f,0x12,
01040         0x12,0x9a,0x28,0x4d,0xea,0xcc,0x4c,0xde,0xfe,0x58,
01041         0xbe,0x71,0x37,0x54,0x1c,0x04,0x71,0x26,0xc8,0xd4,
01042         0x9e,0x27,0x55,0xab,0x18,0x1a,0xb7,0xe9,0x40,0xb0,
01043         0xc0};
01044 
01045         // VC60 workaround: auto_ptr lacks reset()
01046         member_ptr<Weak::ARC4> arc4;
01047         bool pass=true, fail;
01048         int i;
01049 
01050         cout << "\nARC4 validation suite running...\n\n";
01051 
01052         arc4.reset(new Weak::ARC4(Key0, sizeof(Key0)));
01053         arc4->ProcessString(Input0, sizeof(Input0));
01054         fail = memcmp(Input0, Output0, sizeof(Input0)) != 0;
01055         cout << (fail ? "FAILED" : "passed") << "    Test 0" << endl;
01056         pass = pass && !fail;
01057 
01058         arc4.reset(new Weak::ARC4(Key1, sizeof(Key1)));
01059         arc4->ProcessString(Key1, Input1, sizeof(Key1));
01060         fail = memcmp(Output1, Key1, sizeof(Key1)) != 0;
01061         cout << (fail ? "FAILED" : "passed") << "    Test 1" << endl;
01062         pass = pass && !fail;
01063 
01064         arc4.reset(new Weak::ARC4(Key2, sizeof(Key2)));
01065         for (i=0, fail=false; i<sizeof(Input2); i++)
01066                 if (arc4->ProcessByte(Input2[i]) != Output2[i])
01067                         fail = true;
01068         cout << (fail ? "FAILED" : "passed") << "    Test 2" << endl;
01069         pass = pass && !fail;
01070 
01071         arc4.reset(new Weak::ARC4(Key3, sizeof(Key3)));
01072         for (i=0, fail=false; i<sizeof(Input3); i++)
01073                 if (arc4->ProcessByte(Input3[i]) != Output3[i])
01074                         fail = true;
01075         cout << (fail ? "FAILED" : "passed") << "    Test 3" << endl;
01076         pass = pass && !fail;
01077 
01078         arc4.reset(new Weak::ARC4(Key4, sizeof(Key4)));
01079         for (i=0, fail=false; i<sizeof(Input4); i++)
01080                 if (arc4->ProcessByte(Input4[i]) != Output4[i])
01081                         fail = true;
01082         cout << (fail ? "FAILED" : "passed") << "    Test 4" << endl;
01083         pass = pass && !fail;
01084 
01085         return pass;
01086 }
01087 
01088 bool ValidateRC5()
01089 {
01090         cout << "\nRC5 validation suite running...\n\n";
01091 
01092         FileSource valdata("TestData/rc5val.dat", true, new HexDecoder);
01093         return BlockTransformationTest(VariableRoundsCipherFactory<RC5Encryption, RC5Decryption>(16, 12), valdata);
01094 }
01095 
01096 bool ValidateRC6()
01097 {
01098         cout << "\nRC6 validation suite running...\n\n";
01099 
01100         FileSource valdata("TestData/rc6val.dat", true, new HexDecoder);
01101         bool pass = true;
01102         pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(16), valdata, 2) && pass;
01103         pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(24), valdata, 2) && pass;
01104         pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(32), valdata, 2) && pass;
01105         return pass;
01106 }
01107 
01108 bool ValidateMARS()
01109 {
01110         cout << "\nMARS validation suite running...\n\n";
01111 
01112         FileSource valdata("TestData/marsval.dat", true, new HexDecoder);
01113         bool pass = true;
01114         pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(16), valdata, 4) && pass;
01115         pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(24), valdata, 3) && pass;
01116         pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(32), valdata, 2) && pass;
01117         return pass;
01118 }
01119 
01120 bool ValidateRijndael()
01121 {
01122         cout << "\nRijndael (AES) validation suite running...\n\n";
01123 
01124         FileSource valdata("TestData/rijndael.dat", true, new HexDecoder);
01125         bool pass = true;
01126         pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(16), valdata, 4) && pass;
01127         pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(24), valdata, 3) && pass;
01128         pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(32), valdata, 2) && pass;
01129         pass = RunTestDataFile("TestVectors/aes.txt") && pass;
01130         return pass;
01131 }
01132 
01133 bool ValidateTwofish()
01134 {
01135         cout << "\nTwofish validation suite running...\n\n";
01136 
01137         FileSource valdata("TestData/twofishv.dat", true, new HexDecoder);
01138         bool pass = true;
01139         pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(16), valdata, 4) && pass;
01140         pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(24), valdata, 3) && pass;
01141         pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(32), valdata, 2) && pass;
01142         return pass;
01143 }
01144 
01145 bool ValidateSerpent()
01146 {
01147         cout << "\nSerpent validation suite running...\n\n";
01148 
01149         FileSource valdata("TestData/serpentv.dat", true, new HexDecoder);
01150         bool pass = true;
01151         pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(16), valdata, 4) && pass;
01152         pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(24), valdata, 3) && pass;
01153         pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(32), valdata, 2) && pass;
01154         return pass;
01155 }
01156 
01157 bool ValidateBlowfish()
01158 {
01159         cout << "\nBlowfish validation suite running...\n\n";
01160 
01161         HexEncoder output(new FileSink(cout));
01162         const char *key[]={"abcdefghijklmnopqrstuvwxyz", "Who is John Galt?"};
01163         byte *plain[]={(byte *)"BLOWFISH", (byte *)"\xfe\xdc\xba\x98\x76\x54\x32\x10"};
01164         byte *cipher[]={(byte *)"\x32\x4e\xd0\xfe\xf4\x13\xa2\x03", (byte *)"\xcc\x91\x73\x2b\x80\x22\xf6\x84"};
01165         byte out[8], outplain[8];
01166         bool pass=true, fail;
01167 
01168         for (int i=0; i<2; i++)
01169         {
01170                 ECB_Mode<Blowfish>::Encryption enc((byte *)key[i], strlen(key[i]));
01171                 enc.ProcessData(out, plain[i], 8);
01172                 fail = memcmp(out, cipher[i], 8) != 0;
01173 
01174                 ECB_Mode<Blowfish>::Decryption dec((byte *)key[i], strlen(key[i]));
01175                 dec.ProcessData(outplain, cipher[i], 8);
01176                 fail = fail || memcmp(outplain, plain[i], 8);
01177                 pass = pass && !fail;
01178 
01179                 cout << (fail ? "FAILED    " : "passed    ");
01180                 cout << '\"' << key[i] << '\"';
01181                 for (int j=0; j<(signed int)(30-strlen(key[i])); j++)
01182                         cout << ' ';
01183                 output.Put(outplain, 8);
01184                 cout << "  ";
01185                 output.Put(out, 8);
01186                 cout << endl;
01187         }
01188         return pass;
01189 }
01190 
01191 bool ValidateThreeWay()
01192 {
01193         cout << "\n3-WAY validation suite running...\n\n";
01194 
01195         FileSource valdata("TestData/3wayval.dat", true, new HexDecoder);
01196         return BlockTransformationTest(FixedRoundsCipherFactory<ThreeWayEncryption, ThreeWayDecryption>(), valdata);
01197 }
01198 
01199 bool ValidateGOST()
01200 {
01201         cout << "\nGOST validation suite running...\n\n";
01202 
01203         FileSource valdata("TestData/gostval.dat", true, new HexDecoder);
01204         return BlockTransformationTest(FixedRoundsCipherFactory<GOSTEncryption, GOSTDecryption>(), valdata);
01205 }
01206 
01207 bool ValidateSHARK()
01208 {
01209         cout << "\nSHARK validation suite running...\n\n";
01210 
01211         FileSource valdata("TestData/sharkval.dat", true, new HexDecoder);
01212         return BlockTransformationTest(FixedRoundsCipherFactory<SHARKEncryption, SHARKDecryption>(), valdata);
01213 }
01214 
01215 bool ValidateCAST()
01216 {
01217         bool pass = true;
01218 
01219         cout << "\nCAST-128 validation suite running...\n\n";
01220 
01221         FileSource val128("TestData/cast128v.dat", true, new HexDecoder);
01222         pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(16), val128, 1) && pass;
01223         pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(10), val128, 1) && pass;
01224         pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(5), val128, 1) && pass;
01225 
01226         cout << "\nCAST-256 validation suite running...\n\n";
01227 
01228         FileSource val256("TestData/cast256v.dat", true, new HexDecoder);
01229         pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(16), val256, 1) && pass;
01230         pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(24), val256, 1) && pass;
01231         pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(32), val256, 1) && pass;
01232 
01233         return pass;
01234 }
01235 
01236 bool ValidateSquare()
01237 {
01238         cout << "\nSquare validation suite running...\n\n";
01239 
01240         FileSource valdata("TestData/squareva.dat", true, new HexDecoder);
01241         return BlockTransformationTest(FixedRoundsCipherFactory<SquareEncryption, SquareDecryption>(), valdata);
01242 }
01243 
01244 bool ValidateSKIPJACK()
01245 {
01246         cout << "\nSKIPJACK validation suite running...\n\n";
01247 
01248         FileSource valdata("TestData/skipjack.dat", true, new HexDecoder);
01249         return BlockTransformationTest(FixedRoundsCipherFactory<SKIPJACKEncryption, SKIPJACKDecryption>(), valdata);
01250 }
01251 
01252 bool ValidateSEAL()
01253 {
01254         byte input[] = {0x37,0xa0,0x05,0x95,0x9b,0x84,0xc4,0x9c,0xa4,0xbe,0x1e,0x05,0x06,0x73,0x53,0x0f,0x5f,0xb0,0x97,0xfd,0xf6,0xa1,0x3f,0xbd,0x6c,0x2c,0xde,0xcd,0x81,0xfd,0xee,0x7c};
01255         byte output[32];
01256         byte key[] = {0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0};
01257         byte iv[] = {0x01, 0x35, 0x77, 0xaf};
01258 
01259         cout << "\nSEAL validation suite running...\n\n";
01260 
01261         SEAL<>::Encryption seal(key, sizeof(key), iv);
01262         unsigned int size = sizeof(input);
01263         bool pass = true;
01264 
01265         memset(output, 1, size);
01266         seal.ProcessString(output, input, size);
01267         for (unsigned int i=0; i<size; i++)
01268                 if (output[i] != 0)
01269                         pass = false;
01270 
01271         seal.Seek(1);
01272         output[1] = seal.ProcessByte(output[1]);
01273         seal.ProcessString(output+2, size-2);
01274         pass = pass && memcmp(output+1, input+1, size-1) == 0;
01275 
01276         cout << (pass ? "passed" : "FAILED") << endl;
01277         return pass;
01278 }
01279 
01280 bool ValidateBaseCode()
01281 {
01282         bool pass = true, fail;
01283         byte data[255];
01284         for (unsigned int i=0; i<255; i++)
01285                 data[i] = i;
01286         const char *hexEncoded = 
01287 "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627"
01288 "28292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F"
01289 "505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071727374757677"
01290 "78797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"
01291 "A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7"
01292 "C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF"
01293 "F0F1F2F3F4F5F6F7F8F9FAFBFCFDFE";
01294         const char *base32Encoded = 
01295 "AAASEA2EAWDAQCAJBIFS2DIQB6IBCESVCSKTNF22DEPBYHA7D2RUAIJCENUCKJTHFAWUWK3NFWZC8NBT"
01296 "GI3VIPJYG66DUQT5HS8V6R4AIFBEGTCFI3DWSUKKJPGE4VURKBIXEW4WKXMFQYC3MJPX2ZK8M7SGC2VD"
01297 "NTUYN35IPFXGY5DPP3ZZA6MUQP4HK7VZRB6ZW856RX9H9AEBSKB2JBNGS8EIVCWMTUG27D6SUGJJHFEX"
01298 "U4M3TGN4VQQJ5HW9WCS4FI7EWYVKRKFJXKX43MPQX82MDNXVYU45PP72ZG7MZRF7Z496BSQC2RCNMTYH"
01299 "3DE6XU8N3ZHN9WGT4MJ7JXQY49NPVYY55VQ77Z9A6HTQH3HF65V8T4RK7RYQ55ZR8D29F69W8Z5RR8H3"
01300 "9M7939R8";
01301         const char *base64AndHexEncoded = 
01302 "41414543417751464267634943516F4C4441304F4478415245684D554652595847426B6147787764"
01303 "486838674953496A4A43556D4A7967704B6973734C5334764D4445794D7A51310A4E6A63344F546F"
01304 "375044302B50304242516B4E4552555A4853456C4B5330784E546B395155564A5456465657563168"
01305 "5A576C746358563566594746695932526C5A6D646F615770720A6247317562334278636E4E306458"
01306 "5A3365486C3665337839666E2B4167594B44684957476834694A696F754D6A5936506B4A47536B35"
01307 "53566C7065596D5A71626E4A32656E3643680A6F714F6B7061616E714B6D717136797472712B7773"
01308 "624B7A744C573274376935757275387662362F774D484377385446787366497963724C7A4D334F7A"
01309 "39445230745055316462580A324E6E6132397A6433742F6734654C6A354F586D352B6A7036757673"
01310 "3765377638504879382F5431397666342B6672372F50332B0A";
01311 
01312         cout << "\nBase64, base32 and hex coding validation suite running...\n\n";
01313 
01314         fail = !TestFilter(HexEncoder().Ref(), data, 255, (const byte *)hexEncoded, strlen(hexEncoded));
01315         cout << (fail ? "FAILED    " : "passed    ");
01316         cout << "Hex Encoding\n";
01317         pass = pass && !fail;
01318 
01319         fail = !TestFilter(HexDecoder().Ref(), (const byte *)hexEncoded, strlen(hexEncoded), data, 255);
01320         cout << (fail ? "FAILED    " : "passed    ");
01321         cout << "Hex Decoding\n";
01322         pass = pass && !fail;
01323 
01324         fail = !TestFilter(Base32Encoder().Ref(), data, 255, (const byte *)base32Encoded, strlen(base32Encoded));
01325         cout << (fail ? "FAILED    " : "passed    ");
01326         cout << "Base32 Encoding\n";
01327         pass = pass && !fail;
01328 
01329         fail = !TestFilter(Base32Decoder().Ref(), (const byte *)base32Encoded, strlen(base32Encoded), data, 255);
01330         cout << (fail ? "FAILED    " : "passed    ");
01331         cout << "Base32 Decoding\n";
01332         pass = pass && !fail;
01333 
01334         fail = !TestFilter(Base64Encoder(new HexEncoder).Ref(), data, 255, (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded));
01335         cout << (fail ? "FAILED    " : "passed    ");
01336         cout << "Base64 Encoding\n";
01337         pass = pass && !fail;
01338 
01339         fail = !TestFilter(HexDecoder(new Base64Decoder).Ref(), (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded), data, 255);
01340         cout << (fail ? "FAILED    " : "passed    ");
01341         cout << "Base64 Decoding\n";
01342         pass = pass && !fail;
01343 
01344         return pass;
01345 }
01346 
01347 bool ValidateSHACAL2()
01348 {
01349         cout << "\nSHACAL-2 validation suite running...\n\n";
01350 
01351         bool pass = true;
01352         FileSource valdata("TestData/shacal2v.dat", true, new HexDecoder);
01353         pass = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(16), valdata, 4) && pass;
01354         pass = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(64), valdata, 10) && pass;
01355         return pass;
01356 }
01357 
01358 bool ValidateCamellia()
01359 {
01360         cout << "\nCamellia validation suite running...\n\n";
01361 
01362         bool pass = true;
01363         FileSource valdata("TestData/camellia.dat", true, new HexDecoder);
01364         pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(16), valdata, 15) && pass;
01365         pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(24), valdata, 15) && pass;
01366         pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(32), valdata, 15) && pass;
01367         return pass;
01368 }
01369 
01370 bool ValidateSalsa()
01371 {
01372         cout << "\nSalsa validation suite running...\n";
01373 
01374         return RunTestDataFile("TestVectors/salsa.txt");
01375 }
01376 
01377 bool ValidateSosemanuk()
01378 {
01379         cout << "\nSosemanuk validation suite running...\n";
01380         return RunTestDataFile("TestVectors/sosemanuk.txt");
01381 }
01382 
01383 bool ValidateVMAC()
01384 {
01385         cout << "\nVMAC validation suite running...\n";
01386         return RunTestDataFile("TestVectors/vmac.txt");
01387 }
01388 
01389 bool ValidateCCM()
01390 {
01391         cout << "\nAES/CCM validation suite running...\n";
01392         return RunTestDataFile("TestVectors/ccm.txt");
01393 }
01394 
01395 bool ValidateGCM()
01396 {
01397         cout << "\nAES/GCM validation suite running...\n";
01398         cout << "\n2K tables:";
01399         bool pass = RunTestDataFile("TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)2048));
01400         cout << "\n64K tables:";
01401         return RunTestDataFile("TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)64*1024)) && pass;
01402 }
01403 
01404 bool ValidateCMAC()
01405 {
01406         cout << "\nCMAC validation suite running...\n";
01407         return RunTestDataFile("TestVectors/cmac.txt");
01408 }

Generated on Mon Aug 9 2010 15:56:38 for Crypto++ by  doxygen 1.7.1