Skip to content

Commit 7e07cce

Browse files
davidbenjuanarbol
authored andcommitted
crypto: use EVP_PKEY_CTX_set_dsa_paramgen_q_bits when available
This matches the formulation described in the documentation: https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_CTX_set_dsa_paramgen_q_bits.html It is also, starting OpenSSL 3.0, more type-safe because the wrapper macros were finally converted to real functions. In OpenSSL 3.0, it is also no longer quite a wrapper over EVP_PKEY_CTX_ctrl, so using this name saves some extra OSSL_PARAM <-> EVP_PKEY_CTRL conversions. Alas, it was only backported to OpenSSL 1.1.1e, so I've left a temporary compatibility define until you all decide to drop pre-1.1.1e releases of 1.1.1. PR-URL: #44561 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 5854abc commit 7e07cce

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/crypto/crypto_dsa.cc

+13-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212

1313
#include <cstdio>
1414

15+
// EVP_PKEY_CTX_set_dsa_paramgen_q_bits was added in OpenSSL 1.1.1e.
16+
#if OPENSSL_VERSION_NUMBER < 0x1010105fL
17+
#define EVP_PKEY_CTX_set_dsa_paramgen_q_bits(ctx, qbits) \
18+
EVP_PKEY_CTX_ctrl((ctx), \
19+
EVP_PKEY_DSA, \
20+
EVP_PKEY_OP_PARAMGEN, \
21+
EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, \
22+
(qbits), \
23+
nullptr)
24+
#endif
25+
1526
namespace node {
1627

1728
using v8::FunctionCallbackInfo;
@@ -39,13 +50,8 @@ EVPKeyCtxPointer DsaKeyGenTraits::Setup(DsaKeyPairGenConfig* params) {
3950
}
4051

4152
if (params->params.divisor_bits != -1) {
42-
if (EVP_PKEY_CTX_ctrl(
43-
param_ctx.get(),
44-
EVP_PKEY_DSA,
45-
EVP_PKEY_OP_PARAMGEN,
46-
EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS,
47-
params->params.divisor_bits,
48-
nullptr) <= 0) {
53+
if (EVP_PKEY_CTX_set_dsa_paramgen_q_bits(
54+
param_ctx.get(), params->params.divisor_bits) <= 0) {
4955
return EVPKeyCtxPointer();
5056
}
5157
}

0 commit comments

Comments
 (0)