mbedtls_mpi_mod_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 residue.
min
The minimum value to return. It must be strictly smaller than \b N.
N
The modulus. This is the upper bound of the output range, exclusive.
f_rng
int (*)(void *, unsigned char *, size_t)
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.