diff --git a/library/psa_crypto.c b/library/psa_crypto.c index b1555631e..7ea614f45 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1424,12 +1424,11 @@ static psa_status_t psa_hmac_setup_internal( psa_hmac_internal_data *hmac, if( block_size == 0 ) return( PSA_ERROR_NOT_SUPPORTED ); - status = psa_hash_setup( &hmac->hash_ctx, hash_alg ); - if( status != PSA_SUCCESS ) - return( status ); - if( key_length > block_size ) { + status = psa_hash_setup( &hmac->hash_ctx, hash_alg ); + if( status != PSA_SUCCESS ) + goto cleanup; status = psa_hash_update( &hmac->hash_ctx, key, key_length ); if( status != PSA_SUCCESS ) goto cleanup;