mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
test: reuse fixed primes in DH tests
Use the modp14 prime instead of generating fresh parameters for tests of constructors, key setters, and memory retention. Keep generic DiffieHellman instances and the existing setter and leak assertions. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/65980 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
This commit is contained in:
3 files changed
+7
-14
No files matched your search
@@ -5,17 +5,14 @@ if (!common.hasCrypto)
|
||||
|
||||
const assert = require('assert');
|
||||
const crypto = require('crypto');
|
||||
const { hasOpenSSL, hasFIPS } = require('../common/crypto');
|
||||
const { hasFIPS } = require('../common/crypto');
|
||||
|
||||
const size = hasFIPS(3) ?
|
||||
2048 : (crypto.getFips() === 1 || hasOpenSSL(3) ? 1024 : 256);
|
||||
const dh1 = crypto.createDiffieHellman(size);
|
||||
const p1 = dh1.getPrime('buffer');
|
||||
const prime = crypto.getDiffieHellman('modp14').getPrime('buffer');
|
||||
|
||||
{
|
||||
const DiffieHellman = crypto.DiffieHellman;
|
||||
|
||||
const dh = DiffieHellman(p1, 'buffer');
|
||||
const dh = DiffieHellman(prime, 'buffer');
|
||||
assert(dh instanceof DiffieHellman, 'DiffieHellman is expected to return a ' +
|
||||
'new instance when called without `new`');
|
||||
}
|
||||
|
||||
@@ -6,11 +6,9 @@ if (!common.hasCrypto)
|
||||
|
||||
const assert = require('assert');
|
||||
const crypto = require('crypto');
|
||||
const { hasOpenSSL, hasFIPS } = require('../common/crypto');
|
||||
|
||||
{
|
||||
const size = hasFIPS(3) ?
|
||||
2048 : (crypto.getFips() === 1 || hasOpenSSL(3) ? 1024 : 256);
|
||||
const prime = crypto.getDiffieHellman('modp14').getPrime();
|
||||
|
||||
function unlessInvalidState(f) {
|
||||
try {
|
||||
@@ -23,7 +21,7 @@ const { hasOpenSSL, hasFIPS } = require('../common/crypto');
|
||||
}
|
||||
|
||||
function testGenerateKeysChangesKeys(setup, expected) {
|
||||
const dh = crypto.createDiffieHellman(size);
|
||||
const dh = crypto.createDiffieHellman(prime);
|
||||
setup(dh);
|
||||
const firstPublicKey = unlessInvalidState(() => dh.getPublicKey());
|
||||
const firstPrivateKey = unlessInvalidState(() => dh.getPrivateKey());
|
||||
|
||||
@@ -9,13 +9,11 @@ if (common.isASan)
|
||||
|
||||
const assert = require('assert');
|
||||
const crypto = require('crypto');
|
||||
const { hasOpenSSL, hasFIPS } = require('../common/crypto');
|
||||
|
||||
const before = process.memoryUsage.rss();
|
||||
{
|
||||
const size = hasFIPS(3) ?
|
||||
2048 : (crypto.getFips() === 1 || hasOpenSSL(3) ? 1024 : 256);
|
||||
const dh = crypto.createDiffieHellman(size);
|
||||
const prime = crypto.getDiffieHellman('modp14').getPrime();
|
||||
const dh = crypto.createDiffieHellman(prime);
|
||||
const publicKey = dh.generateKeys();
|
||||
const privateKey = dh.getPrivateKey();
|
||||
for (let i = 0; i < 5e4; i += 1) {
|
||||
|
||||
Reference in new issue
Block a user