Correct sign in modular exponentiation algorithm.

The modular exponentiation function  handled the sign incorrectly. This commit fixes this and a test case which should have caught it.
This commit is contained in:
Hanno Becker 2017-04-18 09:07:45 +01:00
parent b65c2be5f1
commit a4af1c47d2
2 changed files with 2 additions and 2 deletions

View file

@ -1790,7 +1790,7 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
*/
MBEDTLS_MPI_CHK( mpi_montred( X, N, mm, &T ) );
if( neg )
if( neg && E->n != 0 && ( E->p[0] & 1 ) != 0 )
{
X->s = -1;
MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( X, N, X ) );