Skip to content

gh-134531: use EVP_MAC API for _hashlib.HMAC #135235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Jun 7, 2025

Just a draft PR for the CI. I'll split the PR tomorrow. Some parts are part of #135234.

This is based on top of #135250 and #135254 so it's a bit messy.

@picnixz
Copy link
Member Author

picnixz commented Jun 7, 2025

!buildbot FIPS

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @picnixz for commit c444180 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135235%2Fmerge

The command will test the builders whose names match following regular expression: FIPS

The builders matched are:

  • AMD64 CentOS9 FIPS No Builtin Hashes PR
  • AMD64 RHEL8 FIPS Only Blake2 Builtin Hash PR
  • AMD64 RHEL8 FIPS No Builtin Hashes PR
  • AMD64 CentOS9 FIPS Only Blake2 Builtin Hash PR

Copy link
Member Author

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, there is also something I wanted to investigate, namely "is it faster to use SN_* names or LN_* names for OpenSSL" and whether it's better to cache the NID (as it's only used in __repr__ or .name) or directly cache a const char *.

I'll need more experiments for this one but this also applies to the existing code where we work with EVP_MD objects instead of caching their properties.

@picnixz picnixz changed the title gh-134531: [PoC] allow to use EVP_MAC API gh-134531: use EVP_MAC API for _hashlib.HMAC Jun 9, 2025
@picnixz picnixz marked this pull request as ready for review June 9, 2025 09:34
@picnixz picnixz requested a review from gpshead as a code owner June 9, 2025 09:34
@python python deleted a comment from bedevere-bot Jun 9, 2025
@picnixz
Copy link
Member Author

picnixz commented Jun 9, 2025

!buildbot FIPS only

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @picnixz for commit 2307154 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135235%2Fmerge

The command will test the builders whose names match following regular expression: FIPS only

The builders matched are:

  • AMD64 RHEL8 FIPS Only Blake2 Builtin Hash PR
  • AMD64 CentOS9 FIPS Only Blake2 Builtin Hash PR

if (digest == NULL) {
return NULL;
}
assert(evp_md_nid != NID_undef);
EVP_MAC_up_ref(state->evp_hmac);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two thoughts about this call:

  • I don't see the corresponding EVP_MAC_free call to decrease the reference count in case EVP_MAC_CTX_new succeeds, so AFAIU state->evp_hmac will leak.
  • This call is not necessary (nor the EVP_MAC_free down below). A EVP_MAC object can be reused by many EVP_MAC_CTX objects as it doesn't contain any state, it just carries the "receipt".

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.

3 participants