From 2c3a5fd0ac124c9d75204c3fa1305a755e1d081b Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 18 Jan 2023 16:41:36 +0100 Subject: [PATCH 1/4] update `Libs` part of pkg-config file with configured MPI providers Signed-off-by: Steffen Jaeckel --- libtomcrypt.pc.in | 2 +- makefile.shared | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libtomcrypt.pc.in b/libtomcrypt.pc.in index b97cb0dee..a7db0394d 100644 --- a/libtomcrypt.pc.in +++ b/libtomcrypt.pc.in @@ -6,5 +6,5 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@ Name: LibTomCrypt Description: public domain open source cryptographic toolkit Version: @PROJECT_VERSION@ -Libs: -L${libdir} -ltomcrypt +Libs: -L${libdir} -ltomcrypt @MPI_PROVIDERS@ Cflags: -I${includedir} diff --git a/makefile.shared b/makefile.shared index 0194a39f2..0abe2073b 100644 --- a/makefile.shared +++ b/makefile.shared @@ -54,6 +54,15 @@ endif include makefile_include.mk +ifneq ($(findstring -DLTM_DESC,$(LTC_CFLAGS)),) +LTC_MPI_PROVIDERS += -ltommath +endif +ifneq ($(findstring -DTFM_DESC,$(LTC_CFLAGS)),) +LTC_MPI_PROVIDERS += -ltfm +endif +ifneq ($(findstring -DGMP_DESC,$(LTC_CFLAGS)),) +LTC_MPI_PROVIDERS += -lgmp +endif #ciphers come in two flavours... enc+dec and enc src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c @@ -80,7 +89,8 @@ $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,@CMAKE_INSTALL_LIBDIR@,lib,' \ - -e 's,@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@,include/tomcrypt,' libtomcrypt.pc.in > libtomcrypt.pc + -e 's,@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@,include/tomcrypt,' \ + -e 's,@MPI_PROVIDERS@,$(LTC_MPI_PROVIDERS),' libtomcrypt.pc.in > libtomcrypt.pc install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/ From 5330cd1d9b82d242ab91127d6da8d966fd73e087 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 18 Jan 2023 19:53:57 +0100 Subject: [PATCH 2/4] also update pkg-config file generated by cmake Signed-off-by: Steffen Jaeckel --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba48f9fb3..63419c23d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,7 @@ if(WITH_LTM) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LTM) endif() target_link_libraries(${PROJECT_NAME} PUBLIC libtommath) + list(APPEND MPI_PROVIDERS -ltommath) endif() # GNU MP if(WITH_GMP) @@ -146,6 +147,7 @@ if(WITH_GMP) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_GMP) endif() target_link_libraries(${PROJECT_NAME} PUBLIC ${GMP_LIBRARIES}) + list(APPEND MPI_PROVIDERS -lgmp) endif() From 3f33ccf181e3fda54fd315625daa973680be8929 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 19 Jun 2023 19:28:13 +0200 Subject: [PATCH 3/4] cmake: Add TomsFastMath support Signed-off-by: Steffen Jaeckel --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63419c23d..a401f4798 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ include(sources.cmake) # Options #----------------------------------------------------------------------------- option(WITH_LTM "Build with support for libtommath" TRUE) +option(WITH_TFM "Build with support for tomsfastmath" FALSE) option(WITH_GMP "Build with support for GNU Multi Precision Arithmetic Library" FALSE) set(MPI_PROVIDER "LTM" CACHE STRING "Build tests and demos against 'LTM', 'TFM' or 'GMP', default is LTM") option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF) @@ -138,6 +139,17 @@ if(WITH_LTM) target_link_libraries(${PROJECT_NAME} PUBLIC libtommath) list(APPEND MPI_PROVIDERS -ltommath) endif() +# tomsfastmath +if(WITH_TFM) + find_package(tomsfastmath 0.13.1 REQUIRED) + + target_compile_definitions(${PROJECT_NAME} PUBLIC TFM_DESC) + if(MPI_PROVIDER MATCHES "TFM") + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_TFM) + endif() + target_link_libraries(${PROJECT_NAME} PUBLIC tomsfastmath) + list(APPEND MPI_PROVIDERS -ltfm) +endif() # GNU MP if(WITH_GMP) pkg_check_modules(GMP REQUIRED gmp>=6.1.2) From 4767558fd070c0867768308e0bec40d9543549ab Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 19 Jun 2023 19:44:17 +0200 Subject: [PATCH 4/4] Add correct MPI provider defines to pkg-config cflags Signed-off-by: Steffen Jaeckel --- CMakeLists.txt | 11 ++++++++--- libtomcrypt.pc.in | 4 ++-- makefile.shared | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a401f4798..738275c37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,8 @@ if(WITH_LTM) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LTM) endif() target_link_libraries(${PROJECT_NAME} PUBLIC libtommath) - list(APPEND MPI_PROVIDERS -ltommath) + list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DLTM_DESC) + list(APPEND LTC_MPI_PROVIDERS_LIBS -ltommath) endif() # tomsfastmath if(WITH_TFM) @@ -148,7 +149,8 @@ if(WITH_TFM) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_TFM) endif() target_link_libraries(${PROJECT_NAME} PUBLIC tomsfastmath) - list(APPEND MPI_PROVIDERS -ltfm) + list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DTFM_DESC) + list(APPEND LTC_MPI_PROVIDERS_LIBS -ltfm) endif() # GNU MP if(WITH_GMP) @@ -159,9 +161,12 @@ if(WITH_GMP) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_GMP) endif() target_link_libraries(${PROJECT_NAME} PUBLIC ${GMP_LIBRARIES}) - list(APPEND MPI_PROVIDERS -lgmp) + list(APPEND LTC_MPI_PROVIDERS_CFLAGS -DGMP_DESC) + list(APPEND LTC_MPI_PROVIDERS_LIBS -lgmp) endif() +list(JOIN LTC_MPI_PROVIDERS_CFLAGS " " MPI_PROVIDERS_CFLAGS) +list(JOIN LTC_MPI_PROVIDERS_LIBS " " MPI_PROVIDERS_LIBS) #----------------------------------------------------------------------------- # demos&test targets diff --git a/libtomcrypt.pc.in b/libtomcrypt.pc.in index a7db0394d..f840a5451 100644 --- a/libtomcrypt.pc.in +++ b/libtomcrypt.pc.in @@ -6,5 +6,5 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@ Name: LibTomCrypt Description: public domain open source cryptographic toolkit Version: @PROJECT_VERSION@ -Libs: -L${libdir} -ltomcrypt @MPI_PROVIDERS@ -Cflags: -I${includedir} +Libs: -L${libdir} -ltomcrypt @MPI_PROVIDERS_LIBS@ +Cflags: -I${includedir} @MPI_PROVIDERS_CFLAGS@ diff --git a/makefile.shared b/makefile.shared index 0abe2073b..9daa41b7f 100644 --- a/makefile.shared +++ b/makefile.shared @@ -55,13 +55,16 @@ endif include makefile_include.mk ifneq ($(findstring -DLTM_DESC,$(LTC_CFLAGS)),) -LTC_MPI_PROVIDERS += -ltommath +LTC_MPI_PROVIDERS_CFLAGS += -DLTM_DESC +LTC_MPI_PROVIDERS_LIBS += -ltommath endif ifneq ($(findstring -DTFM_DESC,$(LTC_CFLAGS)),) -LTC_MPI_PROVIDERS += -ltfm +LTC_MPI_PROVIDERS_CFLAGS += -DTFM_DESC +LTC_MPI_PROVIDERS_LIBS += -ltfm endif ifneq ($(findstring -DGMP_DESC,$(LTC_CFLAGS)),) -LTC_MPI_PROVIDERS += -lgmp +LTC_MPI_PROVIDERS_CFLAGS += -DGMP_DESC +LTC_MPI_PROVIDERS_LIBS += -lgmp endif #ciphers come in two flavours... enc+dec and enc @@ -90,7 +93,8 @@ $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) install: $(call print-help,install,Installs the library + headers + pkg-config file) .common_install sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION_PC),' -e 's,@CMAKE_INSTALL_LIBDIR@,lib,' \ -e 's,@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@,include/tomcrypt,' \ - -e 's,@MPI_PROVIDERS@,$(LTC_MPI_PROVIDERS),' libtomcrypt.pc.in > libtomcrypt.pc + -e 's,@MPI_PROVIDERS_LIBS@,$(LTC_MPI_PROVIDERS_LIBS),' \ + -e 's,@MPI_PROVIDERS_CFLAGS@,$(LTC_MPI_PROVIDERS_CFLAGS),' libtomcrypt.pc.in > libtomcrypt.pc install -p -d $(DESTDIR)$(LIBPATH)/pkgconfig install -p -m 644 libtomcrypt.pc $(DESTDIR)$(LIBPATH)/pkgconfig/