diff --git a/ext/node/ops/crypto/mod.rs b/ext/node/ops/crypto/mod.rs index f66a3a1804a581..abdf14052dc9c1 100644 --- a/ext/node/ops/crypto/mod.rs +++ b/ext/node/ops/crypto/mod.rs @@ -571,7 +571,7 @@ fn scrypt( parallelization, keylen as usize, ) - .unwrap(); + .map_err(|_| JsErrorBox::generic("scrypt params construction failed"))?; // Call into scrypt let res = scrypt::scrypt(&password, &salt, ¶ms, output_buffer); diff --git a/ext/node/polyfills/internal/crypto/scrypt.ts b/ext/node/polyfills/internal/crypto/scrypt.ts index e20ad330110951..2ad88747ca2761 100644 --- a/ext/node/polyfills/internal/crypto/scrypt.ts +++ b/ext/node/polyfills/internal/crypto/scrypt.ts @@ -107,23 +107,19 @@ export function scrypt( throw new Error("exceeds max memory"); } - try { - op_node_scrypt_async( - password, - salt, - keylen, - Math.log2(N), - r, - p, - maxmem, - ).then( - (buf: Uint8Array) => { - cb(null, Buffer.from(buf.buffer)); - }, - ); - } catch (err: unknown) { - return cb(err); - } + op_node_scrypt_async( + password, + salt, + keylen, + Math.log2(N), + r, + p, + maxmem, + ).then( + (buf: Uint8Array) => { + cb(null, Buffer.from(buf.buffer)); + }, + ).catch((err: unknown) => cb(err)); } export default { diff --git a/tests/unit_node/crypto/crypto_scrypt_test.ts b/tests/unit_node/crypto/crypto_scrypt_test.ts index 3f4d1437f02df7..967c77e4a2bea9 100644 --- a/tests/unit_node/crypto/crypto_scrypt_test.ts +++ b/tests/unit_node/crypto/crypto_scrypt_test.ts @@ -188,3 +188,13 @@ Deno.test("scryptSync with options works correctly", () => { ]), ); }); + +Deno.test("log_n > 64 doesn't panic", async () => { + const { promise, resolve } = Promise.withResolvers(); + + scrypt("password", "salt", 128, () => { + resolve(); + }); + + await promise; +});