summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-10-29 03:45:34 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-10-29 03:45:34 +0100
commitbb324029ad442a1f6dd7049a6e6fc1cbe4a05799 (patch)
treee3f3e7c33a8077ba5bc721009dd71ea8644f1c1d
parentfc8c8d82f05911836208cc9169e103d5578ffd70 (diff)
downloadfastd-bb324029ad442a1f6dd7049a6e6fc1cbe4a05799.tar
fastd-bb324029ad442a1f6dd7049a6e6fc1cbe4a05799.zip
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.
-rw-r--r--CMakeLists.txt42
-rw-r--r--fastd_config.h.in (renamed from config.h.in)2
-rw-r--r--src/CMakeLists.txt10
-rw-r--r--src/compat.h2
-rw-r--r--src/fastd.c10
-rw-r--r--src/handshake.c2
-rw-r--r--src/methods/aes128_gcm/CMakeLists.txt2
-rw-r--r--src/methods/aes128_gcm/aes128_gcm.c4
-rw-r--r--src/methods/common.h2
-rw-r--r--src/methods/null/CMakeLists.txt2
-rw-r--r--src/methods/null/null.c2
-rw-r--r--src/methods/xsalsa20_poly1305/CMakeLists.txt2
-rw-r--r--src/methods/xsalsa20_poly1305/xsalsa20_poly1305.c2
-rw-r--r--src/options.c2
-rw-r--r--src/protocols/ec25519_fhmqvc/CMakeLists.txt2
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c8
-rw-r--r--src/types.h2
17 files changed, 65 insertions, 33 deletions
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/fastd_config.h.in
index 5be4660..4868985 100644
--- a/config.h.in
+++ b/fastd_config.h.in
@@ -45,6 +45,8 @@
#cmakedefine WITH_CMDLINE_COMMANDS
+#cmakedefine USE_LIBSODIUM
+
#cmakedefine USE_CRYPTO_AES128CTR
#cmakedefine USE_CRYPTO_GHASH
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 <config.h>
+#include <fastd_config.h>
#include <stdint.h>
#include <unistd.h>
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 <version.h>
+#include <fastd_version.h>
#include <fcntl.h>
#include <grp.h>
@@ -39,6 +39,10 @@
#include <syslog.h>
#include <sys/resource.h>
+#ifdef USE_LIBSODIUM
+#include <sodium/core.h>
+#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 <version.h>
+#include <fastd_version.h>
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 <fastd.h>
-#include <crypto.h>
+#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 <fastd.h>
+#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 <fastd.h>
+#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 <fastd.h>
+#include "../../fastd.h"
#include "../common.h"
#include <crypto_secretbox_xsalsa20poly1305.h>
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 <version.h>
+#include <fastd_version.h>
#include <arpa/inet.h>
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 <fastd.h>
-#include <handshake.h>
-#include <peer.h>
-#include <sha256.h>
+#include "../../fastd.h"
+#include "../../handshake.h"
+#include "../../peer.h"
+#include "../../sha256.h"
#include <libuecc/ecc.h>
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 <config.h>
+#include <fastd_config.h>
#include <stdbool.h>