mbedtls_mpi_mod_write() function
Write a residue into a byte buffer. The modulus \p N must be the modulus associated with \p r (see mbedtls_mpi_mod_residue_setup() and mbedtls_mpi_mod_read()). The residue will be automatically converted from the internal representation based on the value of `N->int_rep` field. \warning If the buffer is smaller than `N->bits`, the number of leading zeroes is leaked through timing. If \p r is secret, the caller must ensure that \p buflen is at least (`N->bits`+7)/8.
Arguments
r
The address of the residue. It must have the same number of limbs as the modulus \p N. (\p r is an input parameter, but its value will be modified during execution and restored before the function returns.)
N
The address of the modulus associated with \p r.
buf
The output buffer to export to.
buflen
The length in bytes of \p buf.
ext_rep
The endianness in which the number should be written into the output buffer.
Return value
\c 0 if successful. #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't large enough to hold the value of \p r (without leading zeroes). #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p ext_rep is invalid. #MBEDTLS_ERR_MPI_ALLOC_FAILED if couldn't allocate enough memory for conversion. Can occur only for moduli with MBEDTLS_MPI_MOD_REP_MONTGOMERY.