@@ -63,10 +63,12 @@ def get_fips_mode():
6363
6464requires_blake2 = unittest .skipUnless (_blake2 , 'requires _blake2' )
6565
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' )
7072
7173
7274def hexstr (s ):
@@ -146,8 +148,6 @@ def __init__(self, *args, **kwargs):
146148
147149 self .constructors_to_test = {}
148150 for algorithm in algorithms :
149- if SKIP_SHA3 and algorithm .startswith ('sha3_' ):
150- continue
151151 self .constructors_to_test [algorithm ] = set ()
152152
153153 # For each algorithm, test the direct constructor and the use
@@ -194,20 +194,18 @@ def add_builtin_constructor(name):
194194 add_builtin_constructor ('sha256' )
195195 add_builtin_constructor ('sha384' )
196196 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' )
197205 if _blake2 :
198206 add_builtin_constructor ('blake2s' )
199207 add_builtin_constructor ('blake2b' )
200208
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-
211209 super (HashLibTestCase , self ).__init__ (* args , ** kwargs )
212210
213211 @property
0 commit comments