Skip to content
Prev Previous commit
Next Next commit
test: use named parameters in DH stress test
Named modp14 parameters avoid generating and repeatedly validating a
custom prime. Keep the existing exchange counts and FIPS rejection
assertion. The separate deterministic padding test continues to cover
imported prime parameters.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
  • Loading branch information
panva committed Sep 11, 2026
commit 638fb885a33036a9741f50a5bcd8a0643506fa36
19 changes: 5 additions & 14 deletions test/pummel/test-dh-regr.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,23 @@ if (common.isPi()) {

const assert = require('assert');
const crypto = require('crypto');
const { hasOpenSSL, hasFIPS } = require('../common/crypto');
const { hasFIPS } = require('../common/crypto');

let p;
let iterations = 2000;
if (hasFIPS(3)) {
assert.throws(() => crypto.createDiffieHellman(1024), {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
});

// Use a precomputed approved group instead of generating a 2048-bit prime
// for every test run. Its larger keys also make each pummel iteration more
// expensive, so use enough iterations to exercise the regression without
// making the FIPS job excessively slow.
p = crypto.getDiffieHellman('modp14').getPrime();
// Keep a lower iteration count for FIPS jobs.
iterations = 100;
} else {
// FIPS requires length >= 1024, but small parameters keep this pummel test
// from timing out in ordinary CI.
const length = crypto.getFips() === 1 ? 1024 : (hasOpenSSL(3) ? 512 : 256);
p = crypto.createDiffieHellman(length).getPrime();
}

for (let i = 0; i < iterations; i++) {
const a = crypto.createDiffieHellman(p);
const b = crypto.createDiffieHellman(p);
// A named group avoids generating and validating custom parameters.
const a = crypto.getDiffieHellman('modp14');
const b = crypto.getDiffieHellman('modp14');

a.generateKeys();
b.generateKeys();
Expand Down