aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/smp.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index f09b6b65cf6b..fea3782989f4 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -191,16 +191,13 @@ int smp_generate_rpa(struct hci_dev *hdev, u8 irk[16], bdaddr_t *rpa)
191 return 0; 191 return 0;
192} 192}
193 193
194static int smp_c1(struct smp_chan *smp, u8 k[16], u8 r[16], u8 preq[7], 194static int smp_c1(struct crypto_blkcipher *tfm_aes, u8 k[16], u8 r[16],
195 u8 pres[7], u8 _iat, bdaddr_t *ia, u8 _rat, bdaddr_t *ra, 195 u8 preq[7], u8 pres[7], u8 _iat, bdaddr_t *ia, u8 _rat,
196 u8 res[16]) 196 bdaddr_t *ra, u8 res[16])
197{ 197{
198 struct hci_dev *hdev = smp->conn->hcon->hdev;
199 u8 p1[16], p2[16]; 198 u8 p1[16], p2[16];
200 int err; 199 int err;
201 200
202 BT_DBG("%s", hdev->name);
203
204 memset(p1, 0, 16); 201 memset(p1, 0, 16);
205 202
206 /* p1 = pres || preq || _rat || _iat */ 203 /* p1 = pres || preq || _rat || _iat */
@@ -218,7 +215,7 @@ static int smp_c1(struct smp_chan *smp, u8 k[16], u8 r[16], u8 preq[7],
218 u128_xor((u128 *) res, (u128 *) r, (u128 *) p1); 215 u128_xor((u128 *) res, (u128 *) r, (u128 *) p1);
219 216
220 /* res = e(k, res) */ 217 /* res = e(k, res) */
221 err = smp_e(smp->tfm_aes, k, res); 218 err = smp_e(tfm_aes, k, res);
222 if (err) { 219 if (err) {
223 BT_ERR("Encrypt data error"); 220 BT_ERR("Encrypt data error");
224 return err; 221 return err;
@@ -228,26 +225,23 @@ static int smp_c1(struct smp_chan *smp, u8 k[16], u8 r[16], u8 preq[7],
228 u128_xor((u128 *) res, (u128 *) res, (u128 *) p2); 225 u128_xor((u128 *) res, (u128 *) res, (u128 *) p2);
229 226
230 /* res = e(k, res) */ 227 /* res = e(k, res) */
231 err = smp_e(smp->tfm_aes, k, res); 228 err = smp_e(tfm_aes, k, res);
232 if (err) 229 if (err)
233 BT_ERR("Encrypt data error"); 230 BT_ERR("Encrypt data error");
234 231
235 return err; 232 return err;
236} 233}
237 234
238static int smp_s1(struct smp_chan *smp, u8 k[16], u8 r1[16], u8 r2[16], 235static int smp_s1(struct crypto_blkcipher *tfm_aes, u8 k[16], u8 r1[16],
239 u8 _r[16]) 236 u8 r2[16], u8 _r[16])
240{ 237{
241 struct hci_dev *hdev = smp->conn->hcon->hdev;
242 int err; 238 int err;
243 239
244 BT_DBG("%s", hdev->name);
245
246 /* Just least significant octets from r1 and r2 are considered */ 240 /* Just least significant octets from r1 and r2 are considered */
247 memcpy(_r, r2, 8); 241 memcpy(_r, r2, 8);
248 memcpy(_r + 8, r1, 8); 242 memcpy(_r + 8, r1, 8);
249 243
250 err = smp_e(smp->tfm_aes, k, _r); 244 err = smp_e(tfm_aes, k, _r);
251 if (err) 245 if (err)
252 BT_ERR("Encrypt data error"); 246 BT_ERR("Encrypt data error");
253 247
@@ -547,7 +541,7 @@ static u8 smp_confirm(struct smp_chan *smp)
547 541
548 BT_DBG("conn %p", conn); 542 BT_DBG("conn %p", conn);
549 543
550 ret = smp_c1(smp, smp->tk, smp->prnd, smp->preq, smp->prsp, 544 ret = smp_c1(smp->tfm_aes, smp->tk, smp->prnd, smp->preq, smp->prsp,
551 conn->hcon->init_addr_type, &conn->hcon->init_addr, 545 conn->hcon->init_addr_type, &conn->hcon->init_addr,
552 conn->hcon->resp_addr_type, &conn->hcon->resp_addr, 546 conn->hcon->resp_addr_type, &conn->hcon->resp_addr,
553 cp.confirm_val); 547 cp.confirm_val);
@@ -578,7 +572,7 @@ static u8 smp_random(struct smp_chan *smp)
578 572
579 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave"); 573 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave");
580 574
581 ret = smp_c1(smp, smp->tk, smp->rrnd, smp->preq, smp->prsp, 575 ret = smp_c1(smp->tfm_aes, smp->tk, smp->rrnd, smp->preq, smp->prsp,
582 hcon->init_addr_type, &hcon->init_addr, 576 hcon->init_addr_type, &hcon->init_addr,
583 hcon->resp_addr_type, &hcon->resp_addr, confirm); 577 hcon->resp_addr_type, &hcon->resp_addr, confirm);
584 if (ret) 578 if (ret)
@@ -594,7 +588,7 @@ static u8 smp_random(struct smp_chan *smp)
594 __le64 rand = 0; 588 __le64 rand = 0;
595 __le16 ediv = 0; 589 __le16 ediv = 0;
596 590
597 smp_s1(smp, smp->tk, smp->rrnd, smp->prnd, stk); 591 smp_s1(smp->tfm_aes, smp->tk, smp->rrnd, smp->prnd, stk);
598 592
599 memset(stk + smp->enc_key_size, 0, 593 memset(stk + smp->enc_key_size, 0,
600 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); 594 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size);
@@ -613,7 +607,7 @@ static u8 smp_random(struct smp_chan *smp)
613 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), 607 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd),
614 smp->prnd); 608 smp->prnd);
615 609
616 smp_s1(smp, smp->tk, smp->prnd, smp->rrnd, stk); 610 smp_s1(smp->tfm_aes, smp->tk, smp->prnd, smp->rrnd, stk);
617 611
618 memset(stk + smp->enc_key_size, 0, 612 memset(stk + smp->enc_key_size, 0,
619 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); 613 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size);