From 9d7701c370f06be663f2a485507d388ab5194ca8 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Wed, 31 Aug 2016 14:09:51 +0200 Subject: Added a CMake system to easily add and choose crypto implementations. --- libcmix-crypto/CMakeLists.txt | 23 ++++++++++++++++------ libcmix-crypto/curve25519.h | 15 -------------- libcmix-crypto/curve25519/CMakeLists.txt | 22 +++++++++++++++++++++ libcmix-crypto/curve25519/curve25519.h | 15 ++++++++++++++ libcmix-crypto/curve25519/sodium/CMakeLists.txt | 15 ++++++++++++++ .../curve25519/sodium/libsodium_curve25519.c | 13 ++++++++++++ libcmix-crypto/keymanagement.h | 15 ++++---------- libcmix-crypto/libsodium_curve25519.c | 13 ------------ libcmix-crypto/rsa/CMakeLists.txt | 4 ++++ libcmix-crypto/rsa/sodium/CMakeLists.txt | 0 10 files changed, 90 insertions(+), 45 deletions(-) delete mode 100644 libcmix-crypto/curve25519.h create mode 100644 libcmix-crypto/curve25519/CMakeLists.txt create mode 100644 libcmix-crypto/curve25519/curve25519.h create mode 100644 libcmix-crypto/curve25519/sodium/CMakeLists.txt create mode 100644 libcmix-crypto/curve25519/sodium/libsodium_curve25519.c delete mode 100644 libcmix-crypto/libsodium_curve25519.c create mode 100644 libcmix-crypto/rsa/CMakeLists.txt create mode 100644 libcmix-crypto/rsa/sodium/CMakeLists.txt (limited to 'libcmix-crypto') diff --git a/libcmix-crypto/CMakeLists.txt b/libcmix-crypto/CMakeLists.txt index 37e60aa..907c601 100644 --- a/libcmix-crypto/CMakeLists.txt +++ b/libcmix-crypto/CMakeLists.txt @@ -1,10 +1,21 @@ +add_library(cmix-crypto-interface INTERFACE) + +target_include_directories(cmix-crypto-interface + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} +) + +include(curve25519_implementations) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/curve25519/) + +include(rsa_implementations) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/rsa) + + add_library(cmix-crypto message.h message.c keymanagement.h keymanagement.c keypair.h - curve25519.h - ) target_include_directories(cmix-crypto @@ -15,10 +26,10 @@ target_compile_options(cmix-crypto PRIVATE "-std=c99" ) -add_library(libsodium_curve25519 - libsodium_curve25519.c -) +option(UseEC "Use curve25519 instead of RSA" ON) + target_link_libraries(cmix-crypto - PUBLIC libsodium_curve25519 + PUBLIC curve25519-implementation +# PUBLIC rsa-implementation ) diff --git a/libcmix-crypto/curve25519.h b/libcmix-crypto/curve25519.h deleted file mode 100644 index 319e693..0000000 --- a/libcmix-crypto/curve25519.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keypair.h" - -#include - -extern struct KeyPair curve25519_create_keypair(); - -#ifdef __cplusplus -} -#endif diff --git a/libcmix-crypto/curve25519/CMakeLists.txt b/libcmix-crypto/curve25519/CMakeLists.txt new file mode 100644 index 0000000..7885e7d --- /dev/null +++ b/libcmix-crypto/curve25519/CMakeLists.txt @@ -0,0 +1,22 @@ + +add_library(curve25519-interface INTERFACE) + +target_include_directories(curve25519-interface + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries(curve25519-interface + INTERFACE cmix-crypto-interface +) + +foreach(impl ${curve25519_implementations}) + add_subdirectory(${impl}) +endforeach() + +add_library(curve25519-implementation INTERFACE) + +target_link_libraries(curve25519-implementation + INTERFACE curve25519-${curve25519_implementation} +) + + diff --git a/libcmix-crypto/curve25519/curve25519.h b/libcmix-crypto/curve25519/curve25519.h new file mode 100644 index 0000000..319e693 --- /dev/null +++ b/libcmix-crypto/curve25519/curve25519.h @@ -0,0 +1,15 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "keypair.h" + +#include + +extern struct KeyPair curve25519_create_keypair(); + +#ifdef __cplusplus +} +#endif diff --git a/libcmix-crypto/curve25519/sodium/CMakeLists.txt b/libcmix-crypto/curve25519/sodium/CMakeLists.txt new file mode 100644 index 0000000..9fbf010 --- /dev/null +++ b/libcmix-crypto/curve25519/sodium/CMakeLists.txt @@ -0,0 +1,15 @@ +include(get_target_name) + +get_target_name(target_name) + +add_library(${target_name} + libsodium_curve25519.c +) + +target_compile_options(${target_name} + PRIVATE -std=c99 +) + +target_link_libraries(${target_name} + PUBLIC curve25519-interface +) diff --git a/libcmix-crypto/curve25519/sodium/libsodium_curve25519.c b/libcmix-crypto/curve25519/sodium/libsodium_curve25519.c new file mode 100644 index 0000000..23dbf12 --- /dev/null +++ b/libcmix-crypto/curve25519/sodium/libsodium_curve25519.c @@ -0,0 +1,13 @@ + +#include "curve25519.h" + +#include + +void sodium_curve25519_keypair_deleter(struct KeyPair* p) { + free(p->sec); + free(p->pub); +} + +struct KeyPair curve25519_create_keypair() { + return (struct KeyPair){NULL, NULL, 0, 0, &sodium_curve25519_keypair_deleter}; +} diff --git a/libcmix-crypto/keymanagement.h b/libcmix-crypto/keymanagement.h index 1db0ce6..18b578a 100644 --- a/libcmix-crypto/keymanagement.h +++ b/libcmix-crypto/keymanagement.h @@ -1,13 +1,13 @@ #pragma once -#include "curve25519.h" - -#include - #ifdef __cplusplus extern "C" { #endif +#include "keypair.h" + +#include + typedef struct KeyPair(*CmixKeyPairCreator)(); typedef struct KeyPair(*CmixKeyPairLoader)(char*, char*); @@ -16,13 +16,6 @@ struct CmixKeyManagementImpl { CmixKeyPairLoader load_keypair; }; -struct CmixKeyManagementImpl get_curve25519_key_management_implementation() { - return (struct CmixKeyManagementImpl) {\ - &curve25519_create_keypair, - NULL - };\ -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/libcmix-crypto/libsodium_curve25519.c b/libcmix-crypto/libsodium_curve25519.c deleted file mode 100644 index 23dbf12..0000000 --- a/libcmix-crypto/libsodium_curve25519.c +++ /dev/null @@ -1,13 +0,0 @@ - -#include "curve25519.h" - -#include - -void sodium_curve25519_keypair_deleter(struct KeyPair* p) { - free(p->sec); - free(p->pub); -} - -struct KeyPair curve25519_create_keypair() { - return (struct KeyPair){NULL, NULL, 0, 0, &sodium_curve25519_keypair_deleter}; -} diff --git a/libcmix-crypto/rsa/CMakeLists.txt b/libcmix-crypto/rsa/CMakeLists.txt new file mode 100644 index 0000000..82e56a9 --- /dev/null +++ b/libcmix-crypto/rsa/CMakeLists.txt @@ -0,0 +1,4 @@ +foreach(impl ${rsa_implementations}) + add_subdirectory(${impl}) +endforeach() + diff --git a/libcmix-crypto/rsa/sodium/CMakeLists.txt b/libcmix-crypto/rsa/sodium/CMakeLists.txt new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3-70-g09d2