1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-05 19:35:48 +03:00

Merge pull request #6732 from wernerlewis/bignum_6019_mod_add

Bignum: Implement mbedtls_mpi_mod_add()
This commit is contained in:
Manuel Pégourié-Gonnard
2022-12-15 11:39:24 +01:00
committed by GitHub
5 changed files with 179 additions and 3 deletions

View File

@@ -198,7 +198,18 @@ int mbedtls_mpi_mod_sub( mbedtls_mpi_mod_residue *X,
/* END MERGE SLOT 4 */
/* BEGIN MERGE SLOT 5 */
int mbedtls_mpi_mod_add( mbedtls_mpi_mod_residue *X,
const mbedtls_mpi_mod_residue *A,
const mbedtls_mpi_mod_residue *B,
const mbedtls_mpi_mod_modulus *N )
{
if( X->limbs != N->limbs || A->limbs != N->limbs || B->limbs != N->limbs )
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
mbedtls_mpi_mod_raw_add(X->p, A->p, B->p, N);
return( 0 );
}
/* END MERGE SLOT 5 */
/* BEGIN MERGE SLOT 6 */

View File

@@ -199,7 +199,36 @@ int mbedtls_mpi_mod_sub( mbedtls_mpi_mod_residue *X,
/* END MERGE SLOT 4 */
/* BEGIN MERGE SLOT 5 */
/**
* \brief Perform a fixed-size modular addition.
*
* Calculate `A + B modulo N`.
*
* \p A, \p B and \p X must all be associated with the modulus \p N and must
* all have the same number of limbs as \p N.
*
* \p X may be aliased to \p A or \p B, or even both, but may not overlap
* either otherwise.
*
* \note This function does not check that \p A or \p B are in canonical
* form (that is, are < \p N) - that will have been done by
* mbedtls_mpi_mod_residue_setup().
*
* \param[out] X The address of the result residue. Must be initialized.
* Must have the same number of limbs as the modulus \p N.
* \param[in] A The address of the first input residue.
* \param[in] B The address of the second input residue.
* \param[in] N The address of the modulus. Used to perform a modulo
* operation on the result of the addition.
*
* \return \c 0 if successful.
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the given MPIs do not
* have the correct number of limbs.
*/
int mbedtls_mpi_mod_add( mbedtls_mpi_mod_residue *X,
const mbedtls_mpi_mod_residue *A,
const mbedtls_mpi_mod_residue *B,
const mbedtls_mpi_mod_modulus *N );
/* END MERGE SLOT 5 */
/* BEGIN MERGE SLOT 6 */