summaryrefslogtreecommitdiffstats
path: root/Modules/_hashopenssl.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-03-23 20:30:05 (GMT)
committerGitHub <noreply@github.com>2022-03-23 20:30:05 (GMT)
commit48e2010d92076b472922fa632fffc98ee150004f (patch)
tree5a55659679517a6ab9c2170bac3cdb912314fee2 /Modules/_hashopenssl.c
parentc62b944dfc98911a5050389fa6ac753e283fee1f (diff)
downloadcpython-48e2010d92076b472922fa632fffc98ee150004f.zip
cpython-48e2010d92076b472922fa632fffc98ee150004f.tar.gz
cpython-48e2010d92076b472922fa632fffc98ee150004f.tar.bz2
bpo-47101: list only activated algorithms in hashlib.algorithms_available (GH-32076)
Diffstat (limited to 'Modules/_hashopenssl.c')
-rw-r--r--Modules/_hashopenssl.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index bb94872..203366e 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -1836,15 +1836,21 @@ typedef struct _internal_name_mapper_state {
/* 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)
+ // ignore all undefined providers
+ if ((md == NULL) || (EVP_MD_nid(md) == NID_undef)) {
return;
+ }
py_name = py_digest_name(md);
if (py_name == NULL) {
@@ -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);