From 909e03c52f7e2132656ed83e5f985466f51f9b24 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 18 Oct 2022 18:14:33 +0200 Subject: [PATCH] Bignum core: fill_random: prototype Signed-off-by: Gilles Peskine --- library/bignum_core.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/bignum_core.h b/library/bignum_core.h index ccccebbffa..624eaf49a3 100644 --- a/library/bignum_core.h +++ b/library/bignum_core.h @@ -470,4 +470,28 @@ void mbedtls_mpi_core_ct_uint_table_lookup( mbedtls_mpi_uint *dest, size_t count, size_t index ); +/** + * \brief Fill an integer with a number of random bytes. + * + * \param X The destination MPI. + * \param X_limbs The number of limbs of \p X. + * \param bytes The number of random bytes to generate. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. This may be + * \c NULL if \p f_rng doesn't need a context argument. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p X does not have + * enough room for \p bytes bytes. + * \return A negative error code on RNG failure. + * + * \note The bytes obtained from the RNG are interpreted + * as a big-endian representation of an MPI; this can + * be relevant in applications like deterministic ECDSA. + */ +int mbedtls_mpi_core_fill_random( mbedtls_mpi_uint *X, size_t X_limbs, + size_t bytes, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + #endif /* MBEDTLS_BIGNUM_CORE_H */