Set SHA-256 as default hash for HMAC

This commit is contained in:
Mark Qvist 2022-06-07 17:33:08 +02:00
parent b2b6708e8f
commit 301661c29e
2 changed files with 3 additions and 3 deletions

View File

@ -6,7 +6,7 @@ def hkdf(length=None, derive_from=None, salt=None, context=None):
hash_len = 32
def hmac_sha256(key, data):
return HMAC.new(key, data, hashlib.sha256).digest()
return HMAC.new(key, data).digest()
if length == None or length < 1:
raise ValueError("Invalid output key length")

View File

@ -24,7 +24,7 @@ class HMAC:
"_hmac", "_inner", "_outer", "block_size", "digest_size"
)
def __init__(self, key, msg=None, digestmod=''):
def __init__(self, key, msg=None, digestmod=_hashlib.sha256):
"""Create a new HMAC object.
key: bytes or buffer, key for the keyed hash object.
msg: bytes or buffer, Initial input for the hash or None.
@ -137,7 +137,7 @@ class HMAC:
h = self._current()
return h.hexdigest()
def new(key, msg=None, digestmod=''):
def new(key, msg=None, digestmod=_hashlib.sha256):
"""Create a new hashing object and return it.
key: bytes or buffer, The starting key for the hash.
msg: bytes or buffer, Initial input for the hash, or None.