Crypto++  5.6.5
Free C++ class library of cryptographic schemes
filters.h
Go to the documentation of this file.
1 // filters.h - originally written and placed in the public domain by Wei Dai
2 
3 /// \file filters.h
4 /// \brief Implementation of BufferedTransformation's attachment interface.
5 
6 #ifndef CRYPTOPP_FILTERS_H
7 #define CRYPTOPP_FILTERS_H
8 
9 #include "cryptlib.h"
10 
11 #if CRYPTOPP_MSC_VERSION
12 # pragma warning(push)
13 # pragma warning(disable: 4127 4189 4231 4275 4514)
14 #endif
15 
16 #include "cryptlib.h"
17 #include "simple.h"
18 #include "secblock.h"
19 #include "misc.h"
20 #include "smartptr.h"
21 #include "queue.h"
22 #include "algparam.h"
23 #include "stdcpp.h"
24 
25 NAMESPACE_BEGIN(CryptoPP)
26 
27 /// \brief Implementation of BufferedTransformation's attachment interface
28 /// \details Filter is a cornerstone of the Pipeline trinitiy. Data flows from
29 /// Sources, through Filters, and then terminates in Sinks. The difference
30 /// between a Source and Filter is a Source \a pumps data, while a Filter does
31 /// not. The difference between a Filter and a Sink is a Filter allows an
32 /// attached transformation, while a Sink does not.
33 /// \details See the discussion of BufferedTransformation in cryptlib.h for
34 /// more details.
35 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Filter : public BufferedTransformation, public NotCopyable
36 {
37 public:
38  virtual ~Filter() {}
39 
40  /// \name ATTACHMENT
41  //@{
42 
43  /// \brief Construct a Filter
44  /// \param attachment an optional attached transformation
45  /// \details attachment can be \p NULL.
46  Filter(BufferedTransformation *attachment = NULLPTR);
47 
48  /// \brief Determine if attachable
49  /// \returns \p true if the object allows attached transformations, \p false otherwise.
50  /// \note Source and Filter offer attached transformations; while Sink does not.
51  bool Attachable() {return true;}
52 
53  /// \brief Retrieve attached transformation
54  /// \returns pointer to a BufferedTransformation if there is an attached transformation, \p NULL otherwise.
55  BufferedTransformation *AttachedTransformation();
56 
57  /// \brief Retrieve attached transformation
58  /// \returns pointer to a BufferedTransformation if there is an attached transformation, \p NULL otherwise.
59  const BufferedTransformation *AttachedTransformation() const;
60 
61  /// \brief Replace an attached transformation
62  /// \param newAttachment an optional attached transformation
63  /// \details newAttachment can be a single filter, a chain of filters or \p NULL.
64  /// Pass \p NULL to remove an existing BufferedTransformation or chain of filters
65  void Detach(BufferedTransformation *newAttachment = NULLPTR);
66 
67  //@}
68 
69  // See the documentation for BufferedTransformation in cryptlib.h
70  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
71  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
72 
73  // See the documentation for BufferedTransformation in cryptlib.h
74  void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1);
75  bool Flush(bool hardFlush, int propagation=-1, bool blocking=true);
76  bool MessageSeriesEnd(int propagation=-1, bool blocking=true);
77 
78 protected:
79  virtual BufferedTransformation * NewDefaultAttachment() const;
80  void Insert(Filter *nextFilter); // insert filter after this one
81 
82  virtual bool ShouldPropagateMessageEnd() const {return true;}
83  virtual bool ShouldPropagateMessageSeriesEnd() const {return true;}
84 
85  void PropagateInitialize(const NameValuePairs &parameters, int propagation);
86 
87  /// \brief Forward processed data on to attached transformation
88  /// \param outputSite unknown, system crash between keyboard and chair...
89  /// \param inString the byte buffer to process
90  /// \param length the size of the string, in bytes
91  /// \param messageEnd means how many filters to signal MessageEnd() to, including this one
92  /// \param blocking specifies whether the object should block when processing input
93  /// \param channel the channel to process the data
94  /// \returns the number of bytes that remain in the block (i.e., bytes not processed)
95  size_t Output(int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
96 
97  /// \brief Output multiple bytes that may be modified by callee.
98  /// \param outputSite unknown, system crash between keyboard and chair...
99  /// \param inString the byte buffer to process
100  /// \param length the size of the string, in bytes
101  /// \param messageEnd means how many filters to signal MessageEnd() to, including this one
102  /// \param blocking specifies whether the object should block when processing input
103  /// \param channel the channel to process the data
104  /// \returns the number of bytes that remain in the block (i.e., bytes not processed)
105  size_t OutputModifiable(int outputSite, byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
106 
107  /// \brief Signals the end of messages to the object
108  /// \param outputSite unknown, system crash between keyboard and chair...
109  /// \param propagation the number of attached transformations the MessageEnd() signal should be passed
110  /// \param blocking specifies whether the object should block when processing input
111  /// \param channel the channel to process the data
112  /// \returns TODO
113  /// \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
114  /// object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
115  bool OutputMessageEnd(int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
116 
117  /// \brief Flush buffered input and/or output, with signal propagation
118  /// \param outputSite unknown, system crash between keyboard and chair...
119  /// \param hardFlush is used to indicate whether all data should be flushed
120  /// \param propagation the number of attached transformations the Flush() signal should be passed
121  /// \param blocking specifies whether the object should block when processing input
122  /// \param channel the channel to process the data
123  /// \returns TODO
124  /// \details propagation count includes this object. Setting propagation to <tt>1</tt> means this
125  /// object only. Setting propagation to <tt>-1</tt> means unlimited propagation.
126  /// \note Hard flushes must be used with care. It means try to process and output everything, even if
127  /// there may not be enough data to complete the action. For example, hard flushing a HexDecoder
128  /// would cause an error if you do it after inputing an odd number of hex encoded characters.
129  /// \note For some types of filters, like ZlibDecompressor, hard flushes can only
130  /// be done at "synchronization points". These synchronization points are positions in the data
131  /// stream that are created by hard flushes on the corresponding reverse filters, in this
132  /// example ZlibCompressor. This is useful when zlib compressed data is moved across a
133  /// network in packets and compression state is preserved across packets, as in the SSH2 protocol.
134  bool OutputFlush(int outputSite, bool hardFlush, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL);
135 
136  /// \brief Marks the end of a series of messages, with signal propagation
137  /// \param outputSite unknown, system crash between keyboard and chair...
138  /// \param propagation the number of attached transformations the MessageSeriesEnd() signal should be passed
139  /// \param blocking specifies whether the object should block when processing input
140  /// \param channel the channel to process the data
141  /// \returns TODO
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 /// \brief Create a working space in a BufferedTransformation
158 struct CRYPTOPP_DLL FilterPutSpaceHelper
159 {
160  virtual ~FilterPutSpaceHelper() {}
161 
162  /// \brief Create a working space in a BufferedTransformation
163  /// \param target BufferedTransformation for the working space
164  /// \param channel channel for the working space
165  /// \param minSize minimum size of the allocation, in bytes
166  /// \param desiredSize preferred size of the allocation, in bytes
167  /// \param bufferSize actual size of the allocation, in bytes
168  /// \pre <tt>desiredSize >= minSize</tt> and <tt>bufferSize >= minSize</tt>.
169  /// \details \p bufferSize is an IN and OUT parameter. If HelpCreatePutSpace() returns a non-NULL value, then
170  /// bufferSize is valid and provides the size of the working space created for the caller.
171  /// \details Internally, HelpCreatePutSpace() calls \ref BufferedTransformation::ChannelCreatePutSpace
172  /// "ChannelCreatePutSpace()" using \p desiredSize. If the target returns \p desiredSize with a size less
173  /// than \p minSize (i.e., the request could not be fulfilled), then an internal SecByteBlock
174  /// called \p m_tempSpace is resized and used for the caller.
175  byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize)
176  {
177  CRYPTOPP_ASSERT(desiredSize >= minSize && bufferSize >= minSize);
178  if (m_tempSpace.size() < minSize)
179  {
180  byte *result = target.ChannelCreatePutSpace(channel, desiredSize);
181  if (desiredSize >= minSize)
182  {
183  bufferSize = desiredSize;
184  return result;
185  }
186  m_tempSpace.New(bufferSize);
187  }
188 
189  bufferSize = m_tempSpace.size();
190  return m_tempSpace.begin();
191  }
192 
193  /// \brief Create a working space in a BufferedTransformation
194  /// \param target the BufferedTransformation for the working space
195  /// \param channel channel for the working space
196  /// \param minSize minimum size of the allocation, in bytes
197  /// \details Internally, the overload calls HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize) using \p minSize for missing arguments.
198  byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize)
199  {return HelpCreatePutSpace(target, channel, minSize, minSize, minSize);}
200 
201  /// \brief Create a working space in a BufferedTransformation
202  /// \param target the BufferedTransformation for the working space
203  /// \param channel channel for the working space
204  /// \param minSize minimum size of the allocation, in bytes
205  /// \param bufferSize the actual size of the allocation, in bytes
206  /// \details Internally, the overload calls HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize) using \p minSize for missing arguments.
207  byte *HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t bufferSize)
208  {return HelpCreatePutSpace(target, channel, minSize, minSize, bufferSize);}
209 
210  /// \brief Temporay working space
212 };
213 
214 /// \brief Measure how many bytes and messages pass through the filter
215 /// \details measure how many bytes and messages pass through the filter. The filter also serves as valve by
216 /// maintaining a list of ranges to skip during processing.
217 class CRYPTOPP_DLL MeterFilter : public Bufferless<Filter>
218 {
219 public:
220  virtual ~MeterFilter() {}
221 
222  /// \brief Construct a MeterFilter
223  /// \param attachment an optional attached transformation
224  /// \param transparent flag indicating if the filter should function transparently
225  /// \details \p attachment can be \p NULL. The filter is transparent by default. If the filter is
226  /// transparent, then PutMaybeModifiable() does not process a request and always returns 0.
227  MeterFilter(BufferedTransformation *attachment=NULLPTR, bool transparent=true)
228  : m_transparent(transparent), m_currentMessageBytes(0), m_totalBytes(0)
229  , m_currentSeriesMessages(0), m_totalMessages(0), m_totalMessageSeries(0)
230  , m_begin(NULLPTR), m_length(0) {Detach(attachment); ResetMeter();}
231 
232  /// \brief Set or change the transparent mode of this object
233  /// \param transparent the new transparent mode
234  void SetTransparent(bool transparent) {m_transparent = transparent;}
235 
236  /// \brief Adds a range to skip during processing
237  /// \param message the message to apply the range
238  /// \param position the 0-based index in the current stream
239  /// \param size the length of the range
240  /// \param sortNow flag indicating whether the range should be sorted
241  /// \details Internally, MeterFilter maitains a deque of ranges to skip. As messages are processed,
242  /// ranges of bytes are skipped according to the list of ranges.
243  void AddRangeToSkip(unsigned int message, lword position, lword size, bool sortNow = true);
244 
245  /// \brief Resets the meter
246  /// \details ResetMeter() reinitializes the meter by setting counters to 0 and removing previous
247  /// skip ranges.
248  void ResetMeter();
249 
250  void IsolatedInitialize(const NameValuePairs &parameters)
251  {CRYPTOPP_UNUSED(parameters); ResetMeter();}
252 
253  lword GetCurrentMessageBytes() const {return m_currentMessageBytes;}
254  lword GetTotalBytes() const {return m_totalBytes;}
255  unsigned int GetCurrentSeriesMessages() const {return m_currentSeriesMessages;}
256  unsigned int GetTotalMessages() const {return m_totalMessages;}
257  unsigned int GetTotalMessageSeries() const {return m_totalMessageSeries;}
258 
259  byte * CreatePutSpace(size_t &size)
260  {return AttachedTransformation()->CreatePutSpace(size);}
261  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
262  size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking);
263  bool IsolatedMessageSeriesEnd(bool blocking);
264 
265 private:
266  size_t PutMaybeModifiable(byte *inString, size_t length, int messageEnd, bool blocking, bool modifiable);
267  bool ShouldPropagateMessageEnd() const {return m_transparent;}
268  bool ShouldPropagateMessageSeriesEnd() const {return m_transparent;}
269 
270  struct MessageRange
271  {
272  inline bool operator<(const MessageRange &b) const // BCB2006 workaround: this has to be a member function
273  {return message < b.message || (message == b.message && position < b.position);}
274  unsigned int message; lword position; lword size;
275  };
276 
277  bool m_transparent;
278  lword m_currentMessageBytes, m_totalBytes;
279  unsigned int m_currentSeriesMessages, m_totalMessages, m_totalMessageSeries;
280  std::deque<MessageRange> m_rangesToSkip;
281  byte *m_begin;
282  size_t m_length;
283 };
284 
285 /// \brief A transparent MeterFilter
286 /// \sa MeterFilter, OpaqueFilter
287 class CRYPTOPP_DLL TransparentFilter : public MeterFilter
288 {
289 public:
290  /// \brief Construct a TransparentFilter
291  /// \param attachment an optional attached transformation
292  TransparentFilter(BufferedTransformation *attachment=NULLPTR) : MeterFilter(attachment, true) {}
293 };
294 
295 /// \brief A non-transparent MeterFilter
296 /// \sa MeterFilter, TransparentFilter
297 class CRYPTOPP_DLL OpaqueFilter : public MeterFilter
298 {
299 public:
300  /// \brief Construct an OpaqueFilter
301  /// \param attachment an optional attached transformation
302  OpaqueFilter(BufferedTransformation *attachment=NULLPTR) : MeterFilter(attachment, false) {}
303 };
304 
305 /// \brief Divides an input stream into discrete blocks
306 /// \details FilterWithBufferedInput divides the input stream into a first block, a number of
307 /// middle blocks, and a last block. First and last blocks are optional, and middle blocks may
308 /// be a stream instead (i.e. <tt>blockSize == 1</tt>).
309 /// \sa AuthenticatedEncryptionFilter, AuthenticatedDecryptionFilter, HashVerificationFilter,
310 /// SignatureVerificationFilter, StreamTransformationFilter
311 class CRYPTOPP_DLL FilterWithBufferedInput : public Filter
312 {
313 public:
314  virtual ~FilterWithBufferedInput() {}
315 
316  /// \brief Construct a FilterWithBufferedInput with an attached transformation
317  /// \param attachment an attached transformation
319 
320  /// \brief Construct a FilterWithBufferedInput with an attached transformation
321  /// \param firstSize the size of the first block
322  /// \param blockSize the size of middle blocks
323  /// \param lastSize the size of the last block
324  /// \param attachment an attached transformation
325  /// \details \p firstSize and \p lastSize may be 0. \p blockSize must be at least 1.
326  FilterWithBufferedInput(size_t firstSize, size_t blockSize, size_t lastSize, BufferedTransformation *attachment);
327 
328  void IsolatedInitialize(const NameValuePairs &parameters);
329  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
330  {
331  return PutMaybeModifiable(const_cast<byte *>(inString), length, messageEnd, blocking, false);
332  }
333 
334  size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
335  {
336  return PutMaybeModifiable(inString, length, messageEnd, blocking, true);
337  }
338 
339  /// \brief Flushes data buffered by this object, without signal propagation
340  /// \param hardFlush indicates whether all data should be flushed
341  /// \param blocking specifies whether the object should block when processing input
342  /// \details IsolatedFlush() calls ForceNextPut() if hardFlush is true
343  /// \note hardFlush must be used with care
344  bool IsolatedFlush(bool hardFlush, bool blocking);
345 
346  /// \brief Flushes data buffered by this object
347  /// \details The input buffer may contain more than blockSize bytes if <tt>lastSize != 0</tt>.
348  /// ForceNextPut() forces a call to NextPut() if this is the case.
349  void ForceNextPut();
350 
351 protected:
352  virtual bool DidFirstPut() const {return m_firstInputDone;}
353  virtual size_t GetFirstPutSize() const {return m_firstSize;}
354  virtual size_t GetBlockPutSize() const {return m_blockSize;}
355  virtual size_t GetLastPutSize() const {return m_lastSize;}
356 
357  virtual void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize)
358  {CRYPTOPP_UNUSED(parameters); CRYPTOPP_UNUSED(firstSize); CRYPTOPP_UNUSED(blockSize); CRYPTOPP_UNUSED(lastSize); InitializeDerived(parameters);}
359  virtual void InitializeDerived(const NameValuePairs &parameters)
360  {CRYPTOPP_UNUSED(parameters);}
361  // FirstPut() is called if (firstSize != 0 and totalLength >= firstSize)
362  // or (firstSize == 0 and (totalLength > 0 or a MessageEnd() is received)).
363  // inString is m_firstSize in length.
364  virtual void FirstPut(const byte *inString) =0;
365  // NextPut() is called if totalLength >= firstSize+blockSize+lastSize
366  virtual void NextPutSingle(const byte *inString)
367  {CRYPTOPP_UNUSED(inString); CRYPTOPP_ASSERT(false);}
368  // Same as NextPut() except length can be a multiple of blockSize
369  // Either NextPut() or NextPutMultiple() must be overridden
370  virtual void NextPutMultiple(const byte *inString, size_t length);
371  // Same as NextPutMultiple(), but inString can be modified
372  virtual void NextPutModifiable(byte *inString, size_t length)
373  {NextPutMultiple(inString, length);}
374  /// \brief Input the last block of data
375  /// \param inString the input byte buffer
376  /// \param length the size of the input buffer, in bytes
377  /// \details LastPut() processes the last block of data and signals attached filters to do the same.
378  /// LastPut() is always called. The pseudo algorithm for the logic is:
379  /// <pre>
380  /// if totalLength < firstSize then length == totalLength
381  /// else if totalLength <= firstSize+lastSize then length == totalLength-firstSize
382  /// else lastSize <= length < lastSize+blockSize
383  /// </pre>
384  virtual void LastPut(const byte *inString, size_t length) =0;
385  virtual void FlushDerived() {}
386 
387 protected:
388  size_t PutMaybeModifiable(byte *begin, size_t length, int messageEnd, bool blocking, bool modifiable);
389  void NextPutMaybeModifiable(byte *inString, size_t length, bool modifiable)
390  {
391  if (modifiable) NextPutModifiable(inString, length);
392  else NextPutMultiple(inString, length);
393  }
394 
395  // This function should no longer be used, put this here to cause a compiler error
396  // if someone tries to override NextPut().
397  virtual int NextPut(const byte *inString, size_t length)
398  {CRYPTOPP_UNUSED(inString); CRYPTOPP_UNUSED(length); CRYPTOPP_ASSERT(false); return 0;}
399 
400  class BlockQueue
401  {
402  public:
403  void ResetQueue(size_t blockSize, size_t maxBlocks);
404  byte *GetBlock();
405  byte *GetContigousBlocks(size_t &numberOfBytes);
406  size_t GetAll(byte *outString);
407  void Put(const byte *inString, size_t length);
408  size_t CurrentSize() const {return m_size;}
409  size_t MaxSize() const {return m_buffer.size();}
410 
411  private:
412  SecByteBlock m_buffer;
413  size_t m_blockSize, m_maxBlocks, m_size;
414  byte *m_begin;
415  };
416 
417  size_t m_firstSize, m_blockSize, m_lastSize;
418  bool m_firstInputDone;
419  BlockQueue m_queue;
420 };
421 
422 /// \brief A filter that buffers input using a ByteQueue
423 /// \details FilterWithInputQueue will buffer input using a ByteQueue. When the filter receives
424 /// a \ref BufferedTransformation::MessageEnd() "MessageEnd()" signal it will pass the data
425 /// on to its attached transformation.
426 class CRYPTOPP_DLL FilterWithInputQueue : public Filter
427 {
428 public:
429  virtual ~FilterWithInputQueue() {}
430 
431  /// \brief Construct a FilterWithInputQueue
432  /// \param attachment an optional attached transformation
433  FilterWithInputQueue(BufferedTransformation *attachment=NULLPTR) : Filter(attachment) {}
434 
435  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
436  {
437  if (!blocking)
438  throw BlockingInputOnly("FilterWithInputQueue");
439 
440  m_inQueue.Put(inString, length);
441  if (messageEnd)
442  {
443  IsolatedMessageEnd(blocking);
444  Output(0, NULLPTR, 0, messageEnd, blocking);
445  }
446  return 0;
447  }
448 
449 protected:
450  virtual bool IsolatedMessageEnd(bool blocking) =0;
451  void IsolatedInitialize(const NameValuePairs &parameters)
452  {CRYPTOPP_UNUSED(parameters); m_inQueue.Clear();}
453 
454  ByteQueue m_inQueue;
455 };
456 
457 /// \struct BlockPaddingSchemeDef
458 /// \brief Padding schemes used for block ciphers
459 /// \since Crypto++ 5.0
461 {
462  /// \enum BlockPaddingScheme
463  /// \brief Padding schemes used for block ciphers.
464  /// \details DEFAULT_PADDING means PKCS_PADDING if <tt>cipher.MandatoryBlockSize() > 1 &&
465  /// cipher.MinLastBlockSize() == 0</tt>, which holds for ECB or CBC mode. Otherwise,
466  /// NO_PADDING for modes like OFB, CFB, CTR, CBC-CTS.
467  /// \sa <A HREF="http://www.weidai.com/scan-mirror/csp.html">Block Cipher Padding</A> for
468  /// additional details.
469  /// \since Crypto++ 5.0
471  /// \brief No padding added to a block
472  /// \since Crypto++ 5.0
474  /// \brief 0's padding added to a block
475  /// \since Crypto++ 5.0
477  /// \brief PKCS #5 padding added to a block
478  /// \since Crypto++ 5.0
480  /// \brief 1 and 0's padding added to a block
481  /// \since Crypto++ 5.0
483  /// \brief W3C padding added to a block
484  /// \sa <A HREF="http://www.w3.org/TR/2002/REC-xmlenc-core-20021210/Overview.html">XML
485  /// Encryption Syntax and Processing</A>
486  /// \since Crypto++ 6.0
488  /// \brief Default padding scheme
489  /// \since Crypto++ 5.0
490  DEFAULT_PADDING
491  };
492 };
493 
494 /// \brief Filter wrapper for StreamTransformation
495 /// \details StreamTransformationFilter() is a filter wrapper for StreamTransformation(). It is used when
496 /// pipelining data for stream ciphers and confidentiality-only block ciphers. The filter will optionally
497 /// handle padding and unpadding when needed. If you are using an authenticated encryption mode of operation,
498 /// then use AuthenticatedEncryptionFilter() and AuthenticatedDecryptionFilter()
499 /// \since Crypto++ 5.0
501 {
502 public:
503  virtual ~StreamTransformationFilter() {}
504 
505  /// \brief Construct a StreamTransformationFilter
506  /// \param c reference to a StreamTransformation
507  /// \param attachment an optional attached transformation
508  /// \param padding the \ref BlockPaddingSchemeDef "padding scheme"
509  /// \details This contructor creates a StreamTransformationFilter() for stream ciphers and
510  /// confidentiality-only block cipher modes of operation. If you are using an authenticated
511  /// encryption mode of operation, then use either AuthenticatedEncryptionFilter() or
512  /// AuthenticatedDecryptionFilter().
513  /// \sa AuthenticatedEncryptionFilter() and AuthenticatedDecryptionFilter()
514  StreamTransformationFilter(StreamTransformation &c, BufferedTransformation *attachment = NULLPTR, BlockPaddingScheme padding = DEFAULT_PADDING);
515 
516  std::string AlgorithmName() const {return m_cipher.AlgorithmName();}
517 
518 protected:
519 
520  friend class AuthenticatedEncryptionFilter;
521  friend class AuthenticatedDecryptionFilter;
522 
523  /// \brief Construct a StreamTransformationFilter
524  /// \param c reference to a StreamTransformation
525  /// \param attachment an optional attached transformation
526  /// \param padding the \ref BlockPaddingSchemeDef "padding scheme"
527  /// \param authenticated flag indicating whether the filter should allow authenticated encryption schemes
528  /// \details This constructor is used for authenticated encryption mode of operation and by
529  /// AuthenticatedEncryptionFilter() and AuthenticatedDecryptionFilter().
531 
532  void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize);
533  void FirstPut(const byte *inString);
534  void NextPutMultiple(const byte *inString, size_t length);
535  void NextPutModifiable(byte *inString, size_t length);
536  void LastPut(const byte *inString, size_t length);
537 
538  static size_t LastBlockSize(StreamTransformation &c, BlockPaddingScheme padding);
539 
540  StreamTransformation &m_cipher;
541  BlockPaddingScheme m_padding;
542  unsigned int m_mandatoryBlockSize;
543  unsigned int m_optimalBufferSize;
544  unsigned int m_reservedBufferSize;
545  bool m_isSpecial;
546 };
547 
548 /// \brief Filter wrapper for HashTransformation
549 /// \since Crypto++ 1.0
550 class CRYPTOPP_DLL HashFilter : public Bufferless<Filter>, private FilterPutSpaceHelper
551 {
552 public:
553  virtual ~HashFilter() {}
554 
555  /// \brief Construct a HashFilter
556  /// \param hm reference to a HashTransformation
557  /// \param attachment an optional attached transformation
558  /// \param putMessage flag indicating whether the original message should be passed to an attached transformation
559  /// \param truncatedDigestSize the size of the digest
560  /// \param messagePutChannel the channel on which the message should be output
561  /// \param hashPutChannel the channel on which the digest should be output
562  HashFilter(HashTransformation &hm, BufferedTransformation *attachment = NULLPTR, bool putMessage=false, int truncatedDigestSize=-1, const std::string &messagePutChannel=DEFAULT_CHANNEL, const std::string &hashPutChannel=DEFAULT_CHANNEL);
563 
564  std::string AlgorithmName() const {return m_hashModule.AlgorithmName();}
565  void IsolatedInitialize(const NameValuePairs &parameters);
566  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
567  byte * CreatePutSpace(size_t &size) {return m_hashModule.CreateUpdateSpace(size);}
568 
569 private:
570  HashTransformation &m_hashModule;
571  bool m_putMessage;
572  unsigned int m_digestSize;
573  byte *m_space;
574  std::string m_messagePutChannel, m_hashPutChannel;
575 };
576 
577 /// \brief Filter wrapper for HashTransformation
578 /// \since Crypto++ 4.0
580 {
581 public:
582  virtual ~HashVerificationFilter() {}
583 
584  /// \brief Exception thrown when a data integrity check failure is encountered
586  {
587  public:
589  : Exception(DATA_INTEGRITY_CHECK_FAILED, "HashVerificationFilter: message hash or MAC not valid") {}
590  };
591 
592  /// \enum Flags
593  /// \brief Flags controlling filter behavior.
594  /// \details The flags are a bitmask and can be OR'd together.
595  enum Flags {
596  /// \brief Indicates the hash is at the end of the message (i.e., concatenation of message+hash)
597  HASH_AT_END=0,
598  /// \brief Indicates the hash is at the beginning of the message (i.e., concatenation of hash+message)
599  HASH_AT_BEGIN=1,
600  /// \brief Indicates the message should be passed to an attached transformation
601  PUT_MESSAGE=2,
602  /// \brief Indicates the hash should be passed to an attached transformation
603  PUT_HASH=4,
604  /// \brief Indicates the result of the verification should be passed to an attached transformation
605  PUT_RESULT=8,
606  /// \brief Indicates the filter should throw a HashVerificationFailed if a failure is encountered
607  THROW_EXCEPTION=16,
608  /// \brief Default flags using \p HASH_AT_BEGIN and \p PUT_RESULT
609  DEFAULT_FLAGS = HASH_AT_BEGIN | PUT_RESULT
610  };
611 
612  /// \brief Construct a HashVerificationFilter
613  /// \param hm reference to a HashTransformation
614  /// \param attachment an optional attached transformation
615  /// \param flags flags indicating behaviors for the filter
616  /// \param truncatedDigestSize the size of the digest
617  /// \details <tt>truncatedDigestSize = -1</tt> indicates \ref HashTransformation::DigestSize() "DigestSize" should be used.
618  HashVerificationFilter(HashTransformation &hm, BufferedTransformation *attachment = NULLPTR, word32 flags = DEFAULT_FLAGS, int truncatedDigestSize=-1);
619 
620  std::string AlgorithmName() const {return m_hashModule.AlgorithmName();}
621  bool GetLastResult() const {return m_verified;}
622 
623 protected:
624  void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize);
625  void FirstPut(const byte *inString);
626  void NextPutMultiple(const byte *inString, size_t length);
627  void LastPut(const byte *inString, size_t length);
628 
629 private:
630  friend class AuthenticatedDecryptionFilter;
631 
632  HashTransformation &m_hashModule;
633  word32 m_flags;
634  unsigned int m_digestSize;
635  bool m_verified;
636  SecByteBlock m_expectedHash;
637 };
638 
639 /// \brief Filter wrapper for encrypting with AuthenticatedSymmetricCipher
640 /// \details AuthenticatedEncryptionFilter() is a wrapper for encrypting with AuthenticatedSymmetricCipher(),
641 /// optionally handling padding/unpadding when needed.
642 /// \sa AuthenticatedDecryptionFilter, EAX, CCM, GCM, AuthenticatedSymmetricCipher
643 /// \since Crypto++ 5.6.0
645 {
646 public:
647  virtual ~AuthenticatedEncryptionFilter() {}
648 
649  /// \brief Construct a AuthenticatedEncryptionFilter
650  /// \param c reference to a AuthenticatedSymmetricCipher
651  /// \param attachment an optional attached transformation
652  /// \param putAAD flag indicating whether the AAD should be passed to an attached transformation
653  /// \param truncatedDigestSize the size of the digest
654  /// \param macChannel the channel on which the MAC should be output
655  /// \param padding the \ref BlockPaddingSchemeDef "padding scheme"
656  /// \details <tt>truncatedDigestSize = -1</tt> indicates \ref HashTransformation::DigestSize() "DigestSize" should be used.
657  /// \since Crypto++ 5.6.0
658  AuthenticatedEncryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment = NULLPTR, bool putAAD=false, int truncatedDigestSize=-1, const std::string &macChannel=DEFAULT_CHANNEL, BlockPaddingScheme padding = DEFAULT_PADDING);
659 
660  void IsolatedInitialize(const NameValuePairs &parameters);
661  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
662  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
663 
664  /// \brief Input the last block of data
665  /// \param inString the input byte buffer
666  /// \param length the size of the input buffer, in bytes
667  /// \details LastPut() processes the last block of data and signals attached filters to do the same.
668  /// LastPut() is always called. The pseudo algorithm for the logic is:
669  /// <pre>
670  /// if totalLength < firstSize then length == totalLength
671  /// else if totalLength <= firstSize+lastSize then length == totalLength-firstSize
672  /// else lastSize <= length < lastSize+blockSize
673  /// </pre>
674  void LastPut(const byte *inString, size_t length);
675 
676 protected:
677  HashFilter m_hf;
678 };
679 
680 /// \brief Filter wrapper for decrypting with AuthenticatedSymmetricCipher
681 /// \details AuthenticatedDecryptionFilter() is a wrapper for decrypting with AuthenticatedSymmetricCipher(),
682 /// optionally handling padding/unpadding when needed.
683 /// \sa AuthenticatedEncryptionFilter, EAX, CCM, GCM, AuthenticatedSymmetricCipher
684 /// \since Crypto++ 5.6.0
686 {
687 public:
688  /// \enum Flags
689  /// \brief Flags controlling filter behavior.
690  /// \details The flags are a bitmask and can be OR'd together.
691  enum Flags {
692  /// \brief Indicates the MAC is at the end of the message (i.e., concatenation of message+mac)
693  MAC_AT_END=0,
694  /// \brief Indicates the MAC is at the beginning of the message (i.e., concatenation of mac+message)
695  MAC_AT_BEGIN=1,
696  /// \brief Indicates the filter should throw a HashVerificationFailed if a failure is encountered
697  THROW_EXCEPTION=16,
698  /// \brief Default flags using \p THROW_EXCEPTION
699  DEFAULT_FLAGS = THROW_EXCEPTION
700  };
701 
702  virtual ~AuthenticatedDecryptionFilter() {}
703 
704  /// \brief Construct a AuthenticatedDecryptionFilter
705  /// \param c reference to a AuthenticatedSymmetricCipher
706  /// \param attachment an optional attached transformation
707  /// \param flags flags indicating behaviors for the filter
708  /// \param truncatedDigestSize the size of the digest
709  /// \param padding the \ref BlockPaddingSchemeDef "padding scheme"
710  /// \details Additional authenticated data should be given in channel "AAD".
711  /// \details <tt>truncatedDigestSize = -1</tt> indicates \ref HashTransformation::DigestSize() "DigestSize" should be used.
712  /// \since Crypto++ 5.6.0
713  AuthenticatedDecryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment = NULLPTR, word32 flags = DEFAULT_FLAGS, int truncatedDigestSize=-1, BlockPaddingScheme padding = DEFAULT_PADDING);
714 
715  std::string AlgorithmName() const {return m_hashVerifier.AlgorithmName();}
716  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
717  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
718  bool GetLastResult() const {return m_hashVerifier.GetLastResult();}
719 
720 protected:
721  void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize);
722  void FirstPut(const byte *inString);
723  void NextPutMultiple(const byte *inString, size_t length);
724 
725  /// \brief Input the last block of data
726  /// \param inString the input byte buffer
727  /// \param length the size of the input buffer, in bytes
728  /// \details LastPut() processes the last block of data and signals attached filters to do the same.
729  /// LastPut() is always called. The pseudo algorithm for the logic is:
730  /// <pre>
731  /// if totalLength < firstSize then length == totalLength
732  /// else if totalLength <= firstSize+lastSize then length == totalLength-firstSize
733  /// else lastSize <= length < lastSize+blockSize
734  /// </pre>
735  void LastPut(const byte *inString, size_t length);
736 
737  HashVerificationFilter m_hashVerifier;
738  StreamTransformationFilter m_streamFilter;
739 };
740 
741 /// \brief Filter wrapper for PK_Signer
742 /// \since Crypto++ 4.0
743 class CRYPTOPP_DLL SignerFilter : public Unflushable<Filter>
744 {
745 public:
746  virtual ~SignerFilter() {}
747 
748  /// \brief Construct a SignerFilter
749  /// \param rng a RandomNumberGenerator derived class
750  /// \param signer a PK_Signer derived class
751  /// \param attachment an optional attached transformation
752  /// \param putMessage flag indicating whether the original message should be passed to an attached transformation
753  SignerFilter(RandomNumberGenerator &rng, const PK_Signer &signer, BufferedTransformation *attachment = NULLPTR, bool putMessage=false)
754  : m_rng(rng), m_signer(signer), m_messageAccumulator(signer.NewSignatureAccumulator(rng)), m_putMessage(putMessage) {Detach(attachment);}
755 
756  std::string AlgorithmName() const {return m_signer.AlgorithmName();}
757 
758  void IsolatedInitialize(const NameValuePairs &parameters);
759  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
760 
761 private:
762  RandomNumberGenerator &m_rng;
763  const PK_Signer &m_signer;
764  member_ptr<PK_MessageAccumulator> m_messageAccumulator;
765  bool m_putMessage;
766  SecByteBlock m_buf;
767 };
768 
769 /// \brief Filter wrapper for PK_Verifier
770 /// \details This filter was formerly named <tt>VerifierFilter</tt>. The name changed at Crypto++ 5.0.
771 /// \since Crypto++ 4.0
773 {
774 public:
775  /// \brief Exception thrown when an invalid signature is encountered
777  {
778  public:
780  : Exception(DATA_INTEGRITY_CHECK_FAILED, "VerifierFilter: digital signature not valid") {}
781  };
782 
783  /// \enum Flags
784  /// \brief Flags controlling filter behavior.
785  /// \details The flags are a bitmask and can be OR'd together.
786  enum Flags {
787  /// \brief Indicates the signature is at the end of the message (i.e., concatenation of message+signature)
788  SIGNATURE_AT_END=0,
789  /// \brief Indicates the signature is at the beginning of the message (i.e., concatenation of signature+message)
790  SIGNATURE_AT_BEGIN=1,
791  /// \brief Indicates the message should be passed to an attached transformation
792  PUT_MESSAGE=2,
793  /// \brief Indicates the signature should be passed to an attached transformation
794  PUT_SIGNATURE=4,
795  /// \brief Indicates the result of the verification should be passed to an attached transformation
796  PUT_RESULT=8,
797  /// \brief Indicates the filter should throw a HashVerificationFailed if a failure is encountered
798  THROW_EXCEPTION=16,
799  /// \brief Default flags using \p SIGNATURE_AT_BEGIN and \p PUT_RESULT
800  DEFAULT_FLAGS = SIGNATURE_AT_BEGIN | PUT_RESULT
801  };
802 
803  virtual ~SignatureVerificationFilter() {}
804 
805  /// \brief Construct a SignatureVerificationFilter
806  /// \param verifier a PK_Verifier derived class
807  /// \param attachment an optional attached transformation
808  /// \param flags flags indicating behaviors for the filter
809  SignatureVerificationFilter(const PK_Verifier &verifier, BufferedTransformation *attachment = NULLPTR, word32 flags = DEFAULT_FLAGS);
810 
811  std::string AlgorithmName() const {return m_verifier.AlgorithmName();}
812 
813  /// \brief Retrieves the result of the last verification
814  /// \returns true if the signature on the previosus message was valid, false otherwise
815  bool GetLastResult() const {return m_verified;}
816 
817 protected:
818  void InitializeDerivedAndReturnNewSizes(const NameValuePairs &parameters, size_t &firstSize, size_t &blockSize, size_t &lastSize);
819  void FirstPut(const byte *inString);
820  void NextPutMultiple(const byte *inString, size_t length);
821  void LastPut(const byte *inString, size_t length);
822 
823 private:
824  const PK_Verifier &m_verifier;
825  member_ptr<PK_MessageAccumulator> m_messageAccumulator;
826  word32 m_flags;
827  SecByteBlock m_signature;
828  bool m_verified;
829 };
830 
831 /// \brief Redirect input to another BufferedTransformation without owning it
832 /// \since Crypto++ 4.0
833 class CRYPTOPP_DLL Redirector : public CustomSignalPropagation<Sink>
834 {
835 public:
836  /// \enum Behavior
837  /// \brief Controls signal propagation behavior
838  enum Behavior
839  {
840  /// \brief Pass data only
841  DATA_ONLY = 0x00,
842  /// \brief Pass signals
843  PASS_SIGNALS = 0x01,
844  /// \brief Pass wait events
845  PASS_WAIT_OBJECTS = 0x02,
846  /// \brief Pass everything
847  /// \details PASS_EVERYTHING is default
848  PASS_EVERYTHING = PASS_SIGNALS | PASS_WAIT_OBJECTS
849  };
850 
851  virtual ~Redirector() {}
852 
853  /// \brief Construct a Redirector
854  Redirector() : m_target(NULLPTR), m_behavior(PASS_EVERYTHING) {}
855 
856  /// \brief Construct a Redirector
857  /// \param target the destination BufferedTransformation
858  /// \param behavior Behavior "flags" specifying signal propagation
859  Redirector(BufferedTransformation &target, Behavior behavior=PASS_EVERYTHING)
860  : m_target(&target), m_behavior(behavior) {}
861 
862  /// \brief Redirect input to another BufferedTransformation
863  /// \param target the destination BufferedTransformation
864  void Redirect(BufferedTransformation &target) {m_target = &target;}
865  /// \brief Stop redirecting input
866  void StopRedirection() {m_target = NULLPTR;}
867 
868  Behavior GetBehavior() {return (Behavior) m_behavior;}
869  void SetBehavior(Behavior behavior) {m_behavior=behavior;}
870  bool GetPassSignals() const {return (m_behavior & PASS_SIGNALS) != 0;}
871  void SetPassSignals(bool pass) { if (pass) m_behavior |= PASS_SIGNALS; else m_behavior &= ~(word32) PASS_SIGNALS; }
872  bool GetPassWaitObjects() const {return (m_behavior & PASS_WAIT_OBJECTS) != 0;}
873  void SetPassWaitObjects(bool pass) { if (pass) m_behavior |= PASS_WAIT_OBJECTS; else m_behavior &= ~(word32) PASS_WAIT_OBJECTS; }
874 
875  bool CanModifyInput() const
876  {return m_target ? m_target->CanModifyInput() : false;}
877 
878  void Initialize(const NameValuePairs &parameters, int propagation);
879  byte * CreatePutSpace(size_t &size)
880  {
881  if (m_target)
882  return m_target->CreatePutSpace(size);
883  else
884  {
885  size = 0;
886  return NULLPTR;
887  }
888  }
889  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
890  {return m_target ? m_target->Put2(inString, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;}
891  bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
892  {return m_target && GetPassSignals() ? m_target->Flush(hardFlush, propagation, blocking) : false;}
893  bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
894  {return m_target && GetPassSignals() ? m_target->MessageSeriesEnd(propagation, blocking) : false;}
895 
896  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
897  {
898  if (m_target)
899  return m_target->ChannelCreatePutSpace(channel, size);
900  else
901  {
902  size = 0;
903  return NULLPTR;
904  }
905  }
906  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
907  {return m_target ? m_target->ChannelPut2(channel, begin, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;}
908  size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
909  {return m_target ? m_target->ChannelPutModifiable2(channel, begin, length, GetPassSignals() ? messageEnd : 0, blocking) : 0;}
910  bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true)
911  {return m_target && GetPassSignals() ? m_target->ChannelFlush(channel, completeFlush, propagation, blocking) : false;}
912  bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true)
913  {return m_target && GetPassSignals() ? m_target->ChannelMessageSeriesEnd(channel, propagation, blocking) : false;}
914 
915  unsigned int GetMaxWaitObjectCount() const
916  { return m_target && GetPassWaitObjects() ? m_target->GetMaxWaitObjectCount() : 0; }
917  void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack)
918  { if (m_target && GetPassWaitObjects()) m_target->GetWaitObjects(container, callStack); }
919 
920 private:
921  BufferedTransformation *m_target;
922  word32 m_behavior;
923 };
924 
925 /// \brief Filter class that is a proxy for a sink
926 /// \details Used By ProxyFilter
927 /// \since Crypto++ 4.0
928 class CRYPTOPP_DLL OutputProxy : public CustomSignalPropagation<Sink>
929 {
930 public:
931  virtual ~OutputProxy() {}
932 
933  /// \brief Construct an OutputProxy
934  /// \param owner the owning transformation
935  /// \param passSignal flag indicating if signals should be passed
936  OutputProxy(BufferedTransformation &owner, bool passSignal) : m_owner(owner), m_passSignal(passSignal) {}
937 
938  /// \brief Retrieve passSignal flag
939  /// \returns flag indicating if signals should be passed
940  bool GetPassSignal() const {return m_passSignal;}
941  /// \brief Set passSignal flag
942  /// \param passSignal flag indicating if signals should be passed
943  void SetPassSignal(bool passSignal) {m_passSignal = passSignal;}
944 
945  byte * CreatePutSpace(size_t &size)
946  {return m_owner.AttachedTransformation()->CreatePutSpace(size);}
947  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
948  {return m_owner.AttachedTransformation()->Put2(inString, length, m_passSignal ? messageEnd : 0, blocking);}
949  size_t PutModifiable2(byte *begin, size_t length, int messageEnd, bool blocking)
950  {return m_owner.AttachedTransformation()->PutModifiable2(begin, length, m_passSignal ? messageEnd : 0, blocking);}
951  void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
952  {if (m_passSignal) m_owner.AttachedTransformation()->Initialize(parameters, propagation);}
953  bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
954  {return m_passSignal ? m_owner.AttachedTransformation()->Flush(hardFlush, propagation, blocking) : false;}
955  bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
956  {return m_passSignal ? m_owner.AttachedTransformation()->MessageSeriesEnd(propagation, blocking) : false;}
957 
958  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
959  {return m_owner.AttachedTransformation()->ChannelCreatePutSpace(channel, size);}
960  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
961  {return m_owner.AttachedTransformation()->ChannelPut2(channel, begin, length, m_passSignal ? messageEnd : 0, blocking);}
962  size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
963  {return m_owner.AttachedTransformation()->ChannelPutModifiable2(channel, begin, length, m_passSignal ? messageEnd : 0, blocking);}
964  bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true)
965  {return m_passSignal ? m_owner.AttachedTransformation()->ChannelFlush(channel, completeFlush, propagation, blocking) : false;}
966  bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true)
967  {return m_passSignal ? m_owner.AttachedTransformation()->ChannelMessageSeriesEnd(channel, propagation, blocking) : false;}
968 
969 private:
970  BufferedTransformation &m_owner;
971  bool m_passSignal;
972 };
973 
974 /// \brief Base class for Filter classes that are proxies for a chain of other filters
975 /// \since Crypto++ 4.0
976 class CRYPTOPP_DLL ProxyFilter : public FilterWithBufferedInput
977 {
978 public:
979  virtual ~ProxyFilter() {}
980 
981  /// \brief Construct a ProxyFilter
982  /// \param filter an output filter
983  /// \param firstSize the first Put size
984  /// \param lastSize the last Put size
985  /// \param attachment an attached transformation
986  ProxyFilter(BufferedTransformation *filter, size_t firstSize, size_t lastSize, BufferedTransformation *attachment);
987 
988  bool IsolatedFlush(bool hardFlush, bool blocking);
989 
990  /// \brief Sets the OutputProxy filter
991  /// \param filter an OutputProxy filter
992  void SetFilter(Filter *filter);
993  void NextPutMultiple(const byte *s, size_t len);
994  void NextPutModifiable(byte *inString, size_t length);
995 
996 protected:
998 };
999 
1000 /// \brief Proxy filter that doesn't modify the underlying filter's input or output
1001 /// \since Crypto++ 5.0
1002 class CRYPTOPP_DLL SimpleProxyFilter : public ProxyFilter
1003 {
1004 public:
1005  /// \brief Construct a SimpleProxyFilter
1006  /// \param filter an output filter
1007  /// \param attachment an attached transformation
1009  : ProxyFilter(filter, 0, 0, attachment) {}
1010 
1011  void FirstPut(const byte * inString)
1012  {CRYPTOPP_UNUSED(inString);}
1013 
1014  /// \brief Input the last block of data
1015  /// \param inString the input byte buffer
1016  /// \param length the size of the input buffer, in bytes
1017  /// \details LastPut() processes the last block of data and signals attached filters to do the same.
1018  /// LastPut() is always called. The pseudo algorithm for the logic is:
1019  /// <pre>
1020  /// if totalLength < firstSize then length == totalLength
1021  /// else if totalLength <= firstSize+lastSize then length == totalLength-firstSize
1022  /// else lastSize <= length < lastSize+blockSize
1023  /// </pre>
1024  void LastPut(const byte *inString, size_t length)
1025  {CRYPTOPP_UNUSED(inString), CRYPTOPP_UNUSED(length); m_filter->MessageEnd();}
1026 };
1027 
1028 /// \brief Filter wrapper for PK_Encryptor
1029 /// \details PK_DecryptorFilter is a proxy for the filter created by PK_Encryptor::CreateEncryptionFilter.
1030 /// This class provides symmetry with VerifierFilter.
1031 /// \since Crypto++ 5.0
1032 class CRYPTOPP_DLL PK_EncryptorFilter : public SimpleProxyFilter
1033 {
1034 public:
1035  /// \brief Construct a PK_EncryptorFilter
1036  /// \param rng a RandomNumberGenerator derived class
1037  /// \param encryptor a PK_Encryptor derived class
1038  /// \param attachment an optional attached transformation
1039  PK_EncryptorFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment = NULLPTR)
1040  : SimpleProxyFilter(encryptor.CreateEncryptionFilter(rng), attachment) {}
1041 };
1042 
1043 /// \brief Filter wrapper for PK_Decryptor
1044 /// \details PK_DecryptorFilter is a proxy for the filter created by PK_Decryptor::CreateDecryptionFilter.
1045 /// This class provides symmetry with SignerFilter.
1046 /// \since Crypto++ 5.0
1047 class CRYPTOPP_DLL PK_DecryptorFilter : public SimpleProxyFilter
1048 {
1049 public:
1050  /// \brief Construct a PK_DecryptorFilter
1051  /// \param rng a RandomNumberGenerator derived class
1052  /// \param decryptor a PK_Decryptor derived class
1053  /// \param attachment an optional attached transformation
1054  PK_DecryptorFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment = NULLPTR)
1055  : SimpleProxyFilter(decryptor.CreateDecryptionFilter(rng), attachment) {}
1056 };
1057 
1058 /// \brief Append input to a string object
1059 /// \tparam T std::basic_string<char> type
1060 /// \details StringSinkTemplate is a StringSinkTemplate typedef
1061 /// \since Crypto++ 5.0
1062 template <class T>
1063 class StringSinkTemplate : public Bufferless<Sink>
1064 {
1065 public:
1066  virtual ~StringSinkTemplate() {}
1067 
1068  /// \brief Construct a StringSinkTemplate
1069  /// \param output std::basic_string<char> type
1071  : m_output(&output) {CRYPTOPP_ASSERT(sizeof(output[0])==1);}
1072 
1073  void IsolatedInitialize(const NameValuePairs &parameters)
1074  {if (!parameters.GetValue("OutputStringPointer", m_output)) throw InvalidArgument("StringSink: OutputStringPointer not specified");}
1075 
1076  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
1077  {
1078  CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking);
1079  typedef typename T::traits_type::char_type char_type;
1080 
1081  if (length > 0)
1082  {
1083  typename T::size_type size = m_output->size();
1084  if (length < size && size + length > m_output->capacity())
1085  m_output->reserve(2*size);
1086  m_output->append((const char_type *)inString, (const char_type *)inString+length);
1087  }
1088  return 0;
1089  }
1090 
1091 private:
1092  T *m_output;
1093 };
1094 
1095 /// \brief Append input to a string object
1096 /// \details StringSink is a typedef for StringSinkTemplate<std::string>.
1097 /// \sa ArraySink, ArrayXorSink
1098 /// \since Crypto++ 4.0
1100 CRYPTOPP_DLL_TEMPLATE_CLASS StringSinkTemplate<std::string>;
1101 
1102 /// \brief Incorporates input into RNG as additional entropy
1103 /// \since Crypto++ 4.0
1104 class RandomNumberSink : public Bufferless<Sink>
1105 {
1106 public:
1107  virtual ~RandomNumberSink() {}
1108 
1109  /// \brief Construct a RandomNumberSink
1111  : m_rng(NULLPTR) {}
1112 
1113  /// \brief Construct a RandomNumberSink
1114  /// \param rng a RandomNumberGenerator derived class
1116  : m_rng(&rng) {}
1117 
1118  void IsolatedInitialize(const NameValuePairs &parameters);
1119  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
1120 
1121 private:
1122  RandomNumberGenerator *m_rng;
1123 };
1124 
1125 /// \brief Copy input to a memory buffer
1126 /// \details ArraySink wraps a fixed size buffer. The buffer is full once Put returns non-0.
1127 /// When used in a pipleline, ArraySink silently discards input if the buffer is full.
1128 /// AvailableSize() can be used to determine how much space remains in the buffer.
1129 /// TotalPutLength() can be used to determine how many bytes were processed.
1130 /// \sa StringSink, ArrayXorSink
1131 /// \since Crypto++ 4.0
1132 class CRYPTOPP_DLL ArraySink : public Bufferless<Sink>
1133 {
1134 public:
1135  virtual ~ArraySink() {}
1136 
1137  /// \brief Construct an ArraySink
1138  /// \param parameters a set of NameValuePairs to initialize this object
1139  /// \details Name::OutputBuffer() is a mandatory parameter using this constructor.
1141  : m_buf(NULLPTR), m_size(0), m_total(0) {IsolatedInitialize(parameters);}
1142 
1143  /// \brief Construct an ArraySink
1144  /// \param buf pointer to a memory buffer
1145  /// \param size length of the memory buffer
1146  ArraySink(byte *buf, size_t size)
1147  : m_buf(buf), m_size(size), m_total(0) {}
1148 
1149  /// \brief Provides the size remaining in the Sink
1150  /// \returns size remaining in the Sink, in bytes
1151  size_t AvailableSize() {return SaturatingSubtract(m_size, m_total);}
1152 
1153  /// \brief Provides the number of bytes written to the Sink
1154  /// \returns number of bytes written to the Sink, in bytes
1155  lword TotalPutLength() {return m_total;}
1156 
1157  void IsolatedInitialize(const NameValuePairs &parameters);
1158  byte * CreatePutSpace(size_t &size);
1159  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
1160 
1161 protected:
1162  byte *m_buf;
1163  size_t m_size;
1164  lword m_total;
1165 };
1166 
1167 /// \brief Xor input to a memory buffer
1168 /// \details ArrayXorSink wraps a fixed size buffer. The buffer is full once Put returns non-0.
1169 /// When used in a pipleline, ArrayXorSink silently discards input if the buffer is full.
1170 /// AvailableSize() can be used to determine how much space remains in the buffer.
1171 /// TotalPutLength() can be used to determine how many bytes were processed.
1172 /// \sa StringSink, ArraySink
1173 /// \since Crypto++ 4.0
1174 class CRYPTOPP_DLL ArrayXorSink : public ArraySink
1175 {
1176 public:
1177  virtual ~ArrayXorSink() {}
1178 
1179  /// \brief Construct an ArrayXorSink
1180  /// \param buf pointer to a memory buffer
1181  /// \param size length of the memory buffer
1182  ArrayXorSink(byte *buf, size_t size)
1183  : ArraySink(buf, size) {}
1184 
1185  size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking);
1186  byte * CreatePutSpace(size_t &size) {return BufferedTransformation::CreatePutSpace(size);}
1187 };
1188 
1189 /// \brief String-based implementation of Store interface
1190 /// \since Crypto++ 4.0
1191 class StringStore : public Store
1192 {
1193 public:
1194  /// \brief Construct a StringStore
1195  /// \param string pointer to a C-String
1196  StringStore(const char *string = NULLPTR)
1197  {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
1198 
1199  /// \brief Construct a StringStore
1200  /// \param string pointer to a memory buffer
1201  /// \param length size of the memory buffer
1202  StringStore(const byte *string, size_t length)
1203  {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));}
1204 
1205  /// \brief Construct a StringStore
1206  /// \tparam T std::basic_string<char> type
1207  /// \param string reference to a std::basic_string<char> type
1208  template <class T> StringStore(const T &string)
1209  {StoreInitialize(MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
1210 
1211  CRYPTOPP_DLL size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
1212  CRYPTOPP_DLL size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
1213 
1214 private:
1215  CRYPTOPP_DLL void StoreInitialize(const NameValuePairs &parameters);
1216 
1217  const byte *m_store;
1218  size_t m_length, m_count;
1219 };
1220 
1221 /// \brief RNG-based implementation of Source interface
1222 /// \since Crypto++ 4.0
1223 class CRYPTOPP_DLL RandomNumberStore : public Store
1224 {
1225 public:
1226  virtual ~RandomNumberStore() {}
1227 
1229  : m_rng(NULLPTR), m_length(0), m_count(0) {}
1230 
1231  RandomNumberStore(RandomNumberGenerator &rng, lword length)
1232  : m_rng(&rng), m_length(length), m_count(0) {}
1233 
1234  bool AnyRetrievable() const {return MaxRetrievable() != 0;}
1235  lword MaxRetrievable() const {return m_length-m_count;}
1236 
1237  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
1238  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
1239  {
1240  CRYPTOPP_UNUSED(target); CRYPTOPP_UNUSED(begin); CRYPTOPP_UNUSED(end); CRYPTOPP_UNUSED(channel); CRYPTOPP_UNUSED(blocking);
1241  throw NotImplemented("RandomNumberStore: CopyRangeTo2() is not supported by this store");
1242  }
1243 
1244 private:
1245  void StoreInitialize(const NameValuePairs &parameters);
1246 
1247  RandomNumberGenerator *m_rng;
1248  lword m_length, m_count;
1249 };
1250 
1251 /// \brief Empty store
1252 /// \since Crypto++ 5.0
1253 class CRYPTOPP_DLL NullStore : public Store
1254 {
1255 public:
1256  NullStore(lword size = ULONG_MAX) : m_size(size) {}
1257  void StoreInitialize(const NameValuePairs &parameters)
1258  {CRYPTOPP_UNUSED(parameters);}
1259  lword MaxRetrievable() const {return m_size;}
1260  size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
1261  size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
1262 
1263 private:
1264  lword m_size;
1265 };
1266 
1267 /// \brief Implementation of BufferedTransformation's attachment interface
1268 /// \details Source is a cornerstone of the Pipeline trinitiy. Data flows from
1269 /// Sources, through Filters, and then terminates in Sinks. The difference
1270 /// between a Source and Filter is a Source \a pumps data, while a Filter does
1271 /// not. The difference between a Filter and a Sink is a Filter allows an
1272 /// attached transformation, while a Sink does not.
1273 /// \details See the discussion of BufferedTransformation in cryptlib.h for
1274 /// more details.
1275 /// \sa Store and SourceTemplate
1276 /// \since Crypto++ 1.0
1277 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Source : public InputRejecting<Filter>
1278 {
1279 public:
1280  virtual ~Source() {}
1281 
1282  /// \brief Construct a Source
1283  /// \param attachment an optional attached transformation
1284  Source(BufferedTransformation *attachment = NULLPTR)
1285  {Source::Detach(attachment);}
1286 
1287  /// \name PIPELINE
1288  //@{
1289 
1290  /// \brief Pump data to attached transformation
1291  /// \param pumpMax the maximpum number of bytes to pump
1292  /// \returns the number of bytes that remain in the block (i.e., bytes not processed)
1293  /// \details Internally, Pump() calls Pump2().
1294  /// \note pumpMax is a \p lword, which is a 64-bit value that typically uses \p LWORD_MAX. The default
1295  /// argument is a \p size_t that uses \p SIZE_MAX, and it can be 32-bits or 64-bits.
1296  lword Pump(lword pumpMax=(size_t)SIZE_MAX)
1297  {Pump2(pumpMax); return pumpMax;}
1298 
1299  /// \brief Pump messages to attached transformation
1300  /// \param count the maximpum number of messages to pump
1301  /// \returns TODO
1302  /// \details Internally, PumpMessages() calls PumpMessages2().
1303  unsigned int PumpMessages(unsigned int count=UINT_MAX)
1304  {PumpMessages2(count); return count;}
1305 
1306  /// \brief Pump all data to attached transformation
1307  /// \details Internally, PumpAll() calls PumpAll2().
1308  void PumpAll()
1309  {PumpAll2();}
1310 
1311  /// \brief Pump data to attached transformation
1312  /// \param byteCount the maximpum number of bytes to pump
1313  /// \param blocking specifies whether the object should block when processing input
1314  /// \returns the number of bytes that remain in the block (i.e., bytes not processed)
1315  /// \details byteCount is an \a IN and \a OUT parameter. When the call is made, byteCount is the
1316  /// requested size of the pump. When the call returns, byteCount is the number of bytes that
1317  /// were pumped.
1318  virtual size_t Pump2(lword &byteCount, bool blocking=true) =0;
1319 
1320  /// \brief Pump messages to attached transformation
1321  /// \param messageCount the maximpum number of messages to pump
1322  /// \param blocking specifies whether the object should block when processing input
1323  /// \details messageCount is an IN and OUT parameter.
1324  virtual size_t PumpMessages2(unsigned int &messageCount, bool blocking=true) =0;
1325 
1326  /// \brief Pump all data to attached transformation
1327  /// \param blocking specifies whether the object should block when processing input
1328  /// \returns the number of bytes that remain in the block (i.e., bytes not processed)
1329  virtual size_t PumpAll2(bool blocking=true);
1330 
1331  /// \brief Determines if the Source is exhausted
1332  /// \returns true if the source has been exhausted
1333  virtual bool SourceExhausted() const =0;
1334 
1335  //@}
1336 
1337 protected:
1338  void SourceInitialize(bool pumpAll, const NameValuePairs &parameters)
1339  {
1340  IsolatedInitialize(parameters);
1341  if (pumpAll)
1342  PumpAll();
1343  }
1344 };
1345 
1346 /// \brief Transform a Store into a Source
1347 /// \tparam T the class or type
1348 /// \since Crypto++ 5.0
1349 template <class T>
1350 class SourceTemplate : public Source
1351 {
1352 public:
1353  virtual ~SourceTemplate() {}
1354 
1355  /// \brief Construct a SourceTemplate
1356  /// \param attachment an attached transformation
1358  : Source(attachment) {}
1359  void IsolatedInitialize(const NameValuePairs &parameters)
1360  {m_store.IsolatedInitialize(parameters);}
1361  size_t Pump2(lword &byteCount, bool blocking=true)
1362  {return m_store.TransferTo2(*AttachedTransformation(), byteCount, DEFAULT_CHANNEL, blocking);}
1363  size_t PumpMessages2(unsigned int &messageCount, bool blocking=true)
1364  {return m_store.TransferMessagesTo2(*AttachedTransformation(), messageCount, DEFAULT_CHANNEL, blocking);}
1365  size_t PumpAll2(bool blocking=true)
1366  {return m_store.TransferAllTo2(*AttachedTransformation(), DEFAULT_CHANNEL, blocking);}
1367  bool SourceExhausted() const
1368  {return !m_store.AnyRetrievable() && !m_store.AnyMessages();}
1369  void SetAutoSignalPropagation(int propagation)
1370  {m_store.SetAutoSignalPropagation(propagation);}
1372  {return m_store.GetAutoSignalPropagation();}
1373 
1374 protected:
1375  T m_store;
1376 };
1377 
1378 /// \brief String-based implementation of the Source interface
1379 /// \since Crypto++ 4.0
1380 class CRYPTOPP_DLL StringSource : public SourceTemplate<StringStore>
1381 {
1382 public:
1383  /// \brief Construct a StringSource
1384  /// \param attachment an optional attached transformation
1385  StringSource(BufferedTransformation *attachment = NULLPTR)
1386  : SourceTemplate<StringStore>(attachment) {}
1387 
1388  /// \brief Construct a StringSource
1389  /// \param string C-String
1390  /// \param pumpAll flag indicating if source data should be pumped to its attached transformation
1391  /// \param attachment an optional attached transformation
1392  StringSource(const char *string, bool pumpAll, BufferedTransformation *attachment = NULLPTR)
1393  : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
1394 
1395  /// \brief Construct a StringSource
1396  /// \param string binary byte array
1397  /// \param length size of the byte array
1398  /// \param pumpAll flag indicating if source data should be pumped to its attached transformation
1399  /// \param attachment an optional attached transformation
1400  StringSource(const byte *string, size_t length, bool pumpAll, BufferedTransformation *attachment = NULLPTR)
1401  : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string, length)));}
1402 
1403  /// \brief Construct a StringSource
1404  /// \param string std::string
1405  /// \param pumpAll flag indicating if source data should be pumped to its attached transformation
1406  /// \param attachment an optional attached transformation
1407  StringSource(const std::string &string, bool pumpAll, BufferedTransformation *attachment = NULLPTR)
1408  : SourceTemplate<StringStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputBuffer", ConstByteArrayParameter(string)));}
1409 };
1410 
1411 /// \brief Pointer-based implementation of the Source interface
1412 /// \details ArraySource is a typedef for StringSource. Use the third constructor for an array source.
1413 /// The third constructor takes a pointer and length.
1414 /// \since Crypto++ 5.6.0
1415 DOCUMENTED_TYPEDEF(StringSource, ArraySource)
1416 
1417 /// \brief RNG-based implementation of Source interface
1418 /// \since Crypto++ 4.0
1420 {
1421 public:
1422  RandomNumberSource(RandomNumberGenerator &rng, int length, bool pumpAll, BufferedTransformation *attachment = NULLPTR)
1423  : SourceTemplate<RandomNumberStore>(attachment)
1424  {SourceInitialize(pumpAll, MakeParameters("RandomNumberGeneratorPointer", &rng)("RandomNumberStoreSize", length));}
1425 };
1426 
1427 NAMESPACE_END
1428 
1429 #if CRYPTOPP_MSC_VERSION
1430 # pragma warning(pop)
1431 #endif
1432 
1433 #endif
lword Pump(lword pumpMax=(size_t) ...)
Pump data to attached transformation.
Definition: filters.h:1296
Used to pass byte array input as part of a NameValuePairs object.
Definition: algparam.h:30
Create a working space in a BufferedTransformation.
Definition: filters.h:158
Base class for all exceptions thrown by the library.
Definition: cryptlib.h:156
Append input to a string object.
Definition: filters.h:1099
bool GetLastResult() const
Retrieves the result of the last verification.
Definition: filters.h:815
An invalid argument was detected.
Definition: cryptlib.h:200
byte * HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t bufferSize)
Create a working space in a BufferedTransformation.
Definition: filters.h:207
StringSource(const char *string, bool pumpAll, BufferedTransformation *attachment=NULL)
Construct a StringSource.
Definition: filters.h:1392
SimpleProxyFilter(BufferedTransformation *filter, BufferedTransformation *attachment)
Construct a SimpleProxyFilter.
Definition: filters.h:1008
container of wait objects
Definition: wait.h:169
Pointer-based implementation of the Source interface.
Definition: filters.h:1415
Classes for working with NameValuePairs.
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:259
Filter wrapper for PK_Verifier.
Definition: filters.h:772
Base class for Filter classes that are proxies for a chain of other filters.
Definition: filters.h:976
Implementation of BufferedTransformation&#39;s attachment interface.
Definition: filters.h:1277
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: filters.h:1259
Classes providing basic library services.
Utility functions for the Crypto++ library.
bool SourceExhausted() const
Determines if the Source is exhausted.
Definition: filters.h:1367
PK_DecryptorFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment=NULL)
Construct a PK_DecryptorFilter.
Definition: filters.h:1054
MeterFilter(BufferedTransformation *attachment=NULL, bool transparent=true)
Construct a MeterFilter.
Definition: filters.h:227
void SetAutoSignalPropagation(int propagation)
Set propagation of automatically generated and transferred signals.
Definition: filters.h:1369
BlockPaddingScheme
Padding schemes used for block ciphers.
Definition: filters.h:470
Interface for authenticated encryption modes of operation.
Definition: cryptlib.h:1266
Filter class that is a proxy for a sink.
Definition: filters.h:928
bool AnyRetrievable() const
Determines whether bytes are ready for retrieval.
Definition: filters.h:1234
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:962
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:960
byte * HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize)
Create a working space in a BufferedTransformation.
Definition: filters.h:198
Interface for public-key signers.
Definition: cryptlib.h:2623
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:906
Interface for public-key encryptors.
Definition: cryptlib.h:2444
void PumpAll()
Pump all data to attached transformation.
Definition: filters.h:1308
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:947
unsigned int PumpMessages(unsigned int count=UINT_MAX)
Pump messages to attached transformation.
Definition: filters.h:1303
Abstract base classes that provide a uniform interface to this library.
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: filters.h:1359
size_t PumpAll2(bool blocking=true)
Pump all data to attached transformation.
Definition: filters.h:1365
Classes for automatic resource management.
Filter wrapper for PK_Signer.
Definition: filters.h:743
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:966
size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee.
Definition: filters.h:334
Acts as a Source for pre-existing, static data.
Definition: simple.h:299
StringStore(const T &string)
Construct a StringStore.
Definition: filters.h:1208
StringSource(const byte *string, size_t length, bool pumpAll, BufferedTransformation *attachment=NULL)
Construct a StringSource.
Definition: filters.h:1400
Interface for random number generators.
Definition: cryptlib.h:1327
Base class for input rejecting filters.
Definition: simple.h:127
unsigned int GetMaxWaitObjectCount() const
Retrieves the maximum number of waitable objects.
Definition: filters.h:915
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:889
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:879
Append input to a string object.
Definition: filters.h:1063
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:564
SecBlock<byte> typedef.
Definition: secblock.h:822
StringSource(const std::string &string, bool pumpAll, BufferedTransformation *attachment=NULL)
Construct a StringSource.
Definition: filters.h:1407
Interface for buffered transformations.
Definition: cryptlib.h:1472
Exception thrown when an invalid signature is encountered.
Definition: filters.h:776
Flags
Flags controlling filter behavior.
Definition: filters.h:786
String-based implementation of the Source interface.
Definition: filters.h:1380
StringStore(const byte *string, size_t length)
Construct a StringStore.
Definition: filters.h:1202
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:964
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:958
Exception thrown when a data integrity check failure is encountered.
Definition: filters.h:585
Classes and functions for secure memory allocations.
1 and 0&#39;s padding added to a block
Definition: filters.h:482
Redirector(BufferedTransformation &target, Behavior behavior=PASS_EVERYTHING)
Construct a Redirector.
Definition: filters.h:859
Copy input to a memory buffer.
Definition: filters.h:1132
Empty store.
Definition: filters.h:1253
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:620
Flags
Flags controlling filter behavior.
Definition: filters.h:691
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:896
Transform a Store into a Source.
Definition: filters.h:1350
Classes for an unlimited queue to store bytes.
Xor input to a memory buffer.
Definition: filters.h:1174
RandomNumberSink(RandomNumberGenerator &rng)
Construct a RandomNumberSink.
Definition: filters.h:1115
Interface for public-key decryptors.
Definition: cryptlib.h:2479
bool operator<(const OID &lhs, const OID &rhs)
Compare two OIDs for ordering.
A method was called which was not implemented.
Definition: cryptlib.h:221
Filter wrapper for HashTransformation.
Definition: filters.h:579
Filter wrapper for HashTransformation.
Definition: filters.h:550
RNG-based implementation of Source interface.
Definition: filters.h:1223
Filter wrapper for decrypting with AuthenticatedSymmetricCipher.
Definition: filters.h:685
void Detach(BufferedTransformation *newAttachment=NULL)
Replace an attached transformation.
Definition: filters.cpp:50
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Definition: cryptlib.h:483
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:509
bool GetPassSignal() const
Retrieve passSignal flag.
Definition: filters.h:940
OutputProxy(BufferedTransformation &owner, bool passSignal)
Construct an OutputProxy.
Definition: filters.h:936
A non-transparent MeterFilter.
Definition: filters.h:297
Filter wrapper for encrypting with AuthenticatedSymmetricCipher.
Definition: filters.h:644
size_t PumpMessages2(unsigned int &messageCount, bool blocking=true)
Pump messages to attached transformation.
Definition: filters.h:1363
Flags
Flags controlling filter behavior.
Definition: filters.h:595
Proxy filter that doesn&#39;t modify the underlying filter&#39;s input or output.
Definition: filters.h:1002
virtual byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
Definition: cryptlib.cpp:432
void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
Initialize or reinitialize this object, with signal propagation.
Definition: filters.h:951
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: filters.h:955
bool CanModifyInput() const
Determines whether input can be modified by the callee.
Definition: filters.h:875
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:811
A filter that buffers input using a ByteQueue.
Definition: filters.h:426
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
Definition: misc.h:885
void StopRedirection()
Stop redirecting input.
Definition: filters.h:866
size_t AvailableSize()
Provides the size remaining in the Sink.
Definition: filters.h:1151
Filter wrapper for PK_Decryptor.
Definition: filters.h:1047
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:1076
Incorporates input into RNG as additional entropy.
Definition: filters.h:1104
Interface for the data processing portion of stream ciphers.
Definition: cryptlib.h:899
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: filters.h:1073
RandomNumberSink()
Construct a RandomNumberSink.
Definition: filters.h:1110
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:1238
Divides an input stream into discrete blocks.
Definition: filters.h:311
StringSource(BufferedTransformation *attachment=NULL)
Construct a StringSource.
Definition: filters.h:1385
String-based implementation of Store interface.
Definition: filters.h:1191
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:60
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:435
Redirect input to another BufferedTransformation without owning it.
Definition: filters.h:833
size_t Pump2(lword &byteCount, bool blocking=true)
Pump data to attached transformation.
Definition: filters.h:1361
Data structure used to store byte strings.
Definition: queue.h:18
TransparentFilter(BufferedTransformation *attachment=NULL)
Construct a TransparentFilter.
Definition: filters.h:292
Redirector()
Construct a Redirector.
Definition: filters.h:854
lword MaxRetrievable() const
Provides the number of bytes ready for retrieval.
Definition: filters.h:1235
Filter wrapper for PK_Encryptor.
Definition: filters.h:1032
Exception thrown by objects that have not implemented nonblocking input processing.
Definition: cryptlib.h:1596
Filter wrapper for StreamTransformation.
Definition: filters.h:500
W3C padding added to a block.
Definition: filters.h:487
void Redirect(BufferedTransformation &target)
Redirect input to another BufferedTransformation.
Definition: filters.h:864
Behavior
Controls signal propagation behavior.
Definition: filters.h:838
const NameValuePairs g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.h:496
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:567
Base class for unflushable filters.
Definition: simple.h:101
Interface for public-key signature verifiers.
Definition: cryptlib.h:2687
bool Attachable()
Determine if attachable.
Definition: filters.h:51
A transparent MeterFilter.
Definition: filters.h:287
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:516
SecByteBlock m_tempSpace
Temporay working space.
Definition: filters.h:211
void SetPassSignal(bool passSignal)
Set passSignal flag.
Definition: filters.h:943
SignerFilter(RandomNumberGenerator &rng, const PK_Signer &signer, BufferedTransformation *attachment=NULL, bool putMessage=false)
Construct a SignerFilter.
Definition: filters.h:753
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:1065
virtual byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: cryptlib.h:1533
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:910
0&#39;s padding added to a block
Definition: filters.h:476
void SetTransparent(bool transparent)
Set or change the transparent mode of this object.
Definition: filters.h:234
ArraySink(const NameValuePairs &parameters=g_nullNameValuePairs)
Construct an ArraySink.
Definition: filters.h:1140
Implementation of BufferedTransformation&#39;s attachment interface.
Definition: filters.h:35
Access a block of memory.
Definition: misc.h:2319
void IsolatedInitialize(const NameValuePairs &parameters)
Initialize or reinitialize this object, without signal propagation.
Definition: filters.h:250
Measure how many bytes and messages pass through the filter.
Definition: filters.h:217
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: filters.h:917
No padding added to a block.
Definition: filters.h:473
Crypto++ library namespace.
ArrayXorSink(byte *buf, size_t size)
Construct an ArrayXorSink.
Definition: filters.h:1182
PKCS #5 padding added to a block.
Definition: filters.h:479
Padding schemes used for block ciphers.
Definition: filters.h:460
bool GetValue(const char *name, T &value) const
Get a named value.
Definition: cryptlib.h:348
PK_EncryptorFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment=NULL)
Construct a PK_EncryptorFilter.
Definition: filters.h:1039
ArraySink(byte *buf, size_t size)
Construct an ArraySink.
Definition: filters.h:1146
StringSinkTemplate(T &output)
Construct a StringSinkTemplate.
Definition: filters.h:1070
RNG-based implementation of Source interface.
Definition: filters.h:1419
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:912
size_t PutModifiable2(byte *begin, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee.
Definition: filters.h:949
byte * HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize)
Create a working space in a BufferedTransformation.
Definition: filters.h:175
FilterWithInputQueue(BufferedTransformation *attachment=NULL)
Construct a FilterWithInputQueue.
Definition: filters.h:433
OpaqueFilter(BufferedTransformation *attachment=NULL)
Construct an OpaqueFilter.
Definition: filters.h:302
Ensures an object is not copyable.
Definition: misc.h:228
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
Definition: filters.h:329
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: filters.h:891
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:1186
StringStore(const char *string=NULL)
Construct a StringStore.
Definition: filters.h:1196
Interface for custom flush signals.
Definition: simple.h:196
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
Definition: filters.h:953
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:715
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:908
lword TotalPutLength()
Provides the number of bytes written to the Sink.
Definition: filters.h:1155
void LastPut(const byte *inString, size_t length)
Input the last block of data.
Definition: filters.h:1024
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition: filters.h:756
Base class for bufferless filters.
Definition: simple.h:91
#define SIZE_MAX
The maximum value of a machine word.
Definition: misc.h:85
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Definition: filters.h:945
int GetAutoSignalPropagation() const
Retrieve automatic signal propagation value.
Definition: filters.h:1371
Interface for retrieving values given their names.
Definition: cryptlib.h:291
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
Definition: filters.h:893
Source(BufferedTransformation *attachment=NULL)
Construct a Source.
Definition: filters.h:1284