From ac1180f74fcb43a2823de67292fa73be3477590d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 12 Apr 2025 14:19:23 +0200 Subject: [PATCH 01/13] simplify HACL* build for MD5, SHA1, SHA2 and SHA3 modules --- Makefile.pre.in | 40 ++++------------------------------------ Modules/Setup.stdlib.in | 8 ++++---- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index e41a26e469dc22..d0a31dc0d862b2 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -227,10 +227,6 @@ ENSUREPIP= @ENSUREPIP@ # Internal static libraries LIBMPDEC_A= Modules/_decimal/libmpdec/libmpdec.a LIBEXPAT_A= Modules/expat/libexpat.a -LIBHACL_MD5_A= Modules/_hacl/libHacl_Hash_MD5.a -LIBHACL_SHA1_A= Modules/_hacl/libHacl_Hash_SHA1.a -LIBHACL_SHA2_A= Modules/_hacl/libHacl_Hash_SHA2.a -LIBHACL_SHA3_A= Modules/_hacl/libHacl_Hash_SHA3.a LIBHACL_BLAKE2_A= Modules/_hacl/libHacl_Hash_Blake2.a LIBHACL_HMAC_A= Modules/_hacl/libHacl_HMAC.a LIBHACL_CFLAGS=@LIBHACL_CFLAGS@ @@ -1466,34 +1462,6 @@ $(LIBEXPAT_A): $(LIBEXPAT_OBJS) # The contents of libHacl_Blake2.a vary depending on whether we # have the ability to compile vectorized versions -Modules/_hacl/Hacl_Hash_MD5.o: $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c $(LIBHACL_MD5_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c - -$(LIBHACL_MD5_A): $(LIBHACL_MD5_OBJS) - -rm -f $@ - $(AR) $(ARFLAGS) $@ $(LIBHACL_MD5_OBJS) - -Modules/_hacl/Hacl_Hash_SHA1.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c $(LIBHACL_SHA1_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c - -$(LIBHACL_SHA1_A): $(LIBHACL_SHA1_OBJS) - -rm -f $@ - $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA1_OBJS) - -Modules/_hacl/Hacl_Hash_SHA2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c $(LIBHACL_SHA2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c - -$(LIBHACL_SHA2_A): $(LIBHACL_SHA2_OBJS) - -rm -f $@ - $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA2_OBJS) - -Modules/_hacl/Hacl_Hash_SHA3.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c $(LIBHACL_SHA3_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c - -$(LIBHACL_SHA3_A): $(LIBHACL_SHA3_OBJS) - -rm -f $@ - $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA3_OBJS) - Modules/_hacl/Hacl_Hash_Blake2s.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c @@ -3302,10 +3270,10 @@ MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h @LIBMPDEC_INTERNAL@ MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c @LIBEXPAT_INTERNAL@ MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h -MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(LIBHACL_MD5_A) -MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) $(LIBHACL_SHA1_A) -MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_SHA2_A) -MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) $(LIBHACL_SHA3_A) +MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c +MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c +MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c +MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) $(LIBHACL_BLAKE2_A) MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) $(LIBHACL_HMAC_A) MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index bd1e6c9a961877..acd5681ed7b5e7 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -77,10 +77,10 @@ @MODULE_READLINE_TRUE@readline readline.c # hashing builtins, can be disabled with --without-builtin-hashlib-hashes -@MODULE__MD5_TRUE@_md5 md5module.c -I$(srcdir)/Modules/_hacl/include Modules/_hacl/libHacl_Hash_MD5.a -D_BSD_SOURCE -D_DEFAULT_SOURCE -@MODULE__SHA1_TRUE@_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include Modules/_hacl/libHacl_Hash_SHA1.a -D_BSD_SOURCE -D_DEFAULT_SOURCE -@MODULE__SHA2_TRUE@_sha2 sha2module.c -I$(srcdir)/Modules/_hacl/include Modules/_hacl/libHacl_Hash_SHA2.a -D_BSD_SOURCE -D_DEFAULT_SOURCE -@MODULE__SHA3_TRUE@_sha3 sha3module.c -I$(srcdir)/Modules/_hacl/include Modules/_hacl/libHacl_Hash_SHA3.a -D_BSD_SOURCE -D_DEFAULT_SOURCE +@MODULE__MD5_TRUE@_md5 md5module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_MD5.c -D_BSD_SOURCE -D_DEFAULT_SOURCE +@MODULE__SHA1_TRUE@_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_SHA1.c -D_BSD_SOURCE -D_DEFAULT_SOURCE +@MODULE__SHA2_TRUE@_sha2 sha2module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_SHA2.c -D_BSD_SOURCE -D_DEFAULT_SOURCE +@MODULE__SHA3_TRUE@_sha3 sha3module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_SHA3.c -D_BSD_SOURCE -D_DEFAULT_SOURCE @MODULE__BLAKE2_TRUE@_blake2 blake2module.c -I$(srcdir)/Modules/_hacl/include Modules/_hacl/libHacl_Hash_Blake2.a -D_BSD_SOURCE -D_DEFAULT_SOURCE @MODULE__HMAC_TRUE@_hmac hmacmodule.c From 3f0b41e86076763726e63e1cb640eb0e13687867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:26:14 +0200 Subject: [PATCH 02/13] remove statically linked libraries for HACL* implementation --- Makefile.pre.in | 58 +++++++++++++++++++++++++++++------------ Modules/Setup.stdlib.in | 18 ++++++++----- Modules/makesetup | 3 ++- configure | 2 +- configure.ac | 4 +-- 5 files changed, 56 insertions(+), 29 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index d0a31dc0d862b2..5e8a7765096388 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -227,13 +227,13 @@ ENSUREPIP= @ENSUREPIP@ # Internal static libraries LIBMPDEC_A= Modules/_decimal/libmpdec/libmpdec.a LIBEXPAT_A= Modules/expat/libexpat.a -LIBHACL_BLAKE2_A= Modules/_hacl/libHacl_Hash_Blake2.a -LIBHACL_HMAC_A= Modules/_hacl/libHacl_HMAC.a LIBHACL_CFLAGS=@LIBHACL_CFLAGS@ LIBHACL_SIMD128_FLAGS=@LIBHACL_SIMD128_FLAGS@ LIBHACL_SIMD256_FLAGS=@LIBHACL_SIMD256_FLAGS@ LIBHACL_SIMD128_OBJS=@LIBHACL_SIMD128_OBJS@ +LIBHACL_SIMD128_SRCS=$(LIBHACL_SIMD128_OBJS:.o=.c) LIBHACL_SIMD256_OBJS=@LIBHACL_SIMD256_OBJS@ +LIBHACL_SIMD256_SRCS=$(LIBHACL_SIMD256_OBJS:.o=.c) # Module state, compiler flags and linker flags # Empty CFLAGS and LDFLAGS are omitted. @@ -657,18 +657,32 @@ LIBEXPAT_HEADERS= \ ########################################################################## # hashlib's HACL* library +LIBHACL_MD5_SRCS= \ + Modules/_hacl/Hacl_Hash_MD5.c LIBHACL_MD5_OBJS= \ Modules/_hacl/Hacl_Hash_MD5.o +LIBHACL_SHA1_SRCS= \ + Modules/_hacl/Hacl_Hash_SHA1.c LIBHACL_SHA1_OBJS= \ Modules/_hacl/Hacl_Hash_SHA1.o +LIBHACL_SHA2_SRCS= \ + Modules/_hacl/Hacl_Hash_SHA2.c LIBHACL_SHA2_OBJS= \ Modules/_hacl/Hacl_Hash_SHA2.o +LIBHACL_SHA3_SRCS= \ + Modules/_hacl/Hacl_Hash_SHA3.c LIBHACL_SHA3_OBJS= \ Modules/_hacl/Hacl_Hash_SHA3.o +LIBHACL_BLAKE2_SRCS= \ + Modules/_hacl/Hacl_Hash_Blake2s.c \ + Modules/_hacl/Hacl_Hash_Blake2b.c \ + Modules/_hacl/Lib_Memzero0.c \ + $(LIBHACL_SIMD128_SRCS) \ + $(LIBHACL_SIMD256_SRCS) LIBHACL_BLAKE2_OBJS= \ Modules/_hacl/Hacl_Hash_Blake2s.o \ Modules/_hacl/Hacl_Hash_Blake2b.o \ @@ -1460,7 +1474,25 @@ $(LIBEXPAT_A): $(LIBEXPAT_OBJS) # Build HACL* static libraries for hashlib and HACL* HMAC. # # The contents of libHacl_Blake2.a vary depending on whether we -# have the ability to compile vectorized versions +# have the ability to compile vectorized versions. +# +# The HACL* modules are dynamically compiled and linked with the +# corresponding CPython built-in modules on demand, depending on +# whether the module is built or not. Since HMAC however requires +# them to be built, we need rules that are always enabled and that +# are not overwritten by those automatically deduced by makesetup. + +Modules/_hacl/Hacl_Hash_MD5.o: $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c $(LIBHACL_MD5_HEADERS) + $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c + +Modules/_hacl/Hacl_Hash_SHA1.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c $(LIBHACL_SHA1_HEADERS) + $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c + +Modules/_hacl/Hacl_Hash_SHA2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c $(LIBHACL_SHA2_HEADERS) + $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c + +Modules/_hacl/Hacl_Hash_SHA3.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c $(LIBHACL_SHA3_HEADERS) + $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c Modules/_hacl/Hacl_Hash_Blake2s.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c @@ -1483,20 +1515,12 @@ Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o: $(srcdir)/Modules/_hacl/Ha Modules/_hacl/Lib_Memzero0.o: $(srcdir)/Modules/_hacl/Lib_Memzero0.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Lib_Memzero0.c -$(LIBHACL_BLAKE2_A): $(LIBHACL_BLAKE2_OBJS) - -rm -f $@ - $(AR) $(ARFLAGS) $@ $(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 -$(LIBHACL_HMAC_A): $(LIBHACL_HMAC_OBJS) - -rm -f $@ - $(AR) $(ARFLAGS) $@ $(LIBHACL_HMAC_OBJS) - # create relative links from build/lib.platform/egg.so to Modules/egg.so # pybuilddir.txt is created too late. We cannot use it in Makefile # targets. ln --relative is not portable. @@ -3270,12 +3294,12 @@ MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h @LIBMPDEC_INTERNAL@ MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c @LIBEXPAT_INTERNAL@ MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h -MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c -MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c -MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c -MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c -MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) $(LIBHACL_BLAKE2_A) -MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) $(LIBHACL_HMAC_A) +MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(LIBHACL_MD5_OBJS) +MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) $(LIBHACL_SHA1_OBJS) +MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_SHA2_OBJS) +MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) $(LIBHACL_SHA3_OBJS) +MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) $(LIBHACL_BLAKE2_OBJS) +MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) $(LIBHACL_HMAC_OBJS) MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index acd5681ed7b5e7..e1b350aec34dcf 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -77,13 +77,17 @@ @MODULE_READLINE_TRUE@readline readline.c # hashing builtins, can be disabled with --without-builtin-hashlib-hashes -@MODULE__MD5_TRUE@_md5 md5module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_MD5.c -D_BSD_SOURCE -D_DEFAULT_SOURCE -@MODULE__SHA1_TRUE@_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_SHA1.c -D_BSD_SOURCE -D_DEFAULT_SOURCE -@MODULE__SHA2_TRUE@_sha2 sha2module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_SHA2.c -D_BSD_SOURCE -D_DEFAULT_SOURCE -@MODULE__SHA3_TRUE@_sha3 sha3module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_SHA3.c -D_BSD_SOURCE -D_DEFAULT_SOURCE -@MODULE__BLAKE2_TRUE@_blake2 blake2module.c -I$(srcdir)/Modules/_hacl/include Modules/_hacl/libHacl_Hash_Blake2.a -D_BSD_SOURCE -D_DEFAULT_SOURCE - -@MODULE__HMAC_TRUE@_hmac hmacmodule.c +# HACL* dependencies are compiled separately, but they should be linked +# against the module when needed. In order for the extension module to +# be correctly linked, we should however specify which *.o will be used +# (but for which no Makefile rule will be auto-generated). +@MODULE__MD5_TRUE@_md5 md5module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_MD5_OBJS) +@MODULE__SHA1_TRUE@_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_SHA1_OBJS) +@MODULE__SHA2_TRUE@_sha2 sha2module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_SHA2_OBJS) +@MODULE__SHA3_TRUE@_sha3 sha3module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_SHA3_OBJS) +@MODULE__BLAKE2_TRUE@_blake2 blake2module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_BLAKE2_OBJS) + +@MODULE__HMAC_TRUE@_hmac hmacmodule.c $(LIBHACL_HMAC_OBJS) ############################################################################ # XML and text diff --git a/Modules/makesetup b/Modules/makesetup index 8bb971b152a522..e9c10c77209fdd 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -140,6 +140,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | '*shared*') doconfig=no; continue;; '*disabled*') doconfig=disabled; continue;; esac + objs= srcs= cpps= libs= @@ -180,6 +181,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | \$\(*_LIBS\)) libs="$libs $arg";; \$\(*_LDFLAGS\)) libs="$libs $arg";; \$\(*_RPATH\)) libs="$libs $arg";; + \$\(*_OBJS\)) objs="$objs $arg";; \$*) libs="$libs $arg" cpps="$cpps $arg";; *.*) echo 1>&2 "bad word $arg in $line" @@ -224,7 +226,6 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | case $noobjects in yes) continue;; esac - objs='' for src in $srcs do case $src in diff --git a/configure b/configure index decb8f2449d162..8472f0ee8dae4c 100755 --- a/configure +++ b/configure @@ -32294,7 +32294,7 @@ fi then : as_fn_append MODULE_BLOCK "MODULE__HMAC_CFLAGS=$LIBHACL_CFLAGS$as_nl" - as_fn_append MODULE_BLOCK "MODULE__HMAC_LDFLAGS=$LIBHACL_CFLAGS Modules/_hacl/libHacl_HMAC.a$as_nl" + as_fn_append MODULE_BLOCK "MODULE__HMAC_LDFLAGS=$LIBHACL_CFLAGS$as_nl" fi if test "$py_cv_module__hmac" = yes; then diff --git a/configure.ac b/configure.ac index 004797b5233c20..d2664c4c054117 100644 --- a/configure.ac +++ b/configure.ac @@ -7923,9 +7923,7 @@ AC_SUBST([LIBHACL_SIMD256_OBJS]) dnl HMAC builtin library does not need OpenSSL for now. In the future dnl we might want to rely on OpenSSL EVP/NID interface or implement dnl our own for algorithm resolution. -PY_STDLIB_MOD([_hmac], [], [], - [$LIBHACL_CFLAGS], - [$LIBHACL_CFLAGS Modules/_hacl/libHacl_HMAC.a]) +PY_STDLIB_MOD([_hmac], [], [], [$LIBHACL_CFLAGS], [$LIBHACL_CFLAGS]) PY_STDLIB_MOD([_ctypes], [], [test "$have_libffi" = yes], From 08f207b78120d729d1a11ea6cfafddb79b99824a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 13 Apr 2025 16:03:49 +0200 Subject: [PATCH 03/13] is it better now? --- Makefile.pre.in | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 5e8a7765096388..35693791514f85 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -227,13 +227,13 @@ ENSUREPIP= @ENSUREPIP@ # Internal static libraries LIBMPDEC_A= Modules/_decimal/libmpdec/libmpdec.a LIBEXPAT_A= Modules/expat/libexpat.a + +# HACL* build configuration LIBHACL_CFLAGS=@LIBHACL_CFLAGS@ LIBHACL_SIMD128_FLAGS=@LIBHACL_SIMD128_FLAGS@ LIBHACL_SIMD256_FLAGS=@LIBHACL_SIMD256_FLAGS@ LIBHACL_SIMD128_OBJS=@LIBHACL_SIMD128_OBJS@ -LIBHACL_SIMD128_SRCS=$(LIBHACL_SIMD128_OBJS:.o=.c) LIBHACL_SIMD256_OBJS=@LIBHACL_SIMD256_OBJS@ -LIBHACL_SIMD256_SRCS=$(LIBHACL_SIMD256_OBJS:.o=.c) # Module state, compiler flags and linker flags # Empty CFLAGS and LDFLAGS are omitted. @@ -657,32 +657,18 @@ LIBEXPAT_HEADERS= \ ########################################################################## # hashlib's HACL* library -LIBHACL_MD5_SRCS= \ - Modules/_hacl/Hacl_Hash_MD5.c LIBHACL_MD5_OBJS= \ Modules/_hacl/Hacl_Hash_MD5.o -LIBHACL_SHA1_SRCS= \ - Modules/_hacl/Hacl_Hash_SHA1.c LIBHACL_SHA1_OBJS= \ Modules/_hacl/Hacl_Hash_SHA1.o -LIBHACL_SHA2_SRCS= \ - Modules/_hacl/Hacl_Hash_SHA2.c LIBHACL_SHA2_OBJS= \ Modules/_hacl/Hacl_Hash_SHA2.o -LIBHACL_SHA3_SRCS= \ - Modules/_hacl/Hacl_Hash_SHA3.c LIBHACL_SHA3_OBJS= \ Modules/_hacl/Hacl_Hash_SHA3.o -LIBHACL_BLAKE2_SRCS= \ - Modules/_hacl/Hacl_Hash_Blake2s.c \ - Modules/_hacl/Hacl_Hash_Blake2b.c \ - Modules/_hacl/Lib_Memzero0.c \ - $(LIBHACL_SIMD128_SRCS) \ - $(LIBHACL_SIMD256_SRCS) LIBHACL_BLAKE2_OBJS= \ Modules/_hacl/Hacl_Hash_Blake2s.o \ Modules/_hacl/Hacl_Hash_Blake2b.o \ @@ -3294,12 +3280,12 @@ MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h @LIBMPDEC_INTERNAL@ MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c @LIBEXPAT_INTERNAL@ MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h -MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(LIBHACL_MD5_OBJS) -MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) $(LIBHACL_SHA1_OBJS) -MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_SHA2_OBJS) -MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) $(LIBHACL_SHA3_OBJS) -MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) $(LIBHACL_BLAKE2_OBJS) -MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) $(LIBHACL_HMAC_OBJS) +MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) +MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) +MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) +MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) +MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) +MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h From 3a3fc29f4ee107456b8211fdafd6f1dc90c7c053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 13 Apr 2025 17:07:18 +0200 Subject: [PATCH 04/13] is it better now? --- Makefile.pre.in | 30 +++++++++++++++--------------- Modules/Setup.stdlib.in | 25 +++++++++++++------------ Modules/makesetup | 13 ++++++++----- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 35693791514f85..a4353db7b0b1a2 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -728,7 +728,6 @@ LIBHACL_BLAKE2_HEADERS= \ Modules/_hacl/internal/Hacl_Impl_Blake2_Constants.h \ Modules/_hacl/internal/Hacl_Hash_Blake2s_Simd128.h \ Modules/_hacl/internal/Hacl_Hash_Blake2b_Simd256.h \ - Modules/_hacl/internal/Hacl_Streaming_Types.h \ $(LIBHACL_HEADERS) LIBHACL_HMAC_HEADERS= \ @@ -1459,51 +1458,52 @@ $(LIBEXPAT_A): $(LIBEXPAT_OBJS) ########################################################################## # Build HACL* static libraries for hashlib and HACL* HMAC. # -# The contents of libHacl_Blake2.a vary depending on whether we -# have the ability to compile vectorized versions. -# # The HACL* modules are dynamically compiled and linked with the # corresponding CPython built-in modules on demand, depending on -# whether the module is built or not. Since HMAC however requires -# them to be built, we need rules that are always enabled and that -# are not overwritten by those automatically deduced by makesetup. +# whether the module is built or not. +# +# In particular, the HACL* objects are also dependencies of the +# corresponding C extension modules and are indicated by defining +# the MODULE__LIBDEPS variable. +Modules/_hacl/Lib_Memzero0.o: $(srcdir)/Modules/_hacl/Lib_Memzero0.c $(LIBHACL_HEADERS) + $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Lib_Memzero0.c + +MODULE__MD5_LIBDEPS=$(LIBHACL_MD5_OBJS) Modules/_hacl/Hacl_Hash_MD5.o: $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c $(LIBHACL_MD5_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c +MODULE__SHA1_LIBDEPS=$(LIBHACL_SHA1_OBJS) Modules/_hacl/Hacl_Hash_SHA1.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c $(LIBHACL_SHA1_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c +MODULE__SHA2_LIBDEPS=$(LIBHACL_SHA2_OBJS) Modules/_hacl/Hacl_Hash_SHA2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c $(LIBHACL_SHA2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c +MODULE__SHA3_LIBDEPS=$(LIBHACL_SHA3_OBJS) Modules/_hacl/Hacl_Hash_SHA3.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c $(LIBHACL_SHA3_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c +MODULE__BLAKE2_LIBDEPS=$(LIBHACL_BLAKE2_OBJS) Modules/_hacl/Hacl_Hash_Blake2s.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c - Modules/_hacl/Hacl_Hash_Blake2b.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b.c - Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD128_FLAGS) -DHACL_CAN_COMPILE_VEC128 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c - Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD128_FLAGS) -DHACL_CAN_COMPILE_VEC128 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c - Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD256_FLAGS) -DHACL_CAN_COMPILE_VEC256 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c - Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD256_FLAGS) -DHACL_CAN_COMPILE_VEC256 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c -Modules/_hacl/Lib_Memzero0.o: $(srcdir)/Modules/_hacl/Lib_Memzero0.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Lib_Memzero0.c +# Other cryptographic primitives +MODULE__HMAC_LIBDEPS=$(LIBHACL_HMAC_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 diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index e1b350aec34dcf..a64df1cdc2d932 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -76,18 +76,19 @@ # needs -lreadline or -ledit, sometimes termcap, termlib, or tinfo @MODULE_READLINE_TRUE@readline readline.c -# hashing builtins, can be disabled with --without-builtin-hashlib-hashes -# HACL* dependencies are compiled separately, but they should be linked -# against the module when needed. In order for the extension module to -# be correctly linked, we should however specify which *.o will be used -# (but for which no Makefile rule will be auto-generated). -@MODULE__MD5_TRUE@_md5 md5module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_MD5_OBJS) -@MODULE__SHA1_TRUE@_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_SHA1_OBJS) -@MODULE__SHA2_TRUE@_sha2 sha2module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_SHA2_OBJS) -@MODULE__SHA3_TRUE@_sha3 sha3module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_SHA3_OBJS) -@MODULE__BLAKE2_TRUE@_blake2 blake2module.c -I$(srcdir)/Modules/_hacl/include $(LIBHACL_BLAKE2_OBJS) - -@MODULE__HMAC_TRUE@_hmac hmacmodule.c $(LIBHACL_HMAC_OBJS) +############################################################################ +# HACL*-based Cryptographic Primitives + +# Hash functions can be disabled with --without-builtin-hashlib-hashes. +@MODULE__MD5_TRUE@_md5 md5module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__MD5_LIBDEPS) +@MODULE__SHA1_TRUE@_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__SHA1_LIBDEPS) +@MODULE__SHA2_TRUE@_sha2 sha2module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__SHA2_LIBDEPS) +@MODULE__SHA3_TRUE@_sha3 sha3module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__SHA3_LIBDEPS) +@MODULE__BLAKE2_TRUE@_blake2 blake2module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__BLAKE2_LIBDEPS) + +# Since HMAC is always supported, the HACL* implementation modules must +# be built unconditionally. +@MODULE__HMAC_TRUE@_hmac hmacmodule.c -I$(srcdir)/Modules/_hacl/include $(MODULE__HMAC_LIBDEPS) ############################################################################ # XML and text diff --git a/Modules/makesetup b/Modules/makesetup index e9c10c77209fdd..fa1fb36c8aa1d9 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -178,10 +178,10 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | *.cpp) srcs="$srcs $arg";; \$\(*_CFLAGS\)) cpps="$cpps $arg";; \$\(*_INCLUDES\)) cpps="$cpps $arg";; - \$\(*_LIBS\)) libs="$libs $arg";; + \$\(*_LIBS\)) libs="$libs $arg";; + \$\(*_LIBDEPS\)) libs="$libs $arg";; \$\(*_LDFLAGS\)) libs="$libs $arg";; \$\(*_RPATH\)) libs="$libs $arg";; - \$\(*_OBJS\)) objs="$objs $arg";; \$*) libs="$libs $arg" cpps="$cpps $arg";; *.*) echo 1>&2 "bad word $arg in $line" @@ -226,6 +226,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | case $noobjects in yes) continue;; esac + objs='' for src in $srcs do case $src in @@ -253,11 +254,13 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | case $doconfig in no) cc="$cc $cpps \$(PY_STDMODULE_CFLAGS) \$(CCSHARED)" - rule="$obj: $src \$(MODULE_${mods_upper}_DEPS) \$(MODULE_DEPS_SHARED) \$(PYTHON_HEADERS); $cc -c $src -o $obj" + rule="$obj: $src \$(MODULE_${mods_upper}_DEPS) \$(MODULE_DEPS_SHARED) \$(PYTHON_HEADERS)" + rule="$rule; $cc -c $src -o $obj" ;; *) cc="$cc $cpps \$(PY_BUILTIN_MODULE_CFLAGS)" - rule="$obj: $src \$(MODULE_${mods_upper}_DEPS) \$(MODULE_DEPS_STATIC) \$(PYTHON_HEADERS); $cc -c $src -o $obj" + rule="$obj: $src \$(MODULE_${mods_upper}_DEPS) \$(MODULE_DEPS_STATIC) \$(PYTHON_HEADERS)" + rule="$rule; $cc -c $src -o $obj" ;; esac echo "$rule" >>$rulesf @@ -274,7 +277,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | BUILT_SHARED="$BUILT_SHARED $mod" ;; esac - rule="$file: $objs" + rule="$file: $objs \$(MODULE_${mods_upper}_LIBDEPS)" rule="$rule; \$(BLDSHARED) $objs $libs \$(LIBPYTHON) -o $file" echo "$rule" >>$rulesf done From a5d39fab7b3b982ac3e813ab31494ec296b463a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 13 Apr 2025 17:08:19 +0200 Subject: [PATCH 05/13] fixup --- Modules/makesetup | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/makesetup b/Modules/makesetup index fa1fb36c8aa1d9..d13b821af4143c 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -140,7 +140,6 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | '*shared*') doconfig=no; continue;; '*disabled*') doconfig=disabled; continue;; esac - objs= srcs= cpps= libs= From de0232a2e10987d05030f2ec37b49c0ab0c745e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Wed, 16 Apr 2025 22:12:51 +0200 Subject: [PATCH 06/13] Present HACL* as a static or shared library. On WASI, extension modules based on HACL* require the HACL* library to be linked statically. On other platforms, it can be built dynamically. --- Makefile.pre.in | 99 ++++++++-- Modules/Setup.stdlib.in | 20 +- Modules/makesetup | 3 +- configure | 416 ++++++++++++++++++++++++---------------- configure.ac | 90 +++++++-- 5 files changed, 416 insertions(+), 212 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index a4353db7b0b1a2..9ef9f70707bbde 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -230,10 +230,9 @@ LIBEXPAT_A= Modules/expat/libexpat.a # HACL* build configuration LIBHACL_CFLAGS=@LIBHACL_CFLAGS@ -LIBHACL_SIMD128_FLAGS=@LIBHACL_SIMD128_FLAGS@ -LIBHACL_SIMD256_FLAGS=@LIBHACL_SIMD256_FLAGS@ -LIBHACL_SIMD128_OBJS=@LIBHACL_SIMD128_OBJS@ -LIBHACL_SIMD256_OBJS=@LIBHACL_SIMD256_OBJS@ +LIBHACL_LDFLAGS=@LIBHACL_LDFLAGS@ +LIBHACL_BLAKE2_SIMD128_CFLAGS=@LIBHACL_SIMD128_FLAGS@ -DHACL_CAN_COMPILE_VEC128 +LIBHACL_BLAKE2_SIMD256_CFLAGS=@LIBHACL_SIMD256_FLAGS@ -DHACL_CAN_COMPILE_VEC256 # Module state, compiler flags and linker flags # Empty CFLAGS and LDFLAGS are omitted. @@ -656,25 +655,40 @@ LIBEXPAT_HEADERS= \ ########################################################################## # hashlib's HACL* library +# +# On WASI, static build is required. +# On other platforms, a shared library is used. LIBHACL_MD5_OBJS= \ Modules/_hacl/Hacl_Hash_MD5.o +LIBHACL_MD5_LIB_STATIC=Modules/_hacl/libHacl_Hash_MD5.a +LIBHACL_MD5_LIB_SHARED=Modules/_hacl/libHacl_Hash_MD5$(SHLIB_SUFFIX) LIBHACL_SHA1_OBJS= \ Modules/_hacl/Hacl_Hash_SHA1.o +LIBHACL_SHA1_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA1.a +LIBHACL_SHA1_LIB_SHARED=Modules/_hacl/libHacl_Hash_SHA1$(SHLIB_SUFFIX) LIBHACL_SHA2_OBJS= \ Modules/_hacl/Hacl_Hash_SHA2.o +LIBHACL_SHA2_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA2.a +LIBHACL_SHA2_LIB_SHARED=Modules/_hacl/libHacl_Hash_SHA2$(SHLIB_SUFFIX) LIBHACL_SHA3_OBJS= \ Modules/_hacl/Hacl_Hash_SHA3.o +LIBHACL_SHA3_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA3.a +LIBHACL_SHA3_LIB_SHARED=Modules/_hacl/libHacl_Hash_SHA3$(SHLIB_SUFFIX) +LIBHACL_BLAKE2_SIMD128_OBJS=@LIBHACL_BLAKE2_SIMD128_OBJS@ +LIBHACL_BLAKE2_SIMD256_OBJS=@LIBHACL_BLAKE2_SIMD256_OBJS@ LIBHACL_BLAKE2_OBJS= \ Modules/_hacl/Hacl_Hash_Blake2s.o \ Modules/_hacl/Hacl_Hash_Blake2b.o \ Modules/_hacl/Lib_Memzero0.o \ - $(LIBHACL_SIMD128_OBJS) \ - $(LIBHACL_SIMD256_OBJS) + $(LIBHACL_BLAKE2_SIMD128_OBJS) \ + $(LIBHACL_BLAKE2_SIMD256_OBJS) +LIBHACL_BLAKE2_LIB_STATIC=Modules/_hacl/libHacl_Hash_BLAKE2.a +LIBHACL_BLAKE2_LIB_SHARED=Modules/_hacl/libHacl_Hash_BLAKE2$(SHLIB_SUFFIX) LIBHACL_HMAC_OBJS= \ Modules/_hacl/Hacl_HMAC.o \ @@ -684,6 +698,8 @@ LIBHACL_HMAC_OBJS= \ $(LIBHACL_SHA2_OBJS) \ $(LIBHACL_SHA3_OBJS) \ $(LIBHACL_BLAKE2_OBJS) +LIBHACL_HMAC_LIB_STATIC=Modules/_hacl/libHacl_HMAC.a +LIBHACL_HMAC_LIB_SHARED=Modules/_hacl/libHacl_HMAC$(SHLIB_SUFFIX) LIBHACL_HEADERS= \ Modules/_hacl/include/krml/FStar_UInt128_Verified.h \ @@ -1456,57 +1472,91 @@ $(LIBEXPAT_A): $(LIBEXPAT_OBJS) $(AR) $(ARFLAGS) $@ $(LIBEXPAT_OBJS) ########################################################################## -# Build HACL* static libraries for hashlib and HACL* HMAC. +# HACL* library build # # The HACL* modules are dynamically compiled and linked with the # corresponding CPython built-in modules on demand, depending on # whether the module is built or not. # # In particular, the HACL* objects are also dependencies of the -# corresponding C extension modules and are indicated by defining -# the MODULE__LIBDEPS variable. +# corresponding C extension modules but makesetup must NOT create +# a rule for them. +# +# For WASI, static linking is needed and HACL* is statically linked instead. Modules/_hacl/Lib_Memzero0.o: $(srcdir)/Modules/_hacl/Lib_Memzero0.c $(LIBHACL_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Lib_Memzero0.c -MODULE__MD5_LIBDEPS=$(LIBHACL_MD5_OBJS) Modules/_hacl/Hacl_Hash_MD5.o: $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c $(LIBHACL_MD5_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c +$(LIBHACL_MD5_LIB_STATIC): $(LIBHACL_MD5_OBJS) + -rm -f $@ + $(AR) $(ARFLAGS) $@ $(LIBHACL_MD5_OBJS) +$(LIBHACL_MD5_LIB_SHARED): $(LIBHACL_MD5_OBJS) + -rm -f $@ + $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_MD5_OBJS) -o $@ -MODULE__SHA1_LIBDEPS=$(LIBHACL_SHA1_OBJS) Modules/_hacl/Hacl_Hash_SHA1.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c $(LIBHACL_SHA1_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c +$(LIBHACL_SHA1_LIB_STATIC): $(LIBHACL_SHA1_OBJS) + -rm -f $@ + $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA1_OBJS) +$(LIBHACL_SHA1_LIB_SHARED): $(LIBHACL_SHA1_OBJS) + -rm -f $@ + $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_SHA1_OBJS) -o $@ -MODULE__SHA2_LIBDEPS=$(LIBHACL_SHA2_OBJS) Modules/_hacl/Hacl_Hash_SHA2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c $(LIBHACL_SHA2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c +$(LIBHACL_SHA2_LIB_STATIC): $(LIBHACL_SHA2_OBJS) + -rm -f $@ + $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA2_OBJS) +$(LIBHACL_SHA2_LIB_SHARED): $(LIBHACL_SHA2_OBJS) + -rm -f $@ + $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_SHA2_OBJS) -o $@ -MODULE__SHA3_LIBDEPS=$(LIBHACL_SHA3_OBJS) Modules/_hacl/Hacl_Hash_SHA3.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c $(LIBHACL_SHA3_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c +$(LIBHACL_SHA3_LIB_STATIC): $(LIBHACL_SHA3_OBJS) + -rm -f $@ + $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA3_OBJS) +$(LIBHACL_SHA3_LIB_SHARED): $(LIBHACL_SHA3_OBJS) + -rm -f $@ + $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_SHA3_OBJS) -o $@ -MODULE__BLAKE2_LIBDEPS=$(LIBHACL_BLAKE2_OBJS) Modules/_hacl/Hacl_Hash_Blake2s.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c Modules/_hacl/Hacl_Hash_Blake2b.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b.c Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD128_FLAGS) -DHACL_CAN_COMPILE_VEC128 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c + $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD128_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD128_FLAGS) -DHACL_CAN_COMPILE_VEC128 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c + $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD128_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD256_FLAGS) -DHACL_CAN_COMPILE_VEC256 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c + $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD256_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_SIMD256_FLAGS) -DHACL_CAN_COMPILE_VEC256 -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c + $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD256_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c -# Other cryptographic primitives +$(LIBHACL_BLAKE2_LIB_STATIC): $(LIBHACL_BLAKE2_OBJS) + -rm -f $@ + $(AR) $(ARFLAGS) $@ $(LIBHACL_BLAKE2_OBJS) +$(LIBHACL_BLAKE2_LIB_SHARED): $(LIBHACL_BLAKE2_OBJS) + -rm -f $@ + $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_BLAKE2_OBJS) -o $@ + +# Other HACL* cryptographic primitives -MODULE__HMAC_LIBDEPS=$(LIBHACL_HMAC_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 +$(LIBHACL_HMAC_LIB_STATIC): $(LIBHACL_HMAC_OBJS) + -rm -f $@ + $(AR) $(ARFLAGS) $@ $(LIBHACL_HMAC_OBJS) +$(LIBHACL_HMAC_LIB_SHARED): $(LIBHACL_HMAC_OBJS) + -rm -f $@ + $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_HMAC_OBJS) -o $@ +########################################################################## # create relative links from build/lib.platform/egg.so to Modules/egg.so # pybuilddir.txt is created too late. We cannot use it in Makefile # targets. ln --relative is not portable. @@ -3280,12 +3330,21 @@ MODULE__DECIMAL_DEPS=$(srcdir)/Modules/_decimal/docstrings.h @LIBMPDEC_INTERNAL@ MODULE__ELEMENTTREE_DEPS=$(srcdir)/Modules/pyexpat.c @LIBEXPAT_INTERNAL@ MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h + +# HACL*-based cryptographic primitives MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) +MODULE__MD5_LDEPS=$(LIBHACL_MD5_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) +MODULE__SHA1_LDEPS=$(LIBHACL_SHA1_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) +MODULE__SHA2_LDEPS=$(LIBHACL_SHA2_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) +MODULE__SHA3_LDEPS=$(LIBHACL_SHA3_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) +MODULE__BLAKE2_LDEPS=$(LIBHACL_BLAKE2_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) +MODULE__HMAC_LDEPS=$(LIBHACL_HMAC_LIB_@LIBHACL_LDEPS_LIBTYPE@) + MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index a64df1cdc2d932..0774e7ddab844c 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -16,6 +16,9 @@ # generated by PY_STDLIB_MOD macro. # * All source files automatically depend on $(PYTHON_HEADERS) and # $(MODULE_{NAME}_DEPS). +# * ${NAME}$(EXT_SUFFIX) rules automatically depend on $(MODULE_{NAME}_LDEPS), +# thus $(MODULE_{NAME}_LDEPS) must only contain Makefile rule names. To pass +# specific values to the linker, use $(MODULE_{NAME}_LDFLAGS) instead. # # See Modules/Setup and Modules/makesetup # @@ -78,17 +81,22 @@ ############################################################################ # HACL*-based Cryptographic Primitives +# +# Since the compilation of the built-in cryptographic modules depends +# on whether we are building on WASI or not, rules will be explicitly +# written. In the future, it should be preferrable to be able to setup +# the relevant bits here instead of in Makefile.pre.in or configure.ac. # Hash functions can be disabled with --without-builtin-hashlib-hashes. -@MODULE__MD5_TRUE@_md5 md5module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__MD5_LIBDEPS) -@MODULE__SHA1_TRUE@_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__SHA1_LIBDEPS) -@MODULE__SHA2_TRUE@_sha2 sha2module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__SHA2_LIBDEPS) -@MODULE__SHA3_TRUE@_sha3 sha3module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__SHA3_LIBDEPS) -@MODULE__BLAKE2_TRUE@_blake2 blake2module.c -I$(srcdir)/Modules/_hacl/include $(MODULE__BLAKE2_LIBDEPS) +@MODULE__MD5_TRUE@_md5 md5module.c +@MODULE__SHA1_TRUE@_sha1 sha1module.c +@MODULE__SHA2_TRUE@_sha2 sha2module.c +@MODULE__SHA3_TRUE@_sha3 sha3module.c +@MODULE__BLAKE2_TRUE@_blake2 blake2module.c # Since HMAC is always supported, the HACL* implementation modules must # be built unconditionally. -@MODULE__HMAC_TRUE@_hmac hmacmodule.c -I$(srcdir)/Modules/_hacl/include $(MODULE__HMAC_LIBDEPS) +@MODULE__HMAC_TRUE@_hmac hmacmodule.c ############################################################################ # XML and text diff --git a/Modules/makesetup b/Modules/makesetup index d13b821af4143c..d7e19e6c3d4783 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -178,7 +178,6 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | \$\(*_CFLAGS\)) cpps="$cpps $arg";; \$\(*_INCLUDES\)) cpps="$cpps $arg";; \$\(*_LIBS\)) libs="$libs $arg";; - \$\(*_LIBDEPS\)) libs="$libs $arg";; \$\(*_LDFLAGS\)) libs="$libs $arg";; \$\(*_RPATH\)) libs="$libs $arg";; \$*) libs="$libs $arg" @@ -276,7 +275,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | BUILT_SHARED="$BUILT_SHARED $mod" ;; esac - rule="$file: $objs \$(MODULE_${mods_upper}_LIBDEPS)" + rule="$file: $objs \$(MODULE_${mods_upper}_LDEPS)" rule="$rule; \$(BLDSHARED) $objs $libs \$(LIBPYTHON) -o $file" echo "$rule" >>$rulesf done diff --git a/configure b/configure index 8472f0ee8dae4c..a0b84f245aecb6 100755 --- a/configure +++ b/configure @@ -708,11 +708,6 @@ MODULE__CTYPES_FALSE MODULE__CTYPES_TRUE MODULE__HMAC_FALSE MODULE__HMAC_TRUE -LIBHACL_SIMD256_OBJS -LIBHACL_SIMD256_FLAGS -LIBHACL_SIMD128_OBJS -LIBHACL_SIMD128_FLAGS -LIBHACL_CFLAGS MODULE__BLAKE2_FALSE MODULE__BLAKE2_TRUE MODULE__SHA3_FALSE @@ -723,6 +718,13 @@ MODULE__SHA1_FALSE MODULE__SHA1_TRUE MODULE__MD5_FALSE MODULE__MD5_TRUE +LIBHACL_LDEPS_LIBTYPE +LIBHACL_BLAKE2_SIMD256_OBJS +LIBHACL_SIMD256_FLAGS +LIBHACL_BLAKE2_SIMD128_OBJS +LIBHACL_SIMD128_FLAGS +LIBHACL_LDFLAGS +LIBHACL_CFLAGS MODULE_UNICODEDATA_FALSE MODULE_UNICODEDATA_TRUE MODULE__MULTIBYTECODEC_FALSE @@ -31912,6 +31914,213 @@ then : fi +############################################################################### +# HACL* compilation and linking configuration (contact: @picnixz) +# +# Used by the HACL*-based implementations of cryptographic primitives. +# +# CPython provides a vendored copy of a subset of the HACL* project used +# to build extension modules of cryptographic primitives. On WASI, HACL* +# sources must be statically linked with the extension modules; on other +# platforms, the extension modules may assume that HACL* has been compiled +# as a shared library. +# +# Example for MD5: +# +# 1. Compile Modules/_hacl/Hacl_Hash_MD5.c into Modules/_hacl/Hacl_Hash_MD5.o. +# 2. Create Modules/_hacl/libHacl_Hash_MD5$EXT where $EXT is the extension +# for a static (resp. shared) library depending on whether we are on WASI. +# 3. Compile Modules/md5module.c into Modules/md5module.o. +# 4. Link Modules/md5module.o with Modules/_hacl/libHacl_Hash_MD5$EXT +# and get Modules/_md5$(EXT_SUFFIX). +# +# LIBHACL_FLAG_I: '-I' flags passed to $(CC) for HACL* and HACL*-based modules +# LIBHACL_FLAG_D: '-D' flags passed to $(CC) for HACL* and HACL*-based modules +# LIBHACL_CFLAGS: flags passed $(CC) for HACL* and HACL*-based modules +# LIBHACL_LDFLAGS: flags passed $(LDSHARED) for HACL* and HACL*-based modules +LIBHACL_FLAG_I='-I$(srcdir)/Modules/_hacl -I$(srcdir)/Modules/_hacl/include' +LIBHACL_FLAG_D='-D_BSD_SOURCE -D_DEFAULT_SOURCE' +case "$ac_sys_system" in + Linux*) + if test "$ac_cv_func_explicit_bzero" = "no"; then + LIBHACL_FLAG_D="${LIBHACL_FLAG_D} -DLINUX_NO_EXPLICIT_BZERO" + fi + ;; +esac +LIBHACL_CFLAGS="\$(CCSHARED) ${LIBHACL_FLAG_I} ${LIBHACL_FLAG_D}" + +LIBHACL_LDFLAGS= # for now, no specific linker flags are needed + + +# The SIMD files use aligned_alloc, which is not available on older versions of +# Android. +# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. +if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2" >&5 +printf %s "checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2... " >&6; } +if test ${ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) + ax_check_save_flags=$CFLAGS + CFLAGS="$CFLAGS -Werror -msse -msse2 -msse3 -msse4.1 -msse4.2" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2=yes +else case e in #( + e) ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + CFLAGS=$ax_check_save_flags ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" >&5 +printf "%s\n" "$ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" >&6; } +if test "x$ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" = xyes +then : + + LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2" + + +printf "%s\n" "#define HACL_CAN_COMPILE_SIMD128 1" >>confdefs.h + + + # macOS universal2 builds *support* the -msse etc flags because they're + # available on x86_64. However, performance of the HACL SIMD128 implementation + # isn't great, so it's disabled on ARM64. + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD128 implementation" >&5 +printf %s "checking for HACL* SIMD128 implementation... " >&6; } + if test "$UNIVERSAL_ARCHS" == "universal2"; then + LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 +printf "%s\n" "universal2" >&6; } + else + LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 +printf "%s\n" "standard" >&6; } + fi + + +else case e in #( + e) : ;; +esac +fi + +fi + + + +# The SIMD files use aligned_alloc, which is not available on older versions of +# Android. +# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. +# +# Although AVX support is not guaranteed on Android +# (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a +# runtime CPUID check. +if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -mavx2" >&5 +printf %s "checking whether C compiler accepts -mavx2... " >&6; } +if test ${ax_cv_check_cflags__Werror__mavx2+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) + ax_check_save_flags=$CFLAGS + CFLAGS="$CFLAGS -Werror -mavx2" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ax_cv_check_cflags__Werror__mavx2=yes +else case e in #( + e) ax_cv_check_cflags__Werror__mavx2=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + CFLAGS=$ax_check_save_flags ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__mavx2" >&5 +printf "%s\n" "$ax_cv_check_cflags__Werror__mavx2" >&6; } +if test "x$ax_cv_check_cflags__Werror__mavx2" = xyes +then : + + LIBHACL_SIMD256_FLAGS="-mavx2" + +printf "%s\n" "#define HACL_CAN_COMPILE_SIMD256 1" >>confdefs.h + + + # macOS universal2 builds *support* the -mavx2 compiler flag because it's + # available on x86_64; but the HACL SIMD256 build then fails because the + # implementation requires symbols that aren't available on ARM64. Use a + # wrapped implementation if we're building for universal2. + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD256 implementation" >&5 +printf %s "checking for HACL* SIMD256 implementation... " >&6; } + if test "$UNIVERSAL_ARCHS" == "universal2"; then + LIBHACL_BLAKE2_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 +printf "%s\n" "universal2" >&6; } + else + LIBHACL_BLAKE2_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 +printf "%s\n" "standard" >&6; } + fi + +else case e in #( + e) : ;; +esac +fi + +fi + + +### end(HACL* configuration) + +############################################################################### +# HACL*-based cryptographic primitives + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* library linking type" >&5 +printf %s "checking for HACL* library linking type... " >&6; } +if test "$ac_sys_system" = "WASI"; then + LIBHACL_LDEPS_LIBTYPE=STATIC + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: static" >&5 +printf "%s\n" "static" >&6; } +else + LIBHACL_LDEPS_LIBTYPE=SHARED + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: shared" >&5 +printf "%s\n" "shared" >&6; } +fi +# Used to complete the "MODULE__LDEPS" Makefile variable. +# The LDEPS variable is a Makefile rule prerequisite. + + + + + + + LIBHACL_MD5_LDFLAGS=LIBHACL_MD5_LIB_${LIBHACL_LDEPS_LIBTYPE} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _md5" >&5 printf %s "checking for stdlib extension module _md5... " >&6; } @@ -31937,8 +32146,8 @@ fi if test "x$py_cv_module__md5" = xyes then : - - + as_fn_append MODULE_BLOCK "MODULE__MD5_CFLAGS=$LIBHACL_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__MD5_LDFLAGS=\$($LIBHACL_MD5_LDFLAGS)$as_nl" fi if test "$py_cv_module__md5" = yes; then @@ -31953,6 +32162,11 @@ fi printf "%s\n" "$py_cv_module__md5" >&6; } + + + + LIBHACL_SHA1_LDFLAGS=LIBHACL_SHA1_LIB_${LIBHACL_LDEPS_LIBTYPE} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _sha1" >&5 printf %s "checking for stdlib extension module _sha1... " >&6; } if test "$py_cv_module__sha1" != "n/a" @@ -31977,8 +32191,8 @@ fi if test "x$py_cv_module__sha1" = xyes then : - - + as_fn_append MODULE_BLOCK "MODULE__SHA1_CFLAGS=$LIBHACL_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__SHA1_LDFLAGS=\$($LIBHACL_SHA1_LDFLAGS)$as_nl" fi if test "$py_cv_module__sha1" = yes; then @@ -31993,6 +32207,11 @@ fi printf "%s\n" "$py_cv_module__sha1" >&6; } + + + + LIBHACL_SHA2_LDFLAGS=LIBHACL_SHA2_LIB_${LIBHACL_LDEPS_LIBTYPE} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _sha2" >&5 printf %s "checking for stdlib extension module _sha2... " >&6; } if test "$py_cv_module__sha2" != "n/a" @@ -32017,8 +32236,8 @@ fi if test "x$py_cv_module__sha2" = xyes then : - - + as_fn_append MODULE_BLOCK "MODULE__SHA2_CFLAGS=$LIBHACL_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__SHA2_LDFLAGS=\$($LIBHACL_SHA2_LDFLAGS)$as_nl" fi if test "$py_cv_module__sha2" = yes; then @@ -32033,6 +32252,11 @@ fi printf "%s\n" "$py_cv_module__sha2" >&6; } + + + + LIBHACL_SHA3_LDFLAGS=LIBHACL_SHA3_LIB_${LIBHACL_LDEPS_LIBTYPE} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _sha3" >&5 printf %s "checking for stdlib extension module _sha3... " >&6; } if test "$py_cv_module__sha3" != "n/a" @@ -32057,8 +32281,8 @@ fi if test "x$py_cv_module__sha3" = xyes then : - - + as_fn_append MODULE_BLOCK "MODULE__SHA3_CFLAGS=$LIBHACL_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__SHA3_LDFLAGS=\$($LIBHACL_SHA3_LDFLAGS)$as_nl" fi if test "$py_cv_module__sha3" = yes; then @@ -32073,6 +32297,11 @@ fi printf "%s\n" "$py_cv_module__sha3" >&6; } + + + + LIBHACL_BLAKE2_LDFLAGS=LIBHACL_BLAKE2_LIB_${LIBHACL_LDEPS_LIBTYPE} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _blake2" >&5 printf %s "checking for stdlib extension module _blake2... " >&6; } if test "$py_cv_module__blake2" != "n/a" @@ -32097,8 +32326,8 @@ fi if test "x$py_cv_module__blake2" = xyes then : - - + as_fn_append MODULE_BLOCK "MODULE__BLAKE2_CFLAGS=$LIBHACL_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__BLAKE2_LDFLAGS=\$($LIBHACL_BLAKE2_LDFLAGS)$as_nl" fi if test "$py_cv_module__blake2" = yes; then @@ -32113,161 +32342,11 @@ fi printf "%s\n" "$py_cv_module__blake2" >&6; } -LIBHACL_CFLAGS='-I$(srcdir)/Modules/_hacl -I$(srcdir)/Modules/_hacl/include -D_BSD_SOURCE -D_DEFAULT_SOURCE $(PY_STDMODULE_CFLAGS) $(CCSHARED)' -case "$ac_sys_system" in - Linux*) - if test "$ac_cv_func_explicit_bzero" = "no"; then - LIBHACL_CFLAGS="$LIBHACL_CFLAGS -DLINUX_NO_EXPLICIT_BZERO" - fi - ;; -esac - - -# The SIMD files use aligned_alloc, which is not available on older versions of -# Android. -# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2" >&5 -printf %s "checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2... " >&6; } -if test ${ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) - ax_check_save_flags=$CFLAGS - CFLAGS="$CFLAGS -Werror -msse -msse2 -msse3 -msse4.1 -msse4.2" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main (void) -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2=yes -else case e in #( - e) ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2=no ;; -esac -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - CFLAGS=$ax_check_save_flags ;; -esac -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" >&5 -printf "%s\n" "$ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" >&6; } -if test "x$ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" = xyes -then : - - LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2" - - -printf "%s\n" "#define HACL_CAN_COMPILE_SIMD128 1" >>confdefs.h - - - # macOS universal2 builds *support* the -msse etc flags because they're - # available on x86_64. However, performance of the HACL SIMD128 implementation - # isn't great, so it's disabled on ARM64. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD128 implementation" >&5 -printf %s "checking for HACL* SIMD128 implementation... " >&6; } - if test "$UNIVERSAL_ARCHS" == "universal2"; then - LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 -printf "%s\n" "universal2" >&6; } - else - LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 -printf "%s\n" "standard" >&6; } - fi - - -else case e in #( - e) : ;; -esac -fi - -fi - - - -# The SIMD files use aligned_alloc, which is not available on older versions of -# Android. -# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. -# -# Although AVX support is not guaranteed on Android -# (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a -# runtime CPUID check. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -mavx2" >&5 -printf %s "checking whether C compiler accepts -mavx2... " >&6; } -if test ${ax_cv_check_cflags__Werror__mavx2+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) - ax_check_save_flags=$CFLAGS - CFLAGS="$CFLAGS -Werror -mavx2" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main (void) -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - ax_cv_check_cflags__Werror__mavx2=yes -else case e in #( - e) ax_cv_check_cflags__Werror__mavx2=no ;; -esac -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - CFLAGS=$ax_check_save_flags ;; -esac -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__mavx2" >&5 -printf "%s\n" "$ax_cv_check_cflags__Werror__mavx2" >&6; } -if test "x$ax_cv_check_cflags__Werror__mavx2" = xyes -then : - - LIBHACL_SIMD256_FLAGS="-mavx2" - -printf "%s\n" "#define HACL_CAN_COMPILE_SIMD256 1" >>confdefs.h - # macOS universal2 builds *support* the -mavx2 compiler flag because it's - # available on x86_64; but the HACL SIMD256 build then fails because the - # implementation requires symbols that aren't available on ARM64. Use a - # wrapped implementation if we're building for universal2. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD256 implementation" >&5 -printf %s "checking for HACL* SIMD256 implementation... " >&6; } - if test "$UNIVERSAL_ARCHS" == "universal2"; then - LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 -printf "%s\n" "universal2" >&6; } - else - LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 -printf "%s\n" "standard" >&6; } - fi - -else case e in #( - e) : ;; -esac -fi - -fi - + LIBHACL_HMAC_LDFLAGS=LIBHACL_HMAC_LIB_${LIBHACL_LDEPS_LIBTYPE} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _hmac" >&5 printf %s "checking for stdlib extension module _hmac... " >&6; } @@ -32294,7 +32373,7 @@ fi then : as_fn_append MODULE_BLOCK "MODULE__HMAC_CFLAGS=$LIBHACL_CFLAGS$as_nl" - as_fn_append MODULE_BLOCK "MODULE__HMAC_LDFLAGS=$LIBHACL_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__HMAC_LDFLAGS=\$($LIBHACL_HMAC_LDFLAGS)$as_nl" fi if test "$py_cv_module__hmac" = yes; then @@ -32310,6 +32389,9 @@ printf "%s\n" "$py_cv_module__hmac" >&6; } +### end(cryptographic primitives) + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _ctypes" >&5 printf %s "checking for stdlib extension module _ctypes... " >&6; } if test "$py_cv_module__ctypes" != "n/a" diff --git a/configure.ac b/configure.ac index d2664c4c054117..9f4ea6ca48648e 100644 --- a/configure.ac +++ b/configure.ac @@ -7846,23 +7846,43 @@ PY_STDLIB_MOD_SIMPLE([_codecs_tw]) PY_STDLIB_MOD_SIMPLE([_multibytecodec]) PY_STDLIB_MOD_SIMPLE([unicodedata]) -dnl By default we always compile these even when OpenSSL is available -dnl (issue #14693). The modules are small. -PY_STDLIB_MOD([_md5], [test "$with_builtin_md5" = yes]) -PY_STDLIB_MOD([_sha1], [test "$with_builtin_sha1" = yes]) -PY_STDLIB_MOD([_sha2], [test "$with_builtin_sha2" = yes]) -PY_STDLIB_MOD([_sha3], [test "$with_builtin_sha3" = yes]) -PY_STDLIB_MOD([_blake2], [test "$with_builtin_blake2" = yes]) - -LIBHACL_CFLAGS='-I$(srcdir)/Modules/_hacl -I$(srcdir)/Modules/_hacl/include -D_BSD_SOURCE -D_DEFAULT_SOURCE $(PY_STDMODULE_CFLAGS) $(CCSHARED)' +############################################################################### +# HACL* compilation and linking configuration (contact: @picnixz) +# +# Used by the HACL*-based implementations of cryptographic primitives. +# +# CPython provides a vendored copy of a subset of the HACL* project used +# to build extension modules of cryptographic primitives. On WASI, HACL* +# sources must be statically linked with the extension modules; on other +# platforms, the extension modules may assume that HACL* has been compiled +# as a shared library. +# +# Example for MD5: +# +# 1. Compile Modules/_hacl/Hacl_Hash_MD5.c into Modules/_hacl/Hacl_Hash_MD5.o. +# 2. Create Modules/_hacl/libHacl_Hash_MD5$EXT where $EXT is the extension +# for a static (resp. shared) library depending on whether we are on WASI. +# 3. Compile Modules/md5module.c into Modules/md5module.o. +# 4. Link Modules/md5module.o with Modules/_hacl/libHacl_Hash_MD5$EXT +# and get Modules/_md5$(EXT_SUFFIX). +# +# LIBHACL_FLAG_I: '-I' flags passed to $(CC) for HACL* and HACL*-based modules +# LIBHACL_FLAG_D: '-D' flags passed to $(CC) for HACL* and HACL*-based modules +# LIBHACL_CFLAGS: flags passed $(CC) for HACL* and HACL*-based modules +# LIBHACL_LDFLAGS: flags passed $(LDSHARED) for HACL* and HACL*-based modules +LIBHACL_FLAG_I='-I$(srcdir)/Modules/_hacl -I$(srcdir)/Modules/_hacl/include' +LIBHACL_FLAG_D='-D_BSD_SOURCE -D_DEFAULT_SOURCE' case "$ac_sys_system" in Linux*) if test "$ac_cv_func_explicit_bzero" = "no"; then - LIBHACL_CFLAGS="$LIBHACL_CFLAGS -DLINUX_NO_EXPLICIT_BZERO" + LIBHACL_FLAG_D="${LIBHACL_FLAG_D} -DLINUX_NO_EXPLICIT_BZERO" fi ;; esac +LIBHACL_CFLAGS="\$(CCSHARED) ${LIBHACL_FLAG_I} ${LIBHACL_FLAG_D}" AC_SUBST([LIBHACL_CFLAGS]) +LIBHACL_LDFLAGS= # for now, no specific linker flags are needed +AC_SUBST([LIBHACL_LDFLAGS]) # The SIMD files use aligned_alloc, which is not available on older versions of # Android. @@ -7879,17 +7899,17 @@ if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || tes # isn't great, so it's disabled on ARM64. AC_MSG_CHECKING([for HACL* SIMD128 implementation]) if test "$UNIVERSAL_ARCHS" == "universal2"; then - [LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"] + [LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"] AC_MSG_RESULT([universal2]) else - [LIBHACL_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"] + [LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"] AC_MSG_RESULT([standard]) fi ], [], [-Werror]) fi AC_SUBST([LIBHACL_SIMD128_FLAGS]) -AC_SUBST([LIBHACL_SIMD128_OBJS]) +AC_SUBST([LIBHACL_BLAKE2_SIMD128_OBJS]) # The SIMD files use aligned_alloc, which is not available on older versions of # Android. @@ -7909,21 +7929,57 @@ if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || tes # wrapped implementation if we're building for universal2. AC_MSG_CHECKING([for HACL* SIMD256 implementation]) if test "$UNIVERSAL_ARCHS" == "universal2"; then - [LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"] + [LIBHACL_BLAKE2_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"] AC_MSG_RESULT([universal2]) else - [LIBHACL_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"] + [LIBHACL_BLAKE2_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"] AC_MSG_RESULT([standard]) fi ], [], [-Werror]) fi AC_SUBST([LIBHACL_SIMD256_FLAGS]) -AC_SUBST([LIBHACL_SIMD256_OBJS]) +AC_SUBST([LIBHACL_BLAKE2_SIMD256_OBJS]) +### end(HACL* configuration) + +############################################################################### +# HACL*-based cryptographic primitives + +AC_MSG_CHECKING([for HACL* library linking type]) +if test "$ac_sys_system" = "WASI"; then + LIBHACL_LDEPS_LIBTYPE=STATIC + AC_MSG_RESULT([static]) +else + LIBHACL_LDEPS_LIBTYPE=SHARED + AC_MSG_RESULT([shared]) +fi +# Used to complete the "MODULE__LDEPS" Makefile variable. +# The LDEPS variable is a Makefile rule prerequisite. +AC_SUBST([LIBHACL_LDEPS_LIBTYPE]) + +dnl PY_HACL_CREATE_MODULE([COMPONENT], [EXTNAME], [ENABLED-TEST]) +dnl The COMPONENT is the name of the HACL* component being built in uppercase. +dnl Corresponding Makefile variables are named as LIBHACL__*. +dnl The EXTNAME is the name of the extension module being built. +AC_DEFUN([PY_HACL_CREATE_MODULE], [ + AS_VAR_PUSHDEF([v], [[LIBHACL_][$1][_LDFLAGS]]) + AS_VAR_SET([v], [[LIBHACL_][$1][_LIB_${LIBHACL_LDEPS_LIBTYPE}]]) + PY_STDLIB_MOD([$2], [$3], [], [$LIBHACL_CFLAGS], [\$($v)]) + AS_VAR_POPDEF([v]) +]) + +dnl By default we always compile these even when OpenSSL is available +dnl (see bpo-14693). The modules are small. +PY_HACL_CREATE_MODULE([MD5], [_md5], [test "$with_builtin_md5" = yes]) +PY_HACL_CREATE_MODULE([SHA1], [_sha1], [test "$with_builtin_sha1" = yes]) +PY_HACL_CREATE_MODULE([SHA2], [_sha2], [test "$with_builtin_sha2" = yes]) +PY_HACL_CREATE_MODULE([SHA3], [_sha3], [test "$with_builtin_sha3" = yes]) +PY_HACL_CREATE_MODULE([BLAKE2], [_blake2], [test "$with_builtin_blake2" = yes]) dnl HMAC builtin library does not need OpenSSL for now. In the future dnl we might want to rely on OpenSSL EVP/NID interface or implement dnl our own for algorithm resolution. -PY_STDLIB_MOD([_hmac], [], [], [$LIBHACL_CFLAGS], [$LIBHACL_CFLAGS]) +PY_HACL_CREATE_MODULE([HMAC], [_hmac], []) +### end(cryptographic primitives) PY_STDLIB_MOD([_ctypes], [], [test "$have_libffi" = yes], From c0b00bf953b4536c906d304211c26a7a7e88a66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 18 Apr 2025 11:48:38 +0200 Subject: [PATCH 07/13] amend whitespace --- Modules/makesetup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/makesetup b/Modules/makesetup index d7e19e6c3d4783..f6cf695b457cbf 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -177,7 +177,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | *.cpp) srcs="$srcs $arg";; \$\(*_CFLAGS\)) cpps="$cpps $arg";; \$\(*_INCLUDES\)) cpps="$cpps $arg";; - \$\(*_LIBS\)) libs="$libs $arg";; + \$\(*_LIBS\)) libs="$libs $arg";; \$\(*_LDFLAGS\)) libs="$libs $arg";; \$\(*_RPATH\)) libs="$libs $arg";; \$*) libs="$libs $arg" From da101423d11c3ee6537c5fdba9b68677ec36f8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 18 Apr 2025 12:23:55 +0200 Subject: [PATCH 08/13] remove temporary .so file as it requires more symlinks --- Makefile.pre.in | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 9ef9f70707bbde..7331a778415b98 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -662,22 +662,22 @@ LIBEXPAT_HEADERS= \ LIBHACL_MD5_OBJS= \ Modules/_hacl/Hacl_Hash_MD5.o LIBHACL_MD5_LIB_STATIC=Modules/_hacl/libHacl_Hash_MD5.a -LIBHACL_MD5_LIB_SHARED=Modules/_hacl/libHacl_Hash_MD5$(SHLIB_SUFFIX) +LIBHACL_MD5_LIB_SHARED=$(LIBHACL_MD5_OBJS) LIBHACL_SHA1_OBJS= \ Modules/_hacl/Hacl_Hash_SHA1.o LIBHACL_SHA1_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA1.a -LIBHACL_SHA1_LIB_SHARED=Modules/_hacl/libHacl_Hash_SHA1$(SHLIB_SUFFIX) +LIBHACL_SHA1_LIB_SHARED=$(LIBHACL_SHA1_OBJS) LIBHACL_SHA2_OBJS= \ Modules/_hacl/Hacl_Hash_SHA2.o LIBHACL_SHA2_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA2.a -LIBHACL_SHA2_LIB_SHARED=Modules/_hacl/libHacl_Hash_SHA2$(SHLIB_SUFFIX) +LIBHACL_SHA2_LIB_SHARED=$(LIBHACL_SHA2_OBJS) LIBHACL_SHA3_OBJS= \ Modules/_hacl/Hacl_Hash_SHA3.o LIBHACL_SHA3_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA3.a -LIBHACL_SHA3_LIB_SHARED=Modules/_hacl/libHacl_Hash_SHA3$(SHLIB_SUFFIX) +LIBHACL_SHA3_LIB_SHARED=$(LIBHACL_SHA3_OBJS) LIBHACL_BLAKE2_SIMD128_OBJS=@LIBHACL_BLAKE2_SIMD128_OBJS@ LIBHACL_BLAKE2_SIMD256_OBJS=@LIBHACL_BLAKE2_SIMD256_OBJS@ @@ -688,7 +688,7 @@ LIBHACL_BLAKE2_OBJS= \ $(LIBHACL_BLAKE2_SIMD128_OBJS) \ $(LIBHACL_BLAKE2_SIMD256_OBJS) LIBHACL_BLAKE2_LIB_STATIC=Modules/_hacl/libHacl_Hash_BLAKE2.a -LIBHACL_BLAKE2_LIB_SHARED=Modules/_hacl/libHacl_Hash_BLAKE2$(SHLIB_SUFFIX) +LIBHACL_BLAKE2_LIB_SHARED=$(LIBHACL_BLAKE2_OBJS) LIBHACL_HMAC_OBJS= \ Modules/_hacl/Hacl_HMAC.o \ @@ -699,7 +699,7 @@ LIBHACL_HMAC_OBJS= \ $(LIBHACL_SHA3_OBJS) \ $(LIBHACL_BLAKE2_OBJS) LIBHACL_HMAC_LIB_STATIC=Modules/_hacl/libHacl_HMAC.a -LIBHACL_HMAC_LIB_SHARED=Modules/_hacl/libHacl_HMAC$(SHLIB_SUFFIX) +LIBHACL_HMAC_LIB_SHARED=$(LIBHACL_HMAC_OBJS) LIBHACL_HEADERS= \ Modules/_hacl/include/krml/FStar_UInt128_Verified.h \ @@ -1492,36 +1492,24 @@ Modules/_hacl/Hacl_Hash_MD5.o: $(srcdir)/Modules/_hacl/Hacl_Hash_MD5.c $(LIBHACL $(LIBHACL_MD5_LIB_STATIC): $(LIBHACL_MD5_OBJS) -rm -f $@ $(AR) $(ARFLAGS) $@ $(LIBHACL_MD5_OBJS) -$(LIBHACL_MD5_LIB_SHARED): $(LIBHACL_MD5_OBJS) - -rm -f $@ - $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_MD5_OBJS) -o $@ Modules/_hacl/Hacl_Hash_SHA1.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c $(LIBHACL_SHA1_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA1.c $(LIBHACL_SHA1_LIB_STATIC): $(LIBHACL_SHA1_OBJS) -rm -f $@ $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA1_OBJS) -$(LIBHACL_SHA1_LIB_SHARED): $(LIBHACL_SHA1_OBJS) - -rm -f $@ - $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_SHA1_OBJS) -o $@ Modules/_hacl/Hacl_Hash_SHA2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c $(LIBHACL_SHA2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA2.c $(LIBHACL_SHA2_LIB_STATIC): $(LIBHACL_SHA2_OBJS) -rm -f $@ $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA2_OBJS) -$(LIBHACL_SHA2_LIB_SHARED): $(LIBHACL_SHA2_OBJS) - -rm -f $@ - $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_SHA2_OBJS) -o $@ Modules/_hacl/Hacl_Hash_SHA3.o: $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c $(LIBHACL_SHA3_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_SHA3.c $(LIBHACL_SHA3_LIB_STATIC): $(LIBHACL_SHA3_OBJS) -rm -f $@ $(AR) $(ARFLAGS) $@ $(LIBHACL_SHA3_OBJS) -$(LIBHACL_SHA3_LIB_SHARED): $(LIBHACL_SHA3_OBJS) - -rm -f $@ - $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_SHA3_OBJS) -o $@ Modules/_hacl/Hacl_Hash_Blake2s.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c @@ -1535,13 +1523,9 @@ Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Bla $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD256_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD256_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c - $(LIBHACL_BLAKE2_LIB_STATIC): $(LIBHACL_BLAKE2_OBJS) -rm -f $@ $(AR) $(ARFLAGS) $@ $(LIBHACL_BLAKE2_OBJS) -$(LIBHACL_BLAKE2_LIB_SHARED): $(LIBHACL_BLAKE2_OBJS) - -rm -f $@ - $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_BLAKE2_OBJS) -o $@ # Other HACL* cryptographic primitives @@ -1552,9 +1536,6 @@ Modules/_hacl/Hacl_Streaming_HMAC.o: $(srcdir)/Modules/_hacl/Hacl_Streaming_HMAC $(LIBHACL_HMAC_LIB_STATIC): $(LIBHACL_HMAC_OBJS) -rm -f $@ $(AR) $(ARFLAGS) $@ $(LIBHACL_HMAC_OBJS) -$(LIBHACL_HMAC_LIB_SHARED): $(LIBHACL_HMAC_OBJS) - -rm -f $@ - $(LDSHARED) $(LIBHACL_LDFLAGS) $(LIBHACL_HMAC_OBJS) -o $@ ########################################################################## # create relative links from build/lib.platform/egg.so to Modules/egg.so From 6a47f8abb2a9a8c9243db3eff137e0fd64f4e03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 19 Apr 2025 12:41:12 +0200 Subject: [PATCH 09/13] avoid smelly symbols --- Modules/_hacl/lib_memzero0.h | 1 + Modules/_hacl/python_hacl_namespaces.h | 447 +++++++++++++------------ Modules/_hacl/refresh.sh | 3 + 3 files changed, 236 insertions(+), 215 deletions(-) diff --git a/Modules/_hacl/lib_memzero0.h b/Modules/_hacl/lib_memzero0.h index fea3e41c907f44..2043834b9bbe08 100644 --- a/Modules/_hacl/lib_memzero0.h +++ b/Modules/_hacl/lib_memzero0.h @@ -1,4 +1,5 @@ #include +#include "python_hacl_namespaces.h" void Lib_Memzero0_memzero0(void *dst, uint64_t len); diff --git a/Modules/_hacl/python_hacl_namespaces.h b/Modules/_hacl/python_hacl_namespaces.h index e234a123e1606d..1c2f7fea5c837a 100644 --- a/Modules/_hacl/python_hacl_namespaces.h +++ b/Modules/_hacl/python_hacl_namespaces.h @@ -6,234 +6,251 @@ * conflicts with builds linking or dynamically loading other code potentially * using HACL* libraries. * - * Something like this to generate new entries for the list: nm *.o | grep Hacl | cut -c 20- | sort | uniq | grep -v python_hashlib | egrep ^_ | gsed 's/_\(.*\)/#define \1 python_hashlib_\1/' + * Something like this to generate new entries for the list: + * + * nm *.o | grep Hacl | cut -c 20- | sort | uniq | grep -v _Py_LibHacl_ | egrep ^_ | sed 's/_\(.*\)/#define \1 _Py_LibHacl_\1/g' */ -#define Hacl_Hash_SHA2_state_sha2_224_s python_hashlib_Hacl_Hash_SHA2_state_sha2_224_s -#define Hacl_Hash_SHA2_state_sha2_224 python_hashlib_Hacl_Hash_SHA2_state_sha2_224 -#define Hacl_Hash_SHA2_state_sha2_256 python_hashlib_Hacl_Hash_SHA2_state_sha2_256 -#define Hacl_Hash_SHA2_state_sha2_384_s python_hashlib_Hacl_Hash_SHA2_state_sha2_384_s -#define Hacl_Hash_SHA2_state_sha2_384 python_hashlib_Hacl_Hash_SHA2_state_sha2_384 -#define Hacl_Hash_SHA2_state_sha2_512 python_hashlib_Hacl_Hash_SHA2_state_sha2_512 -#define Hacl_Hash_SHA2_malloc_256 python_hashlib_Hacl_Hash_SHA2_malloc_256 -#define Hacl_Hash_SHA2_malloc_224 python_hashlib_Hacl_Hash_SHA2_malloc_224 -#define Hacl_Hash_SHA2_malloc_512 python_hashlib_Hacl_Hash_SHA2_malloc_512 -#define Hacl_Hash_SHA2_malloc_384 python_hashlib_Hacl_Hash_SHA2_malloc_384 -#define Hacl_Hash_SHA2_copy_256 python_hashlib_Hacl_Hash_SHA2_copy_256 -#define Hacl_Hash_SHA2_copy_224 python_hashlib_Hacl_Hash_SHA2_copy_224 -#define Hacl_Hash_SHA2_copy_512 python_hashlib_Hacl_Hash_SHA2_copy_512 -#define Hacl_Hash_SHA2_copy_384 python_hashlib_Hacl_Hash_SHA2_copy_384 -#define Hacl_Hash_SHA2_init_256 python_hashlib_Hacl_Hash_SHA2_init_256 -#define Hacl_Hash_SHA2_init_224 python_hashlib_Hacl_Hash_SHA2_init_224 -#define Hacl_Hash_SHA2_init_512 python_hashlib_Hacl_Hash_SHA2_init_512 -#define Hacl_Hash_SHA2_init_384 python_hashlib_Hacl_Hash_SHA2_init_384 -#define Hacl_SHA2_Scalar32_sha512_init python_hashlib_Hacl_SHA2_Scalar32_sha512_init -#define Hacl_Hash_SHA2_update_256 python_hashlib_Hacl_Hash_SHA2_update_256 -#define Hacl_Hash_SHA2_update_224 python_hashlib_Hacl_Hash_SHA2_update_224 -#define Hacl_Hash_SHA2_update_512 python_hashlib_Hacl_Hash_SHA2_update_512 -#define Hacl_Hash_SHA2_update_384 python_hashlib_Hacl_Hash_SHA2_update_384 -#define Hacl_Hash_SHA2_digest_256 python_hashlib_Hacl_Hash_SHA2_digest_256 -#define Hacl_Hash_SHA2_digest_224 python_hashlib_Hacl_Hash_SHA2_digest_224 -#define Hacl_Hash_SHA2_digest_512 python_hashlib_Hacl_Hash_SHA2_digest_512 -#define Hacl_Hash_SHA2_digest_384 python_hashlib_Hacl_Hash_SHA2_digest_384 -#define Hacl_Hash_SHA2_free_256 python_hashlib_Hacl_Hash_SHA2_free_256 -#define Hacl_Hash_SHA2_free_224 python_hashlib_Hacl_Hash_SHA2_free_224 -#define Hacl_Hash_SHA2_free_512 python_hashlib_Hacl_Hash_SHA2_free_512 -#define Hacl_Hash_SHA2_free_384 python_hashlib_Hacl_Hash_SHA2_free_384 -#define Hacl_Hash_SHA2_sha256 python_hashlib_Hacl_Hash_SHA2_sha256 -#define Hacl_Hash_SHA2_sha224 python_hashlib_Hacl_Hash_SHA2_sha224 -#define Hacl_Hash_SHA2_sha512 python_hashlib_Hacl_Hash_SHA2_sha512 -#define Hacl_Hash_SHA2_sha384 python_hashlib_Hacl_Hash_SHA2_sha384 +#define Lib_Memzero0_memzero0 _Py_LibHacl_Lib_Memzero0_memzero0 + +#define Hacl_Hash_SHA2_state_sha2_224_s _Py_LibHacl_Hacl_Hash_SHA2_state_sha2_224_s +#define Hacl_Hash_SHA2_state_sha2_224 _Py_LibHacl_Hacl_Hash_SHA2_state_sha2_224 +#define Hacl_Hash_SHA2_state_sha2_256 _Py_LibHacl_Hacl_Hash_SHA2_state_sha2_256 +#define Hacl_Hash_SHA2_state_sha2_384_s _Py_LibHacl_Hacl_Hash_SHA2_state_sha2_384_s +#define Hacl_Hash_SHA2_state_sha2_384 _Py_LibHacl_Hacl_Hash_SHA2_state_sha2_384 +#define Hacl_Hash_SHA2_state_sha2_512 _Py_LibHacl_Hacl_Hash_SHA2_state_sha2_512 +#define Hacl_Hash_SHA2_malloc_256 _Py_LibHacl_Hacl_Hash_SHA2_malloc_256 +#define Hacl_Hash_SHA2_malloc_224 _Py_LibHacl_Hacl_Hash_SHA2_malloc_224 +#define Hacl_Hash_SHA2_malloc_512 _Py_LibHacl_Hacl_Hash_SHA2_malloc_512 +#define Hacl_Hash_SHA2_malloc_384 _Py_LibHacl_Hacl_Hash_SHA2_malloc_384 +#define Hacl_Hash_SHA2_copy_256 _Py_LibHacl_Hacl_Hash_SHA2_copy_256 +#define Hacl_Hash_SHA2_copy_224 _Py_LibHacl_Hacl_Hash_SHA2_copy_224 +#define Hacl_Hash_SHA2_copy_512 _Py_LibHacl_Hacl_Hash_SHA2_copy_512 +#define Hacl_Hash_SHA2_copy_384 _Py_LibHacl_Hacl_Hash_SHA2_copy_384 +#define Hacl_Hash_SHA2_init_256 _Py_LibHacl_Hacl_Hash_SHA2_init_256 +#define Hacl_Hash_SHA2_init_224 _Py_LibHacl_Hacl_Hash_SHA2_init_224 +#define Hacl_Hash_SHA2_init_512 _Py_LibHacl_Hacl_Hash_SHA2_init_512 +#define Hacl_Hash_SHA2_init_384 _Py_LibHacl_Hacl_Hash_SHA2_init_384 +#define Hacl_SHA2_Scalar32_sha512_init _Py_LibHacl_Hacl_SHA2_Scalar32_sha512_init +#define Hacl_Hash_SHA2_update_256 _Py_LibHacl_Hacl_Hash_SHA2_update_256 +#define Hacl_Hash_SHA2_update_224 _Py_LibHacl_Hacl_Hash_SHA2_update_224 +#define Hacl_Hash_SHA2_update_512 _Py_LibHacl_Hacl_Hash_SHA2_update_512 +#define Hacl_Hash_SHA2_update_384 _Py_LibHacl_Hacl_Hash_SHA2_update_384 +#define Hacl_Hash_SHA2_digest_256 _Py_LibHacl_Hacl_Hash_SHA2_digest_256 +#define Hacl_Hash_SHA2_digest_224 _Py_LibHacl_Hacl_Hash_SHA2_digest_224 +#define Hacl_Hash_SHA2_digest_512 _Py_LibHacl_Hacl_Hash_SHA2_digest_512 +#define Hacl_Hash_SHA2_digest_384 _Py_LibHacl_Hacl_Hash_SHA2_digest_384 +#define Hacl_Hash_SHA2_free_256 _Py_LibHacl_Hacl_Hash_SHA2_free_256 +#define Hacl_Hash_SHA2_free_224 _Py_LibHacl_Hacl_Hash_SHA2_free_224 +#define Hacl_Hash_SHA2_free_512 _Py_LibHacl_Hacl_Hash_SHA2_free_512 +#define Hacl_Hash_SHA2_free_384 _Py_LibHacl_Hacl_Hash_SHA2_free_384 +#define Hacl_Hash_SHA2_sha256 _Py_LibHacl_Hacl_Hash_SHA2_sha256 +#define Hacl_Hash_SHA2_sha224 _Py_LibHacl_Hacl_Hash_SHA2_sha224 +#define Hacl_Hash_SHA2_sha512 _Py_LibHacl_Hacl_Hash_SHA2_sha512 +#define Hacl_Hash_SHA2_sha384 _Py_LibHacl_Hacl_Hash_SHA2_sha384 -#define Hacl_Hash_MD5_malloc python_hashlib_Hacl_Hash_MD5_malloc -#define Hacl_Hash_MD5_init python_hashlib_Hacl_Hash_MD5_init -#define Hacl_Hash_MD5_update python_hashlib_Hacl_Hash_MD5_update -#define Hacl_Hash_MD5_digest python_hashlib_Hacl_Hash_MD5_digest -#define Hacl_Hash_MD5_free python_hashlib_Hacl_Hash_MD5_free -#define Hacl_Hash_MD5_copy python_hashlib_Hacl_Hash_MD5_copy -#define Hacl_Hash_MD5_hash python_hashlib_Hacl_Hash_MD5_hash +#define Hacl_Hash_MD5_malloc _Py_LibHacl_Hacl_Hash_MD5_malloc +#define Hacl_Hash_MD5_init _Py_LibHacl_Hacl_Hash_MD5_init +#define Hacl_Hash_MD5_update _Py_LibHacl_Hacl_Hash_MD5_update +#define Hacl_Hash_MD5_digest _Py_LibHacl_Hacl_Hash_MD5_digest +#define Hacl_Hash_MD5_free _Py_LibHacl_Hacl_Hash_MD5_free +#define Hacl_Hash_MD5_copy _Py_LibHacl_Hacl_Hash_MD5_copy +#define Hacl_Hash_MD5_hash _Py_LibHacl_Hacl_Hash_MD5_hash -#define Hacl_Hash_SHA1_malloc python_hashlib_Hacl_Hash_SHA1_malloc -#define Hacl_Hash_SHA1_init python_hashlib_Hacl_Hash_SHA1_init -#define Hacl_Hash_SHA1_update python_hashlib_Hacl_Hash_SHA1_update -#define Hacl_Hash_SHA1_digest python_hashlib_Hacl_Hash_SHA1_digest -#define Hacl_Hash_SHA1_free python_hashlib_Hacl_Hash_SHA1_free -#define Hacl_Hash_SHA1_copy python_hashlib_Hacl_Hash_SHA1_copy -#define Hacl_Hash_SHA1_hash python_hashlib_Hacl_Hash_SHA1_hash +#define Hacl_Hash_SHA1_malloc _Py_LibHacl_Hacl_Hash_SHA1_malloc +#define Hacl_Hash_SHA1_init _Py_LibHacl_Hacl_Hash_SHA1_init +#define Hacl_Hash_SHA1_update _Py_LibHacl_Hacl_Hash_SHA1_update +#define Hacl_Hash_SHA1_digest _Py_LibHacl_Hacl_Hash_SHA1_digest +#define Hacl_Hash_SHA1_free _Py_LibHacl_Hacl_Hash_SHA1_free +#define Hacl_Hash_SHA1_copy _Py_LibHacl_Hacl_Hash_SHA1_copy +#define Hacl_Hash_SHA1_hash _Py_LibHacl_Hacl_Hash_SHA1_hash -#define Hacl_Hash_SHA3_update_last_sha3 python_hashlib_Hacl_Hash_SHA3_update_last_sha3 -#define Hacl_Hash_SHA3_update_multi_sha3 python_hashlib_Hacl_Hash_SHA3_update_multi_sha3 -#define Hacl_Impl_SHA3_absorb_inner python_hashlib_Hacl_Impl_SHA3_absorb_inner -#define Hacl_Impl_SHA3_keccak python_hashlib_Hacl_Impl_SHA3_keccak -#define Hacl_Impl_SHA3_loadState python_hashlib_Hacl_Impl_SHA3_loadState -#define Hacl_Impl_SHA3_squeeze python_hashlib_Hacl_Impl_SHA3_squeeze -#define Hacl_Impl_SHA3_state_permute python_hashlib_Hacl_Impl_SHA3_state_permute -#define Hacl_SHA3_sha3_224 python_hashlib_Hacl_SHA3_sha3_224 -#define Hacl_SHA3_sha3_256 python_hashlib_Hacl_SHA3_sha3_256 -#define Hacl_SHA3_sha3_384 python_hashlib_Hacl_SHA3_sha3_384 -#define Hacl_SHA3_sha3_512 python_hashlib_Hacl_SHA3_sha3_512 -#define Hacl_SHA3_shake128_hacl python_hashlib_Hacl_SHA3_shake128_hacl -#define Hacl_SHA3_shake256_hacl python_hashlib_Hacl_SHA3_shake256_hacl -#define Hacl_Hash_SHA3_block_len python_hashlib_Hacl_Hash_SHA3_block_len -#define Hacl_Hash_SHA3_copy python_hashlib_Hacl_Hash_SHA3_copy -#define Hacl_Hash_SHA3_digest python_hashlib_Hacl_Hash_SHA3_digest -#define Hacl_Hash_SHA3_free python_hashlib_Hacl_Hash_SHA3_free -#define Hacl_Hash_SHA3_get_alg python_hashlib_Hacl_Hash_SHA3_get_alg -#define Hacl_Hash_SHA3_hash_len python_hashlib_Hacl_Hash_SHA3_hash_len -#define Hacl_Hash_SHA3_is_shake python_hashlib_Hacl_Hash_SHA3_is_shake -#define Hacl_Hash_SHA3_malloc python_hashlib_Hacl_Hash_SHA3_malloc -#define Hacl_Hash_SHA3_reset python_hashlib_Hacl_Hash_SHA3_reset -#define Hacl_Hash_SHA3_update python_hashlib_Hacl_Hash_SHA3_update -#define Hacl_Hash_SHA3_squeeze python_hashlib_Hacl_Hash_SHA3_squeeze +#define Hacl_Hash_SHA3_update_last_sha3 _Py_LibHacl_Hacl_Hash_SHA3_update_last_sha3 +#define Hacl_Hash_SHA3_update_multi_sha3 _Py_LibHacl_Hacl_Hash_SHA3_update_multi_sha3 +#define Hacl_Impl_SHA3_absorb_inner _Py_LibHacl_Hacl_Impl_SHA3_absorb_inner +#define Hacl_Impl_SHA3_keccak _Py_LibHacl_Hacl_Impl_SHA3_keccak +#define Hacl_Impl_SHA3_loadState _Py_LibHacl_Hacl_Impl_SHA3_loadState +#define Hacl_Impl_SHA3_squeeze _Py_LibHacl_Hacl_Impl_SHA3_squeeze +#define Hacl_Impl_SHA3_state_permute _Py_LibHacl_Hacl_Impl_SHA3_state_permute +#define Hacl_SHA3_sha3_224 _Py_LibHacl_Hacl_SHA3_sha3_224 +#define Hacl_SHA3_sha3_256 _Py_LibHacl_Hacl_SHA3_sha3_256 +#define Hacl_SHA3_sha3_384 _Py_LibHacl_Hacl_SHA3_sha3_384 +#define Hacl_SHA3_sha3_512 _Py_LibHacl_Hacl_SHA3_sha3_512 +#define Hacl_SHA3_shake128_hacl _Py_LibHacl_Hacl_SHA3_shake128_hacl +#define Hacl_SHA3_shake256_hacl _Py_LibHacl_Hacl_SHA3_shake256_hacl +#define Hacl_Hash_SHA3_block_len _Py_LibHacl_Hacl_Hash_SHA3_block_len +#define Hacl_Hash_SHA3_copy _Py_LibHacl_Hacl_Hash_SHA3_copy +#define Hacl_Hash_SHA3_digest _Py_LibHacl_Hacl_Hash_SHA3_digest +#define Hacl_Hash_SHA3_free _Py_LibHacl_Hacl_Hash_SHA3_free +#define Hacl_Hash_SHA3_get_alg _Py_LibHacl_Hacl_Hash_SHA3_get_alg +#define Hacl_Hash_SHA3_hash_len _Py_LibHacl_Hacl_Hash_SHA3_hash_len +#define Hacl_Hash_SHA3_is_shake _Py_LibHacl_Hacl_Hash_SHA3_is_shake +#define Hacl_Hash_SHA3_init_ _Py_LibHacl_Hacl_Hash_SHA3_init_ +#define Hacl_Hash_SHA3_malloc _Py_LibHacl_Hacl_Hash_SHA3_malloc +#define Hacl_Hash_SHA3_reset _Py_LibHacl_Hacl_Hash_SHA3_reset +#define Hacl_Hash_SHA3_update _Py_LibHacl_Hacl_Hash_SHA3_update +#define Hacl_Hash_SHA3_squeeze _Py_LibHacl_Hacl_Hash_SHA3_squeeze -#define Hacl_Hash_Blake2b_Simd256_copy python_hashlib_Hacl_Hash_Blake2b_Simd256_copy -#define Hacl_Hash_Blake2b_Simd256_digest python_hashlib_Hacl_Hash_Blake2b_Simd256_digest -#define Hacl_Hash_Blake2b_Simd256_finish python_hashlib_Hacl_Hash_Blake2b_Simd256_finish -#define Hacl_Hash_Blake2b_Simd256_free python_hashlib_Hacl_Hash_Blake2b_Simd256_free -#define Hacl_Hash_Blake2b_Simd256_hash_with_key python_hashlib_Hacl_Hash_Blake2b_Simd256_hash_with_key -#define Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params python_hashlib_Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params -#define Hacl_Hash_Blake2b_Simd256_info python_hashlib_Hacl_Hash_Blake2b_Simd256_info -#define Hacl_Hash_Blake2b_Simd256_init python_hashlib_Hacl_Hash_Blake2b_Simd256_init -#define Hacl_Hash_Blake2b_Simd256_load_state256b_from_state32 python_hashlib_Hacl_Hash_Blake2b_Simd256_load_state256b_from_state32 -#define Hacl_Hash_Blake2b_Simd256_malloc python_hashlib_Hacl_Hash_Blake2b_Simd256_malloc -#define Hacl_Hash_Blake2b_Simd256_malloc_with_key python_hashlib_Hacl_Hash_Blake2b_Simd256_malloc_with_key -#define Hacl_Hash_Blake2b_Simd256_malloc_with_key0 python_hashlib_Hacl_Hash_Blake2b_Simd256_malloc_with_key0 -#define Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key python_hashlib_Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key -#define Hacl_Hash_Blake2b_Simd256_reset python_hashlib_Hacl_Hash_Blake2b_Simd256_reset -#define Hacl_Hash_Blake2b_Simd256_reset_with_key python_hashlib_Hacl_Hash_Blake2b_Simd256_reset_with_key -#define Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params python_hashlib_Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params -#define Hacl_Hash_Blake2b_Simd256_store_state256b_to_state32 python_hashlib_Hacl_Hash_Blake2b_Simd256_store_state256b_to_state32 -#define Hacl_Hash_Blake2b_Simd256_update python_hashlib_Hacl_Hash_Blake2b_Simd256_update -#define Hacl_Hash_Blake2b_Simd256_update_last python_hashlib_Hacl_Hash_Blake2b_Simd256_update_last -#define Hacl_Hash_Blake2b_Simd256_update_multi python_hashlib_Hacl_Hash_Blake2b_Simd256_update_multi -#define Hacl_Hash_Blake2b_copy python_hashlib_Hacl_Hash_Blake2b_copy -#define Hacl_Hash_Blake2b_digest python_hashlib_Hacl_Hash_Blake2b_digest -#define Hacl_Hash_Blake2b_finish python_hashlib_Hacl_Hash_Blake2b_finish -#define Hacl_Hash_Blake2b_free python_hashlib_Hacl_Hash_Blake2b_free -#define Hacl_Hash_Blake2b_hash_with_key python_hashlib_Hacl_Hash_Blake2b_hash_with_key -#define Hacl_Hash_Blake2b_hash_with_key_and_params python_hashlib_Hacl_Hash_Blake2b_hash_with_key_and_params -#define Hacl_Hash_Blake2b_info python_hashlib_Hacl_Hash_Blake2b_info -#define Hacl_Hash_Blake2b_init python_hashlib_Hacl_Hash_Blake2b_init -#define Hacl_Hash_Blake2b_malloc python_hashlib_Hacl_Hash_Blake2b_malloc -#define Hacl_Hash_Blake2b_malloc_with_key python_hashlib_Hacl_Hash_Blake2b_malloc_with_key -#define Hacl_Hash_Blake2b_malloc_with_params_and_key python_hashlib_Hacl_Hash_Blake2b_malloc_with_params_and_key -#define Hacl_Hash_Blake2b_reset python_hashlib_Hacl_Hash_Blake2b_reset -#define Hacl_Hash_Blake2b_reset_with_key python_hashlib_Hacl_Hash_Blake2b_reset_with_key -#define Hacl_Hash_Blake2b_reset_with_key_and_params python_hashlib_Hacl_Hash_Blake2b_reset_with_key_and_params -#define Hacl_Hash_Blake2b_update python_hashlib_Hacl_Hash_Blake2b_update -#define Hacl_Hash_Blake2b_update_last python_hashlib_Hacl_Hash_Blake2b_update_last -#define Hacl_Hash_Blake2b_update_multi python_hashlib_Hacl_Hash_Blake2b_update_multi -#define Hacl_Hash_Blake2s_Simd128_copy python_hashlib_Hacl_Hash_Blake2s_Simd128_copy -#define Hacl_Hash_Blake2s_Simd128_digest python_hashlib_Hacl_Hash_Blake2s_Simd128_digest -#define Hacl_Hash_Blake2s_Simd128_finish python_hashlib_Hacl_Hash_Blake2s_Simd128_finish -#define Hacl_Hash_Blake2s_Simd128_free python_hashlib_Hacl_Hash_Blake2s_Simd128_free -#define Hacl_Hash_Blake2s_Simd128_hash_with_key python_hashlib_Hacl_Hash_Blake2s_Simd128_hash_with_key -#define Hacl_Hash_Blake2s_Simd128_hash_with_key_and_params python_hashlib_Hacl_Hash_Blake2s_Simd128_hash_with_key_and_params -#define Hacl_Hash_Blake2s_Simd128_info python_hashlib_Hacl_Hash_Blake2s_Simd128_info -#define Hacl_Hash_Blake2s_Simd128_init python_hashlib_Hacl_Hash_Blake2s_Simd128_init -#define Hacl_Hash_Blake2s_Simd128_load_state128s_from_state32 python_hashlib_Hacl_Hash_Blake2s_Simd128_load_state128s_from_state32 -#define Hacl_Hash_Blake2s_Simd128_malloc python_hashlib_Hacl_Hash_Blake2s_Simd128_malloc -#define Hacl_Hash_Blake2s_Simd128_malloc_with_key python_hashlib_Hacl_Hash_Blake2s_Simd128_malloc_with_key -#define Hacl_Hash_Blake2s_Simd128_malloc_with_key0 python_hashlib_Hacl_Hash_Blake2s_Simd128_malloc_with_key0 -#define Hacl_Hash_Blake2s_Simd128_malloc_with_params_and_key python_hashlib_Hacl_Hash_Blake2s_Simd128_malloc_with_params_and_key -#define Hacl_Hash_Blake2s_Simd128_reset python_hashlib_Hacl_Hash_Blake2s_Simd128_reset -#define Hacl_Hash_Blake2s_Simd128_reset_with_key python_hashlib_Hacl_Hash_Blake2s_Simd128_reset_with_key -#define Hacl_Hash_Blake2s_Simd128_reset_with_key_and_params python_hashlib_Hacl_Hash_Blake2s_Simd128_reset_with_key_and_params -#define Hacl_Hash_Blake2s_Simd128_store_state128s_to_state32 python_hashlib_Hacl_Hash_Blake2s_Simd128_store_state128s_to_state32 -#define Hacl_Hash_Blake2s_Simd128_update python_hashlib_Hacl_Hash_Blake2s_Simd128_update -#define Hacl_Hash_Blake2s_Simd128_update_last python_hashlib_Hacl_Hash_Blake2s_Simd128_update_last -#define Hacl_Hash_Blake2s_Simd128_update_multi python_hashlib_Hacl_Hash_Blake2s_Simd128_update_multi -#define Hacl_Hash_Blake2s_copy python_hashlib_Hacl_Hash_Blake2s_copy -#define Hacl_Hash_Blake2s_digest python_hashlib_Hacl_Hash_Blake2s_digest -#define Hacl_Hash_Blake2s_finish python_hashlib_Hacl_Hash_Blake2s_finish -#define Hacl_Hash_Blake2s_free python_hashlib_Hacl_Hash_Blake2s_free -#define Hacl_Hash_Blake2s_hash_with_key python_hashlib_Hacl_Hash_Blake2s_hash_with_key -#define Hacl_Hash_Blake2s_hash_with_key_and_params python_hashlib_Hacl_Hash_Blake2s_hash_with_key_and_params -#define Hacl_Hash_Blake2s_info python_hashlib_Hacl_Hash_Blake2s_info -#define Hacl_Hash_Blake2s_init python_hashlib_Hacl_Hash_Blake2s_init -#define Hacl_Hash_Blake2s_malloc python_hashlib_Hacl_Hash_Blake2s_malloc -#define Hacl_Hash_Blake2s_malloc_with_key python_hashlib_Hacl_Hash_Blake2s_malloc_with_key -#define Hacl_Hash_Blake2s_malloc_with_params_and_key python_hashlib_Hacl_Hash_Blake2s_malloc_with_params_and_key -#define Hacl_Hash_Blake2s_reset python_hashlib_Hacl_Hash_Blake2s_reset -#define Hacl_Hash_Blake2s_reset_with_key python_hashlib_Hacl_Hash_Blake2s_reset_with_key -#define Hacl_Hash_Blake2s_reset_with_key_and_params python_hashlib_Hacl_Hash_Blake2s_reset_with_key_and_params -#define Hacl_Hash_Blake2s_update python_hashlib_Hacl_Hash_Blake2s_update -#define Hacl_Hash_Blake2s_update_last python_hashlib_Hacl_Hash_Blake2s_update_last -#define Hacl_Hash_Blake2s_update_multi python_hashlib_Hacl_Hash_Blake2s_update_multi -#define Hacl_Hash_MD5_finish python_hashlib_Hacl_Hash_MD5_finish -#define Hacl_Hash_MD5_hash_oneshot python_hashlib_Hacl_Hash_MD5_hash_oneshot -#define Hacl_Hash_MD5_reset python_hashlib_Hacl_Hash_MD5_reset -#define Hacl_Hash_MD5_update_last python_hashlib_Hacl_Hash_MD5_update_last -#define Hacl_Hash_MD5_update_multi python_hashlib_Hacl_Hash_MD5_update_multi -#define Hacl_Hash_SHA1_finish python_hashlib_Hacl_Hash_SHA1_finish -#define Hacl_Hash_SHA1_hash_oneshot python_hashlib_Hacl_Hash_SHA1_hash_oneshot -#define Hacl_Hash_SHA1_reset python_hashlib_Hacl_Hash_SHA1_reset -#define Hacl_Hash_SHA1_update_last python_hashlib_Hacl_Hash_SHA1_update_last -#define Hacl_Hash_SHA1_update_multi python_hashlib_Hacl_Hash_SHA1_update_multi -#define Hacl_Hash_SHA2_hash_224 python_hashlib_Hacl_Hash_SHA2_hash_224 -#define Hacl_Hash_SHA2_hash_256 python_hashlib_Hacl_Hash_SHA2_hash_256 -#define Hacl_Hash_SHA2_hash_384 python_hashlib_Hacl_Hash_SHA2_hash_384 -#define Hacl_Hash_SHA2_hash_512 python_hashlib_Hacl_Hash_SHA2_hash_512 -#define Hacl_Hash_SHA2_reset_224 python_hashlib_Hacl_Hash_SHA2_reset_224 -#define Hacl_Hash_SHA2_reset_256 python_hashlib_Hacl_Hash_SHA2_reset_256 -#define Hacl_Hash_SHA2_reset_384 python_hashlib_Hacl_Hash_SHA2_reset_384 -#define Hacl_Hash_SHA2_reset_512 python_hashlib_Hacl_Hash_SHA2_reset_512 -#define Hacl_Hash_SHA2_sha224_finish python_hashlib_Hacl_Hash_SHA2_sha224_finish -#define Hacl_Hash_SHA2_sha224_init python_hashlib_Hacl_Hash_SHA2_sha224_init -#define Hacl_Hash_SHA2_sha224_update_last python_hashlib_Hacl_Hash_SHA2_sha224_update_last -#define Hacl_Hash_SHA2_sha256_finish python_hashlib_Hacl_Hash_SHA2_sha256_finish -#define Hacl_Hash_SHA2_sha256_init python_hashlib_Hacl_Hash_SHA2_sha256_init -#define Hacl_Hash_SHA2_sha256_update_last python_hashlib_Hacl_Hash_SHA2_sha256_update_last -#define Hacl_Hash_SHA2_sha256_update_nblocks python_hashlib_Hacl_Hash_SHA2_sha256_update_nblocks -#define Hacl_Hash_SHA2_sha384_finish python_hashlib_Hacl_Hash_SHA2_sha384_finish -#define Hacl_Hash_SHA2_sha384_init python_hashlib_Hacl_Hash_SHA2_sha384_init -#define Hacl_Hash_SHA2_sha384_update_last python_hashlib_Hacl_Hash_SHA2_sha384_update_last -#define Hacl_Hash_SHA2_sha384_update_nblocks python_hashlib_Hacl_Hash_SHA2_sha384_update_nblocks -#define Hacl_Hash_SHA2_sha512_finish python_hashlib_Hacl_Hash_SHA2_sha512_finish -#define Hacl_Hash_SHA2_sha512_init python_hashlib_Hacl_Hash_SHA2_sha512_init -#define Hacl_Hash_SHA2_sha512_update_last python_hashlib_Hacl_Hash_SHA2_sha512_update_last -#define Hacl_Hash_SHA2_sha512_update_nblocks python_hashlib_Hacl_Hash_SHA2_sha512_update_nblocks -#define Hacl_Hash_SHA3_absorb_inner_32 python_hashlib_Hacl_Hash_SHA3_absorb_inner_32 -#define Hacl_Hash_SHA3_keccak_piln python_hashlib_Hacl_Hash_SHA3_keccak_piln -#define Hacl_Hash_SHA3_keccak_rndc python_hashlib_Hacl_Hash_SHA3_keccak_rndc -#define Hacl_Hash_SHA3_keccak_rotc python_hashlib_Hacl_Hash_SHA3_keccak_rotc -#define Hacl_Hash_SHA3_sha3_224 python_hashlib_Hacl_Hash_SHA3_sha3_224 -#define Hacl_Hash_SHA3_sha3_256 python_hashlib_Hacl_Hash_SHA3_sha3_256 -#define Hacl_Hash_SHA3_sha3_384 python_hashlib_Hacl_Hash_SHA3_sha3_384 -#define Hacl_Hash_SHA3_sha3_512 python_hashlib_Hacl_Hash_SHA3_sha3_512 -#define Hacl_Hash_SHA3_shake128 python_hashlib_Hacl_Hash_SHA3_shake128 -#define Hacl_Hash_SHA3_shake128_absorb_final python_hashlib_Hacl_Hash_SHA3_shake128_absorb_final -#define Hacl_Hash_SHA3_shake128_absorb_nblocks python_hashlib_Hacl_Hash_SHA3_shake128_absorb_nblocks -#define Hacl_Hash_SHA3_shake128_squeeze_nblocks python_hashlib_Hacl_Hash_SHA3_shake128_squeeze_nblocks -#define Hacl_Hash_SHA3_shake256 python_hashlib_Hacl_Hash_SHA3_shake256 -#define Hacl_Hash_SHA3_state_free python_hashlib_Hacl_Hash_SHA3_state_free -#define Hacl_Hash_SHA3_state_malloc python_hashlib_Hacl_Hash_SHA3_state_malloc +#define Hacl_Hash_Blake2b_Simd256_copy _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_copy +#define Hacl_Hash_Blake2b_Simd256_copy_internal_state _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_copy_internal_state +#define Hacl_Hash_Blake2b_Simd256_digest _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_digest +#define Hacl_Hash_Blake2b_Simd256_finish _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_finish +#define Hacl_Hash_Blake2b_Simd256_free _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_free +#define Hacl_Hash_Blake2b_Simd256_hash_with_key _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_hash_with_key +#define Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params +#define Hacl_Hash_Blake2b_Simd256_info _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_info +#define Hacl_Hash_Blake2b_Simd256_init _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_init +#define Hacl_Hash_Blake2b_Simd256_load_state256b_from_state32 _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_load_state256b_from_state32 +#define Hacl_Hash_Blake2b_Simd256_malloc _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_malloc +#define Hacl_Hash_Blake2b_Simd256_malloc_internal_state_with_key _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_malloc_internal_state_with_key +#define Hacl_Hash_Blake2b_Simd256_malloc_with_key _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_malloc_with_key +#define Hacl_Hash_Blake2b_Simd256_malloc_with_key0 _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_malloc_with_key0 +#define Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key +#define Hacl_Hash_Blake2b_Simd256_reset _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_reset +#define Hacl_Hash_Blake2b_Simd256_reset_with_key _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_reset_with_key +#define Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params +#define Hacl_Hash_Blake2b_Simd256_store_state256b_to_state32 _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_store_state256b_to_state32 +#define Hacl_Hash_Blake2b_Simd256_update _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_update +#define Hacl_Hash_Blake2b_Simd256_update_last _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_update_last +#define Hacl_Hash_Blake2b_Simd256_update_last_no_inline _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_update_last_no_inline +#define Hacl_Hash_Blake2b_Simd256_update_multi _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_update_multi +#define Hacl_Hash_Blake2b_Simd256_update_multi_no_inline _Py_LibHacl_Hacl_Hash_Blake2b_Simd256_update_multi_no_inline +#define Hacl_Hash_Blake2b_copy _Py_LibHacl_Hacl_Hash_Blake2b_copy +#define Hacl_Hash_Blake2b_digest _Py_LibHacl_Hacl_Hash_Blake2b_digest +#define Hacl_Hash_Blake2b_finish _Py_LibHacl_Hacl_Hash_Blake2b_finish +#define Hacl_Hash_Blake2b_free _Py_LibHacl_Hacl_Hash_Blake2b_free +#define Hacl_Hash_Blake2b_hash_with_key _Py_LibHacl_Hacl_Hash_Blake2b_hash_with_key +#define Hacl_Hash_Blake2b_hash_with_key_and_params _Py_LibHacl_Hacl_Hash_Blake2b_hash_with_key_and_params +#define Hacl_Hash_Blake2b_info _Py_LibHacl_Hacl_Hash_Blake2b_info +#define Hacl_Hash_Blake2b_init _Py_LibHacl_Hacl_Hash_Blake2b_init +#define Hacl_Hash_Blake2b_malloc _Py_LibHacl_Hacl_Hash_Blake2b_malloc +#define Hacl_Hash_Blake2b_malloc_with_key _Py_LibHacl_Hacl_Hash_Blake2b_malloc_with_key +#define Hacl_Hash_Blake2b_malloc_with_params_and_key _Py_LibHacl_Hacl_Hash_Blake2b_malloc_with_params_and_key +#define Hacl_Hash_Blake2b_reset _Py_LibHacl_Hacl_Hash_Blake2b_reset +#define Hacl_Hash_Blake2b_reset_with_key _Py_LibHacl_Hacl_Hash_Blake2b_reset_with_key +#define Hacl_Hash_Blake2b_reset_with_key_and_params _Py_LibHacl_Hacl_Hash_Blake2b_reset_with_key_and_params +#define Hacl_Hash_Blake2b_update _Py_LibHacl_Hacl_Hash_Blake2b_update +#define Hacl_Hash_Blake2b_update_last _Py_LibHacl_Hacl_Hash_Blake2b_update_last +#define Hacl_Hash_Blake2b_update_multi _Py_LibHacl_Hacl_Hash_Blake2b_update_multi +#define Hacl_Hash_Blake2s_Simd128_copy _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_copy +#define Hacl_Hash_Blake2s_Simd128_copy_internal_state _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_copy_internal_state +#define Hacl_Hash_Blake2s_Simd128_digest _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_digest +#define Hacl_Hash_Blake2s_Simd128_finish _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_finish +#define Hacl_Hash_Blake2s_Simd128_free _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_free +#define Hacl_Hash_Blake2s_Simd128_hash_with_key _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_hash_with_key +#define Hacl_Hash_Blake2s_Simd128_hash_with_key_and_params _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_hash_with_key_and_params +#define Hacl_Hash_Blake2s_Simd128_info _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_info +#define Hacl_Hash_Blake2s_Simd128_init _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_init +#define Hacl_Hash_Blake2s_Simd128_load_state128s_from_state32 _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_load_state128s_from_state32 +#define Hacl_Hash_Blake2s_Simd128_malloc _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_malloc +#define Hacl_Hash_Blake2s_Simd128_malloc_internal_state_with_key _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_malloc_internal_state_with_key +#define Hacl_Hash_Blake2s_Simd128_malloc_with_key _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_malloc_with_key +#define Hacl_Hash_Blake2s_Simd128_malloc_with_key0 _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_malloc_with_key0 +#define Hacl_Hash_Blake2s_Simd128_malloc_with_params_and_key _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_malloc_with_params_and_key +#define Hacl_Hash_Blake2s_Simd128_reset _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_reset +#define Hacl_Hash_Blake2s_Simd128_reset_with_key _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_reset_with_key +#define Hacl_Hash_Blake2s_Simd128_reset_with_key_and_params _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_reset_with_key_and_params +#define Hacl_Hash_Blake2s_Simd128_store_state128s_to_state32 _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_store_state128s_to_state32 +#define Hacl_Hash_Blake2s_Simd128_update _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_update +#define Hacl_Hash_Blake2s_Simd128_update_last _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_update_last +#define Hacl_Hash_Blake2s_Simd128_update_last_no_inline _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_update_last_no_inline +#define Hacl_Hash_Blake2s_Simd128_update_multi _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_update_multi +#define Hacl_Hash_Blake2s_Simd128_update_multi_no_inline _Py_LibHacl_Hacl_Hash_Blake2s_Simd128_update_multi_no_inline +#define Hacl_Hash_Blake2s_copy _Py_LibHacl_Hacl_Hash_Blake2s_copy +#define Hacl_Hash_Blake2s_digest _Py_LibHacl_Hacl_Hash_Blake2s_digest +#define Hacl_Hash_Blake2s_finish _Py_LibHacl_Hacl_Hash_Blake2s_finish +#define Hacl_Hash_Blake2s_free _Py_LibHacl_Hacl_Hash_Blake2s_free +#define Hacl_Hash_Blake2s_hash_with_key _Py_LibHacl_Hacl_Hash_Blake2s_hash_with_key +#define Hacl_Hash_Blake2s_hash_with_key_and_params _Py_LibHacl_Hacl_Hash_Blake2s_hash_with_key_and_params +#define Hacl_Hash_Blake2s_info _Py_LibHacl_Hacl_Hash_Blake2s_info +#define Hacl_Hash_Blake2s_init _Py_LibHacl_Hacl_Hash_Blake2s_init +#define Hacl_Hash_Blake2s_malloc _Py_LibHacl_Hacl_Hash_Blake2s_malloc +#define Hacl_Hash_Blake2s_malloc_with_key _Py_LibHacl_Hacl_Hash_Blake2s_malloc_with_key +#define Hacl_Hash_Blake2s_malloc_with_params_and_key _Py_LibHacl_Hacl_Hash_Blake2s_malloc_with_params_and_key +#define Hacl_Hash_Blake2s_reset _Py_LibHacl_Hacl_Hash_Blake2s_reset +#define Hacl_Hash_Blake2s_reset_with_key _Py_LibHacl_Hacl_Hash_Blake2s_reset_with_key +#define Hacl_Hash_Blake2s_reset_with_key_and_params _Py_LibHacl_Hacl_Hash_Blake2s_reset_with_key_and_params +#define Hacl_Hash_Blake2s_update _Py_LibHacl_Hacl_Hash_Blake2s_update +#define Hacl_Hash_Blake2s_update_last _Py_LibHacl_Hacl_Hash_Blake2s_update_last +#define Hacl_Hash_Blake2s_update_multi _Py_LibHacl_Hacl_Hash_Blake2s_update_multi +#define Hacl_Hash_MD5_finish _Py_LibHacl_Hacl_Hash_MD5_finish +#define Hacl_Hash_MD5_hash_oneshot _Py_LibHacl_Hacl_Hash_MD5_hash_oneshot +#define Hacl_Hash_MD5_reset _Py_LibHacl_Hacl_Hash_MD5_reset +#define Hacl_Hash_MD5_update_last _Py_LibHacl_Hacl_Hash_MD5_update_last +#define Hacl_Hash_MD5_update_multi _Py_LibHacl_Hacl_Hash_MD5_update_multi +#define Hacl_Hash_SHA1_finish _Py_LibHacl_Hacl_Hash_SHA1_finish +#define Hacl_Hash_SHA1_hash_oneshot _Py_LibHacl_Hacl_Hash_SHA1_hash_oneshot +#define Hacl_Hash_SHA1_reset _Py_LibHacl_Hacl_Hash_SHA1_reset +#define Hacl_Hash_SHA1_update_last _Py_LibHacl_Hacl_Hash_SHA1_update_last +#define Hacl_Hash_SHA1_update_multi _Py_LibHacl_Hacl_Hash_SHA1_update_multi +#define Hacl_Hash_SHA2_hash_224 _Py_LibHacl_Hacl_Hash_SHA2_hash_224 +#define Hacl_Hash_SHA2_hash_256 _Py_LibHacl_Hacl_Hash_SHA2_hash_256 +#define Hacl_Hash_SHA2_hash_384 _Py_LibHacl_Hacl_Hash_SHA2_hash_384 +#define Hacl_Hash_SHA2_hash_512 _Py_LibHacl_Hacl_Hash_SHA2_hash_512 +#define Hacl_Hash_SHA2_reset_224 _Py_LibHacl_Hacl_Hash_SHA2_reset_224 +#define Hacl_Hash_SHA2_reset_256 _Py_LibHacl_Hacl_Hash_SHA2_reset_256 +#define Hacl_Hash_SHA2_reset_384 _Py_LibHacl_Hacl_Hash_SHA2_reset_384 +#define Hacl_Hash_SHA2_reset_512 _Py_LibHacl_Hacl_Hash_SHA2_reset_512 +#define Hacl_Hash_SHA2_sha224_finish _Py_LibHacl_Hacl_Hash_SHA2_sha224_finish +#define Hacl_Hash_SHA2_sha224_init _Py_LibHacl_Hacl_Hash_SHA2_sha224_init +#define Hacl_Hash_SHA2_sha224_update_last _Py_LibHacl_Hacl_Hash_SHA2_sha224_update_last +#define Hacl_Hash_SHA2_sha224_update_nblocks _Py_LibHacl_Hacl_Hash_SHA2_sha224_update_nblocks +#define Hacl_Hash_SHA2_sha256_finish _Py_LibHacl_Hacl_Hash_SHA2_sha256_finish +#define Hacl_Hash_SHA2_sha256_init _Py_LibHacl_Hacl_Hash_SHA2_sha256_init +#define Hacl_Hash_SHA2_sha256_update_last _Py_LibHacl_Hacl_Hash_SHA2_sha256_update_last +#define Hacl_Hash_SHA2_sha256_update_nblocks _Py_LibHacl_Hacl_Hash_SHA2_sha256_update_nblocks +#define Hacl_Hash_SHA2_sha384_finish _Py_LibHacl_Hacl_Hash_SHA2_sha384_finish +#define Hacl_Hash_SHA2_sha384_init _Py_LibHacl_Hacl_Hash_SHA2_sha384_init +#define Hacl_Hash_SHA2_sha384_update_last _Py_LibHacl_Hacl_Hash_SHA2_sha384_update_last +#define Hacl_Hash_SHA2_sha384_update_nblocks _Py_LibHacl_Hacl_Hash_SHA2_sha384_update_nblocks +#define Hacl_Hash_SHA2_sha512_finish _Py_LibHacl_Hacl_Hash_SHA2_sha512_finish +#define Hacl_Hash_SHA2_sha512_init _Py_LibHacl_Hacl_Hash_SHA2_sha512_init +#define Hacl_Hash_SHA2_sha512_update_last _Py_LibHacl_Hacl_Hash_SHA2_sha512_update_last +#define Hacl_Hash_SHA2_sha512_update_nblocks _Py_LibHacl_Hacl_Hash_SHA2_sha512_update_nblocks +#define Hacl_Hash_SHA3_absorb_inner_32 _Py_LibHacl_Hacl_Hash_SHA3_absorb_inner_32 +#define Hacl_Hash_SHA3_keccak_piln _Py_LibHacl_Hacl_Hash_SHA3_keccak_piln +#define Hacl_Hash_SHA3_keccak_rndc _Py_LibHacl_Hacl_Hash_SHA3_keccak_rndc +#define Hacl_Hash_SHA3_keccak_rotc _Py_LibHacl_Hacl_Hash_SHA3_keccak_rotc +#define Hacl_Hash_SHA3_sha3_224 _Py_LibHacl_Hacl_Hash_SHA3_sha3_224 +#define Hacl_Hash_SHA3_sha3_256 _Py_LibHacl_Hacl_Hash_SHA3_sha3_256 +#define Hacl_Hash_SHA3_sha3_384 _Py_LibHacl_Hacl_Hash_SHA3_sha3_384 +#define Hacl_Hash_SHA3_sha3_512 _Py_LibHacl_Hacl_Hash_SHA3_sha3_512 +#define Hacl_Hash_SHA3_shake128 _Py_LibHacl_Hacl_Hash_SHA3_shake128 +#define Hacl_Hash_SHA3_shake128_absorb_final _Py_LibHacl_Hacl_Hash_SHA3_shake128_absorb_final +#define Hacl_Hash_SHA3_shake128_absorb_nblocks _Py_LibHacl_Hacl_Hash_SHA3_shake128_absorb_nblocks +#define Hacl_Hash_SHA3_shake128_squeeze_nblocks _Py_LibHacl_Hacl_Hash_SHA3_shake128_squeeze_nblocks +#define Hacl_Hash_SHA3_shake256 _Py_LibHacl_Hacl_Hash_SHA3_shake256 +#define Hacl_Hash_SHA3_state_free _Py_LibHacl_Hacl_Hash_SHA3_state_free +#define Hacl_Hash_SHA3_state_malloc _Py_LibHacl_Hacl_Hash_SHA3_state_malloc // Streaming HMAC -#define Hacl_Streaming_HMAC_malloc_ python_hashlib_Hacl_Streaming_HMAC_malloc_ -#define Hacl_Streaming_HMAC_get_impl python_hashlib_Hacl_Streaming_HMAC_get_impl -#define Hacl_Streaming_HMAC_reset python_hashlib_Hacl_Streaming_HMAC_reset -#define Hacl_Streaming_HMAC_update python_hashlib_Hacl_Streaming_HMAC_update -#define Hacl_Streaming_HMAC_digest python_hashlib_Hacl_Streaming_HMAC_digest -#define Hacl_Streaming_HMAC_copy python_hashlib_Hacl_Streaming_HMAC_copy -#define Hacl_Streaming_HMAC_free python_hashlib_Hacl_Streaming_HMAC_free +#define Hacl_Streaming_HMAC_index_of_state _Py_LibHacl_Hacl_Streaming_HMAC_index_of_state +#define Hacl_Streaming_HMAC_malloc_ _Py_LibHacl_Hacl_Streaming_HMAC_malloc_ +#define Hacl_Streaming_HMAC_get_impl _Py_LibHacl_Hacl_Streaming_HMAC_get_impl +#define Hacl_Streaming_HMAC_reset _Py_LibHacl_Hacl_Streaming_HMAC_reset +#define Hacl_Streaming_HMAC_update _Py_LibHacl_Hacl_Streaming_HMAC_update +#define Hacl_Streaming_HMAC_digest _Py_LibHacl_Hacl_Streaming_HMAC_digest +#define Hacl_Streaming_HMAC_copy _Py_LibHacl_Hacl_Streaming_HMAC_copy +#define Hacl_Streaming_HMAC_free _Py_LibHacl_Hacl_Streaming_HMAC_free +#define Hacl_Streaming_HMAC_s1 _Py_LibHacl_Hacl_Streaming_HMAC_s1 +#define Hacl_Streaming_HMAC_s2 _Py_LibHacl_Hacl_Streaming_HMAC_s2 // HMAC-MD5 -#define Hacl_HMAC_compute_md5 python_hashlib_Hacl_HMAC_compute_md5 +#define Hacl_HMAC_compute_md5 _Py_LibHacl_Hacl_HMAC_compute_md5 // HMAC-SHA-1 -#define Hacl_HMAC_compute_sha1 python_hashlib_Hacl_HMAC_compute_sha1 +#define Hacl_HMAC_compute_sha1 _Py_LibHacl_Hacl_HMAC_compute_sha1 // HMAC-SHA-2 -#define Hacl_HMAC_compute_sha2_224 python_hashlib_Hacl_HMAC_compute_sha2_224 -#define Hacl_HMAC_compute_sha2_256 python_hashlib_Hacl_HMAC_compute_sha2_256 -#define Hacl_HMAC_compute_sha2_384 python_hashlib_Hacl_HMAC_compute_sha2_384 -#define Hacl_HMAC_compute_sha2_512 python_hashlib_Hacl_HMAC_compute_sha2_512 +#define Hacl_HMAC_compute_sha2_224 _Py_LibHacl_Hacl_HMAC_compute_sha2_224 +#define Hacl_HMAC_compute_sha2_256 _Py_LibHacl_Hacl_HMAC_compute_sha2_256 +#define Hacl_HMAC_compute_sha2_384 _Py_LibHacl_Hacl_HMAC_compute_sha2_384 +#define Hacl_HMAC_compute_sha2_512 _Py_LibHacl_Hacl_HMAC_compute_sha2_512 // HMAC-SHA-3 -#define Hacl_HMAC_compute_sha3_224 python_hashlib_Hacl_HMAC_compute_sha3_224 -#define Hacl_HMAC_compute_sha3_256 python_hashlib_Hacl_HMAC_compute_sha3_256 -#define Hacl_HMAC_compute_sha3_384 python_hashlib_Hacl_HMAC_compute_sha3_384 -#define Hacl_HMAC_compute_sha3_512 python_hashlib_Hacl_HMAC_compute_sha3_512 +#define Hacl_HMAC_compute_sha3_224 _Py_LibHacl_Hacl_HMAC_compute_sha3_224 +#define Hacl_HMAC_compute_sha3_256 _Py_LibHacl_Hacl_HMAC_compute_sha3_256 +#define Hacl_HMAC_compute_sha3_384 _Py_LibHacl_Hacl_HMAC_compute_sha3_384 +#define Hacl_HMAC_compute_sha3_512 _Py_LibHacl_Hacl_HMAC_compute_sha3_512 // HMAC-BLAKE -#define Hacl_HMAC_compute_blake2s_32 python_hashlib_Hacl_HMAC_compute_blake2s_32 -#define Hacl_HMAC_compute_blake2b_32 python_hashlib_Hacl_HMAC_compute_blake2b_32 +#define Hacl_HMAC_compute_blake2s_32 _Py_LibHacl_Hacl_HMAC_compute_blake2s_32 +#define Hacl_HMAC_compute_blake2b_32 _Py_LibHacl_Hacl_HMAC_compute_blake2b_32 #endif // _PYTHON_HACL_NAMESPACES_H diff --git a/Modules/_hacl/refresh.sh b/Modules/_hacl/refresh.sh index 903d7fb2afd362..b50c9288aa9e43 100755 --- a/Modules/_hacl/refresh.sh +++ b/Modules/_hacl/refresh.sh @@ -145,6 +145,9 @@ $sed -i -z 's!#include !#include \n#include "python_hacl_nam Hacl_HMAC.h \ Hacl_Streaming_HMAC.h +$sed -i -z 's!#include !#include \n#include "python_hacl_namespaces.h"!' \ + lib_memzero0.h + # Step 3: trim whitespace (for the linter) find . -name '*.c' -or -name '*.h' | xargs $sed -i 's![[:space:]]\+$!!' From ca584d97d84d85505220ea99658e127667926d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 19 Apr 2025 12:56:49 +0200 Subject: [PATCH 10/13] fixup checksums --- Misc/sbom.spdx.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Misc/sbom.spdx.json b/Misc/sbom.spdx.json index cafda98ba2d59e..64f15424f34c14 100644 --- a/Misc/sbom.spdx.json +++ b/Misc/sbom.spdx.json @@ -888,11 +888,11 @@ "checksums": [ { "algorithm": "SHA1", - "checksumValue": "3d65f95f6f4bbfe980a89b82c55d02d7694a5a79" + "checksumValue": "66108dcbb7fc9e8aa7adcc440fede22c62164d92" }, { "algorithm": "SHA256", - "checksumValue": "0f8d744620cf5f6b8450da187484b418d24dec7d8cf72b757b7080e84cb3ae5e" + "checksumValue": "284079d2af21a570c58c82e54536b8b9bae0f0a321f229b242c92dc350d10bdf" } ], "fileName": "Modules/_hacl/lib_memzero0.h" @@ -930,11 +930,11 @@ "checksums": [ { "algorithm": "SHA1", - "checksumValue": "dbed915328619b1159012649a427c6928033dd90" + "checksumValue": "4a0bdb9496d49bbfa3ad50bb7854d8f099e84891" }, { "algorithm": "SHA256", - "checksumValue": "0297ea0a5d1117e001d5dbb90f99d47ee9e0f9d3dd45da02ba5dc477e551cb5a" + "checksumValue": "b1a45149239ee7af7de769a3e9339950d47c199bb9eaa10edce8a00fde603b12" } ], "fileName": "Modules/_hacl/python_hacl_namespaces.h" @@ -2432,4 +2432,4 @@ } ], "spdxVersion": "SPDX-2.3" -} \ No newline at end of file +} From f260cbbcde0ebfbb36c0909dc387a3a9323b0c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 19 Apr 2025 12:57:09 +0200 Subject: [PATCH 11/13] regen sbom --- Misc/sbom.spdx.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/sbom.spdx.json b/Misc/sbom.spdx.json index 64f15424f34c14..5da77f158cbf38 100644 --- a/Misc/sbom.spdx.json +++ b/Misc/sbom.spdx.json @@ -2432,4 +2432,4 @@ } ], "spdxVersion": "SPDX-2.3" -} +} \ No newline at end of file From 7f9868c82a81caa608fc17b48ee9ba44c9f3aca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 19 Apr 2025 13:21:36 +0200 Subject: [PATCH 12/13] fixup shell warnings and comments --- configure | 26 ++++++++++++++++---------- configure.ac | 26 ++++++++++++++++---------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/configure b/configure index a0b84f245aecb6..ba99e819425ee1 100755 --- a/configure +++ b/configure @@ -31927,17 +31927,21 @@ fi # # Example for MD5: # -# 1. Compile Modules/_hacl/Hacl_Hash_MD5.c into Modules/_hacl/Hacl_Hash_MD5.o. -# 2. Create Modules/_hacl/libHacl_Hash_MD5$EXT where $EXT is the extension -# for a static (resp. shared) library depending on whether we are on WASI. -# 3. Compile Modules/md5module.c into Modules/md5module.o. -# 4. Link Modules/md5module.o with Modules/_hacl/libHacl_Hash_MD5$EXT -# and get Modules/_md5$(EXT_SUFFIX). +# * Compile Modules/_hacl/Hacl_Hash_MD5.c into Modules/_hacl/Hacl_Hash_MD5.o. +# * Decide whether the object files are to be passed to the linker (emulate +# a shared library without having to install it) or if we need to create +# a static library for WASI. The following summarizes the values taken by +# the MODULE__LDFLAGS variable depending on the linkage type: +# - shared: MODULE__MD5_LDFLAGS is set to LIBHACL_MD5_OBJS +# - static: MODULE__MD5_LDFLAGS is set to Modules/_hacl/libHacl_Hash_MD5.a +# * Compile Modules/md5module.c into Modules/md5module.o. +# * Link Modules/md5module.o using $(MODULE__MD5_LDFLAGS) +# and get Modules/_md5$(EXT_SUFFIX). # # LIBHACL_FLAG_I: '-I' flags passed to $(CC) for HACL* and HACL*-based modules # LIBHACL_FLAG_D: '-D' flags passed to $(CC) for HACL* and HACL*-based modules -# LIBHACL_CFLAGS: flags passed $(CC) for HACL* and HACL*-based modules -# LIBHACL_LDFLAGS: flags passed $(LDSHARED) for HACL* and HACL*-based modules +# LIBHACL_CFLAGS: compiler flags passed for HACL* and HACL*-based modules +# LIBHACL_LDFLAGS: linker flags passed for HACL* and HACL*-based modules LIBHACL_FLAG_I='-I$(srcdir)/Modules/_hacl -I$(srcdir)/Modules/_hacl/include' LIBHACL_FLAG_D='-D_BSD_SOURCE -D_DEFAULT_SOURCE' case "$ac_sys_system" in @@ -31955,7 +31959,8 @@ LIBHACL_LDFLAGS= # for now, no specific linker flags are needed # The SIMD files use aligned_alloc, which is not available on older versions of # Android. # The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then +if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ + test -n "$ANDROID_API_LEVEL" -a "$ANDROID_API_LEVEL" -ge 28; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2" >&5 printf %s "checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2... " >&6; } if test ${ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2+y} @@ -32030,7 +32035,8 @@ fi # Although AVX support is not guaranteed on Android # (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a # runtime CPUID check. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then +if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ + test -n "$ANDROID_API_LEVEL" -a "$ANDROID_API_LEVEL" -ge 28; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -mavx2" >&5 printf %s "checking whether C compiler accepts -mavx2... " >&6; } if test ${ax_cv_check_cflags__Werror__mavx2+y} diff --git a/configure.ac b/configure.ac index 9f4ea6ca48648e..53270c5125ce68 100644 --- a/configure.ac +++ b/configure.ac @@ -7859,17 +7859,21 @@ PY_STDLIB_MOD_SIMPLE([unicodedata]) # # Example for MD5: # -# 1. Compile Modules/_hacl/Hacl_Hash_MD5.c into Modules/_hacl/Hacl_Hash_MD5.o. -# 2. Create Modules/_hacl/libHacl_Hash_MD5$EXT where $EXT is the extension -# for a static (resp. shared) library depending on whether we are on WASI. -# 3. Compile Modules/md5module.c into Modules/md5module.o. -# 4. Link Modules/md5module.o with Modules/_hacl/libHacl_Hash_MD5$EXT -# and get Modules/_md5$(EXT_SUFFIX). +# * Compile Modules/_hacl/Hacl_Hash_MD5.c into Modules/_hacl/Hacl_Hash_MD5.o. +# * Decide whether the object files are to be passed to the linker (emulate +# a shared library without having to install it) or if we need to create +# a static library for WASI. The following summarizes the values taken by +# the MODULE__LDFLAGS variable depending on the linkage type: +# - shared: MODULE__MD5_LDFLAGS is set to LIBHACL_MD5_OBJS +# - static: MODULE__MD5_LDFLAGS is set to Modules/_hacl/libHacl_Hash_MD5.a +# * Compile Modules/md5module.c into Modules/md5module.o. +# * Link Modules/md5module.o using $(MODULE__MD5_LDFLAGS) +# and get Modules/_md5$(EXT_SUFFIX). # # LIBHACL_FLAG_I: '-I' flags passed to $(CC) for HACL* and HACL*-based modules # LIBHACL_FLAG_D: '-D' flags passed to $(CC) for HACL* and HACL*-based modules -# LIBHACL_CFLAGS: flags passed $(CC) for HACL* and HACL*-based modules -# LIBHACL_LDFLAGS: flags passed $(LDSHARED) for HACL* and HACL*-based modules +# LIBHACL_CFLAGS: compiler flags passed for HACL* and HACL*-based modules +# LIBHACL_LDFLAGS: linker flags passed for HACL* and HACL*-based modules LIBHACL_FLAG_I='-I$(srcdir)/Modules/_hacl -I$(srcdir)/Modules/_hacl/include' LIBHACL_FLAG_D='-D_BSD_SOURCE -D_DEFAULT_SOURCE' case "$ac_sys_system" in @@ -7887,7 +7891,8 @@ AC_SUBST([LIBHACL_LDFLAGS]) # The SIMD files use aligned_alloc, which is not available on older versions of # Android. # The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then +if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ + test -n "$ANDROID_API_LEVEL" -a "$ANDROID_API_LEVEL" -ge 28; then dnl This can be extended here to detect e.g. Power8, which HACL* should also support. AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[ [LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"] @@ -7918,7 +7923,8 @@ AC_SUBST([LIBHACL_BLAKE2_SIMD128_OBJS]) # Although AVX support is not guaranteed on Android # (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a # runtime CPUID check. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then +if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ + test -n "$ANDROID_API_LEVEL" -a "$ANDROID_API_LEVEL" -ge 28; then AX_CHECK_COMPILE_FLAG([-mavx2],[ [LIBHACL_SIMD256_FLAGS="-mavx2"] AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations]) From c87bb273a6c80cab569472113736047f549967a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 19 Apr 2025 15:40:16 +0200 Subject: [PATCH 13/13] it *should* work --- Makefile.pre.in | 12 ++++++------ configure | 8 +++++--- configure.ac | 8 +++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 7331a778415b98..886bd7ae1c504d 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -3313,17 +3313,17 @@ MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h # HACL*-based cryptographic primitives -MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) +MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(LIBHACL_MD5_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__MD5_LDEPS=$(LIBHACL_MD5_LIB_@LIBHACL_LDEPS_LIBTYPE@) -MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) +MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA1_HEADERS) $(LIBHACL_SHA1_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__SHA1_LDEPS=$(LIBHACL_SHA1_LIB_@LIBHACL_LDEPS_LIBTYPE@) -MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) +MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_SHA2_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__SHA2_LDEPS=$(LIBHACL_SHA2_LIB_@LIBHACL_LDEPS_LIBTYPE@) -MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) +MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA3_HEADERS) $(LIBHACL_SHA3_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__SHA3_LDEPS=$(LIBHACL_SHA3_LIB_@LIBHACL_LDEPS_LIBTYPE@) -MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) +MODULE__BLAKE2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_BLAKE2_HEADERS) $(LIBHACL_BLAKE2_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__BLAKE2_LDEPS=$(LIBHACL_BLAKE2_LIB_@LIBHACL_LDEPS_LIBTYPE@) -MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) +MODULE__HMAC_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HMAC_HEADERS) $(LIBHACL_HMAC_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__HMAC_LDEPS=$(LIBHACL_HMAC_LIB_@LIBHACL_LDEPS_LIBTYPE@) MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c diff --git a/configure b/configure index ba99e819425ee1..284263dff48f87 100755 --- a/configure +++ b/configure @@ -31951,7 +31951,7 @@ case "$ac_sys_system" in fi ;; esac -LIBHACL_CFLAGS="\$(CCSHARED) ${LIBHACL_FLAG_I} ${LIBHACL_FLAG_D}" +LIBHACL_CFLAGS="${LIBHACL_FLAG_I} ${LIBHACL_FLAG_D} \$(PY_STDMODULE_CFLAGS) \$(CCSHARED)" LIBHACL_LDFLAGS= # for now, no specific linker flags are needed @@ -31960,7 +31960,8 @@ LIBHACL_LDFLAGS= # for now, no specific linker flags are needed # Android. # The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ - test -n "$ANDROID_API_LEVEL" -a "$ANDROID_API_LEVEL" -ge 28; then + { test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; } +then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2" >&5 printf %s "checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2... " >&6; } if test ${ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2+y} @@ -32036,7 +32037,8 @@ fi # (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a # runtime CPUID check. if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ - test -n "$ANDROID_API_LEVEL" -a "$ANDROID_API_LEVEL" -ge 28; then + { test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; } +then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -mavx2" >&5 printf %s "checking whether C compiler accepts -mavx2... " >&6; } if test ${ax_cv_check_cflags__Werror__mavx2+y} diff --git a/configure.ac b/configure.ac index 53270c5125ce68..99ebe111cfb184 100644 --- a/configure.ac +++ b/configure.ac @@ -7883,7 +7883,7 @@ case "$ac_sys_system" in fi ;; esac -LIBHACL_CFLAGS="\$(CCSHARED) ${LIBHACL_FLAG_I} ${LIBHACL_FLAG_D}" +LIBHACL_CFLAGS="${LIBHACL_FLAG_I} ${LIBHACL_FLAG_D} \$(PY_STDMODULE_CFLAGS) \$(CCSHARED)" AC_SUBST([LIBHACL_CFLAGS]) LIBHACL_LDFLAGS= # for now, no specific linker flags are needed AC_SUBST([LIBHACL_LDFLAGS]) @@ -7892,7 +7892,8 @@ AC_SUBST([LIBHACL_LDFLAGS]) # Android. # The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ - test -n "$ANDROID_API_LEVEL" -a "$ANDROID_API_LEVEL" -ge 28; then + { test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; } +then dnl This can be extended here to detect e.g. Power8, which HACL* should also support. AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[ [LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"] @@ -7924,7 +7925,8 @@ AC_SUBST([LIBHACL_BLAKE2_SIMD128_OBJS]) # (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a # runtime CPUID check. if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ - test -n "$ANDROID_API_LEVEL" -a "$ANDROID_API_LEVEL" -ge 28; then + { test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; } +then AX_CHECK_COMPILE_FLAG([-mavx2],[ [LIBHACL_SIMD256_FLAGS="-mavx2"] AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations]) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy