diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2007-11-06 00:32:04 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2007-11-06 00:32:04 (GMT) |
commit | a1e5387ec55261c19718fd5d7c22419073fa9ad7 (patch) | |
tree | f0337eeb337d019ad1d54a558742234eb1009e02 /Lib/hmac.py | |
parent | ca741400510f382fb32fa7c8e882f3c0644dd393 (diff) | |
download | cpython-a1e5387ec55261c19718fd5d7c22419073fa9ad7.zip cpython-a1e5387ec55261c19718fd5d7c22419073fa9ad7.tar.gz cpython-a1e5387ec55261c19718fd5d7c22419073fa9ad7.tar.bz2 |
Backport r58868:
Fixes Issue 1385: The hmac module now computes the correct hmac when using
hashes with a block size other than 64 bytes (such as sha384 and sha512).
Diffstat (limited to 'Lib/hmac.py')
-rw-r--r-- | Lib/hmac.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/hmac.py b/Lib/hmac.py index 41d6c6c..fdd5339 100644 --- a/Lib/hmac.py +++ b/Lib/hmac.py @@ -49,7 +49,15 @@ class HMAC: self.inner = self.digest_cons() self.digest_size = self.inner.digest_size - blocksize = 64 + if hasattr(self.inner, 'block_size'): + blocksize = self.inner.block_size + if blocksize < 16: + # Very low blocksize, most likely a legacy value like + # Lib/sha.py and Lib/md5.py have. + blocksize = 64 + else: + blocksize = 64 + ipad = "\x36" * blocksize opad = "\x5C" * blocksize |