From: Lokesh Vutla <lokeshvutla@ti.com>
To: <herbert@gondor.apana.org.au>, <linux-crypto@vger.kernel.org>,
<davem@davemloft.net>
Cc: <linux-omap@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<t-kristo@ti.com>, <nsekhar@ti.com>, <lokeshvutla@ti.com>
Subject: [PATCH 01/10] crypto: omap-aes: Add support for lengths not aligned with AES_BLOCK_SIZE
Date: Thu, 2 Jul 2015 10:48:31 +0530 [thread overview]
Message-ID: <1435814320-30347-2-git-send-email-lokeshvutla@ti.com> (raw)
In-Reply-To: <1435814320-30347-1-git-send-email-lokeshvutla@ti.com>
OMAP AES driver returns an error if the data is not aligned with
AES_BLOCK_SIZE bytes.
But OMAP AES hw allows data input upto 1 byte aligned, but still
zeros are to be appended and complete AES_BLOCK_SIZE has to be written.
And correct length has to be passed in LENGTH field.
Adding support for inputs not aligned with AES_BLOCK_SIZE.
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
---
drivers/crypto/omap-aes.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index 9a28b7e..a923101 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -558,6 +558,9 @@ static int omap_aes_check_aligned(struct scatterlist *sg, int total)
{
int len = 0;
+ if (!IS_ALIGNED(total, AES_BLOCK_SIZE))
+ return -1;
+
while (sg) {
if (!IS_ALIGNED(sg->offset, 4))
return -1;
@@ -577,9 +580,10 @@ static int omap_aes_check_aligned(struct scatterlist *sg, int total)
static int omap_aes_copy_sgs(struct omap_aes_dev *dd)
{
void *buf_in, *buf_out;
- int pages;
+ int pages, total;
- pages = get_order(dd->total);
+ total = ALIGN(dd->total, AES_BLOCK_SIZE);
+ pages = get_order(total);
buf_in = (void *)__get_free_pages(GFP_ATOMIC, pages);
buf_out = (void *)__get_free_pages(GFP_ATOMIC, pages);
@@ -594,11 +598,11 @@ static int omap_aes_copy_sgs(struct omap_aes_dev *dd)
sg_copy_buf(buf_in, dd->in_sg, 0, dd->total, 0);
sg_init_table(&dd->in_sgl, 1);
- sg_set_buf(&dd->in_sgl, buf_in, dd->total);
+ sg_set_buf(&dd->in_sgl, buf_in, total);
dd->in_sg = &dd->in_sgl;
sg_init_table(&dd->out_sgl, 1);
- sg_set_buf(&dd->out_sgl, buf_out, dd->total);
+ sg_set_buf(&dd->out_sgl, buf_out, total);
dd->out_sg = &dd->out_sgl;
return 0;
@@ -611,7 +615,7 @@ static int omap_aes_handle_queue(struct omap_aes_dev *dd,
struct omap_aes_ctx *ctx;
struct omap_aes_reqctx *rctx;
unsigned long flags;
- int err, ret = 0;
+ int err, ret = 0, len;
spin_lock_irqsave(&dd->lock, flags);
if (req)
@@ -650,8 +654,9 @@ static int omap_aes_handle_queue(struct omap_aes_dev *dd,
dd->sgs_copied = 0;
}
- dd->in_sg_len = scatterwalk_bytes_sglen(dd->in_sg, dd->total);
- dd->out_sg_len = scatterwalk_bytes_sglen(dd->out_sg, dd->total);
+ len = ALIGN(dd->total, AES_BLOCK_SIZE);
+ dd->in_sg_len = scatterwalk_bytes_sglen(dd->in_sg, len);
+ dd->out_sg_len = scatterwalk_bytes_sglen(dd->out_sg, len);
BUG_ON(dd->in_sg_len < 0 || dd->out_sg_len < 0);
rctx = ablkcipher_request_ctx(req);
@@ -678,7 +683,7 @@ static void omap_aes_done_task(unsigned long data)
{
struct omap_aes_dev *dd = (struct omap_aes_dev *)data;
void *buf_in, *buf_out;
- int pages;
+ int pages, len;
pr_debug("enter done_task\n");
@@ -697,7 +702,8 @@ static void omap_aes_done_task(unsigned long data)
sg_copy_buf(buf_out, dd->orig_out, 0, dd->total_save, 1);
- pages = get_order(dd->total_save);
+ len = ALIGN(dd->total_save, AES_BLOCK_SIZE);
+ pages = get_order(len);
free_pages((unsigned long)buf_in, pages);
free_pages((unsigned long)buf_out, pages);
}
@@ -726,11 +732,6 @@ static int omap_aes_crypt(struct ablkcipher_request *req, unsigned long mode)
!!(mode & FLAGS_ENCRYPT),
!!(mode & FLAGS_CBC));
- if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE)) {
- pr_err("request size is not exact amount of AES blocks\n");
- return -EINVAL;
- }
-
dd = omap_aes_find_dev(ctx);
if (!dd)
return -ENODEV;
@@ -1046,9 +1047,7 @@ static irqreturn_t omap_aes_irq(int irq, void *dev_id)
}
}
- dd->total -= AES_BLOCK_SIZE;
-
- BUG_ON(dd->total < 0);
+ dd->total -= min_t(size_t, AES_BLOCK_SIZE, dd->total);
/* Clear IRQ status */
status &= ~AES_REG_IRQ_DATA_OUT;
--
1.7.9.5
next prev parent reply other threads:[~2015-07-02 5:22 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-02 5:18 [PATCH 00/10] crypto: omap-aes: Add support for GCM mode Lokesh Vutla
2015-07-02 5:18 ` Lokesh Vutla [this message]
2015-07-02 7:53 ` [PATCH 01/10] crypto: omap-aes: Add support for lengths not aligned with AES_BLOCK_SIZE Felipe Balbi
2015-07-02 9:26 ` Lokesh Vutla
2015-07-06 7:38 ` Herbert Xu
2015-07-02 5:18 ` [PATCH 02/10] crypto: omap-aes: Fix configuring of AES mode Lokesh Vutla
2015-07-02 7:57 ` Felipe Balbi
2015-07-02 9:43 ` Lokesh Vutla
2015-07-02 5:18 ` [PATCH 03/10] crypto: aead: Add aead_request_cast() api Lokesh Vutla
2015-07-02 7:58 ` Felipe Balbi
2015-07-02 9:46 ` Lokesh Vutla
2015-07-06 7:41 ` Herbert Xu
2015-07-02 5:18 ` [PATCH 04/10] crypto: omap-aes: Use BIT() macro Lokesh Vutla
2015-07-02 7:59 ` Felipe Balbi
2015-07-06 7:42 ` Herbert Xu
2015-07-02 5:18 ` [PATCH 05/10] crypto: omap-aes: Add support for GCM mode Lokesh Vutla
2015-07-02 8:04 ` Felipe Balbi
2015-07-02 10:10 ` Lokesh Vutla
2015-07-02 5:18 ` [PATCH 06/10] crypto: omap-aes: gcm: Handle inputs properly Lokesh Vutla
2015-07-02 8:04 ` Felipe Balbi
2015-07-02 10:13 ` Lokesh Vutla
2015-07-02 5:18 ` [PATCH 07/10] crypto: omap-aes: gcm: Add support for unaligned lengths Lokesh Vutla
2015-07-02 8:05 ` Felipe Balbi
2015-07-02 5:18 ` [PATCH 08/10] crypto: omap-aes: gmc: Add algo info Lokesh Vutla
2015-07-02 8:00 ` Stephan Mueller
2015-07-02 9:54 ` Lokesh Vutla
2015-07-02 9:56 ` Stephan Mueller
2015-07-06 7:35 ` Herbert Xu
2015-07-06 8:15 ` Lokesh Vutla
2015-07-02 5:18 ` [PATCH 09/10] crypto: omap-aes: gcm: Add support for PIO mode Lokesh Vutla
2015-07-02 8:06 ` Felipe Balbi
2015-07-02 10:17 ` Lokesh Vutla
2015-07-02 5:18 ` [PATCH 10/10] crypto: tcrypt: Added speed tests for Async AEAD crypto alogrithms Lokesh Vutla
2015-07-06 7:44 ` Herbert Xu
2015-07-06 8:45 ` Lokesh Vutla
2015-07-06 8:49 ` Herbert Xu
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=1435814320-30347-2-git-send-email-lokeshvutla@ti.com \
--to=lokeshvutla@ti.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=nsekhar@ti.com \
--cc=t-kristo@ti.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
all inboxes | Powered by JetHome®