Skip to content

Commit ebbd6d8

Browse files
committed
update usage of hashlib.h
1 parent 487c4b8 commit ebbd6d8

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

Modules/_hashopenssl.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
#include "pycore_hashtable.h"
2727
#include "pycore_strhex.h" // _Py_strhex()
2828
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_RELAXED
29-
#include "hashlib.h"
29+
30+
#include "_hashlib/hashlib_buffer.h"
31+
#include "_hashlib/hashlib_fetch.h"
32+
#include "_hashlib/hashlib_mutex.h"
3033

3134
/* EVP is the preferred interface to hashing in OpenSSL */
3235
#include <openssl/evp.h>
@@ -532,7 +535,7 @@ raise_unsupported_algorithm_error(_hashlibstate *state, PyObject *digestmod)
532535
{
533536
raise_unsupported_algorithm_impl(
534537
state->unsupported_digestmod_error,
535-
HASHLIB_UNSUPPORTED_ALGORITHM,
538+
_Py_HASHLIB_UNSUPPORTED_ALGORITHM,
536539
digestmod
537540
);
538541
}
@@ -542,7 +545,7 @@ raise_unsupported_str_algorithm_error(_hashlibstate *state, const char *name)
542545
{
543546
raise_unsupported_algorithm_impl(
544547
state->unsupported_digestmod_error,
545-
HASHLIB_UNSUPPORTED_STR_ALGORITHM,
548+
_Py_HASHLIB_UNSUPPORTED_STR_ALGORITHM,
546549
name
547550
);
548551
}

Modules/blake2module.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
#endif
1616

1717
#include "Python.h"
18-
#include "hashlib.h"
18+
#include "pycore_moduleobject.h"
1919
#include "pycore_strhex.h" // _Py_strhex()
2020
#include "pycore_typeobject.h"
21-
#include "pycore_moduleobject.h"
21+
22+
#include "_hashlib/hashlib_buffer.h"
23+
#include "_hashlib/hashlib_mutex.h"
2224

2325
// QUICK CPU AUTODETECTION
2426
//

Modules/hmacmodule.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include "pycore_hashtable.h"
2121
#include "pycore_strhex.h" // _Py_strhex()
2222

23+
#include "_hashlib/hashlib_buffer.h"
24+
#include "_hashlib/hashlib_fetch.h"
25+
#include "_hashlib/hashlib_mutex.h"
26+
2327
/*
2428
* Taken from blake2module.c. In the future, detection of SIMD support
2529
* should be delegated to https://github.com/python/cpython/pull/125011.
@@ -47,8 +51,6 @@
4751

4852
#include <stdbool.h>
4953

50-
#include "hashlib.h"
51-
5254
// --- Reusable error messages ------------------------------------------------
5355

5456
static inline void
@@ -656,7 +658,7 @@ find_hash_info(hmacmodule_state *state, PyObject *hash_info_ref)
656658
}
657659
if (rc == 0) {
658660
PyErr_Format(state->unknown_hash_error,
659-
HASHLIB_UNSUPPORTED_ALGORITHM, hash_info_ref);
661+
_Py_HASHLIB_UNSUPPORTED_ALGORITHM, hash_info_ref);
660662
return NULL;
661663
}
662664
assert(info != NULL);

Modules/md5module.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include "Python.h"
2525
#include "pycore_strhex.h" // _Py_strhex()
2626

27-
#include "hashlib.h"
27+
#include "_hashlib/hashlib_buffer.h"
28+
#include "_hashlib/hashlib_mutex.h"
2829

2930
#include "_hacl/Hacl_Hash_MD5.h"
3031

Modules/sha1module.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
#endif
2121

2222
#include "Python.h"
23-
#include "hashlib.h"
2423
#include "pycore_strhex.h" // _Py_strhex()
2524
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2625

26+
#include "_hashlib/hashlib_buffer.h"
27+
#include "_hashlib/hashlib_mutex.h"
28+
2729
#include "_hacl/Hacl_Hash_SHA1.h"
2830

2931
/* The SHA1 block size and message digest sizes, in bytes */

Modules/sha2module.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
#include "Python.h"
2424
#include "pycore_moduleobject.h" // _PyModule_GetState()
25-
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2625
#include "pycore_strhex.h" // _Py_strhex()
26+
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2727

28-
#include "hashlib.h"
28+
#include "_hashlib/hashlib_buffer.h"
29+
#include "_hashlib/hashlib_mutex.h"
2930

3031
#include "_hacl/Hacl_Hash_SHA2.h"
3132

Modules/sha3module.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#include "Python.h"
2424
#include "pycore_strhex.h" // _Py_strhex()
2525
#include "pycore_typeobject.h" // _PyType_GetModuleState()
26-
#include "hashlib.h"
26+
27+
#include "_hashlib/hashlib_buffer.h"
28+
#include "_hashlib/hashlib_mutex.h"
2729

2830
#include "_hacl/Hacl_Hash_SHA3.h"
2931

0 commit comments

Comments
 (0)