@@ -62,10 +62,12 @@ def get_fips_mode():
62
62
63
63
requires_blake2 = unittest .skipUnless (_blake2 , 'requires _blake2' )
64
64
65
- # bpo-46913: Don't test the _sha3 extension on a Python UBSAN build
66
- # TODO(gh-99108): Revisit this after _sha3 uses HACL*.
67
- SKIP_SHA3 = support .check_sanitizer (ub = True )
68
- requires_sha3 = unittest .skipUnless (not SKIP_SHA3 , 'requires _sha3' )
65
+ try :
66
+ import _sha3
67
+ except ImportError :
68
+ _sha3 = None
69
+
70
+ requires_sha3 = unittest .skipUnless (_sha3 , 'requires _sha3' )
69
71
70
72
71
73
def hexstr (s ):
@@ -132,8 +134,6 @@ def __init__(self, *args, **kwargs):
132
134
133
135
self .constructors_to_test = {}
134
136
for algorithm in algorithms :
135
- if SKIP_SHA3 and algorithm .startswith ('sha3_' ):
136
- continue
137
137
self .constructors_to_test [algorithm ] = set ()
138
138
139
139
# For each algorithm, test the direct constructor and the use
@@ -180,20 +180,18 @@ def add_builtin_constructor(name):
180
180
add_builtin_constructor ('sha256' )
181
181
add_builtin_constructor ('sha384' )
182
182
add_builtin_constructor ('sha512' )
183
+ _sha3 = self ._conditional_import_module ('_sha3' )
184
+ if _sha3 :
185
+ add_builtin_constructor ('sha3_224' )
186
+ add_builtin_constructor ('sha3_256' )
187
+ add_builtin_constructor ('sha3_384' )
188
+ add_builtin_constructor ('sha3_512' )
189
+ add_builtin_constructor ('shake_128' )
190
+ add_builtin_constructor ('shake_256' )
183
191
if _blake2 :
184
192
add_builtin_constructor ('blake2s' )
185
193
add_builtin_constructor ('blake2b' )
186
194
187
- if not SKIP_SHA3 :
188
- _sha3 = self ._conditional_import_module ('_sha3' )
189
- if _sha3 :
190
- add_builtin_constructor ('sha3_224' )
191
- add_builtin_constructor ('sha3_256' )
192
- add_builtin_constructor ('sha3_384' )
193
- add_builtin_constructor ('sha3_512' )
194
- add_builtin_constructor ('shake_128' )
195
- add_builtin_constructor ('shake_256' )
196
-
197
195
super (HashLibTestCase , self ).__init__ (* args , ** kwargs )
198
196
199
197
@property
0 commit comments