Skip to content

[3.14] gh-161383: Fix inverted FIPS property query in _hashlib - #161385

Closed
prashant1221 wants to merge 1 commit into
python:3.14from
prashant1221:fix-3.14-hashlib-fips-property
Closed

prashant1221 wants to merge 1 commit into
python:3.14from
prashant1221:fix-3.14-hashlib-fips-property

Conversation

@prashant1221

@prashant1221 prashant1221 commented Nov 5, 2026 •

Copy link
Copy Markdown

The 3.14 backport of gh-149816 (GH-160006) lost the ! from main's int fips = !disable_fips_property(py_ht);. As a result, usedforsecurity works the wrong way round in FIPS mode, and hashlib.md5() falls back to the built-in _md5 without any error.

Changes:

  • _hashopenssl.c: invert fips after the -1 check. (! can't go on the first line as in main: !-1 would hide the error.)
  • New FIPS-only test test_md5_usedforsecurity_in_fips_mode.
  • check_file_digest() copied from main (Allow tests to temporarily disable specific hash algorithms #136547). Without it, test_case_md5_* fail in FIPS mode once the C fix is in.

Tested with OpenSSL 3.5.8 in FIPS mode (FIPS provider 3.5.4):

  • current 3.14: 14 test_hashlib errors;
  • this PR: test_hashlib and test_hmac pass;
  • C fix reverted: the new test fails.

Without FIPS mode, everything passes and the new test is skipped, as it will be in CI.

In FIPS mode, usedforsecurity worked the wrong way round:
usedforsecurity=False MD5 was refused, usedforsecurity=True MD5 was
allowed, and hashlib.md5() fell back to the built-in _md5 without any
error.

disable_fips_property() returns 1 for usedforsecurity=False, but
py_digest_by_name() uses 'fips' as "1 = strict FIPS lookup". main
inverts the value with "!"; the 3.14 backport of pythongh-149816 (pythonGH-160006)
lost it. Invert it after the -1 error check.

Tests:
- Add a FIPS-only test: MD5 must work with usedforsecurity=False and be
  refused with usedforsecurity=True.
- Copy check_file_digest() from main (pythongh-136547). The 3.14 version
  checks hashlib.new(name), which works through the built-in MD5, and
  then also calls _hashlib.openssl_md5, which FIPS refuses. With only
  the C fix, test_case_md5_* fail in FIPS mode. The main version skips
  each blocked constructor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@python-cla-bot

python-cla-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@hugovk

hugovk commented Nov 5, 2026

Copy link
Copy Markdown
Member

@hugovk hugovk closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants