5 #ifndef CRYPTOPP_IMPORTS 11 void AuthenticatedSymmetricCipherBase::AuthenticateData(
const byte *input,
size_t len)
13 unsigned int blockSize = AuthenticationBlockSize();
14 unsigned int &num = m_bufferedDataLength;
15 byte* data = m_buffer.
begin();
19 if (num+len >= blockSize)
21 memcpy(data+num, input, blockSize-num);
22 AuthenticateBlocks(data, blockSize);
23 input += (blockSize-num);
24 len -= (blockSize-num);
30 memcpy(data+num, input, len);
31 num += (
unsigned int)len;
39 size_t leftOver = AuthenticateBlocks(input, len);
40 input += (len - leftOver);
44 memcpy(data, input, len);
45 num = (
unsigned int)len;
50 m_bufferedDataLength = 0;
51 m_state = State_Start;
53 this->SetKeyWithoutResync(userKey, keylength, params);
54 m_state = State_KeySet;
57 const byte *iv = GetIVAndThrowIfInvalid(params, length);
64 if (m_state < State_KeySet)
67 m_bufferedDataLength = 0;
68 m_totalHeaderLength = m_totalMessageLength = m_totalFooterLength = 0;
69 m_state = State_KeySet;
71 Resync(iv, this->ThrowIfInvalidIVLength(length));
72 m_state = State_IVSet;
77 if (length == 0) {
return;}
85 AuthenticateData(input, length);
86 m_totalHeaderLength += length;
88 case State_AuthUntransformed:
89 case State_AuthTransformed:
90 AuthenticateLastConfidentialBlock();
91 m_bufferedDataLength = 0;
92 m_state = State_AuthFooter;
94 case State_AuthFooter:
95 AuthenticateData(input, length);
96 m_totalFooterLength += length;
105 m_totalMessageLength += length;
115 case State_AuthFooter:
118 AuthenticateLastHeaderBlock();
119 m_bufferedDataLength = 0;
120 m_state = AuthenticationIsOnPlaintext()==
IsForwardTransformation() ? State_AuthUntransformed : State_AuthTransformed;
122 case State_AuthUntransformed:
123 AuthenticateData(inString, length);
124 AccessSymmetricCipher().
ProcessData(outString, inString, length);
126 case State_AuthTransformed:
127 AccessSymmetricCipher().
ProcessData(outString, inString, length);
128 AuthenticateData(outString, length);
143 throw InvalidArgument(
AlgorithmName() +
": additional authenticated data (AAD) cannot be input after data to be encrypted or decrypted");
155 AuthenticateLastHeaderBlock();
156 m_bufferedDataLength = 0;
159 case State_AuthUntransformed:
160 case State_AuthTransformed:
161 AuthenticateLastConfidentialBlock();
162 m_bufferedDataLength = 0;
165 case State_AuthFooter:
166 AuthenticateLastFooterBlock(mac, macSize);
167 m_bufferedDataLength = 0;
174 m_state = State_KeySet;
An invalid argument was detected.
void ProcessData(byte *outString, const byte *inString, size_t length)
Encrypt or decrypt an array of bytes.
Exception thrown when the object is in the wrong state for the operation.
void Resynchronize(const byte *iv, int length=-1)
Resynchronize with an IV.
virtual lword MaxHeaderLength() const =0
Provides the maximum length of AAD that can be input.
void SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
Sets or reset the key of this object.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
iterator begin()
Provides an iterator pointing to the first element in the memory block.
virtual lword MaxMessageLength() const =0
Provides the maximum length of encrypted data.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Crypto++ library namespace.
void TruncatedFinal(byte *mac, size_t macSize)
Computes the hash of the current message.
virtual lword MaxFooterLength() const
Provides the the maximum length of AAD.
Classes for authenticated encryption modes of operation.
Interface for retrieving values given their names.