Skip to content

Commit 0c33595

Browse files
committed
hmac: use EVP_MD_CTX_get_pkey_ctx() instead of EVP_MD_CTX_pkey_ctx()
OpenSSL 3.0 renamed EVP_MD_CTX_pkey_ctx() to include "get" in the function name. Adjust compatibility macro so that we can use the new function name for all OpenSSL 1.0.2-3.0.
1 parent ff2b653 commit 0c33595

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

ext/openssl/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def find_openssl_library
177177
have_func("SSL_CTX_load_verify_file")
178178
have_func("BN_check_prime")
179179
have_func("EVP_MD_CTX_get0_md")
180+
have_func("EVP_MD_CTX_get_pkey_ctx")
180181

181182
Logging::message "=== Checking done. ===\n"
182183

ext/openssl/openssl_missing.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
# define EVP_MD_CTX_free EVP_MD_CTX_destroy
2222
#endif
2323

24-
#if !defined(HAVE_EVP_MD_CTX_PKEY_CTX)
25-
# define EVP_MD_CTX_pkey_ctx(x) (x)->pctx
26-
#endif
27-
2824
#if !defined(HAVE_X509_STORE_GET_EX_DATA)
2925
# define X509_STORE_get_ex_data(x, idx) \
3026
CRYPTO_get_ex_data(&(x)->ex_data, (idx))
@@ -223,4 +219,16 @@ IMPL_PKEY_GETTER(EC_KEY, ec)
223219
# define EVP_MD_CTX_get0_md(ctx) EVP_MD_CTX_md(ctx)
224220
#endif
225221

222+
/*
223+
* OpenSSL 1.1.0 added EVP_MD_CTX_pkey_ctx(), and then it was renamed to
224+
* EVP_MD_CTX_get_pkey_ctx(x) in OpenSSL 3.0.
225+
*/
226+
#ifndef HAVE_EVP_MD_CTX_GET_PKEY_CTX
227+
# ifdef HAVE_EVP_MD_CTX_PKEY_CTX
228+
# define EVP_MD_CTX_get_pkey_ctx(x) EVP_MD_CTX_pkey_ctx(x)
229+
# else
230+
# define EVP_MD_CTX_get_pkey_ctx(x) (x)->pctx
231+
# endif
232+
#endif
233+
226234
#endif /* _OSSL_OPENSSL_MISSING_H_ */

ext/openssl/ossl_hmac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ ossl_hmac_reset(VALUE self)
238238
EVP_PKEY *pkey;
239239

240240
GetHMAC(self, ctx);
241-
pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_pkey_ctx(ctx));
241+
pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_get_pkey_ctx(ctx));
242242
if (EVP_DigestSignInit(ctx, NULL, EVP_MD_CTX_get0_md(ctx), NULL, pkey) != 1)
243243
ossl_raise(eHMACError, "EVP_DigestSignInit");
244244

0 commit comments

Comments
 (0)