From eabbb5eb368df3ff606a472bd96a4a4077a214d8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 3 Nov 2013 03:34:00 +0100 Subject: Improve build system for ciphers and MACs as well --- cmake/config.cmake | 6 --- cmake/deps.cmake | 38 ++++++++-------- cmake/fastd_module.cmake | 9 ++-- src/CMakeLists.txt | 3 +- src/crypto/cipher/CMakeLists.txt | 56 +++++++++++++++++------- src/crypto/cipher/aes128_ctr/CMakeLists.txt | 20 +-------- src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt | 6 +-- src/crypto/mac/CMakeLists.txt | 56 +++++++++++++++++------- src/crypto/mac/ghash/CMakeLists.txt | 20 +-------- src/crypto/mac/ghash/builtin/CMakeLists.txt | 3 +- src/methods/CMakeLists.txt | 15 ++++--- 11 files changed, 121 insertions(+), 111 deletions(-) diff --git a/cmake/config.cmake b/cmake/config.cmake index 53f4b65..cc5ca01 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -26,12 +26,6 @@ set(WITH_CMDLINE_COMMANDS TRUE CACHE BOOL "Include support for setting handler s set(MAX_CONFIG_DEPTH 10 CACHE STRING "Maximum config include depth") -set(WITH_CIPHER_AES128_CTR TRUE CACHE BOOL "Include the AES128-CTR cipher algorithm") -set(WITH_CIPHER_AES128_CTR_NACL TRUE CACHE BOOL "Include the AES128-CTR implementation from the NaCl library") - -set(WITH_MAC_GHASH TRUE CACHE BOOL "Include the GHASH MAC algorithm") -set(WITH_MAC_GHASH_BUILTIN TRUE CACHE BOOL "Include the built-in GHASH implementation") - # Ensure the value is numeric math(EXPR MAX_CONFIG_DEPTH_NUM ${MAX_CONFIG_DEPTH}) diff --git a/cmake/deps.cmake b/cmake/deps.cmake index e49efcd..fa3cb03 100644 --- a/cmake/deps.cmake +++ b/cmake/deps.cmake @@ -16,26 +16,24 @@ set(NACL_LIBRARY_DIRS "") set(NACL_LIBRARIES "") set(NACL_LDFLAGS_OTHER "") -if(WITH_METHOD_XSALSA20_POLY1305 OR WITH_CIPHER_AES128_CTR_NACL) - if(USE_LIBSODIUM) - pkg_check_modules(SODIUM REQUIRED libsodium) - - set(NACL_INCLUDE_DIRS "${SODIUM_INCLUDE_DIRS}") - foreach(dir "${SODIUM_INCLUDEDIR}" ${SODIUM_INCLUDE_DIRS}) - list(APPEND NACL_INCLUDE_DIRS "${dir}/sodium") - endforeach(dir) - - set(NACL_CFLAGS_OTHER "${SODIUM_CFLAGS_OTHER}") - set(NACL_LIBRARY_DIRS "${SODIUM_LIBRARY_DIRS}") - set(NACL_LIBRARIES "${SODIUM_LIBRARIES}") - set(NACL_LDFLAGS_OTHER "${SODIUM_LDFLAGS_OTHER}") - else(USE_LIBSODIUM) - find_package(NaCl REQUIRED) - - set(NACL_INCLUDE_DIRS "${NACL_INCLUDE_DIR}") - set(NACL_LIBRARIES "${NACL_LIBRARY}") - endif(USE_LIBSODIUM) -endif() +if(USE_LIBSODIUM) + pkg_check_modules(SODIUM REQUIRED libsodium) + + set(NACL_INCLUDE_DIRS "${SODIUM_INCLUDE_DIRS}") + foreach(dir "${SODIUM_INCLUDEDIR}" ${SODIUM_INCLUDE_DIRS}) + list(APPEND NACL_INCLUDE_DIRS "${dir}/sodium") + endforeach(dir) + + set(NACL_CFLAGS_OTHER "${SODIUM_CFLAGS_OTHER}") + set(NACL_LIBRARY_DIRS "${SODIUM_LIBRARY_DIRS}") + set(NACL_LIBRARIES "${SODIUM_LIBRARIES}") + set(NACL_LDFLAGS_OTHER "${SODIUM_LDFLAGS_OTHER}") +else(USE_LIBSODIUM) + find_package(NaCl REQUIRED) + + set(NACL_INCLUDE_DIRS "${NACL_INCLUDE_DIR}") + set(NACL_LIBRARIES "${NACL_LIBRARY}") +endif(USE_LIBSODIUM) if(WITH_CAPABILITIES) diff --git a/cmake/fastd_module.cmake b/cmake/fastd_module.cmake index 1c2da9d..53b6d0f 100644 --- a/cmake/fastd_module.cmake +++ b/cmake/fastd_module.cmake @@ -1,10 +1,11 @@ -function(fastd_module type name) +function(fastd_module type info name) string(TOUPPER "${type}" TYPE) string(REPLACE - _ name_ "${name}") + string(REPLACE " " _ name_ "${name_}") string(TOUPPER "${name_}" NAME) - set(WITH_${TYPE}_${NAME} TRUE CACHE BOOL "Include the ${name} ${type}") + set(WITH_${TYPE}_${NAME} TRUE CACHE BOOL "Include the ${name} ${info}") if(WITH_${TYPE}_${NAME}) add_library(${type}_${name_} STATIC ${ARGN}) @@ -13,8 +14,6 @@ function(fastd_module type name) set_property(TARGET ${type}s APPEND PROPERTY LINK_LIBRARIES ${type}_${name_}) list(APPEND ${TYPE}S ${name_}) - - set_property(GLOBAL APPEND PROPERTY FASTD_${TYPE}S ${name_}) endif(WITH_${TYPE}_${NAME}) endfunction(fastd_module) @@ -22,6 +21,7 @@ function(fastd_module_include_directories type name) string(TOUPPER "${type}" TYPE) string(REPLACE - _ name_ "${name}") + string(REPLACE " " _ name_ "${name_}") string(TOUPPER "${name_}" NAME) if(WITH_${TYPE}_${NAME}) @@ -33,6 +33,7 @@ function(fastd_module_link_libraries type name) string(TOUPPER "${type}" TYPE) string(REPLACE - _ name_ "${name}") + string(REPLACE " " _ name_ "${name_}") string(TOUPPER "${name_}" NAME) if(WITH_${TYPE}_${NAME}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5c900f..361b546 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,12 +37,11 @@ add_executable(fastd tuntap.c ${BISON_fastd_config_parse_OUTPUTS} ${PROTOCOL_SOURCES} - ${CRYPTO_SOURCES} ) set_property(TARGET fastd PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") set_property(TARGET fastd PROPERTY LINK_FLAGS "-pthread ${UECC_LDFLAGS_OTHER} ${NACL_LDFLAGS_OTHER}") target_include_directories(fastd PRIVATE ${CAP_INCLUDE_DIR} ${NACL_INCLUDE_DIRS}) -target_link_libraries(fastd methods ${RT_LIBRARY} ${CAP_LIBRARY} ${UECC_LIBRARIES} ${NACL_LIBRARIES}) +target_link_libraries(fastd methods ciphers macs ${RT_LIBRARY} ${CAP_LIBRARY} ${UECC_LIBRARIES} ${NACL_LIBRARIES}) add_dependencies(fastd version) diff --git a/src/crypto/cipher/CMakeLists.txt b/src/crypto/cipher/CMakeLists.txt index 00b8560..6cf6d64 100644 --- a/src/crypto/cipher/CMakeLists.txt +++ b/src/crypto/cipher/CMakeLists.txt @@ -1,34 +1,58 @@ -set(CIPHERS "") +add_library(ciphers STATIC "${CMAKE_CURRENT_BINARY_DIR}/ciphers.c") -if(WITH_CIPHER_AES128_CTR) - list(APPEND CIPHERS aes128_ctr) -endif(WITH_CIPHER_AES128_CTR) +function(fastd_cipher name) + string(REPLACE - _ name_ "${name}") + string(TOUPPER "${name_}" NAME) + + set(WITH_CIPHER_${NAME} TRUE CACHE BOOL "Include the ${name} cipher") + + if(WITH_CIPHER_${NAME}) + set_property(GLOBAL APPEND PROPERTY FASTD_CIPHERS ${name}) + endif(WITH_CIPHER_${NAME}) +endfunction(fastd_cipher) + + +macro(fastd_cipher_impl cipher name) + string(REPLACE - _ cipher_ "${cipher}") + string(TOUPPER "${cipher_}" CIPHER) + + set_property(GLOBAL APPEND PROPERTY FASTD_CIPHER_${CIPHER}_IMPLS ${name}) + + fastd_module(cipher "cipher implementation" "${cipher} ${name}" ${ARGN}) +endmacro(fastd_cipher_impl) + +macro(fastd_cipher_impl_include_directories cipher name) + fastd_module_include_directories(cipher "${cipher} ${name}" ${ARGN}) +endmacro(fastd_cipher_impl_include_directories) + +macro(fastd_cipher_impl_link_libraries cipher name) + fastd_module_link_libraries(cipher "${cipher} ${name}" ${ARGN}) +endmacro(fastd_cipher_impl_link_libraries) + + +add_subdirectory(aes128_ctr) -set(CIPHER_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/ciphers.c") set(CIPHER_DEFINITIONS "") set(CIPHER_IMPLS "") set(CIPHER_LIST "") +get_property(CIPHERS GLOBAL PROPERTY FASTD_CIPHERS) foreach(cipher ${CIPHERS}) - add_subdirectory(${cipher}) - - list(APPEND CIPHER_SOURCES ${IMPL_SOURCES}) + string(REPLACE - _ cipher_ "${cipher}") + string(TOUPPER "${cipher_}" CIPHER) - set(CIPHER_LIST "${CIPHER_LIST}\n{\"${CIPHER_NAME}\", cipher_${cipher}_impls},") - set(CIPHER_IMPLS "${CIPHER_IMPLS}\nstatic const fastd_cipher_t *const cipher_${cipher}_impls[] = {") + set(CIPHER_LIST "${CIPHER_LIST}\n{\"${cipher}\", cipher_${cipher_}_impls},") + set(CIPHER_IMPLS "${CIPHER_IMPLS}\nstatic const fastd_cipher_t *const cipher_${cipher_}_impls[] = {") + get_property(IMPLS GLOBAL PROPERTY FASTD_CIPHER_${CIPHER}_IMPLS) foreach(impl ${IMPLS}) - set(CIPHER_DEFINITIONS "${CIPHER_DEFINITIONS}\nextern const fastd_cipher_t fastd_cipher_${cipher}_${impl};") - set(CIPHER_IMPLS "${CIPHER_IMPLS}&fastd_cipher_${cipher}_${impl}, ") + set(CIPHER_DEFINITIONS "${CIPHER_DEFINITIONS}\nextern const fastd_cipher_t fastd_cipher_${cipher_}_${impl};") + set(CIPHER_IMPLS "${CIPHER_IMPLS}&fastd_cipher_${cipher_}_${impl}, ") endforeach(impl) set(CIPHER_IMPLS "${CIPHER_IMPLS}NULL};") endforeach(cipher) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ciphers.c.in ${CMAKE_CURRENT_BINARY_DIR}/ciphers.c) - - -set(CIPHER_SOURCES "${CIPHER_SOURCES}" PARENT_SCOPE) diff --git a/src/crypto/cipher/aes128_ctr/CMakeLists.txt b/src/crypto/cipher/aes128_ctr/CMakeLists.txt index 6237a7c..16eeeab 100644 --- a/src/crypto/cipher/aes128_ctr/CMakeLists.txt +++ b/src/crypto/cipher/aes128_ctr/CMakeLists.txt @@ -1,18 +1,2 @@ -set(IMPLS "") - -if(WITH_CIPHER_AES128_CTR_NACL) - list(APPEND IMPLS nacl) -endif(WITH_CIPHER_AES128_CTR_NACL) - -set(IMPL_SOURCES "") - -foreach(impl ${IMPLS}) - add_subdirectory(${impl}) - - list(APPEND IMPL_SOURCES $) -endforeach(impl) - - -set(CIPHER_NAME "aes128-ctr" PARENT_SCOPE) -set(IMPLS "${IMPLS}" PARENT_SCOPE) -set(IMPL_SOURCES "${IMPL_SOURCES}" PARENT_SCOPE) +fastd_cipher(aes128-ctr) +add_subdirectory(nacl) diff --git a/src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt b/src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt index ab0d0e8..50e2283 100644 --- a/src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt +++ b/src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt @@ -1,5 +1,5 @@ -add_library(cipher_aes128_ctr_nacl OBJECT +fastd_cipher_impl(aes128-ctr nacl cipher_aes128_ctr_nacl.c ) -set_property(TARGET cipher_aes128_ctr_nacl PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") -target_include_directories(cipher_aes128_ctr_nacl PRIVATE ${NACL_INCLUDE_DIRS}) +fastd_cipher_impl_include_directories(aes128-ctr nacl ${NACL_INCLUDE_DIRS}) +fastd_cipher_impl_link_libraries(aes128-ctr nacl ${NACL_LIBRARIES}) diff --git a/src/crypto/mac/CMakeLists.txt b/src/crypto/mac/CMakeLists.txt index 7f8664c..eb3c903 100644 --- a/src/crypto/mac/CMakeLists.txt +++ b/src/crypto/mac/CMakeLists.txt @@ -1,34 +1,58 @@ -set(MACS "") +add_library(macs STATIC "${CMAKE_CURRENT_BINARY_DIR}/macs.c") -if(WITH_MAC_GHASH) - list(APPEND MACS ghash) -endif(WITH_MAC_GHASH) +function(fastd_mac name) + string(REPLACE - _ name_ "${name}") + string(TOUPPER "${name_}" NAME) + + set(WITH_MAC_${NAME} TRUE CACHE BOOL "Include the ${name} MAC") + + if(WITH_MAC_${NAME}) + set_property(GLOBAL APPEND PROPERTY FASTD_MACS ${name}) + endif(WITH_MAC_${NAME}) +endfunction(fastd_mac) + + +macro(fastd_mac_impl mac name) + string(REPLACE - _ mac_ "${mac}") + string(TOUPPER "${mac_}" MAC) + + set_property(GLOBAL APPEND PROPERTY FASTD_MAC_${MAC}_IMPLS ${name}) + + fastd_module(mac "MAC implementation" "${mac} ${name}" ${ARGN}) +endmacro(fastd_mac_impl) + +macro(fastd_mac_impl_include_directories mac name) + fastd_module_include_directories(mac "${mac} ${name}" ${ARGN}) +endmacro(fastd_mac_impl_include_directories) + +macro(fastd_mac_impl_link_libraries mac name) + fastd_module_link_libraries(mac "${mac} ${name}" ${ARGN}) +endmacro(fastd_mac_impl_link_libraries) + + +add_subdirectory(ghash) -set(MAC_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/macs.c") set(MAC_DEFINITIONS "") set(MAC_IMPLS "") set(MAC_LIST "") +get_property(MACS GLOBAL PROPERTY FASTD_MACS) foreach(mac ${MACS}) - add_subdirectory(${mac}) - - list(APPEND MAC_SOURCES ${IMPL_SOURCES}) + string(REPLACE - _ mac_ "${mac}") + string(TOUPPER "${mac_}" MAC) - set(MAC_LIST "${MAC_LIST}\n{\"${MAC_NAME}\", mac_${mac}_impls},") - set(MAC_IMPLS "${MAC_IMPLS}\nstatic const fastd_mac_t *const mac_${mac}_impls[] = {") + set(MAC_LIST "${MAC_LIST}\n{\"${mac}\", mac_${mac_}_impls},") + set(MAC_IMPLS "${MAC_IMPLS}\nstatic const fastd_mac_t *const mac_${mac_}_impls[] = {") + get_property(IMPLS GLOBAL PROPERTY FASTD_MAC_${MAC}_IMPLS) foreach(impl ${IMPLS}) - set(MAC_DEFINITIONS "${MAC_DEFINITIONS}\nextern const fastd_mac_t fastd_mac_${mac}_${impl};") - set(MAC_IMPLS "${MAC_IMPLS}&fastd_mac_${mac}_${impl}, ") + set(MAC_DEFINITIONS "${MAC_DEFINITIONS}\nextern const fastd_mac_t fastd_mac_${mac_}_${impl};") + set(MAC_IMPLS "${MAC_IMPLS}&fastd_mac_${mac_}_${impl}, ") endforeach(impl) set(MAC_IMPLS "${MAC_IMPLS}NULL};") endforeach(mac) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/macs.c.in ${CMAKE_CURRENT_BINARY_DIR}/macs.c) - - -set(MAC_SOURCES "${MAC_SOURCES}" PARENT_SCOPE) diff --git a/src/crypto/mac/ghash/CMakeLists.txt b/src/crypto/mac/ghash/CMakeLists.txt index 7d697e8..7d44b8a 100644 --- a/src/crypto/mac/ghash/CMakeLists.txt +++ b/src/crypto/mac/ghash/CMakeLists.txt @@ -1,18 +1,2 @@ -set(IMPLS "") - -if(WITH_MAC_GHASH_BUILTIN) - list(APPEND IMPLS builtin) -endif(WITH_MAC_GHASH_BUILTIN) - -set(IMPL_SOURCES "") - -foreach(impl ${IMPLS}) - add_subdirectory(${impl}) - - list(APPEND IMPL_SOURCES $) -endforeach(impl) - - -set(MAC_NAME "ghash" PARENT_SCOPE) -set(IMPLS "${IMPLS}" PARENT_SCOPE) -set(IMPL_SOURCES "${IMPL_SOURCES}" PARENT_SCOPE) +fastd_mac(ghash) +add_subdirectory(builtin) diff --git a/src/crypto/mac/ghash/builtin/CMakeLists.txt b/src/crypto/mac/ghash/builtin/CMakeLists.txt index b7b862a..f5cb130 100644 --- a/src/crypto/mac/ghash/builtin/CMakeLists.txt +++ b/src/crypto/mac/ghash/builtin/CMakeLists.txt @@ -1,4 +1,3 @@ -add_library(mac_ghash_builtin OBJECT +fastd_mac_impl(ghash builtin ghash_builtin.c ) -set_property(TARGET mac_ghash_builtin PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") diff --git a/src/methods/CMakeLists.txt b/src/methods/CMakeLists.txt index 4a1f986..0060f7c 100644 --- a/src/methods/CMakeLists.txt +++ b/src/methods/CMakeLists.txt @@ -1,16 +1,17 @@ add_library(methods STATIC "${CMAKE_CURRENT_BINARY_DIR}/methods.c") add_library(method_common STATIC "common.c") -macro(fastd_method) - fastd_module(method ${ARGV}) +macro(fastd_method name) + fastd_module(method "method" ${name} ${ARGN}) + set_property(GLOBAL APPEND PROPERTY FASTD_METHODS ${name}) endmacro(fastd_method) macro(fastd_method_include_directories) - fastd_module_include_directories(method ${ARGV}) + fastd_module_include_directories(method ${ARGN}) endmacro(fastd_method_include_directories) macro(fastd_method_link_libraries) - fastd_module_link_libraries(method ${ARGV}) + fastd_module_link_libraries(method ${ARGN}) endmacro(fastd_method_link_libraries) @@ -24,8 +25,10 @@ set(METHOD_LIST "") get_property(METHODS GLOBAL PROPERTY FASTD_METHODS) foreach(method ${METHODS}) - set(METHOD_DEFINITIONS "${METHOD_DEFINITIONS}\nextern const fastd_method_t fastd_method_${method};") - set(METHOD_LIST "${METHOD_LIST}\n&fastd_method_${method},") + string(REPLACE - _ method_ "${method}") + + set(METHOD_DEFINITIONS "${METHOD_DEFINITIONS}\nextern const fastd_method_t fastd_method_${method_};") + set(METHOD_LIST "${METHOD_LIST}\n&fastd_method_${method_},") endforeach(method) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/methods.c.in ${CMAKE_CURRENT_BINARY_DIR}/methods.c) -- cgit v1.2.3