xref: /third_party/node/test/parallel/test-crypto-dh-modp2-views.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
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_ci
101cb0ef41Sopenharmony_ciconst modp2 = crypto.createDiffieHellmanGroup('modp2');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst views = common.getArrayBufferViews(modp2buf);
131cb0ef41Sopenharmony_cifor (const buf of [modp2buf, ...views]) {
141cb0ef41Sopenharmony_ci  // Ensure specific generator (string with encoding) works as expected with
151cb0ef41Sopenharmony_ci  // any ArrayBufferViews as the first argument to createDiffieHellman().
161cb0ef41Sopenharmony_ci  const exmodp2 = crypto.createDiffieHellman(buf, '02', 'hex');
171cb0ef41Sopenharmony_ci  modp2.generateKeys();
181cb0ef41Sopenharmony_ci  exmodp2.generateKeys();
191cb0ef41Sopenharmony_ci  const modp2Secret = modp2.computeSecret(exmodp2.getPublicKey())
201cb0ef41Sopenharmony_ci      .toString('hex');
211cb0ef41Sopenharmony_ci  const exmodp2Secret = exmodp2.computeSecret(modp2.getPublicKey())
221cb0ef41Sopenharmony_ci      .toString('hex');
231cb0ef41Sopenharmony_ci  assert.strictEqual(modp2Secret, exmodp2Secret);
241cb0ef41Sopenharmony_ci}
25

Indexes created Thu Nov 07 10:32:03 CST 2024