Return-Path: From: Andrei Emeltchenko To: linux-bluetooth@vger.kernel.org Subject: [RFCv1 16/20] Bluetooth: Add function to derive AMP key using hmac Date: Fri, 13 Jul 2012 16:39:18 +0300 Message-Id: <1342186762-32329-17-git-send-email-Andrei.Emeltchenko.news@gmail.com> In-Reply-To: <1342186762-32329-1-git-send-email-Andrei.Emeltchenko.news@gmail.com> References: <1340981212-21709-1-git-send-email-Andrei.Emeltchenko.news@gmail.com> <1342186762-32329-1-git-send-email-Andrei.Emeltchenko.news@gmail.com> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: From: Dmitry Kasatkin hmac(sha256) will be used for AMP key generation. Signed-off-by: Dmitry Kasatkin Signed-off-by: Andrei Emeltchenko --- net/bluetooth/pal.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/net/bluetooth/pal.c b/net/bluetooth/pal.c index 440f5bf..e9bab6c 100644 --- a/net/bluetooth/pal.c +++ b/net/bluetooth/pal.c @@ -12,6 +12,7 @@ */ #include +#include enum pal_states { DISCONNECTED, @@ -220,3 +221,37 @@ struct phy_link *phylink_lookup(struct amp_mgr *mgr, u8 local_id, u8 remote_id) return found; } + +int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output) +{ + int ret = 0; + struct crypto_shash *tfm; + + tfm = crypto_alloc_shash("hmac(sha256)", 0, 0); + if (IS_ERR(tfm)) { + BT_DBG("crypto_alloc_ahash failed"); + return PTR_ERR(tfm); + } + + if (ksize) { + ret = crypto_shash_setkey(tfm, key, ksize); + if (ret) { + BT_DBG("crypto_ahash_setkey failed"); + } 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); + } + } + + BT_DBG("ret 0x%x", ret); + crypto_free_shash(tfm); + return ret; +} -- 1.7.9.5