mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
Merge branch 'feat/use_common_config_to_sel_crypt_lib_v5.4' into 'release/v5.4'
Feat/use common config to sel crypt lib (v5.4) See merge request espressif/esp-idf!46406
This commit is contained in:
@@ -431,15 +431,6 @@ config BT_LE_LL_CFG_FEAT_LE_ENCRYPTION
|
||||
help
|
||||
Enable encryption connection
|
||||
|
||||
config BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
bool "Override TinyCrypt with mbedTLS for crypto computations"
|
||||
default y
|
||||
depends on !BT_NIMBLE_ENABLED
|
||||
select MBEDTLS_CMAC_C
|
||||
help
|
||||
Enable this option to choose mbedTLS instead of TinyCrypt for crypto
|
||||
computations.
|
||||
|
||||
config BT_LE_WHITELIST_SIZE
|
||||
int "BLE white list size"
|
||||
range 1 31
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -232,10 +232,10 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void);
|
||||
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||
static bool esp_bt_check_wakeup_by_bt(void);
|
||||
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||
#if (CONFIG_BT_CONTROLLER_ONLY) && (CONFIG_BT_LE_SM_SC) && (!CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS)
|
||||
#if (CONFIG_BT_CONTROLLER_ONLY) && (CONFIG_BT_LE_SM_SC) && (!CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS)
|
||||
#include "tinycrypt/ecc.h"
|
||||
static int ecc_rand_func(uint8_t *dst, unsigned int len);
|
||||
#endif // (CONFIG_BT_CONTROLLER_ONLY) && (CONFIG_BT_LE_SM_SC) && (!CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS)
|
||||
#endif // (CONFIG_BT_CONTROLLER_ONLY) && (CONFIG_BT_LE_SM_SC) && (!CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS)
|
||||
/* Local variable definition
|
||||
***************************************************************************
|
||||
*/
|
||||
@@ -1028,9 +1028,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "hci transport init failed %d", ret);
|
||||
goto free_controller;
|
||||
}
|
||||
#if (CONFIG_BT_CONTROLLER_ONLY) && (CONFIG_BT_LE_SM_SC) && (!CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS)
|
||||
#if (CONFIG_BT_CONTROLLER_ONLY) && (CONFIG_BT_LE_SM_SC) && (!CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS)
|
||||
uECC_set_rng(ecc_rand_func);
|
||||
#endif // (CONFIG_BT_CONTROLLER_ONLY) && (CONFIG_BT_LE_SM_SC) && (!CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS)
|
||||
#endif // (CONFIG_BT_CONTROLLER_ONLY) && (CONFIG_BT_LE_SM_SC) && (!CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS)
|
||||
return ESP_OK;
|
||||
free_controller:
|
||||
hci_transport_deinit();
|
||||
@@ -1443,7 +1443,7 @@ uint8_t esp_ble_get_chip_rev_version(void)
|
||||
#if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED)
|
||||
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
||||
#define BLE_SM_KEY_ERR 0x17
|
||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
#include "mbedtls/aes.h"
|
||||
#if CONFIG_BT_LE_SM_SC
|
||||
#include "mbedtls/cipher.h"
|
||||
@@ -1488,7 +1488,7 @@ static int ecc_rand_func(uint8_t *dst, unsigned int len)
|
||||
|
||||
#endif // CONFIG_BT_CONTROLLER_ONLY
|
||||
#endif // CONFIG_BT_LE_SM_SC
|
||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
|
||||
/* Based on Core Specification 4.2 Vol 3. Part H 2.3.5.6.1 */
|
||||
static const uint8_t ble_sm_alg_dbg_priv_key[32] = {
|
||||
@@ -1509,7 +1509,7 @@ int ble_sm_alg_gen_dhkey(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_
|
||||
swap_buf(&pk[32], peer_pub_key_y, 32);
|
||||
swap_buf(priv, our_priv_key, 32);
|
||||
|
||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
struct mbedtls_ecp_point pt = {0}, Q = {0};
|
||||
mbedtls_mpi z = {0}, d = {0};
|
||||
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
||||
@@ -1586,13 +1586,13 @@ exit:
|
||||
if (rc == TC_CRYPTO_FAIL) {
|
||||
return BLE_SM_KEY_ERR;
|
||||
}
|
||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
|
||||
swap_buf(out_dhkey, dh, 32);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
static int mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
|
||||
{
|
||||
int rc = BLE_SM_KEY_ERR;
|
||||
@@ -1637,7 +1637,7 @@ exit:
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
|
||||
/**
|
||||
* pub: 64 bytes
|
||||
@@ -1653,7 +1653,7 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
||||
uint8_t pk[64];
|
||||
|
||||
do {
|
||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
||||
return BLE_SM_KEY_ERR;
|
||||
}
|
||||
@@ -1661,7 +1661,7 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
||||
if (uECC_make_key(pk, priv, uECC_secp256r1()) != TC_CRYPTO_SUCCESS) {
|
||||
return BLE_SM_KEY_ERR;
|
||||
}
|
||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
/* Make sure generated key isn't debug key. */
|
||||
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user