summaryrefslogtreecommitdiff
path: root/appendices/api.h
diff options
context:
space:
mode:
Diffstat (limited to 'appendices/api.h')
-rw-r--r--appendices/api.h187
1 files changed, 187 insertions, 0 deletions
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 <stdbool.h>
+
+#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