Crypto++ 8.0 Free C++ class library of cryptographic schemes

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