Guard new changes with MBEDTLS_VERSION_MAJOR >= 4

Since these changes reference psa_key_agreement() which doesn't exist in
3.6, guard them with MBEDTLS_VERSION_MAJOR >= 4.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann
2024-11-19 17:06:03 +00:00
parent de5f965ebe
commit 56ecabe532
+11 -2
View File
@@ -694,15 +694,18 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
uint8_t output[1024];
size_t output_length;
#if MBEDTLS_VERSION_MAJOR >= 4
uint8_t *exported = NULL;
size_t exported_size = 0;
size_t exported_length = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t export_attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_svc_key_id_t shared_secret_id = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_attributes_t shared_secret_attributes = PSA_KEY_ATTRIBUTES_INIT;
#endif /* MBEDTLS_VERSION_MAJOR >= 4 */
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status = psa_get_key_attributes(key, &attributes);
if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE) {
@@ -743,6 +746,7 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE);
}
#if MBEDTLS_VERSION_MAJOR >= 4
psa_set_key_type(&shared_secret_attributes, PSA_KEY_TYPE_DERIVE);
psa_set_key_usage_flags(&shared_secret_attributes, PSA_KEY_USAGE_DERIVE | PSA_KEY_USAGE_EXPORT);
@@ -775,6 +779,7 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
PSA_ASSERT(status);
}
#endif /* MBEDTLS_VERSION_MAJOR >= 4 */
exit:
/*
@@ -782,14 +787,18 @@ exit:
* thus reset them as required.
*/
psa_reset_key_attributes(&attributes);
#if MBEDTLS_VERSION_MAJOR >= 4
psa_reset_key_attributes(&export_attributes);
/* Make sure to reset and free derived key attributes and slot. */
psa_reset_key_attributes(&shared_secret_attributes);
psa_destroy_key(shared_secret_id);
mbedtls_free(public_key);
mbedtls_free(exported);
#endif /* MBEDTLS_VERSION_MAJOR >= 4 */
mbedtls_free(public_key);
return status;
}