From bb324029ad442a1f6dd7049a6e6fc1cbe4a05799 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 29 Oct 2013 03:45:34 +0100 Subject: Allow using libsodium instead of NaCl As libsodium has some strange include files (like a version.h), we try to use absolute include paths whenever possible in fastd now and rename our generated headers. --- CMakeLists.txt | 42 +++++++++++---- config.h.in | 61 ---------------------- fastd_config.h.in | 63 +++++++++++++++++++++++ src/CMakeLists.txt | 10 ++-- src/compat.h | 2 +- src/fastd.c | 10 +++- src/handshake.c | 2 +- src/methods/aes128_gcm/CMakeLists.txt | 2 +- src/methods/aes128_gcm/aes128_gcm.c | 4 +- src/methods/common.h | 2 +- src/methods/null/CMakeLists.txt | 2 +- src/methods/null/null.c | 2 +- src/methods/xsalsa20_poly1305/CMakeLists.txt | 2 +- src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c | 2 +- src/options.c | 2 +- src/protocols/ec25519_fhmqvc/CMakeLists.txt | 2 +- src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c | 8 +-- src/types.h | 2 +- 18 files changed, 126 insertions(+), 94 deletions(-) delete mode 100644 config.h.in create mode 100644 fastd_config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 910ba33..1a00617 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ endif(LINUX) set(WITH_METHOD_XSALSA20_POLY1305 TRUE CACHE BOOL "Include xsalsa20-poly1305 method") set(WITH_METHOD_AES128_GCM TRUE CACHE BOOL "Include aes128-gcm method") +set(USE_LIBSODIUM FALSE CACHE BOOL "Use libsodium instead of NaCl") + set(MAX_CONFIG_DEPTH 10 CACHE STRING "Maximum config include depth") @@ -87,11 +89,31 @@ find_package(PkgConfig REQUIRED) pkg_check_modules(UECC REQUIRED libuecc>=3) +set(NACL_INCLUDE_DIRS "") +set(NACL_CFLAGS_OTHER "") +set(NACL_LIBRARY_DIRS "") +set(NACL_LIBRARIES "") +set(NACL_LDFLAGS_OTHER "") + if(WITH_METHOD_XSALSA20_POLY1305 OR WITH_CRYPTO_AES128CTR_NACL) - find_package(NaCl REQUIRED) -else(WITH_METHOD_XSALSA20_POLY1305 OR WITH_CRYPTO_AES128CTR_NACL) - set(NACL_INCLUDE_DIR "") - set(NACL_LIBRARY "") + 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(WITH_METHOD_XSALSA20_POLY1305 OR WITH_CRYPTO_AES128CTR_NACL) @@ -143,15 +165,15 @@ check_type_size("struct ethhdr" SIZEOF_ETHHDR) string(COMPARE NOTEQUAL "${SIZEOF_ETHHDR}" "" HAVE_ETHHDR) -configure_file(${FASTD_SOURCE_DIR}/config.h.in ${FASTD_BINARY_DIR}/config.h) +configure_file(${FASTD_SOURCE_DIR}/fastd_config.h.in ${FASTD_BINARY_DIR}/fastd_config.h) add_custom_target( version - COMMAND echo "#ifndef _FASTD_VERSION_H_" > ${FASTD_BINARY_DIR}/version.h.new - COMMAND echo "#define _FASTD_VERSION_H_" >> ${FASTD_BINARY_DIR}/version.h.new - COMMAND sh -c "echo \"#define FASTD_VERSION \\\"$(git --git-dir=./.git describe --dirty 2>/dev/null || echo ${FASTD_VERSION})\\\"\"" >> ${FASTD_BINARY_DIR}/version.h.new - COMMAND echo "#endif /* _FASTD_VERSION_H_ */" >> ${FASTD_BINARY_DIR}/version.h.new - COMMAND cmp -s ${FASTD_BINARY_DIR}/version.h.new ${FASTD_BINARY_DIR}/version.h && rm ${FASTD_BINARY_DIR}/version.h.new || mv ${FASTD_BINARY_DIR}/version.h.new ${FASTD_BINARY_DIR}/version.h + COMMAND echo "#ifndef _FASTD_VERSION_H_" > ${FASTD_BINARY_DIR}/fastd_version.h.new + COMMAND echo "#define _FASTD_VERSION_H_" >> ${FASTD_BINARY_DIR}/fastd_version.h.new + COMMAND sh -c "echo \"#define FASTD_VERSION \\\"$(git --git-dir=./.git describe --dirty 2>/dev/null || echo ${FASTD_VERSION})\\\"\"" >> ${FASTD_BINARY_DIR}/fastd_version.h.new + COMMAND echo "#endif /* _FASTD_VERSION_H_ */" >> ${FASTD_BINARY_DIR}/fastd_version.h.new + COMMAND cmp -s ${FASTD_BINARY_DIR}/fastd_version.h.new ${FASTD_BINARY_DIR}/fastd_version.h && rm ${FASTD_BINARY_DIR}/fastd_version.h.new || mv ${FASTD_BINARY_DIR}/fastd_version.h.new ${FASTD_BINARY_DIR}/fastd_version.h WORKING_DIRECTORY "${FASTD_SOURCE_DIR}" VERBATIM ) diff --git a/config.h.in b/config.h.in deleted file mode 100644 index 5be4660..0000000 --- a/config.h.in +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright (c) 2012-2013, Matthias Schiffer - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#ifndef _FASTD_CONFIG_H_ -#define _FASTD_CONFIG_H_ - -#cmakedefine HAVE_AI_ADDRCONFIG -#cmakedefine HAVE_ETHHDR -#cmakedefine HAVE_GET_CURRENT_DIR_NAME - - -#cmakedefine USE_BINDTODEVICE -#cmakedefine USE_PMTU -#cmakedefine USE_PKTINFO -#cmakedefine USE_MULTIAF_BIND - - -#cmakedefine WITH_CAPABILITIES -#cmakedefine WITH_CMDLINE_USER -#cmakedefine WITH_CMDLINE_LOGGING -#cmakedefine WITH_CMDLINE_OPERATION -#cmakedefine WITH_CMDLINE_COMMANDS - - -#cmakedefine USE_CRYPTO_AES128CTR -#cmakedefine USE_CRYPTO_GHASH - -#cmakedefine WITH_CRYPTO_AES128CTR_NACL -#cmakedefine WITH_CRYPTO_AES128CTR_LINUX -#cmakedefine WITH_CRYPTO_GHASH_BUILTIN -#cmakedefine WITH_CRYPTO_GHASH_LINUX - -#cmakedefine WITH_METHOD_XSALSA20_POLY1305 -#cmakedefine WITH_METHOD_AES128_GCM - -#define MAX_CONFIG_DEPTH @MAX_CONFIG_DEPTH_NUM@ - -#endif /* _FASTD_CONFIG_H_ */ diff --git a/fastd_config.h.in b/fastd_config.h.in new file mode 100644 index 0000000..4868985 --- /dev/null +++ b/fastd_config.h.in @@ -0,0 +1,63 @@ +/* + Copyright (c) 2012-2013, Matthias Schiffer + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef _FASTD_CONFIG_H_ +#define _FASTD_CONFIG_H_ + +#cmakedefine HAVE_AI_ADDRCONFIG +#cmakedefine HAVE_ETHHDR +#cmakedefine HAVE_GET_CURRENT_DIR_NAME + + +#cmakedefine USE_BINDTODEVICE +#cmakedefine USE_PMTU +#cmakedefine USE_PKTINFO +#cmakedefine USE_MULTIAF_BIND + + +#cmakedefine WITH_CAPABILITIES +#cmakedefine WITH_CMDLINE_USER +#cmakedefine WITH_CMDLINE_LOGGING +#cmakedefine WITH_CMDLINE_OPERATION +#cmakedefine WITH_CMDLINE_COMMANDS + + +#cmakedefine USE_LIBSODIUM + +#cmakedefine USE_CRYPTO_AES128CTR +#cmakedefine USE_CRYPTO_GHASH + +#cmakedefine WITH_CRYPTO_AES128CTR_NACL +#cmakedefine WITH_CRYPTO_AES128CTR_LINUX +#cmakedefine WITH_CRYPTO_GHASH_BUILTIN +#cmakedefine WITH_CRYPTO_GHASH_LINUX + +#cmakedefine WITH_METHOD_XSALSA20_POLY1305 +#cmakedefine WITH_METHOD_AES128_GCM + +#define MAX_CONFIG_DEPTH @MAX_CONFIG_DEPTH_NUM@ + +#endif /* _FASTD_CONFIG_H_ */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d3fa991..4f8ab25 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,8 @@ set_directory_properties(PROPERTIES COMPILE_DEFINITIONS _GNU_SOURCE) -set(FASTD_CFLAGS "-Wall -pthread ${UECC_CFLAGS_OTHER}") +set(FASTD_CFLAGS "-Wall -pthread ${UECC_CFLAGS_OTHER} ${NACL_CFLAGS_OTHER}") -include_directories(BEFORE ${FASTD_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CAP_INCLUDE_DIR} ${NACL_INCLUDE_DIR}) -link_directories(${UECC_LIBRARY_DIRS}) +include_directories(${FASTD_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CAP_INCLUDE_DIR} ${NACL_INCLUDE_DIRS}) +link_directories(${UECC_LIBRARY_DIRS} ${NACL_LIBRARY_DIRS}) add_subdirectory(protocols) @@ -35,8 +35,8 @@ add_executable(fastd ${METHOD_SOURCES} ) set_property(TARGET fastd PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") -set_property(TARGET fastd PROPERTY LINK_FLAGS "-pthread ${UECC_LDFLAGS_OTHER}") -target_link_libraries(fastd ${RT_LIBRARY} ${CAP_LIBRARY} ${UECC_LIBRARIES} ${NACL_LIBRARY}) +set_property(TARGET fastd PROPERTY LINK_FLAGS "-pthread ${UECC_LDFLAGS_OTHER} ${NACL_LDFLAGS_OTHER}") +target_link_libraries(fastd ${RT_LIBRARY} ${CAP_LIBRARY} ${UECC_LIBRARIES} ${NACL_LIBRARIES}) add_dependencies(fastd version) diff --git a/src/compat.h b/src/compat.h index c127100..ba77f65 100644 --- a/src/compat.h +++ b/src/compat.h @@ -27,7 +27,7 @@ #ifndef _FASTD_COMPAT_H_ #define _FASTD_COMPAT_H_ -#include +#include #include #include diff --git a/src/fastd.c b/src/fastd.c index c434216..ea197d3 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -28,7 +28,7 @@ #include "crypto.h" #include "handshake.h" #include "peer.h" -#include +#include #include #include @@ -39,6 +39,10 @@ #include #include +#ifdef USE_LIBSODIUM +#include +#endif + static volatile bool sighup = false; static volatile bool terminate = false; @@ -751,6 +755,10 @@ static void drop_caps(fastd_context_t *ctx) { } int main(int argc, char *argv[]) { +#ifdef USE_LIBSODIUM + sodium_init(); +#endif + fastd_context_t ctx = {}; close_fds(&ctx); diff --git a/src/handshake.c b/src/handshake.c index 2986b90..aecce23 100644 --- a/src/handshake.c +++ b/src/handshake.c @@ -26,7 +26,7 @@ #include "handshake.h" #include "peer.h" -#include +#include static const char *const RECORD_TYPES[RECORD_MAX] = { diff --git a/src/methods/aes128_gcm/CMakeLists.txt b/src/methods/aes128_gcm/CMakeLists.txt index 1c5aa3f..6d07318 100644 --- a/src/methods/aes128_gcm/CMakeLists.txt +++ b/src/methods/aes128_gcm/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(BEFORE ${FASTD_SOURCE_DIR}/src ${FASTD_BINARY_DIR} ${NACL_INCLUDE_DIR}) +include_directories(${FASTD_SOURCE_DIR}/src ${FASTD_BINARY_DIR} ${NACL_INCLUDE_DIRS}) add_library(method_aes128_gcm OBJECT aes128_gcm.c diff --git a/src/methods/aes128_gcm/aes128_gcm.c b/src/methods/aes128_gcm/aes128_gcm.c index 610df7c..0b0ad56 100644 --- a/src/methods/aes128_gcm/aes128_gcm.c +++ b/src/methods/aes128_gcm/aes128_gcm.c @@ -24,8 +24,8 @@ */ -#include -#include +#include "../../fastd.h" +#include "../../crypto.h" #include "../common.h" diff --git a/src/methods/common.h b/src/methods/common.h index 0337265..0a26a32 100644 --- a/src/methods/common.h +++ b/src/methods/common.h @@ -27,7 +27,7 @@ #ifndef _FASTD_METHODS_COMMON_H_ #define _FASTD_METHODS_COMMON_H_ -#include +#include "../fastd.h" #define COMMON_NONCEBYTES 7 diff --git a/src/methods/null/CMakeLists.txt b/src/methods/null/CMakeLists.txt index 91c1832..90ead47 100644 --- a/src/methods/null/CMakeLists.txt +++ b/src/methods/null/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(BEFORE ${FASTD_SOURCE_DIR}/src ${FASTD_BINARY_DIR}) +include_directories(${FASTD_SOURCE_DIR}/src ${FASTD_BINARY_DIR}) add_library(method_null OBJECT null.c diff --git a/src/methods/null/null.c b/src/methods/null/null.c index 643e5e1..720cb79 100644 --- a/src/methods/null/null.c +++ b/src/methods/null/null.c @@ -24,7 +24,7 @@ */ -#include +#include "../../fastd.h" struct fastd_method_session_state { diff --git a/src/methods/xsalsa20_poly1305/CMakeLists.txt b/src/methods/xsalsa20_poly1305/CMakeLists.txt index 09b029c..170a1ed 100644 --- a/src/methods/xsalsa20_poly1305/CMakeLists.txt +++ b/src/methods/xsalsa20_poly1305/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(BEFORE ${FASTD_SOURCE_DIR}/src ${FASTD_BINARY_DIR} ${NACL_INCLUDE_DIR}) +include_directories(${FASTD_SOURCE_DIR}/src ${FASTD_BINARY_DIR} ${NACL_INCLUDE_DIRS}) add_library(method_xsalsa20_poly1305 OBJECT xsalsa20_poly1305.c diff --git a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c index 0a9f2c8..825a4b8 100644 --- a/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c +++ b/src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c @@ -24,7 +24,7 @@ */ -#include +#include "../../fastd.h" #include "../common.h" #include diff --git a/src/options.c b/src/options.c index 8d93bf9..333061a 100644 --- a/src/options.c +++ b/src/options.c @@ -26,7 +26,7 @@ #include "fastd.h" #include "peer.h" -#include +#include #include diff --git a/src/protocols/ec25519_fhmqvc/CMakeLists.txt b/src/protocols/ec25519_fhmqvc/CMakeLists.txt index ff1e246..91d6eaa 100644 --- a/src/protocols/ec25519_fhmqvc/CMakeLists.txt +++ b/src/protocols/ec25519_fhmqvc/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(BEFORE ${FASTD_SOURCE_DIR}/src ${FASTD_BINARY_DIR} ${UECC_INCLUDE_DIRS}) +include_directories(${FASTD_SOURCE_DIR}/src ${FASTD_BINARY_DIR} ${UECC_INCLUDE_DIRS}) add_library(protocol_ec25519_fhmqvc OBJECT ec25519_fhmqvc.c diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c index 9fe1414..d894512 100644 --- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c +++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c @@ -24,10 +24,10 @@ */ -#include -#include -#include -#include +#include "../../fastd.h" +#include "../../handshake.h" +#include "../../peer.h" +#include "../../sha256.h" #include diff --git a/src/types.h b/src/types.h index 8e70326..a2b7d38 100644 --- a/src/types.h +++ b/src/types.h @@ -33,7 +33,7 @@ #ifndef _FASTD_TYPES_H_ #define _FASTD_TYPES_H_ -#include +#include #include -- cgit v1.2.3