node-scrypt
node-scrypt copied to clipboard
Error: computing derived key - Invalid argument
I've got a usage of scrypt that was failing at random. Here is the method definition:
// Uses scrypt to hash the master password with a known salt to be
// used as the master key
function generateMasterKey (password, salt, len) {
const scryptParams = scrypt.paramsSync(0.5)
console.log(password, scryptParams, len, salt)
return scrypt.hashSync(password, scryptParams, len, salt)
}
Typically the scryptParams would output at { N: 16, r: 8, p: 1 }, and it would work. But 0-50% of the time, the N would differ by one or two (eg it would be 15) and that would cause the error in my title.
Running on node 6.2.1 on MacOS 10.12.1. My theory is that it's an issue with floating-point precision, assuming that N is not supposed to ever be 15. Any thoughts?
I just had scrypt.paramsSync(1) and also got hit by this.
node v10.11.0 on macOS 10.14.0