From d55e5c77d3cd2a1be150666e92e5b4f3b922f0fc Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Wed, 31 Aug 2016 12:48:49 +0200 Subject: Restructered libcmix-crypto, hiding implementation specifics. --- libcmix-crypto/CMakeLists.txt | 3 +++ libcmix-crypto/curve25519.h | 7 +++---- libcmix-crypto/keypair.h | 30 ++++++++++++++++++++++++++++++ libcmix-crypto/libsodium_curve25519.c | 7 ++++++- 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 libcmix-crypto/keypair.h (limited to 'libcmix-crypto') diff --git a/libcmix-crypto/CMakeLists.txt b/libcmix-crypto/CMakeLists.txt index 1be60dc..37e60aa 100644 --- a/libcmix-crypto/CMakeLists.txt +++ b/libcmix-crypto/CMakeLists.txt @@ -2,6 +2,9 @@ add_library(cmix-crypto message.h message.c keymanagement.h keymanagement.c + keypair.h + curve25519.h + ) target_include_directories(cmix-crypto diff --git a/libcmix-crypto/curve25519.h b/libcmix-crypto/curve25519.h index 2c8b1e3..319e693 100644 --- a/libcmix-crypto/curve25519.h +++ b/libcmix-crypto/curve25519.h @@ -4,10 +4,9 @@ extern "C" { #endif -struct KeyPair { - char* sec; - char* pub; -}; +#include "keypair.h" + +#include extern struct KeyPair curve25519_create_keypair(); diff --git a/libcmix-crypto/keypair.h b/libcmix-crypto/keypair.h new file mode 100644 index 0000000..90cf16b --- /dev/null +++ b/libcmix-crypto/keypair.h @@ -0,0 +1,30 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct KeyPair; + +typedef void(*KeyPairDeleter)(struct KeyPair*); + +void keypair_deleter(struct KeyPair* p) ; + +struct KeyPair { + char* sec; + char* pub; + unsigned int sec_len; + unsigned int pub_len; + KeyPairDeleter deleter; +}; + +void keypair_deleter(struct KeyPair* p) { + free(p->sec); + free(p->pub); +} + +#ifdef __cplusplus +} +#endif diff --git a/libcmix-crypto/libsodium_curve25519.c b/libcmix-crypto/libsodium_curve25519.c index d010d2f..23dbf12 100644 --- a/libcmix-crypto/libsodium_curve25519.c +++ b/libcmix-crypto/libsodium_curve25519.c @@ -3,6 +3,11 @@ #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}; + return (struct KeyPair){NULL, NULL, 0, 0, &sodium_curve25519_keypair_deleter}; } -- cgit v1.2.3-70-g09d2