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