aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-02-18 14:41:31 -0500
committerMarcel Holtmann <marcel@holtmann.org>2014-02-18 14:48:54 -0500
commit893ce8b1b3d92cbddcf34bb92c7d24720efc7fed (patch)
tree68416c7883b79fbcb40e7a6a5828ebbe6a3d0796
parenta735f9e22432899cee188d167966782c29246390 (diff)
Bluetooth: Remove SMP data specific crypto context
Now that each HCI device has its own AES crypto context we don't need the one stored in the SMP data any more. This patch removes the variable from struct smp_chan and updates the SMP code to use the per-hdev crypto context. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--net/bluetooth/smp.c27
-rw-r--r--net/bluetooth/smp.h1
2 files changed, 15 insertions, 13 deletions
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 0c0dd1b52b66..8517d1f0984d 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -413,20 +413,16 @@ static void confirm_work(struct work_struct *work)
413{ 413{
414 struct smp_chan *smp = container_of(work, struct smp_chan, confirm); 414 struct smp_chan *smp = container_of(work, struct smp_chan, confirm);
415 struct l2cap_conn *conn = smp->conn; 415 struct l2cap_conn *conn = smp->conn;
416 struct crypto_blkcipher *tfm; 416 struct hci_dev *hdev = conn->hcon->hdev;
417 struct crypto_blkcipher *tfm = hdev->tfm_aes;
417 struct smp_cmd_pairing_confirm cp; 418 struct smp_cmd_pairing_confirm cp;
418 int ret; 419 int ret;
419 u8 res[16], reason; 420 u8 res[16], reason;
420 421
421 BT_DBG("conn %p", conn); 422 BT_DBG("conn %p", conn);
422 423
423 tfm = crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC); 424 /* Prevent mutual access to hdev->tfm_aes */
424 if (IS_ERR(tfm)) { 425 hci_dev_lock(hdev);
425 reason = SMP_UNSPECIFIED;
426 goto error;
427 }
428
429 smp->tfm = tfm;
430 426
431 if (conn->hcon->out) 427 if (conn->hcon->out)
432 ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, 428 ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp,
@@ -436,6 +432,9 @@ static void confirm_work(struct work_struct *work)
436 ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, 432 ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp,
437 conn->hcon->dst_type, &conn->hcon->dst, 433 conn->hcon->dst_type, &conn->hcon->dst,
438 conn->hcon->src_type, &conn->hcon->src, res); 434 conn->hcon->src_type, &conn->hcon->src, res);
435
436 hci_dev_unlock(hdev);
437
439 if (ret) { 438 if (ret) {
440 reason = SMP_UNSPECIFIED; 439 reason = SMP_UNSPECIFIED;
441 goto error; 440 goto error;
@@ -457,7 +456,8 @@ static void random_work(struct work_struct *work)
457 struct smp_chan *smp = container_of(work, struct smp_chan, random); 456 struct smp_chan *smp = container_of(work, struct smp_chan, random);
458 struct l2cap_conn *conn = smp->conn; 457 struct l2cap_conn *conn = smp->conn;
459 struct hci_conn *hcon = conn->hcon; 458 struct hci_conn *hcon = conn->hcon;
460 struct crypto_blkcipher *tfm = smp->tfm; 459 struct hci_dev *hdev = hcon->hdev;
460 struct crypto_blkcipher *tfm = hdev->tfm_aes;
461 u8 reason, confirm[16], res[16], key[16]; 461 u8 reason, confirm[16], res[16], key[16];
462 int ret; 462 int ret;
463 463
@@ -468,6 +468,9 @@ static void random_work(struct work_struct *work)
468 468
469 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave"); 469 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave");
470 470
471 /* Prevent mutual access to hdev->tfm_aes */
472 hci_dev_lock(hdev);
473
471 if (hcon->out) 474 if (hcon->out)
472 ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, 475 ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp,
473 hcon->src_type, &hcon->src, 476 hcon->src_type, &hcon->src,
@@ -476,6 +479,9 @@ static void random_work(struct work_struct *work)
476 ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, 479 ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp,
477 hcon->dst_type, &hcon->dst, 480 hcon->dst_type, &hcon->dst,
478 hcon->src_type, &hcon->src, res); 481 hcon->src_type, &hcon->src, res);
482
483 hci_dev_unlock(hdev);
484
479 if (ret) { 485 if (ret) {
480 reason = SMP_UNSPECIFIED; 486 reason = SMP_UNSPECIFIED;
481 goto error; 487 goto error;
@@ -562,9 +568,6 @@ void smp_chan_destroy(struct l2cap_conn *conn)
562 568
563 BUG_ON(!smp); 569 BUG_ON(!smp);
564 570
565 if (smp->tfm)
566 crypto_free_blkcipher(smp->tfm);
567
568 kfree(smp); 571 kfree(smp);
569 conn->smp_chan = NULL; 572 conn->smp_chan = NULL;
570 conn->hcon->smp_conn = NULL; 573 conn->hcon->smp_conn = NULL;
diff --git a/net/bluetooth/smp.h b/net/bluetooth/smp.h
index 4f373bc56ad7..8f54c9b152de 100644
--- a/net/bluetooth/smp.h
+++ b/net/bluetooth/smp.h
@@ -133,7 +133,6 @@ struct smp_chan {
133 u8 id_addr_type; 133 u8 id_addr_type;
134 u8 irk[16]; 134 u8 irk[16];
135 unsigned long smp_flags; 135 unsigned long smp_flags;
136 struct crypto_blkcipher *tfm;
137 struct work_struct confirm; 136 struct work_struct confirm;
138 struct work_struct random; 137 struct work_struct random;
139}; 138};