@@ -63,10 +63,12 @@ def get_fips_mode():
63
63
64
64
requires_blake2 = unittest .skipUnless (_blake2 , 'requires _blake2' )
65
65
66
- # bpo-46913: Don't test the _sha3 extension on a Python UBSAN build
67
- # TODO(gh-99108): Revisit this after _sha3 uses HACL*.
68
- SKIP_SHA3 = support .check_sanitizer (ub = True )
69
- requires_sha3 = unittest .skipUnless (not SKIP_SHA3 , 'requires _sha3' )
66
+ try :
67
+ import _sha3
68
+ except ImportError :
69
+ _sha3 = None
70
+
71
+ requires_sha3 = unittest .skipUnless (_sha3 , 'requires _sha3' )
70
72
71
73
72
74
def hexstr (s ):
@@ -146,8 +148,6 @@ def __init__(self, *args, **kwargs):
146
148
147
149
self .constructors_to_test = {}
148
150
for algorithm in algorithms :
149
- if SKIP_SHA3 and algorithm .startswith ('sha3_' ):
150
- continue
151
151
self .constructors_to_test [algorithm ] = set ()
152
152
153
153
# For each algorithm, test the direct constructor and the use
@@ -194,20 +194,18 @@ def add_builtin_constructor(name):
194
194
add_builtin_constructor ('sha256' )
195
195
add_builtin_constructor ('sha384' )
196
196
add_builtin_constructor ('sha512' )
197
+ _sha3 = self ._conditional_import_module ('_sha3' )
198
+ if _sha3 :
199
+ add_builtin_constructor ('sha3_224' )
200
+ add_builtin_constructor ('sha3_256' )
201
+ add_builtin_constructor ('sha3_384' )
202
+ add_builtin_constructor ('sha3_512' )
203
+ add_builtin_constructor ('shake_128' )
204
+ add_builtin_constructor ('shake_256' )
197
205
if _blake2 :
198
206
add_builtin_constructor ('blake2s' )
199
207
add_builtin_constructor ('blake2b' )
200
208
201
- if not SKIP_SHA3 :
202
- _sha3 = self ._conditional_import_module ('_sha3' )
203
- if _sha3 :
204
- add_builtin_constructor ('sha3_224' )
205
- add_builtin_constructor ('sha3_256' )
206
- add_builtin_constructor ('sha3_384' )
207
- add_builtin_constructor ('sha3_512' )
208
- add_builtin_constructor ('shake_128' )
209
- add_builtin_constructor ('shake_256' )
210
-
211
209
super (HashLibTestCase , self ).__init__ (* args , ** kwargs )
212
210
213
211
@property
0 commit comments