feat(ble_mesh): fixed issues where the incorrect node oob private setting

This commit is contained in:
luoxu
2025-12-26 15:46:56 +08:00
parent b8571b1358
commit 8a600bbeeb
6 changed files with 16 additions and 7 deletions
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -67,9 +67,9 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers);
* So as an unprovisioned device, it should use this function to input
* the Public Key exchanged through the out-of-band mechanism.
*
* @param[in] pub_key_x: Unprovisioned device's Public Key X
* @param[in] pub_key_y: Unprovisioned device's Public Key Y
* @param[in] private_key: Unprovisioned device's Private Key
* @param[in] pub_key_x: Unprovisioned device's Public Key X(Little Endian)
* @param[in] pub_key_y: Unprovisioned device's Public Key Y(Little Endian)
* @param[in] private_key: Unprovisioned device's Private Key(Little Endian)
*
* @return ESP_OK on success or error code otherwise.
*/
@@ -335,6 +335,8 @@ void bt_mesh_set_private_key_raw(const uint8_t pri_key[32])
goto cleanup;
}
BT_DBG("Pubkey:%s", bt_hex(dh_pair.public_key, PUB_KEY_SIZE));
BT_DBG("Privkey:%s", bt_hex(dh_pair.private_key, PRIV_KEY_SIZE));
dh_pair.is_ready = true;
cleanup:
@@ -392,6 +392,8 @@ void bt_mesh_set_private_key_raw(const uint8_t pri_key[32])
return;
}
BT_DBG("Pubkey:%s", bt_hex(&dh_pair.public_key[1], PUB_KEY_SIZE));
BT_DBG("Privkey:%s", bt_hex(pri_key, PRIV_KEY_SIZE));
dh_pair.is_ready = true;
psa_reset_key_attributes(&attributes);
}
@@ -236,6 +236,8 @@ void bt_mesh_set_private_key_raw(const uint8_t pri_key[32])
return;
}
BT_DBG("Pubkey:%s", bt_hex(dh_pair.public_key, PUB_KEY_SIZE));
BT_DBG("Privkey:%s", bt_hex(dh_pair.private_key, PRIV_KEY_SIZE));
dh_pair.is_ready = true;
}
@@ -345,11 +345,11 @@ int bt_mesh_pub_key_gen(void);
*
* @return 0 on success, -EAGAIN if public key not ready
*/
static inline int bt_mesh_pub_key_copy(uint8_t buf[64])
static inline int bt_mesh_pub_key_copy(uint8_t *buf)
{
const uint8_t *key = bt_mesh_pub_key_get_raw();
if (key == NULL) {
if (key == NULL || buf == NULL) {
return -EAGAIN;
}
+4 -1
View File
@@ -703,6 +703,8 @@ int bt_mesh_set_oob_pub_key(const uint8_t pub_key_x[32],
const uint8_t pub_key_y[32],
const uint8_t pri_key[32])
{
uint8_t privkey[32] = {0};
if (!pub_key_x || !pub_key_y || !pri_key) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
@@ -714,7 +716,8 @@ int bt_mesh_set_oob_pub_key(const uint8_t pub_key_x[32],
*/
sys_memcpy_swap(&prov_link.conf_inputs[81], pub_key_x, 32);
sys_memcpy_swap(&prov_link.conf_inputs[81] + 32, pub_key_y, 32);
bt_mesh_set_private_key(pri_key);
sys_memcpy_swap(privkey, pri_key, 32);
bt_mesh_set_private_key(privkey);
bt_mesh_atomic_set_bit(prov_link.flags, OOB_PUB_KEY);