FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Port HMAC implementation to new OpenSSL APIs · Issue #134531 · python/cpython · GitHub

Repository navigation

Port HMAC implementation to new OpenSSL APIs #134531

Closed

Activity

  1. picnixz commented on May 23, 2025

    Member

    I can take care of this. Note that EVP_MAC-HMAC is only available since OpenSSL 3.x and the requirements for CPython are OpenSSL 1.1.1 and later. We still need to maintain the old API (though, we're already doing it through PY_EVP_MD macros) since our build requirements OpenSSL 3.0.9 is the recommended minimum version for the ssl and hashlib extension modules.

  2. self-assigned this
    on May 24, 2025
  3. picnixz commented on May 24, 2025

    Member

    Ok, so I had a quick look at how I would plan this. I'll need multiple PRs because _hashopenssl is a bit messy and now that we will use EVP_MAC in addition to EVP_MD, we should rename some functions. To that end, I'll first make a "cleanup" PR which prepares everything and a bit of refactoring especially to reuse functions later.

    Note: I eventually decided against the backports, even if they could ease the life of my future self (see #134626 (comment) and #134703 (comment)).

  4. added a commit that references this issue on May 26, 2025
  5. added a commit that references this issue on May 26, 2025
  6. picnixz commented on Jun 7, 2025

    Member

    Ok, so here's the plan. I've finished writing the implementation, but the PR is huge:

     Modules/_hashopenssl.c | 815 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------
     1 file changed, 582 insertions(+), 233 deletions(-)
    

    So I'll break down the commits, because I also found multiple issues elsewhere. Well, not real issues, but annoying interfaces that should be refactored first.


    • There is one issue that I introduced in gh-134531: cleanup _hashopenssl.c to support EVP_MAC #134626, namely I renamed the structure types, but I forgot to rename them in clinic directives. It's not an issue because it's never used but we should first fix this. [fixed by 4372011]

    • Next, we have a way to map EVP_MD objects to NID (thank you OpenSSL), and digestmods to EVP_MD, and EVP_MD/digestmods to names. That's great. But the names in question are the "preferred" Python names, not the OpenSSL ones (well sometimes they can be OpenSSL ones as we use it as a fallback). Now, for EVP_MAC objects, there is no way to recover the underlying digest. Why? because MAC objects are not necessarily HMAC, and thus there's not always an underlying "digest" (sometimes it's a cipher). [see https://github.com/gh-134531: refactor _hashlib logic for mapping NIDs to EVP_MD objects #135254]

      This is extremely annoying. Also there is no mapping from EVP_MAC to NIDs, and we can only know whether a MAC is a [HPC]MAC etc, not what the parameters for the underlying algorithm itself were. Now, the goods news is: since we provide a way to create HMAC objects using digestmods, we always get an EVP_MD object behind the scenes. From there, we can instantiate HMAC+digest correctly and remember the NID of that EVP_MD. To recover the underlying digest name, we just need to resolve the NID.

    • The last task will be to rely on digestmods <-> NIDS <-> OpenSSL digest names -> HMAC to construct the EVP_MAC_CTX object (we only need one EVP_MAC object because it's always HMAC).


    The deprecated HMAC API is deprecated because it's actually wrapping an EVP_MD object. The new EVP_MAC API generalize MACs by delegating everything to providers, and callback functions, hiding the implementation of the actual MAC algorithm itself. Now, it's the provider that is wrapping an HMAC_CTX object instead of directly wrapping the EVP_MD objects. Long story short: we still have an EVP_MD somewhere but it's no more recoverable from EVP_MAC objects themselves (and there's no EVP_HMAC).


    I have a branch with everything ready so I'll just make different PRs. At the same time, I'll also refactor _hashopenssl.c because the naming is a bit messy (we don't have a clear convention and I think it's better if we had one good convention when dealing with this module). Later, I'll need to refactor out everything so that we have a unified interface that can be used by _hashlib and _hmac for recognizing "digestmods", but for now, we'll keep things separate (this task is #131876).

  7. added 2 commits that reference this issue on Jun 8, 2025
  8. added 2 commits that reference this issue on Jun 19, 2025
  9. added 2 commits that reference this issue on Jul 12, 2025
  10. 2 remaining items

  11. added 4 commits that reference this issue on Aug 4, 2025
  12. added 3 commits that reference this issue on Aug 19, 2025
  13. added a commit that references this issue on Aug 22, 2025
  14. added a commit that references this issue on Sep 10, 2025
  15. added a commit that references this issue on Jun 2, 2026
  16. added 3 commits that reference this issue on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL