From b3b34666575f0a1ac8e828fa5efb12d42ecb4da5 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Wed, 23 Nov 2022 13:17:13 +0100 Subject: [PATCH] Test subtraction if the parameters are aliased to each other Signed-off-by: Gabor Mezei --- .../suites/test_suite_bignum_mod_raw.function | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/suites/test_suite_bignum_mod_raw.function b/tests/suites/test_suite_bignum_mod_raw.function index 256ec9dcb7..2d9e412280 100644 --- a/tests/suites/test_suite_bignum_mod_raw.function +++ b/tests/suites/test_suite_bignum_mod_raw.function @@ -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 );