From f7f0e8c53bc8231264346ef91e2f533164a25562 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Thu, 29 Sep 2016 14:41:32 +0200 Subject: Replaced the RSA implementation with an Elgamal implementation. --- CMakeModules/elgamal_implementations.cmake | 3 +++ CMakeModules/rsa_implementations.cmake | 3 --- libcmix-crypto/CMakeLists.txt | 6 +++--- libcmix-crypto/elgamal/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ libcmix-crypto/elgamal/elgamal.c | 11 +++++++++++ libcmix-crypto/elgamal/elgamal.h | 19 +++++++++++++++++++ libcmix-crypto/elgamal/null/CMakeLists.txt | 16 ++++++++++++++++ libcmix-crypto/elgamal/null/null_elgamal.c | 0 libcmix-crypto/rsa/CMakeLists.txt | 29 ----------------------------- libcmix-crypto/rsa/null/CMakeLists.txt | 16 ---------------- libcmix-crypto/rsa/null/null_rsa.c | 0 libcmix-crypto/rsa/rsa.c | 11 ----------- libcmix-crypto/rsa/rsa.h | 19 ------------------- 13 files changed, 81 insertions(+), 81 deletions(-) create mode 100644 CMakeModules/elgamal_implementations.cmake delete mode 100644 CMakeModules/rsa_implementations.cmake create mode 100644 libcmix-crypto/elgamal/CMakeLists.txt create mode 100644 libcmix-crypto/elgamal/elgamal.c create mode 100644 libcmix-crypto/elgamal/elgamal.h create mode 100644 libcmix-crypto/elgamal/null/CMakeLists.txt create mode 100644 libcmix-crypto/elgamal/null/null_elgamal.c delete mode 100644 libcmix-crypto/rsa/CMakeLists.txt delete mode 100644 libcmix-crypto/rsa/null/CMakeLists.txt delete mode 100644 libcmix-crypto/rsa/null/null_rsa.c delete mode 100644 libcmix-crypto/rsa/rsa.c delete mode 100644 libcmix-crypto/rsa/rsa.h diff --git a/CMakeModules/elgamal_implementations.cmake b/CMakeModules/elgamal_implementations.cmake new file mode 100644 index 0000000..d9fbe2c --- /dev/null +++ b/CMakeModules/elgamal_implementations.cmake @@ -0,0 +1,3 @@ +include(implementations) + +DefineImplementations("elgamal") diff --git a/CMakeModules/rsa_implementations.cmake b/CMakeModules/rsa_implementations.cmake deleted file mode 100644 index 171058f..0000000 --- a/CMakeModules/rsa_implementations.cmake +++ /dev/null @@ -1,3 +0,0 @@ -include(implementations) - -DefineImplementations("rsa") diff --git a/libcmix-crypto/CMakeLists.txt b/libcmix-crypto/CMakeLists.txt index e73ed38..dea1196 100644 --- a/libcmix-crypto/CMakeLists.txt +++ b/libcmix-crypto/CMakeLists.txt @@ -19,8 +19,8 @@ target_sources(cmix-crypto-interface include(curve25519_implementations) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/curve25519/) -include(rsa_implementations) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/rsa) +include(elgamal_implementations) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/elgamal) add_library(cmix-crypto INTERFACE) @@ -36,5 +36,5 @@ option(UseEC "Use curve25519 instead of RSA" ON) target_link_libraries(cmix-crypto INTERFACE curve25519-implementation - INTERFACE rsa-implementation + INTERFACE elgamal-implementation ) diff --git a/libcmix-crypto/elgamal/CMakeLists.txt b/libcmix-crypto/elgamal/CMakeLists.txt new file mode 100644 index 0000000..88f5ba8 --- /dev/null +++ b/libcmix-crypto/elgamal/CMakeLists.txt @@ -0,0 +1,29 @@ +add_library(elgamal-interface INTERFACE) + +target_include_directories(elgamal-interface + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources(elgamal-interface + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/elgamal.h +) + +target_link_libraries(elgamal-interface + INTERFACE cmix-crypto-interface +) + +foreach(impl ${elgamal_implementations}) + add_subdirectory(${impl}) +endforeach() + +add_library(elgamal-implementation + elgamal.h elgamal.c +) + +target_include_directories(elgamal-implementation + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries(elgamal-implementation + PUBLIC elgamal-${elgamal_implementation} +) diff --git a/libcmix-crypto/elgamal/elgamal.c b/libcmix-crypto/elgamal/elgamal.c new file mode 100644 index 0000000..3136688 --- /dev/null +++ b/libcmix-crypto/elgamal/elgamal.c @@ -0,0 +1,11 @@ +#include "elgamal.h" + +struct Api get_elgamal_implementation() +{ + return (struct Api) { + &elgamal_create_keypair, + &elgamal_keypair_deleter, + &elgamal_derive_shared_key, + &elgamal_shared_key_deleter + }; +} diff --git a/libcmix-crypto/elgamal/elgamal.h b/libcmix-crypto/elgamal/elgamal.h new file mode 100644 index 0000000..77b5c9b --- /dev/null +++ b/libcmix-crypto/elgamal/elgamal.h @@ -0,0 +1,19 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "api.h" + +extern struct KeyPair elgamal_create_keypair(); +extern void elgamal_keypair_deleter(struct KeyPair p); + +extern struct SharedKey elgamal_derive_shared_key(struct KeyPair pair, unsigned char* pub_key, bool swap_pub_order); +extern void elgamal_shared_key_deleter(struct SharedKey s); + +struct Api get_elgamal_implementation(); + +#ifdef __cplusplus +} +#endif diff --git a/libcmix-crypto/elgamal/null/CMakeLists.txt b/libcmix-crypto/elgamal/null/CMakeLists.txt new file mode 100644 index 0000000..39db0f0 --- /dev/null +++ b/libcmix-crypto/elgamal/null/CMakeLists.txt @@ -0,0 +1,16 @@ +include(get_target_name) + +get_target_name(target_name) + +add_library(${target_name} SHARED + null_elgamal.c +) + +target_compile_options(${target_name} + PRIVATE -std=c99 +) + +target_link_libraries(${target_name} + INTERFACE cmix-crypto + PRIVATE elgamal-interface +) diff --git a/libcmix-crypto/elgamal/null/null_elgamal.c b/libcmix-crypto/elgamal/null/null_elgamal.c new file mode 100644 index 0000000..e69de29 diff --git a/libcmix-crypto/rsa/CMakeLists.txt b/libcmix-crypto/rsa/CMakeLists.txt deleted file mode 100644 index 2eb847f..0000000 --- a/libcmix-crypto/rsa/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -add_library(rsa-interface INTERFACE) - -target_include_directories(rsa-interface - INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_sources(rsa-interface - INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/rsa.h -) - -target_link_libraries(rsa-interface - INTERFACE cmix-crypto-interface -) - -foreach(impl ${rsa_implementations}) - add_subdirectory(${impl}) -endforeach() - -add_library(rsa-implementation - rsa.h rsa.c -) - -target_include_directories(rsa-implementation - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_link_libraries(rsa-implementation - PUBLIC rsa-${rsa_implementation} -) diff --git a/libcmix-crypto/rsa/null/CMakeLists.txt b/libcmix-crypto/rsa/null/CMakeLists.txt deleted file mode 100644 index 50977fb..0000000 --- a/libcmix-crypto/rsa/null/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -include(get_target_name) - -get_target_name(target_name) - -add_library(${target_name} SHARED - null_rsa.c -) - -target_compile_options(${target_name} - PRIVATE -std=c99 -) - -target_link_libraries(${target_name} - INTERFACE cmix-crypto - PRIVATE rsa-interface -) diff --git a/libcmix-crypto/rsa/null/null_rsa.c b/libcmix-crypto/rsa/null/null_rsa.c deleted file mode 100644 index e69de29..0000000 diff --git a/libcmix-crypto/rsa/rsa.c b/libcmix-crypto/rsa/rsa.c deleted file mode 100644 index 61ade32..0000000 --- a/libcmix-crypto/rsa/rsa.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "rsa.h" - -struct Api get_rsa_implementation() -{ - return (struct Api) { - &rsa_create_keypair, - &rsa_keypair_deleter, - &rsa_derive_shared_key, - &rsa_shared_key_deleter - }; -} diff --git a/libcmix-crypto/rsa/rsa.h b/libcmix-crypto/rsa/rsa.h deleted file mode 100644 index f479a95..0000000 --- a/libcmix-crypto/rsa/rsa.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include "api.h" - -extern struct KeyPair rsa_create_keypair(); -extern void rsa_keypair_deleter(struct KeyPair p); - -extern struct SharedKey rsa_derive_shared_key(struct KeyPair pair, unsigned char* pub_key, bool swap_pub_order); -extern void rsa_shared_key_deleter(struct SharedKey s); - -struct Api get_rsa_implementation(); - -#ifdef __cplusplus -} -#endif -- cgit v1.2.3-70-g09d2