Merge branch 'bugfix/ble_mesh_prov_use_diff_rand' into 'master'

ble_mesh: stack: Use different random for each prov

See merge request espressif/esp-idf!9494
This commit is contained in:
Island 2021-01-20 16:35:47 +08:00
commit 5cd5c96dc8

View File

@ -100,6 +100,7 @@ _Static_assert(BLE_MESH_MAX_CONN >= CONFIG_BLE_MESH_PBG_SAME_TIME,
#define PROV_CONF_KEY_SIZE 0x10 #define PROV_CONF_KEY_SIZE 0x10
#define PROV_DH_KEY_SIZE 0x20 #define PROV_DH_KEY_SIZE 0x20
#define PROV_CONFIRM_SIZE 0x10 #define PROV_CONFIRM_SIZE 0x10
#define PROV_RANDOM_SIZE 0x10
#define PROV_PROV_SALT_SIZE 0x10 #define PROV_PROV_SALT_SIZE 0x10
#define PROV_CONF_INPUTS_SIZE 0x91 #define PROV_CONF_INPUTS_SIZE 0x91
@ -219,12 +220,6 @@ struct bt_mesh_prov_ctx {
/* Provisioning bearers used by Provisioner */ /* Provisioning bearers used by Provisioner */
bt_mesh_prov_bearer_t bearers; bt_mesh_prov_bearer_t bearers;
/* If provisioning random have been generated, set BIT0 to 1 */
uint8_t rand_gen_done;
/* Provisioner random */
uint8_t random[16];
/* Current number of PB-ADV provisioned devices simultaneously */ /* Current number of PB-ADV provisioned devices simultaneously */
uint8_t pba_count; uint8_t pba_count;
@ -1256,6 +1251,7 @@ static void prov_memory_free(const uint8_t idx)
{ {
PROV_FREE_MEM(idx, dhkey); PROV_FREE_MEM(idx, dhkey);
PROV_FREE_MEM(idx, auth); PROV_FREE_MEM(idx, auth);
PROV_FREE_MEM(idx, rand);
PROV_FREE_MEM(idx, conf); PROV_FREE_MEM(idx, conf);
PROV_FREE_MEM(idx, conf_salt); PROV_FREE_MEM(idx, conf_salt);
PROV_FREE_MEM(idx, conf_key); PROV_FREE_MEM(idx, conf_key);
@ -2005,20 +2001,15 @@ static void send_confirm(const uint8_t idx)
BT_DBG("ConfirmationKey: %s", bt_hex(link[idx].conf_key, 16)); BT_DBG("ConfirmationKey: %s", bt_hex(link[idx].conf_key, 16));
/** Provisioner use the same random number for each provisioning link[idx].rand = bt_mesh_calloc(PROV_RANDOM_SIZE);
* device, if different random need to be used, here provisioner if (!link[idx].rand) {
* should allocate memory for rand and call bt_mesh_rand() every time. BT_ERR("%s, Out of memory", __func__);
*/ goto fail;
if (!(prov_ctx.rand_gen_done & BIT(0))) { }
if (bt_mesh_rand(prov_ctx.random, 16)) {
BT_ERR("Failed to generate random number"); if (bt_mesh_rand(link[idx].rand, PROV_RANDOM_SIZE)) {
goto fail; BT_ERR("Failed to generate random number");
} goto fail;
link[idx].rand = prov_ctx.random;
prov_ctx.rand_gen_done |= BIT(0);
} else {
/* Provisioner random has already been generated. */
link[idx].rand = prov_ctx.random;
} }
BT_DBG("LocalRandom: %s", bt_hex(link[idx].rand, 16)); BT_DBG("LocalRandom: %s", bt_hex(link[idx].rand, 16));