diff options
Diffstat (limited to 'libcmix-crypto')
| -rw-r--r-- | libcmix-crypto/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | libcmix-crypto/message.c | 0 | ||||
| -rw-r--r-- | libcmix-crypto/message.h | 85 |
3 files changed, 97 insertions, 0 deletions
diff --git a/libcmix-crypto/CMakeLists.txt b/libcmix-crypto/CMakeLists.txt new file mode 100644 index 0000000..3bbbae6 --- /dev/null +++ b/libcmix-crypto/CMakeLists.txt @@ -0,0 +1,12 @@ + +add_library(cmix-crypto + message.h message.c +) + +target_include_directories(cmix-crypto + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_compile_options(cmix-crypto + PUBLIC "-std=c99" +)
\ No newline at end of file diff --git a/libcmix-crypto/message.c b/libcmix-crypto/message.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/libcmix-crypto/message.c diff --git a/libcmix-crypto/message.h b/libcmix-crypto/message.h new file mode 100644 index 0000000..98cdb9a --- /dev/null +++ b/libcmix-crypto/message.h @@ -0,0 +1,85 @@ + +#include <stddef.h> +#include <stdlib.h> + +typedef char*(*CmixBufferAllocator)(size_t); +typedef void(*CmixBufferDeallocator)(void*); +typedef size_t(*CmixBufferMessageLength)(); + +struct CmixBufferImpl { + CmixBufferAllocator allocate_cmix_buffer; + CmixBufferDeallocator deallocate_cmix_buffer; + CmixBufferMessageLength message_length; +}; + +#define DEFINE_CIPHER(NAME, MESSAGE_SIZE)\ +typedef char NAME ## Message[MESSAGE_SIZE];\ +\ +char* allocate_ ## NAME ## _cmix_buffer(size_t size){\ + return (char*) calloc(size, sizeof(NAME ## Message));\ +}\ +\ +void deallocate_ ## NAME ## _cmix_buffer(void* buffer) {\ + free(buffer);\ +}\ +\ +size_t NAME ## _message_length() {\ + return sizeof(NAME ## Message);\ +}\ +\ +struct CmixBufferImpl get_cmix_ ## NAME ## _buffer_implementation() {\ + return (struct CmixBufferImpl) {\ + allocate_ ## NAME ## _cmix_buffer,\ + deallocate_ ## NAME ## _cmix_buffer,\ + NAME ## _message_length\ + };\ +} + +DEFINE_CIPHER(Null, 0) +DEFINE_CIPHER(Curve25519, 20); + +/* +typedef char NullMessage[0]; + +char* allocate_null_cmix_buffer(size_t size) { + return (char*) calloc(size, sizeof(NullMessage)); +} + +void deallocate_null_cmix_buffer(void* buffer) { + free(buffer); +} + +size_t null_message_length() { + return sizeof(NullMessage); +} + +struct CmixBufferImpl get_cmix_null_buffer_implementation() { + return (struct CmixBufferImpl) { + allocate_null_cmix_buffer, + deallocate_null_cmix_buffer, + null_message_length + }; +} + +typedef char Curve25519Message[20]; + +char* allocate_curve25519_cmix_buffer(size_t size) { + return (char*) calloc(size, sizeof(Curve25519Message)); +} + +void deallocate_curve25519_cmix_buffer(void* buffer) { + free(buffer); +} + +size_t curve25519_message_length() { + return sizeof(Curve25519Message); +} + +struct CmixBufferImpl get_cmix_curve25519_buffer_implementation() { + return (struct CmixBufferImpl) { + allocate_curve25519_cmix_buffer, + deallocate_curve25519_cmix_buffer, + curve25519_message_length + }; +} +*/ |
