diff --git a/src/crypto/crypto_scrypt.cc b/src/crypto/crypto_scrypt.cc index 4dae07f13604d4..a262a2be96d7c3 100644 --- a/src/crypto/crypto_scrypt.cc +++ b/src/crypto/crypto_scrypt.cc @@ -104,7 +104,17 @@ Maybe ScryptTraits::AdditionalConfig( params->maxmem, nullptr, 0) != 1) { - THROW_ERR_CRYPTO_INVALID_SCRYPT_PARAMS(env); + // Do not use CryptoErrorStore or ThrowCryptoError here in order to maintain + // backward compatibility with ERR_CRYPTO_INVALID_SCRYPT_PARAMS. + uint32_t err = ERR_peek_last_error(); + if (err != 0) { + char buf[256]; + ERR_error_string_n(err, buf, sizeof(buf)); + THROW_ERR_CRYPTO_INVALID_SCRYPT_PARAMS( + env, "Invalid scrypt params: %s", buf); + } else { + THROW_ERR_CRYPTO_INVALID_SCRYPT_PARAMS(env); + } return Nothing(); } diff --git a/test/parallel/test-crypto-scrypt.js b/test/parallel/test-crypto-scrypt.js index 73bf0217b1fb67..61bd65fc92678c 100644 --- a/test/parallel/test-crypto-scrypt.js +++ b/test/parallel/test-crypto-scrypt.js @@ -178,7 +178,8 @@ for (const options of bad) { for (const options of toobig) { const expected = { - message: /Invalid scrypt param/ + message: /Invalid scrypt params:.*memory limit exceeded/, + code: 'ERR_CRYPTO_INVALID_SCRYPT_PARAMS', }; assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}), expected);