forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest-crypto-dh-leak.js
More file actions
29 lines (25 loc) · 897 Bytes
/
test-crypto-dh-leak.js
File metadata and controls
29 lines (25 loc) · 897 Bytes
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
27
28
29
// 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 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 << 21, `before=${before} after=${after}`);