Parcourir la source

mbedtls: Don't compile hardware MPI & SHA files if disabled in config

Fixes bug where hardware accelerated mbedtls_mpi API was always used, even when
disabled in config.
Angus Gratton il y a 5 ans
Parent
commit
40c9f0599c
2 fichiers modifiés avec 25 ajouts et 9 suppressions
  1. 18 9
      components/mbedtls/CMakeLists.txt
  2. 7 0
      components/mbedtls/component.mk

+ 18 - 9
components/mbedtls/CMakeLists.txt

@@ -27,15 +27,24 @@ target_sources(mbedtls PRIVATE  "${COMPONENT_DIR}/port/mbedtls_debug.c"
                                 "${COMPONENT_DIR}/port/net_sockets.c")
 
 target_sources(mbedcrypto PRIVATE "${COMPONENT_DIR}/port/esp_hardware.c"
-                                "${COMPONENT_DIR}/port/esp_mem.c"
-                                "${COMPONENT_DIR}/port/esp_sha.c"
-                                "${COMPONENT_DIR}/port/esp_sha1.c"
-                                "${COMPONENT_DIR}/port/esp_sha256.c"
-                                "${COMPONENT_DIR}/port/esp_sha512.c"
-                                "${COMPONENT_DIR}/port/esp_timing.c"
-                                "${COMPONENT_DIR}/port/${idf_target}/esp_bignum.c"
-                                "${COMPONENT_DIR}/port/${idf_target}/aes.c"
-                                "${COMPONENT_DIR}/port/${idf_target}/sha.c")
+                                  "${COMPONENT_DIR}/port/esp_mem.c"
+                                  "${COMPONENT_DIR}/port/esp_timing.c"
+                                  "${COMPONENT_DIR}/port/esp_sha.c"
+                                  "${COMPONENT_DIR}/port/${idf_target}/aes.c"
+)
+
+if(CONFIG_MBEDTLS_HARDWARE_MPI)
+    target_sources(mbedcrypto PRIVATE  "${COMPONENT_DIR}/port/${idf_target}/esp_bignum.c"
+    )
+endif()
+
+if(CONFIG_MBEDTLS_HARDWARE_SHA)
+    target_sources(mbedcrypto PRIVATE  "${COMPONENT_DIR}/port/esp_sha1.c"
+                                       "${COMPONENT_DIR}/port/esp_sha256.c"
+                                       "${COMPONENT_DIR}/port/esp_sha512.c"
+                                       "${COMPONENT_DIR}/port/${idf_target}/sha.c"
+    )
+endif()
 
 foreach(target ${mbedtls_targets})
     target_compile_definitions(${target} PUBLIC -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h")

+ 7 - 0
components/mbedtls/component.mk

@@ -10,3 +10,10 @@ COMPONENT_OBJEXCLUDE := mbedtls/library/net_sockets.o
 
 COMPONENT_SUBMODULES += mbedtls
 
+ifndef CONFIG_MBEDTLS_HARDWARE_MPI
+    COMPONENT_OBJEXCLUDE += port/$(IDF_TARGET)/esp_bignum.o
+endif
+
+ifndef CONFIG_MBEDTLS_HARDWARE_SHA
+    COMPONENT_OBJEXCLUDE += port/esp_sha1.o port/esp_sha256.o port/esp_sha512.o port/$(IDF_TARGET)/sha.o
+endif