From 7f4b10b5bd48a7cda4d69d5f16d571b31ba6be1c Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 6 Feb 2018 03:28:23 -0500 Subject: [PATCH] Move RSA_ALT pk_info type check to the respective check_pair function --- library/pk.c | 7 +------ library/pk_wrap.c | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/library/pk.c b/library/pk.c index 4213001e8..bb55a18fb 100644 --- a/library/pk.c +++ b/library/pk.c @@ -329,12 +329,7 @@ int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_conte return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); } - if( prv->pk_info->type == MBEDTLS_PK_RSA_ALT ) - { - if( pub->pk_info->type != MBEDTLS_PK_RSA ) - return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); - } - else if( prv->pk_info->type != MBEDTLS_PK_OPAQUE ) + if( prv->pk_info->type != MBEDTLS_PK_OPAQUE ) { if( pub->pk_info != prv->pk_info ) return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); diff --git a/library/pk_wrap.c b/library/pk_wrap.c index 17df30474..6098ac178 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -486,6 +486,13 @@ static int rsa_alt_check_pair( const mbedtls_pk_context *pub, const void *prv ) unsigned char hash[32]; size_t sig_len = 0; int ret; + const mbedtls_pk_context* prv_context = prv; + + if( prv_context->pk_info->type == MBEDTLS_PK_RSA_ALT ) + { + if( pub->pk_info->type != MBEDTLS_PK_RSA ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + } if( rsa_alt_get_bitlen( prv ) != rsa_get_bitlen( pub->pk_ctx ) ) return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );