size_t SimpleKeyingInterface::ThrowIfInvalidIVLength(int size) { if (size < 0) return (size_t)IVSize(); else if ((size_t)size < MinIVLength()) throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(size) + " is less than the minimum of " + IntToString(MinIVLength())); else if ((size_t)size > MaxIVLength()) throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": IV length " + IntToString(size) + " exceeds the maximum of " + IntToString(MaxIVLength())); else return (size_t)size; }
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); }
void SimpleKeyingInterface::ThrowIfInvalidIV(const byte *iv) { if (!iv && IVRequirement() == UNPREDICTABLE_RANDOM_IV) throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object cannot use a null IV"); }
void SimpleKeyingInterface::ThrowIfResynchronizable() { if (IsResynchronizable()) throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object requires an IV"); }
void SimpleKeyingInterface::ThrowIfInvalidKeyLength(size_t length) { if (!IsValidKeyLength(length)) throw InvalidKeyLength(GetAlgorithm().AlgorithmName(), length); }
void SimpleKeyingInterface::ThrowIfInvalidIV(const byte *iv) { if (!iv && !(IVRequirement() == INTERNALLY_GENERATED_IV || IVRequirement() == STRUCTURED_IV || !IsResynchronizable())) throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object cannot use a null IV"); }