Skip to content

gh-91069: do not disable sha3 in test_hashlib under UBSan #133001

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 1 commit into from
Apr 27, 2025
Merged
Changes from all commits
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
30 changes: 14 additions & 16 deletions Lib/test/test_hashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ def get_fips_mode():

requires_blake2 = unittest.skipUnless(_blake2, 'requires _blake2')

# bpo-46913: Don't test the _sha3 extension on a Python UBSAN build
# TODO(gh-99108): Revisit this after _sha3 uses HACL*.
SKIP_SHA3 = support.check_sanitizer(ub=True)
requires_sha3 = unittest.skipUnless(not SKIP_SHA3, 'requires _sha3')
try:
import _sha3
except ImportError:
_sha3 = None

requires_sha3 = unittest.skipUnless(_sha3, 'requires _sha3')


def hexstr(s):
Expand Down Expand Up @@ -132,8 +134,6 @@ def __init__(self, *args, **kwargs):

self.constructors_to_test = {}
for algorithm in algorithms:
if SKIP_SHA3 and algorithm.startswith('sha3_'):
continue
self.constructors_to_test[algorithm] = set()

# For each algorithm, test the direct constructor and the use
Expand Down Expand Up @@ -180,20 +180,18 @@ def add_builtin_constructor(name):
add_builtin_constructor('sha256')
add_builtin_constructor('sha384')
add_builtin_constructor('sha512')
_sha3 = self._conditional_import_module('_sha3')
if _sha3:
add_builtin_constructor('sha3_224')
add_builtin_constructor('sha3_256')
add_builtin_constructor('sha3_384')
add_builtin_constructor('sha3_512')
add_builtin_constructor('shake_128')
add_builtin_constructor('shake_256')
if _blake2:
add_builtin_constructor('blake2s')
add_builtin_constructor('blake2b')

if not SKIP_SHA3:
_sha3 = self._conditional_import_module('_sha3')
if _sha3:
add_builtin_constructor('sha3_224')
add_builtin_constructor('sha3_256')
add_builtin_constructor('sha3_384')
add_builtin_constructor('sha3_512')
add_builtin_constructor('shake_128')
add_builtin_constructor('shake_256')

super(HashLibTestCase, self).__init__(*args, **kwargs)

@property
Expand Down
Loading