Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1408 lines
48 KiB

  1. // validat1.cpp - written and placed in the public domain by Wei Dai
  2. #include "pch.h"
  3. #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
  4. #include "files.h"
  5. #include "hex.h"
  6. #include "base32.h"
  7. #include "base64.h"
  8. #include "modes.h"
  9. #include "cbcmac.h"
  10. #include "dmac.h"
  11. #include "idea.h"
  12. #include "des.h"
  13. #include "rc2.h"
  14. #include "arc4.h"
  15. #include "rc5.h"
  16. #include "blowfish.h"
  17. #include "3way.h"
  18. #include "safer.h"
  19. #include "gost.h"
  20. #include "shark.h"
  21. #include "cast.h"
  22. #include "square.h"
  23. #include "seal.h"
  24. #include "rc6.h"
  25. #include "mars.h"
  26. #include "rijndael.h"
  27. #include "twofish.h"
  28. #include "serpent.h"
  29. #include "skipjack.h"
  30. #include "shacal2.h"
  31. #include "camellia.h"
  32. #include "osrng.h"
  33. #include "zdeflate.h"
  34. #include "cpu.h"
  35. #include <time.h>
  36. #include <memory>
  37. #include <iostream>
  38. #include <iomanip>
  39. #include "validate.h"
  40. USING_NAMESPACE(CryptoPP)
  41. USING_NAMESPACE(std)
  42. bool ValidateAll(bool thorough)
  43. {
  44. bool pass=TestSettings();
  45. pass=TestOS_RNG() && pass;
  46. pass=ValidateCRC32() && pass;
  47. pass=ValidateAdler32() && pass;
  48. pass=ValidateMD2() && pass;
  49. pass=ValidateMD5() && pass;
  50. pass=ValidateSHA() && pass;
  51. pass=ValidateTiger() && pass;
  52. pass=ValidateRIPEMD() && pass;
  53. pass=ValidatePanama() && pass;
  54. pass=ValidateWhirlpool() && pass;
  55. pass=ValidateHMAC() && pass;
  56. pass=ValidateTTMAC() && pass;
  57. pass=ValidatePBKDF() && pass;
  58. pass=ValidateDES() && pass;
  59. pass=ValidateCipherModes() && pass;
  60. pass=ValidateIDEA() && pass;
  61. pass=ValidateSAFER() && pass;
  62. pass=ValidateRC2() && pass;
  63. pass=ValidateARC4() && pass;
  64. pass=ValidateRC5() && pass;
  65. pass=ValidateBlowfish() && pass;
  66. pass=ValidateThreeWay() && pass;
  67. pass=ValidateGOST() && pass;
  68. pass=ValidateSHARK() && pass;
  69. pass=ValidateCAST() && pass;
  70. pass=ValidateSquare() && pass;
  71. pass=ValidateSKIPJACK() && pass;
  72. pass=ValidateSEAL() && pass;
  73. pass=ValidateRC6() && pass;
  74. pass=ValidateMARS() && pass;
  75. pass=ValidateRijndael() && pass;
  76. pass=ValidateTwofish() && pass;
  77. pass=ValidateSerpent() && pass;
  78. pass=ValidateSHACAL2() && pass;
  79. pass=ValidateCamellia() && pass;
  80. pass=ValidateSalsa() && pass;
  81. pass=ValidateSosemanuk() && pass;
  82. pass=ValidateVMAC() && pass;
  83. pass=ValidateCCM() && pass;
  84. pass=ValidateGCM() && pass;
  85. pass=ValidateCMAC() && pass;
  86. pass=RunTestDataFile("TestVectors/eax.txt") && pass;
  87. pass=RunTestDataFile("TestVectors/seed.txt") && pass;
  88. pass=ValidateBBS() && pass;
  89. pass=ValidateDH() && pass;
  90. pass=ValidateMQV() && pass;
  91. pass=ValidateRSA() && pass;
  92. pass=ValidateElGamal() && pass;
  93. pass=ValidateDLIES() && pass;
  94. pass=ValidateNR() && pass;
  95. pass=ValidateDSA(thorough) && pass;
  96. pass=ValidateLUC() && pass;
  97. pass=ValidateLUC_DH() && pass;
  98. pass=ValidateLUC_DL() && pass;
  99. pass=ValidateXTR_DH() && pass;
  100. pass=ValidateRabin() && pass;
  101. pass=ValidateRW() && pass;
  102. // pass=ValidateBlumGoldwasser() && pass;
  103. pass=ValidateECP() && pass;
  104. pass=ValidateEC2N() && pass;
  105. pass=ValidateECDSA() && pass;
  106. pass=ValidateESIGN() && pass;
  107. if (pass)
  108. cout << "\nAll tests passed!\n";
  109. else
  110. cout << "\nOops! Not all tests passed.\n";
  111. return pass;
  112. }
  113. bool TestSettings()
  114. {
  115. bool pass = true;
  116. cout << "\nTesting Settings...\n\n";
  117. word32 w;
  118. memcpy_s(&w, sizeof(w), "\x01\x02\x03\x04", 4);
  119. if (w == 0x04030201L)
  120. {
  121. #ifdef IS_LITTLE_ENDIAN
  122. cout << "passed: ";
  123. #else
  124. cout << "FAILED: ";
  125. pass = false;
  126. #endif
  127. cout << "Your machine is little endian.\n";
  128. }
  129. else if (w == 0x01020304L)
  130. {
  131. #ifndef IS_LITTLE_ENDIAN
  132. cout << "passed: ";
  133. #else
  134. cout << "FAILED: ";
  135. pass = false;
  136. #endif
  137. cout << "Your machine is big endian.\n";
  138. }
  139. else
  140. {
  141. cout << "FAILED: Your machine is neither big endian nor little endian.\n";
  142. pass = false;
  143. }
  144. #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
  145. byte testvals[10] = {1,2,2,3,3,3,3,2,2,1};
  146. if (*(word32 *)(testvals+3) == 0x03030303 && *(word64 *)(testvals+1) == W64LIT(0x0202030303030202))
  147. cout << "passed: Your machine allows unaligned data access.\n";
  148. else
  149. {
  150. cout << "FAILED: Unaligned data access gave incorrect results.\n";
  151. pass = false;
  152. }
  153. #else
  154. cout << "passed: CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is not defined. Will restrict to aligned data access.\n";
  155. #endif
  156. if (sizeof(byte) == 1)
  157. cout << "passed: ";
  158. else
  159. {
  160. cout << "FAILED: ";
  161. pass = false;
  162. }
  163. cout << "sizeof(byte) == " << sizeof(byte) << endl;
  164. if (sizeof(word16) == 2)
  165. cout << "passed: ";
  166. else
  167. {
  168. cout << "FAILED: ";
  169. pass = false;
  170. }
  171. cout << "sizeof(word16) == " << sizeof(word16) << endl;
  172. if (sizeof(word32) == 4)
  173. cout << "passed: ";
  174. else
  175. {
  176. cout << "FAILED: ";
  177. pass = false;
  178. }
  179. cout << "sizeof(word32) == " << sizeof(word32) << endl;
  180. if (sizeof(word64) == 8)
  181. cout << "passed: ";
  182. else
  183. {
  184. cout << "FAILED: ";
  185. pass = false;
  186. }
  187. cout << "sizeof(word64) == " << sizeof(word64) << endl;
  188. #ifdef CRYPTOPP_WORD128_AVAILABLE
  189. if (sizeof(word128) == 16)
  190. cout << "passed: ";
  191. else
  192. {
  193. cout << "FAILED: ";
  194. pass = false;
  195. }
  196. cout << "sizeof(word128) == " << sizeof(word128) << endl;
  197. #endif
  198. if (sizeof(word) == 2*sizeof(hword)
  199. #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
  200. && sizeof(dword) == 2*sizeof(word)
  201. #endif
  202. )
  203. cout << "passed: ";
  204. else
  205. {
  206. cout << "FAILED: ";
  207. pass = false;
  208. }
  209. cout << "sizeof(hword) == " << sizeof(hword) << ", sizeof(word) == " << sizeof(word);
  210. #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
  211. cout << ", sizeof(dword) == " << sizeof(dword);
  212. #endif
  213. cout << endl;
  214. #ifdef CRYPTOPP_CPUID_AVAILABLE
  215. bool hasMMX = HasMMX();
  216. bool hasISSE = HasISSE();
  217. bool hasSSE2 = HasSSE2();
  218. bool hasSSSE3 = HasSSSE3();
  219. bool isP4 = IsP4();
  220. int cacheLineSize = GetCacheLineSize();
  221. if ((isP4 && (!hasMMX || !hasSSE2)) || (hasSSE2 && !hasMMX) || (cacheLineSize < 16 || cacheLineSize > 256 || !IsPowerOf2(cacheLineSize)))
  222. {
  223. cout << "FAILED: ";
  224. pass = false;
  225. }
  226. else
  227. cout << "passed: ";
  228. cout << "hasMMX == " << hasMMX << ", hasISSE == " << hasISSE << ", hasSSE2 == " << hasSSE2 << ", hasSSSE3 == " << hasSSSE3 << ", hasAESNI == " << HasAESNI() << ", hasCLMUL == " << HasCLMUL() << ", isP4 == " << isP4 << ", cacheLineSize == " << cacheLineSize;
  229. cout << ", AESNI_INTRINSICS == " << CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE << endl;
  230. #endif
  231. if (!pass)
  232. {
  233. cout << "Some critical setting in config.h is in error. Please fix it and recompile." << endl;
  234. abort();
  235. }
  236. return pass;
  237. }
  238. bool TestOS_RNG()
  239. {
  240. bool pass = true;
  241. member_ptr<RandomNumberGenerator> rng;
  242. #ifdef BLOCKING_RNG_AVAILABLE
  243. try {rng.reset(new BlockingRng);}
  244. catch (OS_RNG_Err &) {}
  245. #endif
  246. if (rng.get())
  247. {
  248. cout << "\nTesting operating system provided blocking random number generator...\n\n";
  249. ArraySink *sink;
  250. RandomNumberSource test(*rng, UINT_MAX, false, new Deflator(sink=new ArraySink(NULL,0)));
  251. unsigned long total=0, length=0;
  252. time_t t = time(NULL), t1 = 0;
  253. // check that it doesn't take too long to generate a reasonable amount of randomness
  254. while (total < 16 && (t1 < 10 || total*8 > (unsigned long)t1))
  255. {
  256. test.Pump(1);
  257. total += 1;
  258. t1 = time(NULL) - t;
  259. }
  260. if (total < 16)
  261. {
  262. cout << "FAILED:";
  263. pass = false;
  264. }
  265. else
  266. cout << "passed:";
  267. cout << " it took " << long(t1) << " seconds to generate " << total << " bytes" << endl;
  268. #if 0 // disable this part. it's causing an unpredictable pause during the validation testing
  269. if (t1 < 2)
  270. {
  271. // that was fast, are we really blocking?
  272. // first exhaust the extropy reserve
  273. t = time(NULL);
  274. while (time(NULL) - t < 2)
  275. {
  276. test.Pump(1);
  277. total += 1;
  278. }
  279. // if it generates too many bytes in a certain amount of time,
  280. // something's probably wrong
  281. t = time(NULL);
  282. while (time(NULL) - t < 2)
  283. {
  284. test.Pump(1);
  285. total += 1;
  286. length += 1;
  287. }
  288. if (length > 1024)
  289. {
  290. cout << "FAILED:";
  291. pass = false;
  292. }
  293. else
  294. cout << "passed:";
  295. cout << " it generated " << length << " bytes in " << long(time(NULL) - t) << " seconds" << endl;
  296. }
  297. #endif
  298. test.AttachedTransformation()->MessageEnd();
  299. if (sink->TotalPutLength() < total)
  300. {
  301. cout << "FAILED:";
  302. pass = false;
  303. }
  304. else
  305. cout << "passed:";
  306. cout << " " << total << " generated bytes compressed to " << (size_t)sink->TotalPutLength() << " bytes by DEFLATE" << endl;
  307. }
  308. else
  309. cout << "\nNo operating system provided blocking random number generator, skipping test." << endl;
  310. rng.reset(NULL);
  311. #ifdef NONBLOCKING_RNG_AVAILABLE
  312. try {rng.reset(new NonblockingRng);}
  313. catch (OS_RNG_Err &) {}
  314. #endif
  315. if (rng.get())
  316. {
  317. cout << "\nTesting operating system provided nonblocking random number generator...\n\n";
  318. ArraySink *sink;
  319. RandomNumberSource test(*rng, 100000, true, new Deflator(sink=new ArraySink(NULL, 0)));
  320. if (sink->TotalPutLength() < 100000)
  321. {
  322. cout << "FAILED:";
  323. pass = false;
  324. }
  325. else
  326. cout << "passed:";
  327. cout << " 100000 generated bytes compressed to " << (size_t)sink->TotalPutLength() << " bytes by DEFLATE" << endl;
  328. }
  329. else
  330. cout << "\nNo operating system provided nonblocking random number generator, skipping test." << endl;
  331. return pass;
  332. }
  333. // VC50 workaround
  334. typedef auto_ptr<BlockTransformation> apbt;
  335. class CipherFactory
  336. {
  337. public:
  338. virtual unsigned int BlockSize() const =0;
  339. virtual unsigned int KeyLength() const =0;
  340. virtual apbt NewEncryption(const byte *key) const =0;
  341. virtual apbt NewDecryption(const byte *key) const =0;
  342. };
  343. template <class E, class D> class FixedRoundsCipherFactory : public CipherFactory
  344. {
  345. public:
  346. FixedRoundsCipherFactory(unsigned int keylen=0) : m_keylen(keylen?keylen:E::DEFAULT_KEYLENGTH) {}
  347. unsigned int BlockSize() const {return E::BLOCKSIZE;}
  348. unsigned int KeyLength() const {return m_keylen;}
  349. apbt NewEncryption(const byte *key) const
  350. {return apbt(new E(key, m_keylen));}
  351. apbt NewDecryption(const byte *key) const
  352. {return apbt(new D(key, m_keylen));}
  353. unsigned int m_keylen;
  354. };
  355. template <class E, class D> class VariableRoundsCipherFactory : public CipherFactory
  356. {
  357. public:
  358. VariableRoundsCipherFactory(unsigned int keylen=0, unsigned int rounds=0)
  359. : m_keylen(keylen ? keylen : E::DEFAULT_KEYLENGTH), m_rounds(rounds ? rounds : E::DEFAULT_ROUNDS) {}
  360. unsigned int BlockSize() const {return E::BLOCKSIZE;}
  361. unsigned int KeyLength() const {return m_keylen;}
  362. apbt NewEncryption(const byte *key) const
  363. {return apbt(new E(key, m_keylen, m_rounds));}
  364. apbt NewDecryption(const byte *key) const
  365. {return apbt(new D(key, m_keylen, m_rounds));}
  366. unsigned int m_keylen, m_rounds;
  367. };
  368. bool BlockTransformationTest(const CipherFactory &cg, BufferedTransformation &valdata, unsigned int tuples = 0xffff)
  369. {
  370. HexEncoder output(new FileSink(cout));
  371. SecByteBlock plain(cg.BlockSize()), cipher(cg.BlockSize()), out(cg.BlockSize()), outplain(cg.BlockSize());
  372. SecByteBlock key(cg.KeyLength());
  373. bool pass=true, fail;
  374. while (valdata.MaxRetrievable() && tuples--)
  375. {
  376. valdata.Get(key, cg.KeyLength());
  377. valdata.Get(plain, cg.BlockSize());
  378. valdata.Get(cipher, cg.BlockSize());
  379. apbt transE = cg.NewEncryption(key);
  380. transE->ProcessBlock(plain, out);
  381. fail = memcmp(out, cipher, cg.BlockSize()) != 0;
  382. apbt transD = cg.NewDecryption(key);
  383. transD->ProcessBlock(out, outplain);
  384. fail=fail || memcmp(outplain, plain, cg.BlockSize());
  385. pass = pass && !fail;
  386. cout << (fail ? "FAILED " : "passed ");
  387. output.Put(key, cg.KeyLength());
  388. cout << " ";
  389. output.Put(outplain, cg.BlockSize());
  390. cout << " ";
  391. output.Put(out, cg.BlockSize());
  392. cout << endl;
  393. }
  394. return pass;
  395. }
  396. class FilterTester : public Unflushable<Sink>
  397. {
  398. public:
  399. FilterTester(const byte *validOutput, size_t outputLen)
  400. : validOutput(validOutput), outputLen(outputLen), counter(0), fail(false) {}
  401. void PutByte(byte inByte)
  402. {
  403. if (counter >= outputLen || validOutput[counter] != inByte)
  404. {
  405. std::cerr << "incorrect output " << counter << ", " << (word16)validOutput[counter] << ", " << (word16)inByte << "\n";
  406. fail = true;
  407. assert(false);
  408. }
  409. counter++;
  410. }
  411. size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
  412. {
  413. while (length--)
  414. FilterTester::PutByte(*inString++);
  415. if (messageEnd)
  416. if (counter != outputLen)
  417. {
  418. fail = true;
  419. assert(false);
  420. }
  421. return 0;
  422. }
  423. bool GetResult()
  424. {
  425. return !fail;
  426. }
  427. const byte *validOutput;
  428. size_t outputLen, counter;
  429. bool fail;
  430. };
  431. bool TestFilter(BufferedTransformation &bt, const byte *in, size_t inLen, const byte *out, size_t outLen)
  432. {
  433. FilterTester *ft;
  434. bt.Attach(ft = new FilterTester(out, outLen));
  435. while (inLen)
  436. {
  437. size_t randomLen = GlobalRNG().GenerateWord32(0, (word32)inLen);
  438. bt.Put(in, randomLen);
  439. in += randomLen;
  440. inLen -= randomLen;
  441. }
  442. bt.MessageEnd();
  443. return ft->GetResult();
  444. }
  445. bool ValidateDES()
  446. {
  447. cout << "\nDES validation suite running...\n\n";
  448. FileSource valdata("TestData/descert.dat", true, new HexDecoder);
  449. bool pass = BlockTransformationTest(FixedRoundsCipherFactory<DESEncryption, DESDecryption>(), valdata);
  450. cout << "\nTesting EDE2, EDE3, and XEX3 variants...\n\n";
  451. FileSource valdata1("TestData/3desval.dat", true, new HexDecoder);
  452. pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_EDE2_Encryption, DES_EDE2_Decryption>(), valdata1, 1) && pass;
  453. pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_EDE3_Encryption, DES_EDE3_Decryption>(), valdata1, 1) && pass;
  454. pass = BlockTransformationTest(FixedRoundsCipherFactory<DES_XEX3_Encryption, DES_XEX3_Decryption>(), valdata1, 1) && pass;
  455. return pass;
  456. }
  457. bool TestModeIV(SymmetricCipher &e, SymmetricCipher &d)
  458. {
  459. SecByteBlock lastIV, iv(e.IVSize());
  460. StreamTransformationFilter filter(e, new StreamTransformationFilter(d));
  461. byte plaintext[20480];
  462. for (unsigned int i=1; i<sizeof(plaintext); i*=2)
  463. {
  464. e.GetNextIV(GlobalRNG(), iv);
  465. if (iv == lastIV)
  466. return false;
  467. else
  468. lastIV = iv;
  469. e.Resynchronize(iv);
  470. d.Resynchronize(iv);
  471. unsigned int length = STDMAX(GlobalRNG().GenerateWord32(0, i), (word32)e.MinLastBlockSize());
  472. GlobalRNG().GenerateBlock(plaintext, length);
  473. if (!TestFilter(filter, plaintext, length, plaintext, length))
  474. return false;
  475. }
  476. return true;
  477. }
  478. bool ValidateCipherModes()
  479. {
  480. cout << "\nTesting DES modes...\n\n";
  481. const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
  482. const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
  483. const byte plain[] = { // "Now is the time for all " without tailing 0
  484. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  485. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  486. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};
  487. DESEncryption desE(key);
  488. DESDecryption desD(key);
  489. bool pass=true, fail;
  490. {
  491. // from FIPS 81
  492. const byte encrypted[] = {
  493. 0x3f, 0xa4, 0x0e, 0x8a, 0x98, 0x4d, 0x48, 0x15,
  494. 0x6a, 0x27, 0x17, 0x87, 0xab, 0x88, 0x83, 0xf9,
  495. 0x89, 0x3d, 0x51, 0xec, 0x4b, 0x56, 0x3b, 0x53};
  496. ECB_Mode_ExternalCipher::Encryption modeE(desE);
  497. fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
  498. plain, sizeof(plain), encrypted, sizeof(encrypted));
  499. pass = pass && !fail;
  500. cout << (fail ? "FAILED " : "passed ") << "ECB encryption" << endl;
  501. ECB_Mode_ExternalCipher::Decryption modeD(desD);
  502. fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
  503. encrypted, sizeof(encrypted), plain, sizeof(plain));
  504. pass = pass && !fail;
  505. cout << (fail ? "FAILED " : "passed ") << "ECB decryption" << endl;
  506. }
  507. {
  508. // from FIPS 81
  509. const byte encrypted[] = {
  510. 0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C,
  511. 0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F,
  512. 0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6};
  513. CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
  514. fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
  515. plain, sizeof(plain), encrypted, sizeof(encrypted));
  516. pass = pass && !fail;
  517. cout << (fail ? "FAILED " : "passed ") << "CBC encryption with no padding" << endl;
  518. CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
  519. fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::NO_PADDING).Ref(),
  520. encrypted, sizeof(encrypted), plain, sizeof(plain));
  521. pass = pass && !fail;
  522. cout << (fail ? "FAILED " : "passed ") << "CBC decryption with no padding" << endl;
  523. fail = !TestModeIV(modeE, modeD);
  524. pass = pass && !fail;
  525. cout << (fail ? "FAILED " : "passed ") << "CBC mode IV generation" << endl;
  526. }
  527. {
  528. // generated with Crypto++, matches FIPS 81
  529. // but has extra 8 bytes as result of padding
  530. const byte encrypted[] = {
  531. 0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C,
  532. 0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F,
  533. 0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6,
  534. 0x62, 0xC1, 0x6A, 0x27, 0xE4, 0xFC, 0xF2, 0x77};
  535. CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
  536. fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
  537. plain, sizeof(plain), encrypted, sizeof(encrypted));
  538. pass = pass && !fail;
  539. cout << (fail ? "FAILED " : "passed ") << "CBC encryption with PKCS #7 padding" << endl;
  540. CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
  541. fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
  542. encrypted, sizeof(encrypted), plain, sizeof(plain));
  543. pass = pass && !fail;
  544. cout << (fail ? "FAILED " : "passed ") << "CBC decryption with PKCS #7 padding" << endl;
  545. }
  546. {
  547. // generated with Crypto++ 5.2, matches FIPS 81
  548. // but has extra 8 bytes as result of padding
  549. const byte encrypted[] = {
  550. 0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C,
  551. 0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F,
  552. 0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6,
  553. 0xcf, 0xb7, 0xc7, 0x64, 0x0e, 0x7c, 0xd9, 0xa7};
  554. CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
  555. fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ONE_AND_ZEROS_PADDING).Ref(),
  556. plain, sizeof(plain), encrypted, sizeof(encrypted));
  557. pass = pass && !fail;
  558. cout << (fail ? "FAILED " : "passed ") << "CBC encryption with one-and-zeros padding" << endl;
  559. CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
  560. fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::ONE_AND_ZEROS_PADDING).Ref(),
  561. encrypted, sizeof(encrypted), plain, sizeof(plain));
  562. pass = pass && !fail;
  563. cout << (fail ? "FAILED " : "passed ") << "CBC decryption with one-and-zeros padding" << endl;
  564. }
  565. {
  566. const byte plain[] = {'a', 0, 0, 0, 0, 0, 0, 0};
  567. // generated with Crypto++
  568. const byte encrypted[] = {
  569. 0x9B, 0x47, 0x57, 0x59, 0xD6, 0x9C, 0xF6, 0xD0};
  570. CBC_Mode_ExternalCipher::Encryption modeE(desE, iv);
  571. fail = !TestFilter(StreamTransformationFilter(modeE, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(),
  572. plain, 1, encrypted, sizeof(encrypted));
  573. pass = pass && !fail;
  574. cout << (fail ? "FAILED " : "passed ") << "CBC encryption with zeros padding" << endl;
  575. CBC_Mode_ExternalCipher::Decryption modeD(desD, iv);
  576. fail = !TestFilter(StreamTransformationFilter(modeD, NULL, StreamTransformationFilter::ZEROS_PADDING).Ref(),
  577. encrypted, sizeof(encrypted), plain, sizeof(plain));
  578. pass = pass && !fail;
  579. cout << (fail ? "FAILED " : "passed ") << "CBC decryption with zeros padding" << endl;
  580. }
  581. {
  582. // generated with Crypto++, matches FIPS 81
  583. // but with last two blocks swapped as result of CTS
  584. const byte encrypted[] = {
  585. 0xE5, 0xC7, 0xCD, 0xDE, 0x87, 0x2B, 0xF2, 0x7C,
  586. 0x68, 0x37, 0x88, 0x49, 0x9A, 0x7C, 0x05, 0xF6,
  587. 0x43, 0xE9, 0x34, 0x00, 0x8C, 0x38, 0x9C, 0x0F};
  588. CBC_CTS_Mode_ExternalCipher::Encryption modeE(desE, iv);
  589. fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
  590. plain, sizeof(plain), encrypted, sizeof(encrypted));
  591. pass = pass && !fail;
  592. cout << (fail ? "FAILED " : "passed ") << "CBC encryption with ciphertext stealing (CTS)" << endl;
  593. CBC_CTS_Mode_ExternalCipher::Decryption modeD(desD, iv);
  594. fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
  595. encrypted, sizeof(encrypted), plain, sizeof(plain));
  596. pass = pass && !fail;
  597. cout << (fail ? "FAILED " : "passed ") << "CBC decryption with ciphertext stealing (CTS)" << endl;
  598. fail = !TestModeIV(modeE, modeD);
  599. pass = pass && !fail;
  600. cout << (fail ? "FAILED " : "passed ") << "CBC CTS IV generation" << endl;
  601. }
  602. {
  603. // generated with Crypto++
  604. const byte decryptionIV[] = {0x4D, 0xD0, 0xAC, 0x8F, 0x47, 0xCF, 0x79, 0xCE};
  605. const byte encrypted[] = {0x12, 0x34, 0x56};
  606. byte stolenIV[8];
  607. CBC_CTS_Mode_ExternalCipher::Encryption modeE(desE, iv);
  608. modeE.SetStolenIV(stolenIV);
  609. fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
  610. plain, 3, encrypted, sizeof(encrypted));
  611. fail = memcmp(stolenIV, decryptionIV, 8) != 0 || fail;
  612. pass = pass && !fail;
  613. cout << (fail ? "FAILED " : "passed ") << "CBC encryption with ciphertext and IV stealing" << endl;
  614. CBC_CTS_Mode_ExternalCipher::Decryption modeD(desD, stolenIV);
  615. fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
  616. encrypted, sizeof(encrypted), plain, 3);
  617. pass = pass && !fail;
  618. cout << (fail ? "FAILED " : "passed ") << "CBC decryption with ciphertext and IV stealing" << endl;
  619. }
  620. {
  621. const byte encrypted[] = { // from FIPS 81
  622. 0xF3,0x09,0x62,0x49,0xC7,0xF4,0x6E,0x51,
  623. 0xA6,0x9E,0x83,0x9B,0x1A,0x92,0xF7,0x84,
  624. 0x03,0x46,0x71,0x33,0x89,0x8E,0xA6,0x22};
  625. CFB_Mode_ExternalCipher::Encryption modeE(desE, iv);
  626. fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
  627. plain, sizeof(plain), encrypted, sizeof(encrypted));
  628. pass = pass && !fail;
  629. cout << (fail ? "FAILED " : "passed ") << "CFB encryption" << endl;
  630. CFB_Mode_ExternalCipher::Decryption modeD(desE, iv);
  631. fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
  632. encrypted, sizeof(encrypted), plain, sizeof(plain));
  633. pass = pass && !fail;
  634. cout << (fail ? "FAILED " : "passed ") << "CFB decryption" << endl;
  635. fail = !TestModeIV(modeE, modeD);
  636. pass = pass && !fail;
  637. cout << (fail ? "FAILED " : "passed ") << "CFB mode IV generation" << endl;
  638. }
  639. {
  640. const byte plain[] = { // "Now is the." without tailing 0
  641. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,0x68,0x65};
  642. const byte encrypted[] = { // from FIPS 81
  643. 0xf3,0x1f,0xda,0x07,0x01,0x14,0x62,0xee,0x18,0x7f};
  644. CFB_Mode_ExternalCipher::Encryption modeE(desE, iv, 1);
  645. fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
  646. plain, sizeof(plain), encrypted, sizeof(encrypted));
  647. pass = pass && !fail;
  648. cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) encryption" << endl;
  649. CFB_Mode_ExternalCipher::Decryption modeD(desE, iv, 1);
  650. fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
  651. encrypted, sizeof(encrypted), plain, sizeof(plain));
  652. pass = pass && !fail;
  653. cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) decryption" << endl;
  654. fail = !TestModeIV(modeE, modeD);
  655. pass = pass && !fail;
  656. cout << (fail ? "FAILED " : "passed ") << "CFB (8-bit feedback) IV generation" << endl;
  657. }
  658. {
  659. const byte encrypted[] = { // from Eric Young's libdes
  660. 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
  661. 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
  662. 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3};
  663. OFB_Mode_ExternalCipher::Encryption modeE(desE, iv);
  664. fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
  665. plain, sizeof(plain), encrypted, sizeof(encrypted));
  666. pass = pass && !fail;
  667. cout << (fail ? "FAILED " : "passed ") << "OFB encryption" << endl;
  668. OFB_Mode_ExternalCipher::Decryption modeD(desE, iv);
  669. fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
  670. encrypted, sizeof(encrypted), plain, sizeof(plain));
  671. pass = pass && !fail;
  672. cout << (fail ? "FAILED " : "passed ") << "OFB decryption" << endl;
  673. fail = !TestModeIV(modeE, modeD);
  674. pass = pass && !fail;
  675. cout << (fail ? "FAILED " : "passed ") << "OFB IV generation" << endl;
  676. }
  677. {
  678. const byte encrypted[] = { // generated with Crypto++
  679. 0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4, 0x6E, 0x51,
  680. 0x16, 0x3A, 0x8C, 0xA0, 0xFF, 0xC9, 0x4C, 0x27,
  681. 0xFA, 0x2F, 0x80, 0xF4, 0x80, 0xB8, 0x6F, 0x75};
  682. CTR_Mode_ExternalCipher::Encryption modeE(desE, iv);
  683. fail = !TestFilter(StreamTransformationFilter(modeE).Ref(),
  684. plain, sizeof(plain), encrypted, sizeof(encrypted));
  685. pass = pass && !fail;
  686. cout << (fail ? "FAILED " : "passed ") << "Counter Mode encryption" << endl;
  687. CTR_Mode_ExternalCipher::Decryption modeD(desE, iv);
  688. fail = !TestFilter(StreamTransformationFilter(modeD).Ref(),
  689. encrypted, sizeof(encrypted), plain, sizeof(plain));
  690. pass = pass && !fail;
  691. cout << (fail ? "FAILED " : "passed ") << "Counter Mode decryption" << endl;
  692. fail = !TestModeIV(modeE, modeD);
  693. pass = pass && !fail;
  694. cout << (fail ? "FAILED " : "passed ") << "Counter Mode IV generation" << endl;
  695. }
  696. {
  697. const byte plain[] = { // "7654321 Now is the time for "
  698. 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
  699. 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  700. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
  701. 0x66, 0x6f, 0x72, 0x20};
  702. const byte mac1[] = { // from FIPS 113
  703. 0xf1, 0xd3, 0x0f, 0x68, 0x49, 0x31, 0x2c, 0xa4};
  704. const byte mac2[] = { // generated with Crypto++
  705. 0x35, 0x80, 0xC5, 0xC4, 0x6B, 0x81, 0x24, 0xE2};
  706. CBC_MAC<DES> cbcmac(key);
  707. HashFilter cbcmacFilter(cbcmac);
  708. fail = !TestFilter(cbcmacFilter, plain, sizeof(plain), mac1, sizeof(mac1));
  709. pass = pass && !fail;
  710. cout << (fail ? "FAILED " : "passed ") << "CBC MAC" << endl;
  711. DMAC<DES> dmac(key);
  712. HashFilter dmacFilter(dmac);
  713. fail = !TestFilter(dmacFilter, plain, sizeof(plain), mac2, sizeof(mac2));
  714. pass = pass && !fail;
  715. cout << (fail ? "FAILED " : "passed ") << "DMAC" << endl;
  716. }
  717. {
  718. CTR_Mode<AES>::Encryption modeE(plain, 16, plain);
  719. CTR_Mode<AES>::Decryption modeD(plain, 16, plain);
  720. fail = !TestModeIV(modeE, modeD);
  721. pass = pass && !fail;
  722. cout << (fail ? "FAILED " : "passed ") << "AES CTR Mode" << endl;
  723. }
  724. {
  725. OFB_Mode<AES>::Encryption modeE(plain, 16, plain);
  726. OFB_Mode<AES>::Decryption modeD(plain, 16, plain);
  727. fail = !TestModeIV(modeE, modeD);
  728. pass = pass && !fail;
  729. cout << (fail ? "FAILED " : "passed ") << "AES OFB Mode" << endl;
  730. }
  731. {
  732. CFB_Mode<AES>::Encryption modeE(plain, 16, plain);
  733. CFB_Mode<AES>::Decryption modeD(plain, 16, plain);
  734. fail = !TestModeIV(modeE, modeD);
  735. pass = pass && !fail;
  736. cout << (fail ? "FAILED " : "passed ") << "AES CFB Mode" << endl;
  737. }
  738. {
  739. CBC_Mode<AES>::Encryption modeE(plain, 16, plain);
  740. CBC_Mode<AES>::Decryption modeD(plain, 16, plain);
  741. fail = !TestModeIV(modeE, modeD);
  742. pass = pass && !fail;
  743. cout << (fail ? "FAILED " : "passed ") << "AES CBC Mode" << endl;
  744. }
  745. return pass;
  746. }
  747. bool ValidateIDEA()
  748. {
  749. cout << "\nIDEA validation suite running...\n\n";
  750. FileSource valdata("TestData/ideaval.dat", true, new HexDecoder);
  751. return BlockTransformationTest(FixedRoundsCipherFactory<IDEAEncryption, IDEADecryption>(), valdata);
  752. }
  753. bool ValidateSAFER()
  754. {
  755. cout << "\nSAFER validation suite running...\n\n";
  756. FileSource valdata("TestData/saferval.dat", true, new HexDecoder);
  757. bool pass = true;
  758. pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_K_Encryption, SAFER_K_Decryption>(8,6), valdata, 4) && pass;
  759. pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_K_Encryption, SAFER_K_Decryption>(16,12), valdata, 4) && pass;
  760. pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_SK_Encryption, SAFER_SK_Decryption>(8,6), valdata, 4) && pass;
  761. pass = BlockTransformationTest(VariableRoundsCipherFactory<SAFER_SK_Encryption, SAFER_SK_Decryption>(16,10), valdata, 4) && pass;
  762. return pass;
  763. }
  764. bool ValidateRC2()
  765. {
  766. cout << "\nRC2 validation suite running...\n\n";
  767. FileSource valdata("TestData/rc2val.dat", true, new HexDecoder);
  768. HexEncoder output(new FileSink(cout));
  769. SecByteBlock plain(RC2Encryption::BLOCKSIZE), cipher(RC2Encryption::BLOCKSIZE), out(RC2Encryption::BLOCKSIZE), outplain(RC2Encryption::BLOCKSIZE);
  770. SecByteBlock key(128);
  771. bool pass=true, fail;
  772. while (valdata.MaxRetrievable())
  773. {
  774. byte keyLen, effectiveLen;
  775. valdata.Get(keyLen);
  776. valdata.Get(effectiveLen);
  777. valdata.Get(key, keyLen);
  778. valdata.Get(plain, RC2Encryption::BLOCKSIZE);
  779. valdata.Get(cipher, RC2Encryption::BLOCKSIZE);
  780. apbt transE(new RC2Encryption(key, keyLen, effectiveLen));
  781. transE->ProcessBlock(plain, out);
  782. fail = memcmp(out, cipher, RC2Encryption::BLOCKSIZE) != 0;
  783. apbt transD(new RC2Decryption(key, keyLen, effectiveLen));
  784. transD->ProcessBlock(out, outplain);
  785. fail=fail || memcmp(outplain, plain, RC2Encryption::BLOCKSIZE);
  786. pass = pass && !fail;
  787. cout << (fail ? "FAILED " : "passed ");
  788. output.Put(key, keyLen);
  789. cout << " ";
  790. output.Put(outplain, RC2Encryption::BLOCKSIZE);
  791. cout << " ";
  792. output.Put(out, RC2Encryption::BLOCKSIZE);
  793. cout << endl;
  794. }
  795. return pass;
  796. }
  797. bool ValidateARC4()
  798. {
  799. unsigned char Key0[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef };
  800. unsigned char Input0[]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
  801. unsigned char Output0[] = {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96};
  802. unsigned char Key1[]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
  803. unsigned char Input1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  804. unsigned char Output1[]={0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79};
  805. unsigned char Key2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  806. unsigned char Input2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  807. unsigned char Output2[]={0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a};
  808. unsigned char Key3[]={0xef,0x01,0x23,0x45};
  809. unsigned char Input3[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  810. unsigned char Output3[]={0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61};
  811. unsigned char Key4[]={ 0x01,0x23,0x45,0x67,0x89,0xab, 0xcd,0xef };
  812. unsigned char Input4[] =
  813. {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  814. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  815. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  816. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  817. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  818. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  819. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  820. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  821. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  822. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  823. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  824. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  825. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  826. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  827. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  828. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  829. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  830. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  831. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  832. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  833. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  834. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  835. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  836. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  837. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  838. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  839. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  840. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  841. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  842. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  843. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  844. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  845. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  846. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  847. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  848. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  849. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  850. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  851. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  852. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  853. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  854. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  855. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  856. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  857. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  858. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  859. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  860. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  861. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  862. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  863. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  864. 0x01};
  865. unsigned char Output4[]= {
  866. 0x75,0x95,0xc3,0xe6,0x11,0x4a,0x09,0x78,0x0c,0x4a,0xd4,
  867. 0x52,0x33,0x8e,0x1f,0xfd,0x9a,0x1b,0xe9,0x49,0x8f,
  868. 0x81,0x3d,0x76,0x53,0x34,0x49,0xb6,0x77,0x8d,0xca,
  869. 0xd8,0xc7,0x8a,0x8d,0x2b,0xa9,0xac,0x66,0x08,0x5d,
  870. 0x0e,0x53,0xd5,0x9c,0x26,0xc2,0xd1,0xc4,0x90,0xc1,
  871. 0xeb,0xbe,0x0c,0xe6,0x6d,0x1b,0x6b,0x1b,0x13,0xb6,
  872. 0xb9,0x19,0xb8,0x47,0xc2,0x5a,0x91,0x44,0x7a,0x95,
  873. 0xe7,0x5e,0x4e,0xf1,0x67,0x79,0xcd,0xe8,0xbf,0x0a,
  874. 0x95,0x85,0x0e,0x32,0xaf,0x96,0x89,0x44,0x4f,0xd3,
  875. 0x77,0x10,0x8f,0x98,0xfd,0xcb,0xd4,0xe7,0x26,0x56,
  876. 0x75,0x00,0x99,0x0b,0xcc,0x7e,0x0c,0xa3,0xc4,0xaa,
  877. 0xa3,0x04,0xa3,0x87,0xd2,0x0f,0x3b,0x8f,0xbb,0xcd,
  878. 0x42,0xa1,0xbd,0x31,0x1d,0x7a,0x43,0x03,0xdd,0xa5,
  879. 0xab,0x07,0x88,0x96,0xae,0x80,0xc1,0x8b,0x0a,0xf6,
  880. 0x6d,0xff,0x31,0x96,0x16,0xeb,0x78,0x4e,0x49,0x5a,
  881. 0xd2,0xce,0x90,0xd7,0xf7,0x72,0xa8,0x17,0x47,0xb6,
  882. 0x5f,0x62,0x09,0x3b,0x1e,0x0d,0xb9,0xe5,0xba,0x53,
  883. 0x2f,0xaf,0xec,0x47,0x50,0x83,0x23,0xe6,0x71,0x32,
  884. 0x7d,0xf9,0x44,0x44,0x32,0xcb,0x73,0x67,0xce,0xc8,
  885. 0x2f,0x5d,0x44,0xc0,0xd0,0x0b,0x67,0xd6,0x50,0xa0,
  886. 0x75,0xcd,0x4b,0x70,0xde,0xdd,0x77,0xeb,0x9b,0x10,
  887. 0x23,0x1b,0x6b,0x5b,0x74,0x13,0x47,0x39,0x6d,0x62,
  888. 0x89,0x74,0x21,0xd4,0x3d,0xf9,0xb4,0x2e,0x44,0x6e,
  889. 0x35,0x8e,0x9c,0x11,0xa9,0xb2,0x18,0x4e,0xcb,0xef,
  890. 0x0c,0xd8,0xe7,0xa8,0x77,0xef,0x96,0x8f,0x13,0x90,
  891. 0xec,0x9b,0x3d,0x35,0xa5,0x58,0x5c,0xb0,0x09,0x29,
  892. 0x0e,0x2f,0xcd,0xe7,0xb5,0xec,0x66,0xd9,0x08,0x4b,
  893. 0xe4,0x40,0x55,0xa6,0x19,0xd9,0xdd,0x7f,0xc3,0x16,
  894. 0x6f,0x94,0x87,0xf7,0xcb,0x27,0x29,0x12,0x42,0x64,
  895. 0x45,0x99,0x85,0x14,0xc1,0x5d,0x53,0xa1,0x8c,0x86,
  896. 0x4c,0xe3,0xa2,0xb7,0x55,0x57,0x93,0x98,0x81,0x26,
  897. 0x52,0x0e,0xac,0xf2,0xe3,0x06,0x6e,0x23,0x0c,0x91,
  898. 0xbe,0xe4,0xdd,0x53,0x04,0xf5,0xfd,0x04,0x05,0xb3,
  899. 0x5b,0xd9,0x9c,0x73,0x13,0x5d,0x3d,0x9b,0xc3,0x35,
  900. 0xee,0x04,0x9e,0xf6,0x9b,0x38,0x67,0xbf,0x2d,0x7b,
  901. 0xd1,0xea,0xa5,0x95,0xd8,0xbf,0xc0,0x06,0x6f,0xf8,
  902. 0xd3,0x15,0x09,0xeb,0x0c,0x6c,0xaa,0x00,0x6c,0x80,
  903. 0x7a,0x62,0x3e,0xf8,0x4c,0x3d,0x33,0xc1,0x95,0xd2,
  904. 0x3e,0xe3,0x20,0xc4,0x0d,0xe0,0x55,0x81,0x57,0xc8,
  905. 0x22,0xd4,0xb8,0xc5,0x69,0xd8,0x49,0xae,0xd5,0x9d,
  906. 0x4e,0x0f,0xd7,0xf3,0x79,0x58,0x6b,0x4b,0x7f,0xf6,
  907. 0x84,0xed,0x6a,0x18,0x9f,0x74,0x86,0xd4,0x9b,0x9c,
  908. 0x4b,0xad,0x9b,0xa2,0x4b,0x96,0xab,0xf9,0x24,0x37,
  909. 0x2c,0x8a,0x8f,0xff,0xb1,0x0d,0x55,0x35,0x49,0x00,
  910. 0xa7,0x7a,0x3d,0xb5,0xf2,0x05,0xe1,0xb9,0x9f,0xcd,
  911. 0x86,0x60,0x86,0x3a,0x15,0x9a,0xd4,0xab,0xe4,0x0f,
  912. 0xa4,0x89,0x34,0x16,0x3d,0xdd,0xe5,0x42,0xa6,0x58,
  913. 0x55,0x40,0xfd,0x68,0x3c,0xbf,0xd8,0xc0,0x0f,0x12,
  914. 0x12,0x9a,0x28,0x4d,0xea,0xcc,0x4c,0xde,0xfe,0x58,
  915. 0xbe,0x71,0x37,0x54,0x1c,0x04,0x71,0x26,0xc8,0xd4,
  916. 0x9e,0x27,0x55,0xab,0x18,0x1a,0xb7,0xe9,0x40,0xb0,
  917. 0xc0};
  918. // VC60 workaround: auto_ptr lacks reset()
  919. member_ptr<Weak::ARC4> arc4;
  920. bool pass=true, fail;
  921. int i;
  922. cout << "\nARC4 validation suite running...\n\n";
  923. arc4.reset(new Weak::ARC4(Key0, sizeof(Key0)));
  924. arc4->ProcessString(Input0, sizeof(Input0));
  925. fail = memcmp(Input0, Output0, sizeof(Input0)) != 0;
  926. cout << (fail ? "FAILED" : "passed") << " Test 0" << endl;
  927. pass = pass && !fail;
  928. arc4.reset(new Weak::ARC4(Key1, sizeof(Key1)));
  929. arc4->ProcessString(Key1, Input1, sizeof(Key1));
  930. fail = memcmp(Output1, Key1, sizeof(Key1)) != 0;
  931. cout << (fail ? "FAILED" : "passed") << " Test 1" << endl;
  932. pass = pass && !fail;
  933. arc4.reset(new Weak::ARC4(Key2, sizeof(Key2)));
  934. for (i=0, fail=false; i<sizeof(Input2); i++)
  935. if (arc4->ProcessByte(Input2[i]) != Output2[i])
  936. fail = true;
  937. cout << (fail ? "FAILED" : "passed") << " Test 2" << endl;
  938. pass = pass && !fail;
  939. arc4.reset(new Weak::ARC4(Key3, sizeof(Key3)));
  940. for (i=0, fail=false; i<sizeof(Input3); i++)
  941. if (arc4->ProcessByte(Input3[i]) != Output3[i])
  942. fail = true;
  943. cout << (fail ? "FAILED" : "passed") << " Test 3" << endl;
  944. pass = pass && !fail;
  945. arc4.reset(new Weak::ARC4(Key4, sizeof(Key4)));
  946. for (i=0, fail=false; i<sizeof(Input4); i++)
  947. if (arc4->ProcessByte(Input4[i]) != Output4[i])
  948. fail = true;
  949. cout << (fail ? "FAILED" : "passed") << " Test 4" << endl;
  950. pass = pass && !fail;
  951. return pass;
  952. }
  953. bool ValidateRC5()
  954. {
  955. cout << "\nRC5 validation suite running...\n\n";
  956. FileSource valdata("TestData/rc5val.dat", true, new HexDecoder);
  957. return BlockTransformationTest(VariableRoundsCipherFactory<RC5Encryption, RC5Decryption>(16, 12), valdata);
  958. }
  959. bool ValidateRC6()
  960. {
  961. cout << "\nRC6 validation suite running...\n\n";
  962. FileSource valdata("TestData/rc6val.dat", true, new HexDecoder);
  963. bool pass = true;
  964. pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(16), valdata, 2) && pass;
  965. pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(24), valdata, 2) && pass;
  966. pass = BlockTransformationTest(FixedRoundsCipherFactory<RC6Encryption, RC6Decryption>(32), valdata, 2) && pass;
  967. return pass;
  968. }
  969. bool ValidateMARS()
  970. {
  971. cout << "\nMARS validation suite running...\n\n";
  972. FileSource valdata("TestData/marsval.dat", true, new HexDecoder);
  973. bool pass = true;
  974. pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(16), valdata, 4) && pass;
  975. pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(24), valdata, 3) && pass;
  976. pass = BlockTransformationTest(FixedRoundsCipherFactory<MARSEncryption, MARSDecryption>(32), valdata, 2) && pass;
  977. return pass;
  978. }
  979. bool ValidateRijndael()
  980. {
  981. cout << "\nRijndael (AES) validation suite running...\n\n";
  982. FileSource valdata("TestData/rijndael.dat", true, new HexDecoder);
  983. bool pass = true;
  984. pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(16), valdata, 4) && pass;
  985. pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(24), valdata, 3) && pass;
  986. pass = BlockTransformationTest(FixedRoundsCipherFactory<RijndaelEncryption, RijndaelDecryption>(32), valdata, 2) && pass;
  987. pass = RunTestDataFile("TestVectors/aes.txt") && pass;
  988. return pass;
  989. }
  990. bool ValidateTwofish()
  991. {
  992. cout << "\nTwofish validation suite running...\n\n";
  993. FileSource valdata("TestData/twofishv.dat", true, new HexDecoder);
  994. bool pass = true;
  995. pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(16), valdata, 4) && pass;
  996. pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(24), valdata, 3) && pass;
  997. pass = BlockTransformationTest(FixedRoundsCipherFactory<TwofishEncryption, TwofishDecryption>(32), valdata, 2) && pass;
  998. return pass;
  999. }
  1000. bool ValidateSerpent()
  1001. {
  1002. cout << "\nSerpent validation suite running...\n\n";
  1003. FileSource valdata("TestData/serpentv.dat", true, new HexDecoder);
  1004. bool pass = true;
  1005. pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(16), valdata, 4) && pass;
  1006. pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(24), valdata, 3) && pass;
  1007. pass = BlockTransformationTest(FixedRoundsCipherFactory<SerpentEncryption, SerpentDecryption>(32), valdata, 2) && pass;
  1008. return pass;
  1009. }
  1010. bool ValidateBlowfish()
  1011. {
  1012. cout << "\nBlowfish validation suite running...\n\n";
  1013. HexEncoder output(new FileSink(cout));
  1014. const char *key[]={"abcdefghijklmnopqrstuvwxyz", "Who is John Galt?"};
  1015. byte *plain[]={(byte *)"BLOWFISH", (byte *)"\xfe\xdc\xba\x98\x76\x54\x32\x10"};
  1016. byte *cipher[]={(byte *)"\x32\x4e\xd0\xfe\xf4\x13\xa2\x03", (byte *)"\xcc\x91\x73\x2b\x80\x22\xf6\x84"};
  1017. byte out[8], outplain[8];
  1018. bool pass=true, fail;
  1019. for (int i=0; i<2; i++)
  1020. {
  1021. ECB_Mode<Blowfish>::Encryption enc((byte *)key[i], strlen(key[i]));
  1022. enc.ProcessData(out, plain[i], 8);
  1023. fail = memcmp(out, cipher[i], 8) != 0;
  1024. ECB_Mode<Blowfish>::Decryption dec((byte *)key[i], strlen(key[i]));
  1025. dec.ProcessData(outplain, cipher[i], 8);
  1026. fail = fail || memcmp(outplain, plain[i], 8);
  1027. pass = pass && !fail;
  1028. cout << (fail ? "FAILED " : "passed ");
  1029. cout << '\"' << key[i] << '\"';
  1030. for (int j=0; j<(signed int)(30-strlen(key[i])); j++)
  1031. cout << ' ';
  1032. output.Put(outplain, 8);
  1033. cout << " ";
  1034. output.Put(out, 8);
  1035. cout << endl;
  1036. }
  1037. return pass;
  1038. }
  1039. bool ValidateThreeWay()
  1040. {
  1041. cout << "\n3-WAY validation suite running...\n\n";
  1042. FileSource valdata("TestData/3wayval.dat", true, new HexDecoder);
  1043. return BlockTransformationTest(FixedRoundsCipherFactory<ThreeWayEncryption, ThreeWayDecryption>(), valdata);
  1044. }
  1045. bool ValidateGOST()
  1046. {
  1047. cout << "\nGOST validation suite running...\n\n";
  1048. FileSource valdata("TestData/gostval.dat", true, new HexDecoder);
  1049. return BlockTransformationTest(FixedRoundsCipherFactory<GOSTEncryption, GOSTDecryption>(), valdata);
  1050. }
  1051. bool ValidateSHARK()
  1052. {
  1053. cout << "\nSHARK validation suite running...\n\n";
  1054. FileSource valdata("TestData/sharkval.dat", true, new HexDecoder);
  1055. return BlockTransformationTest(FixedRoundsCipherFactory<SHARKEncryption, SHARKDecryption>(), valdata);
  1056. }
  1057. bool ValidateCAST()
  1058. {
  1059. bool pass = true;
  1060. cout << "\nCAST-128 validation suite running...\n\n";
  1061. FileSource val128("TestData/cast128v.dat", true, new HexDecoder);
  1062. pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(16), val128, 1) && pass;
  1063. pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(10), val128, 1) && pass;
  1064. pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST128Encryption, CAST128Decryption>(5), val128, 1) && pass;
  1065. cout << "\nCAST-256 validation suite running...\n\n";
  1066. FileSource val256("TestData/cast256v.dat", true, new HexDecoder);
  1067. pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(16), val256, 1) && pass;
  1068. pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(24), val256, 1) && pass;
  1069. pass = BlockTransformationTest(FixedRoundsCipherFactory<CAST256Encryption, CAST256Decryption>(32), val256, 1) && pass;
  1070. return pass;
  1071. }
  1072. bool ValidateSquare()
  1073. {
  1074. cout << "\nSquare validation suite running...\n\n";
  1075. FileSource valdata("TestData/squareva.dat", true, new HexDecoder);
  1076. return BlockTransformationTest(FixedRoundsCipherFactory<SquareEncryption, SquareDecryption>(), valdata);
  1077. }
  1078. bool ValidateSKIPJACK()
  1079. {
  1080. cout << "\nSKIPJACK validation suite running...\n\n";
  1081. FileSource valdata("TestData/skipjack.dat", true, new HexDecoder);
  1082. return BlockTransformationTest(FixedRoundsCipherFactory<SKIPJACKEncryption, SKIPJACKDecryption>(), valdata);
  1083. }
  1084. bool ValidateSEAL()
  1085. {
  1086. 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};
  1087. byte output[32];
  1088. byte key[] = {0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0};
  1089. byte iv[] = {0x01, 0x35, 0x77, 0xaf};
  1090. cout << "\nSEAL validation suite running...\n\n";
  1091. SEAL<>::Encryption seal(key, sizeof(key), iv);
  1092. unsigned int size = sizeof(input);
  1093. bool pass = true;
  1094. memset(output, 1, size);
  1095. seal.ProcessString(output, input, size);
  1096. for (unsigned int i=0; i<size; i++)
  1097. if (output[i] != 0)
  1098. pass = false;
  1099. seal.Seek(1);
  1100. output[1] = seal.ProcessByte(output[1]);
  1101. seal.ProcessString(output+2, size-2);
  1102. pass = pass && memcmp(output+1, input+1, size-1) == 0;
  1103. cout << (pass ? "passed" : "FAILED") << endl;
  1104. return pass;
  1105. }
  1106. bool ValidateBaseCode()
  1107. {
  1108. bool pass = true, fail;
  1109. byte data[255];
  1110. for (unsigned int i=0; i<255; i++)
  1111. data[i] = i;
  1112. const char *hexEncoded =
  1113. "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627"
  1114. "28292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F"
  1115. "505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F7071727374757677"
  1116. "78797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"
  1117. "A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7"
  1118. "C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF"
  1119. "F0F1F2F3F4F5F6F7F8F9FAFBFCFDFE";
  1120. const char *base32Encoded =
  1121. "AAASEA2EAWDAQCAJBIFS2DIQB6IBCESVCSKTNF22DEPBYHA7D2RUAIJCENUCKJTHFAWUWK3NFWZC8NBT"
  1122. "GI3VIPJYG66DUQT5HS8V6R4AIFBEGTCFI3DWSUKKJPGE4VURKBIXEW4WKXMFQYC3MJPX2ZK8M7SGC2VD"
  1123. "NTUYN35IPFXGY5DPP3ZZA6MUQP4HK7VZRB6ZW856RX9H9AEBSKB2JBNGS8EIVCWMTUG27D6SUGJJHFEX"
  1124. "U4M3TGN4VQQJ5HW9WCS4FI7EWYVKRKFJXKX43MPQX82MDNXVYU45PP72ZG7MZRF7Z496BSQC2RCNMTYH"
  1125. "3DE6XU8N3ZHN9WGT4MJ7JXQY49NPVYY55VQ77Z9A6HTQH3HF65V8T4RK7RYQ55ZR8D29F69W8Z5RR8H3"
  1126. "9M7939R8";
  1127. const char *base64AndHexEncoded =
  1128. "41414543417751464267634943516F4C4441304F4478415245684D554652595847426B6147787764"
  1129. "486838674953496A4A43556D4A7967704B6973734C5334764D4445794D7A51310A4E6A63344F546F"
  1130. "375044302B50304242516B4E4552555A4853456C4B5330784E546B395155564A5456465657563168"
  1131. "5A576C746358563566594746695932526C5A6D646F615770720A6247317562334278636E4E306458"
  1132. "5A3365486C3665337839666E2B4167594B44684957476834694A696F754D6A5936506B4A47536B35"
  1133. "53566C7065596D5A71626E4A32656E3643680A6F714F6B7061616E714B6D717136797472712B7773"
  1134. "624B7A744C573274376935757275387662362F774D484377385446787366497963724C7A4D334F7A"
  1135. "39445230745055316462580A324E6E6132397A6433742F6734654C6A354F586D352B6A7036757673"
  1136. "3765377638504879382F5431397666342B6672372F50332B0A";
  1137. cout << "\nBase64, base32 and hex coding validation suite running...\n\n";
  1138. fail = !TestFilter(HexEncoder().Ref(), data, 255, (const byte *)hexEncoded, strlen(hexEncoded));
  1139. cout << (fail ? "FAILED " : "passed ");
  1140. cout << "Hex Encoding\n";
  1141. pass = pass && !fail;
  1142. fail = !TestFilter(HexDecoder().Ref(), (const byte *)hexEncoded, strlen(hexEncoded), data, 255);
  1143. cout << (fail ? "FAILED " : "passed ");
  1144. cout << "Hex Decoding\n";
  1145. pass = pass && !fail;
  1146. fail = !TestFilter(Base32Encoder().Ref(), data, 255, (const byte *)base32Encoded, strlen(base32Encoded));
  1147. cout << (fail ? "FAILED " : "passed ");
  1148. cout << "Base32 Encoding\n";
  1149. pass = pass && !fail;
  1150. fail = !TestFilter(Base32Decoder().Ref(), (const byte *)base32Encoded, strlen(base32Encoded), data, 255);
  1151. cout << (fail ? "FAILED " : "passed ");
  1152. cout << "Base32 Decoding\n";
  1153. pass = pass && !fail;
  1154. fail = !TestFilter(Base64Encoder(new HexEncoder).Ref(), data, 255, (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded));
  1155. cout << (fail ? "FAILED " : "passed ");
  1156. cout << "Base64 Encoding\n";
  1157. pass = pass && !fail;
  1158. fail = !TestFilter(HexDecoder(new Base64Decoder).Ref(), (const byte *)base64AndHexEncoded, strlen(base64AndHexEncoded), data, 255);
  1159. cout << (fail ? "FAILED " : "passed ");
  1160. cout << "Base64 Decoding\n";
  1161. pass = pass && !fail;
  1162. return pass;
  1163. }
  1164. bool ValidateSHACAL2()
  1165. {
  1166. cout << "\nSHACAL-2 validation suite running...\n\n";
  1167. bool pass = true;
  1168. FileSource valdata("TestData/shacal2v.dat", true, new HexDecoder);
  1169. pass = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(16), valdata, 4) && pass;
  1170. pass = BlockTransformationTest(FixedRoundsCipherFactory<SHACAL2Encryption, SHACAL2Decryption>(64), valdata, 10) && pass;
  1171. return pass;
  1172. }
  1173. bool ValidateCamellia()
  1174. {
  1175. cout << "\nCamellia validation suite running...\n\n";
  1176. bool pass = true;
  1177. FileSource valdata("TestData/camellia.dat", true, new HexDecoder);
  1178. pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(16), valdata, 15) && pass;
  1179. pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(24), valdata, 15) && pass;
  1180. pass = BlockTransformationTest(FixedRoundsCipherFactory<CamelliaEncryption, CamelliaDecryption>(32), valdata, 15) && pass;
  1181. return pass;
  1182. }
  1183. bool ValidateSalsa()
  1184. {
  1185. cout << "\nSalsa validation suite running...\n";
  1186. return RunTestDataFile("TestVectors/salsa.txt");
  1187. }
  1188. bool ValidateSosemanuk()
  1189. {
  1190. cout << "\nSosemanuk validation suite running...\n";
  1191. return RunTestDataFile("TestVectors/sosemanuk.txt");
  1192. }
  1193. bool ValidateVMAC()
  1194. {
  1195. cout << "\nVMAC validation suite running...\n";
  1196. return RunTestDataFile("TestVectors/vmac.txt");
  1197. }
  1198. bool ValidateCCM()
  1199. {
  1200. cout << "\nAES/CCM validation suite running...\n";
  1201. return RunTestDataFile("TestVectors/ccm.txt");
  1202. }
  1203. bool ValidateGCM()
  1204. {
  1205. cout << "\nAES/GCM validation suite running...\n";
  1206. cout << "\n2K tables:";
  1207. bool pass = RunTestDataFile("TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)2048));
  1208. cout << "\n64K tables:";
  1209. return RunTestDataFile("TestVectors/gcm.txt", MakeParameters(Name::TableSize(), (int)64*1024)) && pass;
  1210. }
  1211. bool ValidateCMAC()
  1212. {
  1213. cout << "\nCMAC validation suite running...\n";
  1214. return RunTestDataFile("TestVectors/cmac.txt");
  1215. }