mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Reduce the size of mbedtls_mpi
Reduce the size of mbedtls_mpi from 3 words to 2 on most architectures. This also reduces the code size significantly in bignum.o and ecp_curves.o, with negligible variations in other modules. This removes the ability to set MBEDTLS_MPI_MAX_LIMBS to a value >=65536, but we don't support customizing this value anyway (it's always 10000). Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@ -114,7 +114,9 @@ int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs)
|
||||
mbedtls_free(X->p);
|
||||
}
|
||||
|
||||
X->n = nblimbs;
|
||||
/* nblimbs fits in n because we ensure that MBEDTLS_MPI_MAX_LIMBS
|
||||
* fits, and we've checked that nblimbs <= MBEDTLS_MPI_MAX_LIMBS. */
|
||||
X->n = (unsigned short) nblimbs;
|
||||
X->p = p;
|
||||
}
|
||||
|
||||
@ -162,7 +164,9 @@ int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs)
|
||||
mbedtls_free(X->p);
|
||||
}
|
||||
|
||||
X->n = i;
|
||||
/* i fits in n because we ensure that MBEDTLS_MPI_MAX_LIMBS
|
||||
* fits, and we've checked that i <= nblimbs <= MBEDTLS_MPI_MAX_LIMBS. */
|
||||
X->n = (unsigned short) i;
|
||||
X->p = p;
|
||||
|
||||
return 0;
|
||||
@ -1574,8 +1578,8 @@ static void mpi_montred(mbedtls_mpi *A, const mbedtls_mpi *N,
|
||||
{
|
||||
mbedtls_mpi_uint z = 1;
|
||||
mbedtls_mpi U;
|
||||
|
||||
U.n = U.s = (int) z;
|
||||
U.n = 1;
|
||||
U.s = 1;
|
||||
U.p = &z;
|
||||
|
||||
mpi_montmul(A, &U, N, mm, T);
|
||||
|
Reference in New Issue
Block a user