Commit 99780a7b authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann

Bluetooth: Add AES crypto context for each HCI device

Previously the crypto context has only been available for LE SMP
sessions, but now that we'll need to perform operations also during
discovery it makes sense to have this context part of the hci_dev
struct. Later, the context can be removed from the SMP context.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 60478054
...@@ -259,6 +259,7 @@ struct hci_dev { ...@@ -259,6 +259,7 @@ struct hci_dev {
__u32 req_status; __u32 req_status;
__u32 req_result; __u32 req_result;
struct crypto_blkcipher *tfm_aes;
struct discovery_state discovery; struct discovery_state discovery;
struct hci_conn_hash conn_hash; struct hci_conn_hash conn_hash;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/rfkill.h> #include <linux/rfkill.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/crypto.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
#include <net/bluetooth/bluetooth.h> #include <net/bluetooth/bluetooth.h>
...@@ -3205,9 +3206,18 @@ int hci_register_dev(struct hci_dev *hdev) ...@@ -3205,9 +3206,18 @@ int hci_register_dev(struct hci_dev *hdev)
dev_set_name(&hdev->dev, "%s", hdev->name); dev_set_name(&hdev->dev, "%s", hdev->name);
hdev->tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0,
CRYPTO_ALG_ASYNC);
if (IS_ERR(hdev->tfm_aes)) {
BT_ERR("Unable to create crypto context");
error = PTR_ERR(hdev->tfm_aes);
hdev->tfm_aes = NULL;
goto err_wqueue;
}
error = device_add(&hdev->dev); error = device_add(&hdev->dev);
if (error < 0) if (error < 0)
goto err_wqueue; goto err_tfm;
hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev,
RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops, RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops,
...@@ -3243,6 +3253,8 @@ int hci_register_dev(struct hci_dev *hdev) ...@@ -3243,6 +3253,8 @@ int hci_register_dev(struct hci_dev *hdev)
return id; return id;
err_tfm:
crypto_free_blkcipher(hdev->tfm_aes);
err_wqueue: err_wqueue:
destroy_workqueue(hdev->workqueue); destroy_workqueue(hdev->workqueue);
destroy_workqueue(hdev->req_workqueue); destroy_workqueue(hdev->req_workqueue);
...@@ -3293,6 +3305,9 @@ void hci_unregister_dev(struct hci_dev *hdev) ...@@ -3293,6 +3305,9 @@ void hci_unregister_dev(struct hci_dev *hdev)
rfkill_destroy(hdev->rfkill); rfkill_destroy(hdev->rfkill);
} }
if (hdev->tfm_aes)
crypto_free_blkcipher(hdev->tfm_aes);
device_del(&hdev->dev); device_del(&hdev->dev);
debugfs_remove_recursive(hdev->debugfs); debugfs_remove_recursive(hdev->debugfs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment