From 8ee3259a1f08148e1ef09240fd007c5f775c6f76 Mon Sep 17 00:00:00 2001 From: Jason Carpenter <5916026+breadbored@users.noreply.github.com> Date: Fri, 5 Nov 2021 00:38:47 -0400 Subject: [PATCH 1/3] Portable shared library linking --- cmake/flink.cmake | 32 ++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 7 +++---- 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 cmake/flink.cmake diff --git a/cmake/flink.cmake b/cmake/flink.cmake new file mode 100644 index 0000000..e0d826e --- /dev/null +++ b/cmake/flink.cmake @@ -0,0 +1,32 @@ +include(CMakeParseArguments) + +function(target_do_force_link_libraries target visibility lib) + if(MSVC) + target_link_libraries(${target} ${visibility} "/WHOLEARCHIVE:${lib}") + elseif(APPLE) + target_link_libraries(${target} ${visibility} -Wl,-force_load ${lib}) + else() + target_link_libraries(${target} ${visibility} -Wl,--whole-archive ${lib} -Wl,--no-whole-archive) + endif() +endfunction() + +function(target_force_link_libraries target) + cmake_parse_arguments(FLINK + "" + "" + "PUBLIC;INTERFACE;PRIVATE" + ${ARGN} + ) + + foreach(lib IN LISTS FLINK_PUBLIC) + target_do_force_link_libraries(${target} PUBLIC ${lib}) + endforeach() + + foreach(lib IN LISTS FLINK_INTERFACE) + target_do_force_link_libraries(${target} INTERFACE ${lib}) + endforeach() + + foreach(lib IN LISTS FLINK_PRIVATE) + target_do_force_link_libraries(${target} PRIVATE ${lib}) + endforeach() +endfunction() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7ebe6a9..da06a90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ include(../cmake/swifft_defaults.cmake) +include(../cmake/flink.cmake) add_executable(swifft_keygen swifft_keygen.cpp) @@ -57,10 +58,8 @@ add_library(swifft_shared SHARED ${CMAKE_CURRENT_BINARY_DIR}/swifft_so_dummy.c) install(TARGETS swifft_shared DESTINATION lib) set_target_properties(swifft_shared PROPERTIES OUTPUT_NAME swifft) set_target_properties(swifft_shared PROPERTIES LINKER_LANGUAGE CXX) -target_link_libraries(swifft_shared PUBLIC - -Wl,--whole-archive - $ - -Wl,--no-whole-archive +target_force_link_libraries(swifft_shared + PUBLIC $ ) From 3fd2f0be883f00ab2559fc2377f4afa6779cfc51 Mon Sep 17 00:00:00 2001 From: Jason Carpenter <5916026+breadbored@users.noreply.github.com> Date: Sat, 6 Nov 2021 00:18:35 -0400 Subject: [PATCH 2/3] Added SWIFFT_Hash wrapper compatible function For use with languages like Python when compiled to a shared library. LibSWIFFT_Compute takes the output as a param, but this function will return the result for wrappers. --- src/swifft.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/swifft.c b/src/swifft.c index 9aa2c6c..8cc93eb 100644 --- a/src/swifft.c +++ b/src/swifft.c @@ -392,4 +392,15 @@ void SWIFFT_ComputeMultipleSigned(int nblocks, const BitSequence * input, SWIFFT_ISET_NAME(SWIFFT_ComputeMultipleSigned_)(nblocks, input, sign, output); } +//! \brief Computes the result of a SWIFFT operation and returns the value. Made to be compatible with Python. +//! The result is composable with other hash values. +//! +//! \param[in] input the input of 256 bytes (2048 bit). +BitSequence SWIFFT_Hash(const BitSequence input[SWIFFT_INPUT_BLOCK_SIZE]) +{ + SWIFFT_ALIGN BitSequence result[SWIFFT_OUTPUT_BLOCK_SIZE]; + SWIFFT_Compute(input, result); + return result; +} + LIBSWIFFT_END_EXTERN_C From d1bcd04cd79030d4825056da9112a4d907abb81e Mon Sep 17 00:00:00 2001 From: Jason Carpenter <5916026+breadbored@users.noreply.github.com> Date: Thu, 18 Aug 2022 23:20:27 -0400 Subject: [PATCH 3/3] Removed bad code I was attempting to expose the library to Python at the time, but introduced an error referenced in gvilitechltd/LibSWIFFT PR#44. --- src/swifft.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/swifft.c b/src/swifft.c index 8cc93eb..9aa2c6c 100644 --- a/src/swifft.c +++ b/src/swifft.c @@ -392,15 +392,4 @@ void SWIFFT_ComputeMultipleSigned(int nblocks, const BitSequence * input, SWIFFT_ISET_NAME(SWIFFT_ComputeMultipleSigned_)(nblocks, input, sign, output); } -//! \brief Computes the result of a SWIFFT operation and returns the value. Made to be compatible with Python. -//! The result is composable with other hash values. -//! -//! \param[in] input the input of 256 bytes (2048 bit). -BitSequence SWIFFT_Hash(const BitSequence input[SWIFFT_INPUT_BLOCK_SIZE]) -{ - SWIFFT_ALIGN BitSequence result[SWIFFT_OUTPUT_BLOCK_SIZE]; - SWIFFT_Compute(input, result); - return result; -} - LIBSWIFFT_END_EXTERN_C