From b0b77e1b13463967ef6cc8f207c18d98048ce3b1 Mon Sep 17 00:00:00 2001 From: Tom Cosgrove Date: Tue, 20 Sep 2022 13:33:40 +0100 Subject: [PATCH] Document and test aliasing of the bignums given to mbedtls_mpi_core_mla() Signed-off-by: Tom Cosgrove --- library/bignum_core.h | 3 +++ tests/suites/test_suite_mpi.function | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/library/bignum_core.h b/library/bignum_core.h index 3a2d5a17aa..2b3b8b6197 100644 --- a/library/bignum_core.h +++ b/library/bignum_core.h @@ -214,6 +214,9 @@ mbedtls_mpi_uint mbedtls_mpi_core_sub( mbedtls_mpi_uint *X, /** * \brief Perform a fixed-size multiply accumulate operation: X += b * A * + * \p X may be aliased to \p A (when \p X_limbs == \p A_limbs), but may not + * otherwise overlap. + * * \param[in,out] X The pointer to the (little-endian) array * representing the bignum to accumulate onto. * \param X_limbs The number of limbs of \p X. This must be diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index bd98a2c0ea..a82c73e810 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -2008,6 +2008,14 @@ void mpi_core_mla( char * input_A, char * input_B, char * input_S, /* 1b) A += B * s => we should get the correct result */ ASSERT_COMPARE( a, bytes, x, bytes ); + if ( A.n == B.n && memcmp( A.p, B.p, bytes ) == 0 ) + { + /* Check when A and B are aliased */ + memcpy( a, A.p, A.n * sizeof(mbedtls_mpi_uint) ); + TEST_EQUAL( mbedtls_mpi_core_mla( a, limbs, a, limbs, *S.p ), *cy->p ); + ASSERT_COMPARE( a, bytes, x, bytes ); + } + exit: mbedtls_free( a ); mbedtls_free( x );