1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

mbedtls_mpi_mod_read/write: restrict pre-conditions

Require equality for the number of limbs in the modulus and the residue.
This makes these functions consistent with residue_setup().

Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
Janos Follath
2022-11-26 14:59:27 +00:00
parent 75b9f0fd2e
commit d7bb35257b
2 changed files with 17 additions and 5 deletions

View File

@ -207,7 +207,7 @@ int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
/* Do our best to check if r and m have been set up */
if ( r->limbs == 0 || m->limbs == 0 )
goto cleanup;
if ( r->limbs > m->limbs )
if ( r->limbs != m->limbs )
goto cleanup;
ret = mbedtls_mpi_mod_raw_read( r->p, m, buf, buflen, ext_rep );
@ -235,7 +235,7 @@ int mbedtls_mpi_mod_write( const mbedtls_mpi_mod_residue *r,
/* Do our best to check if r and m have been set up */
if ( r->limbs == 0 || m->limbs == 0 )
goto cleanup;
if ( r->limbs > m->limbs )
if ( r->limbs != m->limbs )
goto cleanup;
if ( m->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY)