From 32f16e8c3074f648dbd317974705ba13b900975c Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Fri, 27 Mar 2020 17:10:07 +0800 Subject: [PATCH] crypto tests: fix mallocs that were missing MALLOC_CAP_8BIT Tests had the potential to fail they got non byte-accessible memory allocated. --- components/mbedtls/test/test_aes.c | 16 ++++++++-------- components/mbedtls/test/test_mbedtls_sha.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/mbedtls/test/test_aes.c b/components/mbedtls/test/test_aes.c index a01f2c0102..aaa2f5f5f6 100644 --- a/components/mbedtls/test/test_aes.c +++ b/components/mbedtls/test/test_aes.c @@ -509,7 +509,7 @@ void aes_psram_ctr_test(uint32_t input_buf_caps, uint32_t output_buf_caps) memset(nonce, 0x2F, 16); memset(key, 0x1E, 16); - // allocate internal memory + // allocate memory according the requested caps uint8_t *chipertext = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, output_buf_caps); uint8_t *plaintext = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, input_buf_caps); uint8_t *decryptedtext = heap_caps_malloc(SZ, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); @@ -558,8 +558,8 @@ void aes_psram_one_buf_ctr_test(void) memset(nonce, 0x2F, 16); memset(key, 0x1E, 16); - // allocate internal memory - uint8_t *buf = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, MALLOC_CAP_SPIRAM); + // allocate external memory + uint8_t *buf = heap_caps_malloc(SZ + ALIGNMENT_SIZE_BYTES, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); TEST_ASSERT_NOT_NULL(buf); @@ -1157,17 +1157,17 @@ void aes_icache_ctr_test(uint32_t output_buf_caps) /* Tests how crypto DMA handles data in external memory */ TEST_CASE("mbedtls AES PSRAM tests", "[aes]") { - aes_psram_ctr_test(MALLOC_CAP_INTERNAL, MALLOC_CAP_SPIRAM); - aes_psram_ctr_test(MALLOC_CAP_SPIRAM, MALLOC_CAP_INTERNAL); - aes_psram_ctr_test(MALLOC_CAP_SPIRAM, MALLOC_CAP_SPIRAM); + aes_psram_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + aes_psram_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + aes_psram_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); aes_psram_one_buf_ctr_test(); } /* Tests how crypto DMA handles data from iCache */ TEST_CASE("mbedtls AES iCache tests", "[aes]") { - aes_icache_ctr_test(MALLOC_CAP_SPIRAM); - aes_icache_ctr_test(MALLOC_CAP_INTERNAL); + aes_icache_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + aes_icache_ctr_test(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); } #endif // CONFIG_SPIRAM_USE_MALLOC diff --git a/components/mbedtls/test/test_mbedtls_sha.c b/components/mbedtls/test/test_mbedtls_sha.c index 2882bf5990..3989d000a4 100644 --- a/components/mbedtls/test/test_mbedtls_sha.c +++ b/components/mbedtls/test/test_mbedtls_sha.c @@ -402,8 +402,8 @@ TEST_CASE("mbedtls SHA256 PSRAM DMA", "[mbedtls]") mbedtls_sha256_context sha256_ctx; unsigned char sha256[32]; - // allocate internal memory - uint8_t *buf = heap_caps_malloc(CALL_SZ, MALLOC_CAP_SPIRAM); + // allocate external memory + uint8_t *buf = heap_caps_malloc(CALL_SZ, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); TEST_ASSERT(esp_ptr_external_ram(buf)); memset(buf, 0x54, CALL_SZ);