@@ -467,19 +467,25 @@ def _iter_hash_func_info(excluded):
467467# Mapping from canonical hash names to their explicit HACL* HMAC constructor.
468468# There is currently no OpenSSL one-shot named function and there will likely
469469# be none in the future.
470- _EXPLICIT_HMAC_CONSTRUCTORS = {
471- HashId (name ): f"_hmac.compute_{ name } "
472- for name in CANONICAL_DIGEST_NAMES
470+ _HMACINFO_DATABASE = {
471+ HashId (canonical_name ): _HashInfoItem ( f"_hmac.compute_{ canonical_name } " )
472+ for canonical_name in CANONICAL_DIGEST_NAMES
473473}
474474# Neither HACL* nor OpenSSL supports HMAC over XOFs.
475- _EXPLICIT_HMAC_CONSTRUCTORS [HashId .shake_128 ] = None
476- _EXPLICIT_HMAC_CONSTRUCTORS [HashId .shake_256 ] = None
475+ _HMACINFO_DATABASE [HashId .shake_128 ] = _HashInfoItem ()
476+ _HMACINFO_DATABASE [HashId .shake_256 ] = _HashInfoItem ()
477477# Strictly speaking, HMAC-BLAKE is meaningless as BLAKE2 is already a
478478# keyed hash function. However, as it's exposed by HACL*, we test it.
479- _EXPLICIT_HMAC_CONSTRUCTORS [HashId .blake2s ] = '_hmac.compute_blake2s_32'
480- _EXPLICIT_HMAC_CONSTRUCTORS [HashId .blake2b ] = '_hmac.compute_blake2b_32'
481- _EXPLICIT_HMAC_CONSTRUCTORS = MappingProxyType (_EXPLICIT_HMAC_CONSTRUCTORS )
482- assert _EXPLICIT_HMAC_CONSTRUCTORS .keys () == CANONICAL_DIGEST_NAMES
479+ _HMACINFO_DATABASE [HashId .blake2s ] = _HashInfoItem ('_hmac.compute_blake2s_32' )
480+ _HMACINFO_DATABASE [HashId .blake2b ] = _HashInfoItem ('_hmac.compute_blake2b_32' )
481+ _HMACINFO_DATABASE = MappingProxyType (_HMACINFO_DATABASE )
482+ assert _HMACINFO_DATABASE .keys () == CANONICAL_DIGEST_NAMES
483+
484+
485+ def get_hmac_info_item (name ):
486+ info = _HMACINFO_DATABASE [name ]
487+ assert isinstance (info , _HashInfoItem ), info
488+ return info
483489
484490
485491def _decorate_func_or_class (decorator_func , func_or_class ):
@@ -1011,7 +1017,7 @@ def dummy(data=b'', *, usedforsecurity=True, string=b''):
10111017
10121018def _block_builtin_hmac_constructor (name ):
10131019 """Block explicit HACL* HMAC constructors."""
1014- info = _HashInfoItem ( _EXPLICIT_HMAC_CONSTRUCTORS [ name ] )
1020+ info = get_hmac_info_item ( name )
10151021 assert info .module_name is None or info .module_name == "_hmac" , info
10161022 if (wrapped := info .import_member ()) is None :
10171023 # function shouldn't exist for this implementation
0 commit comments