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 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;
86 AuthenticateData(input, length);
87 m_totalHeaderLength += length;
89 case State_AuthUntransformed:
90 case State_AuthTransformed:
91 AuthenticateLastConfidentialBlock();
92 m_bufferedDataLength = 0;
93 m_state = State_AuthFooter;
95 case State_AuthFooter:
96 AuthenticateData(input, length);
97 m_totalFooterLength += length;
106 m_totalMessageLength += length;
116 case State_AuthFooter:
119 AuthenticateLastHeaderBlock();
120 m_bufferedDataLength = 0;
121 m_state = AuthenticationIsOnPlaintext()==
IsForwardTransformation() ? State_AuthUntransformed : State_AuthTransformed;
123 case State_AuthUntransformed:
124 AuthenticateData(inString, length);
125 AccessSymmetricCipher().
ProcessData(outString, inString, length);
127 case State_AuthTransformed:
128 AccessSymmetricCipher().
ProcessData(outString, inString, length);
129 AuthenticateData(outString, length);
144 throw InvalidArgument(
AlgorithmName() +
": additional authenticated data (AAD) cannot be input after data to be encrypted or decrypted");
156 AuthenticateLastHeaderBlock();
157 m_bufferedDataLength = 0;
160 case State_AuthUntransformed:
161 case State_AuthTransformed:
162 AuthenticateLastConfidentialBlock();
163 m_bufferedDataLength = 0;
166 case State_AuthFooter:
167 AuthenticateLastFooterBlock(mac, macSize);
168 m_bufferedDataLength = 0;
175 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.
#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.
virtual std::string AlgorithmName() const =0
Provides the name of this algorithm.
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.
Base classes for working with authenticated encryption modes of encryption.
Interface for retrieving values given their names.