From e123395317421f8b75a09e6c556aa1ed6c4cfba2 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 11 Feb 2020 16:51:34 +0100 Subject: [PATCH] cmake: link programs that only use crypto with libmbedcrypto When building with CMake, for sample programs that only use functionality in libmbedcrypto (i.e. crypto and platform), link with libmbedcrypto, not with libmbedtls. This doesn't change the result, because the linker skips libraries in which no symbol is used, but it changes the build dependencies, and it has the advantage of bringing programs/*/CMakeLists.txt closer to the corresponding files under crypto/. The programs concerned are crypto sample and test programs, and programs that only use (potential) platform functions such as mbedtls_printf. dh_client and dh_server keep linking with mbedtls because they use functions from the net_sockets module. --- programs/aes/CMakeLists.txt | 4 ++-- programs/hash/CMakeLists.txt | 4 ++-- programs/pkey/CMakeLists.txt | 36 +++++++++++++++++----------------- programs/random/CMakeLists.txt | 6 +++--- programs/test/CMakeLists.txt | 8 ++++---- programs/util/CMakeLists.txt | 2 +- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/programs/aes/CMakeLists.txt b/programs/aes/CMakeLists.txt index f5a0caabb..6c4c7e10f 100644 --- a/programs/aes/CMakeLists.txt +++ b/programs/aes/CMakeLists.txt @@ -1,8 +1,8 @@ add_executable(aescrypt2 aescrypt2.c) -target_link_libraries(aescrypt2 mbedtls) +target_link_libraries(aescrypt2 mbedcrypto) add_executable(crypt_and_hash crypt_and_hash.c) -target_link_libraries(crypt_and_hash mbedtls) +target_link_libraries(crypt_and_hash mbedcrypto) install(TARGETS aescrypt2 crypt_and_hash DESTINATION "bin" diff --git a/programs/hash/CMakeLists.txt b/programs/hash/CMakeLists.txt index eda975bb0..3c6cca9d4 100644 --- a/programs/hash/CMakeLists.txt +++ b/programs/hash/CMakeLists.txt @@ -1,8 +1,8 @@ add_executable(hello hello.c) -target_link_libraries(hello mbedtls) +target_link_libraries(hello mbedcrypto) add_executable(generic_sum generic_sum.c) -target_link_libraries(generic_sum mbedtls) +target_link_libraries(generic_sum mbedcrypto) install(TARGETS hello generic_sum DESTINATION "bin" diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index 5a37a4212..8456228db 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -2,61 +2,61 @@ add_executable(dh_client dh_client.c) target_link_libraries(dh_client mbedtls) add_executable(dh_genprime dh_genprime.c) -target_link_libraries(dh_genprime mbedtls) +target_link_libraries(dh_genprime mbedcrypto) add_executable(dh_server dh_server.c) target_link_libraries(dh_server mbedtls) add_executable(ecdh_curve25519 ecdh_curve25519.c) -target_link_libraries(ecdh_curve25519 mbedtls) +target_link_libraries(ecdh_curve25519 mbedcrypto) add_executable(ecdsa ecdsa.c) -target_link_libraries(ecdsa mbedtls) +target_link_libraries(ecdsa mbedcrypto) add_executable(gen_key gen_key.c) -target_link_libraries(gen_key mbedtls) +target_link_libraries(gen_key mbedcrypto) add_executable(key_app key_app.c) -target_link_libraries(key_app mbedtls) +target_link_libraries(key_app mbedcrypto) add_executable(key_app_writer key_app_writer.c) -target_link_libraries(key_app_writer mbedtls) +target_link_libraries(key_app_writer mbedcrypto) add_executable(mpi_demo mpi_demo.c) -target_link_libraries(mpi_demo mbedtls) +target_link_libraries(mpi_demo mbedcrypto) add_executable(rsa_genkey rsa_genkey.c) -target_link_libraries(rsa_genkey mbedtls) +target_link_libraries(rsa_genkey mbedcrypto) add_executable(rsa_sign rsa_sign.c) -target_link_libraries(rsa_sign mbedtls) +target_link_libraries(rsa_sign mbedcrypto) add_executable(rsa_verify rsa_verify.c) -target_link_libraries(rsa_verify mbedtls) +target_link_libraries(rsa_verify mbedcrypto) add_executable(rsa_sign_pss rsa_sign_pss.c) -target_link_libraries(rsa_sign_pss mbedtls) +target_link_libraries(rsa_sign_pss mbedcrypto) add_executable(rsa_verify_pss rsa_verify_pss.c) -target_link_libraries(rsa_verify_pss mbedtls) +target_link_libraries(rsa_verify_pss mbedcrypto) add_executable(rsa_encrypt rsa_encrypt.c) -target_link_libraries(rsa_encrypt mbedtls) +target_link_libraries(rsa_encrypt mbedcrypto) add_executable(rsa_decrypt rsa_decrypt.c) -target_link_libraries(rsa_decrypt mbedtls) +target_link_libraries(rsa_decrypt mbedcrypto) add_executable(pk_sign pk_sign.c) -target_link_libraries(pk_sign mbedtls) +target_link_libraries(pk_sign mbedcrypto) add_executable(pk_verify pk_verify.c) -target_link_libraries(pk_verify mbedtls) +target_link_libraries(pk_verify mbedcrypto) add_executable(pk_encrypt pk_encrypt.c) -target_link_libraries(pk_encrypt mbedtls) +target_link_libraries(pk_encrypt mbedcrypto) add_executable(pk_decrypt pk_decrypt.c) -target_link_libraries(pk_decrypt mbedtls) +target_link_libraries(pk_decrypt mbedcrypto) install(TARGETS dh_client dh_genprime dh_server key_app mpi_demo rsa_genkey rsa_sign rsa_verify rsa_encrypt rsa_decrypt pk_encrypt pk_decrypt pk_sign pk_verify gen_key DESTINATION "bin" diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index 30933d88d..630c66e9d 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,11 +1,11 @@ add_executable(gen_random_havege gen_random_havege.c) -target_link_libraries(gen_random_havege mbedtls) +target_link_libraries(gen_random_havege mbedcrypto) add_executable(gen_random_ctr_drbg gen_random_ctr_drbg.c) -target_link_libraries(gen_random_ctr_drbg mbedtls) +target_link_libraries(gen_random_ctr_drbg mbedcrypto) add_executable(gen_entropy gen_entropy.c) -target_link_libraries(gen_entropy mbedtls) +target_link_libraries(gen_entropy mbedcrypto) install(TARGETS gen_random_havege gen_random_ctr_drbg gen_entropy DESTINATION "bin" diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 64ed379e7..a26c096de 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -14,22 +14,22 @@ add_executable(selftest selftest.c) target_link_libraries(selftest ${libs}) add_executable(benchmark benchmark.c) -target_link_libraries(benchmark ${libs}) +target_link_libraries(benchmark mbedcrypto) if(TEST_CPP) add_executable(cpp_dummy_build cpp_dummy_build.cpp) - target_link_libraries(cpp_dummy_build ${libs}) + target_link_libraries(cpp_dummy_build mbedcrypto) endif() add_executable(udp_proxy udp_proxy.c) target_link_libraries(udp_proxy ${libs}) add_executable(zeroize zeroize.c) -target_link_libraries(zeroize ${libs}) +target_link_libraries(zeroize mbedcrypto) add_executable(query_compile_time_config query_compile_time_config.c) target_sources(query_compile_time_config PUBLIC query_config.c) -target_link_libraries(query_compile_time_config ${libs}) +target_link_libraries(query_compile_time_config mbedcrypto) install(TARGETS selftest benchmark udp_proxy query_compile_time_config DESTINATION "bin" diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt index f9b660453..4c3fb0dfa 100644 --- a/programs/util/CMakeLists.txt +++ b/programs/util/CMakeLists.txt @@ -1,5 +1,5 @@ set(libs - mbedtls + mbedcrypto ) add_executable(strerror strerror.c)