mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Merge pull request #6747 from gilles-peskine-arm/bignum-mod-random
Bignum mod random
This commit is contained in:
@@ -336,6 +336,74 @@ void mbedtls_mpi_mod_raw_add( mbedtls_mpi_uint *X,
|
||||
|
||||
/* BEGIN MERGE SLOT 6 */
|
||||
|
||||
/** Convert an MPI from canonical representation (little-endian limb array)
|
||||
* to the representation associated with the modulus.
|
||||
*
|
||||
* \param[in,out] X The limb array to convert.
|
||||
* It must have as many limbs as \p N.
|
||||
* It is converted in place.
|
||||
* If this function returns an error, the content of \p X
|
||||
* is unspecified.
|
||||
* \param[in] N The modulus structure.
|
||||
*
|
||||
*\ return \c 0 if successful.
|
||||
* Otherwise an \c MBEDTLS_ERR_MPI_xxx error code.
|
||||
*/
|
||||
int mbedtls_mpi_mod_raw_canonical_to_modulus_rep(
|
||||
mbedtls_mpi_uint *X,
|
||||
const mbedtls_mpi_mod_modulus *N );
|
||||
|
||||
/** Convert an MPI from the representation associated with the modulus
|
||||
* to canonical representation (little-endian limb array).
|
||||
*
|
||||
* \param[in,out] X The limb array to convert.
|
||||
* It must have as many limbs as \p N.
|
||||
* It is converted in place.
|
||||
* If this function returns an error, the content of \p X
|
||||
* is unspecified.
|
||||
* \param[in] N The modulus structure.
|
||||
*
|
||||
*\ return \c 0 if successful.
|
||||
* Otherwise an \c MBEDTLS_ERR_MPI_xxx error code.
|
||||
*/
|
||||
int mbedtls_mpi_mod_raw_modulus_to_canonical_rep(
|
||||
mbedtls_mpi_uint *X,
|
||||
const mbedtls_mpi_mod_modulus *N );
|
||||
|
||||
/** 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, in canonical representation modulo \p N.
|
||||
* It must not be aliased with \p N or otherwise overlap it.
|
||||
* \param min The minimum value to return. It must be strictly smaller
|
||||
* than \b N.
|
||||
* \param N The modulus.
|
||||
* This is the upper bound of the output range, exclusive.
|
||||
* \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_mod_raw_random( mbedtls_mpi_uint *X,
|
||||
mbedtls_mpi_uint min,
|
||||
const mbedtls_mpi_mod_modulus *N,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/* END MERGE SLOT 6 */
|
||||
|
||||
/* BEGIN MERGE SLOT 7 */
|
||||
|
Reference in New Issue
Block a user