@@ -128,12 +128,22 @@ def __get_openssl_constructor(name):
128128 # Prefer our builtin blake2 implementation.
129129 return __get_builtin_constructor (name )
130130 try :
131- # MD5, SHA1, and SHA2 are in all supported OpenSSL versions
132- # SHA3/shake are available in OpenSSL 1.1.1+
131+ # Fetch the OpenSSL hash function if it exists,
132+ # independently of the context security policy.
133133 f = getattr (_hashlib , 'openssl_' + name )
134- # Allow the C module to raise ValueError. The function will be
135- # defined but the hash not actually available. Don't fall back to
136- # builtin if the current security policy blocks a digest, bpo#40695.
134+ # Check if the context security policy blocks the digest or not
135+ # by allowing the C module to raise a ValueError. The function
136+ # will be defined but the hash will not be available at runtime.
137+ #
138+ # We use "usedforsecurity=False" to prevent falling back to the
139+ # built-in function in case the security policy does not allow it.
140+ #
141+ # Note that this only affects the explicit named constructors,
142+ # and not the algorithms exposed through hashlib.new() which
143+ # can still be resolved to a built-in function even if the
144+ # current security policy does not allow it.
145+ #
146+ # See https://github.com/python/cpython/issues/84872.
137147 f (usedforsecurity = False )
138148 # Use the C function directly (very fast)
139149 return f
0 commit comments