mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Merge pull request #6407 from minosgalanakis/minos/6017_add_montgomery_constant_squared
Bignum: Added pre-calculation of Montgomery constants
This commit is contained in:
@ -511,4 +511,18 @@ void mbedtls_mpi_core_montmul( mbedtls_mpi_uint *X,
|
||||
mbedtls_ct_mpi_uint_cond_assign( AN_limbs, X, T, (unsigned char) ( carry ^ borrow ) );
|
||||
}
|
||||
|
||||
int mbedtls_mpi_core_get_mont_r2_unsafe( mbedtls_mpi *X,
|
||||
const mbedtls_mpi *N )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( X, N->n * 2 * biL ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( X, X, N ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shrink( X, N->n ) );
|
||||
|
||||
cleanup:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
@ -412,4 +412,22 @@ void mbedtls_mpi_core_montmul( mbedtls_mpi_uint *X,
|
||||
const mbedtls_mpi_uint *N, size_t AN_limbs,
|
||||
mbedtls_mpi_uint mm, mbedtls_mpi_uint *T );
|
||||
|
||||
/**
|
||||
* \brief Calculate the square of the Montgomery constant. (Needed
|
||||
* for conversion and operations in Montgomery form.)
|
||||
*
|
||||
* \param[out] X A pointer to the result of the calculation of
|
||||
* the square of the Montgomery constant:
|
||||
* 2^{2*n*biL} mod N.
|
||||
* \param[in] N Little-endian presentation of the modulus, which must be odd.
|
||||
*
|
||||
* \return 0 if successful.
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if there is not enough space
|
||||
* to store the value of Montgomery constant squared.
|
||||
* \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p N modulus is zero.
|
||||
* \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p N modulus is negative.
|
||||
*/
|
||||
int mbedtls_mpi_core_get_mont_r2_unsafe( mbedtls_mpi *X,
|
||||
const mbedtls_mpi *N );
|
||||
|
||||
#endif /* MBEDTLS_BIGNUM_CORE_H */
|
||||
|
Reference in New Issue
Block a user