aboutsummaryrefslogtreecommitdiff
path: root/libcmix-crypto/curve25519
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-08-31 14:09:51 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-09-01 13:08:52 +0200
commit9d7701c370f06be663f2a485507d388ab5194ca8 (patch)
treeaea0b55017b7a6003dbd042cdb113ec6fb5ab2e9 /libcmix-crypto/curve25519
parentd55e5c77d3cd2a1be150666e92e5b4f3b922f0fc (diff)
downloadcmix-9d7701c370f06be663f2a485507d388ab5194ca8.tar.gz
cmix-9d7701c370f06be663f2a485507d388ab5194ca8.tar.bz2
cmix-9d7701c370f06be663f2a485507d388ab5194ca8.zip
Added a CMake system to easily add and choose crypto implementations.
Diffstat (limited to 'libcmix-crypto/curve25519')
-rw-r--r--libcmix-crypto/curve25519/CMakeLists.txt22
-rw-r--r--libcmix-crypto/curve25519/curve25519.h15
-rw-r--r--libcmix-crypto/curve25519/sodium/CMakeLists.txt15
-rw-r--r--libcmix-crypto/curve25519/sodium/libsodium_curve25519.c13
4 files changed, 65 insertions, 0 deletions
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 <stdlib.h>
+
+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 <stddef.h>
+
+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};
+}