diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-08-26 11:21:41 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-08-26 11:21:41 +0200 |
| commit | 00ab2cf6add2976b3a4e8f8cc488777ad5c27808 (patch) | |
| tree | b9399bf912d949c289ff31edae8af2303dff7d26 /libcmix | |
| download | cmix-00ab2cf6add2976b3a4e8f8cc488777ad5c27808.tar.gz cmix-00ab2cf6add2976b3a4e8f8cc488777ad5c27808.tar.bz2 cmix-00ab2cf6add2976b3a4e8f8cc488777ad5c27808.zip | |
Initial commit, just some ideas and testing.
Diffstat (limited to 'libcmix')
| -rw-r--r-- | libcmix/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | libcmix/cmix.c | 28 | ||||
| -rw-r--r-- | libcmix/cmix.h | 51 |
3 files changed, 87 insertions, 0 deletions
diff --git a/libcmix/CMakeLists.txt b/libcmix/CMakeLists.txt new file mode 100644 index 0000000..5d87a56 --- /dev/null +++ b/libcmix/CMakeLists.txt @@ -0,0 +1,8 @@ + +add_library(cmix + cmix.h cmix.c +) + +target_include_directories(cmix + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +)
\ No newline at end of file diff --git a/libcmix/cmix.c b/libcmix/cmix.c new file mode 100644 index 0000000..944ac9c --- /dev/null +++ b/libcmix/cmix.c @@ -0,0 +1,28 @@ + +#include "cmix.h" + +#include <string.h> + +enum cmix_error permutation(struct CMixBuffer b) { + return no_error; +} + +enum cmix_error get_message(char* message, struct CMixBuffer b, unsigned int index) +{ + if(index >= b.message_length) { + return index_out_of_range; + } + + strncpy(message, b.buffer + index * b.message_length, b.message_length); + + return no_error; +} + +enum cmix_error set_message(char const* message, struct CMixBuffer b, unsigned int index) +{ + if(index >= b.message_length) { + return index_out_of_range; + } + + strncpy(b.buffer + index * b.message_length, message, b.message_length); +} diff --git a/libcmix/cmix.h b/libcmix/cmix.h new file mode 100644 index 0000000..5fe2e13 --- /dev/null +++ b/libcmix/cmix.h @@ -0,0 +1,51 @@ +/** + * \file + */ + +struct message { + char buffer[2048/8]; +}; + +/** + * \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 + */ +enum cmix_error { + no_error = 0, + index_out_of_range = 1000 +}; + +/** + * \brief permutate mixes the messages before sending the messages. + * \param[in,out] b A buffer of \p nr_messages messages, each message of length *message_len* + * \return no_error + */ +enum cmix_error permute(struct CMixBuffer b); + +/** + * \brief get_message takes the \p index message of the buffer \p b copies it into \p message + * \param[out] message is the output buffer that has to hold at least \p b.message_length bytes. + * \param[in] b is the buffer from which to copy the message. + * \param[in] index is the index of the message to copy. + * \return index_out_of_range if \p index is greater than or equal to \p b.nr_messages , otherwise no_error. + */ +enum cmix_error get_message(char* message, struct CMixBuffer b, unsigned int index); + +/** + * \brief set_message set the \p index message of the buffer to a copy of \p message. + * \param[in] message The message to set the part of the buffer to. + * \param[in,out] b The buffer + * \param[in] index The index into the buffer + * \return index_out_of_range if \p index is greater than or equal to \p b.nr_messages , otherwise no_error. + */ +enum cmix_error set_message(char const* message, struct CMixBuffer b, unsigned int index);
\ No newline at end of file |
