mbedtls_mpi_core_random() function
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.
Arguments
X
The destination MPI, with \p limbs limbs. It must not be aliased with \p N or otherwise overlap it.
min
The minimum value to return.
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.
limbs
The number of limbs of \p N and \p X. This must not be 0.
f_rng
The RNG function to use. This must not be \c NULL.
p_rng
The RNG parameter to be passed to \p f_rng.
Return value
\c 0 if successful. #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.
Notes
There are `N - min` possible outputs. The lower bound \p min can be reached, but the upper bound \p N cannot.
mbedtls_mpi_core_random() is called by 1 function and calls 7 functions:
![]()
mbedtls_mpi_core_random()
mbedtls_mpi_core_random():
![]()
mbedtls_mpi_core_random()