diff --git a/library/x509_crt.c b/library/x509_crt.c index e18dbe777e..ae9cc22538 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -2108,6 +2108,11 @@ static int x509_crt_check_signature(const mbedtls_x509_crt *child, psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(child->sig_md); psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; + /* Skip expensive computation on obvious mismatch */ + if (!mbedtls_pk_can_do(&parent->pk, (mbedtls_pk_type_t) child->sig_pk)) { + return -1; + } + status = psa_hash_compute(hash_alg, child->tbs.p, child->tbs.len, @@ -2118,11 +2123,6 @@ static int x509_crt_check_signature(const mbedtls_x509_crt *child, return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED; } - /* Skip expensive computation on obvious mismatch */ - if (!mbedtls_pk_can_do(&parent->pk, (mbedtls_pk_type_t) child->sig_pk)) { - return -1; - } - #if defined(MBEDTLS_ECP_RESTARTABLE) if (rs_ctx != NULL && child->sig_pk == MBEDTLS_PK_SIGALG_ECDSA) { return mbedtls_pk_verify_restartable(&parent->pk,