Skip to content

gh-131876: extract _hashlib helpers into a separate directory #136995

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update build configuration
  • Loading branch information
picnixz committed Jul 22, 2025
commit e1d233e6e8dfe365ba268798e6dc37fcb311e400
37 changes: 30 additions & 7 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ ENSUREPIP= @ENSUREPIP@
# Internal static libraries
LIBMPDEC_A= Modules/_decimal/libmpdec/libmpdec.a
LIBEXPAT_A= Modules/expat/libexpat.a
LIBHASHLIB_INTERNAL_A=Modules/_hashlib/libhashlib.a

# HACL* build configuration
LIBHACL_CFLAGS=@LIBHACL_CFLAGS@
Expand Down Expand Up @@ -761,6 +762,17 @@ LIBHACL_HMAC_HEADERS= \
$(LIBHACL_BLAKE2_HEADERS) \
$(LIBHACL_HEADERS)

##########################################################################
# Internal library for cryptographic primitives

LIBHASHLIB_INTERNAL_OBJS= \
Modules/_hashlib/hashlib_buffer.o

LIBHASHLIB_INTERNAL_HEADERS= \
Modules/_hashlib/hashlib_buffer.h \
Modules/_hashlib/hashlib_fetch.h \
Modules/_hashlib/hashlib_mutex.h

#########################################################################
# Rules

Expand Down Expand Up @@ -1511,6 +1523,17 @@ $(LIBEXPAT_A): $(LIBEXPAT_OBJS)
-rm -f $@
$(AR) $(ARFLAGS) $@ $(LIBEXPAT_OBJS)

##########################################################################
# '_hashlib', '_hmac' and HACL*-based modules helpers
LIBHASHLIB_INTERNAL_CFLAGS=@LIBHASHLIB_INTERNAL_CFLAGS@ $(PY_STDMODULE_CFLAGS) $(CCSHARED)

Modules/_hashlib/hashlib_buffer.o: Modules/_hashlib/hashlib_buffer.c $(LIBHASHLIB_INTERNAL_HEADERS) $(PYTHON_HEADERS)
$(CC) -I$(srcdir)/Modules/_hashlib -c $(LIBHASHLIB_INTERNAL_CFLAGS) -o $@ $(srcdir)/Modules/_hashlib/hashlib_buffer.c

$(LIBHASHLIB_INTERNAL_A): $(LIBHASHLIB_INTERNAL_OBJS)
-rm -f $@
$(AR) $(ARFLAGS) $@ $(LIBHASHLIB_INTERNAL_OBJS)

##########################################################################
# HACL* library build
#
Expand Down Expand Up @@ -3353,21 +3376,21 @@ MODULE__CTYPES_TEST_DEPS=$(srcdir)/Modules/_ctypes/_ctypes_test_generated.c.h
MODULE__CTYPES_MALLOC_CLOSURE=@MODULE__CTYPES_MALLOC_CLOSURE@
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__HASHLIB_DEPS=@LIBHASHLIB_INTERNAL@
MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h

