Check exactly for the RSA context fields required in rsa_private
Previously, the code was also checking for the presence of D for RSA-CRT, which
is not needed in this case.
diff --git a/library/rsa.c b/library/rsa.c
index 11ba201..d866c7a 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -447,14 +447,19 @@
/* Sanity-check that all relevant fields are at least set,
* but don't perform a full keycheck. */
+#if defined(MBEDTLS_RSA_NO_CRT)
if( mbedtls_mpi_cmp_int( &ctx->N, 0 ) == 0 ||
mbedtls_mpi_cmp_int( &ctx->D, 0 ) == 0 ||
- mbedtls_mpi_cmp_int( &ctx->E, 0 ) == 0 )
+ mbedtls_mpi_cmp_int( &ctx->E, 0 ) == 0 ||
+ mbedtls_mpi_cmp_int( &ctx->P, 0 ) == 0 ||
+ mbedtls_mpi_cmp_int( &ctx->Q, 0 ) == 0 )
{
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
}
-#if !defined(MBEDTLS_RSA_NO_CRT)
- if( mbedtls_mpi_cmp_int( &ctx->P, 0 ) == 0 ||
+#else /* ! MBEDTLS_RSA_NO_CRT */
+ if( mbedtls_mpi_cmp_int( &ctx->N, 0 ) == 0 ||
+ mbedtls_mpi_cmp_int( &ctx->E, 0 ) == 0 ||
+ mbedtls_mpi_cmp_int( &ctx->P, 0 ) == 0 ||
mbedtls_mpi_cmp_int( &ctx->Q, 0 ) == 0 ||
mbedtls_mpi_cmp_int( &ctx->DP, 0 ) == 0 ||
mbedtls_mpi_cmp_int( &ctx->DQ, 0 ) == 0 ||
@@ -462,7 +467,7 @@
{
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
}
-#endif /* MBEDTLS_RSA_NO_CRT */
+#endif /* ! MBEDTLS_RSA_NO_CRT */
#if defined(MBEDTLS_THREADING_C)
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )