Skip to content

Commit 7c9c253

Browse files
committed
Merge branch 'feat/support_both_aes_and_sha_block_and_dma_modes_during_runtime' into 'master'
feat(mbedtls): Support both SHA block and DMA modes during runtime Closes IDF-11848 See merge request espressif/esp-idf!36589
2 parents 5f37de2 + 7d8211b commit 7c9c253

File tree

28 files changed

+456
-1269
lines changed

28 files changed

+456
-1269
lines changed

components/esp-tls/test_apps/main/app_main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
#include "soc/soc_caps.h"
1313
#if SOC_SHA_SUPPORT_PARALLEL_ENG
1414
#include "sha/sha_parallel_engine.h"
15-
#elif SOC_SHA_SUPPORT_DMA
16-
#include "sha/sha_dma.h"
1715
#else
18-
#include "sha/sha_block.h"
16+
#include "sha/sha_core.h"
1917
#endif
2018
#include "esp_newlib.h"
2119

components/esp_tee/scripts/esp32c6/secure_service.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
128 IDF esp_sha_dma 6
3636
129 IDF esp_sha_read_digest_state 2
3737
130 IDF esp_sha_write_digest_state 2
38+
131 IDF esp_sha_block 3
3839
# ID: 168-183 (16) - eFuse
3940
168 IDF esp_efuse_check_secure_version 1
4041
169 IDF esp_efuse_read_field_blob 3

components/esp_tee/src/esp_secure_service_wrapper.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -211,6 +211,11 @@ int __wrap_esp_sha_dma(esp_sha_type sha_type, const void *input, uint32_t ilen,
211211
return esp_tee_service_call(7, SS_ESP_SHA_DMA, sha_type, input, ilen, buf, buf_len, is_first_block);
212212
}
213213

214+
int __wrap_esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_first_block)
215+
{
216+
return esp_tee_service_call(4, SS_ESP_SHA_BLOCK, sha_type, data_block, is_first_block);
217+
}
218+
214219
void __wrap_esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state)
215220
{
216221
esp_tee_service_call(3, SS_ESP_SHA_READ_DIGEST_STATE, sha_type, digest_state);

components/esp_tee/subproject/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ list(APPEND include "${mbedtls_dir}/port/include"
6666
"${mbedtls_dir}/port/aes/include"
6767
"${mbedtls_dir}/port/aes/dma/include")
6868
# SHA
69-
list(APPEND include "${mbedtls_dir}/port/sha/dma/include")
69+
list(APPEND include "${mbedtls_dir}/port/sha/core/include")
7070

7171
# esp_app_desc_t configuration structure for TEE
7272
list(APPEND srcs "common/esp_app_desc_tee.c")

components/esp_tee/subproject/main/core/esp_secure_services.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "soc/soc_caps.h"
2323
#include "aes/esp_aes.h"
24-
#include "sha/sha_dma.h"
24+
#include "sha/sha_core.h"
2525

2626
#include "esp_tee.h"
2727
#include "esp_tee_memory_utils.h"
@@ -314,6 +314,11 @@ void _ss_esp_sha_write_digest_state(esp_sha_type sha_type, void *digest_state)
314314
sha_hal_write_digest(sha_type, digest_state);
315315
}
316316

317+
void _ss_esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_first_block)
318+
{
319+
esp_sha_block(sha_type, data_block, is_first_block);
320+
}
321+
317322
/* ---------------------------------------------- OTA ------------------------------------------------- */
318323

319324
int _ss_esp_tee_ota_begin(void)

components/hal/test_apps/crypto/main/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ if(CONFIG_SOC_SHA_SUPPORTED)
6060

6161
if(CONFIG_SOC_SHA_SUPPORT_DMA)
6262
list(APPEND srcs "sha/sha_dma.c"
63-
"$ENV{IDF_PATH}/components/mbedtls/port/sha/dma/sha.c")
64-
list(APPEND priv_include_dirs "$ENV{IDF_PATH}/components/mbedtls/port/sha/dma/include")
63+
"$ENV{IDF_PATH}/components/mbedtls/port/sha/core/sha.c")
64+
list(APPEND priv_include_dirs "$ENV{IDF_PATH}/components/mbedtls/port/sha/core/include")
6565

