Function esp_idf_svc::sys::mbedtls_mpi_random
source · pub unsafe extern "C" fn mbedtls_mpi_random(
X: *mut mbedtls_mpi,
min: i32,
N: *const mbedtls_mpi,
f_rng: Option<unsafe extern "C" fn(_: *mut c_void, _: *mut u8, _: usize) -> i32>,
p_rng: *mut c_void,
) -> i32
Expand description
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. This must point to an initialized MPI. \param min The minimum value to return. It must be nonnegative. \param N The upper bound of the range, exclusive. In other words, this is one plus the maximum value to return. \p N must be strictly larger than \p min. \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_ALLOC_FAILED if a memory allocation failed. \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p min or \p N is invalid or if they are incompatible. \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. \return Another negative error code on failure.