Minor preparatory changes in mbedtls_pk_check_pair()

1. Mark an RSA-alt-specific code path as such.
2. Move NULL check for wrapper function closer to the use of that function.

Those are in preparation of the next commit.
This commit is contained in:
Manuel Pégourié-Gonnard 2019-09-19 10:45:14 +02:00
parent c10f092a87
commit 2d9466f1db

View File

@ -584,24 +584,25 @@ int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_conte
PK_VALIDATE_RET( pub != NULL ); PK_VALIDATE_RET( pub != NULL );
PK_VALIDATE_RET( prv != NULL ); PK_VALIDATE_RET( prv != NULL );
if( pub->pk_info == NULL || if( pub->pk_info == NULL || prv->pk_info == NULL )
prv->pk_info == NULL ||
prv->pk_info->check_pair_func == NULL )
{
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
}
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
if( pk_info_type( prv->pk_info ) == MBEDTLS_PK_RSA_ALT ) if( pk_info_type( prv->pk_info ) == MBEDTLS_PK_RSA_ALT )
{ {
if( pk_info_type( pub->pk_info ) != MBEDTLS_PK_RSA ) if( pk_info_type( pub->pk_info ) != MBEDTLS_PK_RSA )
return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); return( MBEDTLS_ERR_PK_TYPE_MISMATCH );
} }
else else
#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
{ {
if( pub->pk_info != prv->pk_info ) if( pub->pk_info != prv->pk_info )
return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); return( MBEDTLS_ERR_PK_TYPE_MISMATCH );
} }
if( prv->pk_info->check_pair_func == NULL )
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
return( pk_info_check_pair_func( prv->pk_info, pub->pk_ctx, prv->pk_ctx ) ); return( pk_info_check_pair_func( prv->pk_info, pub->pk_ctx, prv->pk_ctx ) );
} }