Add mod_mul function
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
parent
3e0418fe50
commit
9db81e9cca
2 changed files with 56 additions and 0 deletions
|
@ -176,6 +176,28 @@ exit:
|
|||
|
||||
/* BEGIN MERGE SLOT 2 */
|
||||
|
||||
int mbedtls_mpi_mod_mul( mbedtls_mpi_mod_residue *X,
|
||||
const mbedtls_mpi_mod_residue *A,
|
||||
const mbedtls_mpi_mod_residue *B,
|
||||
const mbedtls_mpi_mod_modulus *N )
|
||||
{
|
||||
if( N->limbs == 0 )
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
|
||||
if( X->limbs != N->limbs || A->limbs != N->limbs || B->limbs != N->limbs )
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
|
||||
mbedtls_mpi_uint *T = mbedtls_calloc( N->limbs * 2 + 1, ciL );
|
||||
if( !T )
|
||||
return MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
||||
|
||||
mbedtls_mpi_mod_raw_mul( X->p, A->p, B->p, N, T );
|
||||
|
||||
mbedtls_free( T );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* END MERGE SLOT 2 */
|
||||
|
||||
/* BEGIN MERGE SLOT 3 */
|
||||
|
|
|
@ -217,6 +217,40 @@ void mbedtls_mpi_mod_modulus_free( mbedtls_mpi_mod_modulus *m );
|
|||
|
||||
/* BEGIN MERGE SLOT 2 */
|
||||
|
||||
/** \brief Multiply two residues, returning the residue modulo the specified
|
||||
* modulus.
|
||||
*
|
||||
* \note Currenty handles the case when `m->int_rep` is
|
||||
* MBEDTLS_MPI_MOD_REP_MONTGOMERY.
|
||||
*
|
||||
* The size of the operation is determined by \p N. \p A and \p B must 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. They may not alias \p N (since they must be in canonical
|
||||
* form, they cannot == \p N).
|
||||
*
|
||||
* \param[out] X The address of the result MPI.
|
||||
* This must be initialized. Must have enough limbs to
|
||||
* store the full value of the result.
|
||||
* On successful completion, \p X contains the result of
|
||||
* the multiplication `A * B * R^-1` mod N where
|
||||
* `R = 2^(biL *N->limbs)`.
|
||||
* \param[in] A The address of the first MPI. This must be initialized.
|
||||
* \param[in] B The address of the second MPI. This must be initialized.
|
||||
* \param[in] N The address of the modulus. Used to perform a modulo
|
||||
* operation on the result of the multiplication.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if all the parameters does not
|
||||
* have the same number of limbs or \p N is invalid.
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
|
||||
*/
|
||||
int mbedtls_mpi_mod_mul( 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 2 */
|
||||
|
||||
/* BEGIN MERGE SLOT 3 */
|
||||
|
|
Loading…
Reference in a new issue