@@ -62,10 +62,12 @@ def get_fips_mode():
6262
6363requires_blake2 = unittest .skipUnless (_blake2 , 'requires _blake2' )
6464
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' )
6971
7072
7173def hexstr (s ):
@@ -132,8 +134,6 @@ def __init__(self, *args, **kwargs):
132134
133135 self .constructors_to_test = {}
134136 for algorithm in algorithms :
135- if SKIP_SHA3 and algorithm .startswith ('sha3_' ):
136- continue
137137 self .constructors_to_test [algorithm ] = set ()
138138
139139 # For each algorithm, test the direct constructor and the use
@@ -180,20 +180,18 @@ def add_builtin_constructor(name):
180180 add_builtin_constructor ('sha256' )
181181 add_builtin_constructor ('sha384' )
182182 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' )
183191 if _blake2 :
184192 add_builtin_constructor ('blake2s' )
185193 add_builtin_constructor ('blake2b' )
186194
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-
197195 super (HashLibTestCase , self ).__init__ (* args , ** kwargs )
198196
199197 @property
0 commit comments