Add additional asserts to Scrypt

This commit is contained in:
Jeffrey Walton 2018-04-01 15:49:00 -04:00
parent ea9a5cf755
commit eb483dd3a6
No known key found for this signature in database
GPG Key ID: B36AB348921B1838

View File

@ -223,10 +223,13 @@ void Scrypt::ValidateParameters(size_t derivedLen, word64 cost, word64 blockSize
}
}
CRYPTOPP_ASSERT(IsPowerOf2(cost));
if (IsPowerOf2(cost) == false)
throw InvalidArgument("Scrypt: cost must be a power of 2");
const word64 prod = static_cast<word64>(blockSize) * parallelization;
CRYPTOPP_ASSERT(prod < (1U << 30));
if (prod >= (1U << 30)) {
std::ostringstream oss;
oss << "r*p " << prod << " is larger than " << (1U << 30);
@ -285,7 +288,6 @@ 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(IsPowerOf2(cost));
ThrowIfInvalidDerivedLength(derivedLen);
ValidateParameters(derivedLen, cost, blockSize, parallel);