-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135571: Guard _hashlib usage in test_hashlib.py #135572
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
base: main
Are you sure you want to change the base?
gh-135571: Guard _hashlib usage in test_hashlib.py #135572
Conversation
Lib/test/test_hashlib.py
Outdated
# when using a combination of libcrypto and interned hash | ||
# implementations, we need to make sure that _hashlib contains | ||
# the constructor we're testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# when using a combination of libcrypto and interned hash | |
# implementations, we need to make sure that _hashlib contains | |
# the constructor we're testing | |
# Make sure that _hashlib contains the constructor | |
# to test when using a combination of libcrypto and | |
# interned hash implementations. |
By "interned" hash implementations, do you mean HACL* implementations or others? because hash_constructors
should actually only contain the the constructors that are "correct"?
Also, I think you can use _hashlib.algorithms_available
instead of _constructors
, but I don't remember well now. I'm leaving so I won't be able to review more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By "interned" hash implementations, do you mean HACL* implementations or others?
I'm not sure which are HACL and which are not, but by "interned" I mean all the hash functions that use source in CPython's tree for hash implementations instead of a linking to libcrypto.
because
hash_constructors
should actually only contain the the constructors that are "correct"
In PR #135402, I observed hash_constructors
containing blake2b
/blake2s
constructors while _hashlib
did not, causing failures when this test tried to invoke it.
Also, I think you can use
_hashlib.algorithms_available
instead of_constructors
Hm, I don't see an algorithms_available
attr of _hashlib
:
$ ./python
Python 3.15.0a0 (heads/add-awslc-ci-job-dirty:be1b72c13b2, Jun 12 2025, 15:30:29) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.OPENSSL_VERSION
'AWS-LC 1.52.1'
>>> import _hashlib
>>> dir(_hashlib)
['HASH', 'HASHXOF', 'HMAC', 'UnsupportedDigestmodError', '_GIL_MINSIZE', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_constructors', 'compare_digest', 'get_fips_mode', 'hmac_digest', 'hmac_new', 'new', 'openssl_md5', 'openssl_md_meth_names', 'openssl_sha1', 'openssl_sha224', 'openssl_sha256', 'openssl_sha384', 'openssl_sha3_224', 'openssl_sha3_256', 'openssl_sha3_384', 'openssl_sha3_512', 'openssl_sha512', 'openssl_shake_128', 'openssl_shake_256', 'pbkdf2_hmac', 'scrypt']
>>> _hashlib.algorithms_available
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
_hashlib.algorithms_available
AttributeError: module '_hashlib' has no attribute 'algorithms_available'
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Notes
See here.
Testing
See here.