diff --git a/ext/node/polyfills/internal/crypto/diffiehellman.ts b/ext/node/polyfills/internal/crypto/diffiehellman.ts index 27e53f8ed6..40080800ba 100644 --- a/ext/node/polyfills/internal/crypto/diffiehellman.ts +++ b/ext/node/polyfills/internal/crypto/diffiehellman.ts @@ -117,7 +117,10 @@ export class DiffieHellmanImpl { // The supplied parameter is our primeLength, generate a suitable prime. this.#primeLength = sizeOrKey as number; if (this.#primeLength < 2) { - throw new NodeError("ERR_OSSL_BN_BITS_TOO_SMALL", "bits too small"); + throw new NodeError( + "ERR_OSSL_DH_MODULUS_TOO_SMALL", + "modulus too small", + ); } this.#prime = Buffer.from( diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc index ccb643b536..c6dcba07a7 100644 --- a/tests/node_compat/config.jsonc +++ b/tests/node_compat/config.jsonc @@ -43,7 +43,6 @@ "test-console-formatTime.js", "test-console-instance.js", "test-console-tty-colors.js", - "test-crypto-dh-errors.js", "test-crypto-hash.js", "test-crypto-hkdf.js", "test-crypto-hmac.js", diff --git a/tests/node_compat/test/parallel/test-crypto-dh-errors.js b/tests/node_compat/test/parallel/test-crypto-dh-errors.js index 73224a715c..2267e58aa2 100644 --- a/tests/node_compat/test/parallel/test-crypto-dh-errors.js +++ b/tests/node_compat/test/parallel/test-crypto-dh-errors.js @@ -2,7 +2,7 @@ // deno-lint-ignore-file // Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 20.11.1 +// Taken from Node 23.9.0 // This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. 'use strict'; @@ -12,6 +12,7 @@ if (!common.hasCrypto) const assert = require('assert'); const crypto = require('crypto'); +const { hasOpenSSL3 } = require('../common/crypto'); // https://github.com/nodejs/node/issues/32738 // XXX(bnoordhuis) validateInt32() throwing ERR_OUT_OF_RANGE and RangeError @@ -31,7 +32,7 @@ assert.throws(() => crypto.createDiffieHellman('abcdef', 13.37), { }); for (const bits of [-1, 0, 1]) { - if (common.hasOpenSSL3) { + if (hasOpenSSL3) { assert.throws(() => crypto.createDiffieHellman(bits), { code: 'ERR_OSSL_DH_MODULUS_TOO_SMALL', name: 'Error', @@ -50,7 +51,7 @@ for (const g of [-1, 1]) { const ex = { code: 'ERR_OSSL_DH_BAD_GENERATOR', name: 'Error', - message: /bad generator/, + message: /(?:bad[_ ]generator)/i, }; assert.throws(() => crypto.createDiffieHellman('abcdef', g), ex); assert.throws(() => crypto.createDiffieHellman('abcdef', 'hex', g), ex); @@ -62,7 +63,7 @@ for (const g of [Buffer.from([]), const ex = { code: 'ERR_OSSL_DH_BAD_GENERATOR', name: 'Error', - message: /bad generator/, + message: /(?:bad[_ ]generator)/i, }; assert.throws(() => crypto.createDiffieHellman('abcdef', g), ex); assert.throws(() => crypto.createDiffieHellman('abcdef', 'hex', g), ex);