6 #if CRYPTOPP_MSC_VERSION 7 # pragma warning(disable: 4100 4189) 10 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 11 # pragma GCC diagnostic ignored "-Wunused-value" 14 #ifndef CRYPTOPP_IMPORTS 27 : m_attachment(attachment), m_inputPosition(0), m_continueAt(0)
87 if (
OutputFlush(1, hardFlush, propagation, blocking))
127 size_t Filter::Output(
int outputSite,
const byte *inString,
size_t length,
int messageEnd,
bool blocking,
const std::string &channel)
136 bool Filter::OutputFlush(
int outputSite,
bool hardFlush,
int propagation,
bool blocking,
const std::string &channel)
162 m_currentMessageBytes = m_totalBytes = m_currentSeriesMessages = m_totalMessages = m_totalMessageSeries = 0;
163 m_rangesToSkip.clear();
169 m_rangesToSkip.push_back(r);
171 std::sort(m_rangesToSkip.begin(), m_rangesToSkip.end());
185 while (m_length > 0 || messageEnd)
187 if (m_length > 0 && !m_rangesToSkip.empty() && m_rangesToSkip.front().message == m_totalMessages && m_currentMessageBytes + m_length > m_rangesToSkip.front().position)
194 m_currentMessageBytes += t;
197 if (m_currentMessageBytes + m_length < m_rangesToSkip.front().position + m_rangesToSkip.front().size)
201 t = (size_t)
SaturatingSubtract(m_rangesToSkip.front().position + m_rangesToSkip.front().size, m_currentMessageBytes);
203 m_rangesToSkip.pop_front();
208 m_currentMessageBytes += t;
215 m_currentMessageBytes += m_length;
216 m_totalBytes += m_length;
221 m_currentMessageBytes = 0;
222 m_currentSeriesMessages++;
234 return PutMaybeModifiable(const_cast<byte *>(begin), length, messageEnd, blocking,
false);
239 return PutMaybeModifiable(begin, length, messageEnd, blocking,
true);
245 m_currentMessageBytes = 0;
246 m_currentSeriesMessages = 0;
247 m_totalMessageSeries++;
255 m_buffer.New(blockSize * maxBlocks);
256 m_blockSize = blockSize;
257 m_maxBlocks = maxBlocks;
264 if (m_size >= m_blockSize)
267 if ((m_begin+=m_blockSize) == m_buffer.end())
269 m_size -= m_blockSize;
278 numberOfBytes =
STDMIN(numberOfBytes,
STDMIN(
size_t(m_buffer.end()-m_begin), m_size));
280 m_begin += numberOfBytes;
281 m_size -= numberOfBytes;
282 if (m_size == 0 || m_begin == m_buffer.end())
290 if (!outString)
return 0;
292 size_t size = m_size;
293 size_t numberOfBytes = m_maxBlocks*m_blockSize;
294 const byte *ptr = GetContigousBlocks(numberOfBytes);
295 memcpy(outString, ptr, numberOfBytes);
296 memcpy(outString+numberOfBytes, m_begin, m_size);
304 if (!inString || !length)
return;
307 byte *end = (m_size < size_t(m_buffer.end()-m_begin)) ? m_begin + m_size : m_begin + m_size - m_buffer.size();
308 size_t len =
STDMIN(length,
size_t(m_buffer.end()-end));
309 memcpy(end, inString, len);
311 memcpy(m_buffer, inString+len, length-len);
316 :
Filter(attachment), m_firstSize(
SIZE_MAX), m_blockSize(0), m_lastSize(
SIZE_MAX), m_firstInputDone(false)
436 (void)
Output(1, NULL, 0, messageEnd, blocking);
478 if (m_target && GetPassSignals())
479 m_target->Initialize(parameters, propagation);
530 m_rng->IncorporateEntropy(begin, length);
547 return length - copied;
553 return m_buf + m_total;
559 if (!parameters.
GetValue(Name::OutputBuffer(), array))
562 m_size = array.
size();
577 return length - copied;
584 , m_cipher(c), m_padding(DEFAULT_PADDING), m_optimalBufferSize(0)
588 if (!allowAuthenticatedSymmetricCipher && dynamic_cast<AuthenticatedSymmetricCipher *>(&c) != 0)
589 throw InvalidArgument(
"StreamTransformationFilter: please use AuthenticatedEncryptionFilter and AuthenticatedDecryptionFilter for AuthenticatedSymmetricCipher");
675 if (isForwardTransformation &&
m_padding ==
ZEROS_PADDING && (minLastBlockSize == 0 || length < minLastBlockSize))
680 if (inString) {
memcpy(space, inString, length);}
681 memset(space + length, 0, blockSize - length);
687 if (minLastBlockSize == 0)
689 if (isForwardTransformation)
690 throw InvalidDataFormat(
"StreamTransformationFilter: plaintext length is not a multiple of block size and NO_PADDING is specified");
692 throw InvalidCiphertext(
"StreamTransformationFilter: ciphertext length is not a multiple of block size");
711 if (inString) {
memcpy(space, inString, length);}
716 memset(space+length, pad, s-length);
720 space[length] = 0x80;
721 memset(space+length+1, 0, s-length-1);
729 throw InvalidCiphertext(
"StreamTransformationFilter: ciphertext length is not a multiple of block size");
733 byte pad = space[s-1];
734 if (pad < 1 || pad > s || std::find_if(space+s-pad, space+s, std::bind2nd(std::not_equal_to<byte>(), pad)) != space+s)
735 throw InvalidCiphertext(
"StreamTransformationFilter: invalid PKCS #7 block padding found");
740 while (length > 1 && space[length-1] == 0)
742 if (space[--length] != 0x80)
743 throw InvalidCiphertext(
"StreamTransformationFilter: invalid ones-and-zeros padding found");
757 : m_hashModule(hm), m_putMessage(putMessage), m_digestSize(0), m_space(NULL)
758 , m_messagePutChannel(messagePutChannel), m_hashPutChannel(hashPutChannel)
776 if (inString && length)
852 bool putAAD,
int truncatedDigestSize,
const std::string &macChannel,
BlockPaddingScheme padding)
882 return m_hf.
Put2(begin, length, 0, blocking);
898 , m_streamFilter(c, new
OutputProxy(*this, false), padding, true)
901 IsolatedInitialize(
MakeParameters(Name::BlockPaddingScheme(), padding)(Name::AuthenticatedDecryptionFilterFlags(), flags)(Name::TruncatedDigestSize(), truncatedDigestSize));
963 m_messageAccumulator.reset(m_signer.NewSignatureAccumulator(m_rng));
969 m_messageAccumulator->Update(inString, length);
974 m_buf.New(m_signer.SignatureLength());
975 m_signer.Sign(m_rng, m_messageAccumulator.release(),
m_buf);
977 m_messageAccumulator.reset(m_signer.NewSignatureAccumulator(m_rng));
984 , m_verifier(verifier), m_flags(0), m_verified(0)
1056 unsigned int messageCount = UINT_MAX;
1059 }
while(messageCount == UINT_MAX);
1077 if (m_messageEnd || count == 0)
1081 CopyTo(target, ULONG_MAX, channel);
1091 if (!parameters.
GetValue(Name::InputBuffer(), array))
1093 m_store = array.
begin();
1094 m_length = array.
size();
1101 size_t blockedBytes =
CopyRangeTo2(target, position, transferBytes, channel, blocking);
1102 m_count += (size_t)position;
1103 transferBytes = position;
1104 return blockedBytes;
1111 size_t blockedBytes = target.
ChannelPut2(channel, m_store+i, len, 0, blocking);
1114 return blockedBytes;
1128 throw NotImplemented(
"RandomNumberStore: nonblocking transfer is not implemented by this object");
1130 transferBytes =
UnsignedMin(transferBytes, m_length - m_count);
1131 m_rng->GenerateIntoBufferedTransformation(target, channel, transferBytes);
1132 m_count += transferBytes;
1139 static const byte nullBytes[128] = {0};
1142 size_t len = (size_t)
STDMIN(end-begin,
lword(128));
1143 size_t blockedBytes = target.
ChannelPut2(channel, nullBytes, len, 0, blocking);
1145 return blockedBytes;
1155 transferBytes = begin;
1157 return blockedBytes;
Used to pass byte array input as part of a NameValuePairs object.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
bool OutputMessageSeriesEnd(int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
Marks the end of a series of messages, with signal propagation.
Standard names for retrieving values by name when working with NameValuePairs.
void FirstPut(const byte *inString)
An invalid argument was detected.
Indicates the hash is at the beginning of the message (i.e., concatenation of hash+message) ...
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.
#define FILTER_END_NO_MESSAGE_END
HashTransformation & m_hashModule
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
void AddRangeToSkip(unsigned int message, lword position, lword size, bool sortNow=true)
Adds a range to skip during processing.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
Utility functions for the Crypto++ library.
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 InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize)
virtual size_t PumpAll2(bool blocking=true)
Pump all data to attached transformation.
BlockPaddingScheme
Padding schemes used for block ciphers.
member_ptr< BufferedTransformation > m_filter
Interface for one direction (encryption or decryption) of a stream cipher or block cipher mode with a...
CRYPTOPP_DLL void GetRequiredIntParameter(const char *className, const char *name, int &value) const
Retrieves a required name/value pair.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
Indicates the filter should throw a HashVerificationFailed if a failure is encountered.
SecByteBlock m_expectedHash
Indicates the result of the verification should be passed to an attached transformation.
Filter class that is a proxy for a sink.
void LastPut(const byte *inString, size_t length)
Input the last block of data.
#define FILTER_OUTPUT(site, output, length, messageEnd)
#define NAMESPACE_BEGIN(x)
void PropagateInitialize(const NameValuePairs ¶meters, int propagation)
bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
Marks the end of a series of messages, with signal propagation.
AuthenticatedDecryptionFilter(AuthenticatedSymmetricCipher &c, BufferedTransformation *attachment=NULL, word32 flags=DEFAULT_FLAGS, int truncatedDigestSize=-1, BlockPaddingScheme padding=DEFAULT_PADDING)
Construct a AuthenticatedDecryptionFilter.
void NextPutMultiple(const byte *inString, size_t length)
member_ptr< BufferedTransformation > m_attachment
size_type size() const
Provides the count of elements in the SecBlock.
void ResetMeter()
Resets the meter.
Indicates the filter should throw a HashVerificationFailed if a failure is encountered.
Classes for automatic resource management.
size_t size() const
Length of the memory block.
Indicates the message should be passed to an attached transformation.
Library configuration file.
void FirstPut(const byte *inString)
byte * ChannelCreatePutSpace(const std::string &channel, size_t &size)
Request space which can be written into by the caller.
StreamTransformationFilter m_streamFilter
bool GetNextMessage()
Start retrieving the next message.
void New(size_type newSize)
Change size without preserving contents.
Combines two sets of NameValuePairs.
void Insert(Filter *nextFilter)
virtual bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const =0
Check whether messageAccumulator contains a valid signature and message, and restart messageAccumulat...
virtual size_t SignatureLength() const =0
Provides the signature length if it only depends on the key.
Used to pass byte array input as part of a NameValuePairs object.
void NextPutMultiple(const byte *s, size_t len)
const byte * begin() const
Pointer to the first byte in the memory block.
void FirstPut(const byte *inString)
Exception thrown when an invalid signature is encountered.
virtual bool ShouldPropagateMessageSeriesEnd() const
SignatureVerificationFilter(const PK_Verifier &verifier, BufferedTransformation *attachment=NULL, word32 flags=DEFAULT_FLAGS)
Construct a SignatureVerificationFilter.
unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
HashTransformation & m_hashModule
Pointer that overloads operator ->
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
size_t Output(int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
Forward processed data on to attached transformation.
Default flags using THROW_EXCEPTION.
void LastPut(const byte *inString, size_t length)
Input the last block of data.
Exception thrown when a data integrity check failure is encountered.
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
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.
1 and 0's padding added to a block
HashVerificationFilter(HashTransformation &hm, BufferedTransformation *attachment=NULL, word32 flags=DEFAULT_FLAGS, int truncatedDigestSize=-1)
Construct a HashVerificationFilter.
bool OutputFlush(int outputSite, bool hardFlush, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
Flush buffered input and/or output, with signal propagation.
bool GetValue(const char *name, T &value) const
Get a named value.
A method was called which was not implemented.
std::string m_hashPutChannel
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
const PK_Verifier & m_verifier
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
void Detach(BufferedTransformation *newAttachment=NULL)
Replace an attached transformation.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
void NextPutMultiple(const byte *inString, size_t length)
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 int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
BufferedTransformation * AttachedTransformation()
Retrieve attached transformation.
size_t PutModifiable2(byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes that may be modified by callee.
Indicates the message should be passed to an attached transformation.
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 PutMaybeModifiable(byte *inString, size_t length, int messageEnd, bool blocking, bool modifiable)
byte * begin() const
Pointer to the first byte in the memory block.
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
#define FILTER_OUTPUT_MAYBE_MODIFIABLE(site, output, length, messageEnd, modifiable)
size_t OutputModifiable(int outputSite, byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
Output multiple bytes that may be modified by callee.
unsigned int m_digestSize
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
const std::string AAD_CHANNEL
Channel for additional authenticated data.
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be neagtive and incorrectly promoted.
Indicates the hash should be passed to an attached transformation.
bool IsolatedMessageSeriesEnd(bool blocking)
Marks the end of a series of messages, without signal propagation.
size_t size() const
Length of the memory block.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
member_ptr< PK_MessageAccumulator > m_messageAccumulator
unsigned int m_digestSize
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without 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.
void LastPut(const byte *inString, size_t length)
Input the last block of data.
void LastPut(const byte *inString, size_t length)
Input the last block of data.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
CRYPTOPP_DLL void StoreInitialize(const NameValuePairs ¶meters)
virtual PK_MessageAccumulator * NewVerificationAccumulator() const =0
Create a new HashTransformation to accumulate the message to be verified.
Implementation of BufferedTransformation's attachment interface.
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
Input multiple bytes for processing.
A decryption filter encountered invalid ciphertext.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.
byte * CreatePutSpace(size_t &size)
Request space which can be written into by the caller.
Interface for public-key signature verifiers.
uint8_t const size_t const size
void * memcpy(void *a, const void *b, size_t c)
#define CRYPTOPP_UNUSED(x)
HashVerificationFilter m_hashVerifier
Indicates the result of the verification should be passed to an attached transformation.
virtual BufferedTransformation * NewDefaultAttachment() const
ProxyFilter(BufferedTransformation *filter, size_t firstSize, size_t lastSize, BufferedTransformation *attachment)
Construct a ProxyFilter.
size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
Transfer bytes from this object to another BufferedTransformation.
virtual bool SignatureUpfront() const
Determines whether the signature must be input before the 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.
bool IsolatedFlush(bool hardFlush, bool blocking)
Flushes data buffered by this object, without signal propagation.
0's padding added to a block
Implementation of BufferedTransformation's attachment interface.
void StoreInitialize(const NameValuePairs ¶meters)
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
std::vector< char * > parameters
No padding added to a block.
void InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize)
void Initialize(const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1)
Initialize or reinitialize this object, with signal propagation.
void Initialize(const NameValuePairs ¶meters, int propagation)
Initialize or reinitialize this object, with signal propagation.
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.
PKCS #5 padding added to a block.
Indicates the signature is at the beginning of the message (i.e., concatenation of signature+message)...
void InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, size_t &firstSize, size_t &blockSize, size_t &lastSize)
Indicates the signature should be passed to an attached transformation.
void NextPutMultiple(const byte *inString, size_t length)
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.
virtual void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, size_t signatureLength) const =0
Input signature into a message accumulator.
Default flags using SIGNATURE_AT_BEGIN and PUT_RESULT.
#define FILTER_OUTPUT3(site, statement, output, length, messageEnd, channel)
byte * HelpCreatePutSpace(BufferedTransformation &target, const std::string &channel, size_t minSize, size_t desiredSize, size_t &bufferSize)
Create a working space in a BufferedTransformation.
void * memmove(void *a, const void *b, size_t c)
std::string m_messagePutChannel
void SetFilter(Filter *filter)
Sets the OutputProxy filter.
bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
Flush buffered input and/or output, with signal propagation.
T1 RoundDownToMultipleOf(const T1 &n, const T2 &m)
Rounds a value down to a multiple of a second value.
Default flags using HASH_AT_BEGIN and PUT_RESULT.
void NextPutModifiable(byte *inString, size_t length)
#define RETURN_IF_NONZERO(x)
void IsolatedInitialize(const NameValuePairs ¶meters)
Initialize or reinitialize this object, without signal propagation.
Interface for retrieving values given their names.