24
24
25
25
#include "Python.h"
26
26
#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
29
29
#include "hashlib.h"
30
30
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>
37
31
/* EVP is the preferred interface to hashing in OpenSSL */
38
32
#include <openssl/evp.h>
39
- #include <openssl/crypto.h> // FIPS_mode()
33
+ #include <openssl/crypto.h> // FIPS_mode()
40
34
/* We use the object interface to discover what hashes OpenSSL supports. */
41
35
#include <openssl/objects.h>
36
+ #include <openssl/err.h>
42
37
43
- #ifdef Py_HAS_OPENSSL3_SUPPORT
38
+ #include <stdbool.h>
39
+
40
+ #if OPENSSL_VERSION_NUMBER >= 0x30000000L
41
+ # define Py_HAS_OPENSSL3_SUPPORT
44
42
# include <openssl/core_names.h> // OSSL_MAC_PARAM_DIGEST
45
43
# include <openssl/params.h> // OSSL_PARAM_*()
46
44
#else
47
45
# include <openssl/hmac.h> // HMAC()
48
46
#endif
49
47
50
- #include <stdbool.h>
51
-
52
48
#ifndef OPENSSL_THREADS
53
49
# error "OPENSSL_THREADS is not defined, Python requires thread-safe OpenSSL"
54
50
#endif
73
69
74
70
#define PY_EVP_MD_CTX_md (CTX ) EVP_MD_CTX_get0_md(CTX)
75
71
76
- #define Py_HMAC_CTX_TYPE EVP_MAC_CTX
72
+ #define PY_HMAC_CTX_TYPE EVP_MAC_CTX
77
73
#define PY_HMAC_CTX_free EVP_MAC_CTX_free
78
74
#define PY_HMAC_update EVP_MAC_update
79
75
#else
84
80
85
81
#define PY_EVP_MD_CTX_md (CTX ) EVP_MD_CTX_md(CTX)
86
82
87
- #define Py_HMAC_CTX_TYPE HMAC_CTX
83
+ #define PY_HMAC_CTX_TYPE HMAC_CTX
88
84
#define PY_HMAC_CTX_free HMAC_CTX_free
89
85
#define PY_HMAC_update HMAC_Update
90
86
#endif
@@ -1975,7 +1971,7 @@ hashlib_HMAC_get_hashlib_digest_name(HMACobject *self)
1975
1971
}
1976
1972
1977
1973
static 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 )
1979
1975
{
1980
1976
if (!PY_HMAC_update (ctx , (const unsigned char * )v -> buf , (size_t )v -> len )) {
1981
1977
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)
1986
1982
1987
1983
/* Thin wrapper around PY_HMAC_CTX_free that allows to pass a NULL 'ctx'. */
1988
1984
static inline void
1989
- hashlib_openssl_HMAC_CTX_free (Py_HMAC_CTX_TYPE * ctx )
1985
+ hashlib_openssl_HMAC_CTX_free (PY_HMAC_CTX_TYPE * ctx )
1990
1986
{
1991
1987
/* The NULL check was not present in every OpenSSL versions. */
1992
1988
if (ctx ) {
@@ -2008,10 +2004,10 @@ hashlib_openssl_HMAC_update_with_lock(HMACobject *self, PyObject *data)
2008
2004
return r ;
2009
2005
}
2010
2006
2011
- static Py_HMAC_CTX_TYPE *
2007
+ static PY_HMAC_CTX_TYPE *
2012
2008
hashlib_openssl_HMAC_ctx_copy_with_lock (HMACobject * self )
2013
2009
{
2014
- Py_HMAC_CTX_TYPE * ctx = NULL ;
2010
+ PY_HMAC_CTX_TYPE * ctx = NULL ;
2015
2011
#ifdef Py_HAS_OPENSSL3_SUPPORT
2016
2012
HASHLIB_ACQUIRE_LOCK (self );
2017
2013
ctx = EVP_MAC_CTX_dup (self -> ctx );
@@ -2041,12 +2037,12 @@ hashlib_openssl_HMAC_ctx_copy_with_lock(HMACobject *self)
2041
2037
return NULL ;
2042
2038
}
2043
2039
2044
- static Py_HMAC_CTX_TYPE *
2040
+ static PY_HMAC_CTX_TYPE *
2045
2041
hashlib_HMAC_CTX_new_from_digestmod (_hashlibstate * state ,
2046
2042
Py_buffer * key , PyObject * digestmod ,
2047
2043
int * nid )
2048
2044
{
2049
- Py_HMAC_CTX_TYPE * ctx = NULL ;
2045
+ PY_HMAC_CTX_TYPE * ctx = NULL ;
2050
2046
PY_EVP_MD * md = NULL ;
2051
2047
int is_xof , r ;
2052
2048
#ifdef Py_HAS_OPENSSL3_SUPPORT
@@ -2149,7 +2145,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
2149
2145
/*[clinic end generated code: output=c20d9e4d9ed6d219 input=5f4071dcc7f34362]*/
2150
2146
{
2151
2147
_hashlibstate * state = get_hashlib_state (module );
2152
- Py_HMAC_CTX_TYPE * ctx = NULL ;
2148
+ PY_HMAC_CTX_TYPE * ctx = NULL ;
2153
2149
HMACobject * self = NULL ;
2154
2150
#ifdef Py_HAS_OPENSSL3_SUPPORT
2155
2151
int nid ;
@@ -2216,7 +2212,7 @@ _hashlib_HMAC_copy_impl(HMACobject *self)
2216
2212
/*[clinic end generated code: output=29aa28b452833127 input=e2fa6a05db61a4d6]*/
2217
2213
{
2218
2214
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 );
2220
2216
if (ctx == NULL ) {
2221
2217
return NULL ;
2222
2218
}
@@ -2322,7 +2318,7 @@ hashlib_openssl_HMAC_digest_compute(HMACobject *self, unsigned char *buf)
2322
2318
assert (PyErr_Occurred ());
2323
2319
return -1 ;
2324
2320
}
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 );
2326
2322
if (ctx == NULL ) {
2327
2323
return -1 ;
2328
2324
}
0 commit comments