mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
change(bt): use BT_SMP_CRYPTO_STACK_MBEDTLS to select bt cryption lib
This commit is contained in:
@@ -747,8 +747,7 @@ if(CONFIG_BT_ENABLED)
|
|||||||
# 1. Controller uses TinyCrypt (not mbedTLS), OR
|
# 1. Controller uses TinyCrypt (not mbedTLS), OR
|
||||||
# 2. NimBLE uses TinyCrypt (not mbedTLS), OR
|
# 2. NimBLE uses TinyCrypt (not mbedTLS), OR
|
||||||
# 3. Bluedroid Host SMP uses TinyCrypt
|
# 3. Bluedroid Host SMP uses TinyCrypt
|
||||||
if(CONFIG_BT_SMP_CRYPTO_STACK_TINYCRYPT OR
|
if(CONFIG_BT_SMP_CRYPTO_STACK_TINYCRYPT OR NOT CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS)
|
||||||
(NOT CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS AND NOT CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS))
|
|
||||||
list(APPEND include_dirs
|
list(APPEND include_dirs
|
||||||
common/tinycrypt/include
|
common/tinycrypt/include
|
||||||
common/tinycrypt/port
|
common/tinycrypt/port
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ config BT_ALARM_MAX_NUM
|
|||||||
|
|
||||||
choice BT_SMP_CRYPTO_STACK
|
choice BT_SMP_CRYPTO_STACK
|
||||||
prompt "SMP cryptographic stack"
|
prompt "SMP cryptographic stack"
|
||||||
depends on (BT_BLE_SMP_ENABLE || BT_SMP_ENABLE || BT_NIMBLE_SECURITY_ENABLE)
|
depends on (BT_BLE_SMP_ENABLE || BT_SMP_ENABLE || BT_NIMBLE_SECURITY_ENABLE || BT_LE_SECURITY_ENABLE)
|
||||||
default BT_SMP_CRYPTO_STACK_NATIVE
|
default BT_SMP_CRYPTO_STACK_TINYCRYPT
|
||||||
help
|
help
|
||||||
Select the cryptographic library to use for SMP operations (AES, AES-CMAC, ECDH P-256).
|
Select the cryptographic library to use for SMP operations (AES, AES-CMAC, ECDH P-256).
|
||||||
|
|
||||||
|
|||||||
@@ -431,15 +431,6 @@ config BT_LE_LL_CFG_FEAT_LE_ENCRYPTION
|
|||||||
help
|
help
|
||||||
Enable encryption connection
|
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
|
config BT_LE_WHITELIST_SIZE
|
||||||
int "BLE white list size"
|
int "BLE white list size"
|
||||||
range 1 31
|
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
|
* 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
|
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||||
static bool esp_bt_check_wakeup_by_bt(void);
|
static bool esp_bt_check_wakeup_by_bt(void);
|
||||||
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
#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"
|
#include "tinycrypt/ecc.h"
|
||||||
static int ecc_rand_func(uint8_t *dst, unsigned int len);
|
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
|
/* 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);
|
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "hci transport init failed %d", ret);
|
||||||
goto free_controller;
|
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);
|
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;
|
return ESP_OK;
|
||||||
free_controller:
|
free_controller:
|
||||||
hci_transport_deinit();
|
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_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED)
|
||||||
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
||||||
#define BLE_SM_KEY_ERR 0x17
|
#define BLE_SM_KEY_ERR 0x17
|
||||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
#if CONFIG_BT_LE_SM_SC
|
#if CONFIG_BT_LE_SM_SC
|
||||||
#include "mbedtls/cipher.h"
|
#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_CONTROLLER_ONLY
|
||||||
#endif // CONFIG_BT_LE_SM_SC
|
#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 */
|
/* 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] = {
|
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(&pk[32], peer_pub_key_y, 32);
|
||||||
swap_buf(priv, our_priv_key, 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};
|
struct mbedtls_ecp_point pt = {0}, Q = {0};
|
||||||
mbedtls_mpi z = {0}, d = {0};
|
mbedtls_mpi z = {0}, d = {0};
|
||||||
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
||||||
@@ -1586,13 +1586,13 @@ exit:
|
|||||||
if (rc == TC_CRYPTO_FAIL) {
|
if (rc == TC_CRYPTO_FAIL) {
|
||||||
return BLE_SM_KEY_ERR;
|
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);
|
swap_buf(out_dhkey, dh, 32);
|
||||||
return 0;
|
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)
|
static int mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
|
||||||
{
|
{
|
||||||
int rc = BLE_SM_KEY_ERR;
|
int rc = BLE_SM_KEY_ERR;
|
||||||
@@ -1637,7 +1637,7 @@ exit:
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pub: 64 bytes
|
* pub: 64 bytes
|
||||||
@@ -1653,7 +1653,7 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
|||||||
uint8_t pk[64];
|
uint8_t pk[64];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
||||||
return BLE_SM_KEY_ERR;
|
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) {
|
if (uECC_make_key(pk, priv, uECC_secp256r1()) != TC_CRYPTO_SUCCESS) {
|
||||||
return BLE_SM_KEY_ERR;
|
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. */
|
/* Make sure generated key isn't debug key. */
|
||||||
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
||||||
|
|
||||||
|
|||||||
@@ -375,15 +375,6 @@ config BT_LE_LL_CFG_FEAT_LE_ENCRYPTION
|
|||||||
help
|
help
|
||||||
Enable encryption connection
|
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
|
config BT_LE_WHITELIST_SIZE
|
||||||
int "BLE white list size"
|
int "BLE white list size"
|
||||||
range 1 15
|
range 1 15
|
||||||
|
|||||||
@@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -1355,7 +1355,7 @@ void esp_ble_controller_log_dump_all(bool output)
|
|||||||
#if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED)
|
#if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED)
|
||||||
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
||||||
#define BLE_SM_KEY_ERR 0x17
|
#define BLE_SM_KEY_ERR 0x17
|
||||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
#if CONFIG_BT_LE_SM_SC
|
#if CONFIG_BT_LE_SM_SC
|
||||||
#include "mbedtls/cipher.h"
|
#include "mbedtls/cipher.h"
|
||||||
@@ -1377,7 +1377,7 @@ static mbedtls_ecp_keypair keypair;
|
|||||||
#include "tinycrypt/cmac_mode.h"
|
#include "tinycrypt/cmac_mode.h"
|
||||||
#include "tinycrypt/ecc_dh.h"
|
#include "tinycrypt/ecc_dh.h"
|
||||||
#endif // CONFIG_BT_LE_SM_SC
|
#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 */
|
/* 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] = {
|
static const uint8_t ble_sm_alg_dbg_priv_key[32] = {
|
||||||
@@ -1398,7 +1398,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(&pk[32], peer_pub_key_y, 32);
|
||||||
swap_buf(priv, our_priv_key, 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};
|
struct mbedtls_ecp_point pt = {0}, Q = {0};
|
||||||
mbedtls_mpi z = {0}, d = {0};
|
mbedtls_mpi z = {0}, d = {0};
|
||||||
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
||||||
@@ -1475,13 +1475,13 @@ exit:
|
|||||||
if (rc == TC_CRYPTO_FAIL) {
|
if (rc == TC_CRYPTO_FAIL) {
|
||||||
return BLE_SM_KEY_ERR;
|
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);
|
swap_buf(out_dhkey, dh, 32);
|
||||||
return 0;
|
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)
|
static int mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
|
||||||
{
|
{
|
||||||
int rc = BLE_SM_KEY_ERR;
|
int rc = BLE_SM_KEY_ERR;
|
||||||
@@ -1526,7 +1526,7 @@ exit:
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pub: 64 bytes
|
* pub: 64 bytes
|
||||||
@@ -1542,7 +1542,7 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
|||||||
uint8_t pk[64];
|
uint8_t pk[64];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
||||||
return BLE_SM_KEY_ERR;
|
return BLE_SM_KEY_ERR;
|
||||||
}
|
}
|
||||||
@@ -1550,7 +1550,7 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
|||||||
if (uECC_make_key(pk, priv, &curve_secp256r1) != TC_CRYPTO_SUCCESS) {
|
if (uECC_make_key(pk, priv, &curve_secp256r1) != TC_CRYPTO_SUCCESS) {
|
||||||
return BLE_SM_KEY_ERR;
|
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. */
|
/* Make sure generated key isn't debug key. */
|
||||||
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
||||||
|
|
||||||
|
|||||||
@@ -532,15 +532,6 @@ config BT_LE_LL_CFG_FEAT_LE_ENCRYPTION
|
|||||||
help
|
help
|
||||||
Enable encryption connection
|
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
|
config BT_LE_WHITELIST_SIZE
|
||||||
int "BLE white list size"
|
int "BLE white list size"
|
||||||
range 1 31
|
range 1 31
|
||||||
|
|||||||
@@ -240,10 +240,10 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void);
|
|||||||
static bool esp_bt_check_wakeup_by_bt(void);
|
static bool esp_bt_check_wakeup_by_bt(void);
|
||||||
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
#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"
|
#include "tinycrypt/ecc.h"
|
||||||
static int ecc_rand_func(uint8_t *dst, unsigned int len);
|
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
|
/* Local variable definition
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -1211,9 +1211,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
|||||||
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "Controller lib version mismatch!");
|
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "Controller lib version mismatch!");
|
||||||
}
|
}
|
||||||
|
|
||||||
#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);
|
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;
|
return ESP_OK;
|
||||||
free_controller:
|
free_controller:
|
||||||
hci_transport_deinit();
|
hci_transport_deinit();
|
||||||
@@ -1665,7 +1665,7 @@ void esp_ble_controller_log_dump_all(bool output)
|
|||||||
#if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED)
|
#if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED)
|
||||||
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
||||||
#define BLE_SM_KEY_ERR 0x17
|
#define BLE_SM_KEY_ERR 0x17
|
||||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
#if CONFIG_BT_LE_SM_SC
|
#if CONFIG_BT_LE_SM_SC
|
||||||
#include "mbedtls/cipher.h"
|
#include "mbedtls/cipher.h"
|
||||||
@@ -1708,7 +1708,7 @@ static int ecc_rand_func(uint8_t *dst, unsigned int len)
|
|||||||
}
|
}
|
||||||
#endif // CONFIG_BT_CONTROLLER_ONLY
|
#endif // CONFIG_BT_CONTROLLER_ONLY
|
||||||
#endif // CONFIG_BT_LE_SM_SC
|
#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 */
|
/* 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] = {
|
static const uint8_t ble_sm_alg_dbg_priv_key[32] = {
|
||||||
@@ -1729,7 +1729,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(&pk[32], peer_pub_key_y, 32);
|
||||||
swap_buf(priv, our_priv_key, 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};
|
struct mbedtls_ecp_point pt = {0}, Q = {0};
|
||||||
mbedtls_mpi z = {0}, d = {0};
|
mbedtls_mpi z = {0}, d = {0};
|
||||||
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
||||||
@@ -1806,13 +1806,13 @@ exit:
|
|||||||
if (rc == TC_CRYPTO_FAIL) {
|
if (rc == TC_CRYPTO_FAIL) {
|
||||||
return BLE_SM_KEY_ERR;
|
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);
|
swap_buf(out_dhkey, dh, 32);
|
||||||
return 0;
|
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)
|
static int mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
|
||||||
{
|
{
|
||||||
int rc = BLE_SM_KEY_ERR;
|
int rc = BLE_SM_KEY_ERR;
|
||||||
@@ -1857,7 +1857,7 @@ exit:
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pub: 64 bytes
|
* pub: 64 bytes
|
||||||
@@ -1873,7 +1873,7 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
|||||||
uint8_t pk[64];
|
uint8_t pk[64];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
||||||
return BLE_SM_KEY_ERR;
|
return BLE_SM_KEY_ERR;
|
||||||
}
|
}
|
||||||
@@ -1881,7 +1881,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) {
|
if (uECC_make_key(pk, priv, uECC_secp256r1()) != TC_CRYPTO_SUCCESS) {
|
||||||
return BLE_SM_KEY_ERR;
|
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. */
|
/* Make sure generated key isn't debug key. */
|
||||||
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
||||||
|
|
||||||
|
|||||||
@@ -526,15 +526,6 @@ config BT_LE_LL_CFG_FEAT_LE_ENCRYPTION
|
|||||||
help
|
help
|
||||||
Enable encryption connection
|
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
|
config BT_LE_WHITELIST_SIZE
|
||||||
int "BLE white list size"
|
int "BLE white list size"
|
||||||
range 1 31
|
range 1 31
|
||||||
|
|||||||
@@ -229,10 +229,10 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void);
|
|||||||
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||||
static bool esp_bt_check_wakeup_by_bt(void);
|
static bool esp_bt_check_wakeup_by_bt(void);
|
||||||
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
#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"
|
#include "tinycrypt/ecc.h"
|
||||||
static int ecc_rand_func(uint8_t *dst, unsigned int len);
|
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
|
/* Local variable definition
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -1164,9 +1164,9 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
|||||||
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "Controller lib version mismatch!");
|
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "Controller lib version mismatch!");
|
||||||
}
|
}
|
||||||
|
|
||||||
#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);
|
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;
|
return ESP_OK;
|
||||||
free_controller:
|
free_controller:
|
||||||
hci_transport_deinit();
|
hci_transport_deinit();
|
||||||
@@ -1616,7 +1616,7 @@ void esp_ble_controller_log_dump_all(bool output)
|
|||||||
#if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED)
|
#if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED)
|
||||||
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
#if CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC
|
||||||
#define BLE_SM_KEY_ERR 0x17
|
#define BLE_SM_KEY_ERR 0x17
|
||||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
#if CONFIG_BT_LE_SM_SC
|
#if CONFIG_BT_LE_SM_SC
|
||||||
#include "mbedtls/cipher.h"
|
#include "mbedtls/cipher.h"
|
||||||
@@ -1659,7 +1659,7 @@ static int ecc_rand_func(uint8_t *dst, unsigned int len)
|
|||||||
}
|
}
|
||||||
#endif // CONFIG_BT_CONTROLLER_ONLY
|
#endif // CONFIG_BT_CONTROLLER_ONLY
|
||||||
#endif // CONFIG_BT_LE_SM_SC
|
#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 */
|
/* 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] = {
|
static const uint8_t ble_sm_alg_dbg_priv_key[32] = {
|
||||||
@@ -1680,7 +1680,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(&pk[32], peer_pub_key_y, 32);
|
||||||
swap_buf(priv, our_priv_key, 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};
|
struct mbedtls_ecp_point pt = {0}, Q = {0};
|
||||||
mbedtls_mpi z = {0}, d = {0};
|
mbedtls_mpi z = {0}, d = {0};
|
||||||
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
mbedtls_ctr_drbg_context ctr_drbg = {0};
|
||||||
@@ -1757,13 +1757,13 @@ exit:
|
|||||||
if (rc == TC_CRYPTO_FAIL) {
|
if (rc == TC_CRYPTO_FAIL) {
|
||||||
return BLE_SM_KEY_ERR;
|
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);
|
swap_buf(out_dhkey, dh, 32);
|
||||||
return 0;
|
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)
|
static int mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
|
||||||
{
|
{
|
||||||
int rc = BLE_SM_KEY_ERR;
|
int rc = BLE_SM_KEY_ERR;
|
||||||
@@ -1808,7 +1808,7 @@ exit:
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pub: 64 bytes
|
* pub: 64 bytes
|
||||||
@@ -1824,7 +1824,7 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
|||||||
uint8_t pk[64];
|
uint8_t pk[64];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
#if CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
#if CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||||
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
||||||
return BLE_SM_KEY_ERR;
|
return BLE_SM_KEY_ERR;
|
||||||
}
|
}
|
||||||
@@ -1832,7 +1832,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) {
|
if (uECC_make_key(pk, priv, uECC_secp256r1()) != TC_CRYPTO_SUCCESS) {
|
||||||
return BLE_SM_KEY_ERR;
|
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. */
|
/* Make sure generated key isn't debug key. */
|
||||||
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ if BLE_MESH
|
|||||||
|
|
||||||
config BLE_MESH_USE_UNIFIED_CRYPTO
|
config BLE_MESH_USE_UNIFIED_CRYPTO
|
||||||
bool "Use the unified BLE tinycrypt implementation"
|
bool "Use the unified BLE tinycrypt implementation"
|
||||||
depends on !BT_LE_CRYPTO_STACK_MBEDTLS && !BT_NIMBLE_CRYPTO_STACK_MBEDTLS
|
depends on !BT_NIMBLE_CRYPTO_STACK_MBEDTLS
|
||||||
default y if BT_SMP_CRYPTO_STACK_TINYCRYPT
|
default y if BT_SMP_CRYPTO_STACK_TINYCRYPT
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
|
|||||||
Reference in New Issue
Block a user