#pragma once #include #include #ifdef __cplusplus extern "C" { #endif /*! * \file */ /*! * \brief The bignum_error enum */ enum bignum_error { NoError = 0, error = -1 }; /*! * \brief cMix internal bignum representation. */ struct Bignum { unsigned char* data; ///< Pointer to the start of the bignum. size_t len; ///< The length of the data array. }; /*! * \brief allocate_bignum. Reserves space for a len size Bignum. * \param len The length of the bignum data array. * \return The Bignum array just allocated. */ inline struct Bignum allocate_bignum(size_t len) { return (struct Bignum){ (unsigned char*) malloc(len), len }; } /*! * \brief free_bignum. Counterpart to allocate_bignum. * \param b The bignum to free */ inline void free_bignum(struct Bignum* b) { free(b->data); b->data = 0; b->len = 0; } /*! * \brief get_curve25519_mod. Conveniance for now, but this returns the mod of curve25519 algorith (2^255-19) * \param result The bignum to store the modulus in, has to be preallocated. * \return Error status code based on backend errors. */ extern enum bignum_error get_curve25519_mod(struct Bignum* result); /*! * \brief multiply_mod Multiplies 2 bignums module mod and stores the result in result. * \param result Preallocated Bignum where the result will be stored. * \param lh Lefthand of Multiplication. * \param rh Righthand of Multiplaction. * \param mod The modulus. * \return Error status code based on backend errors. */ extern enum bignum_error multiply_mod(struct Bignum* result, struct Bignum const lh, struct Bignum const rh, struct Bignum const mod); #ifdef __cplusplus } #endif