void AuthenticatedSymmetricCipherBase::TruncatedFinal(byte *mac, size_t macSize) { if (m_totalHeaderLength > MaxHeaderLength()) throw InvalidArgument(AlgorithmName() + ": header length of " + IntToString(m_totalHeaderLength) + " exceeds the maximum of " + IntToString(MaxHeaderLength())); if (m_totalFooterLength > MaxFooterLength()) { if (MaxFooterLength() == 0) throw InvalidArgument(AlgorithmName() + ": additional authenticated data (AAD) cannot be input after data to be encrypted or decrypted"); else throw InvalidArgument(AlgorithmName() + ": footer length of " + IntToString(m_totalFooterLength) + " exceeds the maximum of " + IntToString(MaxFooterLength())); } switch (m_state) { case State_Start: case State_KeySet: throw BadState(AlgorithmName(), "TruncatedFinal", "setting key and IV"); case State_IVSet: AuthenticateLastHeaderBlock(); m_bufferedDataLength = 0; // fall through case State_AuthUntransformed: case State_AuthTransformed: AuthenticateLastConfidentialBlock(); m_bufferedDataLength = 0; // fall through case State_AuthFooter: AuthenticateLastFooterBlock(mac, macSize); m_bufferedDataLength = 0; break; default: CRYPTOPP_ASSERT(false); } m_state = State_KeySet; }
void AuthenticatedSymmetricCipher::SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength) { if (headerLength > MaxHeaderLength()) throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": header length " + IntToString(headerLength) + " exceeds the maximum of " + IntToString(MaxHeaderLength())); if (messageLength > MaxMessageLength()) throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": message length " + IntToString(messageLength) + " exceeds the maximum of " + IntToString(MaxMessageLength())); if (footerLength > MaxFooterLength()) throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": footer length " + IntToString(footerLength) + " exceeds the maximum of " + IntToString(MaxFooterLength())); UncheckedSpecifyDataLengths(headerLength, messageLength, footerLength); }