Skip to content

Commit 7e0e2f3

Browse files
committed
Merge branch 'bugfix/mbedtls_disable_sha_mpi' into 'master'
mbedtls: Don't compile hardware MPI & SHA files if disabled in config See merge request espressif/esp-idf!8823
2 parents ea78d06 + 94f5129 commit 7e0e2f3

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

components/mbedtls/CMakeLists.txt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,35 @@ endif()
8181
# Add port files to mbedtls targets
8282
target_sources(mbedtls PRIVATE ${mbedtls_target_sources})
8383

84+
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_hardware.c"
85+
"${COMPONENT_DIR}/port/esp_mem.c"
86+
"${COMPONENT_DIR}/port/esp_timing.c"
87+
"${COMPONENT_DIR}/port/esp_sha.c"
88+
"${COMPONENT_DIR}/port/esp_aes_xts.c"
89+
"${COMPONENT_DIR}/port/${idf_target}/aes.c"
90+
"${COMPONENT_DIR}/port/${idf_target}/sha.c"
91+
)
92+
93+
# Note: some mbedTLS hardware acceleration can be enabled/disabled by config.
94+
#
95+
# We don't need to filter aes.c as this uses a different prefix (esp_aes_x) and the
96+
# config option only changes the prefixes in the header so mbedtls_aes_x compiles to esp_aes_x
97+
#
98+
# The other port-specific files don't override internal mbedTLS functions, they just add new functions.
99+
100+
if(CONFIG_MBEDTLS_HARDWARE_MPI)
101+
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_bignum.c"
102+
"${COMPONENT_DIR}/port/${idf_target}/bignum.c"
103+
)
104+
endif()
84105

106+
if(CONFIG_MBEDTLS_HARDWARE_SHA)
107+
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/${idf_target}/esp_sha1.c"
108+
"${COMPONENT_DIR}/port/${idf_target}/esp_sha256.c"
109+
"${COMPONENT_DIR}/port/${idf_target}/esp_sha512.c"
110+
)
111+
endif()
85112

86-
target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_hardware.c"
87-
"${COMPONENT_DIR}/port/esp_mem.c"
88-
"${COMPONENT_DIR}/port/esp_timing.c"
89-
"${COMPONENT_DIR}/port/esp_sha.c"
90-
"${COMPONENT_DIR}/port/esp_bignum.c"
91-
"${COMPONENT_DIR}/port/esp_aes_xts.c"
92-
"${COMPONENT_DIR}/port/${idf_target}/bignum.c"
93-
"${COMPONENT_DIR}/port/${idf_target}/aes.c"
94-
"${COMPONENT_DIR}/port/${idf_target}/sha.c"
95-
"${COMPONENT_DIR}/port/${idf_target}/esp_sha1.c"
96-
"${COMPONENT_DIR}/port/${idf_target}/esp_sha256.c"
97-
"${COMPONENT_DIR}/port/${idf_target}/esp_sha512.c")
98113

99114
foreach(target ${mbedtls_targets})
100115
target_compile_definitions(${target} PUBLIC -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h")

components/mbedtls/component.mk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ COMPONENT_OBJEXCLUDE := mbedtls/library/net_sockets.o
1010

1111
COMPONENT_SUBMODULES += mbedtls
1212

13+
# Note: some mbedTLS hardware acceleration can be enabled/disabled by config.
14+
#
15+
# We don't need to exclude aes.o as these functions use a different prefix (esp_aes_x) and the
16+
# config option only changes the prefixes in the header so mbedtls_aes_x compiles to esp_aes_x
17+
#
18+
# The other port-specific files don't override internal mbedTLS functions, they just add new functions.
19+
20+
ifndef CONFIG_MBEDTLS_HARDWARE_MPI
21+
COMPONENT_OBJEXCLUDE += port/esp_bignum.o port/$(IDF_TARGET)/bignum.o
22+
endif
23+
24+
ifndef CONFIG_MBEDTLS_HARDWARE_SHA
25+
COMPONENT_OBJEXCLUDE += port/$(IDF_TARGET)/esp_sha1.o port/$(IDF_TARGET)/esp_sha256.o port/$(IDF_TARGET)/esp_sha512.o
26+
endif
1327

1428
ifdef CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
1529

0 commit comments

Comments
 (0)