Fabcoin Core  0.16.2
P2P Digital Currency
cryptlib.cpp
Go to the documentation of this file.
1 // cryptlib.cpp - written and placed in the public domain by Wei Dai
2 
3 #include "pch.h"
4 #include "config.h"
5 
6 #if CRYPTOPP_MSC_VERSION
7 # pragma warning(disable: 4127 4189 4459)
8 #endif
9 
10 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
11 # pragma GCC diagnostic ignored "-Wunused-value"
12 # pragma GCC diagnostic ignored "-Wunused-variable"
13 # pragma GCC diagnostic ignored "-Wunused-parameter"
14 #endif
15 
16 #ifndef CRYPTOPP_IMPORTS
17 
18 #include "cryptlib.h"
19 #include "misc.h"
20 #include "filters.h"
21 #include "algparam.h"
22 #include "fips140.h"
23 #include "argnames.h"
24 #include "fltrimpl.h"
25 #include "trdlocal.h"
26 #include "osrng.h"
27 #include "secblock.h"
28 #include "smartptr.h"
29 
30 // http://www.cygwin.com/faq.html#faq.api.winsock
31 #if (defined(__CYGWIN__) || defined(__CYGWIN32__)) && defined(PREFER_WINDOWS_STYLE_SOCKETS)
32 # error Cygwin does not support Windows style sockets. See http://www.cygwin.com/faq.html#faq.api.winsock
33 #endif
34 
36 
37 CRYPTOPP_COMPILE_ASSERT(sizeof(byte) == 1);
38 CRYPTOPP_COMPILE_ASSERT(sizeof(word16) == 2);
39 CRYPTOPP_COMPILE_ASSERT(sizeof(word32) == 4);
40 CRYPTOPP_COMPILE_ASSERT(sizeof(word64) == 8);
41 #ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE
42 CRYPTOPP_COMPILE_ASSERT(sizeof(dword) == 2*sizeof(word));
43 #endif
44 
45 #if HAVE_GCC_INIT_PRIORITY
47 const std::string DEFAULT_CHANNEL __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 25))) = "";
48 const std::string AAD_CHANNEL __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 26))) = "AAD";
50 #elif HAVE_MSC_INIT_PRIORITY
51 #pragma warning(disable: 4073)
52 #pragma init_seg(lib)
53 const std::string DEFAULT_CHANNEL = "";
54 const std::string AAD_CHANNEL = "AAD";
55 const std::string &BufferedTransformation::NULL_CHANNEL = DEFAULT_CHANNEL;
56 #pragma warning(default: 4073)
57 #else
58 static const std::string s1(""), s2("AAD");
59 const std::string DEFAULT_CHANNEL = s1;
60 const std::string AAD_CHANNEL = s2;
61 const std::string &BufferedTransformation::NULL_CHANNEL = DEFAULT_CHANNEL;
62 #endif
63 
65 {
66 public:
67  bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
68  {CRYPTOPP_UNUSED(name); CRYPTOPP_UNUSED(valueType); CRYPTOPP_UNUSED(pValue); return false;}
69 };
70 
71 #if HAVE_GCC_INIT_PRIORITY
74 #else
76 const NameValuePairs &g_nullNameValuePairs = *s_pNullNameValuePairs.m_p;
77 #endif
78 
80 {
81  static BitBucket bitBucket;
82  return bitBucket;
83 }
84 
85 Algorithm::Algorithm(bool checkSelfTestStatus)
86 {
87  if (checkSelfTestStatus && FIPS_140_2_ComplianceEnabled())
88  {
90  throw SelfTestFailure("Cryptographic algorithms are disabled before the power-up self tests are performed.");
91 
93  throw SelfTestFailure("Cryptographic algorithms are disabled after a power-up self test failed.");
94  }
95 }
96 
97 void SimpleKeyingInterface::SetKey(const byte *key, size_t length, const NameValuePairs &params)
98 {
99  this->ThrowIfInvalidKeyLength(length);
100  this->UncheckedSetKey(key, (unsigned int)length, params);
101 }
102 
103 void SimpleKeyingInterface::SetKeyWithRounds(const byte *key, size_t length, int rounds)
104 {
105  SetKey(key, length, MakeParameters(Name::Rounds(), rounds));
106 }
107 
108 void SimpleKeyingInterface::SetKeyWithIV(const byte *key, size_t length, const byte *iv, size_t ivLength)
109 {
110  SetKey(key, length, MakeParameters(Name::IV(), ConstByteArrayParameter(iv, ivLength)));
111 }
112 
114 {
115  if (!IsValidKeyLength(length))
116  throw InvalidKeyLength(GetAlgorithm().AlgorithmName(), length);
117 }
118 
120 {
121  if (IsResynchronizable())
122  throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object requires an IV");
123 }
124 
126 {
127  if (!iv && IVRequirement() == UNPREDICTABLE_RANDOM_IV)
128  throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object cannot use a null IV");
129 }
130 
132 {
133  if (size < 0)
134  return (size_t)IVSize();
135  else if ((size_t)size < MinIVLength())
136  throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(size) + " is less than the minimum of " + IntToString(MinIVLength()));
137  else if ((size_t)size > MaxIVLength())
138  throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(size) + " exceeds the maximum of " + IntToString(MaxIVLength()));
139  else
140  return (size_t)size;
141 }
142 
144 {
145  ConstByteArrayParameter ivWithLength;
146  const byte *iv;
147  bool found = false;
148 
149  try {found = params.GetValue(Name::IV(), ivWithLength);}
150  catch (const NameValuePairs::ValueTypeMismatch &) {}
151 
152  if (found)
153  {
154  iv = ivWithLength.begin();
155  ThrowIfInvalidIV(iv);
156  size = ThrowIfInvalidIVLength((int)ivWithLength.size());
157  return iv;
158  }
159  else if (params.GetValue(Name::IV(), iv))
160  {
161  ThrowIfInvalidIV(iv);
162  size = IVSize();
163  return iv;
164  }
165  else
166  {
167  ThrowIfResynchronizable();
168  size = 0;
169  return NULL;
170  }
171 }
172 
174 {
175  rng.GenerateBlock(IV, IVSize());
176 }
177 
178 size_t BlockTransformation::AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const
179 {
180  CRYPTOPP_ASSERT(inBlocks);
181  CRYPTOPP_ASSERT(outBlocks);
182  CRYPTOPP_ASSERT(length);
183 
184  size_t blockSize = BlockSize();
185  size_t inIncrement = (flags & (BT_InBlockIsCounter|BT_DontIncrementInOutPointers)) ? 0 : blockSize;
186  size_t xorIncrement = xorBlocks ? blockSize : 0;
187  size_t outIncrement = (flags & BT_DontIncrementInOutPointers) ? 0 : blockSize;
188 
189  if (flags & BT_ReverseDirection)
190  {
191  CRYPTOPP_ASSERT(length % blockSize == 0);
192  inBlocks += length - blockSize;
193  xorBlocks += length - blockSize;
194  outBlocks += length - blockSize;
195  inIncrement = 0-inIncrement;
196  xorIncrement = 0-xorIncrement;
197  outIncrement = 0-outIncrement;
198  }
199 
200  while (length >= blockSize)
201  {
202  if (flags & BT_XorInput)
203  {
204  // Coverity finding. However, xorBlocks is never NULL if BT_XorInput.
205  CRYPTOPP_ASSERT(xorBlocks);
206 #if defined(__COVERITY__)
207  if (xorBlocks)
208 #endif
209  xorbuf(outBlocks, xorBlocks, inBlocks, blockSize);
210  ProcessBlock(outBlocks);
211  }
212  else
213  {
214  // xorBlocks can be NULL. See, for example, ECB_OneWay::ProcessData.
215  ProcessAndXorBlock(inBlocks, xorBlocks, outBlocks);
216  }
217 
218  if (flags & BT_InBlockIsCounter)
219  const_cast<byte *>(inBlocks)[blockSize-1]++;
220  inBlocks += inIncrement;
221  outBlocks += outIncrement;
222  xorBlocks += xorIncrement;
223  length -= blockSize;
224  }
225 
226  return length;
227 }
228 
230 {
231  return GetAlignmentOf<word32>();
232 }
233 
235 {
236  return GetAlignmentOf<word32>();
237 }
238 
240 {
241  return GetAlignmentOf<word32>();
242 }
243 
244 void StreamTransformation::ProcessLastBlock(byte *outString, const byte *inString, size_t length)
245 {
246  CRYPTOPP_ASSERT(MinLastBlockSize() == 0); // this function should be overridden otherwise
247 
248  if (length == MandatoryBlockSize())
249  ProcessData(outString, inString, length);
250  else if (length != 0)
251  throw NotImplemented(AlgorithmName() + ": this object doesn't support a special last block");
252 }
253 
254 void AuthenticatedSymmetricCipher::SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
255 {
256  if (headerLength > MaxHeaderLength())
257  throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": header length " + IntToString(headerLength) + " exceeds the maximum of " + IntToString(MaxHeaderLength()));
258 
259  if (messageLength > MaxMessageLength())
260  throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": message length " + IntToString(messageLength) + " exceeds the maximum of " + IntToString(MaxMessageLength()));
261 
262  if (footerLength > MaxFooterLength())
263  throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": footer length " + IntToString(footerLength) + " exceeds the maximum of " + IntToString(MaxFooterLength()));
264 
265  UncheckedSpecifyDataLengths(headerLength, messageLength, footerLength);
266 }
267 
268 void AuthenticatedSymmetricCipher::EncryptAndAuthenticate(byte *ciphertext, byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *message, size_t messageLength)
269 {
270  Resynchronize(iv, ivLength);
271  SpecifyDataLengths(headerLength, messageLength);
272  Update(header, headerLength);
273  ProcessString(ciphertext, message, messageLength);
274  TruncatedFinal(mac, macSize);
275 }
276 
277 bool AuthenticatedSymmetricCipher::DecryptAndVerify(byte *message, const byte *mac, size_t macLength, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *ciphertext, size_t ciphertextLength)
278 {
279  Resynchronize(iv, ivLength);
280  SpecifyDataLengths(headerLength, ciphertextLength);
281  Update(header, headerLength);
282  ProcessString(message, ciphertext, ciphertextLength);
283  return TruncatedVerify(mac, macLength);
284 }
285 
287 {
288  return GenerateByte() & 1;
289 }
290 
292 {
293  byte b;
294  GenerateBlock(&b, 1);
295  return b;
296 }
297 
299 {
300  const word32 range = max-min;
301  const unsigned int maxBits = BitPrecision(range);
302 
303  word32 value;
304 
305  do
306  {
307  GenerateBlock((byte *)&value, sizeof(value));
308  value = Crop(value, maxBits);
309  } while (value > range);
310 
311  return value+min;
312 }
313 
314 // Stack recursion below... GenerateIntoBufferedTransformation calls GenerateBlock,
315 // and GenerateBlock calls GenerateIntoBufferedTransformation. Ad infinitum. Also
316 // see https://github.com/weidai11/cryptopp/issues/38.
317 //
318 // According to Wei, RandomNumberGenerator is an interface, and it should not
319 // be instantiable. Its now spilt milk, and we are going to CRYPTOPP_ASSERT it in Debug
320 // builds to alert the programmer and throw in Release builds. Developers have
321 // a reference implementation in case its needed. If a programmer
322 // unintentionally lands here, then they should ensure use of a
323 // RandomNumberGenerator pointer or reference so polymorphism can provide the
324 // proper runtime dispatching.
325 
326 void RandomNumberGenerator::GenerateBlock(byte *output, size_t size)
327 {
328  CRYPTOPP_UNUSED(output), CRYPTOPP_UNUSED(size);
329 
330 #if 0
331  // This breaks AutoSeededX917RNG<T> generators.
332  throw NotImplemented("RandomNumberGenerator: GenerateBlock not implemented");
333 #endif
334 
335  ArraySink s(output, size);
336  GenerateIntoBufferedTransformation(s, DEFAULT_CHANNEL, size);
337 }
338 
340 {
341  GenerateIntoBufferedTransformation(TheBitBucket(), DEFAULT_CHANNEL, n);
342 }
343 
345 {
347  while (length)
348  {
349  size_t len = UnsignedMin(buffer.size(), length);
350  GenerateBlock(buffer, len);
351  size_t rem = target.ChannelPut(channel, buffer, len);
352  CRYPTOPP_UNUSED(rem); CRYPTOPP_ASSERT(rem == 0);
353  length -= len;
354  }
355 }
356 
363 {
364 public:
367  std::string AlgorithmName() const {return "NullRNG";}
368 
369 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
370  byte GenerateByte () {}
373  unsigned int GenerateBit () {}
375  word32 GenerateWord32 (word32 min, word32 max) {}
376 #endif
377 
379  void GenerateBlock(byte *output, size_t size)
380  {
381  CRYPTOPP_UNUSED(output); CRYPTOPP_UNUSED(size);
382  throw NotImplemented("NullRNG: NullRNG should only be passed to functions that don't need to generate random bytes");
383  }
384 
385 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
386  void GenerateIntoBufferedTransformation (BufferedTransformation &target, const std::string &channel, lword length) {}
389  void IncorporateEntropy (const byte *input, size_t length) {}
391  bool CanIncorporateEntropy () const {}
393  void DiscardBytes (size_t n) {}
395  void Shuffle (IT begin, IT end) {}
396 
397 private:
398  Clonable* Clone () const { return NULL; }
399 #endif
400 };
401 
403 {
404  static ClassNullRNG s_nullRNG;
405  return s_nullRNG;
406 }
407 
408 bool HashTransformation::TruncatedVerify(const byte *digestIn, size_t digestLength)
409 {
410  ThrowIfInvalidTruncatedSize(digestLength);
411  SecByteBlock digest(digestLength);
412  TruncatedFinal(digest, digestLength);
413  return VerifyBufsEqual(digest, digestIn, digestLength);
414 }
415 
417 {
418  if (size > DigestSize())
419  throw InvalidArgument("HashTransformation: can't truncate a " + IntToString(DigestSize()) + " byte digest to " + IntToString(size) + " bytes");
420 }
421 
423 {
424  const BufferedTransformation *t = AttachedTransformation();
425  return t ? t->GetMaxWaitObjectCount() : 0;
426 }
427 
429 {
430  BufferedTransformation *t = AttachedTransformation();
431  if (t)
432  t->GetWaitObjects(container, callStack); // reduce clutter by not adding to stack here
433 }
434 
436 {
437  CRYPTOPP_UNUSED(propagation);
438  CRYPTOPP_ASSERT(!AttachedTransformation());
439  IsolatedInitialize(parameters);
440 }
441 
442 bool BufferedTransformation::Flush(bool hardFlush, int propagation, bool blocking)
443 {
444  CRYPTOPP_UNUSED(propagation);
445  CRYPTOPP_ASSERT(!AttachedTransformation());
446  return IsolatedFlush(hardFlush, blocking);
447 }
448 
449 bool BufferedTransformation::MessageSeriesEnd(int propagation, bool blocking)
450 {
451  CRYPTOPP_UNUSED(propagation);
452  CRYPTOPP_ASSERT(!AttachedTransformation());
453  return IsolatedMessageSeriesEnd(blocking);
454 }
455 
456 byte * BufferedTransformation::ChannelCreatePutSpace(const std::string &channel, size_t &size)
457 {
458  if (channel.empty())
459  return CreatePutSpace(size);
460  else
461  throw NoChannelSupport(AlgorithmName());
462 }
463 
464 size_t BufferedTransformation::ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
465 {
466  if (channel.empty())
467  return Put2(begin, length, messageEnd, blocking);
468  else
469  throw NoChannelSupport(AlgorithmName());
470 }
471 
472 size_t BufferedTransformation::ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
473 {
474  if (channel.empty())
475  return PutModifiable2(begin, length, messageEnd, blocking);
476  else
477  return ChannelPut2(channel, begin, length, messageEnd, blocking);
478 }
479 
480 bool BufferedTransformation::ChannelFlush(const std::string &channel, bool completeFlush, int propagation, bool blocking)
481 {
482  if (channel.empty())
483  return Flush(completeFlush, propagation, blocking);
484  else
485  throw NoChannelSupport(AlgorithmName());
486 }
487 
488 bool BufferedTransformation::ChannelMessageSeriesEnd(const std::string &channel, int propagation, bool blocking)
489 {
490  if (channel.empty())
491  return MessageSeriesEnd(propagation, blocking);
492  else
493  throw NoChannelSupport(AlgorithmName());
494 }
495 
497 {
498  if (AttachedTransformation())
499  return AttachedTransformation()->MaxRetrievable();
500  else
501  return CopyTo(TheBitBucket());
502 }
503 
505 {
506  if (AttachedTransformation())
507  return AttachedTransformation()->AnyRetrievable();
508  else
509  {
510  byte b;
511  return Peek(b) != 0;
512  }
513 }
514 
515 size_t BufferedTransformation::Get(byte &outByte)
516 {
517  if (AttachedTransformation())
518  return AttachedTransformation()->Get(outByte);
519  else
520  return Get(&outByte, 1);
521 }
522 
523 size_t BufferedTransformation::Get(byte *outString, size_t getMax)
524 {
525  if (AttachedTransformation())
526  return AttachedTransformation()->Get(outString, getMax);
527  else
528  {
529  ArraySink arraySink(outString, getMax);
530  return (size_t)TransferTo(arraySink, getMax);
531  }
532 }
533 
534 size_t BufferedTransformation::Peek(byte &outByte) const
535 {
536  if (AttachedTransformation())
537  return AttachedTransformation()->Peek(outByte);
538  else
539  return Peek(&outByte, 1);
540 }
541 
542 size_t BufferedTransformation::Peek(byte *outString, size_t peekMax) const
543 {
544  if (AttachedTransformation())
545  return AttachedTransformation()->Peek(outString, peekMax);
546  else
547  {
548  ArraySink arraySink(outString, peekMax);
549  return (size_t)CopyTo(arraySink, peekMax);
550  }
551 }
552 
554 {
555  if (AttachedTransformation())
556  return AttachedTransformation()->Skip(skipMax);
557  else
558  return TransferTo(TheBitBucket(), skipMax);
559 }
560 
562 {
563  if (AttachedTransformation())
564  return AttachedTransformation()->TotalBytesRetrievable();
565  else
566  return MaxRetrievable();
567 }
568 
570 {
571  if (AttachedTransformation())
572  return AttachedTransformation()->NumberOfMessages();
573  else
574  return CopyMessagesTo(TheBitBucket());
575 }
576 
578 {
579  if (AttachedTransformation())
580  return AttachedTransformation()->AnyMessages();
581  else
582  return NumberOfMessages() != 0;
583 }
584 
586 {
587  if (AttachedTransformation())
588  return AttachedTransformation()->GetNextMessage();
589  else
590  {
591  CRYPTOPP_ASSERT(!AnyMessages());
592  return false;
593  }
594 }
595 
596 unsigned int BufferedTransformation::SkipMessages(unsigned int count)
597 {
598  if (AttachedTransformation())
599  return AttachedTransformation()->SkipMessages(count);
600  else
601  return TransferMessagesTo(TheBitBucket(), count);
602 }
603 
604 size_t BufferedTransformation::TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel, bool blocking)
605 {
606  if (AttachedTransformation())
607  return AttachedTransformation()->TransferMessagesTo2(target, messageCount, channel, blocking);
608  else
609  {
610  unsigned int maxMessages = messageCount;
611  for (messageCount=0; messageCount < maxMessages && AnyMessages(); messageCount++)
612  {
613  size_t blockedBytes;
614  lword transferredBytes;
615 
616  while (AnyRetrievable())
617  {
618  transferredBytes = LWORD_MAX;
619  blockedBytes = TransferTo2(target, transferredBytes, channel, blocking);
620  if (blockedBytes > 0)
621  return blockedBytes;
622  }
623 
624  if (target.ChannelMessageEnd(channel, GetAutoSignalPropagation(), blocking))
625  return 1;
626 
627  bool result = GetNextMessage();
628  CRYPTOPP_UNUSED(result); CRYPTOPP_ASSERT(result);
629  }
630  return 0;
631  }
632 }
633 
634 unsigned int BufferedTransformation::CopyMessagesTo(BufferedTransformation &target, unsigned int count, const std::string &channel) const
635 {
636  if (AttachedTransformation())
637  return AttachedTransformation()->CopyMessagesTo(target, count, channel);
638  else
639  return 0;
640 }
641 
643 {
644  if (AttachedTransformation())
645  AttachedTransformation()->SkipAll();
646  else
647  {
648  while (SkipMessages()) {}
649  while (Skip()) {}
650  }
651 }
652 
653 size_t BufferedTransformation::TransferAllTo2(BufferedTransformation &target, const std::string &channel, bool blocking)
654 {
655  if (AttachedTransformation())
656  return AttachedTransformation()->TransferAllTo2(target, channel, blocking);
657  else
658  {
659  CRYPTOPP_ASSERT(!NumberOfMessageSeries());
660 
661  unsigned int messageCount;
662  do
663  {
664  messageCount = UINT_MAX;
665  size_t blockedBytes = TransferMessagesTo2(target, messageCount, channel, blocking);
666  if (blockedBytes)
667  return blockedBytes;
668  }
669  while (messageCount != 0);
670 
671  lword byteCount;
672  do
673  {
674  byteCount = ULONG_MAX;
675  size_t blockedBytes = TransferTo2(target, byteCount, channel, blocking);
676  if (blockedBytes)
677  return blockedBytes;
678  }
679  while (byteCount != 0);
680 
681  return 0;
682  }
683 }
684 
685 void BufferedTransformation::CopyAllTo(BufferedTransformation &target, const std::string &channel) const
686 {
687  if (AttachedTransformation())
688  AttachedTransformation()->CopyAllTo(target, channel);
689  else
690  {
691  CRYPTOPP_ASSERT(!NumberOfMessageSeries());
692  while (CopyMessagesTo(target, UINT_MAX, channel)) {}
693  }
694 }
695 
696 void BufferedTransformation::SetRetrievalChannel(const std::string &channel)
697 {
698  if (AttachedTransformation())
699  AttachedTransformation()->SetRetrievalChannel(channel);
700 }
701 
702 size_t BufferedTransformation::ChannelPutWord16(const std::string &channel, word16 value, ByteOrder order, bool blocking)
703 {
704  PutWord(false, order, m_buf, value);
705  return ChannelPut(channel, m_buf, 2, blocking);
706 }
707 
708 size_t BufferedTransformation::ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order, bool blocking)
709 {
710  PutWord(false, order, m_buf, value);
711  return ChannelPut(channel, m_buf, 4, blocking);
712 }
713 
714 size_t BufferedTransformation::PutWord16(word16 value, ByteOrder order, bool blocking)
715 {
716  return ChannelPutWord16(DEFAULT_CHANNEL, value, order, blocking);
717 }
718 
719 size_t BufferedTransformation::PutWord32(word32 value, ByteOrder order, bool blocking)
720 {
721  return ChannelPutWord32(DEFAULT_CHANNEL, value, order, blocking);
722 }
723 
724 // Issue 340
725 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
726 # pragma GCC diagnostic push
727 # pragma GCC diagnostic ignored "-Wconversion"
728 # pragma GCC diagnostic ignored "-Wsign-conversion"
729 #endif
730 
731 size_t BufferedTransformation::PeekWord16(word16 &value, ByteOrder order) const
732 {
733  byte buf[2] = {0, 0};
734  size_t len = Peek(buf, 2);
735 
736  if (order)
737  value = (buf[0] << 8) | buf[1];
738  else
739  value = (buf[1] << 8) | buf[0];
740 
741  return len;
742 }
743 
744 size_t BufferedTransformation::PeekWord32(word32 &value, ByteOrder order) const
745 {
746  byte buf[4] = {0, 0, 0, 0};
747  size_t len = Peek(buf, 4);
748 
749  if (order)
750  value = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf [3];
751  else
752  value = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf [0];
753 
754  return len;
755 }
756 
757 // Issue 340
758 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
759 # pragma GCC diagnostic pop
760 #endif
761 
762 size_t BufferedTransformation::GetWord16(word16 &value, ByteOrder order)
763 {
764  return (size_t)Skip(PeekWord16(value, order));
765 }
766 
767 size_t BufferedTransformation::GetWord32(word32 &value, ByteOrder order)
768 {
769  return (size_t)Skip(PeekWord32(value, order));
770 }
771 
773 {
774  if (AttachedTransformation() && AttachedTransformation()->Attachable())
775  AttachedTransformation()->Attach(newOut);
776  else
777  Detach(newOut);
778 }
779 
781 {
782  GenerateRandom(rng, MakeParameters("KeySize", (int)keySize));
783 }
784 
786 {
787 public:
789  : m_rng(rng), m_encryptor(encryptor), m_parameters(parameters)
790  {
791  Detach(attachment);
792  }
793 
794  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
795  {
796  FILTER_BEGIN;
797  m_plaintextQueue.Put(inString, length);
798 
799  if (messageEnd)
800  {
801  {
802  size_t plaintextLength;
803  if (!SafeConvert(m_plaintextQueue.CurrentSize(), plaintextLength))
804  throw InvalidArgument("PK_DefaultEncryptionFilter: plaintext too long");
805  size_t ciphertextLength = m_encryptor.CiphertextLength(plaintextLength);
806 
807  SecByteBlock plaintext(plaintextLength);
808  m_plaintextQueue.Get(plaintext, plaintextLength);
809  m_ciphertext.resize(ciphertextLength);
810  m_encryptor.Encrypt(m_rng, plaintext, plaintextLength, m_ciphertext, m_parameters);
811  }
812 
813  FILTER_OUTPUT(1, m_ciphertext, m_ciphertext.size(), messageEnd);
814  }
816  }
817 
823 };
824 
826 {
827  return new PK_DefaultEncryptionFilter(rng, *this, attachment, parameters);
828 }
829 
831 {
832 public:
834  : m_rng(rng), m_decryptor(decryptor), m_parameters(parameters)
835  {
836  Detach(attachment);
837  }
838 
839  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
840  {
841  FILTER_BEGIN;
842  m_ciphertextQueue.Put(inString, length);
843 
844  if (messageEnd)
845  {
846  {
847  size_t ciphertextLength;
848  if (!SafeConvert(m_ciphertextQueue.CurrentSize(), ciphertextLength))
849  throw InvalidArgument("PK_DefaultDecryptionFilter: ciphertext too long");
850  size_t maxPlaintextLength = m_decryptor.MaxPlaintextLength(ciphertextLength);
851 
852  SecByteBlock ciphertext(ciphertextLength);
853  m_ciphertextQueue.Get(ciphertext, ciphertextLength);
854  m_plaintext.resize(maxPlaintextLength);
855  m_result = m_decryptor.Decrypt(m_rng, ciphertext, ciphertextLength, m_plaintext, m_parameters);
856  if (!m_result.isValidCoding)
857  throw InvalidCiphertext(m_decryptor.AlgorithmName() + ": invalid ciphertext");
858  }
859 
860  FILTER_OUTPUT(1, m_plaintext, m_result.messageLength, messageEnd);
861  }
863  }
864 
871 };
872 
874 {
875  return new PK_DefaultDecryptionFilter(rng, *this, attachment, parameters);
876 }
877 
878 size_t PK_Signer::Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const
879 {
880  member_ptr<PK_MessageAccumulator> m(messageAccumulator);
881  return SignAndRestart(rng, *m, signature, false);
882 }
883 
884 size_t PK_Signer::SignMessage(RandomNumberGenerator &rng, const byte *message, size_t messageLen, byte *signature) const
885 {
886  member_ptr<PK_MessageAccumulator> m(NewSignatureAccumulator(rng));
887  m->Update(message, messageLen);
888  return SignAndRestart(rng, *m, signature, false);
889 }
890 
891 size_t PK_Signer::SignMessageWithRecovery(RandomNumberGenerator &rng, const byte *recoverableMessage, size_t recoverableMessageLength,
892  const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, byte *signature) const
893 {
894  member_ptr<PK_MessageAccumulator> m(NewSignatureAccumulator(rng));
895  InputRecoverableMessage(*m, recoverableMessage, recoverableMessageLength);
896  m->Update(nonrecoverableMessage, nonrecoverableMessageLength);
897  return SignAndRestart(rng, *m, signature, false);
898 }
899 
900 bool PK_Verifier::Verify(PK_MessageAccumulator *messageAccumulator) const
901 {
902  member_ptr<PK_MessageAccumulator> m(messageAccumulator);
903  return VerifyAndRestart(*m);
904 }
905 
906 bool PK_Verifier::VerifyMessage(const byte *message, size_t messageLen, const byte *signature, size_t signatureLength) const
907 {
908  member_ptr<PK_MessageAccumulator> m(NewVerificationAccumulator());
909  InputSignature(*m, signature, signatureLength);
910  m->Update(message, messageLen);
911  return VerifyAndRestart(*m);
912 }
913 
914 DecodingResult PK_Verifier::Recover(byte *recoveredMessage, PK_MessageAccumulator *messageAccumulator) const
915 {
916  member_ptr<PK_MessageAccumulator> m(messageAccumulator);
917  return RecoverAndRestart(recoveredMessage, *m);
918 }
919 
921  const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength,
922  const byte *signature, size_t signatureLength) const
923 {
924  member_ptr<PK_MessageAccumulator> m(NewVerificationAccumulator());
925  InputSignature(*m, signature, signatureLength);
926  m->Update(nonrecoverableMessage, nonrecoverableMessageLength);
927  return RecoverAndRestart(recoveredMessage, *m);
928 }
929 
930 void SimpleKeyAgreementDomain::GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
931 {
932  GeneratePrivateKey(rng, privateKey);
933  GeneratePublicKey(rng, privateKey, publicKey);
934 }
935 
936 void AuthenticatedKeyAgreementDomain::GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
937 {
938  GenerateStaticPrivateKey(rng, privateKey);
939  GenerateStaticPublicKey(rng, privateKey, publicKey);
940 }
941 
942 void AuthenticatedKeyAgreementDomain::GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
943 {
944  GenerateEphemeralPrivateKey(rng, privateKey);
945  GenerateEphemeralPublicKey(rng, privateKey, publicKey);
946 }
947 
949 
950 #endif
virtual void ProcessLastBlock(byte *outString, const byte *inString, size_t length)
Encrypt or decrypt the last block of data.
Definition: cryptlib.cpp:244
Used to pass byte array input as part of a NameValuePairs object.
Definition: algparam.h:29
Standard names for retrieving values by name when working with NameValuePairs.
An invalid argument was detected.
Definition: cryptlib.h:184
virtual size_t ChannelPutModifiable2(const std::string &channel, byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee on a channel.
Definition: cryptlib.cpp:472
virtual void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate private/public key pair.
Definition: cryptlib.cpp:942
size_t ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
Input a 32-bit word for processing on a channel.
Definition: cryptlib.cpp:708
#define FILTER_END_NO_MESSAGE_END
Definition: fltrimpl.h:26
virtual bool AnyRetrievable() const
Determines whether bytes are ready for retrieval.
Definition: cryptlib.cpp:504
size_t TransferAllTo2(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer all bytes from this object to another BufferedTransformation.
Definition: cryptlib.cpp:653
Classes for working with NameValuePairs.
virtual size_t SignMessageWithRecovery(RandomNumberGenerator &rng, const byte *recoverableMessage, size_t recoverableMessageLength, const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, byte *signature) const
Sign a recoverable message.
Definition: cryptlib.cpp:891
virtual BufferedTransformation * CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment=NULL, const NameValuePairs &parameters=g_nullNameValuePairs) const
Create a new decryption filter.
Definition: cryptlib.cpp:873
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
size_t TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer messages from this object to another BufferedTransformation.
Definition: cryptlib.cpp:604
const lword LWORD_MAX
Definition: config.h:246
Utility functions for the Crypto++ library.
virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params=g_nullNameValuePairs)
Sets or reset the key of this object.
Definition: cryptlib.cpp:97
const byte * GetIVAndThrowIfInvalid(const NameValuePairs &params, size_t &size)
Retrieves and validates the IV.
Definition: cryptlib.cpp:143
RandomNumberGenerator & m_rng
Definition: cryptlib.cpp:818
ByteOrder
Provides the byte ordering.
Definition: cryptlib.h:124
virtual bool VerifyMessage(const byte *message, size_t messageLen, const byte *signature, size_t signatureLen) const
Check whether input signature is a valid signature for input message.
Definition: cryptlib.cpp:906
unsigned short word16
Definition: config.h:230
virtual size_t Peek(byte &outByte) const
Peek a 8-bit byte.
Definition: cryptlib.cpp:534
size_t PeekWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER) const
Peek a 16-bit word.
Definition: cryptlib.cpp:731
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Definition: cryptlib.cpp:326
size_t ChannelPut(const std::string &channel, byte inByte, bool blocking=true)
Input a byte for processing on a channel.
Definition: cryptlib.h:1864
#define CRYPTOPP_INIT_PRIORITY
Definition: config.h:138
Exception thrown when an invalid key length is encountered.
Definition: simple.h:47
static const std::string s2("AAD")
virtual unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: cryptlib.cpp:234
const NameValuePairs & m_parameters
Definition: cryptlib.cpp:867
void ThrowIfInvalidKeyLength(size_t length)
Validates the key length.
Definition: cryptlib.cpp:113
void ThrowIfInvalidIV(const byte *iv)
Validates the IV.
Definition: cryptlib.cpp:125
word64 dword
Definition: config.h:309
void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock=NULL)
Access a block of memory.
Definition: misc.h:2123
#define FILTER_OUTPUT(site, output, length, messageEnd)
Definition: fltrimpl.h:49
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
bool FIPS_140_2_ComplianceEnabled()
Determines whether the library provides FIPS validated cryptography.
Definition: fips140.cpp:29
PK_DefaultDecryptionFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
Definition: cryptlib.cpp:833
Interface for public-key encryptors.
Definition: cryptlib.h:2336
virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL)
Generate a random 32 bit word in the range min to max, inclusive.
Definition: cryptlib.cpp:298
size_t count
Definition: ExecStats.cpp:37
PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus()
Provides the current power-up self test status.
Definition: fips140.cpp:39
Abstract base classes that provide a uniform interface to this library.
Thrown when an unexpected type is encountered.
Definition: cryptlib.h:287
size_type size() const
Provides the count of elements in the SecBlock.
Definition: secblock.h:524
void GenerateBlock(byte *output, size_t size)
An implementation that throws NotImplemented.
Definition: cryptlib.cpp:379
virtual void DiscardBytes(size_t n)
Generate and discard n bytes.
Definition: cryptlib.cpp:339
The self tests were executed via DoPowerUpSelfTest() or DoDllPowerUpSelfTest(), but the result was fa...
Definition: fips140.h:44
Classes for automatic resource management.
size_t size() const
Length of the memory block.
Definition: algparam.h:93
Library configuration file.
Interface for random number generators.
Definition: cryptlib.h:1188
const NameValuePairs & m_parameters
Definition: cryptlib.cpp:820
virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: cryptlib.cpp:449
virtual size_t AdvancedProcessBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t length, word32 flags) const
Encrypt and xor multiple blocks using additional flags.
Definition: cryptlib.cpp:178
void SetKeyWithRounds(const byte *key, size_t length, int rounds)
Sets or reset the key of this object.
Definition: cryptlib.cpp:103
virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output on a channel.
Definition: cryptlib.cpp:480
virtual bool TruncatedVerify(const byte *digest, size_t digestLength)
Verifies the hash of the current message.
Definition: cryptlib.cpp:408
virtual DecodingResult Recover(byte *recoveredMessage, PK_MessageAccumulator *messageAccumulator) const
Recover a message from its signature.
Definition: cryptlib.cpp:914
virtual unsigned int SkipMessages(unsigned int count=UINT_MAX)
Skip a number of meessages.
Definition: cryptlib.cpp:596
virtual void SetRetrievalChannel(const std::string &channel)
Sets the default retrieval channel.
Definition: cryptlib.cpp:696
ExecStats::duration min
Definition: ExecStats.cpp:35
Interface for buffered transformations.
Definition: cryptlib.h:1352
const byte * begin() const
Pointer to the first byte in the memory block.
Definition: algparam.h:89
Interface for cloning objects.
Definition: cryptlib.h:482
RandomNumberGenerator & m_rng
Definition: cryptlib.cpp:865
BufferedTransformation & TheBitBucket()
An input discarding BufferedTransformation.
Definition: cryptlib.cpp:79
void ThrowIfInvalidTruncatedSize(size_t size) const
Validates a truncated digest size.
Definition: cryptlib.cpp:416
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: cryptlib.cpp:839
size_t ThrowIfInvalidIVLength(int length)
Validates the IV length.
Definition: cryptlib.cpp:131
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.cpp:59
Classes and functions for secure memory allocations.
#define FILTER_BEGIN
Definition: fltrimpl.h:14
Copy input to a memory buffer.
Definition: filters.h:1101
Exception thrown when a filter does not support named channels.
Definition: cryptlib.h:1852
Returns a decoding results.
Definition: cryptlib.h:238
Algorithm(bool checkSelfTestStatus=true)
Interface for all crypto algorithms.
Definition: cryptlib.cpp:85
bool GetValue(const char *name, T &value) const
Get a named value.
Definition: cryptlib.h:337
virtual void Attach(BufferedTransformation *newAttachment)
Add newAttachment to the end of attachment chain.
Definition: cryptlib.cpp:772
virtual bool AnyMessages() const
Determines if any messages are available for retrieval.
Definition: cryptlib.cpp:577
Interface for public-key decryptors.
Definition: cryptlib.h:2372
virtual BufferedTransformation * CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment=NULL, const NameValuePairs &parameters=g_nullNameValuePairs) const
Create a new encryption filter.
Definition: cryptlib.cpp:825
size_t PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const
Peek a 32-bit word.
Definition: cryptlib.cpp:744
A method was called which was not implemented.
Definition: cryptlib.h:205
virtual void GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate a private/public key pair.
Definition: cryptlib.cpp:930
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:498
Manages resources for a single object.
Definition: smartptr.h:20
static const std::string & NULL_CHANNEL
Definition: cryptlib.h:1356
Exception thrown when a crypto algorithm is used after a self test fails.
Definition: fips140.h:23
unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const
Copy messages from this object to another BufferedTransformation.
Definition: cryptlib.cpp:634
virtual bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true)
Marks the end of a series of messages on a channel.
Definition: cryptlib.cpp:488
DecodingResult m_result
Definition: cryptlib.cpp:870
const char * name
Definition: rest.cpp:36
virtual void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const
Generate a static private/public key pair.
Definition: cryptlib.cpp:936
ExecStats::duration max
Definition: ExecStats.cpp:36
FascTransaction __attribute__
virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: cryptlib.cpp:442
virtual byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: cryptlib.cpp:456
T Crop(T value, size_t bits)
Truncates the value to the specified number of bits.
Definition: misc.h:737
T * m_p
Definition: smartptr.h:30
void ThrowIfResynchronizable()
Validates the object.
Definition: cryptlib.cpp:119
virtual DecodingResult RecoverMessage(byte *recoveredMessage, const byte *nonrecoverableMessage, size_t nonrecoverableMessageLength, const byte *signature, size_t signatureLength) const
Recover a message from its signature.
Definition: cryptlib.cpp:920
const std::string AAD_CHANNEL
Channel for additional authenticated data.
Definition: cryptlib.cpp:60
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be neagtive and incorrectly promoted.
Definition: misc.h:512
virtual size_t ChannelPut2(const std::string &channel, const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing on a channel.
Definition: cryptlib.cpp:464
unsigned long long word64
Definition: config.h:240
virtual lword Skip(lword skipMax=LWORD_MAX)
Discard skipMax bytes from the output buffer.
Definition: cryptlib.cpp:553
PK_DefaultEncryptionFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
Definition: cryptlib.cpp:788
virtual size_t Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const
Sign and delete the messageAccumulator.
Definition: cryptlib.cpp:878
virtual size_t SignMessage(RandomNumberGenerator &rng, const byte *message, size_t messageLen, byte *signature) const
Sign a message.
Definition: cryptlib.cpp:884
const PK_Decryptor & m_decryptor
Definition: cryptlib.cpp:866
#define b(i, j)
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
virtual byte GenerateByte()
Generate new random byte and return it.
Definition: cryptlib.cpp:291
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.cpp:76
std::string AlgorithmName() const
The name of the generator.
Definition: cryptlib.cpp:367
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Definition: misc.cpp:28
Data structure used to store byte strings.
Definition: queue.h:20
size_t GetWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER)
Retrieve a 16-bit word.
Definition: cryptlib.cpp:762
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: cryptlib.cpp:428
Random Number Generator that does not produce random numbers.
Definition: cryptlib.cpp:362
Implementation of BufferedTransformation&#39;s attachment interface.
The self tests have not been performed.
Definition: fips140.h:41
Interface for accumulating messages to be signed or verified.
Definition: cryptlib.h:2510
A decryption filter encountered invalid ciphertext.
Definition: cryptlib.h:198
virtual bool Verify(PK_MessageAccumulator *messageAccumulator) const
Check whether messageAccumulator contains a valid signature and message.
Definition: cryptlib.cpp:900
size_t PutWord32(word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
Input a 32-bit word for processing.
Definition: cryptlib.cpp:719
void SetKeyWithIV(const byte *key, size_t length, const byte *iv, size_t ivLength)
Sets or reset the key of this object.
Definition: cryptlib.cpp:108
size_t GetWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER)
Retrieve a 32-bit word.
Definition: cryptlib.cpp:767
virtual unsigned int GenerateBit()
Generate new random bit and return it.
Definition: cryptlib.cpp:286
Base class for unflushable filters.
Definition: simple.h:94
virtual unsigned int NumberOfMessages() const
Provides the number of meesages processed by this object.
Definition: cryptlib.cpp:569
Classes and functions for the FIPS 140-2 validated library.
uint8_t const size_t const size
Definition: sha3.h:20
virtual unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: cryptlib.cpp:229
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
RandomNumberGenerator & NullRNG()
Random Number Generator that does not produce random numbers.
Definition: cryptlib.cpp:402
virtual void EncryptAndAuthenticate(byte *ciphertext, byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *message, size_t messageLength)
Encrypts and calculates a MAC in one call.
Definition: cryptlib.cpp:268
virtual bool DecryptAndVerify(byte *message, const byte *mac, size_t macLength, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *ciphertext, size_t ciphertextLength)
Decrypts and verifies a MAC in one call.
Definition: cryptlib.cpp:277
virtual void SkipAll()
Skip all messages in the series.
Definition: cryptlib.cpp:642
void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize)
Generate a random key or crypto parameters.
Definition: cryptlib.cpp:780
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition: misc.h:539
size_t PutWord16(word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
Input a 16-bit word for processing.
Definition: cryptlib.cpp:714
virtual lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: cryptlib.cpp:496
unsigned int GetMaxWaitObjectCount() const
Retrieves the maximum number of waitable objects.
Definition: cryptlib.cpp:422
virtual bool GetNextMessage()
Start retrieving the next message.
Definition: cryptlib.cpp:585
#define NAMESPACE_END
Definition: config.h:201
virtual unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition: cryptlib.cpp:239
std::vector< char * > parameters
Definition: boostTest.cpp:46
bool PowerUpSelfTestInProgressOnThisThread()
Definition: fips140.cpp:52
CRYPTOPP_COMPILE_ASSERT(sizeof(byte)==1)
void CopyAllTo(BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) const
Copy messages from this object to another BufferedTransformation.
Definition: cryptlib.cpp:685
void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0)
Prespecifies the data lengths.
Definition: cryptlib.cpp:254
Acts as an input discarding Filter or Sink.
Definition: simple.h:345
virtual size_t Get(byte &outByte)
Retrieve a 8-bit byte.
Definition: cryptlib.cpp:515
word64 lword
Definition: config.h:245
const simple_ptr< NullNameValuePairs > s_pNullNameValuePairs(new NullNameValuePairs)
unsigned int word32
Definition: config.h:231
#define s1(x)
Definition: sha256.c:70
virtual void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
Initialize or reinitialize this object, with signal propagation.
Definition: cryptlib.cpp:435
size_t ChannelPutWord16(const std::string &channel, word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
Input a 16-bit word for processing on a channel.
Definition: cryptlib.cpp:702
virtual void GetNextIV(RandomNumberGenerator &rng, byte *iv)
Retrieves a secure IV for the next message.
Definition: cryptlib.cpp:173
evm_result m_result
Definition: JitVM.cpp:271
virtual void Update(const byte *input, size_t length)=0
Updates a hash with additional input.
unsigned int BitPrecision(const T &value)
Returns the number of bits required for a value.
Definition: misc.h:654
word32 word
Definition: config.h:308
const PK_Encryptor & m_encryptor
Definition: cryptlib.cpp:819
virtual void GenerateIntoBufferedTransformation(BufferedTransformation &target, const std::string &channel, lword length)
Generate random bytes into a BufferedTransformation.
Definition: cryptlib.cpp:344
Classes for access to the operating system&#39;s random number generators.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Definition: cryptlib.cpp:67
bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
Performs a near constant-time comparison of two equally sized buffers.
Definition: misc.cpp:96
bool ChannelMessageEnd(const std::string &channel, int propagation=-1, bool blocking=true)
Signal the end of a message.
Definition: cryptlib.h:1913
Interface for retrieving values given their names.
Definition: cryptlib.h:279
virtual lword TotalBytesRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: cryptlib.cpp:561
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: cryptlib.cpp:794