# HACL*-based cryptographic primitives
MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_MD5_HEADERS) $(LIBHACL_MD5_LIB_@LIBHACL_LDEPS_LIBTYPE@)
MODULE__MD5_DEPS=$(MODULE__HASHLIB_DEPS) $(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) $(LIBHACL_SHA1_LIB_@LIBHACL_LDEPS_LIBTYPE@)
MODULE__SHA1_DEPS=$(MODULE__HASHLIB_DEPS) $(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) $(LIBHACL_SHA2_LIB_@LIBHACL_LDEPS_LIBTYPE@)
MODULE__SHA2_DEPS=$(MODULE__HASHLIB_DEPS) $(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) $(LIBHACL_SHA3_LIB_@LIBHACL_LDEPS_LIBTYPE@)
MODULE__SHA3_DEPS=$(MODULE__HASHLIB_DEPS) $(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) $(LIBHACL_BLAKE2_LIB_@LIBHACL_LDEPS_LIBTYPE@)
MODULE__BLAKE2_DEPS=$(MODULE__HASHLIB_DEPS) $(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) $(LIBHACL_HMAC_LIB_@LIBHACL_LDEPS_LIBTYPE@)
MODULE__HMAC_DEPS=$(MODULE__HASHLIB_DEPS) $(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
Expand Down
6 changes: 6 additions & 0 deletions PCbuild/_hashlib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
<ItemGroup>
<ClCompile Include="..\Modules\_hashopenssl.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Modules\_hashlib\hashlib.h" />
<ClInclude Include="..\Modules\_hashlib\hashlib_buffer.h" />
<ClInclude Include="..\Modules\_hashlib\hashlib_fetch.h" />
<ClInclude Include="..\Modules\_hashlib\hashlib_mutex.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\PC\python_nt.rc" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion PCbuild/_hashlib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>
4 changes: 4 additions & 0 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@
<PreprocessorDefinitions>HACL_CAN_COMPILE_VEC128;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/arch:AVX %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ClCompile Include="..\Modules\_hashlib\hashlib_buffer.c" />
<ClInclude Include="..\Modules\_hashlib\hashlib_buffer.h" />
<ClInclude Include="..\Modules\_hashlib\hashlib_fetch.h" />
<ClInclude Include="..\Modules\_hashlib\hashlib_mutex.h" />
<ClCompile Include="..\Modules\_heapqmodule.c" />
<ClCompile Include="..\Modules\_json.c" />
<ClCompile Include="..\Modules\_localemodule.c" />
Expand Down
12 changes: 12 additions & 0 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@
<ClInclude Include="..\Include\weakrefobject.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Modules\_hashlib\hashlib_buffer.h">
<Filter>Modules\_hashlib</Filter>
</ClInclude>
<ClInclude Include="..\Modules\_hashlib\hashlib_fetch.h">
<Filter>Modules\_hashlib</Filter>
</ClInclude>
<ClInclude Include="..\Modules\_hashlib\hashlib_mutex.h">
<Filter>Modules\_hashlib</Filter>
</ClInclude>
<ClInclude Include="..\Modules\_math.h">
<Filter>Modules</Filter>
</ClInclude>
Expand Down Expand Up @@ -971,6 +980,9 @@
<ClCompile Include="..\Modules\_hacl\Hacl_Streaming_HMAC.c">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="..\Modules\_hashlib\hashlib_buffer.c">
<Filter>Modules\_hashlib</Filter>
</ClCompile>
<ClCompile Include="..\Modules\_heapqmodule.c">
<Filter>Modules</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions Tools/c-analyzer/cpython/ignored.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Modules/_decimal/_decimal.c - signal_map_template -
Modules/_decimal/_decimal.c - ssize_constants -
Modules/_decimal/_decimal.c - INVALID_SIGNALDICT_ERROR_MSG -
Modules/_elementtree.c - ExpatMemoryHandler -
Modules/_hashlib/hashlib_fetch.h - _Py_HASHLIB_MD_NAMES -
Modules/_hashopenssl.c - py_hashes -
Modules/_hacl/Hacl_Hash_SHA1.c - _h0 -
Modules/_hacl/Hacl_Hash_MD5.c - _h0 -
Expand Down
40 changes: 26 additions & 14 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7186,6 +7186,7 @@ SRCDIRS="\
Modules/_decimal \
Modules/_decimal/libmpdec \
Modules/_hacl \
Modules/_hashlib \
Modules/_io \
Modules/_multiprocessing \
Modules/_sqlite \
Expand Down Expand Up @@ -7956,6 +7957,15 @@ PY_STDLIB_MOD_SIMPLE([_codecs_tw])
PY_STDLIB_MOD_SIMPLE([_multibytecodec])
PY_STDLIB_MOD_SIMPLE([unicodedata])

###############################################################################
# Cryptographic primitives
LIBHASHLIB_INTERNAL_CFLAGS="-I\$(srcdir)/Modules/_hashlib"
LIBHASHLIB_INTERNAL_LDFLAGS="-lm \$(LIBHASHLIB_INTERNAL_A)"
LIBHASHLIB_INTERNAL="\$(LIBHASHLIB_INTERNAL_HEADERS) \$(LIBHASHLIB_INTERNAL_A)"

AC_SUBST([LIBHASHLIB_INTERNAL_CFLAGS])
AC_SUBST([LIBHASHLIB_INTERNAL])

###############################################################################
# HACL* compilation and linking configuration (contact: @picnixz)
#
Expand Down Expand Up @@ -8092,7 +8102,9 @@ 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)])
PY_STDLIB_MOD([$2], [$3], [],
[$LIBHACL_CFLAGS $LIBHASHLIB_INTERNAL_CFLAGS],
[\$($v) $LIBHASHLIB_INTERNAL_LDFLAGS])
AS_VAR_POPDEF([v])
])

Expand Down Expand Up @@ -8173,7 +8185,8 @@ dnl OpenSSL bindings
PY_STDLIB_MOD([_ssl], [], [test "$ac_cv_working_openssl_ssl" = yes],
[$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $OPENSSL_LIBS])
PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes],
[$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS])
[$OPENSSL_INCLUDES $LIBHASHLIB_INTERNAL_CFLAGS],
[$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS $LIBHASHLIB_INTERNAL_LDFLAGS])

dnl test modules
PY_STDLIB_MOD([_testcapi],
Expand Down
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