From 672f5c7f3dad8ae12b2d0ce0940ccb7c8e257bf8 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 20 Jan 2019 22:43:00 -0500 Subject: [PATCH] Update documentation --- scrypt.cpp | 18 ++++++++++++++---- scrypt.h | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/scrypt.cpp b/scrypt.cpp index 0098d71a..27e604ee 100644 --- a/scrypt.cpp +++ b/scrypt.cpp @@ -183,6 +183,16 @@ void Scrypt::ValidateParameters(size_t derivedLen, word64 cost, word64 blockSize } } + // https://github.com/weidai11/cryptopp/issues/787 + CRYPTOPP_ASSERT(parallelization <= std::numeric_limits::max()); + if (parallelization > static_cast(std::numeric_limits::max())) + { + std::ostringstream oss; + oss << " parallelization " << parallelization << " is larger than "; + oss << numeric_limits::max(); + throw InvalidArgument("Scrypt: " + oss.str()); + } + CRYPTOPP_ASSERT(IsPowerOf2(cost)); if (IsPowerOf2(cost) == false) throw InvalidArgument("Scrypt: cost must be a power of 2"); @@ -257,10 +267,10 @@ size_t Scrypt::DeriveKey(byte*derived, size_t derivedLen, const byte*secret, siz // 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) PBKDF2_SHA256(B, B.size(), secret, secretLen, salt, saltLen, 1); - // Visual Studio and OpenMP 2.0 fixup. We must use int, not size_t. - int maxParallel=0; - if (!SafeConvert(parallel, maxParallel)) - maxParallel = std::numeric_limits::max(); + // Visual Studio and OpenMP 2.0 fixup. We must use int, not size_t. + int maxParallel=0; + if (!SafeConvert(parallel, maxParallel)) + maxParallel = std::numeric_limits::max(); #ifdef _OPENMP int threads = STDMIN(omp_get_max_threads(), maxParallel); diff --git a/scrypt.h b/scrypt.h index 129c5dc3..8c6f394f 100644 --- a/scrypt.h +++ b/scrypt.h @@ -76,7 +76,9 @@ public: /// \details The parameter blockSize ("r" in the documents) specifies the block /// size. /// \details The parallelization parameter ("p" in the documents) is a positive - /// integer less than or equal to ((2^32-1) * 32) / (128 * r). + /// integer less than or equal to ((2^32-1) * 32) / (128 * r). Due to Microsoft + /// and its OpenMP 2.0 implementation parallelization is limited to + /// std::numeric_limits::max(). /// \details Scrypt always returns 1 because it only performs 1 iteration. Other /// derivation functions, like PBKDF's, will return more interesting values. /// \details The Crypto++ implementation of Scrypt is limited by C++ datatypes. For