1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5
6const assert = require('assert');
7const crypto = require('crypto');
8const { modp2buf } = require('../common/crypto');
9const modp2 = crypto.createDiffieHellmanGroup('modp2');
10
11{
12  // Ensure specific generator (buffer) works as expected.
13  const exmodp2 = crypto.createDiffieHellman(modp2buf, Buffer.from([2]));
14  modp2.generateKeys();
15  exmodp2.generateKeys();
16  const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey())
17      .toString('hex');
18  const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
19      .toString('hex');
20  assert.strictEqual(modp2Secret, exmodp2Secret);
21}
22
23{
24  // Ensure specific generator (string without encoding) works as expected.
25  const exmodp2 = crypto.createDiffieHellman(modp2buf, '\x02');
26  exmodp2.generateKeys();
27  const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey())
28      .toString('hex');
29  const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
30      .toString('hex');
31  assert.strictEqual(modp2Secret, exmodp2Secret);
32}
33
34{
35  // Ensure specific generator (numeric) works as expected.
36  const exmodp2 = crypto.createDiffieHellman(modp2buf, 2);
37  exmodp2.generateKeys();
38  const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey())
39      .toString('hex');
40  const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
41      .toString('hex');
42  assert.strictEqual(modp2Secret, exmodp2Secret);
43}
44