Skip to content

gh-131876: extract _hashlib helpers into a separate directory #136995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update usage of hashlib.h
  • Loading branch information
picnixz committed Jul 22, 2025
commit 854bf43ebcc86a5a7726b3f0e60ea8fa3aab4efe
9 changes: 6 additions & 3 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
#include "pycore_hashtable.h"
#include "pycore_strhex.h" // _Py_strhex()
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_RELAXED
#include "hashlib.h"

#include "_hashlib/hashlib_buffer.h"
#include "_hashlib/hashlib_fetch.h"
#include "_hashlib/hashlib_mutex.h"

/* EVP is the preferred interface to hashing in OpenSSL */
#include <openssl/evp.h>
Expand Down Expand Up @@ -532,7 +535,7 @@ raise_unsupported_algorithm_error(_hashlibstate *state, PyObject *digestmod)
{
raise_unsupported_algorithm_impl(
state->unsupported_digestmod_error,
HASHLIB_UNSUPPORTED_ALGORITHM,
_Py_HASHLIB_UNSUPPORTED_ALGORITHM,
digestmod
);
}
Expand All @@ -542,7 +545,7 @@ raise_unsupported_str_algorithm_error(_hashlibstate *state, const char *name)
{
raise_unsupported_algorithm_impl(
state->unsupported_digestmod_error,
HASHLIB_UNSUPPORTED_STR_ALGORITHM,
_Py_HASHLIB_UNSUPPORTED_STR_ALGORITHM,
name
);
}
Expand Down
6 changes: 4 additions & 2 deletions Modules/blake2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
#endif

#include "Python.h"
#include "hashlib.h"
#include "pycore_moduleobject.h"
#include "pycore_strhex.h" // _Py_strhex()
#include "pycore_typeobject.h"
#include "pycore_moduleobject.h"

#include "_hashlib/hashlib_buffer.h"
#include "_hashlib/hashlib_mutex.h"

// QUICK CPU AUTODETECTION
//
Expand Down
8 changes: 5 additions & 3 deletions Modules/hmacmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "pycore_hashtable.h"
#include "pycore_strhex.h" // _Py_strhex()

#include "_hashlib/hashlib_buffer.h"
#include "_hashlib/hashlib_fetch.h"
#include "_hashlib/hashlib_mutex.h"

/*
* Taken from blake2module.c. In the future, detection of SIMD support
* should be delegated to https://github.com/python/cpython/pull/125011.
Expand Down Expand Up @@ -47,8 +51,6 @@

#include <stdbool.h>

#include "hashlib.h"

// --- Reusable error messages ------------------------------------------------

static inline void
Expand Down Expand Up @@ -656,7 +658,7 @@ find_hash_info(hmacmodule_state *state, PyObject *hash_info_ref)
}
if (rc == 0) {
PyErr_Format(state->unknown_hash_error,
HASHLIB_UNSUPPORTED_ALGORITHM, hash_info_ref);
_Py_HASHLIB_UNSUPPORTED_ALGORITHM, hash_info_ref);
return NULL;
}
assert(info != NULL);
Expand Down
3 changes: 2 additions & 1 deletion Modules/md5module.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include "Python.h"
#include "pycore_strhex.h" // _Py_strhex()

#include "hashlib.h"
#include "_hashlib/hashlib_buffer.h"
#include "_hashlib/hashlib_mutex.h"

#include "_hacl/Hacl_Hash_MD5.h"

Expand Down
4 changes: 3 additions & 1 deletion Modules/sha1module.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#endif

#include "Python.h"
#include "hashlib.h"
#include "pycore_strhex.h" // _Py_strhex()
#include "pycore_typeobject.h" // _PyType_GetModuleState()

#include "_hashlib/hashlib_buffer.h"
#include "_hashlib/hashlib_mutex.h"

#include "_hacl/Hacl_Hash_SHA1.h"

/* The SHA1 block size and message digest sizes, in bytes */
Expand Down
5 changes: 3 additions & 2 deletions Modules/sha2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

#include "Python.h"
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_typeobject.h" // _PyType_GetModuleState()
#include "pycore_strhex.h" // _Py_strhex()
#include "pycore_typeobject.h" // _PyType_GetModuleState()

#include "hashlib.h"
#include "_hashlib/hashlib_buffer.h"
#include "_hashlib/hashlib_mutex.h"

#include "_hacl/Hacl_Hash_SHA2.h"

Expand Down
4 changes: 3 additions & 1 deletion Modules/sha3module.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "Python.h"
#include "pycore_strhex.h" // _Py_strhex()
#include "pycore_typeobject.h" // _PyType_GetModuleState()
#include "hashlib.h"

#include "_hashlib/hashlib_buffer.h"
#include "_hashlib/hashlib_mutex.h"

#include "_hacl/Hacl_Hash_SHA3.h"

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy