forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-crypto-dh-modp2-views.js
More file actions
28 lines (24 loc) · 985 Bytes
/
test-crypto-dh-modp2-views.js
File metadata and controls
28 lines (24 loc) · 985 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
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const { modp2buf } = require('../common/crypto');
if (process.features.openssl_is_boringssl) {
common.skip('Skipping unsupported Diffie-Hellman tests');
}
const modp2 = crypto.createDiffieHellmanGroup('modp2');
const views = common.getArrayBufferViews(modp2buf);
for (const buf of [modp2buf, ...views]) {
// Ensure specific generator (string with encoding) works as expected with
// any ArrayBufferViews as the first argument to createDiffieHellman().
const exmodp2 = crypto.createDiffieHellman(buf, '02', 'hex');
modp2.generateKeys();
exmodp2.generateKeys();
const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey())
.toString('hex');
const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
.toString('hex');
assert.strictEqual(modp2Secret, exmodp2Secret);
}