Crypto++  5.6.3
Free C++ class library of cryptographic schemes
filters.h
Go to the documentation of this file.
1 // filters.h - written and placed in the public domain by Wei Dai
2 
3 //! \file filters.h
4 //! \brief Implementation of BufferedTransformation's attachment interface in cryptlib.h.
5 //! \nosubgrouping
6 
7 #ifndef CRYPTOPP_FILTERS_H
8 #define CRYPTOPP_FILTERS_H
9 
10 //! \file
11 
12 #include "cryptlib.h"
13 
14 #if CRYPTOPP_MSC_VERSION
15 # pragma warning(push)
16 # pragma warning(disable: 4127 4189)
17 #endif
18 
19 #include "cryptlib.h"
20 #include "simple.h"
21 #include "secblock.h"
22 #include "misc.h"
23 #include "smartptr.h"
24 #include "queue.h"
25 #include "algparam.h"
26 #include "stdcpp.h"
27 
28 NAMESPACE_BEGIN(CryptoPP)
29 
30 //! \class Filter
31 //! \brief Implementation of BufferedTransformation's attachment interface
32 //! \details Filter is a cornerstone of the Pipeline trinitiy. Data flows from
33 //! Sources, through Filters, and then terminates in Sinks. The difference
34 //! between a Source and Filter is a Source \a pumps data, while a Filter does
35 //! not. The difference between a Filter and a Sink is a Filter allows an
36 //! attached transformation, while a Sink does not.
37 //! \details See the discussion of BufferedTransformation in cryptlib.h for
38 //! more details.
39 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Filter : public BufferedTransformation, public NotCopyable
40 {
41 public:
42  //! \brief Construct a Filter
43  //! \param attachment the filter's attached transformation
44  //! \details attachment can be \p NULL.
45  Filter(BufferedTransformation *attachment = NULL);
46 
47  //! \brief Determine if attachable
48  //! \returns \p true if the object allows attached transformations, \p false otherwise.
49  //! \note Source and Filter offer attached transformations; while Sink does not.
50  bool Attachable() {return true;}
51 
52  //! \brief Retrieve attached transformation
53  //! \returns pointer to a BufferedTransformation if there is an attached transformation, \p NULL otherwise.
54  BufferedTransformation *AttachedTransformation();
55 
56  //! \brief Retrieve attached transformation
57  //! \returns pointer to a BufferedTransformation if there is an attached transformation, \p NULL otherwise.
58  const BufferedTransformation *AttachedTransformation() const;
59 
60  //! \brief Replace an attached transformation
61  //! \param newAttachment pointer to a new BufferedTransformation
62  //! \details newAttachment cab ne a single filter, a chain of filters or \p NULL.
63  //! Pass \p NULL to remove an existing BufferedTransformation or chain of filters
64  void Detach(BufferedTransformation *newAttachment = NULL);
65 
66  // See the documentation for BufferedTransformation in cryptlib.h
67  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
68  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
69 
70  // See the documentation for BufferedTransformation in cryptlib.h
71  void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1);
72  bool Flush(bool hardFlush, int propagation=-1, bool blocking=true);
73  bool MessageSeriesEnd(int propagation=-1, bool blocking=true);
74 
75 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
76  virtual ~Filter() {}
77 #endif
78 
79 protected:
80  virtual BufferedTransformation * NewDefaultAttachment() const;
81  void Insert(Filter *nextFilter); // insert filter after this one
82 
83  virtual bool ShouldPropagateMessageEnd() const {return true;}
84  virtual bool ShouldPropagateMessageSeriesEnd() const {return true;}
85 
86  void PropagateInitialize(const NameValuePairs &parameters, int propagation);
87 
88  //! \brief Forward processed data on to attached transformation
89  //! \param outputSite unknown, system crash between keyboard and chair...
90  //! \param inString the byte buffer to process
91  //! \param length the size of the string, in bytes
92  //! \param messageEnd means how many filters to signal MessageEnd() to, including this one
93  //! \param blocking specifies whether the object should block when processing input
94  //! \param channel the channel to process the data
95  //! \returns 0 indicates all bytes were processed during the call. Non-0 indicates the
96  //! number of bytes that were \a not processed.
97  size_t Output(int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
98 
99  //! \brief Output multiple bytes that may be modified by callee.
100  //! \param outputSite unknown, system crash between keyboard and chair...
101  //! \param inString the byte buffer to process
102  //! \param length the size of the string, in bytes
103  //! \param messageEnd means how many filters to signal MessageEnd() to, including this one
104  //! \param blocking specifies whether the object should block when processing input
105  //! \param channel the channel to process the data
106  //! \returns 0 indicates all bytes were processed during the call. Non-0 indicates the
107  //! number of bytes that were \a not processed
108  size_t OutputModifiable(int outputSite, byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
109 
110  //! \brief Signals the end of messages to the object
111  //! \param outputSite unknown, system crash between keyboard and chair...
112  //! \param propagation the number of attached transformations the MessageEnd() signal should be passed
113  //! \param blocking specifies whether the object should block when processing input
114  //! \param channel the channel to process the data
115  //! \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
116  //! object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
117  bool OutputMessageEnd(int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
118 
119  //! \brief Flush buffered input and/or output, with signal propagation
120  //! \param outputSite unknown, system crash between keyboard and chair...
121  //! \param hardFlush is used to indicate whether all data should be flushed
122  //! \param propagation the number of attached transformations the Flush() signal should be passed
123  //! \param blocking specifies whether the object should block when processing input
124  //! \param channel the channel to process the data
125  //! \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
126  //! object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
127  //! \note Hard flushes must be used with care. It means try to process and output everything, even if
128  //! there may not be enough data to complete the action. For example, hard flushing a HexDecoder
129  //! would cause an error if you do it after inputing an odd number of hex encoded characters.
130  //! \note For some types of filters, like ZlibDecompressor, hard flushes can only
131  //! be done at "synchronization points". These synchronization points are positions in the data
132  //! stream that are created by hard flushes on the corresponding reverse filters, in this
133  //! example ZlibCompressor. This is useful when zlib compressed data is moved across a
134  //! network in packets and compression state is preserved across packets, as in the SSH2 protocol.
135  bool OutputFlush(int outputSite, bool hardFlush, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
136 
137  //! \brief Marks the end of a series of messages, with signal propagation
138  //! \param outputSite unknown, system crash between keyboard and chair...
139  //! \param propagation the number of attached transformations the MessageSeriesEnd() signal should be passed
140  //! \param blocking specifies whether the object should block when processing input
141  //! \param channel the channel to process the data
142  //! \details Each object that receives the signal will perform its processing, decrement
143  //! propagation, and then pass the signal on to attached transformations if the value is not 0.
144  //! \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
145  //! object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
146  //! \note There should be a MessageEnd() immediately before MessageSeriesEnd().
147  bool OutputMessageSeriesEnd(int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
148 
149 private:
151 
152 protected:
153  size_t m_inputPosition;
154  int m_continueAt;
155 };
156 
157 //! \struct FilterPutSpaceHelper
158 
159 struct CRYPTOPP_DLL FilterPutSpaceHelper
160 {
161  // desiredSize is how much to ask target, bufferSize is how much to allocate in m_tempSpace
162  byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize)
163  {
164  assert(desiredSize >= minSize && bufferSize >= minSize);
165  if (m_tempSpace.size() < minSize)
166  {
167  byte *result = target.ChannelCreatePutSpace(channel, desiredSize);
168  if (desiredSize >= minSize)
169  {
170  bufferSize = desiredSize;
171  return result;
172  }
173  m_tempSpace.New(bufferSize);
174  }
175 
176  bufferSize = m_tempSpace.size();
177  return m_tempSpace.begin();
178  }
179  byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize)
180  {return HelpCreatePutSpace(target, channel, minSize, minSize, minSize);}
181  byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t bufferSize)
182  {return HelpCreatePutSpace(target, channel, minSize, minSize, bufferSize);}
183  SecByteBlock m_tempSpace;
184 };
185 
186 //! measure how many byte and messages pass through, also serves as valve
187 class CRYPTOPP_DLL MeterFilter : public Bufferless<Filter>
188 {
189 public:
190  MeterFilter(BufferedTransformation *attachment=NULL, bool transparent=true)
191  : m_transparent(transparent), m_currentMessageBytes(0), m_totalBytes(0)
192  , m_currentSeriesMessages(0), m_totalMessages(0), m_totalMessageSeries(0)
193  , m_begin(NULL), m_length(0) {Detach(attachment); ResetMeter();}
194 
195  void SetTransparent(bool transparent) {m_transparent = transparent;}
196  void AddRangeToSkip(unsigned int message, lword position, lword size, bool sortNow = true);
197  void ResetMeter();
198  void IsolatedInitialize(const NameValuePairs &parameters)
199  {CRYPTOPP_UNUSED(parameters); ResetMeter();}
200 
201  lword GetCurrentMessageBytes() const {return m_currentMessageBytes;}
202  lword GetTotalBytes() {return m_totalBytes;}
203  unsigned int GetCurrentSeriesMessages() {return m_currentSeriesMessages;}
204  unsigned int GetTotalMessages() {return m_totalMessages;}
205  unsigned int GetTotalMessageSeries() {return m_totalMessageSeries;}
206 
207  byte * CreatePutSpace(size_t &size)
208  {return AttachedTransformation()->CreatePutSpace(size);}
209  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
210  size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking);
211  bool IsolatedMessageSeriesEnd(bool blocking);
212 
213 private:
214  size_t PutMaybeModifiable(byte *inString, size_t length, int messageEnd, bool blocking, bool modifiable);
215  bool ShouldPropagateMessageEnd() const {return m_transparent;}
216  bool ShouldPropagateMessageSeriesEnd() const {return m_transparent;}
217 
218  struct MessageRange
219  {
220  inline bool operator<(const MessageRange &b) const // BCB2006 workaround: this has to be a member function
221  {return message < b.message || (message == b.message && position < b.position);}
222  unsigned int message; lword position; lword size;
223  };
224 
225  bool m_transparent;
226  lword m_currentMessageBytes, m_totalBytes;
227  unsigned int m_currentSeriesMessages, m_totalMessages, m_totalMessageSeries;
228  std::deque<MessageRange> m_rangesToSkip;
229  byte *m_begin;
230  size_t m_length;
231 };
232 
233 //! _
234 class CRYPTOPP_DLL TransparentFilter : public MeterFilter
235 {
236 public:
237  TransparentFilter(BufferedTransformation *attachment=NULL) : MeterFilter(attachment, true) {}
238 };
239 
240 //! _
241 class CRYPTOPP_DLL OpaqueFilter : public MeterFilter
242 {
243 public:
244  OpaqueFilter(BufferedTransformation *attachment=NULL) : MeterFilter(attachment, false) {}
245 };
246 
247 /*! FilterWithBufferedInput divides up the input stream into
248  a first block, a number of middle blocks, and a last block.
249  First and last blocks are optional, and middle blocks may
250  be a stream instead (i.e. blockSize == 1).
251 */
252 class CRYPTOPP_DLL FilterWithBufferedInput : public Filter
253 {
254 public:
255 
256 #if !defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562)
257  //! default FilterWithBufferedInput for temporaries
259 #endif
260 
261  //! construct a FilterWithBufferedInput with an attached transformation
263  //! firstSize and lastSize may be 0, blockSize must be at least 1
264  FilterWithBufferedInput(size_t firstSize, size_t blockSize, size_t lastSize, BufferedTransformation *attachment);
265 
266  void IsolatedInitialize(const NameValuePairs &parameters);
267  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
268  {
269  return PutMaybeModifiable(const_cast<byte *>(inString), length, messageEnd, blocking, false);
270  }
271  size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
272  {
273  return PutMaybeModifiable(inString, length, messageEnd, blocking, true);
274  }
275  /*! calls ForceNextPut() if hardFlush is true */
276  bool IsolatedFlush(bool hardFlush, bool blocking);
277 
278  /*! The input buffer may contain more than blockSize bytes if lastSize != 0.
279  ForceNextPut() forces a call to NextPut() if this is the case.
280  */
281  void ForceNextPut();
282 
283 protected:
284  bool DidFirstPut() {return m_firstInputDone;}
285 
286  virtual void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize)
287  {CRYPTOPP_UNUSED(parameters); CRYPTOPP_UNUSED(firstSize); CRYPTOPP_UNUSED(blockSize); CRYPTOPP_UNUSED(lastSize); InitializeDerived(parameters);}
288  virtual void InitializeDerived(const NameValuePairs &parameters)
289  {CRYPTOPP_UNUSED(parameters);}
290  // FirstPut() is called if (firstSize != 0 and totalLength >= firstSize)
291  // or (firstSize == 0 and (totalLength > 0 or a MessageEnd() is received))
292  virtual void FirstPut(const byte *inString) =0;
293  // NextPut() is called if totalLength >= firstSize+blockSize+lastSize
294  virtual void NextPutSingle(const byte *inString)
295  {CRYPTOPP_UNUSED(inString); assert(false);}
296  // Same as NextPut() except length can be a multiple of blockSize
297  // Either NextPut() or NextPutMultiple() must be overriden
298  virtual void NextPutMultiple(const byte *inString, size_t length);
299  // Same as NextPutMultiple(), but inString can be modified
300  virtual void NextPutModifiable(byte *inString, size_t length)
301  {NextPutMultiple(inString, length);}
302  // LastPut() is always called
303  // if totalLength < firstSize then length == totalLength
304  // else if totalLength <= firstSize+lastSize then length == totalLength-firstSize
305  // else lastSize <= length < lastSize+blockSize
306  virtual void LastPut(const byte *inString, size_t length) =0;
307  virtual void FlushDerived() {}
308 
309 protected:
310  size_t PutMaybeModifiable(byte *begin, size_t length, int messageEnd, bool blocking, bool modifiable);
311  void NextPutMaybeModifiable(byte *inString, size_t length, bool modifiable)
312  {
313  if (modifiable) NextPutModifiable(inString, length);
314  else NextPutMultiple(inString, length);
315  }
316 
317  // This function should no longer be used, put this here to cause a compiler error
318  // if someone tries to override NextPut().
319  virtual int NextPut(const byte *inString, size_t length)
320  {CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); assert(false); return 0;}
321 
322  class BlockQueue
323  {
324  public:
325  void ResetQueue(size_t blockSize, size_t maxBlocks);
326  byte *GetBlock();
327  byte *GetContigousBlocks(size_t &numberOfBytes);
328  size_t GetAll(byte *outString);
329  void Put(const byte *inString, size_t length);
330  size_t CurrentSize() const {return m_size;}
331  size_t MaxSize() const {return m_buffer.size();}
332 
333  private:
334  SecByteBlock m_buffer;
335  size_t m_blockSize, m_maxBlocks, m_size;
336  byte *m_begin;
337  };
338 
339  size_t m_firstSize, m_blockSize, m_lastSize;
340  bool m_firstInputDone;
341  BlockQueue m_queue;
342 };
343 
344 //! _
345 class CRYPTOPP_DLL FilterWithInputQueue : public Filter
346 {
347 public:
348  FilterWithInputQueue(BufferedTransformation *attachment=NULL) : Filter(attachment) {}
349 
350  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
351  {
352  if (!blocking)
353  throw BlockingInputOnly("FilterWithInputQueue");
354 
355  m_inQueue.Put(inString, length);
356  if (messageEnd)
357  {
358  IsolatedMessageEnd(blocking);
359  Output(0, NULL, 0, messageEnd, blocking);
360  }
361  return 0;
362  }
363 
364 protected:
365  virtual bool IsolatedMessageEnd(bool blocking) =0;
366  void IsolatedInitialize(const NameValuePairs &parameters)
367  {CRYPTOPP_UNUSED(parameters); m_inQueue.Clear();}
368 
369  ByteQueue m_inQueue;
370 };
371 
372 //! \struct BlockPaddingSchemeDef
373 //! \details Padding schemes used for block ciphers.
375 {
376  //! \enum BlockPaddingScheme
377  //! \details Padding schemes used for block ciphers.
378  //! \details DEFAULT_PADDING means PKCS_PADDING if <tt>cipher.MandatoryBlockSize() > 1 &&
379  //! cipher.MinLastBlockSize() == 0</tt>, which holds for ECB or CBC mode. Otherwise,
380  //! NO_PADDING for modes like OFB, CFB, CTR, CBC-CTS.
381  //! \sa <A HREF="http://www.weidai.com/scan-mirror/csp.html">Block Cipher Padding</A> for
382  //! additional details.
384  //! \brief No padding added to a block
386  //! \brief 0's padding added to a block
388  //! \brief PKCS #5 padding added to a block
390  //! \brief 1 and 0's padding added to a block
392  //! \brief Default padding acheme
393  DEFAULT_PADDING
394  };
395 };
396 
397 //! Filter Wrapper for StreamTransformation, optionally handling padding/unpadding when needed
399 {
400 public:
401  StreamTransformationFilter(StreamTransformation &c, BufferedTransformation *attachment = NULL, BlockPaddingScheme padding = DEFAULT_PADDING, bool allowAuthenticatedSymmetricCipher = false);
402 
403  std::string AlgorithmName() const {return m_cipher.AlgorithmName();}
404 
405 protected:
406  void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize);
407  void FirstPut(const byte *inString);
408  void NextPutMultiple(const byte *inString, size_t length);
409  void NextPutModifiable(byte *inString, size_t length);
410  void LastPut(const byte *inString, size_t length);
411 
412  static size_t LastBlockSize(StreamTransformation &c, BlockPaddingScheme padding);
413 
414  StreamTransformation &m_cipher;
415  BlockPaddingScheme m_padding;
416  unsigned int m_optimalBufferSize;
417 };
418 
419 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
420 typedef StreamTransformationFilter StreamCipherFilter;
421 #endif
422 
423 //! Filter Wrapper for HashTransformation
424 class CRYPTOPP_DLL HashFilter : public Bufferless<Filter>, private FilterPutSpaceHelper
425 {
426 public:
427  HashFilter(HashTransformation &hm, BufferedTransformation *attachment = NULL, bool putMessage=false, int truncatedDigestSize=-1, const std::string &messagePutChannel=DEFAULT_CHANNEL, const std::string &hashPutChannel=DEFAULT_CHANNEL);
428 
429  std::string AlgorithmName() const {return m_hashModule.AlgorithmName();}
430  void IsolatedInitialize(const NameValuePairs &parameters);
431  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
432  byte * CreatePutSpace(size_t &size) {return m_hashModule.CreateUpdateSpace(size);}
433 
434 private:
435  HashTransformation &m_hashModule;
436  bool m_putMessage;
437  unsigned int m_digestSize;
438  byte *m_space;
439  std::string m_messagePutChannel, m_hashPutChannel;
440 };
441 
442 //! Filter Wrapper for HashTransformation
444 {
445 public:
447  {
448  public:
450  : Exception(DATA_INTEGRITY_CHECK_FAILED, "HashVerificationFilter: message hash or MAC not valid") {}
451  };
452 
453  enum Flags {HASH_AT_END=0, HASH_AT_BEGIN=1, PUT_MESSAGE=2, PUT_HASH=4, PUT_RESULT=8, THROW_EXCEPTION=16, DEFAULT_FLAGS = HASH_AT_BEGIN | PUT_RESULT};
454  HashVerificationFilter(HashTransformation &hm, BufferedTransformation *attachment = NULL, word32 flags = DEFAULT_FLAGS, int truncatedDigestSize=-1);
455 
456  std::string AlgorithmName() const {return m_hashModule.AlgorithmName();}
457  bool GetLastResult() const {return m_verified;}
458 
459 protected:
460  void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize);
461  void FirstPut(const byte *inString);
462  void NextPutMultiple(const byte *inString, size_t length);
463  void LastPut(const byte *inString, size_t length);
464 
465 private:
466  friend class AuthenticatedDecryptionFilter;
467 
468  HashTransformation &m_hashModule;
469  word32 m_flags;
470  unsigned int m_digestSize;
471  bool m_verified;
472  SecByteBlock m_expectedHash;
473 };
474 
475 typedef HashVerificationFilter HashVerifier; // for backwards compatibility
476 
477 //! Filter wrapper for encrypting with AuthenticatedSymmetricCipher, optionally handling padding/unpadding when needed
478 /*! Additional authenticated data should be given in channel "AAD". If putAAD is true, AAD will be Put() to the attached BufferedTransformation in channel "AAD". */
480 {
481 public:
482  /*! See StreamTransformationFilter for documentation on BlockPaddingScheme */
483  AuthenticatedEncryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment = NULL, bool putAAD=false, int truncatedDigestSize=-1, const std::string &macChannel=DEFAULT_CHANNEL, BlockPaddingScheme padding = DEFAULT_PADDING);
484 
485  void IsolatedInitialize(const NameValuePairs &parameters);
486  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
487  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
488  void LastPut(const byte *inString, size_t length);
489 
490 protected:
491  HashFilter m_hf;
492 };
493 
494 //! Filter wrapper for decrypting with AuthenticatedSymmetricCipher, optionally handling padding/unpadding when needed
495 /*! Additional authenticated data should be given in channel "AAD". */
497 {
498 public:
499  enum Flags {MAC_AT_END=0, MAC_AT_BEGIN=1, THROW_EXCEPTION=16, DEFAULT_FLAGS = THROW_EXCEPTION};
500 
501  /*! See StreamTransformationFilter for documentation on BlockPaddingScheme */
502  AuthenticatedDecryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment = NULL, word32 flags = DEFAULT_FLAGS, int truncatedDigestSize=-1, BlockPaddingScheme padding = DEFAULT_PADDING);
503 
504  std::string AlgorithmName() const {return m_hashVerifier.AlgorithmName();}
505  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
506  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
507  bool GetLastResult() const {return m_hashVerifier.GetLastResult();}
508 
509 protected:
510  void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize);
511  void FirstPut(const byte *inString);
512  void NextPutMultiple(const byte *inString, size_t length);
513  void LastPut(const byte *inString, size_t length);
514 
515  HashVerificationFilter m_hashVerifier;
516  StreamTransformationFilter m_streamFilter;
517 };
518 
519 //! Filter Wrapper for PK_Signer
520 class CRYPTOPP_DLL SignerFilter : public Unflushable<Filter>
521 {
522 public:
523  SignerFilter(RandomNumberGenerator &rng, const PK_Signer &signer, BufferedTransformation *attachment = NULL, bool putMessage=false)
524  : m_rng(rng), m_signer(signer), m_messageAccumulator(signer.NewSignatureAccumulator(rng)), m_putMessage(putMessage) {Detach(attachment);}
525 
526  std::string AlgorithmName() const {return m_signer.AlgorithmName();}
527 
528  void IsolatedInitialize(const NameValuePairs &parameters);
529  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
530 
531 private:
532  RandomNumberGenerator &m_rng;
533  const PK_Signer &m_signer;
534  member_ptr<PK_MessageAccumulator> m_messageAccumulator;
535  bool m_putMessage;
536  SecByteBlock m_buf;
537 };
538 
539 //! Filter Wrapper for PK_Verifier
541 {
542 public:
544  {
545  public:
547  : Exception(DATA_INTEGRITY_CHECK_FAILED, "VerifierFilter: digital signature not valid") {}
548  };
549 
550  enum Flags {SIGNATURE_AT_END=0, SIGNATURE_AT_BEGIN=1, PUT_MESSAGE=2, PUT_SIGNATURE=4, PUT_RESULT=8, THROW_EXCEPTION=16, DEFAULT_FLAGS = SIGNATURE_AT_BEGIN | PUT_RESULT};
551  SignatureVerificationFilter(const PK_Verifier &verifier, BufferedTransformation *attachment = NULL, word32 flags = DEFAULT_FLAGS);
552 
553  std::string AlgorithmName() const {return m_verifier.AlgorithmName();}
554 
555  bool GetLastResult() const {return m_verified;}
556 
557 protected:
558  void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize);
559  void FirstPut(const byte *inString);
560  void NextPutMultiple(const byte *inString, size_t length);
561  void LastPut(const byte *inString, size_t length);
562 
563 private:
564  const PK_Verifier &m_verifier;
565  member_ptr<PK_MessageAccumulator> m_messageAccumulator;
566  word32 m_flags;
567  SecByteBlock m_signature;
568  bool m_verified;
569 };
570 
571 typedef SignatureVerificationFilter VerifierFilter; // for backwards compatibility
572 
573 //! Redirect input to another BufferedTransformation without owning it
574 class CRYPTOPP_DLL Redirector : public CustomSignalPropagation<Sink>
575 {
576 public:
577  //! \brief Controls signal propagation behavior
578  enum Behavior
579  {
580  //! \brief Pass data only
581  DATA_ONLY = 0x00,
582  //! \brief Pass signals
583  PASS_SIGNALS = 0x01,
584  //! \brief Pass wait events
585  PASS_WAIT_OBJECTS = 0x02,
586  //! \brief Pass everything
587  //! \details PASS_EVERYTHING is default
588  PASS_EVERYTHING = PASS_SIGNALS | PASS_WAIT_OBJECTS
589  };
590 
591  Redirector() : m_target(NULL), m_behavior(PASS_EVERYTHING) {}
592  Redirector(BufferedTransformation &target, Behavior behavior=PASS_EVERYTHING)
593  : m_target(&target), m_behavior(behavior) {}
594 
595  void Redirect(BufferedTransformation &target) {m_target = &target;}
596  void StopRedirection() {m_target = NULL;}
597 
598  Behavior GetBehavior() {return (Behavior) m_behavior;}
599  void SetBehavior(Behavior behavior) {m_behavior=behavior;}
600  bool GetPassSignals() const {return (m_behavior & PASS_SIGNALS) != 0;}
601  void SetPassSignals(bool pass) { if (pass) m_behavior |= PASS_SIGNALS; else m_behavior &= ~(word32) PASS_SIGNALS; }
602  bool GetPassWaitObjects() const {return (m_behavior & PASS_WAIT_OBJECTS) != 0;}
603  void SetPassWaitObjects(bool pass) { if (pass) m_behavior |= PASS_WAIT_OBJECTS; else m_behavior &= ~(word32) PASS_WAIT_OBJECTS; }
604 
605  bool CanModifyInput() const
606  {return m_target ? m_target->CanModifyInput() : false;}
607 
608  void Initialize(const NameValuePairs &parameters, int propagation);
609  byte * CreatePutSpace(size_t &size)
610  {return m_target ? m_target->CreatePutSpace(size) : (byte *)(size=0, NULL);}
611  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
612  {return m_target ? m_target->Put2(inString, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;}
613  bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
614  {return m_target && GetPassSignals() ? m_target->Flush(hardFlush, propagation, blocking) : false;}
615  bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
616  {return m_target && GetPassSignals() ? m_target->MessageSeriesEnd(propagation, blocking) : false;}
617 
618  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
619  {return m_target ? m_target->ChannelCreatePutSpace(channel, size) : (byte *)(size=0, NULL);}
620  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
621  {return m_target ? m_target->ChannelPut2(channel, begin, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;}
622  size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
623  {return m_target ? m_target->ChannelPutModifiable2(channel, begin, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;}
624  bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true)
625  {return m_target && GetPassSignals() ? m_target->ChannelFlush(channel, completeFlush, propagation, blocking) : false;}
626  bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true)
627  {return m_target && GetPassSignals() ? m_target->ChannelMessageSeriesEnd(channel, propagation, blocking) : false;}
628 
629  unsigned int GetMaxWaitObjectCount() const
630  { return m_target && GetPassWaitObjects() ? m_target->GetMaxWaitObjectCount() : 0; }
631  void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack)
632  { if (m_target && GetPassWaitObjects()) m_target->GetWaitObjects(container, callStack); }
633 
634 private:
635  BufferedTransformation *m_target;
636  word32 m_behavior;
637 };
638 
639 // Used By ProxyFilter
640 class CRYPTOPP_DLL OutputProxy : public CustomSignalPropagation<Sink>
641 {
642 public:
643  OutputProxy(BufferedTransformation &owner, bool passSignal) : m_owner(owner), m_passSignal(passSignal) {}
644 
645  bool GetPassSignal() const {return m_passSignal;}
646  void SetPassSignal(bool passSignal) {m_passSignal = passSignal;}
647 
648  byte * CreatePutSpace(size_t &size)
649  {return m_owner.AttachedTransformation()->CreatePutSpace(size);}
650  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
651  {return m_owner.AttachedTransformation()->Put2(inString, length, m_passSignal ? messageEnd : 0, blocking);}
652  size_t PutModifiable2(byte *begin, size_t length, int messageEnd, bool blocking)
653  {return m_owner.AttachedTransformation()->PutModifiable2(begin, length, m_passSignal ? messageEnd : 0, blocking);}
654  void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
655  {if (m_passSignal) m_owner.AttachedTransformation()->Initialize(parameters, propagation);}
656  bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
657  {return m_passSignal ? m_owner.AttachedTransformation()->Flush(hardFlush, propagation, blocking) : false;}
658  bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
659  {return m_passSignal ? m_owner.AttachedTransformation()->MessageSeriesEnd(propagation, blocking) : false;}
660 
661  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
662  {return m_owner.AttachedTransformation()->ChannelCreatePutSpace(channel, size);}
663  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
664  {return m_owner.AttachedTransformation()->ChannelPut2(channel, begin, length, m_passSignal ? messageEnd : 0, blocking);}
665  size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
666  {return m_owner.AttachedTransformation()->ChannelPutModifiable2(channel, begin, length, m_passSignal ? messageEnd : 0, blocking);}
667  bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true)
668  {return m_passSignal ? m_owner.AttachedTransformation()->ChannelFlush(channel, completeFlush, propagation, blocking) : false;}
669  bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true)
670  {return m_passSignal ? m_owner.AttachedTransformation()->ChannelMessageSeriesEnd(channel, propagation, blocking) : false;}
671 
672 private:
673  BufferedTransformation &m_owner;
674  bool m_passSignal;
675 };
676 
677 //! Base class for Filter classes that are proxies for a chain of other filters.
678 class CRYPTOPP_DLL ProxyFilter : public FilterWithBufferedInput
679 {
680 public:
681  ProxyFilter(BufferedTransformation *filter, size_t firstSize, size_t lastSize, BufferedTransformation *attachment);
682 
683  bool IsolatedFlush(bool hardFlush, bool blocking);
684 
685  void SetFilter(Filter *filter);
686  void NextPutMultiple(const byte *s, size_t len);
687  void NextPutModifiable(byte *inString, size_t length);
688 
689 protected:
691 };
692 
693 //! simple proxy filter that doesn't modify the underlying filter's input or output
694 class CRYPTOPP_DLL SimpleProxyFilter : public ProxyFilter
695 {
696 public:
698  : ProxyFilter(filter, 0, 0, attachment) {}
699 
700  void FirstPut(const byte *) {}
701  void LastPut(const byte *, size_t) {m_filter->MessageEnd();}
702 };
703 
704 //! proxy for the filter created by PK_Encryptor::CreateEncryptionFilter
705 /*! This class is here just to provide symmetry with VerifierFilter. */
706 class CRYPTOPP_DLL PK_EncryptorFilter : public SimpleProxyFilter
707 {
708 public:
709  PK_EncryptorFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment = NULL)
710  : SimpleProxyFilter(encryptor.CreateEncryptionFilter(rng), attachment) {}
711 };
712 
713 //! proxy for the filter created by PK_Decryptor::CreateDecryptionFilter
714 /*! This class is here just to provide symmetry with SignerFilter. */
715 class CRYPTOPP_DLL PK_DecryptorFilter : public SimpleProxyFilter
716 {
717 public:
718  PK_DecryptorFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment = NULL)
719  : SimpleProxyFilter(decryptor.CreateDecryptionFilter(rng), attachment) {}
720 };
721 
722 //! Append input to a string object
723 template <class T>
724 class StringSinkTemplate : public Bufferless<Sink>
725 {
726 public:
727  // VC60 workaround: no T::char_type
728  typedef typename T::traits_type::char_type char_type;
729 
730  StringSinkTemplate(T &output)
731  : m_output(&output) {assert(sizeof(output[0])==1);}
732 
733  void IsolatedInitialize(const NameValuePairs &parameters)
734  {if (!parameters.GetValue("OutputStringPointer", m_output)) throw InvalidArgument("StringSink: OutputStringPointer not specified");}
735 
736  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
737  {
738  CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking);
739  if (length > 0)
740  {
741  typename T::size_type size = m_output->size();
742  if (length < size && size + length > m_output->capacity())
743  m_output->reserve(2*size);
744  m_output->append((const char_type *)inString, (const char_type *)inString+length);
745  }
746  return 0;
747  }
748 
749 private:
750  T *m_output;
751 };
752 
753 //! Append input to an std::string
754 CRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate<std::string>;
756 
757 //! incorporates input into RNG as additional entropy
758 class RandomNumberSink : public Bufferless<Sink>
759 {
760 public:
762  : m_rng(NULL) {}
763 
765  : m_rng(&rng) {}
766 
767  void IsolatedInitialize(const NameValuePairs &parameters);
768  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
769 
770 private:
771  RandomNumberGenerator *m_rng;
772 };
773 
774 //! Copy input to a memory buffer
775 class CRYPTOPP_DLL ArraySink : public Bufferless<Sink>
776 {
777 public:
778  ArraySink(const NameValuePairs &parameters = g_nullNameValuePairs)
779  : m_buf(NULL), m_size(0), m_total(0) {IsolatedInitialize(parameters);}
780  ArraySink(byte *buf, size_t size)
781  : m_buf(buf), m_size(size), m_total(0) {}
782 
783  size_t AvailableSize() {return SaturatingSubtract(m_size, m_total);}
784  lword TotalPutLength() {return m_total;}
785 
786  void IsolatedInitialize(const NameValuePairs &parameters);
787  byte * CreatePutSpace(size_t &size);
788  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
789 
790 protected:
791  byte *m_buf;
792  size_t m_size;
793  lword m_total;
794 };
795 
796 //! Xor input to a memory buffer
797 class CRYPTOPP_DLL ArrayXorSink : public ArraySink
798 {
799 public:
800  ArrayXorSink(byte *buf, size_t size)
801  : ArraySink(buf, size) {}
802 
803  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
804  byte * CreatePutSpace(size_t &size) {return BufferedTransformation::CreatePutSpace(size);}
805 };
806 
807 //! string-based implementation of Store interface
808 class StringStore : public Store
809 {
810 public:
811  StringStore(const char *string = NULL)
812  {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
813  StringStore(const byte *string, size_t length)
814  {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));}
815  template <class T> StringStore(const T &string)
816  {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
817 
818  CRYPTOPP_DLL size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
819  CRYPTOPP_DLL size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
820 
821 private:
822  CRYPTOPP_DLL void StoreInitialize(const NameValuePairs &parameters);
823 
824  const byte *m_store;
825  size_t m_length, m_count;
826 };
827 
828 //! RNG-based implementation of Source interface
829 class CRYPTOPP_DLL RandomNumberStore : public Store
830 {
831 public:
833  : m_rng(NULL), m_length(0), m_count(0) {}
834 
835  RandomNumberStore(RandomNumberGenerator &rng, lword length)
836  : m_rng(&rng), m_length(length), m_count(0) {}
837 
838  bool AnyRetrievable() const {return MaxRetrievable() != 0;}
839  lword MaxRetrievable() const {return m_length-m_count;}
840 
841  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
842  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
843  {
844  CRYPTOPP_UNUSED(target); CRYPTOPP_UNUSED(begin); CRYPTOPP_UNUSED(end); CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(blocking);
845  throw NotImplemented("RandomNumberStore: CopyRangeTo2() is not supported by this store");
846  }
847 
848 private:
849  void StoreInitialize(const NameValuePairs &parameters);
850 
851  RandomNumberGenerator *m_rng;
852  lword m_length, m_count;
853 };
854 
855 //! empty store
856 class CRYPTOPP_DLL NullStore : public Store
857 {
858 public:
859  NullStore(lword size = ULONG_MAX) : m_size(size) {}
860  void StoreInitialize(const NameValuePairs &parameters)
861  {CRYPTOPP_UNUSED(parameters);}
862  lword MaxRetrievable() const {return m_size;}
863  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
864  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
865 
866 private:
867  lword m_size;
868 };
869 
870 //! \class Source
871 //! \brief Implementation of BufferedTransformation's attachment interface
872 //! \details Source is a cornerstone of the Pipeline trinitiy. Data flows from
873 //! Sources, through Filters, and then terminates in Sinks. The difference
874 //! between a Source and Filter is a Source \a pumps data, while a Filter does
875 //! not. The difference between a Filter and a Sink is a Filter allows an
876 //! attached transformation, while a Sink does not.
877 //! \details See the discussion of BufferedTransformation in cryptlib.h for
878 //! more details.
879 //! \sa Store and SourceTemplate
880 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Source : public InputRejecting<Filter>
881 {
882 public:
883  Source(BufferedTransformation *attachment = NULL)
884  {Source::Detach(attachment);}
885 
886  //! \name PIPELINE
887  //@{
888 
889  lword Pump(lword pumpMax=size_t(SIZE_MAX))
890  {Pump2(pumpMax); return pumpMax;}
891  unsigned int PumpMessages(unsigned int count=UINT_MAX)
892  {PumpMessages2(count); return count;}
893  void PumpAll()
894  {PumpAll2();}
895  virtual size_t Pump2(lword &byteCount, bool blocking=true) =0;
896  virtual size_t PumpMessages2(unsigned int &messageCount, bool blocking=true) =0;
897  virtual size_t PumpAll2(bool blocking=true);
898  virtual bool SourceExhausted() const =0;
899 
900  //@}
901 
902 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
903  virtual ~Source() {}
904 #endif
905 
906 protected:
907  void SourceInitialize(bool pumpAll, const NameValuePairs &parameters)
908  {
909  IsolatedInitialize(parameters);
910  if (pumpAll)
911  PumpAll();
912  }
913 };
914 
915 //! \class SourceTemplate
916 //! \brief Transform a Store into a Source
917 //! \tparam T the class or type
918 template <class T>
919 class SourceTemplate : public Source
920 {
921 public:
923  : Source(attachment) {}
924  void IsolatedInitialize(const NameValuePairs &parameters)
925  {m_store.IsolatedInitialize(parameters);}
926  size_t Pump2(lword &byteCount, bool blocking=true)
927  {return m_store.TransferTo2(*AttachedTransformation(), byteCount, DEFAULT_CHANNEL, blocking);}
928  size_t PumpMessages2(unsigned int &messageCount, bool blocking=true)
929  {return m_store.TransferMessagesTo2(*AttachedTransformation(), messageCount, DEFAULT_CHANNEL, blocking);}
930  size_t PumpAll2(bool blocking=true)
931  {return m_store.TransferAllTo2(*AttachedTransformation(), DEFAULT_CHANNEL, blocking);}
932  bool SourceExhausted() const
933  {return !m_store.AnyRetrievable() && !m_store.AnyMessages();}
934  void SetAutoSignalPropagation(int propagation)
935  {m_store.SetAutoSignalPropagation(propagation);}
937  {return m_store.GetAutoSignalPropagation();}
938 
939 protected:
940  T m_store;
941 };
942 
943 //! \class SourceTemplate
944 //! \brief String-based implementation of the Source interface
945 class CRYPTOPP_DLL StringSource : public SourceTemplate<StringStore>
946 {
947 public:
948  StringSource(BufferedTransformation *attachment = NULL)
949  : SourceTemplate<StringStore>(attachment) {}
950  //! zero terminated string as source
951  StringSource(const char *string, bool pumpAll, BufferedTransformation *attachment = NULL)
952  : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
953  //! binary byte array as source
954  StringSource(const byte *string, size_t length, bool pumpAll, BufferedTransformation *attachment = NULL)
955  : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));}
956  //! std::string as source
957  StringSource(const std::string &string, bool pumpAll, BufferedTransformation *attachment = NULL)
958  : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
959 };
960 
961 //! use the third constructor for an array source
963 
964 //! RNG-based implementation of Source interface
965 class CRYPTOPP_DLL RandomNumberSource : public SourceTemplate<RandomNumberStore>
966 {
967 public:
968  RandomNumberSource(RandomNumberGenerator &rng, int length, bool pumpAll, BufferedTransformation *attachment = NULL)
969  : SourceTemplate<RandomNumberStore>(attachment)
970  {SourceInitialize(pumpAll, MakeParameters("RandomNumberGeneratorPointer", &rng)("RandomNumberStoreSize", length));}
971 };
972 
973 NAMESPACE_END
974 
975 #if CRYPTOPP_MSC_VERSION
976 # pragma warning(pop)
977 #endif
978 
979 #endif
used to pass byte array input as part of a NameValuePairs object
Definition: algparam.h:30
Base class for all exceptions thrown by Crypto++.
Definition: cryptlib.h:124
An invalid argument was detected.
Definition: cryptlib.h:166
StringSource(const char *string, bool pumpAll, BufferedTransformation *attachment=NULL)
zero terminated string as source
Definition: filters.h:951
container of wait objects
Definition: wait.h:151
Classes for working with NameValuePairs.
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:207
size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
Copy bytes from this object to another BufferedTransformation.
Definition: filters.h:842
Filter Wrapper for PK_Verifier.
Definition: filters.h:540
Base class for Filter classes that are proxies for a chain of other filters.
Definition: filters.h:678
virtual BufferedTransformation * CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment=NULL, const NameValuePairs &parameters=g_nullNameValuePairs) const
create a new decryption filter
Definition: cryptlib.cpp:864
Implementation of BufferedTransformation&#39;s attachment interface.
Definition: filters.h:880
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:553
Classes providing simple keying interfaces.
Utility functions for the Crypto++ library.
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:429
void SetAutoSignalPropagation(int propagation)
Set propagation of automatically generated and transferred signals.
Definition: filters.h:934
Interface for one direction (encryption or decryption) of a stream cipher or block cipher mode with a...
Definition: cryptlib.h:1036
size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee on a channel.
Definition: filters.h:665
size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing on a channel.
Definition: filters.h:663
Interface for public-key signers.
Definition: cryptlib.h:2310
size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing on a channel.
Definition: filters.h:620
Interface for public-key encryptors.
Definition: cryptlib.h:2163
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:650
Abstract base classes that provide a uniform interface to this library.
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:526
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: filters.h:924
Classes for automatic resource management.
Filter Wrapper for PK_Signer.
Definition: filters.h:520
bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true)
Marks the end of a series of messages on a channel.
Definition: filters.h:669
size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee.
Definition: filters.h:271
Acts as a Source for pre-existing, static data.
Definition: simple.h:228
StringSource(const byte *string, size_t length, bool pumpAll, BufferedTransformation *attachment=NULL)
binary byte array as source
Definition: filters.h:954
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:403
Interface for random number generators.
Definition: cryptlib.h:1085
Base class for input rejecting filters.
Definition: simple.h:105
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:611
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:609
Append input to a string object.
Definition: filters.h:724
SecByteBlock is a SecBlock<byte> typedef.
Definition: secblock.h:719
StringSource(const std::string &string, bool pumpAll, BufferedTransformation *attachment=NULL)
std::string as source
Definition: filters.h:957
Interface for buffered transformations.
Definition: cryptlib.h:1247
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:456
bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output on a channel.
Definition: filters.h:667
virtual PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const =0
create a new HashTransformation to accumulate the message to be signed
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:661
Classes and functions for secure memory allocations.
1 and 0&#39;s padding added to a block
Definition: filters.h:391
bool MessageEnd(int propagation=-1, bool blocking=true)
Signals the end of messages to the object.
Definition: cryptlib.h:1326
Copy input to a memory buffer.
Definition: filters.h:775
empty store
Definition: filters.h:856
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:618
Transform a Store into a Source.
Definition: filters.h:919
Classes for an unlimited queue to store bytes.
Xor input to a memory buffer.
Definition: filters.h:797
bool GetValue(const char *name, T &value) const
Get a named value.
Definition: cryptlib.h:319
bool CanModifyInput() const
Determines whether input can be modifed by the callee.
Definition: filters.h:605
Interface for public-key decryptors.
Definition: cryptlib.h:2196
virtual BufferedTransformation * CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment=NULL, const NameValuePairs &parameters=g_nullNameValuePairs) const
Create a new encryption filter.
Definition: cryptlib.cpp:816
A method was called which was not implemented.
Definition: cryptlib.h:187
Filter Wrapper for HashTransformation.
Definition: filters.h:443
Filter Wrapper for HashTransformation.
Definition: filters.h:424
RNG-based implementation of Source interface.
Definition: filters.h:829
Filter wrapper for decrypting with AuthenticatedSymmetricCipher, optionally handling padding/unpaddin...
Definition: filters.h:496
void Detach(BufferedTransformation *newAttachment=NULL)
Replace an attached transformation.
Definition: filters.cpp:50
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.cpp:41
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:487
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: filters.h:862
Filter wrapper for encrypting with AuthenticatedSymmetricCipher, optionally handling padding/unpaddin...
Definition: filters.h:479
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:504
simple proxy filter that doesn&#39;t modify the underlying filter&#39;s input or output
Definition: filters.h:694
virtual byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: cryptlib.cpp:459
void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
Initialize or reinitialize this object, with signal propagation.
Definition: filters.h:654
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: filters.h:658
unsigned int GetMaxWaitObjectCount() const
Retrieves the maximum number of waitable objects.
Definition: filters.h:629
StringSource ArraySource
use the third constructor for an array source
Definition: filters.h:962
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
Definition: misc.h:855
proxy for the filter created by PK_Decryptor::CreateDecryptionFilter
Definition: filters.h:715
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:736
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.cpp:79
incorporates input into RNG as additional entropy
Definition: filters.h:758
bool operator<(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
Definition: gf2n.h:253
Interface for the data processing portion of stream ciphers.
Definition: cryptlib.h:752
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: filters.h:733
string-based implementation of Store interface
Definition: filters.h:808
int GetAutoSignalPropagation() const
Retrieve automatic signal propagation value.
Definition: filters.h:936
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:350
Redirect input to another BufferedTransformation without owning it.
Definition: filters.h:574
Byte Queue.
Definition: queue.h:20
bool AnyRetrievable() const
Determines whether bytes are ready for retrieval.
Definition: filters.h:838
proxy for the filter created by PK_Encryptor::CreateEncryptionFilter
Definition: filters.h:706
thrown by objects that have not implemented nonblocking input processing
Definition: cryptlib.h:1359
Filter Wrapper for StreamTransformation, optionally handling padding/unpadding when needed...
Definition: filters.h:398
Behavior
Controls signal propagation behavior.
Definition: filters.h:578
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:432
Base class for unflushable filters.
Definition: simple.h:78
Interface for public-key signature verifiers.
Definition: cryptlib.h:2355
bool Attachable()
Determine if attachable.
Definition: filters.h:50
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:858
virtual byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: cryptlib.h:1303
bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output on a channel.
Definition: filters.h:624
0&#39;s padding added to a block
Definition: filters.h:387
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: filters.h:839
Implementation of BufferedTransformation&#39;s attachment interface.
Definition: filters.h:39
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: filters.h:198
measure how many byte and messages pass through, also serves as valve
Definition: filters.h:187
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: filters.h:631
No padding added to a block.
Definition: filters.h:385
Crypto++ library namespace.
PKCS #5 padding added to a block.
Definition: filters.h:389
RNG-based implementation of Source interface.
Definition: filters.h:965
bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true)
Marks the end of a series of messages on a channel.
Definition: filters.h:626
size_t PutModifiable2(byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee.
Definition: filters.h:652
Ensures an object is not copyable.
Definition: misc.h:184
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:267
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: filters.h:613
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:804
Provides interface for initialization of derived filters.
Definition: simple.h:162
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: filters.h:656
size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee on a channel.
Definition: filters.h:622
Base class for bufferless filters.
Definition: simple.h:67
#define SIZE_MAX
The maximum value of a machine word.
Definition: misc.h:70
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:648
Interface for retrieving values given their names.
Definition: cryptlib.h:261
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: filters.h:615