From 14a00c057845fc914440cc5b30638021ce9b3719 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Wed, 11 Oct 2017 12:58:23 +0100 Subject: [PATCH] Add early detection of bad parameters in `mbedtls_deduce_primes` --- library/rsa_internal.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/rsa_internal.c b/library/rsa_internal.c index 879e2d5d7..4d688e09d 100644 --- a/library/rsa_internal.c +++ b/library/rsa_internal.c @@ -169,6 +169,11 @@ int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, &K, &K ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &K, &K, N ) ); } + + if( mbedtls_mpi_cmp_int( &K, 1 ) != 0 ) + { + break; + } } ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;