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_ci
91cb0ef41Sopenharmony_ciconst size = common.hasFipsCrypto || common.hasOpenSSL3 ? 1024 : 256;
101cb0ef41Sopenharmony_ciconst dh1 = crypto.createDiffieHellman(size);
111cb0ef41Sopenharmony_ciconst p1 = dh1.getPrime('buffer');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci{
141cb0ef41Sopenharmony_ci  const DiffieHellman = crypto.DiffieHellman;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  const dh = DiffieHellman(p1, 'buffer');
171cb0ef41Sopenharmony_ci  assert(dh instanceof DiffieHellman, 'DiffieHellman is expected to return a ' +
181cb0ef41Sopenharmony_ci                                      'new instance when called without `new`');
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci{
221cb0ef41Sopenharmony_ci  const DiffieHellmanGroup = crypto.DiffieHellmanGroup;
231cb0ef41Sopenharmony_ci  const dhg = DiffieHellmanGroup('modp5');
241cb0ef41Sopenharmony_ci  assert(dhg instanceof DiffieHellmanGroup, 'DiffieHellmanGroup is expected ' +
251cb0ef41Sopenharmony_ci                                            'to return a new instance when ' +
261cb0ef41Sopenharmony_ci                                            'called without `new`');
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci{
301cb0ef41Sopenharmony_ci  const ECDH = crypto.ECDH;
311cb0ef41Sopenharmony_ci  const ecdh = ECDH('prime256v1');
321cb0ef41Sopenharmony_ci  assert(ecdh instanceof ECDH, 'ECDH is expected to return a new instance ' +
331cb0ef41Sopenharmony_ci                              'when called without `new`');
341cb0ef41Sopenharmony_ci}
35