This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [doc] hmac cannot be used with shake algorithms
Type: behavior Stage:
Components: Documentation, Extension Modules Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: christian.heimes, docs@python, minrk, takluyver
Priority: normal Keywords:

Created on 2016-10-07 11:50 by minrk, last changed 2022-04-11 14:58 by admin.

Messages (2)
msg278235 - (view) Author: Min RK (minrk) * Date: 2016-10-07 11:50
HMAC digest methods call inner.digest() with no arguments, but new-in-3.6 shake algorithms require a length argument.

possible solutions:

1. add optional length argument to HMAC.[hex]digest, and pass through to inner hash object
2. set hmac.digest_size, and use that to pass through to inner hash object if inner hash object has digest_size == 0
3. give shake hashers a default value for `length` in digest methods (logically 32 for shake_256, 16 for shake_128, I think)

test:

import hmac, hashlib

h = hmac.HMAC(b'secret', digestmod=hashlib.shake_256)
h.hexdigest() # raises on self.inner.digest() requires length argument
msg278468 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-10-11 09:32
It's not a bug, but indented behavior. It does not make any sense to use SHAKE with the HMAC construct. In fact it does not make sense to combine Keccak sponge or Blake2 with HMAC at all. HMAC is only necessary for old, Merkle-Damgard hashing algorithms like MD5, SHA1 and SHA2, because they are subject to length extension attacks.

The correct solution is
4. improve documentation
History
Date User Action Args
2022-04-11 14:58:38adminsetgithub: 72570
2022-01-17 23:14:46iritkatrielsetnosy: + docs@python
title: hmac cannot be used with shake algorithms -> [doc] hmac cannot be used with shake algorithms
assignee: docs@python
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.6, Python 3.7
components: + Documentation
2016-10-11 09:32:00christian.heimessetmessages: + msg278468
2016-10-07 18:28:53SilentGhostsetnosy: + christian.heimes
type: behavior
components: + Extension Modules
2016-10-07 13:15:22takluyversetnosy: + takluyver
2016-10-07 11:50:44minrkcreate