diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index 59bbf8ff71233c..410759414f635d 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -332,7 +332,6 @@ async function ecdhDeriveBits(algorithm, baseKey, length) { const bits = await jobPromise(() => new ECDHBitsJob( kCryptoJobAsync, - key.algorithm.name === 'ECDH' ? baseKey.algorithm.namedCurve : baseKey.algorithm.name, key[kKeyObject][kHandle], baseKey[kKeyObject][kHandle])); diff --git a/src/crypto/crypto_ec.cc b/src/crypto/crypto_ec.cc index 3942a52c142226..89b0dde2a59a03 100644 --- a/src/crypto/crypto_ec.cc +++ b/src/crypto/crypto_ec.cc @@ -45,22 +45,6 @@ int GetCurveFromName(const char* name) { return nid; } -int GetOKPCurveFromName(const char* name) { - int nid; - if (strcmp(name, "Ed25519") == 0) { - nid = EVP_PKEY_ED25519; - } else if (strcmp(name, "Ed448") == 0) { - nid = EVP_PKEY_ED448; - } else if (strcmp(name, "X25519") == 0) { - nid = EVP_PKEY_X25519; - } else if (strcmp(name, "X448") == 0) { - nid = EVP_PKEY_X448; - } else { - nid = NID_undef; - } - return nid; -} - void ECDH::Initialize(Environment* env, Local target) { Isolate* isolate = env->isolate(); Local context = env->context(); @@ -450,17 +434,14 @@ Maybe ECDHBitsTraits::AdditionalConfig( ECDHBitsConfig* params) { Environment* env = Environment::GetCurrent(args); - CHECK(args[offset]->IsString()); // curve name - CHECK(args[offset + 1]->IsObject()); // public key - CHECK(args[offset + 2]->IsObject()); // private key + CHECK(args[offset]->IsObject()); // public key + CHECK(args[offset + 1]->IsObject()); // private key KeyObjectHandle* private_key; KeyObjectHandle* public_key; - Utf8Value name(env->isolate(), args[offset]); - - ASSIGN_OR_RETURN_UNWRAP(&public_key, args[offset + 1], Nothing()); - ASSIGN_OR_RETURN_UNWRAP(&private_key, args[offset + 2], Nothing()); + ASSIGN_OR_RETURN_UNWRAP(&public_key, args[offset], Nothing()); + ASSIGN_OR_RETURN_UNWRAP(&private_key, args[offset + 1], Nothing()); if (private_key->Data().GetKeyType() != kKeyTypePrivate || public_key->Data().GetKeyType() != kKeyTypePublic) { @@ -468,7 +449,6 @@ Maybe ECDHBitsTraits::AdditionalConfig( return Nothing(); } - params->id_ = GetOKPCurveFromName(*name); params->private_ = private_key->Data().addRef(); params->public_ = public_key->Data().addRef(); @@ -482,7 +462,7 @@ bool ECDHBitsTraits::DeriveBits(Environment* env, const auto& m_privkey = params.private_.GetAsymmetricKey(); const auto& m_pubkey = params.public_.GetAsymmetricKey(); - switch (params.id_) { + switch (m_privkey.id()) { case EVP_PKEY_X25519: // Fall through case EVP_PKEY_X448: { diff --git a/src/crypto/crypto_ec.h b/src/crypto/crypto_ec.h index 49a87d1663e7ee..b5de681fbe1516 100644 --- a/src/crypto/crypto_ec.h +++ b/src/crypto/crypto_ec.h @@ -16,7 +16,6 @@ namespace node { namespace crypto { int GetCurveFromName(const char* name); -int GetOKPCurveFromName(const char* name); class ECDH final : public BaseObject { public: diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index 784180e90a8702..efd20cdb9452e3 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -909,6 +909,22 @@ void KeyObjectHandle::InitECRaw(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(true); } +int GetOKPCurveFromName(const char* name) { + int nid; + if (strcmp(name, "Ed25519") == 0) { + nid = EVP_PKEY_ED25519; + } else if (strcmp(name, "Ed448") == 0) { + nid = EVP_PKEY_ED448; + } else if (strcmp(name, "X25519") == 0) { + nid = EVP_PKEY_X25519; + } else if (strcmp(name, "X448") == 0) { + nid = EVP_PKEY_X448; + } else { + nid = NID_undef; + } + return nid; +} + void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); KeyObjectHandle* key; diff --git a/src/crypto/crypto_keys.h b/src/crypto/crypto_keys.h index fd7ff00b21c8e2..6d794b439b51ba 100644 --- a/src/crypto/crypto_keys.h +++ b/src/crypto/crypto_keys.h @@ -408,6 +408,8 @@ WebCryptoKeyExportStatus PKEY_SPKI_Export(const KeyObjectData& key_data, WebCryptoKeyExportStatus PKEY_PKCS8_Export(const KeyObjectData& key_data, ByteSource* out); +int GetOKPCurveFromName(const char* name); + namespace Keys { void Initialize(Environment* env, v8::Local target); void RegisterExternalReferences(ExternalReferenceRegistry* registry);