diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1cf648dcf..78b27f3a3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ concurrency: jobs: Docs: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 container: texlive/texlive:latest-medium steps: - uses: actions/checkout@v4 @@ -36,7 +36,7 @@ jobs: strategy: matrix: cc: [ gcc, clang ] - os: [ ubuntu-20.04, ubuntu-22.04 ] + os: [ ubuntu-22.04, ubuntu-24.04 ] config: - { BUILDNAME: 'META_BUILDS', BUILDOPTIONS: '-DGMP_DESC', BUILDSCRIPT: '.ci/meta_builds.sh' } - { BUILDNAME: 'VALGRIND', BUILDOPTIONS: '', BUILDSCRIPT: '.ci/valgrind.sh' } diff --git a/contrib/libtomcrypt.cmake b/contrib/libtomcrypt.cmake new file mode 100644 index 000000000..ee90767f3 --- /dev/null +++ b/contrib/libtomcrypt.cmake @@ -0,0 +1,14 @@ +# To find libtomcrypt no matter what the installation look like, start with +# looking for the CMake specific configuration, and failing that, try the +# pkg-config package instead. The resulting target is different in each +# case, but is recorded in the variable ${LIBTOMCRYPT}, so please use that +# for all targets that depend on libtomcrypt. + +find_package(libtomcrypt QUIET) +if (libtomcrypt_FOUND) + set(LIBTOMCRYPT libtomcrypt) +else() + find_package(PkgConfig) + pkg_check_modules(libtomcrypt REQUIRED IMPORTED_TARGET libtomcrypt) + set(LIBTOMCRYPT PkgConfig::libtomcrypt) +endif() diff --git a/doc/crypt.tex b/doc/crypt.tex index af9645562..ea0b250c4 100644 --- a/doc/crypt.tex +++ b/doc/crypt.tex @@ -8868,6 +8868,34 @@ \subsection{Installation Directories} A shared library build can be done by setting \textbf{-DBUILD\_SHARED\_LIBS=On} when invoking the \textbf{cmake} command. Tests can be enabled by setting \textbf{-DBUILD\_TESTING=On} when invoking the \textbf{cmake} command. +\mysection{Building a libtomcrypt app with CMake} + +Depending on if libtomcrypt was built and installed using the +available makefiles, or using CMake, different package files are +provided. + +With the available makefiles, the pkg-config file +\texttt{libtomcrypt.pc} is produced, while with CMake, the CMake +config file \texttt{libtomcrypt-config.cmake} is produced. + +The result is that different installations have different package +config files. + +This has proven problematic for other CMake-based projects. That is, +however, fairly easy to solve with this little CMake snippet (also +found in \texttt{contrib/libtomcrypt.cmake}: + +\begin{verbatim} +find_package(libtomcrypt QUIET) +if (libtomcrypt_FOUND) + set(LIBTOMCRYPT libtomcrypt) +else() + find_package(PkgConfig) + pkg_check_modules(libtomcrypt REQUIRED IMPORTED_TARGET libtomcrypt) + set(LIBTOMCRYPT PkgConfig::libtomcrypt) +endif() +\end{verbatim} + \mysection{Header Configuration} The file \textit{tomcrypt\_cfg.h} is what lets you control various high level macros which control the behaviour of the library. Build options are also stored in \textit{tomcrypt\_custom.h} which allow the enabling and disabling of various algorithms. diff --git a/helper.pl b/helper.pl index b24551d02..b9664f4ed 100755 --- a/helper.pl +++ b/helper.pl @@ -233,8 +233,8 @@ sub prepare_msvc_files_xml { ########### aes_enc "hack" disabled - discussion: https://github.com/libtom/libtomcrypt/pull/158 # if ($full eq 'src\ciphers\aes\aes.c') { #hack # my %cmd = ( -# 'Debug|Win32' => [ 'Debug/aes.obj;Debug/aes_enc.obj', 'cl /nologo /MLd /W3 /Gm /GX /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Debug/libtomcrypt.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c $(InputPath) cl /nologo /DENCRYPT_ONLY /MLd /W3 /Gm /GX /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Debug/libtomcrypt.pch" /YX /Fo"Debug/aes_enc.obj" /Fd"Debug/" /FD /GZ /c $(InputPath) ' ], -# 'Release|Win32' => [ 'Release/aes.obj;Release/aes_enc.obj', 'cl /nologo /MLd /W3 /Gm /GX /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Release/libtomcrypt.pch" /YX /Fo"Release/" /Fd"Release/" /FD /GZ /c $(InputPath) cl /nologo /DENCRYPT_ONLY /MLd /W3 /Gm /GX /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Release/libtomcrypt.pch" /YX /Fo"Release/aes_enc.obj" /Fd"Release/" /FD /GZ /c $(InputPath) ' ], +# 'Debug|Win32' => [ 'Debug/aes.obj;Debug/aes_enc.obj', 'cl /nologo /MLd /W3 /Gm /GX /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D /D "USE_LTM" /Fp"Debug/libtomcrypt.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c $(InputPath) cl /nologo /DENCRYPT_ONLY /MLd /W3 /Gm /GX /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D /D "USE_LTM" /Fp"Debug/libtomcrypt.pch" /YX /Fo"Debug/aes_enc.obj" /Fd"Debug/" /FD /GZ /c $(InputPath) ' ], +# 'Release|Win32' => [ 'Release/aes.obj;Release/aes_enc.obj', 'cl /nologo /MLd /W3 /Gm /GX /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D /D "USE_LTM" /Fp"Release/libtomcrypt.pch" /YX /Fo"Release/" /Fd"Release/" /FD /GZ /c $(InputPath) cl /nologo /DENCRYPT_ONLY /MLd /W3 /Gm /GX /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D /D "USE_LTM" /Fp"Release/libtomcrypt.pch" /YX /Fo"Release/aes_enc.obj" /Fd"Release/" /FD /GZ /c $(InputPath) ' ], # ); # for (@$targets) { # next unless $cmd{$_}; diff --git a/libtomcrypt_VS2008.vcproj b/libtomcrypt_VS2008.vcproj index 0cb96ce3f..84b8555b9 100644 --- a/libtomcrypt_VS2008.vcproj +++ b/libtomcrypt_VS2008.vcproj @@ -46,7 +46,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="src\headers,..\libtommath" - PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;LTM_DESC;LTC_SOURCE;LTC_NO_TEST;LTC_NO_PROTOTYPES" + PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;LTM_DESC;LTC_NO_TEST;LTC_NO_PROTOTYPES" MinimalRebuild="true" ExceptionHandling="0" BasicRuntimeChecks="3" @@ -123,7 +123,7 @@ Optimization="2" InlineFunctionExpansion="1" AdditionalIncludeDirectories="src\headers,..\libtommath" - PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;LTM_DESC;LTC_SOURCE;LTC_NO_TEST;LTC_NO_PROTOTYPES" + PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;LTM_DESC;LTC_NO_TEST;LTC_NO_PROTOTYPES" StringPooling="true" ExceptionHandling="0" RuntimeLibrary="0" @@ -199,7 +199,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="src\headers,..\libtommath" - PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;LTM_DESC;LTC_SOURCE;LTC_NO_TEST;LTC_NO_PROTOTYPES" + PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;LTM_DESC;LTC_NO_TEST;LTC_NO_PROTOTYPES" MinimalRebuild="true" ExceptionHandling="0" BasicRuntimeChecks="3" @@ -277,7 +277,7 @@ Optimization="2" InlineFunctionExpansion="1" AdditionalIncludeDirectories="src\headers,..\libtommath" - PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;LTM_DESC;LTC_SOURCE;LTC_NO_TEST;LTC_NO_PROTOTYPES" + PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;LTM_DESC;LTC_NO_TEST;LTC_NO_PROTOTYPES" StringPooling="true" ExceptionHandling="0" RuntimeLibrary="0" diff --git a/makefile.mingw b/makefile.mingw index b6403260a..1234941b9 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -25,7 +25,7 @@ CFLAGS = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath EXTRALIBS = -L../libtommath -ltommath #Compilation flags -LTC_CFLAGS = -Isrc/headers -Itests -DLTC_SOURCE $(CFLAGS) +LTC_CFLAGS = -Isrc/headers -Itests $(CFLAGS) LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS) VERSION=1.18.2-develop diff --git a/makefile.msvc b/makefile.msvc index cc8ef91ea..99782a591 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -20,7 +20,7 @@ CFLAGS = /Ox /DUSE_LTM /DLTM_DESC /I../libtommath EXTRALIBS = ../libtommath/tommath.lib #Compilation flags -LTC_CFLAGS = /nologo /Isrc/headers/ /Itests/ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /DLTC_SOURCE /W3 $(CFLAGS) +LTC_CFLAGS = /nologo /Isrc/headers/ /Itests/ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /W3 $(CFLAGS) LTC_LDFLAGS = advapi32.lib $(EXTRALIBS) VERSION=1.18.2-develop diff --git a/makefile.unix b/makefile.unix index 79b9464a1..46afebadc 100644 --- a/makefile.unix +++ b/makefile.unix @@ -40,7 +40,7 @@ PC_CFLAGS = -DLTM_DESC PC_LIBS = -ltommath #Compilation flags -LTC_CFLAGS = -Isrc/headers -Itests -DLTC_SOURCE $(CFLAGS) +LTC_CFLAGS = -Isrc/headers -Itests $(CFLAGS) LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS) VERSION=1.18.2-develop VERSION_PC=1.18.2 diff --git a/makefile_include.mk b/makefile_include.mk index 6e87ebcaa..ba01bf453 100644 --- a/makefile_include.mk +++ b/makefile_include.mk @@ -74,7 +74,7 @@ endef # Also note that we're extending the environments' CFLAGS. # If you think that our CFLAGS are not nice you can easily override them # by giving them as a parameter to make: -# make CFLAGS="-I./src/headers/ -DLTC_SOURCE ..." ... +# make CFLAGS="-I./src/headers/ ..." ... # ifneq ($(shell echo $(CFLAGS) | grep LTM_DESC),) LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I libtommath ${silent_stderr} || true) @@ -85,7 +85,7 @@ endif ifneq ($(shell echo $(CFLAGS) | grep GMP_DESC),) LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I gmp ${silent_stderr} || true) endif -LTC_CFLAGS += -I./src/headers/ -DLTC_SOURCE -Wall -Wsign-compare -Wshadow +LTC_CFLAGS += -I./src/headers/ -Wall -Wsign-compare -Wshadow ifdef OLD_GCC LTC_CFLAGS += -W diff --git a/src/headers/tomcrypt_cfg.h b/src/headers/tomcrypt_cfg.h index c6c1fe13c..38eca3708 100644 --- a/src/headers/tomcrypt_cfg.h +++ b/src/headers/tomcrypt_cfg.h @@ -91,9 +91,6 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #define ENDIAN_LITTLE #define ENDIAN_64BITWORD #define LTC_FAST - #if defined(_ILP32) || defined(__ILP32__) - #define ENDIAN_64BITWORD_X32 - #endif #endif /* detect PPC32 */ @@ -178,6 +175,11 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #define LTC_FAST #endif +/* Detect ILP32, commonly known as x32 on Linux and also possible on AIX */ +#if defined(_ILP32) || defined(__ILP32__) + #define ENDIAN_64BITWORD_ILP32 +#endif + /* endianness fallback */ #if !defined(ENDIAN_BIG) && !defined(ENDIAN_LITTLE) #if defined(_BYTE_ORDER) && _BYTE_ORDER == _BIG_ENDIAN || \ diff --git a/src/headers/tomcrypt_private.h b/src/headers/tomcrypt_private.h index 677081b22..1751d3b7a 100644 --- a/src/headers/tomcrypt_private.h +++ b/src/headers/tomcrypt_private.h @@ -12,8 +12,8 @@ #define LTC_PAD_MASK (0xF000U) -/* only real 64bit, not x32 */ -#if defined(ENDIAN_64BITWORD) && !defined(ENDIAN_64BITWORD_X32) +/* only real 64bit, not ILP32 */ +#if defined(ENDIAN_64BITWORD) && !defined(ENDIAN_64BITWORD_ILP32) #define CONSTPTR(n) CONST64(n) #else #define CONSTPTR(n) n ## uL diff --git a/tests/multi_test.c b/tests/multi_test.c index 99b055a54..e02940554 100644 --- a/tests/multi_test.c +++ b/tests/multi_test.c @@ -15,7 +15,7 @@ int multi_test(void) /* HASH testing */ len = sizeof(buf[0]); -#if defined(ENDIAN_32BITWORD) || defined(_WIN32) || defined(ENDIAN_64BITWORD_X32) +#if defined(ENDIAN_32BITWORD) || defined(_WIN32) || defined(ENDIAN_64BITWORD_ILP32) len2 = 0x80000000UL; #else /* Check against the max. input limit of SHA-1 as of RFC8017 */