mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Merge pull request #6550 from minosgalanakis/minos/6017_add_montgomery_conversion
Bignum: Add Montgomery conversion from/to cannonical form
This commit is contained in:
@ -127,7 +127,40 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A,
|
||||
/* END MERGE SLOT 6 */
|
||||
|
||||
/* BEGIN MERGE SLOT 7 */
|
||||
int mbedtls_mpi_mod_raw_to_mont_rep( mbedtls_mpi_uint *X,
|
||||
const mbedtls_mpi_mod_modulus *m )
|
||||
{
|
||||
mbedtls_mpi_uint *T;
|
||||
const size_t t_limbs = m->limbs * 2 + 1;
|
||||
|
||||
if( ( T = (mbedtls_mpi_uint *) mbedtls_calloc( t_limbs, ciL ) ) == NULL )
|
||||
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
|
||||
|
||||
mbedtls_mpi_core_montmul( X, X, m->rep.mont.rr, m->limbs, m->p, m->limbs,
|
||||
m->rep.mont.mm, T );
|
||||
|
||||
mbedtls_platform_zeroize( T, t_limbs * ciL );
|
||||
mbedtls_free( T );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_mpi_mod_raw_from_mont_rep( mbedtls_mpi_uint *X,
|
||||
const mbedtls_mpi_mod_modulus *m )
|
||||
{
|
||||
const mbedtls_mpi_uint one = 1;
|
||||
const size_t t_limbs = m->limbs * 2 + 1;
|
||||
mbedtls_mpi_uint *T;
|
||||
|
||||
if( ( T = (mbedtls_mpi_uint *) mbedtls_calloc( t_limbs, ciL ) ) == NULL )
|
||||
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
|
||||
|
||||
mbedtls_mpi_core_montmul( X, X, &one, 1, m->p, m->limbs,
|
||||
m->rep.mont.mm, T );
|
||||
|
||||
mbedtls_platform_zeroize( T, t_limbs * ciL );
|
||||
mbedtls_free( T );
|
||||
return( 0 );
|
||||
}
|
||||
/* END MERGE SLOT 7 */
|
||||
|
||||
/* BEGIN MERGE SLOT 8 */
|
||||
|
@ -163,7 +163,29 @@ int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A,
|
||||
/* END MERGE SLOT 6 */
|
||||
|
||||
/* BEGIN MERGE SLOT 7 */
|
||||
/** Convert an MPI into Montgomery form.
|
||||
*
|
||||
* \param X The address of the MPI.
|
||||
* Must have the same number of limbs as \p m.
|
||||
* \param m The address of the modulus, which gives the size of
|
||||
* the base `R` = 2^(biL*m->limbs).
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
*/
|
||||
int mbedtls_mpi_mod_raw_to_mont_rep( mbedtls_mpi_uint *X,
|
||||
const mbedtls_mpi_mod_modulus *m );
|
||||
|
||||
/** Convert an MPI back from Montgomery representation.
|
||||
*
|
||||
* \param X The address of the MPI.
|
||||
* Must have the same number of limbs as \p m.
|
||||
* \param m The address of the modulus, which gives the size of
|
||||
* the base `R`= 2^(biL*m->limbs).
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
*/
|
||||
int mbedtls_mpi_mod_raw_from_mont_rep( mbedtls_mpi_uint *X,
|
||||
const mbedtls_mpi_mod_modulus *m );
|
||||
/* END MERGE SLOT 7 */
|
||||
|
||||
/* BEGIN MERGE SLOT 8 */
|
||||
|
Reference in New Issue
Block a user