Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v8.x backport] crypto: expose ECDH class #16245

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ function toBuf(str, encoding) {
}
exports._toBuf = toBuf;


const assert = require('assert');
const StringDecoder = require('string_decoder').StringDecoder;

Expand Down Expand Up @@ -559,17 +558,16 @@ DiffieHellman.prototype.setPrivateKey = function setPrivateKey(key, encoding) {
};


exports.createECDH = exports.ECDH = ECDH;
function ECDH(curve) {
if (!(this instanceof ECDH))
return new ECDH(curve);
if (typeof curve !== 'string')
throw new TypeError('"curve" argument should be a string');

this._handle = new binding.ECDH(curve);
}

exports.createECDH = function createECDH(curve) {
return new ECDH(curve);
};

ECDH.prototype.computeSecret = DiffieHellman.prototype.computeSecret;
ECDH.prototype.setPrivateKey = DiffieHellman.prototype.setPrivateKey;
ECDH.prototype.setPublicKey = DiffieHellman.prototype.setPublicKey;
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-crypto-classes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
const common = require('../common');
const assert = require('assert');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
const crypto = require('crypto');

// 'ClassName' : ['args', 'for', 'constructor']
const TEST_CASES = {
'Hash': ['sha1'],
'Hmac': ['sha1', 'Node'],
'Cipheriv': ['des-ede3-cbc', '0123456789abcd0123456789', '12345678'],
'Decipheriv': ['des-ede3-cbc', '0123456789abcd0123456789', '12345678'],
'Sign': ['RSA-SHA1'],
'Verify': ['RSA-SHA1'],
'DiffieHellman': [1024],
'DiffieHellmanGroup': ['modp5'],
'ECDH': ['prime256v1'],
'Credentials': []
};

if (!common.hasFipsCrypto) {
TEST_CASES.Cipher = ['aes192', 'secret'];
TEST_CASES.Decipher = ['aes192', 'secret'];
TEST_CASES.DiffieHellman = [256];
}

for (const [clazz, args] of Object.entries(TEST_CASES)) {
assert(crypto[`create${clazz}`](...args) instanceof crypto[clazz]);
}