node/test/parallel/test-crypto-dh-leak.js
Daniel Bevenius 640fe94354 src,test: support dynamically linking OpenSSL 3.0
This commit enables node to dynamically link against OpenSSL 3.0.

The motivation for opening this PR even though OpenSSL 3.0 has not been
released yet is to allow a nightly CI job to be created. This will
allow us stay on top of changes required for OpenSSL 3.0, and also to
make sure that changes to node crypto do not cause issues when linking
to OpenSSL 3.0.

PR-URL: https://github.com/nodejs/node/pull/37669
Refs: https://github.com/nodejs/node/issues/29817
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2021-03-16 05:59:25 +01:00

30 lines
913 B
JavaScript

// Flags: --expose-gc --noconcurrent_recompilation
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (process.config.variables.asan)
common.skip('ASAN messes with memory measurements');
const assert = require('assert');
const crypto = require('crypto');
const before = process.memoryUsage.rss();
{
const size = common.hasFipsCrypto || common.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 << 20, `before=${before} after=${after}`);