From b85c05d556dff88e785a575514c13b17eab947c6 Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Thu, 20 Aug 2026 18:19:11 +0530 Subject: [PATCH] test(mbedtls): fix in-place AES-CTR PSRAM test on targets without AES hardware With MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS enabled, an in-place psa_cipher_update() reaches the selected cipher implementation without defensive buffer copies. The ESP AES PSA driver accepts an in-place update of any length for CTR (PSA classifies CTR as a stream cipher, so the driver's block_length is 1), but on targets without the AES peripheral (e.g. ESP32-C61) the operation falls back to the mbedtls builtin cipher layer, which rejects in-place updates whose length is not a multiple of the block size (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, surfacing as PSA_ERROR_INVALID_ARGUMENT). Round the in-place test length down to a block multiple when CONFIG_MBEDTLS_HARDWARE_AES is not set; partial-block PSRAM coverage is retained through the separate-buffer alignment tests. --- components/mbedtls/test_apps/mbedtls_ut/main/test_psa_aes.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/mbedtls/test_apps/mbedtls_ut/main/test_psa_aes.c b/components/mbedtls/test_apps/mbedtls_ut/main/test_psa_aes.c index c980dcbc171..6d413f33d62 100644 --- a/components/mbedtls/test_apps/mbedtls_ut/main/test_psa_aes.c +++ b/components/mbedtls/test_apps/mbedtls_ut/main/test_psa_aes.c @@ -1952,7 +1952,11 @@ void aes_psram_one_buf_ctr_test(void) uint8_t nonce[16]; uint8_t key[16]; psa_status_t status; +#if CONFIG_MBEDTLS_HARDWARE_AES size_t SZ = TEST_AES_CTR_DATA_LEN; +#else + size_t SZ = TEST_AES_CTR_DATA_LEN - (TEST_AES_CTR_DATA_LEN % 16); +#endif size_t ALIGNMENT_SIZE_BYTES = 32; memset(nonce, 0x2F, 16); memset(key, 0x1E, 16);