mbedtls_mpi_core_exp_mod() ouuput may alias input A

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
This commit is contained in:
Tom Cosgrove 2022-12-07 13:29:07 +00:00
parent 90af1a10ab
commit a7f0d7b029
2 changed files with 9 additions and 0 deletions

View File

@ -517,6 +517,9 @@ size_t mbedtls_mpi_core_exp_mod_working_limbs( size_t AN_limbs, size_t E_limbs )
* \brief Perform a modular exponentiation with secret exponent:
* X = A^E mod N, where \p A is already in Montgomery form.
*
* \p X may be aliased to \p A, but not to \p RR or \p E, even if \p E_limbs ==
* \p AN_limbs.
*
* \param[out] X The destination MPI, as a little endian array of length
* \p AN_limbs.
* \param[in] A The base MPI, as a little endian array of length \p AN_limbs.

View File

@ -1097,6 +1097,12 @@ void mpi_core_exp_mod( char * input_N, char * input_A,
TEST_EQUAL( 0, memcmp( X, Y, N_limbs * sizeof( mbedtls_mpi_uint ) ) );
/* Check when output aliased to input */
mbedtls_mpi_core_exp_mod( A, A, N, N_limbs, E, E_limbs, R2, T );
TEST_EQUAL( 0, memcmp( X, A, N_limbs * sizeof( mbedtls_mpi_uint ) ) );
exit:
mbedtls_free( T );
mbedtls_free( A );