6#if CRYPTOPP_MSC_VERSION
7# pragma warning(disable: 4189 4355)
10#ifndef CRYPTOPP_IMPORTS
23 : m_attachment(attachment), m_inputPosition(0), m_continueAt(0)
29 return new MessageQueue;
34 if (m_attachment.get() == NULLPTR)
35 m_attachment.reset(NewDefaultAttachment());
36 return m_attachment.get();
41 if (m_attachment.get() == NULLPTR)
42 const_cast<Filter *
>(
this)->m_attachment.reset(NewDefaultAttachment());
43 return m_attachment.get();
48 m_attachment.reset(newOut);
51void Filter::Insert(
Filter *filter)
53 filter->m_attachment.reset(m_attachment.release());
54 m_attachment.reset(filter);
69 m_inputPosition = m_continueAt = 0;
71 PropagateInitialize(parameters, propagation);
74bool Filter::Flush(
bool hardFlush,
int propagation,
bool blocking)
83 if (OutputFlush(1, hardFlush, propagation, blocking))
100 if (ShouldPropagateMessageSeriesEnd() && OutputMessageSeriesEnd(1, propagation, blocking))
108void Filter::PropagateInitialize(
const NameValuePairs ¶meters,
int propagation)
114size_t Filter::OutputModifiable(
int outputSite,
byte *inString,
size_t length,
int messageEnd,
bool blocking,
const std::string &channel)
119 m_continueAt = result ? outputSite : 0;
123size_t Filter::Output(
int outputSite,
const byte *inString,
size_t length,
int messageEnd,
bool blocking,
const std::string &channel)
128 m_continueAt = result ? outputSite : 0;
132bool Filter::OutputFlush(
int outputSite,
bool hardFlush,
int propagation,
bool blocking,
const std::string &channel)
136 m_continueAt = outputSite;
143bool Filter::OutputMessageSeriesEnd(
int outputSite,
int propagation,
bool blocking,
const std::string &channel)
147 m_continueAt = outputSite;
158 m_currentMessageBytes = m_totalBytes = m_currentSeriesMessages = m_totalMessages = m_totalMessageSeries = 0;
159 m_rangesToSkip.clear();
164 MessageRange r = {message, position, size};
165 m_rangesToSkip.push_back(r);
167 std::sort(m_rangesToSkip.begin(), m_rangesToSkip.end());
170size_t MeterFilter::PutMaybeModifiable(
byte *begin,
size_t length,
int messageEnd,
bool blocking,
bool modifiable)
181 while (m_length > 0 || messageEnd)
183 if (m_length > 0 && !m_rangesToSkip.empty() && m_rangesToSkip.front().message == m_totalMessages && m_currentMessageBytes + m_length > m_rangesToSkip.front().position)
185 FILTER_OUTPUT_MAYBE_MODIFIABLE(1, m_begin, t = (
size_t)
SaturatingSubtract(m_rangesToSkip.front().position, m_currentMessageBytes),
false, modifiable);
188 m_begin =
PtrAdd(m_begin, t);
190 m_currentMessageBytes += t;
193 if (m_currentMessageBytes + m_length < m_rangesToSkip.front().position + m_rangesToSkip.front().size)
197 t = (size_t)
SaturatingSubtract(m_rangesToSkip.front().position + m_rangesToSkip.front().size, m_currentMessageBytes);
199 m_rangesToSkip.pop_front();
202 m_begin =
PtrAdd(m_begin, t);
204 m_currentMessageBytes += t;
209 FILTER_OUTPUT_MAYBE_MODIFIABLE(2, m_begin, m_length, messageEnd, modifiable);
211 m_currentMessageBytes += m_length;
212 m_totalBytes += m_length;
217 m_currentMessageBytes = 0;
218 m_currentSeriesMessages++;
225 FILTER_END_NO_MESSAGE_END;
228size_t MeterFilter::Put2(
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
230 return PutMaybeModifiable(
const_cast<byte *
>(begin), length, messageEnd, blocking,
false);
235 return PutMaybeModifiable(begin, length, messageEnd, blocking,
true);
240 CRYPTOPP_UNUSED(blocking);
241 m_currentMessageBytes = 0;
242 m_currentSeriesMessages = 0;
243 m_totalMessageSeries++;
249void FilterWithBufferedInput::BlockQueue::ResetQueue(
size_t blockSize,
size_t maxBlocks)
251 m_buffer.New(blockSize * maxBlocks);
252 m_blockSize = blockSize;
253 m_maxBlocks = maxBlocks;
258byte *FilterWithBufferedInput::BlockQueue::GetBlock()
260 if (m_size >= m_blockSize)
263 if ((m_begin =
PtrAdd(m_begin, m_blockSize)) == m_buffer.end())
265 m_size -= m_blockSize;
272byte *FilterWithBufferedInput::BlockQueue::GetContigousBlocks(
size_t &numberOfBytes)
276 m_begin =
PtrAdd(m_begin, numberOfBytes);
277 m_size -= numberOfBytes;
278 if (m_size == 0 || m_begin == m_buffer.end())
283size_t FilterWithBufferedInput::BlockQueue::GetAll(
byte *outString)
286 if (!outString)
return 0;
288 size_t size = m_size;
289 size_t numberOfBytes = m_maxBlocks*m_blockSize;
290 const byte *ptr = GetContigousBlocks(numberOfBytes);
291 std::memcpy(outString, ptr, numberOfBytes);
292 std::memcpy(
PtrAdd(outString, numberOfBytes), m_begin, m_size);
297void FilterWithBufferedInput::BlockQueue::Put(
const byte *inString,
size_t length)
300 if (!inString || !length)
return;
303 byte *end = (m_size < static_cast<size_t>(
PtrDiff(m_buffer.end(), m_begin)) ?
304 PtrAdd(m_begin, m_size) :
PtrAdd(m_begin, m_size - m_buffer.size()));
305 size_t len =
STDMIN(length,
size_t(m_buffer.end()-end));
306 std::memcpy(end, inString, len);
308 std::memcpy(m_buffer,
PtrAdd(inString, len), length-len);
313 :
Filter(attachment), m_firstSize(
SIZE_MAX), m_blockSize(0), m_lastSize(
SIZE_MAX), m_firstInputDone(false)
318 :
Filter(attachment), m_firstSize(firstSize), m_blockSize(blockSize), m_lastSize(lastSize), m_firstInputDone(false)
323 m_queue.ResetQueue(1, m_firstSize);
328 InitializeDerivedAndReturnNewSizes(parameters, m_firstSize, m_blockSize, m_lastSize);
330 throw InvalidArgument(
"FilterWithBufferedInput: invalid buffer size");
331 m_queue.ResetQueue(1, m_firstSize);
332 m_firstInputDone =
false;
347size_t FilterWithBufferedInput::PutMaybeModifiable(
byte *inString,
size_t length,
int messageEnd,
bool blocking,
bool modifiable)
354 size_t newLength = m_queue.CurrentSize() + length;
356 if (!m_firstInputDone && newLength >= m_firstSize)
358 size_t len = m_firstSize - m_queue.CurrentSize();
359 m_queue.Put(inString, len);
360 FirstPut(m_queue.GetContigousBlocks(m_firstSize));
362 m_queue.ResetQueue(m_blockSize, (2*m_blockSize+m_lastSize-2)/m_blockSize);
364 inString =
PtrAdd(inString, len);
365 newLength -= m_firstSize;
366 m_firstInputDone =
true;
369 if (m_firstInputDone)
371 if (m_blockSize == 1)
373 while (newLength > m_lastSize && m_queue.CurrentSize() > 0)
375 size_t len = newLength - m_lastSize;
376 byte *ptr = m_queue.GetContigousBlocks(len);
377 NextPutModifiable(ptr, len);
381 if (newLength > m_lastSize)
383 size_t len = newLength - m_lastSize;
384 NextPutMaybeModifiable(inString, len, modifiable);
385 inString =
PtrAdd(inString, len);
391 while (newLength >= m_blockSize + m_lastSize && m_queue.CurrentSize() >= m_blockSize)
393 NextPutModifiable(m_queue.GetBlock(), m_blockSize);
394 newLength -= m_blockSize;
397 if (newLength >= m_blockSize + m_lastSize && m_queue.CurrentSize() > 0)
400 size_t len = m_blockSize - m_queue.CurrentSize();
401 m_queue.Put(inString, len);
402 inString =
PtrAdd(inString, len);
403 NextPutModifiable(m_queue.GetBlock(), m_blockSize);
404 newLength -= m_blockSize;
407 if (newLength >= m_blockSize + m_lastSize)
410 NextPutMaybeModifiable(inString, len, modifiable);
411 inString =
PtrAdd(inString, len);
417 m_queue.Put(inString, newLength - m_queue.CurrentSize());
422 if (!m_firstInputDone && m_firstSize==0)
425 SecByteBlock temp(m_queue.CurrentSize());
426 m_queue.GetAll(temp);
427 LastPut(temp, temp.size());
429 m_firstInputDone =
false;
430 m_queue.ResetQueue(1, m_firstSize);
433 (void)Output(1, NULLPTR, 0, messageEnd, blocking);
440 if (!m_firstInputDone)
445 while (m_queue.CurrentSize() >= m_blockSize)
446 NextPutModifiable(m_queue.GetBlock(), m_blockSize);
451 while ((len = m_queue.CurrentSize()) > 0)
452 NextPutModifiable(m_queue.GetContigousBlocks(len), len);
456void FilterWithBufferedInput::NextPutMultiple(
const byte *inString,
size_t length)
462 NextPutSingle(inString);
463 inString =
PtrAdd(inString, m_blockSize);
464 length -= m_blockSize;
476 m_target->Initialize(parameters, propagation);
490 return m_filter.get() ? m_filter->Flush(hardFlush, -1, blocking) :
false;
495 m_filter.reset(filter);
499 member_ptr<OutputProxy> temp(proxy =
new OutputProxy(*
this,
false));
500 m_filter->TransferAllTo(*proxy);
501 m_filter->Attach(temp.release());
505void ProxyFilter::NextPutMultiple(
const byte *s,
size_t len)
508 m_filter->Put(s, len);
511void ProxyFilter::NextPutModifiable(
byte *s,
size_t len)
514 m_filter->PutModifiable(s, len);
526 CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking);
527 m_rng->IncorporateEntropy(begin, length);
531size_t ArraySink::Put2(
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
533 CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking);
541 std::memmove(
PtrAdd(m_buf, m_total), begin, copied);
544 return length - copied;
550 return PtrAdd(m_buf, m_total);
555 ByteArrayParameter array;
557 throw InvalidArgument(
"ArraySink: missing OutputBuffer argument");
558 m_buf = array.
begin();
559 m_size = array.
size();
562size_t ArrayXorSink::Put2(
const byte *begin,
size_t length,
int messageEnd,
bool blocking)
564 CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking);
574 return length - copied;
582 CRYPTOPP_ASSERT(c.MinLastBlockSize() == 0 || c.MinLastBlockSize() > c.MandatoryBlockSize());
585 if (authenticatedFilter)
586 throw InvalidArgument(
"StreamTransformationFilter: please use AuthenticatedEncryptionFilter and AuthenticatedDecryptionFilter for AuthenticatedSymmetricCipher");
589 m_mandatoryBlockSize = m_cipher.MandatoryBlockSize();
590 m_optimalBufferSize = m_cipher.OptimalBlockSize();
591 m_isSpecial = m_cipher.IsLastBlockSpecial() && m_mandatoryBlockSize > 1;
592 m_reservedBufferSize =
STDMAX(2*m_mandatoryBlockSize, m_optimalBufferSize);
603 if (!authenticatedFilter)
605 CRYPTOPP_ASSERT(c.MinLastBlockSize() == 0 || c.MinLastBlockSize() > c.MandatoryBlockSize());
608 if (authenticatedFilter && !authenticated)
609 throw InvalidArgument(
"StreamTransformationFilter: please use AuthenticatedEncryptionFilter and AuthenticatedDecryptionFilter for AuthenticatedSymmetricCipher");
612 m_mandatoryBlockSize = m_cipher.MandatoryBlockSize();
613 m_optimalBufferSize = m_cipher.OptimalBlockSize();
614 m_isSpecial = m_cipher.IsLastBlockSpecial() && m_mandatoryBlockSize > 1;
615 m_reservedBufferSize =
STDMAX(2*m_mandatoryBlockSize, m_optimalBufferSize);
622size_t StreamTransformationFilter::LastBlockSize(
StreamTransformation &c, BlockPaddingScheme padding)
624 if (c.MinLastBlockSize() > 0)
625 return c.MinLastBlockSize();
626 else if (c.MandatoryBlockSize() > 1 && !c.IsForwardTransformation() && padding !=
NO_PADDING && padding !=
ZEROS_PADDING)
627 return c.MandatoryBlockSize();
632void StreamTransformationFilter::InitializeDerivedAndReturnNewSizes(
const NameValuePairs ¶meters,
size_t &firstSize,
size_t &blockSize,
size_t &lastSize)
635 bool isBlockCipher = (m_mandatoryBlockSize > 1 && m_cipher.MinLastBlockSize() == 0);
645 throw InvalidArgument(
"StreamTransformationFilter: PKCS_PADDING cannot be used with " + m_cipher.AlgorithmName());
647 throw InvalidArgument(
"StreamTransformationFilter: W3C_PADDING cannot be used with " + m_cipher.AlgorithmName());
649 throw InvalidArgument(
"StreamTransformationFilter: ONE_AND_ZEROS_PADDING cannot be used with " + m_cipher.AlgorithmName());
653 blockSize = m_mandatoryBlockSize;
654 lastSize = LastBlockSize(m_cipher, m_padding);
657void StreamTransformationFilter::FirstPut(
const byte* inString)
659 CRYPTOPP_UNUSED(inString);
663void StreamTransformationFilter::NextPutMultiple(
const byte *inString,
size_t length)
668 const size_t s = m_cipher.MandatoryBlockSize();
671 size_t len = m_optimalBufferSize;
675 if (len == m_optimalBufferSize)
676 len -= m_cipher.GetOptimalBlockSizeUsed();
681 m_cipher.ProcessString(space, inString, len);
683 inString =
PtrAdd(inString, len);
689void StreamTransformationFilter::NextPutModifiable(
byte *inString,
size_t length)
691 m_cipher.ProcessString(inString, length);
695void StreamTransformationFilter::LastPut(
const byte *inString,
size_t length)
719 const size_t leftOver = length % m_mandatoryBlockSize;
726 m_cipher.ProcessData(space, inString, length);
728 inString =
PtrAdd(inString, length);
734 length = m_cipher.ProcessLastBlock(space, m_reservedBufferSize, inString, leftOver);
740 length = m_cipher.ProcessLastBlock(space, m_reservedBufferSize, NULLPTR, 0);
753 const size_t minLastBlockSize = m_cipher.MinLastBlockSize();
754 const bool isForwardTransformation = m_cipher.IsForwardTransformation();
756 if (isForwardTransformation && m_padding ==
ZEROS_PADDING && (minLastBlockSize == 0 || length < minLastBlockSize))
759 size_t blockSize =
STDMAX(minLastBlockSize, (
size_t)m_mandatoryBlockSize);
761 if (inString) {std::memcpy(space, inString, length);}
762 std::memset(
PtrAdd(space, length), 0, blockSize - length);
763 size_t used = m_cipher.ProcessLastBlock(space, blockSize, space, blockSize);
768 if (minLastBlockSize == 0)
770 if (isForwardTransformation)
771 throw InvalidDataFormat(
"StreamTransformationFilter: plaintext length is not a multiple of block size and NO_PADDING is specified");
773 throw InvalidCiphertext(
"StreamTransformationFilter: ciphertext length is not a multiple of block size");
777 size_t used = m_cipher.ProcessLastBlock(space, length, inString, length);
788 s = m_mandatoryBlockSize;
791 if (m_cipher.IsForwardTransformation())
794 if (inString) {std::memcpy(space, inString, length);}
798 byte pad =
static_cast<byte>(s-length);
799 std::memset(
PtrAdd(space, length), pad, s-length);
804 std::memset(
PtrAdd(space, length), 0, s-length-1);
805 space[s-1] =
static_cast<byte>(s-length);
809 space[length] = 0x80;
810 std::memset(
PtrAdd(space, length+1), 0, s-length-1);
812 m_cipher.ProcessData(space, space, s);
818 throw InvalidCiphertext(
"StreamTransformationFilter: ciphertext length is not a multiple of block size");
819 m_cipher.ProcessData(space, inString, s);
822 byte pad = space[s-1];
824 throw InvalidCiphertext(
"StreamTransformationFilter: invalid PKCS #7 block padding found");
829 byte pad = space[s - 1];
830 if (pad < 1 || pad > s)
831 throw InvalidCiphertext(
"StreamTransformationFilter: invalid W3C block padding found");
836 while (length > 1 && space[length-1] == 0)
838 if (space[--length] != 0x80)
839 throw InvalidCiphertext(
"StreamTransformationFilter: invalid ones-and-zeros padding found");
853 : m_hashModule(hm), m_putMessage(putMessage), m_digestSize(0), m_space(NULLPTR)
854 , m_messagePutChannel(messagePutChannel), m_hashPutChannel(hashPutChannel)
856 m_digestSize = truncatedDigestSize < 0 ? m_hashModule.DigestSize() : truncatedDigestSize;
864 m_digestSize = s < 0 ? m_hashModule.DigestSize() : s;
867size_t HashFilter::Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking)
871 FILTER_OUTPUT3(1, 0, inString, length, 0, m_messagePutChannel);
872 if (inString && length)
873 m_hashModule.Update(inString, length);
879 m_hashModule.TruncatedFinal(m_space, m_digestSize);
881 FILTER_OUTPUT3(2, 0, m_space, m_digestSize, messageEnd, m_hashPutChannel);
883 FILTER_END_NO_MESSAGE_END;
890 , m_hashModule(hm), m_flags(0), m_digestSize(0), m_verified(false)
898void HashVerificationFilter::InitializeDerivedAndReturnNewSizes(
const NameValuePairs ¶meters,
size_t &firstSize,
size_t &blockSize,
size_t &lastSize)
902 m_digestSize = s < 0 ? m_hashModule.DigestSize() : s;
909void HashVerificationFilter::FirstPut(
const byte *inString)
913 m_expectedHash.New(m_digestSize);
914 if (inString) {std::memcpy(m_expectedHash, inString, m_expectedHash.size());}
920void HashVerificationFilter::NextPutMultiple(
const byte *inString,
size_t length)
922 m_hashModule.Update(inString, length);
927void HashVerificationFilter::LastPut(
const byte *inString,
size_t length)
932 m_verified = m_hashModule.TruncatedVerify(m_expectedHash, m_digestSize);
936 m_verified = (length==m_digestSize && m_hashModule.TruncatedVerify(inString, length));
951 bool putAAD,
int truncatedDigestSize,
const std::string &macChannel, BlockPaddingScheme padding)
960 m_hf.IsolatedInitialize(parameters);
970 return m_hf.CreatePutSpace(size);
981 return m_hf.Put2(begin, length, 0, blocking);
988 StreamTransformationFilter::LastPut(inString, length);
997 , m_streamFilter(c, new
OutputProxy(*this, false), padding, true)
1007void AuthenticatedDecryptionFilter::InitializeDerivedAndReturnNewSizes(
const NameValuePairs ¶meters,
size_t &firstSize,
size_t &blockSize,
size_t &lastSize)
1012 m_streamFilter.Initialize(parameters);
1014 firstSize = m_hashVerifier.m_firstSize;
1016 lastSize = m_hashVerifier.m_lastSize;
1021 if (channel.empty())
1022 return m_streamFilter.CreatePutSpace(size);
1025 return m_hashVerifier.CreatePutSpace(size);
1032 if (channel.empty())
1035 m_hashVerifier.ForceNextPut();
1040 return m_hashVerifier.Put2(begin, length, 0, blocking);
1045void AuthenticatedDecryptionFilter::FirstPut(
const byte *inString)
1047 m_hashVerifier.Put(inString, m_firstSize);
1050void AuthenticatedDecryptionFilter::NextPutMultiple(
const byte *inString,
size_t length)
1052 m_streamFilter.Put(inString, length);
1055void AuthenticatedDecryptionFilter::LastPut(
const byte *inString,
size_t length)
1057 m_streamFilter.MessageEnd();
1058 m_hashVerifier.PutMessageEnd(inString, length);
1066 m_messageAccumulator.reset(m_signer.NewSignatureAccumulator(m_rng));
1069size_t SignerFilter::Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking)
1072 m_messageAccumulator->Update(inString, length);
1074 FILTER_OUTPUT(1, inString, length, 0);
1077 m_buf.New(m_signer.SignatureLength());
1078 m_signer.Sign(m_rng, m_messageAccumulator.release(), m_buf);
1079 FILTER_OUTPUT(2, m_buf, m_buf.size(), messageEnd);
1080 m_messageAccumulator.reset(m_signer.NewSignatureAccumulator(m_rng));
1082 FILTER_END_NO_MESSAGE_END;
1087 , m_verifier(verifier), m_flags(0), m_verified(0)
1094void SignatureVerificationFilter::InitializeDerivedAndReturnNewSizes(
const NameValuePairs ¶meters,
size_t &firstSize,
size_t &blockSize,
size_t &lastSize)
1097 m_messageAccumulator.reset(m_verifier.NewVerificationAccumulator());
1098 size_t size = m_verifier.SignatureLength();
1106void SignatureVerificationFilter::FirstPut(
const byte *inString)
1110 if (m_verifier.SignatureUpfront())
1111 m_verifier.InputSignature(*m_messageAccumulator, inString, m_verifier.SignatureLength());
1114 m_signature.New(m_verifier.SignatureLength());
1115 if (inString) {std::memcpy(m_signature, inString, m_signature.size());}
1127void SignatureVerificationFilter::NextPutMultiple(
const byte *inString,
size_t length)
1129 m_messageAccumulator->Update(inString, length);
1134void SignatureVerificationFilter::LastPut(
const byte *inString,
size_t length)
1139 m_verifier.InputSignature(*m_messageAccumulator, m_signature, m_signature.size());
1140 m_verified = m_verifier.VerifyAndRestart(*m_messageAccumulator);
1144 m_verifier.InputSignature(*m_messageAccumulator, inString, length);
1145 m_verified = m_verifier.VerifyAndRestart(*m_messageAccumulator);
1161 unsigned int messageCount = UINT_MAX;
1164 }
while(messageCount == UINT_MAX);
1180unsigned int Store::CopyMessagesTo(
BufferedTransformation &target,
unsigned int count,
const std::string &channel)
const
1182 if (m_messageEnd || count == 0)
1186 CopyTo(target, ULONG_MAX, channel);
1193void StringStore::StoreInitialize(
const NameValuePairs ¶meters)
1195 ConstByteArrayParameter array;
1197 throw InvalidArgument(
"StringStore: missing InputBuffer argument");
1198 m_store = array.
begin();
1199 m_length = array.
size();
1206 size_t blockedBytes =
CopyRangeTo2(target, position, transferBytes, channel, blocking);
1207 m_count +=
static_cast<size_t>(position);
1208 transferBytes = position;
1209 return blockedBytes;
1216 size_t blockedBytes = target.
ChannelPut2(channel,
PtrAdd(m_store, i), len, 0, blocking);
1218 begin =
PtrAdd(begin, len);
1219 return blockedBytes;
1222void RandomNumberStore::StoreInitialize(
const NameValuePairs ¶meters)
1233 throw NotImplemented(
"RandomNumberStore: nonblocking transfer is not implemented by this object");
1235 transferBytes =
UnsignedMin(transferBytes, m_length - m_count);
1236 m_rng->GenerateIntoBufferedTransformation(target, channel, transferBytes);
1237 m_count += transferBytes;
1244 static const byte nullBytes[128] = {0};
1247 size_t len = (size_t)
STDMIN(end-begin,
lword(128));
1248 size_t blockedBytes = target.
ChannelPut2(channel, nullBytes, len, 0, blocking);
1250 return blockedBytes;
1251 begin =
PtrAdd(begin, len);
1260 transferBytes = begin; m_size -= begin;
1261 return blockedBytes;
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Standard names for retrieving values by name when working with NameValuePairs.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
@ DEFAULT_FLAGS
Default flags using THROW_EXCEPTION.
AuthenticatedDecryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment=NULL, word32 flags=DEFAULT_FLAGS, int truncatedDigestSize=-1, BlockPaddingScheme padding=DEFAULT_PADDING)
Construct a AuthenticatedDecryptionFilter.
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.
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
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.
void LastPut(const byte *inString, size_t length)
Input the last block of data.
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
AuthenticatedEncryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment=NULL, bool putAAD=false, int truncatedDigestSize=-1, const std::string &macChannel=DEFAULT_CHANNEL, BlockPaddingScheme padding=DEFAULT_PADDING)
Construct a AuthenticatedEncryptionFilter.
Interface for authenticated encryption modes of operation.
int GetAutoSignalPropagation() const
byte * begin() const
Pointer to the first byte in the memory block.
size_t size() const
Length of the memory block.
const byte * begin() const
Pointer to the first byte in the memory block.
size_t size() const
Length of the memory block.
Implementation of BufferedTransformation's attachment interface.
void Initialize(const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1)
Initialize or reinitialize this object, with signal propagation.
Filter(BufferedTransformation *attachment=NULL)
Construct a Filter.
void Detach(BufferedTransformation *newAttachment=NULL)
Replace an attached transformation.
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.
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.
BufferedTransformation * AttachedTransformation()
Retrieve attached transformation.
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
HashFilter(HashTransformation &hm, BufferedTransformation *attachment=NULL, bool putMessage=false, int truncatedDigestSize=-1, const std::string &messagePutChannel=DEFAULT_CHANNEL, const std::string &hashPutChannel=DEFAULT_CHANNEL)
Construct a HashFilter.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
Exception thrown when a data integrity check failure is encountered.
HashVerificationFilter(HashTransformation &hm, BufferedTransformation *attachment=NULL, word32 flags=DEFAULT_FLAGS, int truncatedDigestSize=-1)
Construct a HashVerificationFilter.
@ DEFAULT_FLAGS
Default flags using HASH_AT_BEGIN and PUT_RESULT.
@ HASH_AT_BEGIN
The hash is at the beginning of the message (i.e., concatenation of hash+message)
@ THROW_EXCEPTION
The filter should throw a HashVerificationFailed if a failure is encountered.
@ PUT_HASH
The hash should be passed to an attached transformation.
@ PUT_MESSAGE
The message should be passed to an attached transformation.
@ PUT_RESULT
The result of the verification should be passed to an attached transformation.
An invalid argument was detected.
size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee.
void AddRangeToSkip(unsigned int message, lword position, lword size, bool sortNow=true)
Adds a range to skip during processing.
void ResetMeter()
Resets the meter.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
bool IsolatedMessageSeriesEnd(bool blocking)
Marks the end of a series of messages, without signal propagation.
Interface for retrieving values given their names.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
bool GetValue(const char *name, T &value) const
Get a named value.
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
CRYPTOPP_DLL void GetRequiredIntParameter(const char *className, const char *name, int &value) const
Retrieves a required name/value pair.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
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.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.
Filter class that is a proxy for a sink.
Interface for public-key signature verifiers.
ProxyFilter(BufferedTransformation *filter, size_t firstSize, size_t lastSize, BufferedTransformation *attachment)
Construct a ProxyFilter.
void SetFilter(Filter *filter)
Sets the OutputProxy filter.
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.
@ PASS_EVERYTHING
Pass everything.
bool GetPassSignals() const
Retrieve signal propagation behavior.
void Initialize(const NameValuePairs ¶meters, int propagation)
Initialize or reinitialize this object, with signal propagation.
Exception thrown when an invalid signature is encountered.
@ SIGNATURE_AT_BEGIN
The signature is at the beginning of the message (i.e., concatenation of signature+message)
@ THROW_EXCEPTION
The filter should throw a HashVerificationFailed if a failure is encountered.
@ DEFAULT_FLAGS
Default flags using SIGNATURE_AT_BEGIN and PUT_RESULT.
@ PUT_MESSAGE
The message should be passed to an attached transformation.
@ PUT_RESULT
The result of the verification should be passed to an attached transformation.
@ PUT_SIGNATURE
The signature should be passed to an attached transformation.
SignatureVerificationFilter(const PK_Verifier &verifier, BufferedTransformation *attachment=NULL, word32 flags=DEFAULT_FLAGS)
Construct a SignatureVerificationFilter.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
virtual size_t PumpMessages2(unsigned int &messageCount, bool blocking=true)=0
Pump messages to attached transformation.
virtual size_t PumpAll2(bool blocking=true)
Pump all data to attached transformation.
bool GetNextMessage()
Start retrieving the next message.
CRYPTOPP_DLL 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.
CRYPTOPP_DLL size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.
Library configuration file.
unsigned int word32
32-bit unsigned datatype
word64 lword
Large word type.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
const std::string AAD_CHANNEL
Channel for additional authenticated data.
Implementation of BufferedTransformation's attachment interface.
Utility functions for the Crypto++ library.
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
#define SIZE_MAX
The maximum value of a machine word.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
ptrdiff_t PtrDiff(const PTR pointer1, const PTR pointer2)
Determine pointer difference.
T1 RoundDownToMultipleOf(const T1 &n, const T2 &m)
Rounds a value down to a multiple of a second value.
InputIt FindIfNot(InputIt first, InputIt last, const T &value)
Finds first element not in a range.
PTR PtrAdd(PTR pointer, OFF offset)
Create a pointer with an offset.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be negative and incorrectly promoted.
CRYPTOPP_DLL void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
Classes for an unlimited queue to store messages.
Crypto++ library namespace.
const char * InputBuffer()
ConstByteArrayParameter.
const char * TruncatedDigestSize()
int
const char * AuthenticatedDecryptionFilterFlags()
word32
const char * PutMessage()
bool
const char * OutputBuffer()
ByteArrayParameter.
const char * HashVerificationFilterFlags()
word32
const char * BlockPaddingScheme()
StreamTransformationFilter::BlockPaddingScheme.
const char * SignatureVerificationFilterFlags()
word32
Classes for automatic resource management.
BlockPaddingScheme
Padding schemes used for block ciphers.
@ DEFAULT_PADDING
Default padding scheme.
@ W3C_PADDING
W3C padding added to a block.
@ PKCS_PADDING
PKCS padding added to a block.
@ ONE_AND_ZEROS_PADDING
1 and 0's padding added to a block
@ NO_PADDING
No padding added to a block.
@ ZEROS_PADDING
0's padding added to a block
byte * HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize)
Create a working space in a BufferedTransformation.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.