SIGN IN SIGN UP

gh-146287: Fix signed/unsigned mismatch in _hashlib_hmac_digest_size (GH-148407)

* gh-146287: use signed type for HMAC digest size to prevent unsigned wrapping

Change _hashlib_hmac_digest_size() return type from unsigned int to int
so that a hypothetical negative return from EVP_MD_size() is not
silently wrapped to a large positive value. Add an explicit check for
negative digest_size in the legacy OpenSSL path, and use SystemError
(not ValueError) since these conditions indicate internal invariant
violations. Also add debug-build asserts to EVP_get_block_size and
EVP_get_digest_size documenting that the hash context is always
initialized.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
G
Gregory P. Smith committed
d761f539bdae6090817438ae65c0be8a10c9e4e3
Parent: cef334f
Committed by GitHub <noreply@github.com> on 4/12/2026, 12:02:56 AM