Skip to content

Commit 7015823

Browse files
bpo-40695: Limit hashlib builtin hash fallback (GH-20259)
:mod:`hashlib` no longer falls back to builtin hash implementations when OpenSSL provides a hash digest and the algorithm is blocked by security policy. Signed-off-by: Christian Heimes <[email protected]> (cherry picked from commit 4cc2f93) Co-authored-by: Christian Heimes <[email protected]>
1 parent 82c274e commit 7015823

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Lib/hashlib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ def __get_openssl_constructor(name):
127127
# SHA3/shake are available in OpenSSL 1.1.1+
128128
f = getattr(_hashlib, 'openssl_' + name)
129129
# Allow the C module to raise ValueError. The function will be
130-
# defined but the hash not actually available thanks to OpenSSL.
131-
f()
130+
# defined but the hash not actually available. Don't fall back to
131+
# builtin if the current security policy blocks a digest, bpo#40695.
132+
f(usedforsecurity=False)
132133
# Use the C function directly (very fast)
133134
return f
134135
except (AttributeError, ValueError):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`hashlib` no longer falls back to builtin hash implementations when
2+
OpenSSL provides a hash digest and the algorithm is blocked by security
3+
policy.

0 commit comments

Comments
 (0)