diff options
author | Dmitry Kasatkin <dmitry.kasatkin@intel.com> | 2012-09-27 17:26:17 +0300 |
---|---|---|
committer | Gustavo Padovan <gustavo.padovan@collabora.co.uk> | 2012-09-27 17:18:40 -0300 |
commit | ba221bbabadd5fc2c80677b52178138fd694cc26 (patch) | |
tree | 1da965299f2089b603d57e123129c83df79528c2 /net/bluetooth | |
parent | 93c3e8f5c9a0e4dc6b6c93108dcf3ec54ab1191a (diff) | |
download | linux-stable-ba221bbabadd5fc2c80677b52178138fd694cc26.tar.gz linux-stable-ba221bbabadd5fc2c80677b52178138fd694cc26.tar.bz2 linux-stable-ba221bbabadd5fc2c80677b52178138fd694cc26.zip |
Bluetooth: Add function to derive AMP key using hmac
hmac(sha256) will be used for AMP key generation.
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com>
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/amp.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c index 8ef912c36224..ea4d5ffc1151 100644 --- a/net/bluetooth/amp.c +++ b/net/bluetooth/amp.c @@ -16,6 +16,7 @@ #include <net/bluetooth/hci_core.h> #include <net/bluetooth/a2mp.h> #include <net/bluetooth/amp.h> +#include <crypto/hash.h> /* Remote AMP Controllers interface */ static void amp_ctrl_get(struct amp_ctrl *ctrl) @@ -125,6 +126,41 @@ struct hci_conn *phylink_add(struct hci_dev *hdev, struct amp_mgr *mgr, return hcon; } +/* AMP crypto key generation interface */ +static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output) +{ + int ret = 0; + struct crypto_shash *tfm; + + if (!ksize) + return -EINVAL; + + tfm = crypto_alloc_shash("hmac(sha256)", 0, 0); + if (IS_ERR(tfm)) { + BT_DBG("crypto_alloc_ahash failed: err %ld", PTR_ERR(tfm)); + return PTR_ERR(tfm); + } + + ret = crypto_shash_setkey(tfm, key, ksize); + if (ret) { + BT_DBG("crypto_ahash_setkey failed: err %d", ret); + } else { + struct { + struct shash_desc shash; + char ctx[crypto_shash_descsize(tfm)]; + } desc; + + desc.shash.tfm = tfm; + desc.shash.flags = CRYPTO_TFM_REQ_MAY_SLEEP; + + ret = crypto_shash_digest(&desc.shash, plaintext, psize, + output); + } + + crypto_free_shash(tfm); + return ret; +} + void amp_read_loc_assoc_frag(struct hci_dev *hdev, u8 phy_handle) { struct hci_cp_read_local_amp_assoc cp; |