diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-28 15:48:59 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-28 15:48:59 +0100 |
| commit | a4a912873058e50060561c21e965b4fec1d9b08b (patch) | |
| tree | 564432cf3f760483a9acfa64f109f5f42be469c1 | |
| parent | b8d2fe28870d1f54aad1fd9fce04e57caa85ba0b (diff) | |
| download | cmix-a4a912873058e50060561c21e965b4fec1d9b08b.tar.gz cmix-a4a912873058e50060561c21e965b4fec1d9b08b.tar.bz2 cmix-a4a912873058e50060561c21e965b4fec1d9b08b.zip | |
Cleans up and documents the whole cmix protocol.
| -rw-r--r-- | Doxyfile.in | 1 | ||||
| -rw-r--r-- | libcmix-common/cmixprotofunctor.hpp | 3 | ||||
| -rw-r--r-- | libcmix-crypto/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | libcmix-crypto/groupelement.h | 7 | ||||
| -rw-r--r-- | libcmix-crypto/message.h | 78 | ||||
| -rw-r--r-- | libcmix-network/acceptor.hpp | 3 | ||||
| -rw-r--r-- | libcmix-network/server.hpp | 3 | ||||
| -rw-r--r-- | libcmix/cmix.c | 28 | ||||
| -rw-r--r-- | libcmix/cmix.h | 244 | ||||
| -rw-r--r-- | node/node.cpp | 15 | ||||
| -rw-r--r-- | node/node.hpp | 6 | ||||
| -rw-r--r-- | node/node_node.cpp | 19 | ||||
| -rw-r--r-- | scratchpad/scratchpad.c | 20 |
13 files changed, 267 insertions, 162 deletions
diff --git a/Doxyfile.in b/Doxyfile.in index 38915c3..dcab54d 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -12,3 +12,4 @@ FILE_PATTERNS = *.h \ RECURSIVE = YES USE_MDFILE_AS_MAINPAGE = @doxy_main_page@ ENABLE_PREPROCESSING = YES + diff --git a/libcmix-common/cmixprotofunctor.hpp b/libcmix-common/cmixprotofunctor.hpp index 57536e5..0c8a341 100644 --- a/libcmix-common/cmixprotofunctor.hpp +++ b/libcmix-common/cmixprotofunctor.hpp @@ -42,12 +42,13 @@ struct CMixProtoFunctor { * Defines one iteration of the Repeat below, * \param Z level over repeat we are using it should be 1. * \param N current iteration - * \param The sequence consisiting of "pairs" of TYPE, NAME + * \param DATA The sequence consisiting of "pairs" of TYPE, NAME */ #define MESSAGE_SETTER_DEF_ITERATION(Z, N, DATA) \ MESSAGE_SETTER_DEF(BOOST_PP_SEQ_ELEM(BOOST_PP_MUL(N, 2), DATA), BOOST_PP_SEQ_ELEM(BOOST_PP_ADD(BOOST_PP_MUL(N, 2), 1), DATA)) /*! + * \def MESSAGE_SETTER_DEFS(...) * Loops over the length of the variadic macro parameter / 2 */ #define MESSAGE_SETTER_DEFS(...) \ diff --git a/libcmix-crypto/CMakeLists.txt b/libcmix-crypto/CMakeLists.txt index 08036f4..7fa0d29 100644 --- a/libcmix-crypto/CMakeLists.txt +++ b/libcmix-crypto/CMakeLists.txt @@ -9,7 +9,7 @@ set(interface_sources ${CMAKE_CURRENT_SOURCE_DIR}/api.h ${CMAKE_CURRENT_SOURCE_DIR}/keypair.h ${CMAKE_CURRENT_SOURCE_DIR}/sharedkey.h - ${CMAKE_CURRENT_SOURCE_DIR}/message.h + ${CMAKE_CURRENT_SOURCE_DIR}/groupelement.h ) target_sources(cmix-crypto-interface diff --git a/libcmix-crypto/groupelement.h b/libcmix-crypto/groupelement.h index 60c6b21..353e525 100644 --- a/libcmix-crypto/groupelement.h +++ b/libcmix-crypto/groupelement.h @@ -4,6 +4,13 @@ extern "C" { #endif +/*! + * \file + */ + +/*! + * \brief GroupElement Token te represent group elements. + */ typedef void* GroupElement; #ifdef __cplusplus diff --git a/libcmix-crypto/message.h b/libcmix-crypto/message.h deleted file mode 100644 index b1c3b87..0000000 --- a/libcmix-crypto/message.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -/** - * \file - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stddef.h> -#include <stdlib.h> - -/*! - * 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 diff --git a/libcmix-network/acceptor.hpp b/libcmix-network/acceptor.hpp index 0ee9294..eecc511 100644 --- a/libcmix-network/acceptor.hpp +++ b/libcmix-network/acceptor.hpp @@ -74,6 +74,9 @@ public: */ void start_accepting(std::shared_ptr<boost::asio::ssl::context> ctx, SSLAcceptHandler accept_handler); + /*! + * \brief closes the acceptor socket and cancels the async_operations. + */ void close(); }; diff --git a/libcmix-network/server.hpp b/libcmix-network/server.hpp index 6976f04..29559e7 100644 --- a/libcmix-network/server.hpp +++ b/libcmix-network/server.hpp @@ -53,6 +53,9 @@ public: */ Server(boost::asio::io_service& io_service, ListenSettings const& listen_settings, std::shared_ptr<boost::asio::ssl::context> ctx, SSLAcceptHandler accept_handler); + /*! + * \brief close closes all the accepting sockets. + */ void close(); }; diff --git a/libcmix/cmix.c b/libcmix/cmix.c index 2311bea..f8a40b6 100644 --- a/libcmix/cmix.c +++ b/libcmix/cmix.c @@ -143,14 +143,14 @@ size_t get_group_element_array_size(struct CMixContext const* ctx) { return ctx->api.get_group_element_array_size(); } -enum cmix_error set_network_key(struct CMixContext* ctx, char const* buffer, size_t len) { - ctx->network_key = ctx->api.array_to_element(buffer, len, true); +enum cmix_error set_network_key(struct CMixContext* ctx, char const* buffer) { + ctx->network_key = ctx->api.array_to_element(buffer, get_group_element_array_size(ctx), true); return no_error; } -enum cmix_error encrypt_r(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, size_t nr_elements) { +enum cmix_error encrypt_r(struct CMixContext const* ctx, char** random_buffer, char** message_buffer) { - for(size_t i = 0; i < nr_elements; ++i) { + for(size_t i = 0; i < ctx->nr_participants; ++i) { GroupElement random_element; GroupElement message_element; @@ -166,9 +166,9 @@ enum cmix_error encrypt_r(struct CMixContext const* ctx, char** random_buffer, c return no_error; } -enum cmix_error encrypt_r_and_multiply(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, const char** random_element, const char** message_element, size_t nr_elements) { +enum cmix_error encrypt_r_and_multiply(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, const char** random_element, const char** message_element) { - for(size_t i = 0; i < nr_elements; ++i) { + for(size_t i = 0; i < ctx->nr_participants; ++i) { GroupElement enc_random_element; GroupElement enc_message_element; @@ -196,10 +196,10 @@ enum cmix_error encrypt_r_and_multiply(struct CMixContext const* ctx, char** ran return no_error; } -enum cmix_error permute_and_multiply_encrypted_s(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, char const** random_element, char const** message_element, size_t nr_elements) { +enum cmix_error permute_and_multiply_encrypted_s(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, char const** random_element, char const** message_element) { size_t el_size = get_group_element_array_size(ctx); - for(size_t i = 0; i < nr_elements; ++i) { + for(size_t i = 0; i < ctx->nr_participants; ++i) { unsigned int new_pos = ctx->permutation[i]; GroupElement random_r = ctx->api.array_to_element(random_element[i], el_size, true); GroupElement message_r = ctx->api.array_to_element(message_element[i], el_size, true); @@ -226,10 +226,10 @@ enum cmix_error permute_and_multiply_encrypted_s(struct CMixContext const* ctx, return no_error; } -enum cmix_error permute_and_multiply_s(struct CMixContext const* ctx, char** out_buffer, char const** message, size_t nr_elements) { +enum cmix_error permute_and_multiply_s(struct CMixContext const* ctx, char** out_buffer, char const** message) { size_t el_size = get_group_element_array_size(ctx); - for(size_t i = 0; i < nr_elements; ++i) { + for(size_t i = 0; i < ctx->nr_participants; ++i) { unsigned int new_pos = ctx->permutation[i]; GroupElement message_el = ctx->api.array_to_element(message[i], el_size, false); @@ -296,8 +296,8 @@ enum cmix_error key_exchange_initiator(struct CMixContext const* ctx, GroupEleme return no_error; } -enum cmix_error post_process(struct CMixContext* ctx, char** r_out, char** m_out, const char** r_epirs, const char** m_epirs, size_t nr_elements) { - for(size_t i = 0; i < nr_elements; ++i) { +enum cmix_error post_process(struct CMixContext* ctx, char** r_out, char** m_out, const char** r_epirs, const char** m_epirs) { + for(size_t i = 0; i < ctx->nr_participants; ++i) { GroupElement x = ctx->api.array_to_element(r_epirs[i], get_group_element_array_size(ctx), true); GroupElement D = ctx->api.get_decryption_share(x, ctx->keypair.sec); @@ -338,10 +338,10 @@ enum cmix_error blind_message(struct CMixContext const* ctx, char* m_out, char c return no_error; } -enum cmix_error swap_k_for_r(struct CMixContext const* ctx, char** out_buffer, const char** message, const GroupElement* key, size_t nr_elements) { +enum cmix_error swap_k_for_r(struct CMixContext const* ctx, char** out_buffer, const char** message, const GroupElement* key) { size_t len = get_group_element_array_size(ctx); - for(size_t i = 0; i < nr_elements; ++i) { + for(size_t i = 0; i < ctx->nr_participants; ++i) { GroupElement mes = ctx->api.array_to_element(message[i], len, false); GroupElement inv_key = ctx->api.invert(key[i]); diff --git a/libcmix/cmix.h b/libcmix/cmix.h index 0b2a42a..28088b9 100644 --- a/libcmix/cmix.h +++ b/libcmix/cmix.h @@ -12,17 +12,6 @@ extern "C" { * \file */ -/** - * \struct - * \brief The CMixBuffer struct is the temporary storage of messages in each Node. - * On this buffer, operations like decrypt and permute are performed. - */ -struct CMixBuffer { - char* buffer; ///< The actual buffer - unsigned int nr_messages; ///< The number of messages in the buffer - unsigned int message_length; ///< The length of each message in the buffer -}; - /*! * \brief The cmix_error enum describes the output state of a each of the cmix functions */ @@ -34,78 +23,269 @@ enum cmix_error { }; /*! + * \brief The CMixContext struct contains all the neccesary data to perform a cmix "mix" */ struct CMixContext { - struct Api api; - struct KeyPair keypair; - GroupElement network_key; - size_t nr_participants; - GroupElement* r; - GroupElement* s; - unsigned int* permutation; - GroupElement* pirs; + struct Api api; ///< The crypto api in use. + struct KeyPair keypair; ///< The keypair used in the crypto api. + GroupElement network_key; ///< The network key (called d in the paper). + size_t nr_participants; ///< The number of mix participants. + GroupElement* r; ///< An array of random values (R in the paper). + GroupElement* s; ///< An array of random values (S in the paper). + unsigned int* permutation; ///< a permutation (π in the paper (called Pi in source)). + GroupElement* pirs; ///< an array containing π(R) * S }; #ifndef NDEBUG +/*! + * \brief element_to_buffer under Release operation non public function that converts a element to an array. + * This function is disabled in release builds + * \param ctx The current cmix context. + * \param buffer A pointer that points to a buffer large enough to fit the element. + * \param element The element to convert to the array representation. + */ void element_to_buffer(struct CMixContext const* ctx, char* buffer, GroupElement const element); #endif +/*! + * \brief initialize_cmix_context is a CMixContext factory. it required a crypto api. + * \param api The cryptop api to initialize this CMixContext for. + * \return The created and Initialized CMixContext; + */ struct CMixContext initialize_cmix_context(struct Api api); +/*! + * \brief deinitialize deallocates all the context resources and deinitializes the crypto api. + * \param ctx The CMixContext to deinitialize. + */ void deinitialize(struct CMixContext* ctx); +/*! + * \brief initialize_keypair initializes a new keypair from random data, using the crypto api. + * \param ctx The relevant cmix context. + * \return A cmix_error + */ enum cmix_error initialize_keypair(struct CMixContext* ctx); +/*! + * \brief get_public_key Retrieves an array representation of the public key. + * \param ctx The context with the public key. + * \param buffer The buffer to store the array representation in. Should be long enough to store the result. + * \return A cmix_error + */ enum cmix_error get_public_key(struct CMixContext const* ctx, char* buffer); +/*! + * \brief add_public_share Multiplies your public key with the received public share. + * \param ctx The relevant context. + * \param buffer Buffer large enough to write the result to. + * \param share Buffer containing the current share. + * \return A cmix_error + */ enum cmix_error add_public_share(struct CMixContext const* ctx, char* buffer, char const* share); +/*! + * \brief get_pub_key_hash get a hash representation of your public key; + * \param ctx The relevant context. + * \param buffer A pointer to a char pointer that after this function will point to a buffer + * of size len containing the hash. Should be deleted with free after use + * \param len The length of the hash buffer. + * \return A cmix_error + */ enum cmix_error get_pub_key_hash(struct CMixContext const* ctx, char** buffer, size_t* len); +/*! + * \brief get_pub_key_hash_length a seperate function that returns the length of the hash returned by get_pub_key_hash + * \param ctx The relevant context. + * \return A cmix_error + */ size_t get_pub_key_hash_length(struct CMixContext const* ctx); +/*! + * \brief start_mix Releases the previous and allocates the new mix. + * \param ctx The relevant context. + * \param nr_participants The number of participants in the new mix. + * \return A cmix_error + */ enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants); +/*! + * \brief release_mix Releases all the mix resources in the current mix (not the keypair nor the api) + * \param ctx The relevant context. + */ void release_mix(struct CMixContext* ctx); +/*! + * \brief initialize_mix_randomness initializes all the randomness (R, S and Pi (permutation)) + * \param ctx The relevant context. + * \return A cmix_error + */ enum cmix_error initialize_mix_randomness(struct CMixContext* ctx); +/*! + * \brief generate_random_message Generates a random message + * \param ctx The relevant context. + * \param buffer A pointer to a buffer large enough to hold an array representation of a group element. + * \return A cmix_error + */ enum cmix_error generate_random_message(struct CMixContext* ctx, char* buffer); +/*! + * \brief get_group_element_array_size Get the minimum size required to store an array representation of a group element. + * \param ctx The relevant context. + * \return A cmix_error + */ size_t get_group_element_array_size(struct CMixContext const* ctx); -enum cmix_error set_network_key(struct CMixContext* ctx, char const* buffer, size_t len); - -enum cmix_error encrypt_r(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, size_t nr_elements); +/*! + * \brief set_network_key Sets the nework key in the context to the group element stored in buffer. + * \param ctx The relevant context. + * \param buffer The buffer containing an array representation of a group element. + * \return + */ +enum cmix_error set_network_key(struct CMixContext* ctx, char const* buffer); -enum cmix_error encrypt_r_and_multiply(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, char const** random_element, char const** message_element, size_t nr_elements); +/*! + * \brief encrypt_r Encrypts r with the network key + * \param ctx The relevant context. + * \param random_buffer An array of buffers for storing the random component of the elgamal encryption. + * \param message_buffer An array of buffers for storing the message component of the elgamal encryption. + * \return A cmix_error + */ +enum cmix_error encrypt_r(struct CMixContext const* ctx, char** random_buffer, char** message_buffer); -enum cmix_error permute_and_multiply_encrypted_s(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, char const** random_element, char const** message_element, size_t nr_elements); +/*! + * \brief encrypt_r_and_multiply Encrypts R and multiplies it with a previous result. + * \param ctx The relevant context. + * \param random_buffer The random component output buffer. + * \param message_buffer The message component output buffer. + * \param random_element The random component of a previous encryption. + * \param message_element The message componenet of a previous encryption. + * \return + */ +enum cmix_error encrypt_r_and_multiply(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, char const** random_element, char const** message_element); -enum cmix_error permute_and_multiply_s(struct CMixContext const* ctx, char** out_buffer, char const** message, size_t nr_elements); +/*! + * \brief permute_and_multiply_encrypted_s Permutes the incoming buffer and multiplies with encrypted S + * \param ctx The relevant context. + * \param random_buffer The random component output buffer. + * \param message_buffer The message component output buffer. + * \param random_element The random component of a previous encryption. + * \param message_element The message component of a previous encryption. + * \return + */ +enum cmix_error permute_and_multiply_encrypted_s(struct CMixContext const* ctx, char** random_buffer, char** message_buffer, char const** random_element, char const** message_element); -enum cmix_error get_key_exchange_value(struct CMixContext const* ctx, char* buffer, GroupElement priv_element); +/*! + * \brief permute_and_multiply_s Permutes the incoming buffer and multiplies with S + * \param ctx The relevant context. + * \param out_buffer The output buffer. + * \param message The input buffer. + * \return A cmix_error + */ +enum cmix_error permute_and_multiply_s(struct CMixContext const* ctx, char** out_buffer, char const** message); +/*! + * \brief key_exchange_init Function to call when initiating a key exchange. + * \param ctx The relevan context. + * \param pubkey_buffer Buffer large enough to hold the public key in array representation. + * \param value_buffer The exchange value to send over to the other party. + * \param secret_value The secret value used to finalize the key exchange. + * \return A cmix_error + */ enum cmix_error key_exchange_init(struct CMixContext const* ctx, char* pubkey_buffer, char* value_buffer, GroupElement* secret_value); +/*! + * \brief key_exchange_responder When receiving a key exchange request call this function. + * \param ctx The relevant context. + * \param shared_key A pointer to a GroupElement storage that will be filled by this function. + * \param public_key_buffer A buffer large enough to hold the array representation of your public key. + * \param exhange_value_buffer The exchange value to send over to the other party. + * \param pubkey The other parties public key in array representation. + * \param value The other parties exchange value. + * \return A cmix_error + */ enum cmix_error key_exchange_responder(struct CMixContext const* ctx, GroupElement* shared_key, char* public_key_buffer, char* exhange_value_buffer, char const* pubkey, char const* value); +/*! + * \brief key_exchange_initiator When you initiaed the key exchange and receive an exchagne message call this function. + * \param ctx The relevant context. + * \param shared_key A pointer to a GroupElement storage that will be filled by this function. + * \param pubkey The other parties public key. + * \param value The other parties exchange value. + * \param priv_el The private element generated by key_exchange_init. + * \return A cmix_error + */ enum cmix_error key_exchange_initiator(struct CMixContext const* ctx, GroupElement* shared_key, char const* pubkey, char const* value, GroupElement* priv_el); -enum cmix_error post_process(struct CMixContext* ctx, char** r_out, char** m_out, char const** r_epirs, char const** m_epirs, size_t nr_elements); +/*! + * \brief post_process decrypts Pi(R) * S and stores it in the context. + * \note The stored pirs only has meaning for the last node, but just storing it for the last node just adds unneeded complexity. + * \param ctx The relevant context. + * \param r_out The output buffer for the random components. + * \param m_out The output buffer for the message components. + * \param r_epirs The input buffer for the random components. + * \param m_epirs The input buffer for the message components. + * \return A cmix_error + */ +enum cmix_error post_process(struct CMixContext* ctx, char** r_out, char** m_out, char const** r_epirs, char const** m_epirs); +//TODO: check if we should add a length that pairs with message. +/*! + * \brief blind_message Blinds the message with all the shared keys between you and the nodes. + * \param ctx The relevant context. + * \param m_out The output buffer large enough to hold the array representation of a group element. + * \param message The input message buffer. + * \param keys Buffer that contains nr_nodes shared keys. + * \param nr_nodes The number of keys in the keys buffer. + * \return A cmix_error + */ enum cmix_error blind_message(struct CMixContext const* ctx, char* m_out, char const* message, GroupElement const* keys, size_t const nr_nodes); -enum cmix_error enqueue_message(struct CMixContext* ctx, char const* message, size_t index); - -enum cmix_error enqueue_random_message(struct CMixContext* ctx, size_t index); - -enum cmix_error swap_k_for_r(struct CMixContext const* ctx, char** out_buffer, char const** message, GroupElement const* key, size_t nr_elements); +/*! + * \brief swap_k_for_r multiplies with K^-1 and multiplies with R + * \param ctx The relevant context. + * \param out_buffer The output buffer. + * \param message The input buffer. + * \param key The K to inverse and multiply with. + * \return A cmix_error + */ +enum cmix_error swap_k_for_r(struct CMixContext const* ctx, char** out_buffer, char const** message, GroupElement const* key); +/*! + * \brief remove_r_and_s multiply with (Pi(R) * S)^-1 + * \param ctx The relevant context. + * \param out_buffer The ouput buffer, + * \param message The input buffer + * \param index message process message x (take the x'th Pi(R) * S) + * \return A cmix_error + */ enum cmix_error remove_r_and_s(struct CMixContext const* ctx, char* out_buffer, char const* message, size_t index); +/*! + * \brief create_message Creates a message by embedding the destination in the message buffer. + * \param ctx The relevant context. + * \param out_buffer output buffer needs to be large enough to hold a GroupElement in array representation. + * \param dest The destination string. + * \param dest_len The destination string length. + * \param payload The payload string. + * \param payload_len The payload string length. + * \return A cmix_error + */ enum cmix_error create_message(struct CMixContext const* ctx, char* out_buffer, char const* dest, size_t dest_len, char const* payload, size_t payload_len); +/*! + * \brief split_message Splits a message in its destination and payload components. + * \param ctx The relevant context. + * \param dest_buffer pointer to a char* storage that will be initialized by this function. + * must be free()d + * \param dest_len pointer to a size_t ,will be filled with the resulting destination string length. + * \param payload_buffer pointer to a char* storage that will be initialized by this function. + * must be free()d + * \param payload_len point to a size_t, will be filled with the resulting payload string length. + * \param message The unsplitted string pointer (is of length group element array representation length). + * \return A cmix_error + */ enum cmix_error split_message(struct CMixContext const* ctx, char** dest_buffer, size_t* dest_len, char** payload_buffer, size_t* payload_len, char const* message); #ifdef __cplusplus diff --git a/node/node.cpp b/node/node.cpp index b31f60a..c17fe4f 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -202,14 +202,22 @@ void Node::start_precomputation() { if(encrypt_r( &cmix_ctx, r_er.data(), - m_er.data(), - cmix_ctx.nr_participants + m_er.data() ) != no_error) { exit(-1); } BOOST_LOG_TRIVIAL(trace) << "Sending prepre message: " << prepre.ShortDebugString(); next_node.async_send(prepre); + + auto it = messages.cbegin(); + while(it != messages.cend()) { + if(it->second.empty()) { + it = messages.erase(it); + } else { + ++it; + } + } } void Node::start_realtime_phase() { @@ -251,8 +259,7 @@ void Node::start_realtime_phase() { &cmix_ctx, ms.data(), msv.data(), - keys.data(), - index_map.size() + keys.data() ); for(auto&& pair : index_map) { diff --git a/node/node.hpp b/node/node.hpp index 5365c9f..a058916 100644 --- a/node/node.hpp +++ b/node/node.hpp @@ -22,6 +22,12 @@ */ #ifndef NDEBUG +/*! + * \brief to_string Debug function that turns a groupelement to a string. + * \param el element to convert. + * \param ctx The context to use. + * \return The string containing the binary data of the array representation of the groupelement + */ inline std::string to_string(GroupElement el, CMixContext const& ctx) { std::string ret; ret.resize(get_group_element_array_size(&ctx)); diff --git a/node/node_node.cpp b/node/node_node.cpp index 00968a0..d859da9 100644 --- a/node/node_node.cpp +++ b/node/node_node.cpp @@ -44,8 +44,7 @@ cmix_proto::PrePre fill_precomputation_pre_message(CMixContext& ctx, T const& rs r_ers.data(), m_ers.data(), rsv.data(), - msv.data(), - ms.size() + msv.data() ) != no_error) { exit(-1); } @@ -80,8 +79,7 @@ cmix_proto::PreMix fill_precomputation_mix_message(CMixContext const& ctx, T con r_epirs.data(), m_epirs.data(), rsv.data(), - msv.data(), - ms.size() + msv.data() ); return premix; } @@ -114,8 +112,7 @@ cmix_proto::PrePost fill_precomputation_post_message(CMixContext& ctx, T const& r_epirs.data(), m_epirs.data(), rsv.data(), - msv.data(), - ms.size() + msv.data() ); return prepost; @@ -147,8 +144,7 @@ cmix_proto::RealPre fill_realtime_pre_message(CMixContext& ctx, T const& hs, T c &ctx, msv1.data(), msv2.data(), - gs.data(), - ms.size() + gs.data() ); return realpre; @@ -172,8 +168,7 @@ cmix_proto::RealMix fill_realtime_mix_message(CMixContext& ctx, T const& ms) { permute_and_multiply_s( &ctx, mv.data(), - msv.data(), - ms.size() + msv.data() ); return realmix; @@ -182,7 +177,7 @@ cmix_proto::RealMix fill_realtime_mix_message(CMixContext& ctx, T const& ms) { void Node::handle_node_initialization(const cmix_proto::Initialization& init) { if(network_settings.is_first) { - set_network_key(&cmix_ctx, init.public_share().data(), init.public_share().size()); + set_network_key(&cmix_ctx, init.public_share().data()); cmix_proto::SecretKey sec; sec.set_secret_key(init.public_share().data(), init.public_share().size()); @@ -207,7 +202,7 @@ void Node::handle_node_secretkey(cmix_proto::SecretKey const& secret) if(network_settings.is_first) { start_timer_delayed_mix(); } else { - set_network_key(&cmix_ctx, secret.secret_key().data(), secret.secret_key().size()); + set_network_key(&cmix_ctx, secret.secret_key().data()); next_node.async_send(secret); } } diff --git a/scratchpad/scratchpad.c b/scratchpad/scratchpad.c index 49a484f..4e7f007 100644 --- a/scratchpad/scratchpad.c +++ b/scratchpad/scratchpad.c @@ -1,6 +1,5 @@ #include "cmix.h" -#include "message.h" #include "api.h" @@ -10,7 +9,6 @@ #include <string.h> #include <stddef.h> -void cmix_buffer_scratch(); void crypto_api_scratch(); void gcrypt_scratch(); @@ -123,24 +121,6 @@ void gcrypt_scratch() { gcry_sexp_release(plain_sexpr); } -void cmix_buffer_scratch() { - struct CmixBufferImpl buffer_impl = get_cmix_Curve25519_buffer_implementation(); - char* buffer = buffer_impl.allocate_cmix_buffer(3); - - int message_size = buffer_impl.message_length(); - - for(int i=0; i < 3; i++) { - buffer[i*message_size] = 'h'; - } - - for(int i=0; i < 3; i++) { - putc(buffer[i*message_size], stdout); - putc('\n', stdout); - } - - buffer_impl.deallocate_cmix_buffer(buffer); -} - void crypto_api_scratch() { /* struct Api api = get_implementation(); |
