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