Return-Path: Date: Tue, 24 Jul 2012 18:16:31 -0300 From: Gustavo Padovan To: Andrei Emeltchenko Cc: linux-bluetooth@vger.kernel.org Subject: Re: [RFCv2 13/20] Bluetooth: Add function to derive AMP key using hmac Message-ID: <20120724211631.GG20029@joana> References: <1340981212-21709-1-git-send-email-Andrei.Emeltchenko.news@gmail.com> <1343136121-22476-1-git-send-email-Andrei.Emeltchenko.news@gmail.com> <1343136121-22476-14-git-send-email-Andrei.Emeltchenko.news@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <1343136121-22476-14-git-send-email-Andrei.Emeltchenko.news@gmail.com> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: Hi Dmitry, * Andrei Emeltchenko [2012-07-24 16:21:54 +0300]: > 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 335cbc3..a405e88 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) { can you move the check for ksize to the beginning of the function? This avoid unnecessary calls to crypto_alloc_ahash() in case ksize is zero. Gustavo