mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Align Montgomery init with development
The signature and naming of the Montgomrey initialisation function in development and in the LTS was different. Align them for easier readability and maintenance. Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
committed by
Dave Rodgman
parent
f10bfbbe74
commit
8cdb6064de
@ -1907,19 +1907,17 @@ int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_s
|
||||
/*
|
||||
* Fast Montgomery initialization (thanks to Tom St Denis)
|
||||
*/
|
||||
void mbedtls_mpi_montg_init(mbedtls_mpi_uint *mm, const mbedtls_mpi *N)
|
||||
mbedtls_mpi_uint mbedtls_mpi_montmul_init(const mbedtls_mpi_uint *N)
|
||||
{
|
||||
mbedtls_mpi_uint x, m0 = N->p[0];
|
||||
unsigned int i;
|
||||
mbedtls_mpi_uint x = N[0];
|
||||
|
||||
x = m0;
|
||||
x += ((m0 + 2) & 4) << 1;
|
||||
x += ((N[0] + 2) & 4) << 1;
|
||||
|
||||
for (i = biL; i >= 8; i /= 2) {
|
||||
x *= (2 - (m0 * x));
|
||||
for (unsigned int i = biL; i >= 8; i /= 2) {
|
||||
x *= (2 - (N[0] * x));
|
||||
}
|
||||
|
||||
*mm = ~x + 1;
|
||||
return ~x + 1;
|
||||
}
|
||||
|
||||
void mbedtls_mpi_montmul(mbedtls_mpi *A,
|
||||
@ -2069,7 +2067,7 @@ int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
/*
|
||||
* Init temps and window size
|
||||
*/
|
||||
mbedtls_mpi_montg_init(&mm, N);
|
||||
mm = mbedtls_mpi_montmul_init(N->p);
|
||||
mbedtls_mpi_init(&RR); mbedtls_mpi_init(&T);
|
||||
mbedtls_mpi_init(&Apos);
|
||||
mbedtls_mpi_init(&WW);
|
||||
|
@ -30,14 +30,14 @@ int mbedtls_mpi_get_mont_r2_unsafe(mbedtls_mpi *X,
|
||||
|
||||
/**
|
||||
* \brief Calculate initialisation value for fast Montgomery modular
|
||||
* multiplication.
|
||||
* multiplication
|
||||
*
|
||||
* \param[out] mm The initialisation value for fast Montgomery modular
|
||||
* multiplication.
|
||||
* \param[in] N Little-endian presentation of the modulus. This must have
|
||||
* at least one limb.
|
||||
*
|
||||
* \return The initialisation value for fast Montgomery modular multiplication
|
||||
*/
|
||||
void mbedtls_mpi_montg_init(mbedtls_mpi_uint *mm, const mbedtls_mpi *N);
|
||||
mbedtls_mpi_uint mbedtls_mpi_montmul_init(const mbedtls_mpi_uint *N);
|
||||
|
||||
/** Montgomery multiplication: A = A * B * R^-1 mod N (HAC 14.36)
|
||||
*
|
||||
|
@ -815,8 +815,7 @@ static int rsa_unblind(mbedtls_mpi *T, mbedtls_mpi *Vf, const mbedtls_mpi *N)
|
||||
const size_t nlimbs = N->n;
|
||||
const size_t tlimbs = 2 * (nlimbs + 1);
|
||||
|
||||
mbedtls_mpi_uint mm;
|
||||
mbedtls_mpi_montg_init(&mm, N);
|
||||
mbedtls_mpi_uint mm = mbedtls_mpi_montmul_init(N->p);
|
||||
|
||||
mbedtls_mpi RR, M_T;
|
||||
|
||||
|
Reference in New Issue
Block a user