Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d26dedf

Browse filesBrowse files
panvaaduh95
authored andcommitted
src: refactor ECDHBitsJob signature
PR-URL: #55610 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent b79e483 commit d26dedf
Copy full SHA for d26dedf

File tree

Expand file treeCollapse file tree

5 files changed

+23
-27
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+23
-27
lines changed
Open diff view settings
Collapse file

‎lib/internal/crypto/diffiehellman.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/diffiehellman.js
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ async function ecdhDeriveBits(algorithm, baseKey, length) {
332332

333333
const bits = await jobPromise(() => new ECDHBitsJob(
334334
kCryptoJobAsync,
335-
key.algorithm.name === 'ECDH' ? baseKey.algorithm.namedCurve : baseKey.algorithm.name,
336335
key[kKeyObject][kHandle],
337336
baseKey[kKeyObject][kHandle]));
338337

Collapse file

‎src/crypto/crypto_ec.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_ec.cc
+5-25Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,6 @@ int GetCurveFromName(const char* name) {
4545
return nid;
4646
}
4747

48-
int GetOKPCurveFromName(const char* name) {
49-
int nid;
50-
if (strcmp(name, "Ed25519") == 0) {
51-
nid = EVP_PKEY_ED25519;
52-
} else if (strcmp(name, "Ed448") == 0) {
53-
nid = EVP_PKEY_ED448;
54-
} else if (strcmp(name, "X25519") == 0) {
55-
nid = EVP_PKEY_X25519;
56-
} else if (strcmp(name, "X448") == 0) {
57-
nid = EVP_PKEY_X448;
58-
} else {
59-
nid = NID_undef;
60-
}
61-
return nid;
62-
}
63-
6448
void ECDH::Initialize(Environment* env, Local<Object> target) {
6549
Isolate* isolate = env->isolate();
6650
Local<Context> context = env->context();
@@ -450,25 +434,21 @@ Maybe<void> ECDHBitsTraits::AdditionalConfig(
450434
ECDHBitsConfig* params) {
451435
Environment* env = Environment::GetCurrent(args);
452436

453-
CHECK(args[offset]->IsString()); // curve name
454-
CHECK(args[offset + 1]->IsObject()); // public key
455-
CHECK(args[offset + 2]->IsObject()); // private key
437+
CHECK(args[offset]->IsObject()); // public key
438+
CHECK(args[offset + 1]->IsObject()); // private key
456439

457440
KeyObjectHandle* private_key;
458441
KeyObjectHandle* public_key;
459442

460-
Utf8Value name(env->isolate(), args[offset]);
461-
462-
ASSIGN_OR_RETURN_UNWRAP(&public_key, args[offset + 1], Nothing<void>());
463-
ASSIGN_OR_RETURN_UNWRAP(&private_key, args[offset + 2], Nothing<void>());
443+
ASSIGN_OR_RETURN_UNWRAP(&public_key, args[offset], Nothing<void>());
444+
ASSIGN_OR_RETURN_UNWRAP(&private_key, args[offset + 1], Nothing<void>());
464445

465446
if (private_key->Data().GetKeyType() != kKeyTypePrivate ||
466447
public_key->Data().GetKeyType() != kKeyTypePublic) {
467448
THROW_ERR_CRYPTO_INVALID_KEYTYPE(env);
468449
return Nothing<void>();
469450
}
470451

471-
params->id_ = GetOKPCurveFromName(*name);
472452
params->private_ = private_key->Data().addRef();
473453
params->public_ = public_key->Data().addRef();
474454

@@ -482,7 +462,7 @@ bool ECDHBitsTraits::DeriveBits(Environment* env,
482462
const auto& m_privkey = params.private_.GetAsymmetricKey();
483463
const auto& m_pubkey = params.public_.GetAsymmetricKey();
484464

485-
switch (params.id_) {
465+
switch (m_privkey.id()) {
486466
case EVP_PKEY_X25519:
487467
// Fall through
488468
case EVP_PKEY_X448: {
Collapse file

‎src/crypto/crypto_ec.h‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_ec.h
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace node {
1717
namespace crypto {
1818
int GetCurveFromName(const char* name);
19-
int GetOKPCurveFromName(const char* name);
2019

2120
class ECDH final : public BaseObject {
2221
public:
Collapse file

‎src/crypto/crypto_keys.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_keys.cc
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,22 @@ void KeyObjectHandle::InitECRaw(const FunctionCallbackInfo<Value>& args) {
909909
args.GetReturnValue().Set(true);
910910
}
911911

912+
int GetOKPCurveFromName(const char* name) {
913+
int nid;
914+
if (strcmp(name, "Ed25519") == 0) {
915+
nid = EVP_PKEY_ED25519;
916+
} else if (strcmp(name, "Ed448") == 0) {
917+
nid = EVP_PKEY_ED448;
918+
} else if (strcmp(name, "X25519") == 0) {
919+
nid = EVP_PKEY_X25519;
920+
} else if (strcmp(name, "X448") == 0) {
921+
nid = EVP_PKEY_X448;
922+
} else {
923+
nid = NID_undef;
924+
}
925+
return nid;
926+
}
927+
912928
void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo<Value>& args) {
913929
Environment* env = Environment::GetCurrent(args);
914930
KeyObjectHandle* key;
Collapse file

‎src/crypto/crypto_keys.h‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_keys.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ WebCryptoKeyExportStatus PKEY_SPKI_Export(const KeyObjectData& key_data,
408408
WebCryptoKeyExportStatus PKEY_PKCS8_Export(const KeyObjectData& key_data,
409409
ByteSource* out);
410410

411+
int GetOKPCurveFromName(const char* name);
412+
411413
namespace Keys {
412414
void Initialize(Environment* env, v8::Local<v8::Object> target);
413415
void RegisterExternalReferences(ExternalReferenceRegistry* registry);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.