From b69757ab619cc807d1e0132f98aedacc9d12bcac Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 29 Apr 2024 12:38:16 +0200 Subject: [PATCH] Fix a compilation warning in pk.c when PSA is enabled and RSA is disabled It isn't detected on the CI because we only test this with an ancient Clang that doesn't warn. Old GCC, modern GCC and modern Clang do warn (-Wunused-but-set-variable). Signed-off-by: Gilles Peskine --- ChangeLog.d/pk-norsa-warning.txt | 2 ++ library/pk.c | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 ChangeLog.d/pk-norsa-warning.txt diff --git a/ChangeLog.d/pk-norsa-warning.txt b/ChangeLog.d/pk-norsa-warning.txt new file mode 100644 index 000000000..d00aa8a87 --- /dev/null +++ b/ChangeLog.d/pk-norsa-warning.txt @@ -0,0 +1,2 @@ +Bugfix + * Fix a compilation warning in pk.c when PSA is enabled and RSA is disabled. diff --git a/library/pk.c b/library/pk.c index e33a2434b..3fe51ea34 100644 --- a/library/pk.c +++ b/library/pk.c @@ -868,7 +868,6 @@ static int copy_from_psa(mbedtls_svc_key_id_t key_id, psa_status_t status; psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; psa_key_type_t key_type; - psa_algorithm_t alg_type; size_t key_bits; /* Use a buffer size large enough to contain either a key pair or public key. */ unsigned char exp_key[PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE]; @@ -899,7 +898,6 @@ static int copy_from_psa(mbedtls_svc_key_id_t key_id, key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type); } key_bits = psa_get_key_bits(&key_attr); - alg_type = psa_get_key_algorithm(&key_attr); #if defined(MBEDTLS_RSA_C) if ((key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) || @@ -919,6 +917,7 @@ static int copy_from_psa(mbedtls_svc_key_id_t key_id, goto exit; } + psa_algorithm_t alg_type = psa_get_key_algorithm(&key_attr); mbedtls_md_type_t md_type = MBEDTLS_MD_NONE; if (PSA_ALG_GET_HASH(alg_type) != PSA_ALG_ANY_HASH) { md_type = mbedtls_md_type_from_psa_alg(alg_type);