Skip to content

Commit

Permalink
Merge branch 'fix/aes_ext_mem_case_for_older_targets' into 'master'
Browse files Browse the repository at this point in the history
fix(mbedtls/aes): Check location of the buffer only for SOC_AXI_DMA_EXT_MEM_ENC_ALIGNMENT

Closes IDFCI-2153

See merge request espressif/esp-idf!30850
  • Loading branch information
Harshal5 committed May 16, 2024
2 parents b893e3b + 141cdac commit bb34d78
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions components/mbedtls/port/aes/dma/esp_aes_dma_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ static int esp_aes_process_dma_ext_ram(esp_aes_context *ctx, const unsigned char
size_t chunk_len;
int ret = 0;
int offset = 0;
uint32_t heap_caps = 0;
uint32_t input_heap_caps = MALLOC_CAP_DMA;
uint32_t output_heap_caps = MALLOC_CAP_DMA;
unsigned char *input_buf = NULL;
unsigned char *output_buf = NULL;
const unsigned char *dma_input;
Expand All @@ -223,14 +224,15 @@ static int esp_aes_process_dma_ext_ram(esp_aes_context *ctx, const unsigned char
if (esp_ptr_external_ram(input) || esp_ptr_external_ram(output) || esp_ptr_in_drom(input) || esp_ptr_in_drom(output)) {
input_alignment = MAX(get_cache_line_size(input), SOC_AXI_DMA_EXT_MEM_ENC_ALIGNMENT);
output_alignment = MAX(get_cache_line_size(output), SOC_AXI_DMA_EXT_MEM_ENC_ALIGNMENT);

input_heap_caps = MALLOC_CAP_8BIT | (esp_ptr_external_ram(input) ? MALLOC_CAP_SPIRAM : MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
output_heap_caps = MALLOC_CAP_8BIT | (esp_ptr_external_ram(output) ? MALLOC_CAP_SPIRAM : MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
}
}
#endif /* SOC_AXI_DMA_EXT_MEM_ENC_ALIGNMENT */

if (realloc_input) {
heap_caps = MALLOC_CAP_8BIT | (esp_ptr_external_ram(input) ? MALLOC_CAP_SPIRAM : MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
input_buf = heap_caps_aligned_alloc(input_alignment, chunk_len, heap_caps);

input_buf = heap_caps_aligned_alloc(input_alignment, chunk_len, input_heap_caps);
if (input_buf == NULL) {
mbedtls_platform_zeroize(output, len);
ESP_LOGE(TAG, "Failed to allocate memory");
Expand All @@ -239,9 +241,7 @@ static int esp_aes_process_dma_ext_ram(esp_aes_context *ctx, const unsigned char
}

if (realloc_output) {
heap_caps = MALLOC_CAP_8BIT | (esp_ptr_external_ram(output) ? MALLOC_CAP_SPIRAM : MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
output_buf = heap_caps_aligned_alloc(output_alignment, chunk_len, heap_caps);

output_buf = heap_caps_aligned_alloc(output_alignment, chunk_len, output_heap_caps);
if (output_buf == NULL) {
mbedtls_platform_zeroize(output, len);
ESP_LOGE(TAG, "Failed to allocate memory");
Expand Down

0 comments on commit bb34d78

Please sign in to comment.