5#ifndef CRYPTOPP_IMPORTS
9NAMESPACE_BEGIN(CryptoPP)
11void AuthenticatedSymmetricCipherBase::AuthenticateData(
const byte *input,
size_t len)
14 CRYPTOPP_ASSERT(input && len);
15 if(!input || !len)
return;
17 unsigned int blockSize = AuthenticationBlockSize();
18 unsigned int &num = m_bufferedDataLength;
19 byte* data = m_buffer.
begin();
23 if (num+len >= blockSize)
25 memcpy(data+num, input, blockSize-num);
26 AuthenticateBlocks(data, blockSize);
27 input += (blockSize-num);
28 len -= (blockSize-num);
34 memcpy(data+num, input, len);
35 num += (
unsigned int)len;
43 size_t leftOver = AuthenticateBlocks(input, len);
44 input += (len - leftOver);
49 memcpy(data, input, len);
50 num = (
unsigned int)len;
55 m_bufferedDataLength = 0;
56 m_state = State_Start;
58 this->SetKeyWithoutResync(userKey, keylength, params);
59 m_state = State_KeySet;
69 if (m_state < State_KeySet)
72 m_bufferedDataLength = 0;
73 m_totalHeaderLength = m_totalMessageLength = m_totalFooterLength = 0;
74 m_state = State_KeySet;
77 m_state = State_IVSet;
83 if (length == 0) {
return;}
91 AuthenticateData(input, length);
92 m_totalHeaderLength += length;
94 case State_AuthUntransformed:
95 case State_AuthTransformed:
96 AuthenticateLastConfidentialBlock();
97 m_bufferedDataLength = 0;
98 m_state = State_AuthFooter;
100 case State_AuthFooter:
101 AuthenticateData(input, length);
102 m_totalFooterLength += length;
105 CRYPTOPP_ASSERT(
false);
111 if (m_state >= State_IVSet && length >
MaxMessageLength()-m_totalMessageLength)
113 m_totalMessageLength += length;
121 case State_AuthFooter:
124 AuthenticateLastHeaderBlock();
125 m_bufferedDataLength = 0;
126 m_state = AuthenticationIsOnPlaintext()==
IsForwardTransformation() ? State_AuthUntransformed : State_AuthTransformed;
128 case State_AuthUntransformed:
129 AuthenticateData(inString, length);
130 AccessSymmetricCipher().
ProcessData(outString, inString, length);
132 case State_AuthTransformed:
133 AccessSymmetricCipher().
ProcessData(outString, inString, length);
134 AuthenticateData(outString, length);
137 CRYPTOPP_ASSERT(
false);
152 throw InvalidArgument(
AlgorithmName() +
": additional authenticated data (AAD) cannot be input after data to be encrypted or decrypted");
164 AuthenticateLastHeaderBlock();
165 m_bufferedDataLength = 0;
168 case State_AuthUntransformed:
169 case State_AuthTransformed:
170 AuthenticateLastConfidentialBlock();
171 m_bufferedDataLength = 0;
174 case State_AuthFooter:
175 AuthenticateLastFooterBlock(mac, macSize);
176 m_bufferedDataLength = 0;
180 CRYPTOPP_ASSERT(
false);
183 m_state = State_KeySet;
Classes for authenticated encryption modes of operation.
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.
void ProcessData(byte *outString, const byte *inString, size_t length)
Encrypt or decrypt an array of bytes.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
void TruncatedFinal(byte *mac, size_t macSize)
Computes the hash of the current message.
void SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
Sets or reset the key of this object.
virtual lword MaxHeaderLength() const =0
Provides the maximum length of AAD that can be input.
virtual lword MaxFooterLength() const
Provides the maximum length of AAD.
virtual lword MaxMessageLength() const =0
Provides the maximum length of encrypted data.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
An invalid argument was detected.
Interface for retrieving values given their names.
iterator begin()
Provides an iterator pointing to the first element in the memory block.
const byte * GetIVAndThrowIfInvalid(const NameValuePairs ¶ms, size_t &size)
Retrieves and validates the IV.
size_t ThrowIfInvalidIVLength(int length)
Validates the IV length.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.