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 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 appendices/api.h (limited to 'appendices/api.h') 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 -- cgit v1.2.3-70-g09d2