#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 void(*PubKeyHashGetter)(char** buffer, size_t* len, GroupElement const pub); /*! * \brief PublicShareAdder typedef */ typedef void(*PublicShareAdder)(GroupElement*, char const*, size_t, GroupElement); /*! * */ typedef GroupElement(*GroupElementGetter)(bool); /*! * */ typedef GroupElement(*KeyExchangeValueGetter)(GroupElement); /*! * */ typedef GroupElement(*GroupElementMultiplier)(GroupElement, GroupElement, bool); /*! * */ typedef size_t(*GroupElementArraySizeGetter)(); /*! * */ 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; PubKeyHashGetter get_pub_key_hash; ///< Get the hash of the public key. GroupElementGetter get_group_element; ///< get group element GroupElementArraySizeGetter get_group_element_array_size; ///< Return the size required to store a groupelement in an array; GroupElementDeleter free_group_element; ///< frees a base type of the cryptolibrary. KeyExchangeValueGetter get_key_exchange_value; ///< get generator *op* group element. GroupElementMultiplier multiply; ///< Multiplies two groupelements modulo group. 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