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