summaryrefslogtreecommitdiff
path: root/test/parallel/test-crypto-dh-leak.js
blob: 9ba8d29e155dc6b0bdaed4017c6ac899ff6d0591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Flags: --expose-gc --noconcurrent_recompilation
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');

const assert = require('assert');
const crypto = require('crypto');

const before = process.memoryUsage().rss;
{
  const dh = crypto.createDiffieHellman(common.hasFipsCrypto ? 1024 : 256);
  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}`);