Skip to content

Commit

Permalink
feat(node/crypto): Builtin Diffie-Hellman Groups (#19137)
Browse files Browse the repository at this point in the history
Towards #18455
  • Loading branch information
levex committed May 18, 2023
1 parent b15cc76 commit 4df46b7
Show file tree
Hide file tree
Showing 6 changed files with 900 additions and 31 deletions.
1 change: 1 addition & 0 deletions cli/tests/node_compat/config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"test-console-sync-write-error.js",
"test-console-table.js",
"test-console-tty-colors.js",
"test-crypto-dh-shared.js",
"test-crypto-dh.js",
"test-crypto-hkdf.js",
"test-crypto-hmac.js",
Expand Down
22 changes: 22 additions & 0 deletions cli/tests/node_compat/test/parallel/test-crypto-dh-shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const crypto = require('crypto');

const alice = crypto.createDiffieHellmanGroup('modp5');
const bob = crypto.createDiffieHellmanGroup('modp5');
alice.generateKeys();
bob.generateKeys();
const aSecret = alice.computeSecret(bob.getPublicKey()).toString('hex');
const bSecret = bob.computeSecret(alice.getPublicKey()).toString('hex');
assert.strictEqual(aSecret, bSecret);
26 changes: 13 additions & 13 deletions cli/tests/node_compat/test/parallel/test-crypto-dh.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,21 @@ if (false) {
message: 'The "curve" argument must be of type string. ' +
'Received undefined'
});

assert.throws(
function() {
crypto.getDiffieHellman('unknown-group');
},
{
name: 'Error',
code: 'ERR_CRYPTO_UNKNOWN_DH_GROUP',
message: 'Unknown DH group'
},
'crypto.getDiffieHellman(\'unknown-group\') ' +
'failed to throw the expected error.'
);
}

assert.throws(
function() {
crypto.getDiffieHellman('unknown-group');
},
{
name: 'Error',
code: 'ERR_CRYPTO_UNKNOWN_DH_GROUP',
message: 'Unknown DH group'
},
'crypto.getDiffieHellman(\'unknown-group\') ' +
'failed to throw the expected error.'
);

assert.throws(
() => crypto.createDiffieHellman('', true),
{
Expand Down
Loading

0 comments on commit 4df46b7

Please sign in to comment.