diff options
| -rw-r--r-- | libcmix-crypto/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | libcmix-crypto/curve25519.h | 7 | ||||
| -rw-r--r-- | libcmix-crypto/keypair.h | 30 | ||||
| -rw-r--r-- | libcmix-crypto/libsodium_curve25519.c | 7 |
4 files changed, 42 insertions, 5 deletions
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 <stdlib.h> 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 <stdlib.h> + +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 <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}; + return (struct KeyPair){NULL, NULL, 0, 0, &sodium_curve25519_keypair_deleter}; } |
