From 1e316c9a7437580f499453cdafbb0c7433a46b88 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Sat, 18 Aug 2018 14:14:55 +0200 Subject: Processes review comments. --- appendices/api.h | 187 ++++++++++++++++++++++++++++++++++++++++++++++++ appendices/appendix.tex | 50 +++++++++---- appendices/ed25519.h | 47 ++++++++++++ appendices/elgamal.h | 47 ++++++++++++ 4 files changed, 316 insertions(+), 15 deletions(-) create mode 100644 appendices/api.h create mode 100644 appendices/ed25519.h create mode 100644 appendices/elgamal.h (limited to 'appendices') diff --git a/appendices/api.h b/appendices/api.h new file mode 100644 index 0000000..8279dbb --- /dev/null +++ b/appendices/api.h @@ -0,0 +1,187 @@ +#pragma once + +/*! + * \file + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "groupelement.h" +#include "keypair.h" +#include "sharedkey.h" + +typedef void(*Initializer)(void); + +/*! + * \brief Defines how a KeyPair create function should look like. + * Used to store a pointer to function to a implementation. + */ +typedef struct KeyPair (*KeyPairCreator)(void); + +/*! + * \brief Defines how a KeyPair deleter function should look like. + * Used to store a pointer to function to a implementation. + */ +typedef void (*KeyPairDeleter)(struct KeyPair*); + +/*! + * \brief Defines how a Derived Shared Key function should look like. + * Used to store a pointer to function to a implementation. + */ +typedef GroupElement (*SharedKeyDeriver)(struct KeyPair, unsigned char const*, size_t, unsigned char const*, size_t, GroupElement, bool); + +/*! + * \brief Defines how a Derived Shared Key deleter function should look like. + * Used to store a pointer to function to a implementation. + */ +typedef void (*SharedKeyDeleter)(struct SharedKey*); + +/*! + * \brief Defines how the crypto library deinitialization should look. + */ +typedef void(*Deinitializer)(void); + +/*! + * \brief PubKeyArrayGetter typedef + */ +typedef void(*ElementToArray)(unsigned char**, size_t* size, GroupElement); + +/*! + * + */ +typedef void(*BufferDeleter)(void*); + +/*! + * + */ +typedef GroupElement(*ArrayToElement)(char const*, size_t size, bool); + +/*! + * + */ +typedef GroupElement(*MessageToElement)(char const*, size_t size, bool); + +/*! + * + */ +typedef void(*ElementToMessage)(unsigned char** message, const GroupElement element); + +/*! + * + */ +typedef void(*PubKeyHashGetter)(char** buffer, size_t* len, GroupElement const pub); + +/*! + * + */ +typedef size_t(*PubKeyHashLengthGetter)(); + +/*! + * \brief PublicShareAdder typedef + */ +typedef void(*PublicShareAdder)(GroupElement*, char const*, size_t, GroupElement); + +/*! + * + */ +typedef GroupElement(*GroupElementGetter)(bool); + +/*! + * + */ +typedef GroupElement(*KeyExchangeValueGetter)(GroupElement); + +/*! + * + */ +typedef GroupElement(*GroupElementCombiner)(GroupElement, GroupElement, bool); + +/*! + * + */ +typedef GroupElement(*GroupElementUncombiner)(GroupElement, GroupElement, bool); + +/*! + * + */ +typedef size_t(*GroupElementArraySizeGetter)(); + +/*! + * + */ +typedef size_t(*MessageSizeGetter)(); + +/*! + * + */ +typedef void(*GroupElementDeleter)(GroupElement); + +/*! + * + */ +typedef void (*Encrypter)(GroupElement*, GroupElement*, GroupElement, GroupElement); + +/*! + * + */ +typedef GroupElement (*Inverter)(GroupElement); + +/*! + * + */ +typedef unsigned int (*UniformIntGetter)(unsigned int); + +/*! + * + */ +typedef GroupElement (*DecryptionShareGetter)(GroupElement, GroupElement); + +/*! + * \brief The Api struct stores pointers to functions of a specific implementation. Like a Curve25519 specific one. + */ +struct Api { + Initializer initialize; ///< Function that will initialize the crypto library. + KeyPairCreator create_keypair; ///< Pointer to keypair creation function + KeyPairDeleter free_keypair; ///< Pointer to keypair deletor function + ElementToArray element_to_array; ///< Get the array representation of a public key + BufferDeleter free_buffer; ///< frees library allocated buffers. + ArrayToElement array_to_element; ///< The the GroupElement representation of this array. + MessageToElement message_to_element; ///< Convert Message to element. + ElementToMessage element_to_message; ///< Convert Element to message. + PubKeyHashGetter get_pub_key_hash; ///< Get the hash of the public key. + PubKeyHashLengthGetter get_pub_key_hash_length; ///< Get the length of the pubkey hash. + GroupElementGetter get_group_element; ///< get group element + GroupElementArraySizeGetter get_group_element_array_size; ///< Return the size required to store a groupelement in an array; + MessageSizeGetter get_message_size; ///< Retrieve how large a message can be. + GroupElementDeleter free_group_element; ///< frees a base type of the cryptolibrary. + KeyExchangeValueGetter get_key_exchange_value; ///< get generator *op* group element. + GroupElementCombiner combine; ///< Combines two groupelements modulo group. + GroupElementUncombiner uncombine; ///< Uncombines two groupelements; + DecryptionShareGetter get_decryption_share; ///< calculates the first argument to the power of Inverse second argument; + PublicShareAdder add_public_share; ///< Adds the public key stored in void* to the existing share. + SharedKeyDeriver derive_shared_key; ///< Pointer to shared key derivation function + SharedKeyDeleter free_shared_key; ///< Pointer to shared key deleter function + Encrypter encrypt; ///< encrypt value with key; + Inverter invert; ///< Invert the group element; + UniformIntGetter get_uniform_int; ///< Get a uniform int [0 .. argument); + Deinitializer deinitialize; ///< Function that will deinitialize the crypto library. +}; + +/*! + * A Pointer to function typedef to facilitate multiple implementations. + */ +typedef struct Api(*ImplementationGetter)(void); + +/*! + * \brief get_implementation The pointer to member function variable to implement when + * defining a an implementation + */ +extern ImplementationGetter get_implementation; + +#ifdef __cplusplus +} +#endif diff --git a/appendices/appendix.tex b/appendices/appendix.tex index e8787ea..c8358a8 100644 --- a/appendices/appendix.tex +++ b/appendices/appendix.tex @@ -3,6 +3,7 @@ \section{Implementation} \label{app:impl} +\label{app:code} \begin{table}[!ht] \begin{tabular}{l l} @@ -66,19 +67,19 @@ both C and C++ optimization related compiler flags: \end{tabularx} \end{table} -\section{Some scripts to do result processing} - -The script that converts the output from the statsd to a \LaTeX\xspace table format. - -\begin{lstlisting} -cut -d ',' -f 2,5,8,11,14,17,20,23,26,29,32,35 | awk 'BEGIN {FS=",";}; {if (NR == 1) {print "prepre (s) & premix (s) & prepost (s) & realpre (s) & realmix (s) & realpost (s) \\\\\hline\\hline";} else{ OFMT="%.2f"; c=1000000000; print ($5-$6)/c,"&",($1-$2)/c,"&",($3-$4)/c,"&",($11-$12)/c,"&",($7-$8)/c,"&",($9-$10)/c,"\\\\\\hline";}}' -\end{lstlisting} - -Script that calculates the mean and standard deviation of each column. - -\begin{lstlisting} -tail -n +2 | cut -d ',' -f 2,5,8,11,14,17,20,23,26,29,32,35 | awk 'BEGIN {FS=",";}; { OFMT="%.2f"; c=1000000000; print ($5-$6)/c,($1-$2)/c,($3-$4)/c,($11-$12)/c,($7-$8)/c,($9-$10)/c;}' | awk '{for(i=1;i<=NF;i++) {sum[i] += $i; sumsq[i] += ($i)^2}} END {for (i=1;i<=NF;i++) {printf " & %.3f (%.3f)", sum[i]/NR, sqrt((sumsq[i]-sum[i]^2/NR)/NR)} printf("\n")}' -\end{lstlisting} +%\section{Some scripts to do result processing} +% +%The script that converts the output from the statsd to a \LaTeX\xspace table format. +% +%\begin{lstlisting} +%cut -d ',' -f 2,5,8,11,14,17,20,23,26,29,32,35 | awk 'BEGIN {FS=",";}; {if (NR == 1) {print "prepre (s) & premix (s) & prepost (s) & realpre (s) & realmix (s) & realpost (s) \\\\\hline\\hline";} else{ OFMT="%.2f"; c=1000000000; print ($5-$6)/c,"&",($1-$2)/c,"&",($3-$4)/c,"&",($11-$12)/c,"&",($7-$8)/c,"&",($9-$10)/c,"\\\\\\hline";}}' +%\end{lstlisting} +% +%Script that calculates the mean and standard deviation of each column. +% +%\begin{lstlisting} +%tail -n +2 | cut -d ',' -f 2,5,8,11,14,17,20,23,26,29,32,35 | awk 'BEGIN {FS=",";}; { OFMT="%.2f"; c=1000000000; print ($5-$6)/c,($1-$2)/c,($3-$4)/c,($11-$12)/c,($7-$8)/c,($9-$10)/c;}' | awk '{for(i=1;i<=NF;i++) {sum[i] += $i; sumsq[i] += ($i)^2}} END {for (i=1;i<=NF;i++) {printf " & %.3f (%.3f)", sum[i]/NR, sqrt((sumsq[i]-sum[i]^2/NR)/NR)} printf("\n")}' +%\end{lstlisting} \clearpage @@ -188,8 +189,27 @@ tail -n +2 | cut -d ',' -f 2,5,8,11,14,17,20,23,26,29,32,35 | awk 'BEGIN {FS="," \end{table} -%%----------------------------------------------------------------------- -% +\newpage +\section{crypto interface} +\lstinputlisting[ +language=C++, +caption={ed25519.h}, +label={lst:ed25519.h}, +keywordstyle=\color{blue}, +stringstyle=\color{red} +]{appendices/ed25519.h} + +\newpage +\lstinputlisting[ +language=C++, +caption={elgamal.h}, +label={lst:elgamal.h}, +keywordstyle=\color{blue}, +stringstyle=\color{red} +]{appendices/elgamal.h} + +%======= +%----------------------------------------------------------------------- %\vfill %\clearpage % diff --git a/appendices/ed25519.h b/appendices/ed25519.h new file mode 100644 index 0000000..43746bf --- /dev/null +++ b/appendices/ed25519.h @@ -0,0 +1,47 @@ +#pragma once + +#include "api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * \file + */ + +extern Initializer ed25519_initialize; +extern KeyPairCreator ed25519_create_keypair; +extern KeyPairDeleter ed25519_delete_keypair; +extern ElementToArray ed25519_element_to_array; +extern BufferDeleter ed25519_free_buffer; +extern ArrayToElement ed25519_array_to_element; +extern MessageToElement ed25519_message_to_element; +extern ElementToMessage ed25519_element_to_message; +extern PubKeyHashGetter ed25519_get_pub_key_hash; +extern PubKeyHashLengthGetter ed25519_get_pub_key_hash_length; +extern GroupElementGetter ed25519_get_group_element; +extern GroupElementDeleter ed25519_delete_group_element; +extern KeyExchangeValueGetter ed25519_get_key_exchange_value; +extern GroupElementCombiner ed25519_combine; +extern GroupElementUncombiner ed25519_uncombine; +extern DecryptionShareGetter ed25519_get_decryption_share; +extern GroupElementArraySizeGetter ed25519_get_group_element_array_size; +extern MessageSizeGetter ed25519_get_message_size; +extern PublicShareAdder ed25519_add_public_share; +extern SharedKeyDeriver ed25519_derive_shared_key; +extern SharedKeyDeleter ed25519_delete_shared_key; +extern Encrypter ed25519_encrypt; +extern Inverter ed25519_invert; +extern UniformIntGetter ed25519_get_uniform_int; +extern Deinitializer ed25519_deinitialize; + +/*! + * \brief get_ed25519_implementation + * \return An Api struct filled with a ed25519 implementation. + */ +struct Api get_ed25519_implementation(); + +#ifdef __cplusplus +} +#endif diff --git a/appendices/elgamal.h b/appendices/elgamal.h new file mode 100644 index 0000000..833047e --- /dev/null +++ b/appendices/elgamal.h @@ -0,0 +1,47 @@ +#pragma once + +/*! + * \file + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "api.h" + +extern Initializer elgamal_initialize; +extern KeyPairCreator elgamal_create_keypair; +extern KeyPairDeleter elgamal_delete_keypair; +extern ElementToArray elgamal_element_to_array; +extern BufferDeleter elgamal_free_buffer; +extern ArrayToElement elgamal_array_to_element; +extern MessageToElement elgamal_message_to_element; +extern ElementToMessage elgamal_element_to_message; +extern PubKeyHashGetter elgamal_get_pub_key_hash; +extern PubKeyHashLengthGetter elgamal_get_pub_key_hash_length; +extern GroupElementGetter elgamal_get_group_element; +extern GroupElementDeleter elgamal_delete_group_element; +extern KeyExchangeValueGetter elgamal_get_key_exchange_value; +extern GroupElementCombiner elgamal_combine; +extern GroupElementUncombiner elgamal_uncombine; +extern DecryptionShareGetter elgamal_get_decryption_share; +extern GroupElementArraySizeGetter elgamal_get_group_element_array_size; +extern MessageSizeGetter elgamal_get_message_size; +extern PublicShareAdder elgamal_add_public_share; +extern SharedKeyDeriver elgamal_derive_shared_key; +extern SharedKeyDeleter elgamal_delete_shared_key; +extern Encrypter elgamal_encrypt; +extern Inverter elgamal_invert; +extern UniformIntGetter elgamal_get_uniform_int; +extern Deinitializer elgamal_deinitialize; + +/*! + * \brief get_elgamal_implementation + * \return + */ +struct Api get_elgamal_implementation(); + +#ifdef __cplusplus +} +#endif -- cgit v1.2.3-70-g09d2