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

crypto: expose ECDH class #8188

Closed
wants to merge 2 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
7 changes: 2 additions & 5 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ const {
} = require('internal/crypto/util');
const Certificate = require('internal/crypto/certificate');

function createECDH(curve) {
return new ECDH(curve);
}

module.exports = exports = {
// Methods
_toBuf: toBuf,
Expand All @@ -92,7 +88,7 @@ module.exports = exports = {
createDecipheriv: Decipheriv,
createDiffieHellman: DiffieHellman,
createDiffieHellmanGroup: DiffieHellmanGroup,
createECDH,
createECDH: ECDH,
createHash: Hash,
createHmac: Hmac,
createSign: Sign,
Expand Down Expand Up @@ -124,6 +120,7 @@ module.exports = exports = {
Decipheriv,
DiffieHellman,
DiffieHellmanGroup,
ECDH,
Hash,
Hmac,
Sign,
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/crypto/diffiehellman.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ DiffieHellman.prototype.setPrivateKey = function setPrivateKey(key, encoding) {


function ECDH(curve) {
if (!(this instanceof ECDH))
return new ECDH(curve);

if (typeof curve !== 'string')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'curve', 'string');

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

if (!common.hasCrypto) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fips fail: # Error: crypto.createCipher() is not supported in FIPS mode.

You probably want to add a check against common.hasFipsCrypto

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'];
}

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