diff --git a/lib/internal/crypto/scrypt.js b/lib/internal/crypto/scrypt.js index 458723df28ffca..45a04905bfd447 100644 --- a/lib/internal/crypto/scrypt.js +++ b/lib/internal/crypto/scrypt.js @@ -16,6 +16,7 @@ const { const { validateCallback, validateInteger, + validateInt32, validateUint32, } = require('internal/validators'); @@ -90,7 +91,7 @@ function check(password, salt, keylen, options) { password = getArrayBufferOrView(password, 'password'); salt = getArrayBufferOrView(salt, 'salt'); - validateUint32(keylen, 'keylen'); + validateInt32(keylen, 'keylen', 0); let { N, r, p, maxmem } = defaults; if (options && options !== defaults) { diff --git a/test/parallel/test-crypto-scrypt.js b/test/parallel/test-crypto-scrypt.js index 9db69646bbfb0a..7b695a36f2b5a4 100644 --- a/test/parallel/test-crypto-scrypt.js +++ b/test/parallel/test-crypto-scrypt.js @@ -143,6 +143,10 @@ const badargs = [ args: ['', '', -42], expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ }, }, + { + args: ['', '', 2147485780], + expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ }, + }, ]; for (const options of good) {