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).
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 @@
         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