From: Tudor Ambarus <tudor.ambarus@microchip.com>
To: Romain Izard <romain.izard.pro@gmail.com>
Cc: <linux-crypto@vger.kernel.org>,
linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
Cyrille Pitchen <cyrille.pitchen@atmel.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Nicolas Ferre <nicolas.ferre@microchip.com>
Subject: Re: Kernel panic when using ccm(aes) with the Atmel AES HW accelerator
Date: Tue, 24 Oct 2017 18:25:08 +0300 [thread overview]
Message-ID: <16357069-115f-ba62-d32b-baaed3aa6dfd@microchip.com> (raw)
In-Reply-To: <CAGkQfmP6Kq4DEBbGU7AW71PjbUJ2acdJF5PVDm6VqZkUaaoEzA@mail.gmail.com>
Hi, Romain,
On 10/18/2017 04:32 PM, Romain Izard wrote:
> diff --git a/crypto/ccm.c b/crypto/ccm.c
> index 1ce37ae0ce56..e7c2121a3ab2 100644
> --- a/crypto/ccm.c
> +++ b/crypto/ccm.c
> @@ -47,6 +47,7 @@ struct crypto_ccm_req_priv_ctx {
> u8 odata[16];
> u8 idata[16];
> u8 auth_tag[16];
> + u8 iv[16];
> u32 flags;
> struct scatterlist src[3];
> struct scatterlist dst[3];
> @@ -248,32 +249,22 @@ static void crypto_ccm_encrypt_done(struct
> crypto_async_request *areq, int err)
> aead_request_complete(req, err);
> }
>
> -static inline int crypto_ccm_check_iv(const u8 *iv)
> -{
> - /* 2 <= L <= 8, so 1 <= L' <= 7. */
> - if (1 > iv[0] || iv[0] > 7)
> - return -EINVAL;
> -
> - return 0;
> -}
> -
> -static int crypto_ccm_init_crypt(struct aead_request *req, u8 *tag)
> +static int crypto_ccm_init_crypt(struct aead_request *req, u8 *tag, u8* iv)
> {
> struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
> struct scatterlist *sg;
> - u8 *iv = req->iv;
> - int err;
> + u8 L = req->iv[0] + 1;
>
> - err = crypto_ccm_check_iv(iv);
> - if (err)
> - return err;
> -
> - pctx->flags = aead_request_flags(req);
> + if (2 > L || L > 8)
> + return -EINVAL;
>
> /* Note: rfc 3610 and NIST 800-38C require counter of
> * zero to encrypt auth tag.
> */
> - memset(iv + 15 - iv[0], 0, iv[0] + 1);
> + memcpy(iv, req->iv, 16 - L);
> + memset(iv + 16 - L, 0, L);
> +
> + pctx->flags = aead_request_flags(req);
>
> sg_init_table(pctx->src, 3);
> sg_set_buf(pctx->src, tag, 16);
> @@ -301,10 +292,10 @@ static int crypto_ccm_encrypt(struct aead_request *req)
> struct scatterlist *dst;
> unsigned int cryptlen = req->cryptlen;
> u8 *odata = pctx->odata;
> - u8 *iv = req->iv;
> + u8 *iv = pctx->iv;
> int err;
>
> - err = crypto_ccm_init_crypt(req, odata);
> + err = crypto_ccm_init_crypt(req, odata, iv);
> if (err)
> return err;
>
> @@ -363,12 +354,12 @@ static int crypto_ccm_decrypt(struct aead_request *req)
> unsigned int cryptlen = req->cryptlen;
> u8 *authtag = pctx->auth_tag;
> u8 *odata = pctx->odata;
> - u8 *iv = req->iv;
> + u8 *iv = pctx->iv;
> int err;
>
> cryptlen -= authsize;
>
> - err = crypto_ccm_init_crypt(req, authtag);
> + err = crypto_ccm_init_crypt(req, authtag, iv);
> if (err)
> return err;
Looks good. Can you please submit with a commit message?
Thanks,
ta
next prev parent reply other threads:[~2017-10-24 15:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-18 13:32 Kernel panic when using ccm(aes) with the Atmel AES HW accelerator Romain Izard
2017-10-23 12:38 ` Tudor Ambarus
2017-10-24 3:20 ` Herbert Xu
2017-10-24 9:30 ` Romain Izard
2017-10-24 15:25 ` Tudor Ambarus [this message]
2017-10-26 12:34 ` Tudor Ambarus
2017-10-27 12:02 ` Romain Izard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16357069-115f-ba62-d32b-baaed3aa6dfd@microchip.com \
--to=tudor.ambarus@microchip.com \
--cc=cyrille.pitchen@atmel.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=romain.izard.pro@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox