Merge pull request #3028 from gilles-peskine-arm/mpi_copy_shrink-2.7
Backport 2.7: Improve robustness and testing of mbedtls_mpi_copy
This commit is contained in:
commit
6cf5931f1d
3 changed files with 161 additions and 34 deletions
|
@ -151,9 +151,10 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs )
|
|||
mbedtls_mpi_uint *p;
|
||||
size_t i;
|
||||
|
||||
/* Actually resize up in this case */
|
||||
/* Actually resize up if there are currently fewer than nblimbs limbs. */
|
||||
if( X->n <= nblimbs )
|
||||
return( mbedtls_mpi_grow( X, nblimbs ) );
|
||||
/* After this point, then X->n > nblimbs and in particular X->n > 0. */
|
||||
|
||||
for( i = X->n - 1; i > 0; i-- )
|
||||
if( X->p[i] != 0 )
|
||||
|
@ -190,7 +191,7 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y )
|
|||
if( X == Y )
|
||||
return( 0 );
|
||||
|
||||
if( Y->p == NULL )
|
||||
if( Y->n == 0 )
|
||||
{
|
||||
mbedtls_mpi_free( X );
|
||||
return( 0 );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue