#pragma once /** * \file */ #ifdef __cplusplus extern "C" { #endif #include #include /*! * Defines how a cMix Buffer allocater should look like. */ typedef char*(*CmixBufferAllocator)(size_t); /*! * Defines how a cMix Buffer deallocater should look like. */ typedef void(*CmixBufferDeallocator)(void*); /*! * Defines how the function looks like that returns the length of one message in this buffer implementation. */ typedef size_t(*CmixBufferMessageLength)(); /*! * \brief The CmixBufferImpl struct */ struct CmixBufferImpl { CmixBufferAllocator allocate_cmix_buffer; ///< pointer to function to implementation specific allocater. CmixBufferDeallocator deallocate_cmix_buffer; ///< pointer to function to implementation specific deallocater. CmixBufferMessageLength message_length; ///< pointer to function to implementation specific function returning message length. }; /*! * \def DEFINE_CIPHER(NAME, MESSAGE_SIZE) * Generates some cipher specific boilerplate for manipulating the message buffer. */ #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(Null, 0) /*! * #DEFINE_CIPHER(Curve25519, 31) */ DEFINE_CIPHER(Curve25519, 31) #undef DEFINE_CIPHER #ifdef __cplusplus } // extern "C" #endif