smp_keys.cc 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. /******************************************************************************
  2. *
  3. * Copyright 1999-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * This file contains security manager protocol utility functions
  21. *
  22. ******************************************************************************/
  23. #include "bt_target.h"
  24. #if (SMP_DEBUG == TRUE)
  25. #include <stdio.h>
  26. #endif
  27. #include <base/bind.h>
  28. #include <string.h>
  29. #include "bt_utils.h"
  30. #include "btm_ble_api.h"
  31. #include "btm_ble_int.h"
  32. #include "btm_int.h"
  33. #include "device/include/controller.h"
  34. #include "hcimsgs.h"
  35. #include "osi/include/osi.h"
  36. #include "p_256_ecc_pp.h"
  37. #include "smp_int.h"
  38. #include "stack/crypto_toolbox/crypto_toolbox.h"
  39. #include <algorithm>
  40. using base::Bind;
  41. using crypto_toolbox::aes_128;
  42. #ifndef SMP_MAX_ENC_REPEAT
  43. #define SMP_MAX_ENC_REPEAT 3
  44. #endif
  45. static void smp_process_stk(tSMP_CB* p_cb, Octet16* p);
  46. static Octet16 smp_calculate_legacy_short_term_key(tSMP_CB* p_cb);
  47. static void smp_process_private_key(tSMP_CB* p_cb);
  48. #define SMP_PASSKEY_MASK 0xfff00000
  49. void smp_debug_print_nbyte_little_endian(uint8_t* p, const char* key_name,
  50. uint8_t len) {
  51. #if (SMP_DEBUG == TRUE)
  52. int ind;
  53. int col_count = 32;
  54. int row_count;
  55. uint8_t p_buf[512];
  56. SMP_TRACE_DEBUG("%s(LSB ~ MSB):", key_name);
  57. memset(p_buf, 0, sizeof(p_buf));
  58. row_count = len % col_count ? len / col_count + 1 : len / col_count;
  59. ind = 0;
  60. for (int row = 0; row < row_count; row++) {
  61. for (int column = 0, x = 0; (ind < len) && (column < col_count);
  62. column++, ind++) {
  63. x += snprintf((char*)&p_buf[x], sizeof(p_buf) - x, "%02x ", p[ind]);
  64. }
  65. SMP_TRACE_DEBUG(" [%03d]: %s", row * col_count, p_buf);
  66. }
  67. #endif
  68. }
  69. inline void smp_debug_print_nbyte_little_endian(const Octet16& p,
  70. const char* key_name,
  71. uint8_t len) {
  72. smp_debug_print_nbyte_little_endian(const_cast<uint8_t*>(p.data()), key_name,
  73. len);
  74. }
  75. void smp_debug_print_nbyte_big_endian(uint8_t* p, const char* key_name,
  76. uint8_t len) {
  77. #if (SMP_DEBUG == TRUE)
  78. uint8_t p_buf[512];
  79. SMP_TRACE_DEBUG("%s(MSB ~ LSB):", key_name);
  80. memset(p_buf, 0, sizeof(p_buf));
  81. int ind = 0;
  82. int ncols = 32; /* num entries in one line */
  83. int nrows; /* num lines */
  84. nrows = len % ncols ? len / ncols + 1 : len / ncols;
  85. for (int row = 0; row < nrows; row++) {
  86. for (int col = 0, x = 0; (ind < len) && (col < ncols); col++, ind++) {
  87. x += snprintf((char*)&p_buf[len - x - 1], sizeof(p_buf) - (len - x - 1),
  88. "%02x ", p[ind]);
  89. }
  90. SMP_TRACE_DEBUG("[%03d]: %s", row * ncols, p_buf);
  91. }
  92. #endif
  93. }
  94. /** This function is called to process a passkey. */
  95. void smp_proc_passkey(tSMP_CB* p_cb, BT_OCTET8 rand) {
  96. uint8_t* tt = p_cb->tk.data();
  97. uint32_t passkey; /* 19655 test number; */
  98. uint8_t* pp = rand;
  99. SMP_TRACE_DEBUG("%s", __func__);
  100. STREAM_TO_UINT32(passkey, pp);
  101. passkey &= ~SMP_PASSKEY_MASK;
  102. /* truncate by maximum value */
  103. while (passkey > BTM_MAX_PASSKEY_VAL) passkey >>= 1;
  104. /* save the TK */
  105. p_cb->tk = {0};
  106. UINT32_TO_STREAM(tt, passkey);
  107. if (p_cb->p_callback) {
  108. tSMP_EVT_DATA smp_evt_data;
  109. smp_evt_data.passkey = passkey;
  110. (*p_cb->p_callback)(SMP_PASSKEY_NOTIF_EVT, p_cb->pairing_bda,
  111. &smp_evt_data);
  112. }
  113. if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_PASSKEY_DISP) {
  114. tSMP_INT_DATA smp_int_data;
  115. smp_int_data.passkey = passkey;
  116. smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &smp_int_data);
  117. } else {
  118. tSMP_KEY key;
  119. key.key_type = SMP_KEY_TYPE_TK;
  120. key.p_data = p_cb->tk.data();
  121. tSMP_INT_DATA smp_int_data;
  122. smp_int_data.key = key;
  123. smp_sm_event(p_cb, SMP_KEY_READY_EVT, &smp_int_data);
  124. }
  125. }
  126. /*******************************************************************************
  127. *
  128. * Function smp_generate_passkey
  129. *
  130. * Description This function is called to generate passkey.
  131. *
  132. * Returns void
  133. *
  134. ******************************************************************************/
  135. void smp_generate_passkey(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  136. SMP_TRACE_DEBUG("%s", __func__);
  137. /* generate MRand or SRand */
  138. btsnd_hcic_ble_rand(Bind(&smp_proc_passkey, p_cb));
  139. }
  140. /*******************************************************************************
  141. *
  142. * Function smp_generate_stk
  143. *
  144. * Description This function is called to generate STK calculated by
  145. * running AES with the TK value as key and a concatenation of
  146. * the random values.
  147. *
  148. * Returns void
  149. *
  150. ******************************************************************************/
  151. void smp_generate_stk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  152. Octet16 output;
  153. SMP_TRACE_DEBUG("%s", __func__);
  154. if (p_cb->le_secure_connections_mode_is_used) {
  155. SMP_TRACE_WARNING("FOR LE SC LTK IS USED INSTEAD OF STK");
  156. output = p_cb->ltk;
  157. } else {
  158. output = smp_calculate_legacy_short_term_key(p_cb);
  159. }
  160. smp_process_stk(p_cb, &output);
  161. }
  162. /**
  163. * This function is called to calculate CSRK
  164. */
  165. void smp_compute_csrk(uint16_t div, tSMP_CB* p_cb) {
  166. uint8_t buffer[4]; /* for (r || DIV) r=1*/
  167. uint16_t r = 1;
  168. uint8_t* p = buffer;
  169. p_cb->div = div;
  170. SMP_TRACE_DEBUG("%s: div=%x", __func__, p_cb->div);
  171. const Octet16& er = BTM_GetDeviceEncRoot();
  172. /* CSRK = d1(ER, DIV, 1) */
  173. UINT16_TO_STREAM(p, p_cb->div);
  174. UINT16_TO_STREAM(p, r);
  175. p_cb->csrk = aes_128(er, buffer, 4);
  176. smp_send_csrk_info(p_cb, NULL);
  177. }
  178. /**
  179. * This function is called to calculate CSRK, starting with DIV generation.
  180. */
  181. void smp_generate_csrk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  182. bool div_status;
  183. SMP_TRACE_DEBUG("smp_generate_csrk");
  184. div_status = btm_get_local_div(p_cb->pairing_bda, &p_cb->div);
  185. if (div_status) {
  186. smp_compute_csrk(p_cb->div, p_cb);
  187. } else {
  188. SMP_TRACE_DEBUG("Generate DIV for CSRK");
  189. btsnd_hcic_ble_rand(Bind(
  190. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  191. uint16_t div;
  192. STREAM_TO_UINT16(div, rand);
  193. smp_compute_csrk(div, p_cb);
  194. },
  195. p_cb));
  196. }
  197. }
  198. /*******************************************************************************
  199. * Function smp_concatenate_peer - LSB first
  200. * add pairing command sent from local device into p1.
  201. ******************************************************************************/
  202. void smp_concatenate_local(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) {
  203. uint8_t* p = *p_data;
  204. SMP_TRACE_DEBUG("%s", __func__);
  205. UINT8_TO_STREAM(p, op_code);
  206. UINT8_TO_STREAM(p, p_cb->local_io_capability);
  207. UINT8_TO_STREAM(p, p_cb->loc_oob_flag);
  208. UINT8_TO_STREAM(p, p_cb->loc_auth_req);
  209. UINT8_TO_STREAM(p, p_cb->loc_enc_size);
  210. UINT8_TO_STREAM(p, p_cb->local_i_key);
  211. UINT8_TO_STREAM(p, p_cb->local_r_key);
  212. *p_data = p;
  213. }
  214. /*******************************************************************************
  215. * Function smp_concatenate_peer - LSB first
  216. * add pairing command received from peer device into p1.
  217. ******************************************************************************/
  218. void smp_concatenate_peer(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) {
  219. uint8_t* p = *p_data;
  220. SMP_TRACE_DEBUG("smp_concatenate_peer ");
  221. UINT8_TO_STREAM(p, op_code);
  222. UINT8_TO_STREAM(p, p_cb->peer_io_caps);
  223. UINT8_TO_STREAM(p, p_cb->peer_oob_flag);
  224. UINT8_TO_STREAM(p, p_cb->peer_auth_req);
  225. UINT8_TO_STREAM(p, p_cb->peer_enc_size);
  226. UINT8_TO_STREAM(p, p_cb->peer_i_key);
  227. UINT8_TO_STREAM(p, p_cb->peer_r_key);
  228. *p_data = p;
  229. }
  230. /** Generate Confirm/Compare Step1:
  231. * p1 = (MSB) pres || preq || rat' || iat' (LSB)
  232. * Fill in values LSB first thus
  233. * p1 = iat' || rat' || preq || pres
  234. */
  235. Octet16 smp_gen_p1_4_confirm(tSMP_CB* p_cb,
  236. tBLE_ADDR_TYPE remote_bd_addr_type) {
  237. SMP_TRACE_DEBUG("%s", __func__);
  238. Octet16 p1;
  239. uint8_t* p = p1.data();
  240. if (p_cb->role == HCI_ROLE_MASTER) {
  241. /* iat': initiator's (local) address type */
  242. UINT8_TO_STREAM(p, p_cb->addr_type);
  243. /* rat': responder's (remote) address type */
  244. UINT8_TO_STREAM(p, remote_bd_addr_type);
  245. /* preq : Pairing Request (local) command */
  246. smp_concatenate_local(p_cb, &p, SMP_OPCODE_PAIRING_REQ);
  247. /* pres : Pairing Response (remote) command */
  248. smp_concatenate_peer(p_cb, &p, SMP_OPCODE_PAIRING_RSP);
  249. } else {
  250. /* iat': initiator's (remote) address type */
  251. UINT8_TO_STREAM(p, remote_bd_addr_type);
  252. /* rat': responder's (local) address type */
  253. UINT8_TO_STREAM(p, p_cb->addr_type);
  254. /* preq : Pairing Request (remote) command */
  255. smp_concatenate_peer(p_cb, &p, SMP_OPCODE_PAIRING_REQ);
  256. /* pres : Pairing Response (local) command */
  257. smp_concatenate_local(p_cb, &p, SMP_OPCODE_PAIRING_RSP);
  258. }
  259. smp_debug_print_nbyte_little_endian(p1, "p1 = iat' || rat' || preq || pres",
  260. 16);
  261. return p1;
  262. }
  263. /** Generate Confirm/Compare Step2:
  264. * p2 = (MSB) padding || ia || ra (LSB)
  265. * Fill values LSB first and thus:
  266. * p2 = ra || ia || padding
  267. */
  268. Octet16 smp_gen_p2_4_confirm(tSMP_CB* p_cb, const RawAddress& remote_bda) {
  269. SMP_TRACE_DEBUG("%s", __func__);
  270. Octet16 p2{0};
  271. uint8_t* p = p2.data();
  272. /* 32-bit Padding */
  273. memset(p, 0, OCTET16_LEN);
  274. if (p_cb->role == HCI_ROLE_MASTER) {
  275. /* ra : Responder's (remote) address */
  276. BDADDR_TO_STREAM(p, remote_bda);
  277. /* ia : Initiator's (local) address */
  278. BDADDR_TO_STREAM(p, p_cb->local_bda);
  279. } else {
  280. /* ra : Responder's (local) address */
  281. BDADDR_TO_STREAM(p, p_cb->local_bda);
  282. /* ia : Initiator's (remote) address */
  283. BDADDR_TO_STREAM(p, remote_bda);
  284. }
  285. smp_debug_print_nbyte_little_endian(p2, "p2 = ra || ia || padding", 16);
  286. return p2;
  287. }
  288. /*******************************************************************************
  289. *
  290. * Function smp_calculate_comfirm
  291. *
  292. * Description This function (c1) is called to calculate Confirm value.
  293. *
  294. * Returns tSMP_STATUS status of confirmation calculation
  295. *
  296. ******************************************************************************/
  297. tSMP_STATUS smp_calculate_comfirm(tSMP_CB* p_cb, const Octet16& rand,
  298. Octet16* output) {
  299. SMP_TRACE_DEBUG("%s", __func__);
  300. RawAddress remote_bda;
  301. tBLE_ADDR_TYPE remote_bd_addr_type = 0;
  302. /* get remote connection specific bluetooth address */
  303. if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, remote_bda,
  304. &remote_bd_addr_type)) {
  305. SMP_TRACE_ERROR("%s: cannot obtain remote device address", __func__);
  306. return SMP_PAIR_FAIL_UNKNOWN;
  307. }
  308. /* get local connection specific bluetooth address */
  309. BTM_ReadConnectionAddr(p_cb->pairing_bda, p_cb->local_bda, &p_cb->addr_type);
  310. /* generate p1 = pres || preq || rat' || iat' */
  311. Octet16 p1 = smp_gen_p1_4_confirm(p_cb, remote_bd_addr_type);
  312. /* p1' = rand XOR p1 */
  313. smp_xor_128(&p1, rand);
  314. smp_debug_print_nbyte_little_endian(p1, "p1' = p1 XOR r", 16);
  315. /* calculate e1 = e(k, p1'), where k = TK */
  316. smp_debug_print_nbyte_little_endian(p_cb->tk.data(), "TK", 16);
  317. Octet16 e1 = aes_128(p_cb->tk, p1);
  318. smp_debug_print_nbyte_little_endian(e1.data(), "e1 = e(k, p1')", 16);
  319. /* generate p2 = padding || ia || ra */
  320. Octet16 p2 = smp_gen_p2_4_confirm(p_cb, remote_bda);
  321. /* calculate p2' = (p2 XOR e1) */
  322. smp_xor_128(&p2, e1);
  323. smp_debug_print_nbyte_little_endian(p2, "p2' = p2 XOR e1", 16);
  324. /* calculate: c1 = e(k, p2') */
  325. *output = aes_128(p_cb->tk, p2);
  326. return SMP_SUCCESS;
  327. }
  328. /*******************************************************************************
  329. *
  330. * Function smp_generate_confirm
  331. *
  332. * Description This function is called when random number (MRand or SRand)
  333. * is generated by the controller and the stack needs to
  334. * calculate c1 value (MConfirm or SConfirm) for the first time
  335. *
  336. * Returns void
  337. *
  338. ******************************************************************************/
  339. static void smp_generate_confirm(tSMP_CB* p_cb) {
  340. SMP_TRACE_DEBUG("%s", __func__);
  341. smp_debug_print_nbyte_little_endian(p_cb->rand.data(), "local_rand", 16);
  342. Octet16 output;
  343. tSMP_STATUS status = smp_calculate_comfirm(p_cb, p_cb->rand, &output);
  344. if (status != SMP_SUCCESS) {
  345. tSMP_INT_DATA smp_int_data;
  346. smp_int_data.status = status;
  347. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
  348. return;
  349. }
  350. tSMP_KEY key;
  351. p_cb->confirm = output;
  352. smp_debug_print_nbyte_little_endian(p_cb->confirm, "Local Confirm generated",
  353. 16);
  354. key.key_type = SMP_KEY_TYPE_CFM;
  355. key.p_data = output.data();
  356. tSMP_INT_DATA smp_int_data;
  357. smp_int_data.key = key;
  358. smp_sm_event(p_cb, SMP_KEY_READY_EVT, &smp_int_data);
  359. }
  360. /*******************************************************************************
  361. *
  362. * Function smp_generate_srand_mrand_confirm
  363. *
  364. * Description This function is called to start the second pairing phase by
  365. * start generating random number.
  366. *
  367. *
  368. * Returns void
  369. *
  370. ******************************************************************************/
  371. void smp_generate_srand_mrand_confirm(tSMP_CB* p_cb,
  372. UNUSED_ATTR tSMP_INT_DATA* p_data) {
  373. SMP_TRACE_DEBUG("%s", __func__);
  374. /* generate MRand or SRand */
  375. btsnd_hcic_ble_rand(Bind(
  376. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  377. memcpy(p_cb->rand.data(), rand, 8);
  378. /* generate 64 MSB of MRand or SRand */
  379. btsnd_hcic_ble_rand(Bind(
  380. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  381. memcpy((void*)&p_cb->rand[8], rand, BT_OCTET8_LEN);
  382. smp_generate_confirm(p_cb);
  383. },
  384. p_cb));
  385. },
  386. p_cb));
  387. }
  388. /*******************************************************************************
  389. *
  390. * Function smp_generate_compare
  391. *
  392. * Description This function is called when random number (MRand or SRand)
  393. * is received from remote device and the c1 value (MConfirm
  394. * or SConfirm) needs to be generated to authenticate remote
  395. * device.
  396. *
  397. * Returns void
  398. *
  399. ******************************************************************************/
  400. void smp_generate_compare(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  401. SMP_TRACE_DEBUG("smp_generate_compare ");
  402. smp_debug_print_nbyte_little_endian(p_cb->rrand, "peer rand", 16);
  403. Octet16 output;
  404. tSMP_STATUS status = smp_calculate_comfirm(p_cb, p_cb->rrand, &output);
  405. if (status != SMP_SUCCESS) {
  406. tSMP_INT_DATA smp_int_data;
  407. smp_int_data.status = status;
  408. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
  409. return;
  410. }
  411. tSMP_KEY key;
  412. smp_debug_print_nbyte_little_endian(output.data(), "Remote Confirm generated",
  413. 16);
  414. key.key_type = SMP_KEY_TYPE_CMP;
  415. key.p_data = output.data();
  416. tSMP_INT_DATA smp_int_data;
  417. smp_int_data.key = key;
  418. smp_sm_event(p_cb, SMP_KEY_READY_EVT, &smp_int_data);
  419. }
  420. /** This function is called when STK is generated proceed to send the encrypt
  421. * the link using STK. */
  422. static void smp_process_stk(tSMP_CB* p_cb, Octet16* p) {
  423. tSMP_KEY key;
  424. SMP_TRACE_DEBUG("smp_process_stk ");
  425. #if (SMP_DEBUG == TRUE)
  426. SMP_TRACE_ERROR("STK Generated");
  427. #endif
  428. smp_mask_enc_key(p_cb->loc_enc_size, p);
  429. key.key_type = SMP_KEY_TYPE_STK;
  430. key.p_data = p->data();
  431. tSMP_INT_DATA smp_int_data;
  432. smp_int_data.key = key;
  433. smp_sm_event(p_cb, SMP_KEY_READY_EVT, &smp_int_data);
  434. }
  435. /** This function calculates EDIV = Y xor DIV */
  436. static void smp_process_ediv(tSMP_CB* p_cb, Octet16& p) {
  437. tSMP_KEY key;
  438. uint8_t* pp = p.data();
  439. uint16_t y;
  440. SMP_TRACE_DEBUG("smp_process_ediv ");
  441. STREAM_TO_UINT16(y, pp);
  442. /* EDIV = Y xor DIV */
  443. p_cb->ediv = p_cb->div ^ y;
  444. /* send LTK ready */
  445. SMP_TRACE_ERROR("LTK ready");
  446. key.key_type = SMP_KEY_TYPE_LTK;
  447. key.p_data = p.data();
  448. tSMP_INT_DATA smp_int_data;
  449. smp_int_data.key = key;
  450. smp_sm_event(p_cb, SMP_KEY_READY_EVT, &smp_int_data);
  451. }
  452. /**
  453. * This function is to proceed generate Y = E(DHK, Rand)
  454. */
  455. static void smp_generate_y(tSMP_CB* p_cb, BT_OCTET8 rand) {
  456. SMP_TRACE_DEBUG("%s ", __func__);
  457. const Octet16& dhk = BTM_GetDeviceDHK();
  458. memcpy(p_cb->enc_rand, rand, BT_OCTET8_LEN);
  459. Octet16 output = aes_128(dhk, rand, BT_OCTET8_LEN);
  460. smp_process_ediv(p_cb, output);
  461. }
  462. /**
  463. * Calculate LTK = d1(ER, DIV, 0)= e(ER, DIV)
  464. */
  465. static void smp_generate_ltk_cont(uint16_t div, tSMP_CB* p_cb) {
  466. p_cb->div = div;
  467. SMP_TRACE_DEBUG("%s", __func__);
  468. const Octet16& er = BTM_GetDeviceEncRoot();
  469. /* LTK = d1(ER, DIV, 0)= e(ER, DIV)*/
  470. Octet16 ltk = aes_128(er, (uint8_t*)&p_cb->div, sizeof(uint16_t));
  471. /* mask the LTK */
  472. smp_mask_enc_key(p_cb->loc_enc_size, &ltk);
  473. p_cb->ltk = ltk;
  474. /* generate EDIV and rand now */
  475. btsnd_hcic_ble_rand(Bind(&smp_generate_y, p_cb));
  476. }
  477. /*******************************************************************************
  478. *
  479. * Function smp_generate_ltk
  480. *
  481. * Description This function is called:
  482. * - in legacy pairing - to calculate LTK, starting with DIV
  483. * generation;
  484. * - in LE Secure Connections pairing over LE transport - to
  485. * process LTK already generated to encrypt LE link;
  486. * - in LE Secure Connections pairing over BR/EDR transport -
  487. * to start BR/EDR Link Key processing.
  488. *
  489. * Returns void
  490. *
  491. ******************************************************************************/
  492. void smp_generate_ltk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  493. SMP_TRACE_DEBUG("%s", __func__);
  494. if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) {
  495. smp_br_process_link_key(p_cb, NULL);
  496. return;
  497. } else if (p_cb->le_secure_connections_mode_is_used) {
  498. smp_process_secure_connection_long_term_key();
  499. return;
  500. }
  501. bool div_status = btm_get_local_div(p_cb->pairing_bda, &p_cb->div);
  502. if (div_status) {
  503. smp_generate_ltk_cont(p_cb->div, p_cb);
  504. } else {
  505. SMP_TRACE_DEBUG("%s: Generate DIV for LTK", __func__);
  506. /* generate MRand or SRand */
  507. btsnd_hcic_ble_rand(Bind(
  508. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  509. uint16_t div;
  510. STREAM_TO_UINT16(div, rand);
  511. smp_generate_ltk_cont(div, p_cb);
  512. },
  513. p_cb));
  514. }
  515. }
  516. /* The function calculates legacy STK */
  517. Octet16 smp_calculate_legacy_short_term_key(tSMP_CB* p_cb) {
  518. SMP_TRACE_DEBUG("%s", __func__);
  519. Octet16 text{0};
  520. if (p_cb->role == HCI_ROLE_MASTER) {
  521. memcpy(text.data(), p_cb->rand.data(), BT_OCTET8_LEN);
  522. memcpy(text.data() + BT_OCTET8_LEN, p_cb->rrand.data(), BT_OCTET8_LEN);
  523. } else {
  524. memcpy(text.data(), p_cb->rrand.data(), BT_OCTET8_LEN);
  525. memcpy(text.data() + BT_OCTET8_LEN, p_cb->rand.data(), BT_OCTET8_LEN);
  526. }
  527. /* generate STK = Etk(rand|rrand)*/
  528. return aes_128(p_cb->tk, text);
  529. }
  530. /*******************************************************************************
  531. *
  532. * Function smp_create_private_key
  533. *
  534. * Description This function is called to create private key used to
  535. * calculate public key and DHKey.
  536. * The function starts private key creation requesting
  537. * for the controller to generate [0-7] octets of private key.
  538. *
  539. * Returns void
  540. *
  541. ******************************************************************************/
  542. void smp_create_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  543. SMP_TRACE_DEBUG("%s", __func__);
  544. btsnd_hcic_ble_rand(Bind(
  545. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  546. memcpy((void*)p_cb->private_key, rand, BT_OCTET8_LEN);
  547. btsnd_hcic_ble_rand(Bind(
  548. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  549. memcpy((void*)&p_cb->private_key[8], rand, BT_OCTET8_LEN);
  550. btsnd_hcic_ble_rand(Bind(
  551. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  552. memcpy((void*)&p_cb->private_key[16], rand, BT_OCTET8_LEN);
  553. btsnd_hcic_ble_rand(Bind(
  554. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  555. memcpy((void*)&p_cb->private_key[24], rand,
  556. BT_OCTET8_LEN);
  557. smp_process_private_key(p_cb);
  558. },
  559. p_cb));
  560. },
  561. p_cb));
  562. },
  563. p_cb));
  564. },
  565. p_cb));
  566. }
  567. /*******************************************************************************
  568. *
  569. * Function smp_use_oob_private_key
  570. *
  571. * Description This function is called
  572. * - to save the secret key used to calculate the public key
  573. * used in calculations of commitment sent OOB to a peer
  574. * - to use this secret key to recalculate the public key and
  575. * start the process of sending this public key to the peer
  576. * if secret/public keys have to be reused.
  577. * If the keys aren't supposed to be reused, continue from the
  578. * point from which request for OOB data was issued.
  579. *
  580. * Returns void
  581. *
  582. ******************************************************************************/
  583. void smp_use_oob_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  584. SMP_TRACE_DEBUG("%s req_oob_type: %d, role: %d", __func__, p_cb->req_oob_type,
  585. p_cb->role);
  586. switch (p_cb->req_oob_type) {
  587. case SMP_OOB_BOTH:
  588. case SMP_OOB_LOCAL:
  589. SMP_TRACE_DEBUG("%s restore secret key", __func__)
  590. memcpy(p_cb->private_key, p_cb->sc_oob_data.loc_oob_data.private_key_used,
  591. BT_OCTET32_LEN);
  592. smp_process_private_key(p_cb);
  593. break;
  594. default:
  595. SMP_TRACE_DEBUG("%s create secret key anew", __func__);
  596. smp_set_state(SMP_STATE_PAIR_REQ_RSP);
  597. smp_decide_association_model(p_cb, NULL);
  598. break;
  599. }
  600. }
  601. /*******************************************************************************
  602. *
  603. * Function smp_process_private_key
  604. *
  605. * Description This function processes private key.
  606. * It calculates public key and notifies SM that private key /
  607. * public key pair is created.
  608. *
  609. * Returns void
  610. *
  611. ******************************************************************************/
  612. void smp_process_private_key(tSMP_CB* p_cb) {
  613. Point public_key;
  614. BT_OCTET32 private_key;
  615. SMP_TRACE_DEBUG("%s", __func__);
  616. memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN);
  617. ECC_PointMult(&public_key, &(curve_p256.G), (uint32_t*)private_key,
  618. KEY_LENGTH_DWORDS_P256);
  619. memcpy(p_cb->loc_publ_key.x, public_key.x, BT_OCTET32_LEN);
  620. memcpy(p_cb->loc_publ_key.y, public_key.y, BT_OCTET32_LEN);
  621. smp_debug_print_nbyte_little_endian(p_cb->private_key, "private",
  622. BT_OCTET32_LEN);
  623. smp_debug_print_nbyte_little_endian(p_cb->loc_publ_key.x, "local public(x)",
  624. BT_OCTET32_LEN);
  625. smp_debug_print_nbyte_little_endian(p_cb->loc_publ_key.y, "local public(y)",
  626. BT_OCTET32_LEN);
  627. p_cb->flags |= SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY;
  628. smp_sm_event(p_cb, SMP_LOC_PUBL_KEY_CRTD_EVT, NULL);
  629. }
  630. /*******************************************************************************
  631. *
  632. * Function smp_compute_dhkey
  633. *
  634. * Description The function:
  635. * - calculates a new public key using as input local private
  636. * key and peer public key;
  637. * - saves the new public key x-coordinate as DHKey.
  638. *
  639. * Returns void
  640. *
  641. ******************************************************************************/
  642. void smp_compute_dhkey(tSMP_CB* p_cb) {
  643. Point peer_publ_key, new_publ_key;
  644. BT_OCTET32 private_key;
  645. SMP_TRACE_DEBUG("%s", __func__);
  646. memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN);
  647. memcpy(peer_publ_key.x, p_cb->peer_publ_key.x, BT_OCTET32_LEN);
  648. memcpy(peer_publ_key.y, p_cb->peer_publ_key.y, BT_OCTET32_LEN);
  649. ECC_PointMult(&new_publ_key, &peer_publ_key, (uint32_t*)private_key,
  650. KEY_LENGTH_DWORDS_P256);
  651. memcpy(p_cb->dhkey, new_publ_key.x, BT_OCTET32_LEN);
  652. smp_debug_print_nbyte_little_endian(p_cb->dhkey, "Old DHKey", BT_OCTET32_LEN);
  653. smp_debug_print_nbyte_little_endian(p_cb->private_key, "private",
  654. BT_OCTET32_LEN);
  655. smp_debug_print_nbyte_little_endian(p_cb->peer_publ_key.x, "rem public(x)",
  656. BT_OCTET32_LEN);
  657. smp_debug_print_nbyte_little_endian(p_cb->peer_publ_key.y, "rem public(y)",
  658. BT_OCTET32_LEN);
  659. smp_debug_print_nbyte_little_endian(p_cb->dhkey, "Reverted DHKey",
  660. BT_OCTET32_LEN);
  661. }
  662. /** The function calculates and saves local commmitment in CB. */
  663. void smp_calculate_local_commitment(tSMP_CB* p_cb) {
  664. uint8_t random_input;
  665. SMP_TRACE_DEBUG("%s", __func__);
  666. switch (p_cb->selected_association_model) {
  667. case SMP_MODEL_SEC_CONN_JUSTWORKS:
  668. case SMP_MODEL_SEC_CONN_NUM_COMP:
  669. if (p_cb->role == HCI_ROLE_MASTER)
  670. SMP_TRACE_WARNING(
  671. "local commitment calc on master is not expected "
  672. "for Just Works/Numeric Comparison models");
  673. p_cb->commitment = crypto_toolbox::f4(
  674. p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, p_cb->rand, 0);
  675. break;
  676. case SMP_MODEL_SEC_CONN_PASSKEY_ENT:
  677. case SMP_MODEL_SEC_CONN_PASSKEY_DISP:
  678. random_input =
  679. smp_calculate_random_input(p_cb->local_random.data(), p_cb->round);
  680. p_cb->commitment =
  681. crypto_toolbox::f4(p_cb->loc_publ_key.x, p_cb->peer_publ_key.x,
  682. p_cb->rand, random_input);
  683. break;
  684. case SMP_MODEL_SEC_CONN_OOB:
  685. SMP_TRACE_WARNING(
  686. "local commitment calc is expected for OOB model BEFORE pairing");
  687. p_cb->commitment = crypto_toolbox::f4(
  688. p_cb->loc_publ_key.x, p_cb->loc_publ_key.x, p_cb->local_random, 0);
  689. break;
  690. default:
  691. SMP_TRACE_ERROR("Association Model = %d is not used in LE SC",
  692. p_cb->selected_association_model);
  693. return;
  694. }
  695. SMP_TRACE_EVENT("local commitment calculation is completed");
  696. }
  697. /** The function calculates peer commmitment */
  698. Octet16 smp_calculate_peer_commitment(tSMP_CB* p_cb) {
  699. uint8_t ri;
  700. SMP_TRACE_DEBUG("%s", __func__);
  701. Octet16 output;
  702. switch (p_cb->selected_association_model) {
  703. case SMP_MODEL_SEC_CONN_JUSTWORKS:
  704. case SMP_MODEL_SEC_CONN_NUM_COMP:
  705. if (p_cb->role == HCI_ROLE_SLAVE)
  706. SMP_TRACE_WARNING(
  707. "peer commitment calc on slave is not expected "
  708. "for Just Works/Numeric Comparison models");
  709. output = crypto_toolbox::f4(p_cb->peer_publ_key.x, p_cb->loc_publ_key.x,
  710. p_cb->rrand, 0);
  711. break;
  712. case SMP_MODEL_SEC_CONN_PASSKEY_ENT:
  713. case SMP_MODEL_SEC_CONN_PASSKEY_DISP:
  714. ri = smp_calculate_random_input(p_cb->peer_random.data(), p_cb->round);
  715. output = crypto_toolbox::f4(p_cb->peer_publ_key.x, p_cb->loc_publ_key.x,
  716. p_cb->rrand, ri);
  717. break;
  718. case SMP_MODEL_SEC_CONN_OOB:
  719. output = crypto_toolbox::f4(p_cb->peer_publ_key.x, p_cb->peer_publ_key.x,
  720. p_cb->peer_random, 0);
  721. break;
  722. default:
  723. SMP_TRACE_ERROR("Association Model = %d is not used in LE SC",
  724. p_cb->selected_association_model);
  725. return output;
  726. }
  727. SMP_TRACE_EVENT("peer commitment calculation is completed");
  728. return output;
  729. }
  730. /*******************************************************************************
  731. *
  732. * Function smp_calculate_numeric_comparison_display_number
  733. *
  734. * Description The function calculates and saves number to display in
  735. * numeric comparison association mode.
  736. *
  737. * Returns void
  738. *
  739. ******************************************************************************/
  740. void smp_calculate_numeric_comparison_display_number(tSMP_CB* p_cb,
  741. tSMP_INT_DATA* p_data) {
  742. SMP_TRACE_DEBUG("%s", __func__);
  743. if (p_cb->role == HCI_ROLE_MASTER) {
  744. p_cb->number_to_display = crypto_toolbox::g2(
  745. p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, p_cb->rand, p_cb->rrand);
  746. } else {
  747. p_cb->number_to_display = crypto_toolbox::g2(
  748. p_cb->peer_publ_key.x, p_cb->loc_publ_key.x, p_cb->rrand, p_cb->rand);
  749. }
  750. if (p_cb->number_to_display >= (BTM_MAX_PASSKEY_VAL + 1)) {
  751. tSMP_INT_DATA smp_int_data;
  752. smp_int_data.status = SMP_PAIR_FAIL_UNKNOWN;
  753. p_cb->failure = SMP_PAIR_FAIL_UNKNOWN;
  754. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
  755. return;
  756. }
  757. SMP_TRACE_EVENT("Number to display in numeric comparison = %d",
  758. p_cb->number_to_display);
  759. p_cb->cb_evt = SMP_NC_REQ_EVT;
  760. tSMP_INT_DATA smp_int_data;
  761. smp_int_data.passkey = p_cb->number_to_display;
  762. smp_sm_event(p_cb, SMP_SC_DSPL_NC_EVT, &smp_int_data);
  763. return;
  764. }
  765. /*******************************************************************************
  766. *
  767. * Function smp_calculate_local_dhkey_check
  768. *
  769. * Description The function calculates and saves local device DHKey check
  770. * value in CB.
  771. * Before doing this it calls
  772. * smp_calculate_f5_mackey_and_long_term_key(...).
  773. * to calculate MacKey and LTK.
  774. * MacKey is used in dhkey calculation.
  775. *
  776. * Returns void
  777. *
  778. ******************************************************************************/
  779. void smp_calculate_local_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  780. uint8_t iocap[3], a[7], b[7];
  781. SMP_TRACE_DEBUG("%s", __func__);
  782. smp_calculate_f5_mackey_and_long_term_key(p_cb);
  783. smp_collect_local_io_capabilities(iocap, p_cb);
  784. smp_collect_local_ble_address(a, p_cb);
  785. smp_collect_peer_ble_address(b, p_cb);
  786. p_cb->dhkey_check = crypto_toolbox::f6(p_cb->mac_key, p_cb->rand, p_cb->rrand,
  787. p_cb->peer_random, iocap, a, b);
  788. SMP_TRACE_EVENT("local DHKey check calculation is completed");
  789. }
  790. /*******************************************************************************
  791. *
  792. * Function smp_calculate_peer_dhkey_check
  793. *
  794. * Description The function calculates peer device DHKey check value.
  795. *
  796. * Returns void
  797. *
  798. ******************************************************************************/
  799. void smp_calculate_peer_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  800. uint8_t iocap[3], a[7], b[7];
  801. tSMP_KEY key;
  802. SMP_TRACE_DEBUG("%s", __func__);
  803. smp_collect_peer_io_capabilities(iocap, p_cb);
  804. smp_collect_local_ble_address(a, p_cb);
  805. smp_collect_peer_ble_address(b, p_cb);
  806. Octet16 param_buf = crypto_toolbox::f6(p_cb->mac_key, p_cb->rrand, p_cb->rand,
  807. p_cb->local_random, iocap, b, a);
  808. SMP_TRACE_EVENT("peer DHKey check calculation is completed");
  809. #if (SMP_DEBUG == TRUE)
  810. smp_debug_print_nbyte_little_endian(param_buf, "peer DHKey check",
  811. OCTET16_LEN);
  812. #endif
  813. key.key_type = SMP_KEY_TYPE_PEER_DHK_CHCK;
  814. key.p_data = param_buf.data();
  815. tSMP_INT_DATA smp_int_data;
  816. smp_int_data.key = key;
  817. smp_sm_event(p_cb, SMP_SC_KEY_READY_EVT, &smp_int_data);
  818. }
  819. /*******************************************************************************
  820. *
  821. * Function smp_calculate_link_key_from_long_term_key
  822. *
  823. * Description The function calculates and saves BR/EDR link key derived
  824. * from LE SC LTK.
  825. *
  826. * Returns false if out of resources, true in other cases.
  827. *
  828. ******************************************************************************/
  829. bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {
  830. tBTM_SEC_DEV_REC* p_dev_rec;
  831. RawAddress bda_for_lk;
  832. tBLE_ADDR_TYPE conn_addr_type;
  833. SMP_TRACE_DEBUG("%s", __func__);
  834. if (p_cb->id_addr_rcvd && p_cb->id_addr_type == BLE_ADDR_PUBLIC) {
  835. SMP_TRACE_DEBUG(
  836. "Use rcvd identity address as BD_ADDR of LK rcvd identity address");
  837. bda_for_lk = p_cb->id_addr;
  838. } else if ((BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, bda_for_lk,
  839. &conn_addr_type)) &&
  840. conn_addr_type == BLE_ADDR_PUBLIC) {
  841. SMP_TRACE_DEBUG("Use rcvd connection address as BD_ADDR of LK");
  842. } else {
  843. SMP_TRACE_WARNING("Don't have peer public address to associate with LK");
  844. return false;
  845. }
  846. p_dev_rec = btm_find_dev(p_cb->pairing_bda);
  847. if (p_dev_rec == NULL) {
  848. SMP_TRACE_ERROR("%s failed to find Security Record", __func__);
  849. return false;
  850. }
  851. Octet16 link_key =
  852. crypto_toolbox::ltk_to_link_key(p_cb->ltk, p_cb->key_derivation_h7_used);
  853. uint8_t link_key_type;
  854. if (btm_cb.security_mode == BTM_SEC_MODE_SC) {
  855. /* Secure Connections Only Mode */
  856. link_key_type = BTM_LKEY_TYPE_AUTH_COMB_P_256;
  857. } else if (controller_get_interface()->supports_secure_connections()) {
  858. /* both transports are SC capable */
  859. if (p_cb->sec_level == SMP_SEC_AUTHENTICATED)
  860. link_key_type = BTM_LKEY_TYPE_AUTH_COMB_P_256;
  861. else
  862. link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB_P_256;
  863. } else if (btm_cb.security_mode == BTM_SEC_MODE_SP) {
  864. /* BR/EDR transport is SSP capable */
  865. if (p_cb->sec_level == SMP_SEC_AUTHENTICATED)
  866. link_key_type = BTM_LKEY_TYPE_AUTH_COMB;
  867. else
  868. link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB;
  869. } else {
  870. SMP_TRACE_ERROR("%s failed to update link_key. Sec Mode = %d, sm4 = 0x%02x",
  871. __func__, btm_cb.security_mode, p_dev_rec->sm4);
  872. return false;
  873. }
  874. link_key_type += BTM_LTK_DERIVED_LKEY_OFFSET;
  875. Octet16 notif_link_key = link_key;
  876. btm_sec_link_key_notification(bda_for_lk, notif_link_key, link_key_type);
  877. SMP_TRACE_EVENT("%s is completed", __func__);
  878. return true;
  879. }
  880. /** The function calculates and saves SC LTK derived from BR/EDR link key. */
  881. bool smp_calculate_long_term_key_from_link_key(tSMP_CB* p_cb) {
  882. tBTM_SEC_DEV_REC* p_dev_rec;
  883. SMP_TRACE_DEBUG("%s", __func__);
  884. p_dev_rec = btm_find_dev(p_cb->pairing_bda);
  885. if (p_dev_rec == NULL) {
  886. SMP_TRACE_ERROR("%s failed to find Security Record", __func__);
  887. return false;
  888. }
  889. uint8_t br_link_key_type;
  890. br_link_key_type = BTM_SecGetDeviceLinkKeyType(p_cb->pairing_bda);
  891. if (br_link_key_type == BTM_LKEY_TYPE_IGNORE) {
  892. SMP_TRACE_ERROR("%s failed to retrieve BR link type", __func__);
  893. return false;
  894. }
  895. if ((br_link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256) &&
  896. (br_link_key_type != BTM_LKEY_TYPE_UNAUTH_COMB_P_256)) {
  897. SMP_TRACE_ERROR("%s LE SC LTK can't be derived from LK %d", __func__,
  898. br_link_key_type);
  899. return false;
  900. }
  901. Octet16 rev_link_key;
  902. std::reverse_copy(p_dev_rec->link_key.begin(), p_dev_rec->link_key.end(),
  903. rev_link_key.begin());
  904. p_cb->ltk = crypto_toolbox::link_key_to_ltk(rev_link_key,
  905. p_cb->key_derivation_h7_used);
  906. p_cb->sec_level = (br_link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256)
  907. ? SMP_SEC_AUTHENTICATED
  908. : SMP_SEC_UNAUTHENTICATE;
  909. SMP_TRACE_EVENT("%s is completed", __func__);
  910. return true;
  911. }
  912. /**
  913. * This function generates nonce.
  914. */
  915. void smp_start_nonce_generation(tSMP_CB* p_cb) {
  916. SMP_TRACE_DEBUG("%s", __func__);
  917. btsnd_hcic_ble_rand(Bind(
  918. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  919. memcpy(p_cb->rand.data(), rand, BT_OCTET8_LEN);
  920. btsnd_hcic_ble_rand(Bind(
  921. [](tSMP_CB* p_cb, BT_OCTET8 rand) {
  922. memcpy(p_cb->rand.data() + 8, rand, BT_OCTET8_LEN);
  923. SMP_TRACE_DEBUG("%s round %d", __func__, p_cb->round);
  924. /* notifies SM that it has new nonce. */
  925. smp_sm_event(p_cb, SMP_HAVE_LOC_NONCE_EVT, NULL);
  926. },
  927. p_cb));
  928. },
  929. p_cb));
  930. }