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