fix(mbedtls): misc updates post PSA crypto migration

This commit is contained in:
Mahavir Jain
2026-01-05 14:54:33 +05:30
parent e41ecaabf2
commit 1f0ce0524c
7 changed files with 122 additions and 56 deletions
+24 -27
View File
@@ -213,31 +213,30 @@ endforeach()
list(APPEND mbedtls_targets everest p256m)
set(mbedtls_target_sources "${COMPONENT_DIR}/port/mbedtls_debug.c"
"${COMPONENT_DIR}/port/esp_platform_time.c")
"${COMPONENT_DIR}/port/esp_platform_time.c"
"${COMPONENT_DIR}/port/esp_timing.c")
if(CONFIG_MBEDTLS_VER_4_X_SUPPORT)
list(APPEND mbedtls_target_sources "${COMPONENT_DIR}/port/esp_psa_crypto_init.c")
# Add ESP-IDF NVS-based PSA ITS implementation
# Only compile esp_psa_its.c if nvs_flash component is available
if(NOT ${IDF_TARGET} STREQUAL "linux")
if(IDF_BUILD_V2)
# For v2: conditionally compile source and link only if nvs_flash target exists
target_sources(
tfpsacrypto PRIVATE
"$<$<TARGET_EXISTS:idf::nvs_flash>:${COMPONENT_DIR}/port/psa_crypto_storage/esp_psa_its.c>"
)
target_link_libraries(tfpsacrypto PRIVATE "$<$<TARGET_EXISTS:idf::nvs_flash>:idf::nvs_flash>")
# Define compile definition to indicate ESP-IDF PSA ITS implementation is available
target_compile_definitions(tfpsacrypto PRIVATE "$<$<TARGET_EXISTS:idf::nvs_flash>:ESP_PSA_ITS_AVAILABLE>")
else()
# For v1: check if component is in build before adding source and linking
idf_build_get_property(build_components BUILD_COMPONENTS)
if(nvs_flash IN_LIST build_components)
target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/psa_crypto_storage/esp_psa_its.c")
idf_component_get_property(nvs_flash_lib nvs_flash COMPONENT_LIB)
target_link_libraries(tfpsacrypto PRIVATE ${nvs_flash_lib})
target_compile_definitions(tfpsacrypto PRIVATE ESP_PSA_ITS_AVAILABLE)
endif()
list(APPEND mbedtls_target_sources "${COMPONENT_DIR}/port/esp_psa_crypto_init.c")
# Add ESP-IDF NVS-based PSA ITS implementation
# Only compile esp_psa_its.c if nvs_flash component is available
if(NOT ${IDF_TARGET} STREQUAL "linux")
if(IDF_BUILD_V2)
# For v2: conditionally compile source and link only if nvs_flash target exists
target_sources(
tfpsacrypto PRIVATE
"$<$<TARGET_EXISTS:idf::nvs_flash>:${COMPONENT_DIR}/port/psa_crypto_storage/esp_psa_its.c>"
)
target_link_libraries(tfpsacrypto PRIVATE "$<$<TARGET_EXISTS:idf::nvs_flash>:idf::nvs_flash>")
# Define compile definition to indicate ESP-IDF PSA ITS implementation is available
target_compile_definitions(tfpsacrypto PRIVATE "$<$<TARGET_EXISTS:idf::nvs_flash>:ESP_PSA_ITS_AVAILABLE>")
else()
# For v1: check if component is in build before adding source and linking
idf_build_get_property(build_components BUILD_COMPONENTS)
if(nvs_flash IN_LIST build_components)
target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/psa_crypto_storage/esp_psa_its.c")
idf_component_get_property(nvs_flash_lib nvs_flash COMPONENT_LIB)
target_link_libraries(tfpsacrypto PRIVATE ${nvs_flash_lib})
target_compile_definitions(tfpsacrypto PRIVATE ESP_PSA_ITS_AVAILABLE)
endif()
endif()
endif()
@@ -337,9 +336,7 @@ endif()
if(NOT ${IDF_TARGET} STREQUAL "linux")
target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/esp_hardware.c")
endif()
target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/esp_mem.c"
# "${COMPONENT_DIR}/port/esp_timing.c"
)
target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/esp_mem.c")
if(CONFIG_SOC_AES_SUPPORTED)
target_include_directories(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/aes/include")
@@ -100,7 +100,6 @@ TEST_CASE("PSA CMAC AES-128 test", "[psa_cmac]")
// Cleanup
psa_destroy_key(key_id);
free(cmac);
// mbedtls_psa_crypto_free();
}
TEST_CASE("PSA CMAC AES-256 test", "[psa_cmac]")
@@ -144,7 +143,6 @@ TEST_CASE("PSA CMAC AES-256 test", "[psa_cmac]")
// Cleanup
psa_destroy_key(key_id);
free(cmac);
// mbedtls_psa_crypto_free();
}
TEST_CASE("PSA CMAC AES-128 multipart test", "[psa_cmac]")
@@ -197,7 +195,6 @@ TEST_CASE("PSA CMAC AES-128 multipart test", "[psa_cmac]")
// Cleanup
psa_destroy_key(key_id);
free(cmac);
// mbedtls_psa_crypto_free();
}
TEST_CASE("PSA CMAC AES-128 multipart verify test", "[psa_cmac]")
@@ -257,7 +254,6 @@ TEST_CASE("PSA CMAC AES-128 multipart verify test", "[psa_cmac]")
// Cleanup
psa_destroy_key(key_id);
free(cmac);
// mbedtls_psa_crypto_free();
}
TEST_CASE("PSA CMAC zero-length test", "[psa_cmac]")
@@ -301,7 +297,6 @@ TEST_CASE("PSA CMAC zero-length test", "[psa_cmac]")
// Cleanup
psa_destroy_key(key_id);
free(cmac);
// mbedtls_psa_crypto_free();
}
TEST_CASE("PSA CMAC memory alignment test", "[psa_cmac]")
@@ -355,7 +350,6 @@ TEST_CASE("PSA CMAC memory alignment test", "[psa_cmac]")
psa_destroy_key(key_id);
free(cmac_internal);
free(cmac_dma);
// mbedtls_psa_crypto_free();
}
TEST_CASE("PSA CMAC verify failure test", "[psa_cmac]")
@@ -393,6 +387,5 @@ TEST_CASE("PSA CMAC verify failure test", "[psa_cmac]")
// Cleanup
psa_destroy_key(key_id);
// mbedtls_psa_crypto_free();
}
#endif /* CONFIG_MBEDTLS_CMAC_C */
@@ -129,7 +129,6 @@ TEST_CASE("PSA ARIA-GCM multipart", "[psa-gcm]")
/* Destroy the key */
psa_destroy_key(key_id);
// mbedtls_psa_crypto_free();
}
TEST_CASE("PSA ARIA-GCM one-shot", "[psa-gcm]")
@@ -206,5 +205,4 @@ TEST_CASE("PSA ARIA-GCM one-shot", "[psa-gcm]")
/* Destroy the key */
psa_destroy_key(key_id);
// mbedtls_psa_crypto_free();
}