@ -37,7 +37,6 @@ set(NTRU_REF_SRC
)
)
set ( NTRU_SRC
set ( NTRU_SRC
$ { N T R U _ A V X _ S R C }
$ { N T R U _ R E F _ S R C }
$ { N T R U _ R E F _ S R C }
l i b n t r u p / s r c / n t r u . c p p
l i b n t r u p / s r c / n t r u . c p p
)
)
@ -47,21 +46,41 @@ set(CRYPTOGRAPHY_SRC ${NTRU_SRC})
add_library ( ${ CRYPTOGRAPHY_LIB } STATIC ${ CRYPTOGRAPHY_SRC } )
add_library ( ${ CRYPTOGRAPHY_LIB } STATIC ${ CRYPTOGRAPHY_SRC } )
add_log_tag ( ${ CRYPTOGRAPHY_LIB } )
add_log_tag ( ${ CRYPTOGRAPHY_LIB } )
# T h e a v x i m p l e m e n t a t i o n u s e s r u n t i m e C P U f e a t u r e d e t e c t i o n t o e n a b l e i t s e l f , s o w e * a l w a y s * w a n t t o
# c o m p i l e i t w i t h a v x 2 s u p p o r t e v e n i f w e a r e n ' t c o m p i l i n g w i t h A V X 2 e n a b l e d .
add_library ( cryptography_avx_lib STATIC ${ NTRU_AVX_SRC } )
if ( USE_AVX2 )
# A s s u m e c x x f l a g s a r e a l r e a d y e n a b l i n g A V X 2
else ( )
include ( CheckCXXCompilerFlag )
check_cxx_compiler_flag ( -mavx2 COMPILER_SUPPORTS_AVX2 )
check_cxx_compiler_flag ( -mfma COMPILER_SUPPORTS_FMA )
if ( COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA )
target_compile_options ( cryptography_avx_lib PRIVATE -mavx2 -mfma )
message ( STATUS "Building libntrup with runtime AVX2/FMA support" )
else ( )
message ( STATUS "Not building with libntrup runtime AVX2/FMA support (can't figure out how to compile with AVX2/FMA: -mavx2 -mfma didn't work)" )
endif ( )
endif ( )
target_link_libraries ( ${ CRYPTOGRAPHY_LIB } PRIVATE cryptography_avx_lib )
option ( DOWNLOAD_SODIUM "Allow libsodium to be downloaded and built locally if not found on the system" OFF )
option ( DOWNLOAD_SODIUM "Allow libsodium to be downloaded and built locally if not found on the system" OFF )
find_package ( Sodium 1.0.17 )
find_package ( Sodium 1.0.17 )
if ( sodium_FOUND )
if ( sodium_FOUND )
target_include_directories ( ${ CRYPTOGRAPHY_LIB } PUBLIC ${ sodium_INCLUDE_DIR } )
target_include_directories ( ${ CRYPTOGRAPHY_LIB } PUBLIC ${ sodium_INCLUDE_DIR } )
target_link_libraries ( ${ CRYPTOGRAPHY_LIB } ${ sodium_LIBRARY_RELEASE } )
target_include_directories ( cryptography_avx_lib PUBLIC ${ sodium_INCLUDE_DIR } )
target_link_libraries ( ${ CRYPTOGRAPHY_LIB } PUBLIC ${ sodium_LIBRARY_RELEASE } )
elseif ( DOWNLOAD_SODIUM )
elseif ( DOWNLOAD_SODIUM )
message ( STATUS "Sodium >= 1.0.17 not found, but DOWNLOAD_SODIUM specified, so downloading it" )
message ( STATUS "Sodium >= 1.0.17 not found, but DOWNLOAD_SODIUM specified, so downloading it" )
include ( DownloadLibSodium )
include ( DownloadLibSodium )
target_link_libraries ( ${ CRYPTOGRAPHY_LIB } sodium_vendor )
target_link_libraries ( ${ CRYPTOGRAPHY_LIB } PUBLIC sodium_vendor)
else ( )
else ( )
message ( FATAL_ERROR "Could not find libsodium >= 1.0.17; either install it on your system or use -DDOWNLOAD_SODIUM=ON to download and build an internal copy" )
message ( FATAL_ERROR "Could not find libsodium >= 1.0.17; either install it on your system or use -DDOWNLOAD_SODIUM=ON to download and build an internal copy" )
endif ( )
endif ( )
target_include_directories ( ${ CRYPTOGRAPHY_LIB } PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libntrup/include" )
target_include_directories ( ${ CRYPTOGRAPHY_LIB } PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libntrup/include" )
target_include_directories ( cryptography_avx_lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libntrup/include" )