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.
This commit is contained in:
Hanno Becker 2017-09-29 15:19:28 +01:00
parent a6f5539413
commit 2fdffe0da0

View file

@ -447,14 +447,19 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
/* 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 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
{
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 )