Skip to content

Commit f26f278

Browse files
committed
crypto: use EVP_MD_fetch and cache EVP_MD for hashes
nodejs/node#51034
1 parent 64bb553 commit f26f278

3 files changed

+33
-9
lines changed

patches/node/feat_add_knostartdebugsignalhandler_to_environment_to_prevent.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ index 022f1507ce6a72d0ef140409efba476c7ef7825a..ac4295f495e240331a183b4a0a22d743
2222
// configure --no-browser-globals
2323
#ifdef NODE_NO_BROWSER_GLOBALS
2424
diff --git a/src/env.h b/src/env.h
25-
index 994b9573822fd3eb0588e87edaa0e505aa5102fb..dc4b3628a351aef0f3895dee07548df1dee29d91 100644
25+
index bb84f5ab43cb5be42019921e5dc2fc010d7b9018..f0a1d5ef2b45d4c27c5660177c9805acee19e5f2 100644
2626
--- a/src/env.h
2727
+++ b/src/env.h
2828
@@ -801,6 +801,7 @@ class Environment : public MemoryRetainer {

patches/node/fix_handle_boringssl_and_openssl_incompatibilities.patch

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ index 6e5bbe07d0c337b36f3157c2e6404fdc91849fd1..7ec682833213de9054a8c30751436d12
147147
DHPointer dh;
148148
{
149149
diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc
150-
index b4447102a8478639a5aa774e583834d79808603f..d3dad0ae8a9810e8481529776f4ed4686a8d9c53 100644
150+
index b4447102a8478639a5aa774e583834d79808603f..678be07feb394530b944c1b356265416f2d50742 100644
151151
--- a/src/crypto/crypto_dh.cc
152152
+++ b/src/crypto/crypto_dh.cc
153153
@@ -154,13 +154,11 @@ bool DiffieHellman::Init(BignumPointer&& bn_p, int g) {
@@ -166,7 +166,7 @@ index b4447102a8478639a5aa774e583834d79808603f..d3dad0ae8a9810e8481529776f4ed468
166166
return false;
167167
}
168168
BignumPointer bn_p(
169-
@@ -176,18 +174,17 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
169+
@@ -176,20 +174,17 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
170170
bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
171171
dh_.reset(DH_new());
172172
if (p_len <= 0) {
@@ -184,11 +184,13 @@ index b4447102a8478639a5aa774e583834d79808603f..d3dad0ae8a9810e8481529776f4ed468
184184
BignumPointer bn_g(
185185
BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, nullptr));
186186
if (BN_is_zero(bn_g.get()) || BN_is_one(bn_g.get())) {
187+
- ERR_put_error(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS,
188+
- DH_R_BAD_GENERATOR, __FILE__, __LINE__);
187189
+ OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
188-
ERR_put_error(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS,
189-
DH_R_BAD_GENERATOR, __FILE__, __LINE__);
190190
return false;
191-
@@ -219,8 +216,10 @@ typedef BignumPointer (*StandardizedGroupInstantiator)();
191+
}
192+
BignumPointer bn_p(
193+
@@ -219,8 +214,10 @@ typedef BignumPointer (*StandardizedGroupInstantiator)();
192194
inline StandardizedGroupInstantiator FindDiffieHellmanGroup(const char* name) {
193195
#define V(n, p) \
194196
if (StringEqualNoCase(name, n)) return InstantiateStandardizedGroup<p>
@@ -199,7 +201,7 @@ index b4447102a8478639a5aa774e583834d79808603f..d3dad0ae8a9810e8481529776f4ed468
199201
V("modp5", BN_get_rfc3526_prime_1536);
200202
V("modp14", BN_get_rfc3526_prime_2048);
201203
V("modp15", BN_get_rfc3526_prime_3072);
202-
@@ -559,15 +558,20 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
204+
@@ -559,15 +556,20 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
203205
return EVPKeyCtxPointer();
204206
}
205207

@@ -220,7 +222,7 @@ index b4447102a8478639a5aa774e583834d79808603f..d3dad0ae8a9810e8481529776f4ed468
220222
if (!param_ctx ||
221223
EVP_PKEY_paramgen_init(param_ctx.get()) <= 0 ||
222224
EVP_PKEY_CTX_set_dh_paramgen_prime_len(
223-
@@ -581,6 +585,9 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
225+
@@ -581,6 +583,9 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
224226
}
225227

226228
key_params = EVPKeyPointer(raw_params);
@@ -370,6 +372,28 @@ index 5734d8fdc5505e1586f571c19b840bd56e9c9f1f..3034b114e081e2b32dd5b71653927a41
370372
}
371373
} // namespace
372374

375+
diff --git a/src/env.h b/src/env.h
376+
index 994b9573822fd3eb0588e87edaa0e505aa5102fb..bb84f5ab43cb5be42019921e5dc2fc010d7b9018 100644
377+
--- a/src/env.h
378+
+++ b/src/env.h
379+
@@ -49,7 +49,7 @@
380+
#include "uv.h"
381+
#include "v8.h"
382+
383+
-#if HAVE_OPENSSL
384+
+#if HAVE_OPENSSL && OPENSSL_VERSION_MAJOR >= 3
385+
#include <openssl/evp.h>
386+
#endif
387+
388+
@@ -1032,7 +1032,7 @@ class Environment : public MemoryRetainer {
389+
kExitInfoFieldCount
390+
};
391+
392+
-#if HAVE_OPENSSL
393+
+#if HAVE_OPENSSL// && !defined(OPENSSL_IS_BORINGSSL)
394+
#if OPENSSL_VERSION_MAJOR >= 3
395+
// We declare another alias here to avoid having to include crypto_util.h
396+
using EVPMDPointer = DeleteFnPtr<EVP_MD, EVP_MD_free>;
373397
diff --git a/src/node.cc b/src/node.cc
374398
index 10e04ed8a28bd010e4887ad5b9af3886f7b32a53..012dd487e8db232d068bce358ad44b14e78d0fe9 100644
375399
--- a/src/node.cc

patches/node/src_preload_function_for_environment.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ index ac4295f495e240331a183b4a0a22d7437fc85271..63ce35ba68b48a55d8150395304bf86c
9292
async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] += 1;
9393
return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter];
9494
diff --git a/src/env.h b/src/env.h
95-
index dc4b3628a351aef0f3895dee07548df1dee29d91..3b3724d6c7156b87555be31470e75b1cf28b5e3f 100644
95+
index f0a1d5ef2b45d4c27c5660177c9805acee19e5f2..910c69b6d1d17ef25201dbb39d3d074f4f3f011f 100644
9696
--- a/src/env.h
9797
+++ b/src/env.h
9898
@@ -1003,6 +1003,9 @@ class Environment : public MemoryRetainer {

0 commit comments

Comments
 (0)