Fabcoin Core  0.16.2
P2P Digital Currency
test.cpp
Go to the documentation of this file.
1 // test.cpp - written and placed in the public domain by Wei Dai
2 
3 #define CRYPTOPP_DEFAULT_NO_DLL
4 #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
5 
6 #include "dll.h"
7 #include "aes.h"
8 #include "cryptlib.h"
9 #include "filters.h"
10 #include "md5.h"
11 #include "ripemd.h"
12 #include "rng.h"
13 #include "gzip.h"
14 #include "default.h"
15 #include "randpool.h"
16 #include "ida.h"
17 #include "base64.h"
18 #include "socketft.h"
19 #include "wait.h"
20 #include "factory.h"
21 #include "whrlpool.h"
22 #include "tiger.h"
23 #include "smartptr.h"
24 #include "ossig.h"
25 #include "trap.h"
26 
27 #include "validate.h"
28 #include "bench.h"
29 
30 #include <algorithm>
31 #include <iostream>
32 #include <sstream>
33 #include <string>
34 #include <locale>
35 #include <time.h>
36 
37 #ifdef CRYPTOPP_WIN32_AVAILABLE
38 #define WIN32_LEAN_AND_MEAN
39 #include <windows.h>
40 #endif
41 
42 #if defined(USE_BERKELEY_STYLE_SOCKETS) && !defined(macintosh)
43 #include <netinet/in.h>
44 #include <netinet/tcp.h>
45 #endif
46 
47 #if (_MSC_VER >= 1000)
48 #include <crtdbg.h> // for the debug heap
49 #endif
50 
51 #if defined(__MWERKS__) && defined(macintosh)
52 #include <console.h>
53 #endif
54 
55 #ifdef _OPENMP
56 # include <omp.h>
57 #endif
58 
59 #ifdef __BORLANDC__
60 #pragma comment(lib, "cryptlib_bds.lib")
61 #pragma comment(lib, "ws2_32.lib")
62 #endif
63 
64 // Aggressive stack checking with VS2005 SP1 and above.
65 #if (CRYPTOPP_MSC_VERSION >= 1410)
66 # pragma strict_gs_check (on)
67 #endif
68 
69 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
70 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
71 #endif
72 
75 
76 const int MAX_PHRASE_LENGTH=250;
77 
78 void RegisterFactories();
79 void PrintSeedAndThreads(const std::string& seed);
80 
81 void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
82 string RSAEncryptString(const char *pubFilename, const char *seed, const char *message);
83 string RSADecryptString(const char *privFilename, const char *ciphertext);
84 void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename);
85 bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename);
86 
87 void DigestFile(const char *file);
88 void HmacFile(const char *hexKey, const char *file);
89 
90 void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile);
91 
92 string EncryptString(const char *plaintext, const char *passPhrase);
93 string DecryptString(const char *ciphertext, const char *passPhrase);
94 
95 void EncryptFile(const char *in, const char *out, const char *passPhrase);
96 void DecryptFile(const char *in, const char *out, const char *passPhrase);
97 
98 void SecretShareFile(int threshold, int nShares, const char *filename, const char *seed);
99 void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFilenames);
100 
101 void InformationDisperseFile(int threshold, int nShares, const char *filename);
102 void InformationRecoverFile(int threshold, const char *outFilename, char *const *inFilenames);
103 
104 void GzipFile(const char *in, const char *out, int deflate_level);
105 void GunzipFile(const char *in, const char *out);
106 
107 void Base64Encode(const char *infile, const char *outfile);
108 void Base64Decode(const char *infile, const char *outfile);
109 void HexEncode(const char *infile, const char *outfile);
110 void HexDecode(const char *infile, const char *outfile);
111 
112 void ForwardTcpPort(const char *sourcePort, const char *destinationHost, const char *destinationPort);
113 
116 
117 bool Validate(int, bool, const char *);
118 void PrintSeedAndThreads(const std::string& seed);
119 
120 int (*AdhocTest)(int argc, char *argv[]) = NULL;
121 
122 namespace { OFB_Mode<AES>::Encryption s_globalRNG; }
124 {
125  return dynamic_cast<RandomNumberGenerator&>(s_globalRNG);
126 }
127 
128 // See misc.h and trap.h for comments and usage
129 #if defined(CRYPTOPP_DEBUG) && defined(UNIX_SIGNALS_AVAILABLE)
130 static const SignalHandler<SIGTRAP, false> s_dummyHandler;
131 // static const DebugTrapHandler s_dummyHandler;
132 #endif
133 
134 int CRYPTOPP_API main(int argc, char *argv[])
135 {
136 #ifdef _CRTDBG_LEAK_CHECK_DF
137  // Turn on leak-checking
138  int tempflag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
139  tempflag |= _CRTDBG_LEAK_CHECK_DF;
140  _CrtSetDbgFlag( tempflag );
141 #endif
142 
143 #if defined(__MWERKS__) && defined(macintosh)
144  argc = ccommand(&argv);
145 #endif
146 
147  try
148  {
150 
151  // Some editors have problems with the '\0' character when redirecting output.
152  std::string seed = IntToString(time(NULL));
153  seed.resize(16, ' ');
154 
155  // Fetch the SymmetricCipher interface, not the RandomNumberGenerator interface, to key the underlying cipher
157  aesg.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
158 
159  std::string command, executableName, macFilename;
160 
161  if (argc < 2)
162  command = 'h';
163  else
164  command = argv[1];
165 
166  if (command == "g")
167  {
168  char thisSeed[1024], privFilename[128], pubFilename[128];
169  unsigned int keyLength;
170 
171  cout << "Key length in bits: ";
172  cin >> keyLength;
173 
174  cout << "\nSave private key to file: ";
175  cin >> privFilename;
176 
177  cout << "\nSave public key to file: ";
178  cin >> pubFilename;
179 
180  cout << "\nRandom Seed: ";
181  ws(cin);
182  cin.getline(thisSeed, 1024);
183 
184  GenerateRSAKey(keyLength, privFilename, pubFilename, thisSeed);
185  }
186  else if (command == "rs")
187  RSASignFile(argv[2], argv[3], argv[4]);
188  else if (command == "rv")
189  {
190  bool verified = RSAVerifyFile(argv[2], argv[3], argv[4]);
191  cout << (verified ? "valid signature" : "invalid signature") << endl;
192  }
193  else if (command == "r")
194  {
195  char privFilename[128], pubFilename[128];
196  char thisSeed[1024], message[1024];
197 
198  cout << "Private key file: ";
199  cin >> privFilename;
200 
201  cout << "\nPublic key file: ";
202  cin >> pubFilename;
203 
204  cout << "\nRandom Seed: ";
205  ws(cin);
206  cin.getline(thisSeed, 1024);
207 
208  cout << "\nMessage: ";
209  cin.getline(message, 1024);
210 
211  string ciphertext = RSAEncryptString(pubFilename, thisSeed, message);
212  cout << "\nCiphertext: " << ciphertext << endl;
213 
214  string decrypted = RSADecryptString(privFilename, ciphertext.c_str());
215  cout << "\nDecrypted: " << decrypted << endl;
216  }
217  else if (command == "mt")
218  {
220  FileStore fs(argv[2]);
221  fs.TransferAllTo(mt);
222  cout << "Maurer Test Value: " << mt.GetTestValue() << endl;
223  }
224  else if (command == "mac_dll")
225  {
226  std::string fname(argv[2] ? argv[2] : "");
227 
228  // sanity check on file size
229  std::fstream dllFile(fname.c_str(), ios::in | ios::out | ios::binary);
230  if (!dllFile.good())
231  {
232  cerr << "Failed to open file \"" << fname << "\"\n";
233  return 1;
234  }
235 
236  std::ifstream::pos_type fileEnd = dllFile.seekg(0, std::ios_base::end).tellg();
237  if (fileEnd > 20*1000*1000)
238  {
239  cerr << "Input file " << fname << " is too large";
240  cerr << "(size is " << fileEnd << ").\n";
241  return 1;
242  }
243 
244  // read file into memory
245  unsigned int fileSize = (unsigned int)fileEnd;
246  SecByteBlock buf(fileSize);
247  dllFile.seekg(0, std::ios_base::beg);
248  dllFile.read((char *)buf.begin(), fileSize);
249 
250  // find positions of relevant sections in the file, based on version 8 of documentation from http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
251  word32 coffPos = *(word16 *)(void *)(buf+0x3c);
252  word32 optionalHeaderPos = coffPos + 24;
253  word16 optionalHeaderMagic = *(word16 *)(void *)(buf+optionalHeaderPos);
254  if (optionalHeaderMagic != 0x10b && optionalHeaderMagic != 0x20b)
255  {
256  cerr << "Target file is not a PE32 or PE32+ image.\n";
257  return 3;
258  }
259  word32 checksumPos = optionalHeaderPos + 64;
260  word32 certificateTableDirectoryPos = optionalHeaderPos + (optionalHeaderMagic == 0x10b ? 128 : 144);
261  word32 certificateTablePos = *(word32 *)(void *)(buf+certificateTableDirectoryPos);
262  word32 certificateTableSize = *(word32 *)(void *)(buf+certificateTableDirectoryPos+4);
263  if (certificateTableSize != 0)
264  cerr << "Warning: certificate table (IMAGE_DIRECTORY_ENTRY_SECURITY) of target image is not empty.\n";
265 
266  // find where to place computed MAC
268  byte *found = std::search(buf.begin(), buf.end(), mac+0, mac+sizeof(mac));
269  if (found == buf.end())
270  {
271  cerr << "MAC placeholder not found. The MAC may already be placed.\n";
272  return 2;
273  }
274  word32 macPos = (unsigned int)(found-buf.begin());
275 
276  // compute MAC
278  CRYPTOPP_ASSERT(pMac->DigestSize() == sizeof(mac));
279  MeterFilter f(new HashFilter(*pMac, new ArraySink(mac, sizeof(mac))));
280  f.AddRangeToSkip(0, checksumPos, 4);
281  f.AddRangeToSkip(0, certificateTableDirectoryPos, 8);
282  f.AddRangeToSkip(0, macPos, sizeof(mac));
283  f.AddRangeToSkip(0, certificateTablePos, certificateTableSize);
284  f.PutMessageEnd(buf.begin(), buf.size());
285 
286  // Encode MAC
287  string hexMac;
288  HexEncoder encoder;
289  encoder.Put(mac, sizeof(mac)), encoder.MessageEnd();
290  hexMac.resize(static_cast<size_t>(encoder.MaxRetrievable()));
291  encoder.Get(reinterpret_cast<byte*>(&hexMac[0]), hexMac.size());
292 
293  // Report MAC and location
294  std::cout << "Placing MAC " << hexMac << " in " << fname << " at file offset " << macPos;
295  std::cout << " (0x" << std::hex << macPos << std::dec << ").\n";
296 
297  // place MAC
298  dllFile.seekg(macPos, std::ios_base::beg);
299  dllFile.write((char *)mac, sizeof(mac));
300  }
301  else if (command == "m")
302  DigestFile(argv[2]);
303  else if (command == "tv")
304  {
305  // TestDataFile() adds CRYPTOPP_DATA_DIR as required
306  std::string fname = (argv[2] ? argv[2] : "all");
307  if (fname.find(".txt") == std::string::npos)
308  fname = "TestVectors/" + fname + ".txt";
309 
310  PrintSeedAndThreads(seed);
311  return !RunTestDataFile(fname.c_str());
312  }
313  else if (command == "t")
314  {
315  // VC60 workaround: use char array instead of std::string to workaround MSVC's getline bug
316  char passPhrase[MAX_PHRASE_LENGTH], plaintext[1024];
317 
318  cout << "Passphrase: ";
319  cin.getline(passPhrase, MAX_PHRASE_LENGTH);
320 
321  cout << "\nPlaintext: ";
322  cin.getline(plaintext, 1024);
323 
324  string ciphertext = EncryptString(plaintext, passPhrase);
325  cout << "\nCiphertext: " << ciphertext << endl;
326 
327  string decrypted = DecryptString(ciphertext.c_str(), passPhrase);
328  cout << "\nDecrypted: " << decrypted << endl;
329 
330  return 0;
331  }
332  else if (command == "e64")
333  Base64Encode(argv[2], argv[3]);
334  else if (command == "d64")
335  Base64Decode(argv[2], argv[3]);
336  else if (command == "e16")
337  HexEncode(argv[2], argv[3]);
338  else if (command == "d16")
339  HexDecode(argv[2], argv[3]);
340  else if (command == "e" || command == "d")
341  {
342  char passPhrase[MAX_PHRASE_LENGTH];
343  cout << "Passphrase: ";
344  cin.getline(passPhrase, MAX_PHRASE_LENGTH);
345  if (command == "e")
346  EncryptFile(argv[2], argv[3], passPhrase);
347  else
348  DecryptFile(argv[2], argv[3], passPhrase);
349  }
350  else if (command == "ss")
351  {
352  char thisSeed[1024];
353  cout << "\nRandom Seed: ";
354  ws(cin);
355  cin.getline(thisSeed, 1024);
356  SecretShareFile(StringToValue<int, true>(argv[2]), StringToValue<int, true>(argv[3]), argv[4], thisSeed);
357  }
358  else if (command == "sr")
359  SecretRecoverFile(argc-3, argv[2], argv+3);
360  else if (command == "id")
362  else if (command == "ir")
363  InformationRecoverFile(argc-3, argv[2], argv+3);
364  else if (command == "v" || command == "vv")
365  return !Validate(argc>2 ? StringToValue<int, true>(argv[2]) : 0, argv[1][1] == 'v', argc>3 ? argv[3] : NULL);
366  else if (command == "b")
367  BenchmarkAll(argc<3 ? 1 : StringToValue<float, true>(argv[2]), argc<4 ? 0.0f : StringToValue<float, true>(argv[3])*1e9);
368  else if (command == "b2")
369  BenchmarkAll2(argc<3 ? 1 : StringToValue<float, true>(argv[2]), argc<4 ? 0.0f : StringToValue<float, true>(argv[3])*1e9);
370  else if (command == "z")
371  GzipFile(argv[3], argv[4], argv[2][0]-'0');
372  else if (command == "u")
373  GunzipFile(argv[2], argv[3]);
374  else if (command == "fips")
376  else if (command == "fips-rand")
378  else if (command == "ft")
379  ForwardTcpPort(argv[2], argv[3], argv[4]);
380  else if (command == "a")
381  {
382  if (AdhocTest)
383  return (*AdhocTest)(argc, argv);
384  else
385  {
386  cerr << "AdhocTest not defined.\n";
387  return 1;
388  }
389  }
390  else if (command == "hmac")
391  HmacFile(argv[2], argv[3]);
392  else if (command == "ae")
393  AES_CTR_Encrypt(argv[2], argv[3], argv[4], argv[5]);
394  else if (command == "h")
395  {
396  FileSource usage(CRYPTOPP_DATA_DIR "TestData/usage.dat", true, new FileSink(cout));
397  return 1;
398  }
399  else if (command == "V")
400  {
401  cout << CRYPTOPP_VERSION / 100 << '.' << (CRYPTOPP_VERSION % 100) / 10 << '.' << CRYPTOPP_VERSION % 10 << endl;
402  }
403  else
404  {
405  cerr << "Unrecognized command. Run \"cryptest h\" to obtain usage information.\n";
406  return 1;
407  }
408  return 0;
409  }
410  catch(const CryptoPP::Exception &e)
411  {
412  cout << "\nCryptoPP::Exception caught: " << e.what() << endl;
413  return -1;
414  }
415  catch(const std::exception &e)
416  {
417  cout << "\nstd::exception caught: " << e.what() << endl;
418  return -2;
419  }
420 } // End main()
421 
423 {
424 #ifdef OS_RNG_AVAILABLE
425  DefaultAutoSeededRNG rng;
426  RandomNumberStore store(rng, ULONG_MAX);
427 
428  for (unsigned int i=0; i<100000; i++)
429  store.TransferTo(FileSink((IntToString(i) + ".rnd").c_str()).Ref(), 20000);
430 #else
431  cout << "OS provided RNG not available.\n";
432  exit(-1);
433 #endif
434 }
435 
436 template <class T, bool NON_NEGATIVE>
437 T StringToValue(const std::string& str) {
438  std::istringstream iss(str);
439 
440  // Arbitrary, but we need to clear a Coverity finding TAINTED_SCALAR
441  if(iss.str().length() > 25)
442  throw InvalidArgument("cryptest.exe: '" + str +"' is too long");
443 
444  T value;
445  iss >> std::noskipws >> value;
446 
447  // Use fail(), not bad()
448  if (iss.fail() || !iss.eof())
449  throw InvalidArgument("cryptest.exe: '" + str +"' is not a value");
450 
451  if (NON_NEGATIVE && value < 0)
452  throw InvalidArgument("cryptest.exe: '" + str +"' is negative");
453 
454  return value;
455 }
456 
457 template<>
458 int StringToValue<int, true>(const std::string& str)
459 {
460  Integer n(str.c_str());
461  long l = n.ConvertToLong();
462 
463  int r;
464  if(!SafeConvert(l, r))
465  throw InvalidArgument("cryptest.exe: '" + str +"' is not an integer value");
466 
467  return r;
468 }
469 
470 void PrintSeedAndThreads(const std::string& seed)
471 {
472  cout << "Using seed: " << seed << endl;
473 
474 #ifdef _OPENMP
475  int tc = 0;
476  #pragma omp parallel
477  {
478  tc = omp_get_num_threads();
479  }
480 
481  std::cout << "Using " << tc << " OMP " << (tc == 1 ? "thread" : "threads") << std::endl;
482 #endif
483 }
484 
486 {
487  StringSource ss(hex, true, new HexDecoder);
488  SecByteBlock result((size_t)ss.MaxRetrievable());
489  ss.Get(result, result.size());
490  return result;
491 }
492 
493 void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
494 {
495  RandomPool randPool;
496  randPool.IncorporateEntropy((byte *)seed, strlen(seed));
497 
498  RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
499  HexEncoder privFile(new FileSink(privFilename));
500  priv.DEREncode(privFile);
501  privFile.MessageEnd();
502 
503  RSAES_OAEP_SHA_Encryptor pub(priv);
504  HexEncoder pubFile(new FileSink(pubFilename));
505  pub.DEREncode(pubFile);
506  pubFile.MessageEnd();
507 }
508 
509 string RSAEncryptString(const char *pubFilename, const char *seed, const char *message)
510 {
511  FileSource pubFile(pubFilename, true, new HexDecoder);
512  RSAES_OAEP_SHA_Encryptor pub(pubFile);
513 
514  RandomPool randPool;
515  randPool.IncorporateEntropy((byte *)seed, strlen(seed));
516 
517  string result;
518  StringSource(message, true, new PK_EncryptorFilter(randPool, pub, new HexEncoder(new StringSink(result))));
519  return result;
520 }
521 
522 string RSADecryptString(const char *privFilename, const char *ciphertext)
523 {
524  FileSource privFile(privFilename, true, new HexDecoder);
525  RSAES_OAEP_SHA_Decryptor priv(privFile);
526 
527  string result;
528  StringSource(ciphertext, true, new HexDecoder(new PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result))));
529  return result;
530 }
531 
532 void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename)
533 {
534  FileSource privFile(privFilename, true, new HexDecoder);
535  RSASS<PKCS1v15, SHA>::Signer priv(privFile);
536  FileSource f(messageFilename, true, new SignerFilter(GlobalRNG(), priv, new HexEncoder(new FileSink(signatureFilename))));
537 }
538 
539 bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename)
540 {
541  FileSource pubFile(pubFilename, true, new HexDecoder);
542  RSASS<PKCS1v15, SHA>::Verifier pub(pubFile);
543 
544  FileSource signatureFile(signatureFilename, true, new HexDecoder);
545  if (signatureFile.MaxRetrievable() != pub.SignatureLength())
546  return false;
547  SecByteBlock signature(pub.SignatureLength());
548  signatureFile.Get(signature, signature.size());
549 
550  VerifierFilter *verifierFilter = new VerifierFilter(pub);
551  verifierFilter->Put(signature, pub.SignatureLength());
552  FileSource f(messageFilename, true, verifierFilter);
553 
554  return verifierFilter->GetLastResult();
555 }
556 
557 void DigestFile(const char *filename)
558 {
559  SHA1 sha;
560  RIPEMD160 ripemd;
561  SHA256 sha256;
562  Tiger tiger;
563  SHA512 sha512;
564  Whirlpool whirlpool;
566  filters[0].reset(new HashFilter(sha));
567  filters[1].reset(new HashFilter(ripemd));
568  filters[2].reset(new HashFilter(tiger));
569  filters[3].reset(new HashFilter(sha256));
570  filters[4].reset(new HashFilter(sha512));
571  filters[5].reset(new HashFilter(whirlpool));
572 
573  member_ptr<ChannelSwitch> channelSwitch(new ChannelSwitch);
574  size_t i;
575  for (i=0; i<filters.size(); i++)
576  channelSwitch->AddDefaultRoute(*filters[i]);
577  FileSource(filename, true, channelSwitch.release());
578 
579  HexEncoder encoder(new FileSink(cout), false);
580  for (i=0; i<filters.size(); i++)
581  {
582  cout << filters[i]->AlgorithmName() << ": ";
583  filters[i]->TransferTo(encoder);
584  cout << "\n";
585  }
586 }
587 
588 void HmacFile(const char *hexKey, const char *file)
589 {
591  if (strcmp(hexKey, "selftest") == 0)
592  {
593  cerr << "Computing HMAC/SHA1 value for self test.\n";
595  }
596  else
597  {
598  std::string decodedKey;
599  StringSource(hexKey, true, new HexDecoder(new StringSink(decodedKey)));
600  mac.reset(new HMAC<SHA1>((const byte *)decodedKey.data(), decodedKey.size()));
601  }
602  FileSource(file, true, new HashFilter(*mac, new HexEncoder(new FileSink(cout))));
603 }
604 
605 void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
606 {
607  SecByteBlock key = HexDecodeString(hexKey);
608  SecByteBlock iv = HexDecodeString(hexIV);
609  CTR_Mode<AES>::Encryption aes(key, key.size(), iv);
610  FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile)));
611 }
612 
613 string EncryptString(const char *instr, const char *passPhrase)
614 {
615  string outstr;
616 
617  DefaultEncryptorWithMAC encryptor(passPhrase, new HexEncoder(new StringSink(outstr)));
618  encryptor.Put((byte *)instr, strlen(instr));
619  encryptor.MessageEnd();
620 
621  return outstr;
622 }
623 
624 string DecryptString(const char *instr, const char *passPhrase)
625 {
626  string outstr;
627 
628  HexDecoder decryptor(new DefaultDecryptorWithMAC(passPhrase, new StringSink(outstr)));
629  decryptor.Put((byte *)instr, strlen(instr));
630  decryptor.MessageEnd();
631 
632  return outstr;
633 }
634 
635 void EncryptFile(const char *in, const char *out, const char *passPhrase)
636 {
637  FileSource f(in, true, new DefaultEncryptorWithMAC(passPhrase, new FileSink(out)));
638 }
639 
640 void DecryptFile(const char *in, const char *out, const char *passPhrase)
641 {
642  FileSource f(in, true, new DefaultDecryptorWithMAC(passPhrase, new FileSink(out)));
643 }
644 
645 void SecretShareFile(int threshold, int nShares, const char *filename, const char *seed)
646 {
647  CRYPTOPP_ASSERT(nShares >= 1 && nShares<=1000);
648  if (nShares < 1 || nShares > 1000)
649  throw InvalidArgument("SecretShareFile: " + IntToString(nShares) + " is not in range [1, 1000]");
650 
651  RandomPool rng;
652  rng.IncorporateEntropy((byte *)seed, strlen(seed));
653 
654  ChannelSwitch *channelSwitch = NULL;
655  FileSource source(filename, false, new SecretSharing(rng, threshold, nShares, channelSwitch = new ChannelSwitch));
656 
657  vector_member_ptrs<FileSink> fileSinks(nShares);
658  string channel;
659  for (int i=0; i<nShares; i++)
660  {
661  char extension[5] = ".000";
662  extension[1]='0'+byte(i/100);
663  extension[2]='0'+byte((i/10)%10);
664  extension[3]='0'+byte(i%10);
665  fileSinks[i].reset(new FileSink((string(filename)+extension).c_str()));
666 
667  channel = WordToString<word32>(i);
668  fileSinks[i]->Put((const byte *)channel.data(), 4);
669  channelSwitch->AddRoute(channel, *fileSinks[i], DEFAULT_CHANNEL);
670  }
671 
672  source.PumpAll();
673 }
674 
675 void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFilenames)
676 {
677  CRYPTOPP_ASSERT(threshold >= 1 && threshold <=1000);
678  if (threshold < 1 || threshold > 1000)
679  throw InvalidArgument("SecretRecoverFile: " + IntToString(threshold) + " is not in range [1, 1000]");
680 
681  SecretRecovery recovery(threshold, new FileSink(outFilename));
682 
683  vector_member_ptrs<FileSource> fileSources(threshold);
684  SecByteBlock channel(4);
685  int i;
686  for (i=0; i<threshold; i++)
687  {
688  fileSources[i].reset(new FileSource(inFilenames[i], false));
689  fileSources[i]->Pump(4);
690  fileSources[i]->Get(channel, 4);
691  fileSources[i]->Attach(new ChannelSwitch(recovery, string((char *)channel.begin(), 4)));
692  }
693 
694  while (fileSources[0]->Pump(256))
695  for (i=1; i<threshold; i++)
696  fileSources[i]->Pump(256);
697 
698  for (i=0; i<threshold; i++)
699  fileSources[i]->PumpAll();
700 }
701 
702 void InformationDisperseFile(int threshold, int nShares, const char *filename)
703 {
704  CRYPTOPP_ASSERT(threshold >= 1 && threshold <=1000);
705  if (threshold < 1 || threshold > 1000)
706  throw InvalidArgument("InformationDisperseFile: " + IntToString(nShares) + " is not in range [1, 1000]");
707 
708  ChannelSwitch *channelSwitch = NULL;
709  FileSource source(filename, false, new InformationDispersal(threshold, nShares, channelSwitch = new ChannelSwitch));
710 
711  vector_member_ptrs<FileSink> fileSinks(nShares);
712  string channel;
713  for (int i=0; i<nShares; i++)
714  {
715  char extension[5] = ".000";
716  extension[1]='0'+byte(i/100);
717  extension[2]='0'+byte((i/10)%10);
718  extension[3]='0'+byte(i%10);
719  fileSinks[i].reset(new FileSink((string(filename)+extension).c_str()));
720 
721  channel = WordToString<word32>(i);
722  fileSinks[i]->Put((const byte *)channel.data(), 4);
723  channelSwitch->AddRoute(channel, *fileSinks[i], DEFAULT_CHANNEL);
724  }
725 
726  source.PumpAll();
727 }
728 
729 void InformationRecoverFile(int threshold, const char *outFilename, char *const *inFilenames)
730 {
731  CRYPTOPP_ASSERT(threshold<=1000);
732  if (threshold < 1 || threshold > 1000)
733  throw InvalidArgument("InformationRecoverFile: " + IntToString(threshold) + " is not in range [1, 1000]");
734 
735  InformationRecovery recovery(threshold, new FileSink(outFilename));
736 
737  vector_member_ptrs<FileSource> fileSources(threshold);
738  SecByteBlock channel(4);
739  int i;
740  for (i=0; i<threshold; i++)
741  {
742  fileSources[i].reset(new FileSource(inFilenames[i], false));
743  fileSources[i]->Pump(4);
744  fileSources[i]->Get(channel, 4);
745  fileSources[i]->Attach(new ChannelSwitch(recovery, string((char *)channel.begin(), 4)));
746  }
747 
748  while (fileSources[0]->Pump(256))
749  for (i=1; i<threshold; i++)
750  fileSources[i]->Pump(256);
751 
752  for (i=0; i<threshold; i++)
753  fileSources[i]->PumpAll();
754 }
755 
756 void GzipFile(const char *in, const char *out, int deflate_level)
757 {
758 // FileSource(in, true, new Gzip(new FileSink(out), deflate_level));
759 
760  // use a filter graph to compare decompressed data with original
761  //
762  // Source ----> Gzip ------> Sink
763  // \ |
764  // \ Gunzip
765  // \ |
766  // \ v
767  // > ComparisonFilter
768 
769  EqualityComparisonFilter comparison;
770 
771  Gunzip gunzip(new ChannelSwitch(comparison, "0"));
772  gunzip.SetAutoSignalPropagation(0);
773 
774  FileSink sink(out);
775 
776  ChannelSwitch *cs;
777  Gzip gzip(cs = new ChannelSwitch(sink), deflate_level);
778  cs->AddDefaultRoute(gunzip);
779 
780  cs = new ChannelSwitch(gzip);
781  cs->AddDefaultRoute(comparison, "1");
782  FileSource source(in, true, cs);
783 
784  comparison.ChannelMessageSeriesEnd("0");
785  comparison.ChannelMessageSeriesEnd("1");
786 }
787 
788 void GunzipFile(const char *in, const char *out)
789 {
790  FileSource(in, true, new Gunzip(new FileSink(out)));
791 }
792 
793 void Base64Encode(const char *in, const char *out)
794 {
795  FileSource(in, true, new Base64Encoder(new FileSink(out)));
796 }
797 
798 void Base64Decode(const char *in, const char *out)
799 {
800  FileSource(in, true, new Base64Decoder(new FileSink(out)));
801 }
802 
803 void HexEncode(const char *in, const char *out)
804 {
805  FileSource(in, true, new HexEncoder(new FileSink(out)));
806 }
807 
808 void HexDecode(const char *in, const char *out)
809 {
810  FileSource(in, true, new HexDecoder(new FileSink(out)));
811 }
812 
813 void ForwardTcpPort(const char *sourcePortName, const char *destinationHost, const char *destinationPortName)
814 {
815  // Quiet warnings for Windows Phone and Windows Store builds
816  CRYPTOPP_UNUSED(sourcePortName), CRYPTOPP_UNUSED(destinationHost), CRYPTOPP_UNUSED(destinationPortName);
817 
818 #ifdef SOCKETS_AVAILABLE
819  SocketsInitializer sockInit;
820 
821  Socket sockListen, sockSource, sockDestination;
822 
823  int sourcePort = Socket::PortNameToNumber(sourcePortName);
824  int destinationPort = Socket::PortNameToNumber(destinationPortName);
825 
826  sockListen.Create();
827  sockListen.Bind(sourcePort);
828 
829  const int flag = 1;
830  int err = setsockopt(sockListen, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int));
831  CRYPTOPP_ASSERT(err == 0);
832  if(err != 0)
833  throw Socket::Err(sockListen, "setsockopt", sockListen.GetLastError());
834 
835  cout << "Listing on port " << sourcePort << ".\n";
836  sockListen.Listen();
837 
838  sockListen.Accept(sockSource);
839  cout << "Connection accepted on port " << sourcePort << ".\n";
840  sockListen.CloseSocket();
841 
842  cout << "Making connection to " << destinationHost << ", port " << destinationPort << ".\n";
843  sockDestination.Create();
844  sockDestination.Connect(destinationHost, destinationPort);
845 
846  cout << "Connection made to " << destinationHost << ", starting to forward.\n";
847 
848  SocketSource out(sockSource, false, new SocketSink(sockDestination));
849  SocketSource in(sockDestination, false, new SocketSink(sockSource));
850 
851  WaitObjectContainer waitObjects;
852 
853  while (!(in.SourceExhausted() && out.SourceExhausted()))
854  {
855  waitObjects.Clear();
856 
857  out.GetWaitObjects(waitObjects, CallStack("ForwardTcpPort - out", NULL));
858  in.GetWaitObjects(waitObjects, CallStack("ForwardTcpPort - in", NULL));
859 
860  waitObjects.Wait(INFINITE_TIME);
861 
862  if (!out.SourceExhausted())
863  {
864  cout << "o" << flush;
865  out.PumpAll2(false);
866  if (out.SourceExhausted())
867  cout << "EOF received on source socket.\n";
868  }
869 
870  if (!in.SourceExhausted())
871  {
872  cout << "i" << flush;
873  in.PumpAll2(false);
874  if (in.SourceExhausted())
875  cout << "EOF received on destination socket.\n";
876  }
877  }
878 #else
879  cout << "Socket support was not enabled at compile time.\n";
880  exit(-1);
881 #endif
882 }
883 
884 bool Validate(int alg, bool thorough, const char *seedInput)
885 {
886  bool result;
887 
888  // Some editors have problems with the '\0' character when redirecting output.
889  // seedInput is argv[3] when issuing 'cryptest.exe v all <seed>'
890  std::string seed = (seedInput ? seedInput : IntToString(time(NULL)));
891  seed.resize(16, ' ');
892 
894  prng.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
895 
896  PrintSeedAndThreads(seed);
897 
898  switch (alg)
899  {
900  case 0: result = ValidateAll(thorough); break;
901  case 1: result = TestSettings(); break;
902  case 2: result = TestOS_RNG(); break;
903  case 3: result = TestNIST_DRBG(); break;
904  case 4: result = ValidateMD5(); break;
905  case 5: result = ValidateSHA(); break;
906  case 6: result = ValidateDES(); break;
907  case 7: result = ValidateIDEA(); break;
908  case 8: result = ValidateARC4(); break;
909  case 9: result = ValidateRC5(); break;
910  case 10: result = ValidateBlowfish(); break;
911 // case 11: result = ValidateDiamond2(); break;
912  case 12: result = ValidateThreeWay(); break;
913  case 13: result = ValidateBBS(); break;
914  case 14: result = ValidateDH(); break;
915  case 15: result = ValidateRSA(); break;
916  case 16: result = ValidateElGamal(); break;
917  case 17: result = ValidateDSA(thorough); break;
918 // case 18: result = ValidateHAVAL(); break;
919  case 19: result = ValidateSAFER(); break;
920  case 20: result = ValidateLUC(); break;
921  case 21: result = ValidateRabin(); break;
922 // case 22: result = ValidateBlumGoldwasser(); break;
923  case 23: result = ValidateECP(); break;
924  case 24: result = ValidateEC2N(); break;
925 // case 25: result = ValidateMD5MAC(); break;
926  case 26: result = ValidateGOST(); break;
927  case 27: result = ValidateTiger(); break;
928  case 28: result = ValidateRIPEMD(); break;
929  case 29: result = ValidateHMAC(); break;
930 // case 30: result = ValidateXMACC(); break;
931  case 31: result = ValidateSHARK(); break;
932  case 32: result = ValidateLUC_DH(); break;
933  case 33: result = ValidateLUC_DL(); break;
934  case 34: result = ValidateSEAL(); break;
935  case 35: result = ValidateCAST(); break;
936  case 36: result = ValidateSquare(); break;
937  case 37: result = ValidateRC2(); break;
938  case 38: result = ValidateRC6(); break;
939  case 39: result = ValidateMARS(); break;
940  case 40: result = ValidateRW(); break;
941  case 41: result = ValidateMD2(); break;
942  case 42: result = ValidateNR(); break;
943  case 43: result = ValidateMQV(); break;
944  case 44: result = ValidateRijndael(); break;
945  case 45: result = ValidateTwofish(); break;
946  case 46: result = ValidateSerpent(); break;
947  case 47: result = ValidateCipherModes(); break;
948  case 48: result = ValidateCRC32(); break;
949  case 49: result = ValidateCRC32C(); break;
950  case 50: result = ValidateECDSA(); break;
951  case 51: result = ValidateECGDSA(); break;
952  case 52: result = ValidateXTR_DH(); break;
953  case 53: result = ValidateSKIPJACK(); break;
954  case 54: result = ValidateSHA2(); break;
955  case 55: result = ValidatePanama(); break;
956  case 56: result = ValidateAdler32(); break;
957  case 57: result = ValidateMD4(); break;
958  case 58: result = ValidatePBKDF(); break;
959  case 59: result = ValidateESIGN(); break;
960  case 60: result = ValidateDLIES(); break;
961  case 61: result = ValidateBaseCode(); break;
962  case 62: result = ValidateSHACAL2(); break;
963  case 63: result = ValidateCamellia(); break;
964  case 64: result = ValidateWhirlpool(); break;
965  case 65: result = ValidateTTMAC(); break;
966  case 66: result = ValidateSalsa(); break;
967  case 67: result = ValidateSosemanuk(); break;
968  case 68: result = ValidateVMAC(); break;
969  case 69: result = ValidateCCM(); break;
970  case 70: result = ValidateGCM(); break;
971  case 71: result = ValidateCMAC(); break;
972  case 72: result = ValidateHKDF(); break;
973  case 73: result = ValidateBLAKE2s(); break;
974  case 74: result = ValidateBLAKE2b(); break;
975  case 75: result = ValidatePoly1305(); break;
976  case 76: result = ValidateSipHash(); break;
977 
978 #if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
979  // http://github.com/weidai11/cryptopp/issues/92
980  case 9999: result = TestSecBlock(); break;
981  // http://github.com/weidai11/cryptopp/issues/64
982  case 9998: result = TestPolynomialMod2(); break;
983  // http://github.com/weidai11/cryptopp/issues/336
984  case 9997: result = TestIntegerBitops(); break;
985  // http://github.com/weidai11/cryptopp/issues/242
986  case 9996: result = TestHuffmanCodes(); break;
987  // http://github.com/weidai11/cryptopp/issues/346
988  case 9995: result = TestASN1Parse(); break;
989 #endif
990 
991  default: return false;
992  }
993 
994 // Safer functions on Windows for C&A, https://github.com/weidai11/cryptopp/issues/55
995 #if (CRYPTOPP_MSC_VERSION >= 1400)
996  tm localTime = {};
997  char timeBuf[64];
998  errno_t err;
999 
1000  const time_t endTime = time(NULL);
1001  err = localtime_s(&localTime, &endTime);
1002  CRYPTOPP_ASSERT(err == 0);
1003  err = asctime_s(timeBuf, sizeof(timeBuf), &localTime);
1004  CRYPTOPP_ASSERT(err == 0);
1005 
1006  cout << "\nTest ended at " << timeBuf;
1007 #else
1008  const time_t endTime = time(NULL);
1009  cout << "\nTest ended at " << asctime(localtime(&endTime));
1010 #endif
1011 
1012  cout << "Seed used was: " << seed << endl;
1013 
1014  return result;
1015 }
void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
Definition: randpool.cpp:26
Append input to a string object.
bool ValidateRW()
Definition: validat2.cpp:775
iterator end()
Provides an iterator pointing beyond the last element in the memory block.
Definition: secblock.h:507
CRYPTOPP_DLL MessageAuthenticationCode *CRYPTOPP_API NewIntegrityCheckingMAC()
Class object that calculates the MAC on the module.
Definition: fipstest.cpp:271
bool ValidateTwofish()
Definition: validat1.cpp:1960
bool ValidateRijndael()
Definition: validat1.cpp:1926
An invalid argument was detected.
Definition: cryptlib.h:184
void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename)
Definition: test.cpp:532
bool ValidateRC6()
Definition: validat1.cpp:1860
void HexDecode(const char *infile, const char *outfile)
Definition: test.cpp:808
bool ValidateIDEA()
Definition: validat1.cpp:1602
void InformationRecoverFile(int threshold, const char *outFilename, char *const *inFilenames)
Definition: test.cpp:729
bool ValidateTTMAC()
Definition: validat3.cpp:514
void AddRangeToSkip(unsigned int message, lword position, lword size, bool sortNow=true)
Adds a range to skip during processing.
Definition: filters.cpp:166
Randomness Pool based on AES-256.
Definition: randpool.h:49
bool ValidatePoly1305()
Definition: validat3.cpp:782
bool ValidateRC5()
Definition: validat1.cpp:1832
Filter wrapper for PK_Verifier.
Definition: filters.h:745
void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFilenames)
Definition: test.cpp:675
uint8_t byte
Definition: Common.h:57
bool SafeConvert(T1 from, T2 &to)
Tests whether a conversion from -> to is safe to perform.
Definition: misc.h:526
void BenchmarkAll(double t, double hertz)
Definition: bench1.cpp:248
bool ValidateCipherModes()
Definition: validat1.cpp:1299
SHA-256 message digest.
Definition: sha.h:39
Classes for RIPEMD message digest.
Class file for Randomness Pool.
bool ValidateSHACAL2()
Definition: validat1.cpp:2358
unsigned short word16
Definition: config.h:230
void ForwardTcpPort(const char *sourcePort, const char *destinationHost, const char *destinationPort)
Definition: test.cpp:813
const int MAX_PHRASE_LENGTH
Definition: test.cpp:76
bool ValidateDSA(bool thorough)
Definition: validat2.cpp:701
Implementation of Store interface.
Definition: files.h:80
Converts given data to base 16.
Definition: hex.h:16
#define T(i, x)
Tiger
Definition: tiger.h:16
int CRYPTOPP_API main(int argc, char *argv[])
Definition: test.cpp:134
GZIP Decompression (RFC 1952)
Definition: gzip.h:52
void PumpAll()
Pump all data to attached transformation.
Definition: filters.h:1270
bool ValidateWhirlpool()
Definition: validat3.cpp:370
Base64 decodes data.
Definition: base64.h:59
SecByteBlock HexDecodeString(const char *hex)
Definition: test.cpp:485
Decode base 16 data back to bytes.
Definition: hex.h:36
Abstract base classes that provide a uniform interface to this library.
RIPEMD-160 message digest.
Definition: ripemd.h:17
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
Definition: test.cpp:493
bool ValidateHKDF()
Definition: validat3.cpp:688
void AddDefaultRoute(BufferedTransformation &destination)
Definition: channels.cpp:262
void RegisterFactories()
Definition: regtest.cpp:71
size_type size() const
Provides the count of elements in the SecBlock.
Definition: secblock.h:524
bool ValidateCRC32()
Definition: validat3.cpp:95
RandomNumberGenerator & GlobalRNG()
Definition: test.cpp:123
void FIPS140_SampleApplication()
Definition: dlltest.cpp:12
bool ValidateSosemanuk()
Definition: validat1.cpp:2430
bool ValidateThreeWay()
Definition: validat1.cpp:2082
Classes for automatic resource management.
Filter wrapper for PK_Signer.
Definition: filters.h:717
Classes for DefaultEncryptor, DefaultDecryptor, DefaultEncryptorWithMAC and DefaultDecryptorWithMAC.
bool ValidateECGDSA()
Definition: validat2.cpp:1062
bool ValidateSAFER()
Definition: validat1.cpp:1610
std::hash for asio::adress
Definition: Common.h:323
Interface for random number generators.
Definition: cryptlib.h:1188
bool ValidateBLAKE2s()
Definition: validat3.cpp:1080
string RSAEncryptString(const char *pubFilename, const char *seed, const char *message)
Definition: test.cpp:509
bool ValidateElGamal()
Definition: validat2.cpp:638
DataEncryptorWithMAC< DefaultBlockCipher, DefaultHashModule, DefaultMAC, DefaultParametersInfo > DefaultEncryptorWithMAC
Definition: default.h:308
void Base64Encode(const char *infile, const char *outfile)
Definition: test.cpp:793
Route input to different and/or multiple channels based on channel ID.
Definition: channels.h:92
bool ValidateCCM()
Definition: validat1.cpp:2442
bool ValidateRC2()
Definition: validat1.cpp:1623
bool ValidateMQV()
Definition: validat2.cpp:377
bool ValidatePanama()
Definition: validat3.cpp:365
Pointer that overloads operator ->
Definition: smartptr.h:39
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.cpp:59
Base64 encodes data.
Definition: base64.h:17
bool MessageEnd(int propagation=-1, bool blocking=true)
Signals the end of messages to the object.
Definition: cryptlib.h:1434
bool ValidateMD4()
Definition: validat3.cpp:173
bool TestOS_RNG()
Definition: validat1.cpp:345
Copy input to a memory buffer.
Definition: filters.h:1101
bool ValidateESIGN()
Definition: validat2.cpp:1404
T StringToValue(const std::string &str)
Definition: test.cpp:437
bool ValidateBLAKE2b()
Definition: validat3.cpp:1475
void GzipFile(const char *in, const char *out, int deflate_level)
Definition: test.cpp:756
bool ValidateARC4()
Definition: validat1.cpp:1664
GZIP compression and decompression (RFC 1952)
bool ValidateVMAC()
Definition: validat1.cpp:2436
const char * source
Definition: rpcconsole.cpp:60
lword TransferTo(BufferedTransformation &target, lword transferMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL)
move transferMax bytes of the buffered output to target as input
Definition: cryptlib.h:1654
void SetAutoSignalPropagation(int propagation)
Definition: simple.h:287
void BenchmarkAll2(double t, double hertz)
Definition: bench2.cpp:271
Filter wrapper for HashTransformation.
Definition: filters.h:521
Password-based encryptor with MAC.
Definition: default.h:180
RNG-based implementation of Source interface.
Definition: filters.h:1186
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition: cryptlib.h:1376
bool ValidateDH()
Definition: validat2.cpp:368
Block cipher mode of operation aggregate.
Definition: modes.h:285
int(* AdhocTest)(int argc, char *argv[])
Definition: test.cpp:120
Utility class for trapping OS signals.
string EncryptString(const char *plaintext, const char *passPhrase)
Definition: test.cpp:613
signed long ConvertToLong() const
Convert the Integer to Long.
Definition: integer.cpp:2946
string DecryptString(const char *ciphertext, const char *passPhrase)
Definition: test.cpp:624
Whirlpool
Definition: whrlpool.h:10
bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true)
Marks the end of a series of messages on a channel.
Definition: mqueue.cpp:135
void HexEncode(const char *infile, const char *outfile)
Definition: test.cpp:803
Maurer&#39;s Universal Statistical Test for Random Bit Generators.
Definition: rng.h:84
SHA-512 message digest.
Definition: sha.h:69
bool ValidatePBKDF()
Definition: validat3.cpp:602
Class file for the AES cipher (Rijndael)
bool ValidateAll(bool thorough)
Definition: validat1.cpp:70
void InformationDisperseFile(int threshold, int nShares, const char *filename)
Definition: test.cpp:702
bool ValidateSHA2()
Definition: validat3.cpp:217
Manages resources for an array of objects.
Definition: smartptr.h:284
bool Validate(int, bool, const char *)
Definition: test.cpp:884
Multiple precision integer with arithmetic operations.
Definition: integer.h:43
bool ValidateEC2N()
Definition: validat2.cpp:962
SHA-1 message digest.
Definition: sha.h:25
bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename)
Definition: test.cpp:539
bool ValidateSEAL()
Definition: validat1.cpp:2263
#define CRYPTOPP_API
Definition: config.h:705
Filter wrapper for PK_Decryptor.
Definition: filters.h:1022
bool ValidateCAST()
Definition: validat1.cpp:2156
void GunzipFile(const char *in, const char *out)
Definition: test.cpp:788
bool ValidateGCM()
Definition: validat1.cpp:2448
bool ValidateCMAC()
Definition: validat1.cpp:2457
bool ValidateSipHash()
Definition: validat3.cpp:900
bool ValidateSquare()
Definition: validat1.cpp:2219
Classes and functions for registering and locating library objects.
bool ValidateSerpent()
Definition: validat1.cpp:1989
Miscellaneous classes for RNGs.
bool TestNIST_DRBG()
Definition: validat1.cpp:753
void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
Definition: test.cpp:605
DataDecryptorWithMAC< DefaultBlockCipher, DefaultHashModule, DefaultMAC, DefaultParametersInfo > DefaultDecryptorWithMAC
Definition: default.h:309
bool ValidateBaseCode()
Definition: validat1.cpp:2291
bool ValidateRSA()
Definition: validat2.cpp:281
void FIPS140_GenerateRandomFiles()
Definition: test.cpp:422
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
void PrintSeedAndThreads(const std::string &seed)
Definition: test.cpp:470
bool ValidateHMAC()
Definition: validat3.cpp:440
bool ValidateBlowfish()
Definition: validat1.cpp:2019
bool ValidateLUC_DL()
Definition: validat2.cpp:737
const unsigned long INFINITE_TIME
Represents infinite time.
Definition: cryptlib.h:111
bool ValidateSHARK()
Definition: validat1.cpp:2130
bool GetLastResult() const
Retrieves the result of the last verification.
Definition: filters.h:788
iterator begin()
Provides an iterator pointing to the first element in the memory block.
Definition: secblock.h:499
void DecryptFile(const char *in, const char *out, const char *passPhrase)
Definition: test.cpp:640
bool ValidateCamellia()
Definition: validat1.cpp:2390
Implementation of BufferedTransformation&#39;s attachment interface.
bool ValidateSKIPJACK()
Definition: validat1.cpp:2241
Implementation of Store interface.
Definition: files.h:23
#define f(x)
Definition: gost.cpp:57
int StringToValue< int, true >(const std::string &str)
Definition: test.cpp:458
bool TestSettings()
Definition: validat1.cpp:184
#define USING_NAMESPACE(x)
Definition: config.h:206
Filter wrapper for PK_Encryptor.
Definition: filters.h:1007
Classes for the Base64Encoder, Base64Decoder, Base64URLEncoder and Base64URLDecoder.
Filter wrapper for StreamTransformation.
Definition: filters.h:491
#define CRYPTOPP_DUMMY_DLL_MAC
The placeholder used prior to embedding the actual MAC in the module.
Definition: fips140.h:109
bool ValidateECP()
Definition: validat2.cpp:913
bool ValidateMD5()
Definition: validat3.cpp:192
void TransferAllTo(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL)
Transfer all bytes from this object to another BufferedTransformation.
Definition: cryptlib.h:1763
Internal SHA-512 implementation.
Definition: sha512.cpp:15
bool ValidateAdler32()
Definition: validat3.cpp:135
HMAC.
Definition: hmac.h:50
T * release()
Definition: smartptr.h:55
virtual unsigned int DigestSize() const =0
Provides the digest size of the hash.
Rabin&#39;s Information Dispersal Algorithm.
Definition: ida.h:147
bool ValidateDLIES()
Definition: validat2.cpp:656
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
h256 sha256(bytesConstRef _input)
Definition: Hash.cpp:33
Debugging and diagnostic assertions.
void Base64Decode(const char *infile, const char *outfile)
Definition: test.cpp:798
uint8_t byte
Definition: Common.h:10
SignatureVerificationFilter VerifierFilter
Definition: filters.h:804
#define CRYPTOPP_VERSION
Definition: config.h:66
bool ValidateLUC()
Definition: validat2.cpp:718
bool ValidateGOST()
Definition: validat1.cpp:2104
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:539
Measure how many bytes and messages pass through the filter.
Definition: filters.h:220
bool ValidateTiger()
Definition: validat3.cpp:223
bool ValidateNR()
Definition: validat2.cpp:679
virtual lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: cryptlib.cpp:496
size_t size() const
Definition: smartptr.h:300
size_t PutMessageEnd(const byte *inString, size_t length, int propagation=-1, bool blocking=true)
Input multiple bytes for processing and signal the end of a message.
Definition: cryptlib.h:1447
string RSADecryptString(const char *privFilename, const char *ciphertext)
Definition: test.cpp:522
#define e(i)
Definition: sha.cpp:733
A filter that checks messages on two channels for equality.
Definition: mqueue.h:71
bool ValidateSHA()
Definition: validat3.cpp:211
bool ValidateBBS()
Definition: validat2.cpp:74
bool ValidateSalsa()
Definition: validat1.cpp:2423
bool ValidateRIPEMD()
Definition: validat3.cpp:245
virtual size_t Get(byte &outByte)
Retrieve a 8-bit byte.
Definition: cryptlib.cpp:515
bool RunTestDataFile(const char *filename, const NameValuePairs &overrideParameters, bool thorough)
Definition: datatest.cpp:841
GZIP Compression (RFC 1952)
Definition: gzip.h:18
bool ValidateLUC_DH()
Definition: validat2.cpp:620
bool ValidateECDSA()
Definition: validat2.cpp:1011
double GetTestValue() const
Definition: rng.cpp:152
Shamir&#39;s Secret Sharing Algorithm.
Definition: ida.h:97
unsigned int word32
Definition: config.h:231
void EncryptFile(const char *in, const char *out, const char *passPhrase)
Definition: test.cpp:635
Implementation of Store interface.
Definition: files.h:125
bool ValidateCRC32C()
Definition: validat3.cpp:115
bool ValidateDES()
Definition: validat1.cpp:1253
Functions and definitions required for building the FIPS-140 DLL on Windows.
bool ValidateXTR_DH()
Definition: validat2.cpp:629
a variant of Rabin&#39;s Information Dispersal Algorithm
Definition: ida.h:121
void HmacFile(const char *hexKey, const char *file)
Definition: test.cpp:588
#define CRYPTOPP_DATA_DIR
Definition: config.h:72
void reset(T *p=0)
Definition: smartptr.h:72
Shamir&#39;s Secret Sharing Algorithm.
Definition: ida.h:71
bool ValidateMD2()
Definition: validat3.cpp:154
bool ValidateMARS()
Definition: validat1.cpp:1893
void DigestFile(const char *file)
Definition: test.cpp:557
bool ValidateRabin()
Definition: validat2.cpp:756
Classes for Rabin&#39;s Information Dispersal and Shamir&#39;s Secret Sharing algorithms. ...
void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel)
Definition: channels.cpp:292
void SecretShareFile(int threshold, int nShares, const char *filename, const char *seed)
Definition: test.cpp:645
Template implementing constructors for public key algorithm classes.
Definition: pubkey.h:1989