Skip to content

Commit dde51f3

Browse files
committed
lib: cleanup stateless diffiehellman key handling
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
1 parent e6ef477 commit dde51f3

File tree

3 files changed

+271
-564
lines changed

3 files changed

+271
-564
lines changed

lib/internal/crypto/diffiehellman.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const {
55
FunctionPrototypeCall,
66
MathCeil,
77
ObjectDefineProperty,
8-
SafeSet,
98
TypedArrayPrototypeGetBuffer,
109
Uint8Array,
1110
} = primordials;
@@ -26,10 +25,7 @@ const {
2625
codes: {
2726
ERR_CRYPTO_ECDH_INVALID_FORMAT,
2827
ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY,
29-
ERR_CRYPTO_INCOMPATIBLE_KEY,
30-
ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE,
3128
ERR_INVALID_ARG_TYPE,
32-
ERR_INVALID_ARG_VALUE,
3329
},
3430
} = require('internal/errors');
3531

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

5349
const {
54-
isKeyObject,
5550
kAlgorithm,
5651
kKeyType,
5752
preparePrivateKey,
@@ -276,8 +271,6 @@ function getFormat(format) {
276271
return POINT_CONVERSION_UNCOMPRESSED;
277272
}
278273

279-
const dhEnabledKeyTypes = new SafeSet(['dh', 'ec', 'x448', 'x25519']);
280-
281274
function diffieHellman(options, callback) {
282275
validateObject(options, 'options');
283276

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

287280
const { privateKey, publicKey } = options;
288281

289-
// TODO(@panva): remove these non-semver-major error code preserving measures
290-
// in a semver-major followup, the final state is just preparePublicOrPrivateKey
291-
// and preparePrivateKey
292-
if (privateKey == null)
293-
throw new ERR_INVALID_ARG_VALUE('options.privateKey', privateKey);
294-
295-
if (publicKey == null)
296-
throw new ERR_INVALID_ARG_VALUE('options.publicKey', publicKey);
297-
298-
if (isKeyObject(privateKey)) {
299-
if (privateKey.type !== 'private')
300-
throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(privateKey.type, 'private');
301-
}
302-
303-
if (isKeyObject(publicKey)) {
304-
if (publicKey.type !== 'public' && publicKey.type !== 'private') {
305-
throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(publicKey.type,
306-
'private or public');
307-
}
308-
}
309-
310-
if (isKeyObject(privateKey) && isKeyObject(publicKey)) {
311-
const privateType = privateKey.asymmetricKeyType;
312-
const publicType = publicKey.asymmetricKeyType;
313-
if (privateType !== publicType || !dhEnabledKeyTypes.has(privateType)) {
314-
throw new ERR_CRYPTO_INCOMPATIBLE_KEY('key types for Diffie-Hellman',
315-
`${privateType} and ${publicType}`);
316-
}
317-
}
318-
319282
const {
320283
data: pubData,
321284
format: pubFormat,

0 commit comments

Comments
 (0)