From 5f743900e79282ac6d6c82d52e7c6261a974a0a6 Mon Sep 17 00:00:00 2001 From: luoxu Date: Wed, 2 Apr 2025 19:23:28 +0800 Subject: [PATCH] feat(ble_mesh): unify tinycrypto component --- components/bt/CMakeLists.txt | 40 ++++++++++++++++----------- components/bt/esp_ble_mesh/Kconfig.in | 8 ++++++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index a5a0742f3d..9b3a577afa 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -29,7 +29,6 @@ set(common_include_dirs set(ble_mesh_include_dirs "esp_ble_mesh/common/include" - "esp_ble_mesh/common/tinycrypt/include" "esp_ble_mesh/core" "esp_ble_mesh/core/include" "esp_ble_mesh/core/storage" @@ -42,6 +41,10 @@ set(ble_mesh_include_dirs "esp_ble_mesh/api" ) +set(ble_mesh_tinycrypt_dirs + "esp_ble_mesh/common/tinycrypt/include" +) + set(ble_mesh_v11_include_dirs "esp_ble_mesh/lib/include" "esp_ble_mesh/v1.1/api/core/include" @@ -500,21 +503,6 @@ if(CONFIG_BT_ENABLED) "esp_ble_mesh/btc/btc_ble_mesh_prov.c" "esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c" "esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c" - "esp_ble_mesh/common/tinycrypt/src/aes_decrypt.c" - "esp_ble_mesh/common/tinycrypt/src/aes_encrypt.c" - "esp_ble_mesh/common/tinycrypt/src/cbc_mode.c" - "esp_ble_mesh/common/tinycrypt/src/ccm_mode.c" - "esp_ble_mesh/common/tinycrypt/src/cmac_mode.c" - "esp_ble_mesh/common/tinycrypt/src/ctr_mode.c" - "esp_ble_mesh/common/tinycrypt/src/ctr_prng.c" - "esp_ble_mesh/common/tinycrypt/src/ecc_dh.c" - "esp_ble_mesh/common/tinycrypt/src/ecc_dsa.c" - "esp_ble_mesh/common/tinycrypt/src/ecc_platform_specific.c" - "esp_ble_mesh/common/tinycrypt/src/ecc.c" - "esp_ble_mesh/common/tinycrypt/src/hmac_prng.c" - "esp_ble_mesh/common/tinycrypt/src/hmac.c" - "esp_ble_mesh/common/tinycrypt/src/sha256.c" - "esp_ble_mesh/common/tinycrypt/src/utils.c" "esp_ble_mesh/common/atomic.c" "esp_ble_mesh/common/buf.c" "esp_ble_mesh/common/common.c" @@ -565,6 +553,26 @@ if(CONFIG_BT_ENABLED) "esp_ble_mesh/models/server/state_binding.c" "esp_ble_mesh/models/server/state_transition.c" "esp_ble_mesh/models/server/time_scene_server.c") + + if(NOT CONFIG_BLE_MESH_USE_UNIFIED_CRYPTO) + list(APPEND include_dirs ${ble_mesh_tinycrypt_dirs}) + list(APPEND srcs + "esp_ble_mesh/common/tinycrypt/src/aes_decrypt.c" + "esp_ble_mesh/common/tinycrypt/src/aes_encrypt.c" + "esp_ble_mesh/common/tinycrypt/src/cbc_mode.c" + "esp_ble_mesh/common/tinycrypt/src/ccm_mode.c" + "esp_ble_mesh/common/tinycrypt/src/cmac_mode.c" + "esp_ble_mesh/common/tinycrypt/src/ctr_mode.c" + "esp_ble_mesh/common/tinycrypt/src/ctr_prng.c" + "esp_ble_mesh/common/tinycrypt/src/ecc_dh.c" + "esp_ble_mesh/common/tinycrypt/src/ecc_dsa.c" + "esp_ble_mesh/common/tinycrypt/src/ecc_platform_specific.c" + "esp_ble_mesh/common/tinycrypt/src/ecc.c" + "esp_ble_mesh/common/tinycrypt/src/hmac_prng.c" + "esp_ble_mesh/common/tinycrypt/src/hmac.c" + "esp_ble_mesh/common/tinycrypt/src/sha256.c" + "esp_ble_mesh/common/tinycrypt/src/utils.c") + endif() if(CONFIG_BLE_MESH_V11_SUPPORT) list(APPEND include_dirs ${ble_mesh_v11_include_dirs}) diff --git a/components/bt/esp_ble_mesh/Kconfig.in b/components/bt/esp_ble_mesh/Kconfig.in index e805231edc..6d6c138746 100644 --- a/components/bt/esp_ble_mesh/Kconfig.in +++ b/components/bt/esp_ble_mesh/Kconfig.in @@ -22,6 +22,14 @@ if BLE_MESH for mesh packets. And this could help avoid collision of advertising packets. + config BLE_MESH_USE_UNIFIED_CRYPTO + bool "Use the unified BLE tinycrypt implementation" + depends on !BT_LE_CRYPTO_STACK_MBEDTLS && !BT_NIMBLE_CRYPTO_STACK_MBEDTLS + default n + help + Enable this option to use the unified BLE tinycrypt solution + instead of the default one in BLE Mesh stack. + menuconfig BLE_MESH_USE_BLE_50 bool "Support using BLE 5.0 APIs for BLE Mesh" depends on BLE_MESH_EXPERIMENTAL