Skip to content
Open
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
37 changes: 0 additions & 37 deletions lib/internal/crypto/diffiehellman.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const {
FunctionPrototypeCall,
MathCeil,
ObjectDefineProperty,
SafeSet,
TypedArrayPrototypeGetBuffer,
Uint8Array,
} = primordials;
Expand All @@ -26,10 +25,7 @@ const {
codes: {
ERR_CRYPTO_ECDH_INVALID_FORMAT,
ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY,
ERR_CRYPTO_INCOMPATIBLE_KEY,
ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
},
} = require('internal/errors');

Expand All @@ -51,7 +47,6 @@ const {
} = require('internal/util');

const {
isKeyObject,
kAlgorithm,
kKeyType,
preparePrivateKey,
Expand Down Expand Up @@ -276,8 +271,6 @@ function getFormat(format) {
return POINT_CONVERSION_UNCOMPRESSED;
}

const dhEnabledKeyTypes = new SafeSet(['dh', 'ec', 'x448', 'x25519']);

function diffieHellman(options, callback) {
validateObject(options, 'options');

Expand All @@ -286,36 +279,6 @@ function diffieHellman(options, callback) {

const { privateKey, publicKey } = options;

// TODO(@panva): remove these non-semver-major error code preserving measures
// in a semver-major followup, the final state is just preparePublicOrPrivateKey
// and preparePrivateKey
if (privateKey == null)
throw new ERR_INVALID_ARG_VALUE('options.privateKey', privateKey);

if (publicKey == null)
throw new ERR_INVALID_ARG_VALUE('options.publicKey', publicKey);

if (isKeyObject(privateKey)) {
if (privateKey.type !== 'private')
throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(privateKey.type, 'private');
}

if (isKeyObject(publicKey)) {
if (publicKey.type !== 'public' && publicKey.type !== 'private') {
throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(publicKey.type,
'private or public');
}
}

if (isKeyObject(privateKey) && isKeyObject(publicKey)) {
const privateType = privateKey.asymmetricKeyType;
const publicType = publicKey.asymmetricKeyType;
if (privateType !== publicType || !dhEnabledKeyTypes.has(privateType)) {
throw new ERR_CRYPTO_INCOMPATIBLE_KEY('key types for Diffie-Hellman',
`${privateType} and ${publicType}`);
}
}

const {
data: pubData,
format: pubFormat,
Expand Down
Loading
Loading