Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/crypto/crypto_scrypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Maybe<void> ScryptTraits::AdditionalConfig(
params->length = args[offset + 6].As<Int32>()->Value();
CHECK_GE(params->length, 0);

ncrypto::MarkPopErrorOnReturn mark_pop_error_on_return;
if (!ncrypto::checkScryptParams(
params->N, params->r, params->p, params->maxmem)) {
// Do not use CryptoErrorStore or ThrowCryptoError here in order to maintain
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-crypto-scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if (!common.hasCrypto)

const assert = require('assert');
const crypto = require('crypto');
const fixtures = require('../common/fixtures');
const { hasFIPS, isBoringSSL } = require('../common/crypto');
const isFips = hasFIPS(3);

Expand Down Expand Up @@ -196,6 +197,19 @@ for (const options of toobig) {
expected);
}

// A failed parameter check must not leave an error on the OpenSSL error queue
// for the next unrelated crypto operation to pick up.
{
const key = fixtures.readKey('ec_p256_private.pem');
const options = { N: 2 ** 10, p: 1, r: 8, maxmem: 2 ** 20 };
const expected = { code: 'ERR_CRYPTO_INVALID_SCRYPT_PARAMS' };
assert.throws(() => crypto.scryptSync('pass', 'salt', 1, options), expected);
crypto.createPrivateKey(key);
assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
expected);
crypto.createPrivateKey(key);
}

if (!isFips) {
const expected = '4cac4540';
const actual = crypto.scryptSync('pass', 'salt', 4);
Expand Down
Loading