summaryrefslogtreecommitdiffstats
path: root/Lib/hmac.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-11-06 00:32:04 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-11-06 00:32:04 (GMT)
commita1e5387ec55261c19718fd5d7c22419073fa9ad7 (patch)
treef0337eeb337d019ad1d54a558742234eb1009e02 /Lib/hmac.py
parentca741400510f382fb32fa7c8e882f3c0644dd393 (diff)
downloadcpython-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.py10
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