diff options
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | CMakeModules/curve25519_implementations.cmake | 3 | ||||
| -rw-r--r-- | CMakeModules/get_target_name.cmake | 10 | ||||
| -rw-r--r-- | CMakeModules/implementations.cmake | 23 | ||||
| -rw-r--r-- | CMakeModules/rsa_implementations.cmake | 3 | ||||
| -rw-r--r-- | libcmix-crypto/CMakeLists.txt | 23 | ||||
| -rw-r--r-- | libcmix-crypto/curve25519/CMakeLists.txt | 22 | ||||
| -rw-r--r-- | libcmix-crypto/curve25519/curve25519.h (renamed from libcmix-crypto/curve25519.h) | 0 | ||||
| -rw-r--r-- | libcmix-crypto/curve25519/sodium/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | libcmix-crypto/curve25519/sodium/libsodium_curve25519.c (renamed from libcmix-crypto/libsodium_curve25519.c) | 0 | ||||
| -rw-r--r-- | libcmix-crypto/keymanagement.h | 15 | ||||
| -rw-r--r-- | libcmix-crypto/rsa/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | libcmix-crypto/rsa/sodium/CMakeLists.txt | 0 |
13 files changed, 103 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ea049cf..48bd387 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.6.1) project(cmix) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules) + find_package(Doxygen) if(DOXYGEN_FOUND) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) diff --git a/CMakeModules/curve25519_implementations.cmake b/CMakeModules/curve25519_implementations.cmake new file mode 100644 index 0000000..6be8dca --- /dev/null +++ b/CMakeModules/curve25519_implementations.cmake @@ -0,0 +1,3 @@ +include(implementations) + +DefineImplementations("curve25519") diff --git a/CMakeModules/get_target_name.cmake b/CMakeModules/get_target_name.cmake new file mode 100644 index 0000000..6e7c6fd --- /dev/null +++ b/CMakeModules/get_target_name.cmake @@ -0,0 +1,10 @@ + +function(get_target_name target_name) + +get_filename_component(implementation ${CMAKE_CURRENT_LIST_DIR} NAME) +get_filename_component(implementation_path ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) +get_filename_component(algorithm ${implementation_path} NAME) + +set(${target_name} "${algorithm}-${implementation}" PARENT_SCOPE) + +endfunction(get_target_name) diff --git a/CMakeModules/implementations.cmake b/CMakeModules/implementations.cmake new file mode 100644 index 0000000..aa6a8bf --- /dev/null +++ b/CMakeModules/implementations.cmake @@ -0,0 +1,23 @@ +function(DefineImplementations prefix) + + FILE(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${prefix}/*) + + set(implementations "") + foreach(child ${children}) + IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${prefix}/${child}) + LIST(APPEND implementations ${child}) + ENDIF() + ENDFOREACH() + + list(LENGTH implementations nr_implementations) + + if(nr_implementations EQUAL 0) + message(FATAL_ERROR "Cannot call DefineImplementations with an empty implementations list.") + endif() + + list(GET implementations 0 default) + set(${prefix}_implementations ${implementations} PARENT_SCOPE) + set(${prefix}_implementation "${default}" CACHE STRING "${prefix} implementation chosen at configure time") + set_property(CACHE ${prefix}_implementation PROPERTY STRINGS ${implementations}) + +endfunction(DefineImplementations) diff --git a/CMakeModules/rsa_implementations.cmake b/CMakeModules/rsa_implementations.cmake new file mode 100644 index 0000000..171058f --- /dev/null +++ b/CMakeModules/rsa_implementations.cmake @@ -0,0 +1,3 @@ +include(implementations) + +DefineImplementations("rsa") 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/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.h b/libcmix-crypto/curve25519/curve25519.h index 319e693..319e693 100644 --- a/libcmix-crypto/curve25519.h +++ b/libcmix-crypto/curve25519/curve25519.h 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/libsodium_curve25519.c b/libcmix-crypto/curve25519/sodium/libsodium_curve25519.c index 23dbf12..23dbf12 100644 --- a/libcmix-crypto/libsodium_curve25519.c +++ b/libcmix-crypto/curve25519/sodium/libsodium_curve25519.c 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 <stddef.h> - #ifdef __cplusplus extern "C" { #endif +#include "keypair.h" + +#include <stddef.h> + 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/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 --- /dev/null +++ b/libcmix-crypto/rsa/sodium/CMakeLists.txt |
