Optimize unnecessary zeorizing in mbedtls_mpi_copy

Based on a contribution by Alexey Skalozub
(https://github.com/ARMmbed/mbedtls/pull/405).
This commit is contained in:
Gilles Peskine 2018-03-21 16:29:03 +01:00
parent 70ad839725
commit 4e4be7cf62
2 changed files with 15 additions and 3 deletions

View File

@ -1,5 +1,11 @@
mbed TLS ChangeLog (Sorted per branch, date)
= mbed TLS 2.x.x branch released xxxx-xx-xx
Changes
* Optimize unnecessary zeroing in mbedtls_mpi_copy. Based on a contribution
by Alexey Skalozub.
= mbed TLS 2.7.0 branch released 2018-02-03
Security

View File

@ -184,7 +184,7 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs )
*/
int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y )
{
int ret;
int ret = 0;
size_t i;
if( X == Y )
@ -203,9 +203,15 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y )
X->s = Y->s;
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i ) );
if( X->n < i )
{
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i ) );
}
else
{
memset( X->p + i, 0, ( X->n - i ) * ciL );
}
memset( X->p, 0, X->n * ciL );
memcpy( X->p, Y->p, i * ciL );
cleanup: