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