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