#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 struct SharedKey (*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 GroupElement(*ArrayToElement)(char const*, size_t size, bool); /*! * \brief PublicShareAdder typedef */ typedef void(*PublicShareAdder)(char**, size_t*, char const*, size_t, GroupElement); /*! * */ typedef GroupElement(*GroupElementGetter)(bool); /*! * */ typedef GroupElement(*KeyExchangeValueGetter)(GroupElement); /*! * */ typedef GroupElement(*GroupElementMultiplier)(GroupElement, GroupElement, bool); /*! * */ typedef void(*GroupElementDeleter)(GroupElement); /*! * */ typedef void (*Encrypter)(GroupElement*, GroupElement*, 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_key_pair; ///< Pointer to keypair creation function KeyPairDeleter free_key_pair; ///< Pointer to keypair deletor function ElementToArray element_to_array; ///< Get the array representation of a public key ArrayToElement array_to_element; ///< The the GroupElement representation of this array; GroupElementGetter get_group_element; ///< get group element 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. 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; 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