Skip to content

Commit f216699

Browse files
tniessenMylesBorins
authored andcommitted
crypto: remove DiffieHellman.initialised_
As pointed out by Ben Noordhuis, this internal field can be removed since all instances are initialized when exposed to users. PR-URL: #23717 Refs: #23648 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent d13bb2c commit f216699

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

src/node_crypto.cc

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,11 +4001,7 @@ bool DiffieHellman::Init(int primeLength, int g) {
40014001
dh_.reset(DH_new());
40024002
if (!DH_generate_parameters_ex(dh_.get(), primeLength, g, 0))
40034003
return false;
4004-
bool result = VerifyContext();
4005-
if (!result)
4006-
return false;
4007-
initialised_ = true;
4008-
return true;
4004+
return VerifyContext();
40094005
}
40104006

40114007

@@ -4020,11 +4016,7 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
40204016
BN_free(bn_g);
40214017
return false;
40224018
}
4023-
bool result = VerifyContext();
4024-
if (!result)
4025-
return false;
4026-
initialised_ = true;
4027-
return true;
4019+
return VerifyContext();
40284020
}
40294021

40304022

@@ -4037,11 +4029,7 @@ bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
40374029
BN_free(bn_g);
40384030
return false;
40394031
}
4040-
bool result = VerifyContext();
4041-
if (!result)
4042-
return false;
4043-
initialised_ = true;
4044-
return true;
4032+
return VerifyContext();
40454033
}
40464034

40474035

@@ -4115,7 +4103,6 @@ void DiffieHellman::GenerateKeys(const FunctionCallbackInfo<Value>& args) {
41154103

41164104
DiffieHellman* diffieHellman;
41174105
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4118-
CHECK(diffieHellman->initialised_);
41194106

41204107
if (!DH_generate_key(diffieHellman->dh_.get())) {
41214108
return ThrowCryptoError(env, ERR_get_error(), "Key generation failed");
@@ -4137,7 +4124,6 @@ void DiffieHellman::GetField(const FunctionCallbackInfo<Value>& args,
41374124

41384125
DiffieHellman* dh;
41394126
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4140-
CHECK(dh->initialised_);
41414127

41424128
const BIGNUM* num = get_field(dh->dh_.get());
41434129
if (num == nullptr) return env->ThrowError(err_if_null);
@@ -4189,7 +4175,6 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
41894175

41904176
DiffieHellman* diffieHellman;
41914177
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4192-
CHECK(diffieHellman->initialised_);
41934178

41944179
ClearErrorOnReturn clear_error_on_return;
41954180

@@ -4257,7 +4242,6 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<Value>& args,
42574242

42584243
DiffieHellman* dh;
42594244
ASSIGN_OR_RETURN_UNWRAP(&dh, args.Holder());
4260-
CHECK(dh->initialised_);
42614245

42624246
char errmsg[64];
42634247

@@ -4303,7 +4287,6 @@ void DiffieHellman::VerifyErrorGetter(const FunctionCallbackInfo<Value>& args) {
43034287

43044288
DiffieHellman* diffieHellman;
43054289
ASSIGN_OR_RETURN_UNWRAP(&diffieHellman, args.Holder());
4306-
CHECK(diffieHellman->initialised_);
43074290

43084291
args.GetReturnValue().Set(diffieHellman->verifyError_);
43094292
}

src/node_crypto.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ class DiffieHellman : public BaseObject {
615615

616616
DiffieHellman(Environment* env, v8::Local<v8::Object> wrap)
617617
: BaseObject(env, wrap),
618-
initialised_(false),
619618
verifyError_(0) {
620619
MakeWeak();
621620
}
@@ -633,7 +632,6 @@ class DiffieHellman : public BaseObject {
633632
int (*set_field)(DH*, BIGNUM*), const char* what);
634633
bool VerifyContext();
635634

636-
bool initialised_;
637635
int verifyError_;
638636
DHPointer dh_;
639637
};

0 commit comments

Comments
 (0)