Lines Matching refs:keys
381 if (!conn->le.keys) { in smp_keys_check()
382 conn->le.keys = bt_keys_find(BT_KEYS_LTK_P256, in smp_keys_check()
384 if (!conn->le.keys) { in smp_keys_check()
385 conn->le.keys = bt_keys_find(BT_KEYS_LTK, in smp_keys_check()
391 if (!conn->le.keys || in smp_keys_check()
392 !(conn->le.keys->keys & (BT_KEYS_LTK | BT_KEYS_LTK_P256))) { in smp_keys_check()
397 !(conn->le.keys->flags & BT_KEYS_AUTHENTICATED)) { in smp_keys_check()
402 !((conn->le.keys->flags & BT_KEYS_AUTHENTICATED) && in smp_keys_check()
403 (conn->le.keys->keys & BT_KEYS_LTK_P256) && in smp_keys_check()
404 (conn->le.keys->enc_size == BT_SMP_MAX_ENC_KEY_SIZE))) { in smp_keys_check()
613 static bool update_keys_check(struct bt_smp *smp, struct bt_keys *keys) in update_keys_check() argument
626 if (!keys || in update_keys_check()
627 !(keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK))) { in update_keys_check()
631 if (keys->enc_size > get_encryption_key_size(smp)) { in update_keys_check()
635 if ((keys->keys & BT_KEYS_LTK_P256) && in update_keys_check()
640 if ((keys->flags & BT_KEYS_AUTHENTICATED) && in update_keys_check()
646 (!(keys->flags & BT_KEYS_AUTHENTICATED) in update_keys_check()
649 (keys->id == smp->chan.chan.conn->id)) { in update_keys_check()
662 if (!conn->le.keys) { in update_debug_keys_check()
663 conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst); in update_debug_keys_check()
666 if (!conn->le.keys || in update_debug_keys_check()
667 !(conn->le.keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK))) { in update_debug_keys_check()
671 if (conn->le.keys->flags & BT_KEYS_DEBUG) { in update_debug_keys_check()
774 if (bt_crypto_h7(salt, conn->le.keys->ltk.val, ilk)) { in sc_derive_link_key()
782 if (bt_crypto_h6(conn->le.keys->ltk.val, tmp1, ilk)) { in sc_derive_link_key()
794 if (conn->le.keys->flags & BT_KEYS_AUTHENTICATED) { in sc_derive_link_key()
822 struct bt_keys *keys; in smp_pairing_br_complete() local
832 keys = bt_keys_find_addr(conn->id, &addr); in smp_pairing_br_complete()
837 if (keys) { in smp_pairing_br_complete()
838 bt_keys_clear(keys); in smp_pairing_br_complete()
852 if (bond_flag && keys) { in smp_pairing_br_complete()
853 bt_keys_store(keys); in smp_pairing_br_complete()
945 struct bt_keys *keys; in smp_br_derive_ltk() local
966 keys = bt_keys_get_type(BT_KEYS_LTK_P256, conn->id, &addr); in smp_br_derive_ltk()
967 if (!keys) { in smp_br_derive_ltk()
988 bt_keys_clear(keys); in smp_br_derive_ltk()
993 if (bt_crypto_h6(ilk, brle, keys->ltk.val)) { in smp_br_derive_ltk()
994 bt_keys_clear(keys); in smp_br_derive_ltk()
998 (void)memset(keys->ltk.ediv, 0, sizeof(keys->ltk.ediv)); in smp_br_derive_ltk()
999 (void)memset(keys->ltk.rand, 0, sizeof(keys->ltk.rand)); in smp_br_derive_ltk()
1000 keys->enc_size = smp->enc_key_size; in smp_br_derive_ltk()
1003 keys->flags |= BT_KEYS_AUTHENTICATED; in smp_br_derive_ltk()
1005 keys->flags &= ~BT_KEYS_AUTHENTICATED; in smp_br_derive_ltk()
1046 struct bt_keys *keys; in smp_br_distribute_keys() local
1056 keys = bt_keys_get_addr(conn->id, &addr); in smp_br_distribute_keys()
1057 if (!keys) { in smp_br_distribute_keys()
1118 bt_keys_add_type(keys, BT_KEYS_LOCAL_CSRK); in smp_br_distribute_keys()
1119 memcpy(keys->local_csrk.val, info->csrk, 16); in smp_br_distribute_keys()
1120 keys->local_csrk.cnt = 0U; in smp_br_distribute_keys()
1326 struct bt_keys *keys; in smp_br_ident_info() local
1340 keys = bt_keys_get_type(BT_KEYS_IRK, conn->id, &addr); in smp_br_ident_info()
1341 if (!keys) { in smp_br_ident_info()
1346 memcpy(keys->irk.val, req->irk, sizeof(keys->irk.val)); in smp_br_ident_info()
1398 struct bt_keys *keys; in smp_br_signing_info() local
1410 keys = bt_keys_get_type(BT_KEYS_REMOTE_CSRK, conn->id, &addr); in smp_br_signing_info()
1411 if (!keys) { in smp_br_signing_info()
1416 memcpy(keys->remote_csrk.val, req->csrk, sizeof(keys->remote_csrk.val)); in smp_br_signing_info()
1738 if (conn->le.keys == NULL) { in smp_pairing_complete()
1762 bt_keys_show_sniffer_info(conn->le.keys, NULL); in smp_pairing_complete()
1765 if (bond_flag && conn->le.keys) { in smp_pairing_complete()
1766 bt_keys_store(conn->le.keys); in smp_pairing_complete()
1782 if (conn->le.keys && in smp_pairing_complete()
1783 (!conn->le.keys->enc_size || in smp_pairing_complete()
1785 bt_keys_clear(conn->le.keys); in smp_pairing_complete()
1786 conn->le.keys = NULL; in smp_pairing_complete()
2023 struct bt_keys *keys = conn->le.keys; in legacy_distribute_keys() local
2051 memcpy(info->ltk, rand.key, keys->enc_size); in legacy_distribute_keys()
2052 if (keys->enc_size < sizeof(info->ltk)) { in legacy_distribute_keys()
2053 (void)memset(info->ltk + keys->enc_size, 0, in legacy_distribute_keys()
2054 sizeof(info->ltk) - keys->enc_size); in legacy_distribute_keys()
2073 bt_keys_add_type(keys, BT_KEYS_PERIPH_LTK); in legacy_distribute_keys()
2075 memcpy(keys->periph_ltk.val, rand.key, in legacy_distribute_keys()
2076 sizeof(keys->periph_ltk.val)); in legacy_distribute_keys()
2077 memcpy(keys->periph_ltk.rand, rand.rand, in legacy_distribute_keys()
2078 sizeof(keys->periph_ltk.rand)); in legacy_distribute_keys()
2079 memcpy(keys->periph_ltk.ediv, rand.ediv, in legacy_distribute_keys()
2080 sizeof(keys->periph_ltk.ediv)); in legacy_distribute_keys()
2089 struct bt_keys *keys = conn->le.keys; in bt_smp_distribute_keys() local
2091 if (!keys) { in bt_smp_distribute_keys()
2154 bt_keys_add_type(keys, BT_KEYS_LOCAL_CSRK); in bt_smp_distribute_keys()
2155 memcpy(keys->local_csrk.val, info->csrk, 16); in bt_smp_distribute_keys()
2156 keys->local_csrk.cnt = 0U; in bt_smp_distribute_keys()
2269 struct bt_keys *keys; in legacy_request_tk() local
2277 keys = bt_keys_find_addr(conn->id, &conn->le.dst); in legacy_request_tk()
2278 if (keys && (keys->flags & BT_KEYS_AUTHENTICATED) && in legacy_request_tk()
2528 struct bt_keys *keys; in smp_encrypt_info() local
2530 keys = bt_keys_get_type(BT_KEYS_LTK, conn->id, &conn->le.dst); in smp_encrypt_info()
2531 if (!keys) { in smp_encrypt_info()
2536 memcpy(keys->ltk.val, req->ltk, 16); in smp_encrypt_info()
2553 struct bt_keys *keys; in smp_central_ident() local
2555 keys = bt_keys_get_type(BT_KEYS_LTK, conn->id, &conn->le.dst); in smp_central_ident()
2556 if (!keys) { in smp_central_ident()
2561 memcpy(keys->ltk.ediv, req->ediv, sizeof(keys->ltk.ediv)); in smp_central_ident()
2562 memcpy(keys->ltk.rand, req->rand, sizeof(req->rand)); in smp_central_ident()
2815 if (!conn->le.keys) { in bt_smp_request_ltk()
2816 conn->le.keys = bt_keys_find(BT_KEYS_LTK_P256, conn->id, in bt_smp_request_ltk()
2818 if (!conn->le.keys) { in bt_smp_request_ltk()
2819 conn->le.keys = bt_keys_find(BT_KEYS_PERIPH_LTK, in bt_smp_request_ltk()
2825 conn->le.keys && (conn->le.keys->keys & BT_KEYS_LTK_P256)) { in bt_smp_request_ltk()
2826 enc_size = conn->le.keys->enc_size; in bt_smp_request_ltk()
2828 memcpy(ltk, conn->le.keys->ltk.val, enc_size); in bt_smp_request_ltk()
2839 if (conn->le.keys && (conn->le.keys->keys & BT_KEYS_PERIPH_LTK) && in bt_smp_request_ltk()
2840 !memcmp(conn->le.keys->periph_ltk.rand, &rand, 8) && in bt_smp_request_ltk()
2841 !memcmp(conn->le.keys->periph_ltk.ediv, &ediv, 2)) { in bt_smp_request_ltk()
2842 enc_size = conn->le.keys->enc_size; in bt_smp_request_ltk()
2844 memcpy(ltk, conn->le.keys->periph_ltk.val, enc_size); in bt_smp_request_ltk()
2900 if (!conn->le.keys) { in smp_send_security_req()
2901 conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst); in smp_send_security_req()
2902 if (!conn->le.keys) { in smp_send_security_req()
2952 if (!conn->le.keys) { in smp_pairing_req()
2953 conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst); in smp_pairing_req()
2954 if (!conn->le.keys) { in smp_pairing_req()
3025 if (!update_keys_check(smp, conn->le.keys)) { in smp_pairing_req()
3146 if (!conn->le.keys) { in smp_send_pairing_req()
3147 conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst); in smp_send_pairing_req()
3148 if (!conn->le.keys) { in smp_send_pairing_req()
3253 if (!update_keys_check(smp, conn->le.keys)) { in smp_pairing_rsp()
3861 struct bt_keys *keys; in smp_ident_info() local
3863 keys = bt_keys_get_type(BT_KEYS_IRK, conn->id, &conn->le.dst); in smp_ident_info()
3864 if (!keys) { in smp_ident_info()
3869 memcpy(keys->irk.val, req->irk, 16); in smp_ident_info()
3948 struct bt_keys *keys = bt_keys_find_addr(conn->id, &req->addr); in smp_ident_addr_info() local
3950 if (keys) { in smp_ident_addr_info()
3951 if (!update_keys_check(smp, keys)) { in smp_ident_addr_info()
3955 bt_keys_clear(keys); in smp_ident_addr_info()
3961 struct bt_keys *keys; in smp_ident_addr_info() local
3963 keys = bt_keys_get_type(BT_KEYS_IRK, conn->id, &conn->le.dst); in smp_ident_addr_info()
3964 if (!keys) { in smp_ident_addr_info()
3983 bt_addr_copy(&keys->irk.rpa, &dst->a); in smp_ident_addr_info()
4000 bt_addr_le_copy(&keys->addr, &req->addr); in smp_ident_addr_info()
4006 err = smp_id_add_replace(smp, keys); in smp_ident_addr_info()
4042 struct bt_keys *keys; in smp_signing_info() local
4044 keys = bt_keys_get_type(BT_KEYS_REMOTE_CSRK, conn->id, in smp_signing_info()
4046 if (!keys) { in smp_signing_info()
4051 memcpy(keys->remote_csrk.val, req->csrk, in smp_signing_info()
4052 sizeof(keys->remote_csrk.val)); in smp_signing_info()
4123 if (conn->le.keys) { in smp_security_request()
4125 if (!(conn->le.keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK))) { in smp_security_request()
4129 conn->le.keys = bt_keys_find(BT_KEYS_LTK_P256, conn->id, in smp_security_request()
4131 if (!conn->le.keys) { in smp_security_request()
4132 conn->le.keys = bt_keys_find(BT_KEYS_LTK, conn->id, in smp_security_request()
4137 if (!conn->le.keys) { in smp_security_request()
4143 !(conn->le.keys->flags & BT_KEYS_AUTHENTICATED)) { in smp_security_request()
4155 !(conn->le.keys->keys & BT_KEYS_LTK_P256)) { in smp_security_request()
4160 if (bt_conn_le_start_encryption(conn, conn->le.keys->ltk.rand, in smp_security_request()
4161 conn->le.keys->ltk.ediv, in smp_security_request()
4162 conn->le.keys->ltk.val, in smp_security_request()
4163 conn->le.keys->enc_size) < 0) { in smp_security_request()
4697 struct bt_keys *keys = chan->conn->le.keys; in bt_smp_disconnected() local
4714 if (keys) { in bt_smp_disconnected()
4719 if (!keys->keys || (!IS_ENABLED(CONFIG_BT_STORE_DEBUG_KEYS) && in bt_smp_disconnected()
4720 (keys->flags & BT_KEYS_DEBUG))) { in bt_smp_disconnected()
4721 bt_keys_clear(keys); in bt_smp_disconnected()
4822 smp_err = smp_id_add_replace(smp, conn->le.keys); in bt_smp_encrypt_change()
4896 struct bt_keys *keys; in bt_smp_sign_verify() local
4904 keys = bt_keys_find(BT_KEYS_REMOTE_CSRK, conn->id, &conn->le.dst); in bt_smp_sign_verify()
4905 if (!keys) { in bt_smp_sign_verify()
4911 cnt = sys_cpu_to_le32(keys->remote_csrk.cnt); in bt_smp_sign_verify()
4915 bt_hex(keys->remote_csrk.val, 16), keys->remote_csrk.cnt); in bt_smp_sign_verify()
4917 err = smp_sign_buf(keys->remote_csrk.val, buf->data, in bt_smp_sign_verify()
4929 keys->remote_csrk.cnt++; in bt_smp_sign_verify()
4936 struct bt_keys *keys; in bt_smp_sign() local
4940 keys = bt_keys_find(BT_KEYS_LOCAL_CSRK, conn->id, &conn->le.dst); in bt_smp_sign()
4941 if (!keys) { in bt_smp_sign()
4950 cnt = sys_cpu_to_le32(keys->local_csrk.cnt); in bt_smp_sign()
4953 LOG_DBG("Sign data len %u key %s count %u", buf->len, bt_hex(keys->local_csrk.val, 16), in bt_smp_sign()
4954 keys->local_csrk.cnt); in bt_smp_sign()
4956 err = smp_sign_buf(keys->local_csrk.val, buf->data, buf->len - 12); in bt_smp_sign()
4962 keys->local_csrk.cnt++; in bt_smp_sign()
5940 conn->le.keys->ltk.rand, in bt_smp_start_security()
5941 conn->le.keys->ltk.ediv, in bt_smp_start_security()
5942 conn->le.keys->ltk.val, in bt_smp_start_security()
5943 conn->le.keys->enc_size); in bt_smp_start_security()
5979 if (conn->le.keys) { in bt_smp_update_keys()
5980 bt_keys_clear(conn->le.keys); in bt_smp_update_keys()
5983 conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst); in bt_smp_update_keys()
5984 if (!conn->le.keys) { in bt_smp_update_keys()
5992 conn->le.keys->flags |= BT_KEYS_DEBUG; in bt_smp_update_keys()
6003 conn->le.keys->flags |= BT_KEYS_OOB; in bt_smp_update_keys()
6008 conn->le.keys->flags |= BT_KEYS_AUTHENTICATED; in bt_smp_update_keys()
6013 conn->le.keys->flags &= ~BT_KEYS_OOB; in bt_smp_update_keys()
6014 conn->le.keys->flags &= ~BT_KEYS_AUTHENTICATED; in bt_smp_update_keys()
6018 conn->le.keys->enc_size = get_encryption_key_size(smp); in bt_smp_update_keys()
6026 conn->le.keys->flags |= BT_KEYS_SC; in bt_smp_update_keys()
6029 bt_keys_add_type(conn->le.keys, BT_KEYS_LTK_P256); in bt_smp_update_keys()
6030 memcpy(conn->le.keys->ltk.val, smp->tk, in bt_smp_update_keys()
6031 sizeof(conn->le.keys->ltk.val)); in bt_smp_update_keys()
6032 (void)memset(conn->le.keys->ltk.rand, 0, in bt_smp_update_keys()
6033 sizeof(conn->le.keys->ltk.rand)); in bt_smp_update_keys()
6034 (void)memset(conn->le.keys->ltk.ediv, 0, in bt_smp_update_keys()
6035 sizeof(conn->le.keys->ltk.ediv)); in bt_smp_update_keys()
6039 sys_memcpy_swap(ltk, smp->tk, conn->le.keys->enc_size); in bt_smp_update_keys()
6040 LOG_INF("SC LTK: 0x%s (No bonding)", bt_hex(ltk, conn->le.keys->enc_size)); in bt_smp_update_keys()
6043 conn->le.keys->flags &= ~BT_KEYS_SC; in bt_smp_update_keys()