From 4e189556edf225eb76a3e829ba2cf171e4f890a2 Mon Sep 17 00:00:00 2001
From: tamaki0575-cloud <265693791+tamaki0575-cloud@users.noreply.github.com>
Date: Sun, 22 Nov 2026 03:32:38 +1100
Subject: [PATCH 1/3] gh-162219: Provide explicit SIMD defaults for HACL
streaming HMAC
---
Makefile.pre.in | 4 ++--
Modules/_hmac_hacl.c | 11 +++++++++++
PCbuild/pythoncore.vcxproj | 2 +-
PCbuild/pythoncore.vcxproj.filters | 2 +-
4 files changed, 15 insertions(+), 4 deletions(-)
create mode 100644 Modules/_hmac_hacl.c
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 650838d68286c73..06653e5e52ab452 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1581,8 +1581,8 @@ $(LIBHACL_BLAKE2_LIB_STATIC): $(LIBHACL_BLAKE2_OBJS)
Modules/_hacl/Hacl_HMAC.o: $(srcdir)/Modules/_hacl/Hacl_HMAC.c $(LIBHACL_HMAC_HEADERS)
$(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_HMAC.c
-Modules/_hacl/Hacl_Streaming_HMAC.o: $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c $(LIBHACL_HMAC_HEADERS)
- $(CC) -Wno-unused-variable -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c
+Modules/_hacl/Hacl_Streaming_HMAC.o: $(srcdir)/Modules/_hmac_hacl.c $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c $(LIBHACL_HMAC_HEADERS)
+ $(CC) -Wno-unused-variable -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hmac_hacl.c
$(LIBHACL_HMAC_LIB_STATIC): $(LIBHACL_HMAC_OBJS)
-rm -f $@
$(AR) $(ARFLAGS) $@ $(LIBHACL_HMAC_OBJS)
diff --git a/Modules/_hmac_hacl.c b/Modules/_hmac_hacl.c
new file mode 100644
index 000000000000000..358844e63c2ce33
--- /dev/null
+++ b/Modules/_hmac_hacl.c
@@ -0,0 +1,11 @@
+/* Compile the HACL* streaming HMAC implementation with explicit SIMD defaults. */
+#include "_hacl/internal/Hacl_Streaming_HMAC.h"
+
+#ifndef HACL_CAN_COMPILE_VEC128
+# define HACL_CAN_COMPILE_VEC128 0
+#endif
+#ifndef HACL_CAN_COMPILE_VEC256
+# define HACL_CAN_COMPILE_VEC256 0
+#endif
+
+#include "_hacl/Hacl_Streaming_HMAC.c"
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index d16aa7b4254b453..9498b856cb266a4 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -458,7 +458,7 @@
-
+
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index 99b2631b673a80d..c63ffcae647c118 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -1028,7 +1028,7 @@
Modules
-
+
Modules
From edd38b5f0ae5154c9b8662c627f44f1724ceab66 Mon Sep 17 00:00:00 2001
From: tamaki0575-cloud <265693791+tamaki0575-cloud@users.noreply.github.com>
Date: Sun, 22 Nov 2026 20:26:38 +1100
Subject: [PATCH 2/3] gh-162219: Move the HMAC wrapper beside the HACL sources
---
Makefile.pre.in | 4 ++--
Modules/_hacl/README.md | 1 +
Modules/{ => _hacl}/_hmac_hacl.c | 4 ++--
PCbuild/pythoncore.vcxproj | 2 +-
PCbuild/pythoncore.vcxproj.filters | 2 +-
Tools/build/generate_sbom.py | 1 +
6 files changed, 8 insertions(+), 6 deletions(-)
rename Modules/{ => _hacl}/_hmac_hacl.c (72%)
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 06653e5e52ab452..5e5564107a93d94 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1581,8 +1581,8 @@ $(LIBHACL_BLAKE2_LIB_STATIC): $(LIBHACL_BLAKE2_OBJS)
Modules/_hacl/Hacl_HMAC.o: $(srcdir)/Modules/_hacl/Hacl_HMAC.c $(LIBHACL_HMAC_HEADERS)
$(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_HMAC.c
-Modules/_hacl/Hacl_Streaming_HMAC.o: $(srcdir)/Modules/_hmac_hacl.c $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c $(LIBHACL_HMAC_HEADERS)
- $(CC) -Wno-unused-variable -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hmac_hacl.c
+Modules/_hacl/Hacl_Streaming_HMAC.o: $(srcdir)/Modules/_hacl/_hmac_hacl.c $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c $(LIBHACL_HMAC_HEADERS)
+ $(CC) -Wno-unused-variable -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/_hmac_hacl.c
$(LIBHACL_HMAC_LIB_STATIC): $(LIBHACL_HMAC_OBJS)
-rm -f $@
$(AR) $(ARFLAGS) $@ $(LIBHACL_HMAC_OBJS)
diff --git a/Modules/_hacl/README.md b/Modules/_hacl/README.md
index 0d6454cdd6efb36..c3fce79494b2f37 100644
--- a/Modules/_hacl/README.md
+++ b/Modules/_hacl/README.md
@@ -19,6 +19,7 @@ changes needed, work with the upstream repository.
## Local files
+* [_hmac_hacl.c](_hmac_hacl.c)
* [python_hacl_namespaces.h](python_hacl_namespaces.h)
* [README.md](README.md)
* [refresh.sh](refresh.sh)
diff --git a/Modules/_hmac_hacl.c b/Modules/_hacl/_hmac_hacl.c
similarity index 72%
rename from Modules/_hmac_hacl.c
rename to Modules/_hacl/_hmac_hacl.c
index 358844e63c2ce33..a4e800736aeb911 100644
--- a/Modules/_hmac_hacl.c
+++ b/Modules/_hacl/_hmac_hacl.c
@@ -1,5 +1,5 @@
/* Compile the HACL* streaming HMAC implementation with explicit SIMD defaults. */
-#include "_hacl/internal/Hacl_Streaming_HMAC.h"
+#include "internal/Hacl_Streaming_HMAC.h"
#ifndef HACL_CAN_COMPILE_VEC128
# define HACL_CAN_COMPILE_VEC128 0
@@ -8,4 +8,4 @@
# define HACL_CAN_COMPILE_VEC256 0
#endif
-#include "_hacl/Hacl_Streaming_HMAC.c"
+#include "Hacl_Streaming_HMAC.c"
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 9498b856cb266a4..3dea47e239df28a 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -458,7 +458,7 @@
-
+
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index c63ffcae647c118..842795ecb2f6a6c 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -1028,7 +1028,7 @@
Modules
-
+
Modules
diff --git a/Tools/build/generate_sbom.py b/Tools/build/generate_sbom.py
index 6975d9687f815dc..051ec48e00a4e08 100644
--- a/Tools/build/generate_sbom.py
+++ b/Tools/build/generate_sbom.py
@@ -77,6 +77,7 @@ class PackageFiles(typing.NamedTuple):
exclude=[
"Modules/_hacl/refresh.sh",
"Modules/_hacl/README.md",
+ "Modules/_hacl/_hmac_hacl.c",
"Modules/_hacl/python_hacl_namespace.h",
]
),
From 2f60c4823a017dc770ae7af3452831cdd890e8e0 Mon Sep 17 00:00:00 2001
From: tamaki0575-cloud <265693791+tamaki0575-cloud@users.noreply.github.com>
Date: Mon, 23 Nov 2026 15:28:04 +1100
Subject: [PATCH 3/3] gh-162219: Compile vendored HACL HMAC directly
---
Makefile.pre.in | 5 +++--
Modules/_hacl/README.md | 1 -
Modules/_hacl/_hmac_hacl.c | 11 -----------
Modules/blake2module.c | 11 +++++++++--
Modules/hmacmodule.c | 7 +++++++
PCbuild/pythoncore.vcxproj | 2 +-
PCbuild/pythoncore.vcxproj.filters | 2 +-
Tools/build/generate_sbom.py | 1 -
8 files changed, 21 insertions(+), 19 deletions(-)
delete mode 100644 Modules/_hacl/_hmac_hacl.c
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 5e5564107a93d94..c62c65f7c985e23 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1581,8 +1581,9 @@ $(LIBHACL_BLAKE2_LIB_STATIC): $(LIBHACL_BLAKE2_OBJS)
Modules/_hacl/Hacl_HMAC.o: $(srcdir)/Modules/_hacl/Hacl_HMAC.c $(LIBHACL_HMAC_HEADERS)
$(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_HMAC.c
-Modules/_hacl/Hacl_Streaming_HMAC.o: $(srcdir)/Modules/_hacl/_hmac_hacl.c $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c $(LIBHACL_HMAC_HEADERS)
- $(CC) -Wno-unused-variable -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/_hmac_hacl.c
+# The vendored HMAC source uses undefined SIMD macros as zero.
+Modules/_hacl/Hacl_Streaming_HMAC.o: $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c $(LIBHACL_HMAC_HEADERS)
+ $(CC) -Wno-unused-variable -c $(LIBHACL_CFLAGS) -Wno-undef -o $@ $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC.c
$(LIBHACL_HMAC_LIB_STATIC): $(LIBHACL_HMAC_OBJS)
-rm -f $@
$(AR) $(ARFLAGS) $@ $(LIBHACL_HMAC_OBJS)
diff --git a/Modules/_hacl/README.md b/Modules/_hacl/README.md
index c3fce79494b2f37..0d6454cdd6efb36 100644
--- a/Modules/_hacl/README.md
+++ b/Modules/_hacl/README.md
@@ -19,7 +19,6 @@ changes needed, work with the upstream repository.
## Local files
-* [_hmac_hacl.c](_hmac_hacl.c)
* [python_hacl_namespaces.h](python_hacl_namespaces.h)
* [README.md](README.md)
* [refresh.sh](refresh.sh)
diff --git a/Modules/_hacl/_hmac_hacl.c b/Modules/_hacl/_hmac_hacl.c
deleted file mode 100644
index a4e800736aeb911..000000000000000
--- a/Modules/_hacl/_hmac_hacl.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* Compile the HACL* streaming HMAC implementation with explicit SIMD defaults. */
-#include "internal/Hacl_Streaming_HMAC.h"
-
-#ifndef HACL_CAN_COMPILE_VEC128
-# define HACL_CAN_COMPILE_VEC128 0
-#endif
-#ifndef HACL_CAN_COMPILE_VEC256
-# define HACL_CAN_COMPILE_VEC256 0
-#endif
-
-#include "Hacl_Streaming_HMAC.c"
diff --git a/Modules/blake2module.c b/Modules/blake2module.c
index 551ebd7cd052af9..c14a49b1d7d2b6a 100644
--- a/Modules/blake2module.c
+++ b/Modules/blake2module.c
@@ -51,6 +51,13 @@
# undef _Py_HACL_CAN_COMPILE_VEC256
#endif
+#ifndef _Py_HACL_CAN_COMPILE_VEC128
+# define _Py_HACL_CAN_COMPILE_VEC128 0
+#endif
+#ifndef _Py_HACL_CAN_COMPILE_VEC256
+# define _Py_HACL_CAN_COMPILE_VEC256 0
+#endif
+
// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable
// the corresponding SIMD instructions so we need to "forward" the values
// we just deduced above.
@@ -89,7 +96,7 @@ blake2_get_state(PyObject *module)
return (Blake2State *)state;
}
-#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256)
+#if _Py_HACL_CAN_COMPILE_VEC128 || _Py_HACL_CAN_COMPILE_VEC256
static inline Blake2State *
blake2_get_state_from_type(PyTypeObject *module)
{
@@ -334,7 +341,7 @@ is_blake2s(blake2_impl impl)
static inline blake2_impl
type_to_impl(PyTypeObject *type)
{
-#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256)
+#if _Py_HACL_CAN_COMPILE_VEC128 || _Py_HACL_CAN_COMPILE_VEC256
Blake2State *st = blake2_get_state_from_type(type);
#endif
if (!strcmp(type->tp_name, blake2b_type_spec.name)) {
diff --git a/Modules/hmacmodule.c b/Modules/hmacmodule.c
index a76a7056e494437..a02fb9791c1a33d 100644
--- a/Modules/hmacmodule.c
+++ b/Modules/hmacmodule.c
@@ -35,6 +35,13 @@
# undef _Py_HACL_CAN_COMPILE_VEC256
#endif
+#ifndef _Py_HACL_CAN_COMPILE_VEC128
+# define _Py_HACL_CAN_COMPILE_VEC128 0
+#endif
+#ifndef _Py_HACL_CAN_COMPILE_VEC256
+# define _Py_HACL_CAN_COMPILE_VEC256 0
+#endif
+
// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable
// the corresponding SIMD instructions so we need to "forward" the values
// we just deduced above.
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 3dea47e239df28a..d16aa7b4254b453 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -458,7 +458,7 @@
-
+
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index 842795ecb2f6a6c..99b2631b673a80d 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -1028,7 +1028,7 @@
Modules
-
+
Modules
diff --git a/Tools/build/generate_sbom.py b/Tools/build/generate_sbom.py
index 051ec48e00a4e08..6975d9687f815dc 100644
--- a/Tools/build/generate_sbom.py
+++ b/Tools/build/generate_sbom.py
@@ -77,7 +77,6 @@ class PackageFiles(typing.NamedTuple):
exclude=[
"Modules/_hacl/refresh.sh",
"Modules/_hacl/README.md",
- "Modules/_hacl/_hmac_hacl.c",
"Modules/_hacl/python_hacl_namespace.h",
]
),