Hoist XY and V out of parallel for loop

pull/634/head
Jeffrey Walton 2018-04-02 13:40:33 -04:00
parent cdd751d27a
commit e92fd0f9b2
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 4 additions and 15 deletions

View File

@ -251,34 +251,23 @@ 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);
if (parallel == 1)
// http://stackoverflow.com/q/49604260/608639
#pragma omp parallel
{
AlignedSecByteBlock XY(static_cast<size_t>(blockSize * 256U));
AlignedSecByteBlock V(static_cast<size_t>(blockSize * cost * 128U));
// 2: for i = 0 to p - 1 do
// 3: B_i <-- MF(B_i, N)
Smix(B, static_cast<size_t>(blockSize), cost, V, XY);
XY.SetMark(256); V.SetMark(128);
}
else
{
// 2: for i = 0 to p - 1 do
#pragma omp parallel for
#pragma omp for
for (size_t i = 0; i < static_cast<size_t>(parallel); ++i)
{
// Can't figure out how to hoist this out of the for-loop
// https://stackoverflow.com/q/49604260/608639
AlignedSecByteBlock XY(static_cast<size_t>(blockSize * 256U));
AlignedSecByteBlock V(static_cast<size_t>(blockSize * cost * 128U));
// 3: B_i <-- MF(B_i, N)
const ptrdiff_t offset = static_cast<ptrdiff_t>(blockSize*i*128);
Smix(B+offset, static_cast<size_t>(blockSize), cost, V, XY);
XY.SetMark(256); V.SetMark(128);
}
}
// 5: DK <-- PBKDF2(P, B, 1, dkLen)
PBKDF2_SHA256(derived, derivedLen, secret, secretLen, B, B.size(), 1);