Skip to content

gh-162219: Provide explicit SIMD defaults for HACL streaming HMAC - #162393

Open
tamaki0575-cloud wants to merge 2 commits into
python:mainfrom
tamaki0575-cloud:gh-162219-hacl-hmac-simd-defaults
Open

tamaki0575-cloud wants to merge 2 commits into
python:mainfrom
tamaki0575-cloud:gh-162219-hacl-hmac-simd-defaults

Conversation

@tamaki0575-cloud

@tamaki0575-cloud tamaki0575-cloud commented Nov 21, 2026 •

Copy link
Copy Markdown

Compile the vendored HACL* streaming HMAC implementation through a CPython wrapper. The wrapper defaults HACL_CAN_COMPILE_VEC128 and HACL_CAN_COMPILE_VEC256 to 0 only when they are undefined. The Makefile and Windows project both use the wrapper, so the vendored source stays untouched.

Fixes #162219.

Testing

  • Debian Bookworm (Docker), GCC 12.2: make Modules/_hacl/Hacl_Streaming_HMAC.o CC='gcc -Wundef' reproduced both warnings before the patch and emitted neither after it.
  • Built CPython from main at 1822ff5 and ran ./python -m test test_hmac test_hashlib. Both test modules passed (241 tests run, 17 skipped).
  • Checked the compile entries in both Windows project files. No Windows build was run.

Codex was used to verify the patch and prepare this PR description.

@python-cla-bot

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Nov 21, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Comment thread Modules/_hmac_hacl.c Outdated
@@ -0,0 +1,11 @@
/* Compile the HACL* streaming HMAC implementation with explicit SIMD defaults. */
#include "_hacl/internal/Hacl_Streaming_HMAC.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would rather prefer that this file is put in the _hacl folder next to refresh.sh or update the sh script instead if necessary. We already have some namespace hacking for HACL

@bedevere-app

bedevere-app Bot commented Nov 21, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@bedevere-app

bedevere-app Bot commented Nov 22, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@tamaki0575-cloud

Copy link
Copy Markdown
Author

I moved _hmac_hacl.c next to refresh.sh and updated the Makefile and Windows project to use the new path. The C analyzer now uses its existing HACL* include paths for the wrapper. The SBOM generator treats the wrapper as a CPython file.

On Linux, make check-c-globals passed with zero failures. The HMAC object built with -Wundef without either SIMD macro warning, test_hmac and test_hashlib passed, and make regen-sbom left the SBOM unchanged.

I have made the requested changes; please review again.

@bedevere-app

bedevere-app Bot commented Nov 22, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app
bedevere-app Bot requested a review from picnixz November 22, 2026 09:26
exclude=[
"Modules/_hacl/refresh.sh",
"Modules/_hacl/README.md",
"Modules/_hacl/_hmac_hacl.c",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can name it hmac_defines.c I guess. But i wonder if this is the right solution eventually. Why not changing the non-vendored sources to specify explicitly the values of the defines and ignore the -Wundef flag for _hacl sources?

If necessary, we can also add some .h file instead of a .c file which defines the macros and is included by .c files in hacl. I think it is cleaner than creating this fake .c file (I alao think the approach is wrong actually; the .c files looks like a ugly hack)

@tamaki0575-cloud

tamaki0575-cloud commented Nov 22, 2026 via email

Copy link
Copy Markdown
Author

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.

[HACL] The HACL_CAN_COMPILE_VEC128 macro is not defined when building Python with -Wundef

2 participants