Simplify is-zero check

The loop exits early iff there is a nonzero limb, so i==0 means that
all limbs are 0, whether the number of limbs is 0 or not.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-06-17 14:35:25 +02:00
parent 8802b127b5
commit 38a384d2cc

View file

@ -1654,13 +1654,13 @@ int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
for( i = A->n; i > 0; i-- ) for( i = A->n; i > 0; i-- )
if( A->p[i - 1] != 0 ) if( A->p[i - 1] != 0 )
break; break;
if( i == 0 && ( A->n == 0 || A->p[0] == 0 ) ) if( i == 0 )
result_is_zero = 1; result_is_zero = 1;
for( j = B->n; j > 0; j-- ) for( j = B->n; j > 0; j-- )
if( B->p[j - 1] != 0 ) if( B->p[j - 1] != 0 )
break; break;
if( j == 0 && ( B->n == 0 || B->p[0] == 0 ) ) if( j == 0 )
result_is_zero = 1; result_is_zero = 1;
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i + j ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i + j ) );