mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
change(bt): use BT_SMP_CRYPTO_STACK_MBEDTLS to select bt cryption lib
This commit is contained in:
@@ -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
|
||||
*/
|
||||
@@ -1481,7 +1481,7 @@ void esp_ble_controller_log_dump_all(bool output)
|
||||
#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"
|
||||
@@ -1503,7 +1503,7 @@ static mbedtls_ecp_keypair keypair;
|
||||
#include "tinycrypt/cmac_mode.h"
|
||||
#include "tinycrypt/ecc_dh.h"
|
||||
#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] = {
|
||||
@@ -1524,7 +1524,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};
|
||||
@@ -1601,13 +1601,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;
|
||||
@@ -1652,7 +1652,7 @@ exit:
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif // CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
#endif // CONFIG_BT_SMP_CRYPTO_STACK_MBEDTLS
|
||||
|
||||
/**
|
||||
* pub: 64 bytes
|
||||
@@ -1668,7 +1668,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;
|
||||
}
|
||||
@@ -1676,7 +1676,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) {
|
||||
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