mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Bignum core: random: prototype
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -512,6 +512,43 @@ int mbedtls_mpi_core_fill_random( mbedtls_mpi_uint *X, size_t X_limbs,
|
|||||||
int (*f_rng)(void *, unsigned char *, size_t),
|
int (*f_rng)(void *, unsigned char *, size_t),
|
||||||
void *p_rng );
|
void *p_rng );
|
||||||
|
|
||||||
|
/** Generate a random number uniformly in a range.
|
||||||
|
*
|
||||||
|
* This function generates a random number between \p min inclusive and
|
||||||
|
* \p N exclusive.
|
||||||
|
*
|
||||||
|
* The procedure complies with RFC 6979 §3.3 (deterministic ECDSA)
|
||||||
|
* when the RNG is a suitably parametrized instance of HMAC_DRBG
|
||||||
|
* and \p min is \c 1.
|
||||||
|
*
|
||||||
|
* \note There are `N - min` possible outputs. The lower bound
|
||||||
|
* \p min can be reached, but the upper bound \p N cannot.
|
||||||
|
*
|
||||||
|
* \param X The destination MPI, with \p limbs limbs.
|
||||||
|
* It must not be aliased with \p N or otherwise overlap it.
|
||||||
|
* \param min The minimum value to return.
|
||||||
|
* \param N The upper bound of the range, exclusive, with \p limbs limbs.
|
||||||
|
* In other words, this is one plus the maximum value to return.
|
||||||
|
* \p N must be strictly larger than \p min.
|
||||||
|
* \param limbs The number of limbs of \p N and \p X.
|
||||||
|
* This must not be 0.
|
||||||
|
* \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.
|
||||||
|
*
|
||||||
|
* \return \c 0 if successful.
|
||||||
|
* \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if the implementation was
|
||||||
|
* unable to find a suitable value within a limited number
|
||||||
|
* of attempts. This has a negligible probability if \p N
|
||||||
|
* is significantly larger than \p min, which is the case
|
||||||
|
* for all usual cryptographic applications.
|
||||||
|
*/
|
||||||
|
int mbedtls_mpi_core_random( mbedtls_mpi_uint *X,
|
||||||
|
mbedtls_mpi_uint min,
|
||||||
|
const mbedtls_mpi_uint *N,
|
||||||
|
size_t limbs,
|
||||||
|
int (*f_rng)(void *, unsigned char *, size_t),
|
||||||
|
void *p_rng );
|
||||||
|
|
||||||
/* BEGIN MERGE SLOT 1 */
|
/* BEGIN MERGE SLOT 1 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user