Test subtraction if the parameters are aliased to each other

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
Gabor Mezei 2022-11-23 13:17:13 +01:00
parent 4d3f3c5430
commit b3b3466657
No known key found for this signature in database
GPG Key ID: FEE76C0CF8C6267D

View File

@ -314,9 +314,29 @@ void mpi_mod_raw_sub( char * input_A,
MBEDTLS_MPI_MOD_REP_MONTGOMERY ), 0 );
mbedtls_mpi_mod_raw_sub( X, A, B, &m );
ASSERT_COMPARE( X, bytes, res, bytes );
/* alias X to A */
memcpy( X, A, bytes );
mbedtls_mpi_mod_raw_sub( X, X, B, &m );
ASSERT_COMPARE( X, bytes, res, bytes );
/* alias X to B */
memcpy( X, B, bytes );
mbedtls_mpi_mod_raw_sub( X, A, X, &m );
ASSERT_COMPARE( X, bytes, res, bytes );
/* A == B: alias A and B */
if( memcmp( A, B, bytes ) == 0 )
{
mbedtls_mpi_mod_raw_sub( X, A, A, &m );
ASSERT_COMPARE( X, bytes, res, bytes );
/* X, A, B all aliased together */
memcpy( X, A, bytes );
mbedtls_mpi_mod_raw_sub( X, X, X, &m );
ASSERT_COMPARE( X, bytes, res, bytes );
}
exit:
mbedtls_free( A );
mbedtls_free( B );