]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-136912: fix handling of `OverflowError` in `hmac.digest` (GH-136917) (...
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Wed, 8 Oct 2025 10:09:45 +0000 (12:09 +0200)
committerGitHub <noreply@github.com>
Wed, 8 Oct 2025 10:09:45 +0000 (12:09 +0200)
commit8ad6eda4830f480380f84c2847acd7f550b2d1c2
treee588e3368c1059baf0cc46083488dc64a4faf5b5
parentc625839237b85b16f6e6d00d0af5e50849003706
[3.14] gh-136912: fix handling of `OverflowError` in `hmac.digest` (GH-136917) (#137116)

The OpenSSL and HACL* implementations of HMAC single-shot
digest computation reject keys whose length exceeds `INT_MAX`
and `UINT32_MAX` respectively. The OpenSSL implementation
also rejects messages whose length exceed `INT_MAX`.

Using such keys in `hmac.digest` previously raised an `OverflowError`
which was propagated to the caller. This commit mitigates this case by
making `hmac.digest` fall back to HMAC's pure Python implementation
which accepts arbitrary large keys or messages.

This change only affects the top-level entrypoint `hmac.digest`, leaving
`_hashopenssl.hmac_digest` and `_hmac.compute_digest` untouched.

(cherry picked from commit d658b9053beaacaae80e318f59a5ddd672aa757a)
Lib/hmac.py
Lib/test/test_hmac.py
Misc/NEWS.d/next/Library/2025-07-21-11-56-47.gh-issue-136912.zWosAL.rst [new file with mode: 0644]