2929))
3030
3131NON_HMAC_DIGEST_NAMES = frozenset ({
32- 'shake_128' , 'shake_256' , 'blake2s' , 'blake2b'
32+ 'shake_128' , 'shake_256' ,
33+ 'blake2s' , 'blake2b' ,
3334})
3435
35- # Mapping from a "canonical" name to a pair (HACL*, _hashlib.*, hashlib.*)
36- # constructors. If the constructor name is None, then this means that the
37- # algorithm can only be used by the "agile" new() interfaces.
3836
3937class HashAPI (namedtuple ("HashAPI" , "builtin openssl hashlib" )):
4038
@@ -50,6 +48,9 @@ def fullname(self, typ):
5048 raise AssertionError (f"unknown type: { typ } " )
5149
5250
51+ # Mapping from a "canonical" name to a pair (HACL*, _hashlib.*, hashlib.*)
52+ # constructors. If the constructor name is None, then this means that the
53+ # algorithm can only be used by the "agile" new() interfaces.
5354_EXPLICIT_CONSTRUCTORS = MappingProxyType ({
5455 "md5" : HashAPI ("_md5.md5" , "openssl_md5" , "md5" ),
5556 "sha1" : HashAPI ("_sha1.sha1" , "openssl_sha1" , "sha1" ),
@@ -66,7 +67,6 @@ def fullname(self, typ):
6667 "blake2s" : HashAPI ("_blake2.blake2s" , None , "blake2s" ),
6768 "blake2b" : HashAPI ("_blake2.blake2b" , None , "blake2b" ),
6869})
69-
7070assert _EXPLICIT_CONSTRUCTORS .keys () == CANONICAL_DIGEST_NAMES
7171
7272_EXPLICIT_HMAC_CONSTRUCTORS = {
@@ -78,6 +78,8 @@ def fullname(self, typ):
7878}
7979_EXPLICIT_HMAC_CONSTRUCTORS ['shake_128' ] = None
8080_EXPLICIT_HMAC_CONSTRUCTORS ['shake_256' ] = None
81+ # Strictly speaking, HMAC-BLAKE is meaningless as BLAKE2 is already a
82+ # keyed hash function. However, as it's exposed by HACL*, we test it.
8183_EXPLICIT_HMAC_CONSTRUCTORS ['blake2s' ] = '_hmac.compute_blake2s_32'
8284_EXPLICIT_HMAC_CONSTRUCTORS ['blake2b' ] = '_hmac.compute_blake2b_32'
8385_EXPLICIT_HMAC_CONSTRUCTORS = MappingProxyType (_EXPLICIT_HMAC_CONSTRUCTORS )
0 commit comments