Fix overcommit resources for Scrypt parallelization (GH #641)

pull/665/head
Jeffrey Walton 2018-05-20 08:33:21 -04:00
parent a0f91aeb25
commit edc7689a7f
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 7 additions and 1 deletions

View File

@ -245,8 +245,14 @@ 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) // 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen)
PBKDF2_SHA256(B, B.size(), secret, secretLen, salt, saltLen, 1); PBKDF2_SHA256(B, B.size(), secret, secretLen, salt, saltLen, 1);
#ifdef _OPENMP
int threads = STDMIN(omp_get_max_threads(),
static_cast<int>(STDMIN(static_cast<size_t>(parallel),
static_cast<size_t>(std::numeric_limits<int>::max()))));
#endif
// http://stackoverflow.com/q/49604260/608639 // http://stackoverflow.com/q/49604260/608639
#pragma omp parallel #pragma omp parallel num_threads(threads)
{ {
// Each thread gets its own copy // Each thread gets its own copy
AlignedSecByteBlock XY(static_cast<size_t>(blockSize * 256U)); AlignedSecByteBlock XY(static_cast<size_t>(blockSize * 256U));