diff --git a/cryptlib.cpp b/cryptlib.cpp index 621f4f9a6..173c6d102 100644 --- a/cryptlib.cpp +++ b/cryptlib.cpp @@ -344,10 +344,10 @@ size_t KeyDerivationFunction::MaxDerivedKeyLength() const return static_cast(-1); } -void KeyDerivationFunction::ThrowIfInvalidDerivedLength(size_t length) const +void KeyDerivationFunction::ThrowIfInvalidDerivedKeyLength(size_t length) const { if (!IsValidDerivedLength(length)) - throw InvalidDerivedLength(GetAlgorithm().AlgorithmName(), length); + throw InvalidDerivedKeyLength(GetAlgorithm().AlgorithmName(), length); } void KeyDerivationFunction::SetParameters(const NameValuePairs& params) { diff --git a/cryptlib.h b/cryptlib.h index b1f5a71b2..7e105a3c8 100644 --- a/cryptlib.h +++ b/cryptlib.h @@ -1503,7 +1503,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE KeyDerivationFunction : public Algorithm /// \param secretLen the size of the secret buffer, in bytes /// \param params additional initialization parameters to configure this object /// \returns the number of iterations performed - /// \throws InvalidDerivedLength if derivedLen is invalid for the scheme + /// \throws InvalidDerivedKeyLength if derivedLen is invalid for the scheme /// \details DeriveKey() provides a standard interface to derive a key from /// a secret seed and other parameters. Each class that derives from KeyDerivationFunction /// provides an overload that accepts most parameters used by the derivation function. @@ -1525,7 +1525,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE KeyDerivationFunction : public Algorithm /// \brief Validates the derived key length /// \param length the size of the derived key material, in bytes /// \throws InvalidKeyLength if the key length is invalid - void ThrowIfInvalidDerivedLength(size_t length) const; + void ThrowIfInvalidDerivedKeyLength(size_t length) const; }; /// \brief Interface for password based key derivation functions diff --git a/hkdf.h b/hkdf.h index cbb5319e7..56e3054d0 100644 --- a/hkdf.h +++ b/hkdf.h @@ -39,7 +39,7 @@ class HKDF : public KeyDerivationFunction } // KeyDerivationFunction interface - size_t MaxDerivedLength() const { + size_t MaxDerivedKeyLength() const { return static_cast(T::DIGESTSIZE) * 255; } @@ -60,7 +60,7 @@ class HKDF : public KeyDerivationFunction /// \param info the additional input buffer /// \param infoLen the size of the info buffer, in bytes /// \returns the number of iterations performed - /// \throws InvalidDerivedLength if derivedLen is invalid for the scheme + /// \throws InvalidDerivedKeyLength if derivedLen is invalid for the scheme /// \details DeriveKey() provides a standard interface to derive a key from /// a seed and other parameters. Each class that derives from KeyDerivationFunction /// provides an overload that accepts most parameters used by the derivation function. @@ -92,8 +92,8 @@ class HKDF : public KeyDerivationFunction template size_t HKDF::GetValidDerivedLength(size_t keylength) const { - if (keylength > MaxDerivedLength()) - return MaxDerivedLength(); + if (keylength > MaxDerivedKeyLength()) + return MaxDerivedKeyLength(); return keylength; } @@ -103,7 +103,7 @@ size_t HKDF::DeriveKey(byte *derived, size_t derivedLen, { CRYPTOPP_ASSERT(secret && secretLen); CRYPTOPP_ASSERT(derived && derivedLen); - CRYPTOPP_ASSERT(derivedLen <= MaxDerivedLength()); + CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); ConstByteArrayParameter p; SecByteBlock salt, info; @@ -127,9 +127,9 @@ size_t HKDF::DeriveKey(byte *derived, size_t derivedLen, const byte *secret, { CRYPTOPP_ASSERT(secret && secretLen); CRYPTOPP_ASSERT(derived && derivedLen); - CRYPTOPP_ASSERT(derivedLen <= MaxDerivedLength()); + CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); - ThrowIfInvalidDerivedLength(derivedLen); + ThrowIfInvalidDerivedKeyLength(derivedLen); // HKDF business logic. NULL is different than empty. if (salt == NULLPTR) diff --git a/pwdbased.h b/pwdbased.h index dcc238378..ded97aea9 100644 --- a/pwdbased.h +++ b/pwdbased.h @@ -61,7 +61,7 @@ class PKCS5_PBKDF1 : public PasswordBasedKeyDerivationFunction /// \param iterations the number of iterations /// \param timeInSeconds the in seconds /// \returns the number of iterations performed - /// \throws InvalidDerivedLength if derivedLen is invalid for the scheme + /// \throws InvalidDerivedKeyLength if derivedLen is invalid for the scheme /// \details DeriveKey() provides a standard interface to derive a key from /// a seed and other parameters. Each class that derives from KeyDerivationFunction /// provides an overload that accepts most parameters used by the derivation function. @@ -116,7 +116,7 @@ size_t PKCS5_PBKDF1::DeriveKey(byte *derived, size_t derivedLen, byte purpose CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); CRYPTOPP_UNUSED(purpose); - ThrowIfInvalidDerivedLength(derivedLen); + ThrowIfInvalidDerivedKeyLength(derivedLen); // Business logic if (!iterations) { iterations = 1; } @@ -187,7 +187,7 @@ class PKCS5_PBKDF2_HMAC : public PasswordBasedKeyDerivationFunction /// \param iterations the number of iterations /// \param timeInSeconds the in seconds /// \returns the number of iterations performed - /// \throws InvalidDerivedLength if derivedLen is invalid for the scheme + /// \throws InvalidDerivedKeyLength if derivedLen is invalid for the scheme /// \details DeriveKey() provides a standard interface to derive a key from /// a seed and other parameters. Each class that derives from KeyDerivationFunction /// provides an overload that accepts most parameters used by the derivation function. @@ -241,7 +241,7 @@ size_t PKCS5_PBKDF2_HMAC::DeriveKey(byte *derived, size_t derivedLen, byte pu CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); CRYPTOPP_UNUSED(purpose); - ThrowIfInvalidDerivedLength(derivedLen); + ThrowIfInvalidDerivedKeyLength(derivedLen); // Business logic if (!iterations) { iterations = 1; } @@ -344,7 +344,7 @@ class PKCS12_PBKDF : public PasswordBasedKeyDerivationFunction /// \param iterations the number of iterations /// \param timeInSeconds the in seconds /// \returns the number of iterations performed - /// \throws InvalidDerivedLength if derivedLen is invalid for the scheme + /// \throws InvalidDerivedKeyLength if derivedLen is invalid for the scheme /// \details DeriveKey() provides a standard interface to derive a key from /// a seed and other parameters. Each class that derives from KeyDerivationFunction /// provides an overload that accepts most parameters used by the derivation function. @@ -398,7 +398,7 @@ size_t PKCS12_PBKDF::DeriveKey(byte *derived, size_t derivedLen, byte purpose CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); CRYPTOPP_ASSERT(iterations > 0 || timeInSeconds > 0); - ThrowIfInvalidDerivedLength(derivedLen); + ThrowIfInvalidDerivedKeyLength(derivedLen); // Business logic if (!iterations) { iterations = 1; } diff --git a/scrypt.cpp b/scrypt.cpp index b588de332..3b995813f 100644 --- a/scrypt.cpp +++ b/scrypt.cpp @@ -177,8 +177,8 @@ NAMESPACE_BEGIN(CryptoPP) size_t Scrypt::GetValidDerivedLength(size_t keylength) const { - if (keylength > MaxDerivedLength()) - return MaxDerivedLength(); + if (keylength > MaxDerivedKeyLength()) + return MaxDerivedKeyLength(); return keylength; } @@ -261,7 +261,7 @@ size_t Scrypt::DeriveKey(byte*derived, size_t derivedLen, { CRYPTOPP_ASSERT(secret /*&& secretLen*/); CRYPTOPP_ASSERT(derived && derivedLen); - CRYPTOPP_ASSERT(derivedLen <= MaxDerivedLength()); + CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); word64 cost=0, blockSize=0, parallelization=0; if(params.GetValue("Cost", cost) == false) @@ -284,9 +284,9 @@ size_t Scrypt::DeriveKey(byte*derived, size_t derivedLen, const byte*secret, siz { CRYPTOPP_ASSERT(secret /*&& secretLen*/); CRYPTOPP_ASSERT(derived && derivedLen); - CRYPTOPP_ASSERT(derivedLen <= MaxDerivedLength()); + CRYPTOPP_ASSERT(derivedLen <= MaxDerivedKeyLength()); - ThrowIfInvalidDerivedLength(derivedLen); + ThrowIfInvalidDerivedKeyLength(derivedLen); ValidateParameters(derivedLen, cost, blockSize, parallel); AlignedSecByteBlock B(static_cast(blockSize * parallel * 128U)); diff --git a/scrypt.h b/scrypt.h index 8c6f394f2..37c0161db 100644 --- a/scrypt.h +++ b/scrypt.h @@ -45,8 +45,8 @@ class Scrypt : public KeyDerivationFunction } // KeyDerivationFunction interface - size_t MaxDerivedLength() const { - return static_cast(-1); + size_t MaxDerivedKeyLength() const { + return static_cast(0)-1; } // KeyDerivationFunction interface @@ -67,7 +67,7 @@ class Scrypt : public KeyDerivationFunction /// \param blockSize the block size /// \param parallelization the parallelization factor /// \returns the number of iterations performed - /// \throws InvalidDerivedLength if derivedLen is invalid for the scheme + /// \throws InvalidDerivedKeyLength if derivedLen is invalid for the scheme /// \details DeriveKey() provides a standard interface to derive a key from /// a seed and other parameters. Each class that derives from KeyDerivationFunction /// provides an overload that accepts most parameters used by the derivation function. diff --git a/simple.h b/simple.h index 4ebe8d812..f14cf2bab 100644 --- a/simple.h +++ b/simple.h @@ -70,10 +70,10 @@ class CRYPTOPP_DLL InvalidBlockSize : public InvalidArgument }; /// \brief Exception thrown when an invalid derived key length is encountered -class CRYPTOPP_DLL InvalidDerivedLength : public InvalidArgument +class CRYPTOPP_DLL InvalidDerivedKeyLength : public InvalidArgument { public: - explicit InvalidDerivedLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid derived key length") {} + explicit InvalidDerivedKeyLength(const std::string &algorithm, size_t length) : InvalidArgument(algorithm + ": " + IntToString(length) + " is not a valid derived key length") {} }; /// \brief Exception thrown when an invalid personalization string length is encountered