mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
Since `common/crypto` already exists, it makes sense to keep crypto-related utilities there. The only exception being common.hasCrypto which is needed up front to determine if tests should be skipped. Eliminate the redundant check in hasFipsCrypto and just use crypto.getFips() directly where needed. PR-URL: https://github.com/nodejs/node/pull/56714 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
31 lines
939 B
JavaScript
31 lines
939 B
JavaScript
// Flags: --expose-gc --noconcurrent_recompilation
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
if (common.isASan)
|
|
common.skip('ASan messes with memory measurements');
|
|
|
|
const assert = require('assert');
|
|
const crypto = require('crypto');
|
|
const { hasOpenSSL3 } = require('../common/crypto');
|
|
|
|
const before = process.memoryUsage.rss();
|
|
{
|
|
const size = crypto.getFips() || hasOpenSSL3 ? 1024 : 256;
|
|
const dh = crypto.createDiffieHellman(size);
|
|
const publicKey = dh.generateKeys();
|
|
const privateKey = dh.getPrivateKey();
|
|
for (let i = 0; i < 5e4; i += 1) {
|
|
dh.setPublicKey(publicKey);
|
|
dh.setPrivateKey(privateKey);
|
|
}
|
|
}
|
|
global.gc();
|
|
const after = process.memoryUsage.rss();
|
|
|
|
// RSS should stay the same, ceteris paribus, but allow for
|
|
// some slop because V8 mallocs memory during execution.
|
|
assert(after - before < 10 << 21, `before=${before} after=${after}`);
|