From 9ca233bf9ccb4b636631c3957ea67ba14c053fe6 Mon Sep 17 00:00:00 2001 From: Spencer Wilson Date: Fri, 12 Jan 2024 11:57:05 -0500 Subject: [PATCH] Build oqs-internal library --- src/CMakeLists.txt | 21 +++++++++++++++++++++ src/common/CMakeLists.txt | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6d867097fc..cb96355f6c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,14 +53,20 @@ add_library(oqs kem/kem.c sig/sig.c ${SIG_OBJS} ${COMMON_OBJS}) + +# Internal library to be used only by test programs +add_library(oqs-internal ${INTERNAL_OBJS}) + set(COMMON_OBJS ${COMMON_OBJS} PARENT_SCOPE) set(_ALL_OBJS ${KEM_OBJS} ${SIG_OBJS} ${COMMON_OBJS} $) set(ALL_OBJS ${_ALL_OBJS} PARENT_SCOPE) if(DEFINED SANITIZER_LD_FLAGS) target_link_libraries(oqs PUBLIC ${SANITIZER_LD_FLAGS}) + target_link_libraries(oqs-internal PUBLIC ${SANITIZER_LD_FLAGS}) endif() if(${OQS_USE_OPENSSL}) target_link_libraries(oqs PRIVATE ${OPENSSL_CRYPTO_LIBRARY}) + target_link_libraries(oqs-internal PRIVATE ${OPENSSL_CRYPTO_LIBRARY}) endif() target_include_directories(oqs @@ -68,6 +74,13 @@ target_include_directories(oqs "$" "$" ) + +target_include_directories(oqs-internal + PUBLIC + "$" + "$" +) + set_target_properties(oqs PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" @@ -77,6 +90,14 @@ set_target_properties(oqs # For Windows DLLs RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") +set_target_properties(oqs-internal + PROPERTIES + C_VISIBILITY_PRESET default + ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" + # For Windows DLLs + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") + configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/liboqsConfig.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/liboqs diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 2c49f115b1..e22c198ff6 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -4,6 +4,7 @@ include(CheckSymbolExists) # initialize to avoid --warn-uninitialized report set(_COMMON_OBJS "") +set(_INTERNAL_OBJS "") if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") @@ -81,8 +82,17 @@ add_library(common OBJECT ${AES_IMPL} rand/rand.c rand/rand_nist.c) +# Implementations of the internal API to be exposed to test programs +add_library(internal OBJECT ${AES_IMPL} + ${SHA2_IMPL} + ${SHA3_IMPL} + ${OSSL_HELPERS} + common.c) +set_property(TARGET internal PROPERTY C_VISIBILITY_PRESET default) + if(${OQS_USE_OPENSSL}) target_include_directories(common PRIVATE ${OPENSSL_INCLUDE_DIR}) + target_include_directories(internal PRIVATE ${OPENSSL_INCLUDE_DIR}) else() check_symbol_exists(getentropy "unistd.h;sys/random.h" CMAKE_HAVE_GETENTROPY) if(${CMAKE_HAVE_GETENTROPY}) @@ -91,6 +101,7 @@ else() endif() if(CMAKE_USE_PTHREADS_INIT) target_link_libraries(common PRIVATE Threads::Threads) + target_link_libraries(internal PRIVATE Threads::Threads) endif() # check available functions to perform aligned mallocs @@ -100,14 +111,17 @@ check_symbol_exists(memalign malloc.h CMAKE_HAVE_MEMALIGN) if(CMAKE_HAVE_ALIGNED_ALLOC) target_compile_definitions(common PRIVATE OQS_HAVE_ALIGNED_ALLOC) + target_compile_definitions(internal PRIVATE OQS_HAVE_ALIGNED_ALLOC) endif() if(CMAKE_HAVE_POSIX_MEMALIGN) target_compile_definitions(common PRIVATE OQS_HAVE_POSIX_MEMALIGN) + target_compile_definitions(internal PRIVATE OQS_HAVE_POSIX_MEMALIGN) endif() if(CMAKE_HAVE_MEMALIGN) target_compile_definitions(common PRIVATE OQS_HAVE_MEMALIGN) + target_compile_definitions(internal PRIVATE OQS_HAVE_MEMALIGN) endif() # check if explicit_bzero exists or memset_s @@ -116,15 +130,20 @@ check_symbol_exists(memset_s string.h CMAKE_HAVE_MEMSET_S) if(CMAKE_HAVE_EXPLICIT_BZERO) target_compile_definitions(common PRIVATE OQS_HAVE_EXPLICIT_BZERO) + target_compile_definitions(internal PRIVATE OQS_HAVE_EXPLICIT_BZERO) endif() if(CMAKE_HAVE_MEMSET_S) target_compile_definitions(common PRIVATE OQS_HAVE_MEMSET_S) + target_compile_definitions(internal PRIVATE OQS_HAVE_MEMSET_S) endif() if(${OQS_ENABLE_SHA3_xkcp_low}) # using XKCP set(_COMMON_OBJS ${_COMMON_OBJS} ${XKCP_LOW_OBJS}) + set(_INTERNAL_OBJS ${_INTERNAL_OBJS} ${XKCP_LOW_OBJS}) endif() set(_COMMON_OBJS ${_COMMON_OBJS} $) set(COMMON_OBJS ${_COMMON_OBJS} PARENT_SCOPE) +set(_INTERNAL_OBJS ${_INTERNAL_OBJS} $) +set(INTERNAL_OBJS ${_INTERNAL_OBJS} PARENT_SCOPE)