8000 bpo-47101: list only activated algorithms in hashlib.algorithms_available by tiran · Pull Request #32076 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-47101: list only activated algorithms in hashlib.algorithms_available #32076

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 3 commits into from
Mar 23, 2022
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
Next Next commit
bpo-47101: list only activated algorithms in hashlib.algorithms_avail…
…able
  • Loading branch information
tiran committed Mar 23, 2022
commit ef9ff7f4d2b4f6333ad39541a342420ff1b3cfb4
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:const:`hashlib.algorithms_available` now lists only algorithms that are
provided by activated crypto providers on OpenSSL 3.0. Legacy algorithms are
not listed unless the legacy provider has been loaded into the default
OSSL context.
13 changes: 12 additions & 1 deletion Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1831,20 +1831,26 @@ PyType_Spec HMACtype_spec = {
typedef struct _internal_name_mapper_state {
PyObject *set;
int error;
PyObject *undefined;
} _InternalNameMapperState;


/* A callback function to pass to OpenSSL's OBJ_NAME_do_all(...) */
static void
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
_openssl_hash_name_mapper(EVP_MD *md, void *arg)
#else
_openssl_hash_name_mapper(const EVP_MD *md, const char *from,
const char *to, void *arg)
#endif
{
_InternalNameMapperState *state = (_InternalNameMapperState *)arg;
PyObject *py_name;

assert(state != NULL);
if (md == NULL)
if ((md == NULL) || (EVP_MD_nid(md) == NID_undef)) {
return;
}

py_name = py_digest_name(md);
if (py_name == NULL) {
Expand All @@ -1870,7 +1876,12 @@ hashlib_md_meth_names(PyObject *module)
return -1;
}

#if OPENSSL_VERSION_NUMBER >= 0x30000000L
// get algorithms from all activated providers in default context
EVP_MD_do_all_provided(NULL, &_openssl_hash_name_mapper, &state);
#else
EVP_MD_do_all(&_openssl_hash_name_mapper, &state);
#endif

if (state.error) {
Py_DECREF(state.set);
Expand Down
0