X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=CMakeLists.txt;h=cee45356fbaa35570543e8dfb868fd1c66d6c4f2;hb=2ffd7dabe3d9f191c8933d89dcc62db1bee75200;hp=774a1a7c2ae225b5ff4e878908f84c38f3306848;hpb=f2d6039b1b8c501d989c35adf42095186de4f999;p=openssl-gost%2Fengine.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 774a1a7..cee4535 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,16 +2,19 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) project(gost-engine LANGUAGES C) include(GNUInstallDirs) +include(CheckLibraryExists) +include(CheckFunctionExists) +include(CheckCSourceRuns) enable_testing() -find_package(OpenSSL 1.1.1 REQUIRED) +find_package(OpenSSL 3.0 REQUIRED) include_directories(${OPENSSL_INCLUDE_DIR}) if (CMAKE_C_COMPILER_ID MATCHES "Clang") - add_compile_options(-Qunused-arguments) + add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Qunused-arguments) elseif(CMAKE_C_COMPILER_ID MATCHES "GNU") - add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb) + add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Wno-error=unknown-pragmas -Wno-deprecated-declarations) elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_DEPRECATED_NO_WARNINGS) @@ -19,7 +22,23 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC") add_compile_options(/MP /WX /W4 /wd4100 /wd4267 /wd4206 /wd4706 /wd4244 /wd4115) endif() +if (ASAN) + message(STATUS "address sanitizer enabled") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -g3 -fno-omit-frame-pointer") + set(SKIP_PERL_TESTS 1) +endif() + +# DEPRECATEDIN_3_0 CMAC +set_source_files_properties(gost_omac.c PROPERTIES COMPILE_FLAGS -Wno-error=deprecated-declarations) +# DEPRECATEDIN_3_0 HMAC +set_source_files_properties(gost_keyexpimp.c PROPERTIES COMPILE_FLAGS -Wno-error=deprecated-declarations) + set(CMAKE_C_STANDARD 90) +CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME_C) +CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_CLOCK_GETTIME_RT) +if(HAVE_CLOCK_GETTIME_RT AND NOT HAVE_CLOCK_GETTIME_C) + set(CLOCK_GETTIME_LIB rt) +endif() include (TestBigEndian) TEST_BIG_ENDIAN(IS_BIG_ENDIAN) @@ -30,14 +49,44 @@ else() add_definitions(-DL_ENDIAN) endif() +check_c_source_runs(" + #ifdef _MSC_VER + # include + #else + # include + #endif + int main(void) { + unsigned long long x = -1, y = 1, r; + unsigned char cf; + cf = _addcarry_u64(1, x, y, &r); + return !(cf == 1 && r == 1); + } + " ADDCARRY_U64) +if (ADDCARRY_U64) + add_definitions(-DHAVE_ADDCARRY_U64) +endif() + set(BIN_DIRECTORY bin) -set(OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/${BIN_DIRECTORY}) +# Same soversion as OpenSSL +set(GOST_SOVERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}") + +set(OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BIN_DIRECTORY}) #set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}) +# Remove when https://gitlab.kitware.com/cmake/cmake/issues/18525 is addressed +set(OPENSSL_ENGINES_DIR "" CACHE PATH "OpenSSL Engines Directory") +if ("${OPENSSL_ENGINES_DIR}" STREQUAL "") + include(FindPkgConfig) + pkg_get_variable(OPENSSL_ENGINES_DIR libcrypto enginesdir) + if ("${OPENSSL_ENGINES_DIR}" STREQUAL "") + message( FATAL_ERROR "Unable to discover the OpenSSL engines directory. Provide the path using -DOPENSSL_ENGINES_DIR" ) + endif() +endif() + set(GOST_89_SOURCE_FILES gost89.c gost89.h @@ -111,32 +160,92 @@ set(GOST_ENGINE_SOURCE_FILES gost_pmeth.c gost_omac.c gost_omac_acpkm.c + gost_gost2015.c ) +add_executable(test_digest test_digest.c) +target_link_libraries(test_digest gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) +add_test(NAME digest + COMMAND test_digest) + +add_executable(test_ciphers test_ciphers.c) +target_link_libraries(test_ciphers gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) +add_test(NAME ciphers + COMMAND test_ciphers) + add_executable(test_curves test_curves.c) target_link_libraries(test_curves gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) add_test(NAME curves COMMAND test_curves) +add_executable(test_params test_params.c) +target_link_libraries(test_params gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) +add_test(NAME parameters + COMMAND test_params) + +add_executable(test_sign test_sign.c) +target_link_libraries(test_sign gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) +add_test(NAME sign/verify + COMMAND test_sign) + +add_executable(test_tls test_tls.c) +target_link_libraries(test_tls gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY}) +add_test(NAME TLS + COMMAND test_tls) + add_executable(test_context test_context.c) target_link_libraries(test_context gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) add_test(NAME context COMMAND test_context) -add_executable(test_grasshopper test_grasshopper.c) -target_link_libraries(test_grasshopper gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) -add_test(NAME grasshopper - COMMAND test_grasshopper) +add_executable(test_keyexpimp test_keyexpimp.c) +#target_compile_definitions(test_keyexpimp PUBLIC -DOPENSSL_LOAD_CONF) +target_link_libraries(test_keyexpimp gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) +add_test(NAME keyexpimp + COMMAND test_keyexpimp) + +add_executable(test_gost89 test_gost89.c) +target_link_libraries(test_gost89 gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) +add_test(NAME gost89 + COMMAND test_gost89) + +if(NOT SKIP_PERL_TESTS) + execute_process(COMMAND perl -MTest2::V0 -e "" + ERROR_QUIET RESULT_VARIABLE HAVE_TEST2_V0) + if(NOT HAVE_TEST2_V0) + add_test(NAME engine + COMMAND perl run_tests + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test) + set_tests_properties(engine PROPERTIES ENVIRONMENT + "OPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR};OPENSSL_ENGINES=${OUTPUT_DIRECTORY};OPENSSL_CONF=${CMAKE_SOURCE_DIR}/test/empty.cnf") + else() + message(STATUS "No Test2::V0 perl module (engine tests skipped)") + endif() +endif() -add_test(NAME engine - COMMAND perl run_tests - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test) +add_executable(sign benchmark/sign.c) +target_link_libraries(sign gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} ${CLOCK_GETTIME_LIB}) + +# All that may need to load just built engine will have path to it defined. +set(BINARY_TESTS_TARGETS + test_digest + test_ciphers + test_curves + test_params + test_sign + test_context + test_keyexpimp + test_gost89 + test_tls + ) +set_property(TARGET ${BINARY_TESTS_TARGETS} APPEND PROPERTY COMPILE_DEFINITIONS ENGINE_DIR="${OUTPUT_DIRECTORY}") add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES}) set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON) -add_library(gost_engine MODULE ${GOST_ENGINE_SOURCE_FILES}) +add_library(gost_engine SHARED ${GOST_ENGINE_SOURCE_FILES}) set_target_properties(gost_engine PROPERTIES PREFIX "" OUTPUT_NAME "gost") +set_target_properties(gost_engine PROPERTIES VERSION ${GOST_SOVERSION} SOVERSION ${GOST_SOVERSION}) target_link_libraries(gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) set(GOST_SUM_SOURCE_FILES @@ -144,7 +253,7 @@ set(GOST_SUM_SOURCE_FILES ) add_executable(gostsum ${GOST_SUM_SOURCE_FILES}) -target_link_libraries(gostsum gost_core) +target_link_libraries(gostsum gost_core ${OPENSSL_CRYPTO_LIBRARY}) set(GOST_12_SUM_SOURCE_FILES gost12sum.c @@ -153,25 +262,26 @@ set(GOST_12_SUM_SOURCE_FILES add_executable(gost12sum ${GOST_12_SUM_SOURCE_FILES}) target_link_libraries(gost12sum gost_core) -add_executable(unit_expimp gost_keyexpimp.c e_gost_err.c) -target_compile_definitions(unit_expimp PUBLIC -DENABLE_UNIT_TESTS) -target_compile_definitions(unit_expimp PUBLIC -DOPENSSL_LOAD_CONF) -target_link_libraries(unit_expimp PUBLIC ${OPENSSL_CRYPTO_LIBRARY}) - set_source_files_properties(tags PROPERTIES GENERATED true) add_custom_target(tags COMMAND ctags -R . ${OPENSSL_ROOT_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +add_custom_target(tcl_tests + COMMAND ENGINE_DIR=${OUTPUT_DIRECTORY} sh ./runtest.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tcl_tests) + +add_executable(test_tlstree test_tlstree.c) +target_link_libraries(test_tlstree PUBLIC ${OPENSSL_CRYPTO_LIBRARY}) + # install -set(OPENSSL_ENGINES_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/engines-${OPENSSL_VERSION_MAJOR}_${OPENSSL_VERSION_MINOR}) set(OPENSSL_MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1) install(TARGETS gost_engine gostsum gost12sum EXPORT GostEngineConfig - LIBRARY DESTINATION ${OPENSSL_ENGINES_INSTALL_DIR} + LIBRARY DESTINATION ${OPENSSL_ENGINES_DIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES gostsum.1 gost12sum.1 DESTINATION ${OPENSSL_MAN_INSTALL_DIR}) if (MSVC) - install(FILES $ DESTINATION ${OPENSSL_ENGINES_INSTALL_DIR} OPTIONAL) + install(FILES $ DESTINATION ${OPENSSL_ENGINES_DIR} OPTIONAL) install(FILES $ $ DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) endif()