diff options
Diffstat (limited to 'frozen_deps/Cryptodome/Hash/HMAC.py')
-rw-r--r-- | frozen_deps/Cryptodome/Hash/HMAC.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/frozen_deps/Cryptodome/Hash/HMAC.py b/frozen_deps/Cryptodome/Hash/HMAC.py index 165dd83..615056a 100644 --- a/frozen_deps/Cryptodome/Hash/HMAC.py +++ b/frozen_deps/Cryptodome/Hash/HMAC.py @@ -35,13 +35,28 @@ from Cryptodome.Util.py3compat import bord, tobytes from binascii import unhexlify -from Cryptodome.Hash import MD5 from Cryptodome.Hash import BLAKE2s from Cryptodome.Util.strxor import strxor from Cryptodome.Random import get_random_bytes __all__ = ['new', 'HMAC'] +_hash2hmac_oid = { + '1.3.14.3.2.26': '1.2.840.113549.2.7', # SHA-1 + '2.16.840.1.101.3.4.2.4': '1.2.840.113549.2.8', # SHA-224 + '2.16.840.1.101.3.4.2.1': '1.2.840.113549.2.9', # SHA-256 + '2.16.840.1.101.3.4.2.2': '1.2.840.113549.2.10', # SHA-384 + '2.16.840.1.101.3.4.2.3': '1.2.840.113549.2.11', # SHA-512 + '2.16.840.1.101.3.4.2.5': '1.2.840.113549.2.12', # SHA-512_224 + '2.16.840.1.101.3.4.2.6': '1.2.840.113549.2.13', # SHA-512_256 + '2.16.840.1.101.3.4.2.7': '2.16.840.1.101.3.4.2.13', # SHA-3 224 + '2.16.840.1.101.3.4.2.8': '2.16.840.1.101.3.4.2.14', # SHA-3 256 + '2.16.840.1.101.3.4.2.9': '2.16.840.1.101.3.4.2.15', # SHA-3 384 + '2.16.840.1.101.3.4.2.10': '2.16.840.1.101.3.4.2.16', # SHA-3 512 +} + +_hmac2hash_oid = {v: k for k, v in _hash2hmac_oid.items()} + class HMAC(object): """An HMAC hash object. @@ -49,11 +64,15 @@ class HMAC(object): :ivar digest_size: the size in bytes of the resulting MAC tag :vartype digest_size: integer + + :ivar oid: the ASN.1 object ID of the HMAC algorithm. + Only present if the algorithm was officially assigned one. """ def __init__(self, key, msg=b"", digestmod=None): if digestmod is None: + from Cryptodome.Hash import MD5 digestmod = MD5 if msg is None: @@ -64,6 +83,12 @@ class HMAC(object): self._digestmod = digestmod + # Hash OID --> HMAC OID + try: + self.oid = _hash2hmac_oid[digestmod.oid] + except (KeyError, AttributeError): + pass + if isinstance(key, memoryview): key = key.tobytes() |