11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst crypto = require('crypto'); 81cb0ef41Sopenharmony_ciconst { modp2buf } = require('../common/crypto'); 91cb0ef41Sopenharmony_ciconst modp2 = crypto.createDiffieHellmanGroup('modp2'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci{ 121cb0ef41Sopenharmony_ci // Ensure specific generator (buffer) works as expected. 131cb0ef41Sopenharmony_ci const exmodp2 = crypto.createDiffieHellman(modp2buf, Buffer.from([2])); 141cb0ef41Sopenharmony_ci modp2.generateKeys(); 151cb0ef41Sopenharmony_ci exmodp2.generateKeys(); 161cb0ef41Sopenharmony_ci const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey()) 171cb0ef41Sopenharmony_ci .toString('hex'); 181cb0ef41Sopenharmony_ci const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey()) 191cb0ef41Sopenharmony_ci .toString('hex'); 201cb0ef41Sopenharmony_ci assert.strictEqual(modp2Secret, exmodp2Secret); 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci{ 241cb0ef41Sopenharmony_ci // Ensure specific generator (string without encoding) works as expected. 251cb0ef41Sopenharmony_ci const exmodp2 = crypto.createDiffieHellman(modp2buf, '\x02'); 261cb0ef41Sopenharmony_ci exmodp2.generateKeys(); 271cb0ef41Sopenharmony_ci const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey()) 281cb0ef41Sopenharmony_ci .toString('hex'); 291cb0ef41Sopenharmony_ci const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey()) 301cb0ef41Sopenharmony_ci .toString('hex'); 311cb0ef41Sopenharmony_ci assert.strictEqual(modp2Secret, exmodp2Secret); 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci{ 351cb0ef41Sopenharmony_ci // Ensure specific generator (numeric) works as expected. 361cb0ef41Sopenharmony_ci const exmodp2 = crypto.createDiffieHellman(modp2buf, 2); 371cb0ef41Sopenharmony_ci exmodp2.generateKeys(); 381cb0ef41Sopenharmony_ci const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey()) 391cb0ef41Sopenharmony_ci .toString('hex'); 401cb0ef41Sopenharmony_ci const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey()) 411cb0ef41Sopenharmony_ci .toString('hex'); 421cb0ef41Sopenharmony_ci assert.strictEqual(modp2Secret, exmodp2Secret); 431cb0ef41Sopenharmony_ci} 44