2424
2525#include "Python.h"
2626#include "pycore_hashtable.h"
27- #include "pycore_strhex.h" // _Py_strhex()
28- #include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_RELAXED
27+ #include "pycore_strhex.h" // _Py_strhex()
28+ #include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_RELAXED
2929#include "hashlib.h"
3030
31- #include <openssl/opensslv.h>
32- #if OPENSSL_VERSION_NUMBER >= 0x30000000L
33- # define Py_HAS_OPENSSL3_SUPPORT
34- #endif
35-
36- #include <openssl/err.h>
3731/* EVP is the preferred interface to hashing in OpenSSL */
3832#include <openssl/evp.h>
39- #include <openssl/crypto.h> // FIPS_mode()
33+ #include <openssl/crypto.h> // FIPS_mode()
4034/* We use the object interface to discover what hashes OpenSSL supports. */
4135#include <openssl/objects.h>
36+ #include <openssl/err.h>
4237
43- #ifdef Py_HAS_OPENSSL3_SUPPORT
38+ #include <stdbool.h>
39+
40+ #if OPENSSL_VERSION_NUMBER >= 0x30000000L
41+ # define Py_HAS_OPENSSL3_SUPPORT
4442# include <openssl/core_names.h> // OSSL_MAC_PARAM_DIGEST
4543# include <openssl/params.h> // OSSL_PARAM_*()
4644#else
4745# include <openssl/hmac.h> // HMAC()
4846#endif
4947
50- #include <stdbool.h>
51-
5248#ifndef OPENSSL_THREADS
5349# error "OPENSSL_THREADS is not defined, Python requires thread-safe OpenSSL"
5450#endif
7369
7470#define PY_EVP_MD_CTX_md (CTX ) EVP_MD_CTX_get0_md(CTX)
7571
76- #define Py_HMAC_CTX_TYPE EVP_MAC_CTX
72+ #define PY_HMAC_CTX_TYPE EVP_MAC_CTX
7773#define PY_HMAC_CTX_free EVP_MAC_CTX_free
7874#define PY_HMAC_update EVP_MAC_update
7975#else
8480
8581#define PY_EVP_MD_CTX_md (CTX ) EVP_MD_CTX_md(CTX)
8682
87- #define Py_HMAC_CTX_TYPE HMAC_CTX
83+ #define PY_HMAC_CTX_TYPE HMAC_CTX
8884#define PY_HMAC_CTX_free HMAC_CTX_free
8985#define PY_HMAC_update HMAC_Update
9086#endif
@@ -1975,7 +1971,7 @@ hashlib_HMAC_get_hashlib_digest_name(HMACobject *self)
19751971}
19761972
19771973static int
1978- hashlib_openssl_HMAC_update_once (Py_HMAC_CTX_TYPE * ctx , const Py_buffer * v )
1974+ hashlib_openssl_HMAC_update_once (PY_HMAC_CTX_TYPE * ctx , const Py_buffer * v )
19791975{
19801976 if (!PY_HMAC_update (ctx , (const unsigned char * )v -> buf , (size_t )v -> len )) {
19811977 notify_smart_ssl_error_occurred_in (Py_STRINGIFY (PY_HMAC_update ));
@@ -1986,7 +1982,7 @@ hashlib_openssl_HMAC_update_once(Py_HMAC_CTX_TYPE *ctx, const Py_buffer *v)
19861982
19871983/* Thin wrapper around PY_HMAC_CTX_free that allows to pass a NULL 'ctx'. */
19881984static inline void
1989- hashlib_openssl_HMAC_CTX_free (Py_HMAC_CTX_TYPE * ctx )
1985+ hashlib_openssl_HMAC_CTX_free (PY_HMAC_CTX_TYPE * ctx )
19901986{
19911987 /* The NULL check was not present in every OpenSSL versions. */
19921988 if (ctx ) {
@@ -2008,10 +2004,10 @@ hashlib_openssl_HMAC_update_with_lock(HMACobject *self, PyObject *data)
20082004 return r ;
20092005}
20102006
2011- static Py_HMAC_CTX_TYPE *
2007+ static PY_HMAC_CTX_TYPE *
20122008hashlib_openssl_HMAC_ctx_copy_with_lock (HMACobject * self )
20132009{
2014- Py_HMAC_CTX_TYPE * ctx = NULL ;
2010+ PY_HMAC_CTX_TYPE * ctx = NULL ;
20152011#ifdef Py_HAS_OPENSSL3_SUPPORT
20162012 HASHLIB_ACQUIRE_LOCK (self );
20172013 ctx = EVP_MAC_CTX_dup (self -> ctx );
@@ -2041,12 +2037,12 @@ hashlib_openssl_HMAC_ctx_copy_with_lock(HMACobject *self)
20412037 return NULL ;
20422038}
20432039
2044- static Py_HMAC_CTX_TYPE *
2040+ static PY_HMAC_CTX_TYPE *
20452041hashlib_HMAC_CTX_new_from_digestmod (_hashlibstate * state ,
20462042 Py_buffer * key , PyObject * digestmod ,
20472043 int * nid )
20482044{
2049- Py_HMAC_CTX_TYPE * ctx = NULL ;
2045+ PY_HMAC_CTX_TYPE * ctx = NULL ;
20502046 PY_EVP_MD * md = NULL ;
20512047 int is_xof , r ;
20522048#ifdef Py_HAS_OPENSSL3_SUPPORT
@@ -2149,7 +2145,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
21492145/*[clinic end generated code: output=c20d9e4d9ed6d219 input=5f4071dcc7f34362]*/
21502146{
21512147 _hashlibstate * state = get_hashlib_state (module );
2152- Py_HMAC_CTX_TYPE * ctx = NULL ;
2148+ PY_HMAC_CTX_TYPE * ctx = NULL ;
21532149 HMACobject * self = NULL ;
21542150#ifdef Py_HAS_OPENSSL3_SUPPORT
21552151 int nid ;
@@ -2216,7 +2212,7 @@ _hashlib_HMAC_copy_impl(HMACobject *self)
22162212/*[clinic end generated code: output=29aa28b452833127 input=e2fa6a05db61a4d6]*/
22172213{
22182214 HMACobject * retval ;
2219- Py_HMAC_CTX_TYPE * ctx = hashlib_openssl_HMAC_ctx_copy_with_lock (self );
2215+ PY_HMAC_CTX_TYPE * ctx = hashlib_openssl_HMAC_ctx_copy_with_lock (self );
22202216 if (ctx == NULL ) {
22212217 return NULL ;
22222218 }
@@ -2322,7 +2318,7 @@ hashlib_openssl_HMAC_digest_compute(HMACobject *self, unsigned char *buf)
23222318 assert (PyErr_Occurred ());
23232319 return -1 ;
23242320 }
2325- Py_HMAC_CTX_TYPE * ctx = hashlib_openssl_HMAC_ctx_copy_with_lock (self );
2321+ PY_HMAC_CTX_TYPE * ctx = hashlib_openssl_HMAC_ctx_copy_with_lock (self );
23262322 if (ctx == NULL ) {
23272323 return -1 ;
23282324 }
0 commit comments