ble_mesh: Not using pre-initialized private key
This commit is contained in:
parent
c3d33f4232
commit
0c06be9bcd
4 changed files with 25 additions and 21 deletions
|
@ -46,12 +46,7 @@ struct bt_mesh_dev bt_mesh_dev;
|
|||
|
||||
/* P-256 Variables */
|
||||
static u8_t bt_mesh_public_key[64];
|
||||
static BT_OCTET32 bt_mesh_private_key = {
|
||||
0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38,
|
||||
0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50,
|
||||
0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99,
|
||||
0x58, 0x99, 0xb8, 0xa6, 0xcd, 0x3c, 0x1a, 0xbd
|
||||
};
|
||||
static BT_OCTET32 bt_mesh_private_key;
|
||||
|
||||
/* Scan related functions */
|
||||
static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb;
|
||||
|
@ -102,11 +97,6 @@ int bt_mesh_host_init(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_host_deinit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bt_mesh_hci_init(void)
|
||||
{
|
||||
const uint8_t *features = controller_get_interface()->get_features_ble()->as_array;
|
||||
|
@ -1797,8 +1787,17 @@ void bt_mesh_gatt_deinit(void)
|
|||
void bt_mesh_adapt_init(void)
|
||||
{
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* initialization of P-256 parameters */
|
||||
p_256_init_curve(KEY_LENGTH_DWORDS_P256);
|
||||
|
||||
/* Set "bt_mesh_dev.flags" to 0 (only the "BLE_MESH_DEV_HAS_PUB_KEY"
|
||||
* flag is used) here, because we need to make sure each time after
|
||||
* the private key is initialized, a corresponding public key must
|
||||
* be generated.
|
||||
*/
|
||||
bt_mesh_atomic_set(bt_mesh_dev.flags, 0);
|
||||
bt_mesh_rand(bt_mesh_private_key, sizeof(bt_mesh_private_key));
|
||||
}
|
||||
|
||||
int bt_mesh_rand(void *buf, size_t len)
|
||||
|
@ -1854,7 +1853,8 @@ const u8_t *bt_mesh_pub_key_get(void)
|
|||
memcpy(bt_mesh_public_key + BT_OCTET32_LEN, public_key.y, BT_OCTET32_LEN);
|
||||
|
||||
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY);
|
||||
BT_DBG("gen the bt_mesh_public_key:%s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key)));
|
||||
|
||||
BT_DBG("Public Key %s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key)));
|
||||
|
||||
return bt_mesh_public_key;
|
||||
}
|
||||
|
|
|
@ -665,7 +665,6 @@ struct bt_mesh_gatt_attr {
|
|||
}
|
||||
|
||||
int bt_mesh_host_init(void);
|
||||
int bt_mesh_host_deinit(void);
|
||||
|
||||
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
|
|
|
@ -63,12 +63,7 @@ struct bt_mesh_dev bt_mesh_dev;
|
|||
|
||||
/* P-256 Variables */
|
||||
static u8_t bt_mesh_public_key[64];
|
||||
static u8_t bt_mesh_private_key[32] = {
|
||||
0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38,
|
||||
0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50,
|
||||
0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99,
|
||||
0x58, 0x99, 0xb8, 0xa6, 0xcd, 0x3c, 0x1a, 0xbd
|
||||
};
|
||||
static u8_t bt_mesh_private_key[32];
|
||||
|
||||
/* Scan related functions */
|
||||
static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb;
|
||||
|
@ -1758,8 +1753,17 @@ void ble_sm_alg_ecc_init(void);
|
|||
void bt_mesh_adapt_init(void)
|
||||
{
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* initialization of P-256 parameters */
|
||||
ble_sm_alg_ecc_init();
|
||||
|
||||
/* Set "bt_mesh_dev.flags" to 0 (only the "BLE_MESH_DEV_HAS_PUB_KEY"
|
||||
* flag is used) here, because we need to make sure each time after
|
||||
* the private key is initialized, a corresponding public key must
|
||||
* be generated.
|
||||
*/
|
||||
bt_mesh_atomic_set(bt_mesh_dev.flags, 0);
|
||||
bt_mesh_rand(bt_mesh_private_key, sizeof(bt_mesh_private_key));
|
||||
}
|
||||
|
||||
int bt_mesh_rand(void *buf, size_t len)
|
||||
|
@ -1815,7 +1819,8 @@ const u8_t *bt_mesh_pub_key_get(void)
|
|||
memcpy(bt_mesh_private_key, pri_key, 32);
|
||||
|
||||
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY);
|
||||
BT_DBG("gen the bt_mesh_public_key:%s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key)));
|
||||
|
||||
BT_DBG("Public Key %s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key)));
|
||||
|
||||
return bt_mesh_public_key;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ enum {
|
|||
REMOTE_PUB_KEY, /* Remote key has been received */
|
||||
OOB_PUB_KEY, /* OOB public key is available */
|
||||
LINK_ACTIVE, /* Link has been opened */
|
||||
HAVE_DHKEY, /* DHKey has been calcualted */
|
||||
HAVE_DHKEY, /* DHKey has been calculated */
|
||||
SEND_CONFIRM, /* Waiting to send Confirm value */
|
||||
WAIT_NUMBER, /* Waiting for number input from user */
|
||||
WAIT_STRING, /* Waiting for string input from user */
|
||||
|
|
Loading…
Reference in a new issue