Add early detection of bad parameters in `mbedtls_deduce_primes`
diff --git a/library/rsa_internal.c b/library/rsa_internal.c
index 879e2d5..4d688e0 100644
--- a/library/rsa_internal.c
+++ b/library/rsa_internal.c
@@ -169,6 +169,11 @@
             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;