X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=CMakeLists.txt;h=9768cca04e284b8520d322fb69ff953d4f601f9a;hb=9812e2735188c354c8bd405d1bde4225800cef62;hp=4c069700e334a14526f36050097444044f44abcb;hpb=6061d170c7993f943a7ee5443ed9ddc544459b9e;p=openssl-gost%2Fengine.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c06970..9768cca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,13 +8,16 @@ include(CheckCSourceRuns) enable_testing() -find_package(OpenSSL 1.1.1 REQUIRED) +find_package(OpenSSL 3.0 REQUIRED) +find_program(OPENSSL_PROGRAM openssl + PATHS ${OPENSSL_ROOT_DIR} PATH_SUFFIXES apps bin NO_DEFAULT_PATH) +message("-- Found OpenSSL application: ${OPENSSL_PROGRAM}") include_directories(${OPENSSL_INCLUDE_DIR}) if (CMAKE_C_COMPILER_ID MATCHES "Clang") - add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Qunused-arguments) + add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Qunused-arguments -Wno-deprecated-declarations) elseif(CMAKE_C_COMPILER_ID MATCHES "GNU") - add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Wno-error=unknown-pragmas) + add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb -Wno-error=unknown-pragmas -Wno-error=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) @@ -25,6 +28,7 @@ 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 @@ -65,10 +69,19 @@ if (ADDCARRY_U64) add_definitions(-DHAVE_ADDCARRY_U64) endif() -set(BIN_DIRECTORY bin) +check_c_source_runs(" + int main(void) { + char buf[16] = { 0, 1, 2 }; + int *p = (int *)(buf + 1); + int *q = (int *)(buf + 2); + return (*p == *q); + } + " RELAXED_ALIGNMENT) +if (NOT RELAXED_ALIGNMENT) + add_definitions(-DSTRICT_ALIGNMENT) +endif() -# Same soversion as OpenSSL -set(GOST_SOVERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}") +set(BIN_DIRECTORY bin) set(OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${BIN_DIRECTORY}) @@ -121,12 +134,18 @@ set(GOST_GRASSHOPPER_SOURCE_FILES set(GOST_CORE_SOURCE_FILES e_gost_err.c e_gost_err.h + gost_ameth.c + gost_pmeth.c + gost_ctl.c gost_asn1.c gost_crypt.c - gost_ctl.c - gost_eng.c gost_keywrap.c gost_keywrap.h + gost_md.c + gost_md2012.c + gost_omac.c + gost_omac_acpkm.c + gost_gost2015.c gost_lcl.h gost_params.c gost_keyexpimp.c @@ -135,6 +154,14 @@ set(GOST_CORE_SOURCE_FILES set(GOST_EC_SOURCE_FILES gost_ec_keyx.c gost_ec_sign.c + ecp_id_GostR3410_2001_CryptoPro_A_ParamSet.c + ecp_id_GostR3410_2001_CryptoPro_B_ParamSet.c + ecp_id_GostR3410_2001_CryptoPro_C_ParamSet.c + ecp_id_GostR3410_2001_TestParamSet.c + ecp_id_tc26_gost_3410_2012_256_paramSetA.c + ecp_id_tc26_gost_3410_2012_512_paramSetA.c + ecp_id_tc26_gost_3410_2012_512_paramSetB.c + ecp_id_tc26_gost_3410_2012_512_paramSetC.c ) set (GOST_OMAC_SOURCE_FILES @@ -143,6 +170,7 @@ set (GOST_OMAC_SOURCE_FILES ) set(GOST_LIB_SOURCE_FILES + ${GOST_CORE_SOURCE_FILES} ${GOST_89_SOURCE_FILES} ${GOST_HASH_SOURCE_FILES} ${GOST_HASH_2012_SOURCE_FILES} @@ -152,80 +180,92 @@ set(GOST_LIB_SOURCE_FILES ) set(GOST_ENGINE_SOURCE_FILES - ${GOST_CORE_SOURCE_FILES} - gost_ameth.c - gost_md.c - gost_md2012.c - gost_pmeth.c - gost_omac.c - gost_omac_acpkm.c + gost_eng.c ) add_executable(test_digest test_digest.c) -target_link_libraries(test_digest gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) +target_link_libraries(test_digest 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_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}) +target_link_libraries(test_curves 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}) +target_link_libraries(test_params gost_core ${OPENSSL_CRYPTO_LIBRARY}) add_test(NAME parameters COMMAND test_params) +add_executable(test_derive test_derive.c) +target_link_libraries(test_derive gost_core ${OPENSSL_CRYPTO_LIBRARY}) +add_test(NAME derive + COMMAND test_derive) + add_executable(test_sign test_sign.c) -target_link_libraries(test_sign gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY}) +target_link_libraries(test_sign 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}) +target_link_libraries(test_tls 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}) +target_link_libraries(test_context 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}) +target_link_libraries(test_keyexpimp 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}) +target_link_libraries(test_gost89 gost_core ${OPENSSL_CRYPTO_LIBRARY}) add_test(NAME gost89 COMMAND test_gost89) -if(NOT ASAN) -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") +if(NOT SKIP_PERL_TESTS) + execute_process(COMMAND perl -MTest2::V0 -e "" + ERROR_QUIET RESULT_VARIABLE HAVE_TEST2_V0) + if(NOT HAVE_TEST2_V0) + set(TEST_ENVIRONMENT + CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} + PERL5LIB=${CMAKE_CURRENT_SOURCE_DIR}/test + OPENSSL_ENGINES=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + OPENSSL_PROGRAM=${OPENSSL_PROGRAM} + OPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY} + OPENSSL_CONF=${CMAKE_CURRENT_SOURCE_DIR}/test/empty.cnf + ) + add_test(NAME engine + COMMAND prove --merge -PWrapOpenSSL ${CMAKE_CURRENT_SOURCE_DIR}/test) + set_tests_properties(engine PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}") + else() + message(STATUS "No Test2::V0 perl module (engine tests skipped)") + endif() endif() add_executable(sign benchmark/sign.c) -target_link_libraries(sign gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} ${CLOCK_GETTIME_LIB}) +target_link_libraries(sign 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_derive test_sign test_context - test_grasshopper test_keyexpimp test_gost89 test_tls @@ -235,10 +275,22 @@ set_property(TARGET ${BINARY_TESTS_TARGETS} APPEND PROPERTY COMPILE_DEFINITIONS add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES}) set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON) -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}) +# The GOST engine in module form +add_library(gost_engine MODULE ${GOST_ENGINE_SOURCE_FILES}) +# Set the suffix explicitly to adapt to OpenSSL's idea of what a +# module suffix should be +set_target_properties(gost_engine PROPERTIES + PREFIX "" OUTPUT_NAME "gost" SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) +target_link_libraries(gost_engine PRIVATE gost_core ${OPENSSL_CRYPTO_LIBRARY}) + +# The GOST engine in library form +add_library(lib_gost_engine SHARED ${GOST_ENGINE_SOURCE_FILES}) +set_target_properties(lib_gost_engine PROPERTIES + COMPILE_DEFINITIONS "BUILDING_ENGINE_AS_LIBRARY" + PUBLIC_HEADER gost-engine.h + OUTPUT_NAME "gost") +target_link_libraries(lib_gost_engine PRIVATE gost_core ${OPENSSL_CRYPTO_LIBRARY}) + set(GOST_SUM_SOURCE_FILES gostsum.c @@ -266,14 +318,21 @@ add_custom_target(tcl_tests add_executable(test_tlstree test_tlstree.c) target_link_libraries(test_tlstree PUBLIC ${OPENSSL_CRYPTO_LIBRARY}) -# install -set(OPENSSL_MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1) +# install programs and manuals +install(TARGETS gostsum gost12sum RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES gostsum.1 gost12sum.1 DESTINATION ${CMAKE_INSTALL_DIR}/man1) -install(TARGETS gost_engine gostsum gost12sum EXPORT GostEngineConfig +# install engine in library and module form +install(TARGETS lib_gost_engine EXPORT GostEngineConfig LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(TARGETS gost_engine EXPORT GostEngineConfig LIBRARY DESTINATION ${OPENSSL_ENGINES_DIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -install(FILES gostsum.1 gost12sum.1 DESTINATION ${OPENSSL_MAN_INSTALL_DIR}) + RUNTIME DESTINATION ${OPENSSL_ENGINES_DIR}) if (MSVC) - install(FILES $ DESTINATION ${OPENSSL_ENGINES_DIR} OPTIONAL) - install(FILES $ $ DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) + install(FILES $ + EXPORT GostEngineConfig DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) + install(FILES $ $ + EXPORT GostEngineConfig DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) + install(FILES $ + EXPORT GostEngineConfig DESTINATION ${OPENSSL_ENGINES_DIR} OPTIONAL) endif() +install(EXPORT GostEngineConfig DESTINATION GostEngine/share/cmake/GostEngine)