6666
if(NOT CONFIG_SOC_SHA_GDMA)
67-
list(APPEND srcs "$ENV{IDF_PATH}/components/mbedtls/port/sha/dma/esp_sha_crypto_dma_impl.c")
67+
list(APPEND srcs "$ENV{IDF_PATH}/components/mbedtls/port/sha/core/esp_sha_crypto_dma_impl.c")
6868
else()
69-
list(APPEND srcs "$ENV{IDF_PATH}/components/mbedtls/port/sha/dma/esp_sha_gdma_impl.c"
69+
list(APPEND srcs "$ENV{IDF_PATH}/components/mbedtls/port/sha/core/esp_sha_gdma_impl.c"
7070
"$ENV{IDF_PATH}/components/mbedtls/port/crypto_shared_gdma/esp_crypto_shared_gdma.c")
7171
endif()
7272
endif()

components/hal/test_apps/crypto/main/sha/sha_dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#if SOC_SHA_SUPPORTED
1818
#if SOC_SHA_SUPPORT_DMA
1919

20-
#include "sha/sha_dma.h"
20+
#include "sha/sha_core.h"
2121
#include "sha_dma.h"
2222

2323
#if defined(SOC_SHA_SUPPORT_SHA1)

components/mbedtls/CMakeLists.txt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,10 @@ endif()
191191
# Choose peripheral type
192192

193193
if(CONFIG_SOC_SHA_SUPPORTED)
194-
if(CONFIG_SOC_SHA_SUPPORT_DMA)
195-
set(SHA_PERIPHERAL_TYPE "dma")
196-
elseif(CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG)
194+
if(CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG)
197195
set(SHA_PERIPHERAL_TYPE "parallel_engine")
198196
else()
199-
set(SHA_PERIPHERAL_TYPE "block")
197+
set(SHA_PERIPHERAL_TYPE "core")
200198
endif()
201199
endif()
202200

@@ -208,15 +206,15 @@ if(CONFIG_SOC_AES_SUPPORTED)
208206
endif()
209207
endif()
210208

211-
if(SHA_PERIPHERAL_TYPE STREQUAL "dma")
212-
target_include_directories(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/sha/dma/include")
209+
if(SHA_PERIPHERAL_TYPE STREQUAL "core")
210+
target_include_directories(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/sha/core/include")
213211

214-
if(NOT CONFIG_SOC_SHA_GDMA)
215-
set(SHA_DMA_SRCS "${COMPONENT_DIR}/port/sha/dma/esp_sha_crypto_dma_impl.c")
216-
else()
217-
set(SHA_DMA_SRCS "${COMPONENT_DIR}/port/sha/dma/esp_sha_gdma_impl.c")
212+
if(CONFIG_SOC_SHA_GDMA)
213+
set(SHA_CORE_SRCS "${COMPONENT_DIR}/port/sha/core/esp_sha_gdma_impl.c")
214+
elseif(CONFIG_SOC_SHA_CRYPTO_DMA)
215+
set(SHA_CORE_SRCS "${COMPONENT_DIR}/port/sha/core/esp_sha_crypto_dma_impl.c")
218216
endif()
219-
target_sources(mbedcrypto PRIVATE "${SHA_DMA_SRCS}")
217+
target_sources(mbedcrypto PRIVATE "${SHA_CORE_SRCS}")
220218
endif()
221219

222220
if(AES_PERIPHERAL_TYPE STREQUAL "dma")
@@ -232,7 +230,7 @@ if(AES_PERIPHERAL_TYPE STREQUAL "dma")
232230
target_sources(mbedcrypto PRIVATE "${AES_DMA_SRCS}")
233231
endif()
234232

235-
if(SHA_PERIPHERAL_TYPE STREQUAL "dma" OR AES_PERIPHERAL_TYPE STREQUAL "dma")
233+
if((SHA_PERIPHERAL_TYPE STREQUAL "core" AND CONFIG_SOC_SHA_SUPPORT_DMA) OR AES_PERIPHERAL_TYPE STREQUAL "dma")
236234
target_link_libraries(mbedcrypto PRIVATE idf::esp_mm)
237235
if(CONFIG_SOC_SHA_GDMA OR CONFIG_SOC_AES_GDMA)
238236
if(CONFIG_SOC_AXI_DMA_EXT_MEM_ENC_ALIGNMENT)

components/mbedtls/esp_tee/esp_tee_mbedtls.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ list(APPEND srcs "${hal_dir}/aes_hal.c"
1515

1616
list(APPEND include_dirs "${COMPONENT_DIR}/port/aes/include"
1717
"${COMPONENT_DIR}/port/aes/dma/include"
18-
"${COMPONENT_DIR}/port/sha/dma/include")
18+
"${COMPONENT_DIR}/port/sha/core/include")
1919

2020
list(APPEND srcs "${COMPONENT_DIR}/port/aes/esp_aes_common.c"
2121
"${COMPONENT_DIR}/port/aes/dma/esp_aes.c"
2222
"${COMPONENT_DIR}/port/aes/dma/esp_aes_dma_core.c")
2323

24-
list(APPEND srcs "${COMPONENT_DIR}/port/sha/dma/sha.c"
24+
list(APPEND srcs "${COMPONENT_DIR}/port/sha/core/sha.c"
2525
"${COMPONENT_DIR}/port/sha/esp_sha.c")
2626

2727
# Supporting headers
@@ -54,8 +54,8 @@ endforeach()
5454
target_link_libraries(${COMPONENT_LIB} INTERFACE ${mbedtls_targets})
5555

5656
if(CONFIG_MBEDTLS_HARDWARE_SHA)
57-
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/sha/dma/esp_sha1.c"
58-
"${COMPONENT_DIR}/port/sha/dma/esp_sha256.c"
59-
"${COMPONENT_DIR}/port/sha/dma/esp_sha512.c"
57+
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/sha/core/esp_sha1.c"
58+
"${COMPONENT_DIR}/port/sha/core/esp_sha256.c"
59+
"${COMPONENT_DIR}/port/sha/core/esp_sha512.c"
6060
)
6161
endif()
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
// Copyright 2019-2020 Espressif Systems (Shanghai) PTE LTD
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
146

157
#pragma once
168

17-
#include "sha/sha_dma.h"
9+
#include "sha/sha_core.h"
1810

19-
#warning esp32s2/sha.h is deprecated, please use sha/sha_dma.h instead
11+
#warning esp32s2/sha.h is deprecated, please use sha/sha_core.h instead

0 commit comments

Comments
 (0)