Skip to content

Commit

Permalink
hmac: use EVP_MD_CTX_get_pkey_ctx() instead of EVP_MD_CTX_pkey_ctx()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rhenium committed Oct 24, 2021
1 parent 0a25302 commit c106d88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions ext/openssl/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def find_openssl_library
have_func("SSL_CTX_load_verify_file")
have_func("BN_check_prime")
have_func("EVP_MD_CTX_get0_md")
have_func("EVP_MD_CTX_get_pkey_ctx")

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

Expand Down
16 changes: 12 additions & 4 deletions ext/openssl/openssl_missing.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
# define EVP_MD_CTX_free EVP_MD_CTX_destroy
#endif

#if !defined(HAVE_EVP_MD_CTX_PKEY_CTX)
# define EVP_MD_CTX_pkey_ctx(x) (x)->pctx
#endif

#if !defined(HAVE_X509_STORE_GET_EX_DATA)
# define X509_STORE_get_ex_data(x, idx) \
CRYPTO_get_ex_data(&(x)->ex_data, (idx))
Expand Down Expand Up @@ -223,4 +219,16 @@ IMPL_PKEY_GETTER(EC_KEY, ec)
# define EVP_MD_CTX_get0_md(ctx) EVP_MD_CTX_md(ctx)
#endif

/*
* OpenSSL 1.1.0 added EVP_MD_CTX_pkey_ctx(), and then it was renamed to
* EVP_MD_CTX_get_pkey_ctx(x) in OpenSSL 3.0.
*/
#ifndef HAVE_EVP_MD_CTX_GET_PKEY_CTX
# ifdef HAVE_EVP_MD_CTX_PKEY_CTX
# define EVP_MD_CTX_get_pkey_ctx(x) EVP_MD_CTX_pkey_ctx(x)
# else
# define EVP_MD_CTX_get_pkey_ctx(x) (x)->pctx
# endif
#endif

#endif /* _OSSL_OPENSSL_MISSING_H_ */
2 changes: 1 addition & 1 deletion ext/openssl/ossl_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ ossl_hmac_reset(VALUE self)
EVP_PKEY *pkey;

GetHMAC(self, ctx);
pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_pkey_ctx(ctx));
pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_get_pkey_ctx(ctx));
if (EVP_DigestSignInit(ctx, NULL, EVP_MD_CTX_get0_md(ctx), NULL, pkey) != 1)
ossl_raise(eHMACError, "EVP_DigestSignInit");

Expand Down

0 comments on commit c106d88

Please sign in to comment.