All of lore.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: [PATCH 29/30] crypto: aes-ce-ccm - Use skcipher walk interface
Date: Tue, 12 Jul 2016 13:18:02 +0800	[thread overview]
Message-ID: <E1bMq54-0007Vj-SY@gondolin.me.apana.org.au> (raw)
In-Reply-To: 20160712051554.GA28324@gondor.apana.org.au

This patch makes use of the new skcipher walk interface instead of
the obsolete blkcipher walk interface.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 arch/arm64/crypto/aes-ce-ccm-glue.c |   50 +++++++++---------------------------
 1 file changed, 13 insertions(+), 37 deletions(-)

diff --git a/arch/arm64/crypto/aes-ce-ccm-glue.c b/arch/arm64/crypto/aes-ce-ccm-glue.c
index f4bf2f2..d4f3568 100644
--- a/arch/arm64/crypto/aes-ce-ccm-glue.c
+++ b/arch/arm64/crypto/aes-ce-ccm-glue.c
@@ -11,9 +11,9 @@
 #include <asm/neon.h>
 #include <asm/unaligned.h>
 #include <crypto/aes.h>
-#include <crypto/algapi.h>
 #include <crypto/scatterwalk.h>
 #include <crypto/internal/aead.h>
+#include <crypto/internal/skcipher.h>
 #include <linux/module.h>
 
 #include "aes-ce-setkey.h"
@@ -149,12 +149,7 @@ static int ccm_encrypt(struct aead_request *req)
 {
 	struct crypto_aead *aead = crypto_aead_reqtfm(req);
 	struct crypto_aes_ctx *ctx = crypto_aead_ctx(aead);
-	struct blkcipher_desc desc = { .info = req->iv };
-	struct blkcipher_walk walk;
-	struct scatterlist srcbuf[2];
-	struct scatterlist dstbuf[2];
-	struct scatterlist *src;
-	struct scatterlist *dst;
+	struct skcipher_walk walk;
 	u8 __aligned(8) mac[AES_BLOCK_SIZE];
 	u8 buf[AES_BLOCK_SIZE];
 	u32 len = req->cryptlen;
@@ -172,27 +167,19 @@ static int ccm_encrypt(struct aead_request *req)
 	/* preserve the original iv for the final round */
 	memcpy(buf, req->iv, AES_BLOCK_SIZE);
 
-	src = scatterwalk_ffwd(srcbuf, req->src, req->assoclen);
-	dst = src;
-	if (req->src != req->dst)
-		dst = scatterwalk_ffwd(dstbuf, req->dst, req->assoclen);
-
-	blkcipher_walk_init(&walk, dst, src, len);
-	err = blkcipher_aead_walk_virt_block(&desc, &walk, aead,
-					     AES_BLOCK_SIZE);
+	err = skcipher_walk_aead(&walk, req, true);
 
 	while (walk.nbytes) {
 		u32 tail = walk.nbytes % AES_BLOCK_SIZE;
 
-		if (walk.nbytes == len)
+		if (walk.nbytes == walk.total)
 			tail = 0;
 
 		ce_aes_ccm_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
 				   walk.nbytes - tail, ctx->key_enc,
 				   num_rounds(ctx), mac, walk.iv);
 
-		len -= walk.nbytes - tail;
-		err = blkcipher_walk_done(&desc, &walk, tail);
+		err = skcipher_walk_done(&walk, tail);
 	}
 	if (!err)
 		ce_aes_ccm_final(mac, buf, ctx->key_enc, num_rounds(ctx));
@@ -203,7 +190,7 @@ static int ccm_encrypt(struct aead_request *req)
 		return err;
 
 	/* copy authtag to end of dst */
-	scatterwalk_map_and_copy(mac, dst, req->cryptlen,
+	scatterwalk_map_and_copy(mac, req->dst, req->assoclen + req->cryptlen,
 				 crypto_aead_authsize(aead), 1);
 
 	return 0;
@@ -214,12 +201,7 @@ static int ccm_decrypt(struct aead_request *req)
 	struct crypto_aead *aead = crypto_aead_reqtfm(req);
 	struct crypto_aes_ctx *ctx = crypto_aead_ctx(aead);
 	unsigned int authsize = crypto_aead_authsize(aead);
-	struct blkcipher_desc desc = { .info = req->iv };
-	struct blkcipher_walk walk;
-	struct scatterlist srcbuf[2];
-	struct scatterlist dstbuf[2];
-	struct scatterlist *src;
-	struct scatterlist *dst;
+	struct skcipher_walk walk;
 	u8 __aligned(8) mac[AES_BLOCK_SIZE];
 	u8 buf[AES_BLOCK_SIZE];
 	u32 len = req->cryptlen - authsize;
@@ -237,27 +219,19 @@ static int ccm_decrypt(struct aead_request *req)
 	/* preserve the original iv for the final round */
 	memcpy(buf, req->iv, AES_BLOCK_SIZE);
 
-	src = scatterwalk_ffwd(srcbuf, req->src, req->assoclen);
-	dst = src;
-	if (req->src != req->dst)
-		dst = scatterwalk_ffwd(dstbuf, req->dst, req->assoclen);
-
-	blkcipher_walk_init(&walk, dst, src, len);
-	err = blkcipher_aead_walk_virt_block(&desc, &walk, aead,
-					     AES_BLOCK_SIZE);
+	err = skcipher_walk_aead(&walk, req, true);
 
 	while (walk.nbytes) {
 		u32 tail = walk.nbytes % AES_BLOCK_SIZE;
 
-		if (walk.nbytes == len)
+		if (walk.nbytes == walk.total)
 			tail = 0;
 
 		ce_aes_ccm_decrypt(walk.dst.virt.addr, walk.src.virt.addr,
 				   walk.nbytes - tail, ctx->key_enc,
 				   num_rounds(ctx), mac, walk.iv);
 
-		len -= walk.nbytes - tail;
-		err = blkcipher_walk_done(&desc, &walk, tail);
+		err = skcipher_walk_done(&walk, tail);
 	}
 	if (!err)
 		ce_aes_ccm_final(mac, buf, ctx->key_enc, num_rounds(ctx));
@@ -268,7 +242,8 @@ static int ccm_decrypt(struct aead_request *req)
 		return err;
 
 	/* compare calculated auth tag with the stored one */
-	scatterwalk_map_and_copy(buf, src, req->cryptlen - authsize,
+	scatterwalk_map_and_copy(buf, req->src,
+				 req->assoclen + req->cryptlen - authsize,
 				 authsize, 0);
 
 	if (crypto_memneq(mac, buf, authsize))
@@ -287,6 +262,7 @@ static struct aead_alg ccm_aes_alg = {
 		.cra_module		= THIS_MODULE,
 	},
 	.ivsize		= AES_BLOCK_SIZE,
+	.chunksize	= AES_BLOCK_SIZE,
 	.maxauthsize	= AES_BLOCK_SIZE,
 	.setkey		= ccm_setkey,
 	.setauthsize	= ccm_setauthsize,

  parent reply	other threads:[~2016-07-12  5:18 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-12  5:15 [PATCH 0/30] crypto: skcipher - skcipher algorithm conversion part 2 Herbert Xu
2016-07-12  5:17 ` [PATCH 1/30] crypto: skcipher - Add low-level skcipher interface Herbert Xu
2016-07-12  5:17 ` [PATCH 2/30] crypto: null - Add new default null skcipher Herbert Xu
2016-07-12  5:17 ` [PATCH 3/30] crypto: aead - Add chunk size Herbert Xu
2016-07-12  5:17 ` [PATCH 4/30] crypto: authenc - Use skcipher Herbert Xu
2016-07-12  5:17 ` [PATCH 5/30] crypto: authencesn " Herbert Xu
2016-07-12  5:17 ` [PATCH 6/30] crypto: ctr - Use skcipher in rfc3686 Herbert Xu
2016-07-12  5:17 ` [PATCH 7/30] crypto: ccm - Use skcipher Herbert Xu
2016-07-12  5:17 ` [PATCH 8/30] crypto: gcm " Herbert Xu
2016-07-12  5:17 ` [PATCH 9/30] crypto: chacha20poly1305 " Herbert Xu
2016-07-12  5:17 ` [PATCH 10/30] crypto: cryptd - Add support for skcipher Herbert Xu
2016-07-12  5:17 ` [PATCH 11/30] crypto: aead - Add skcipher null for IV generators Herbert Xu
2016-07-12  5:17 ` [PATCH 12/30] crypto: echainiv - Use skcipher Herbert Xu
2016-07-12  5:17 ` [PATCH 13/30] crypto: seqiv " Herbert Xu
2016-07-12  5:17 ` [PATCH 14/30] crypto: aead - Remove blkcipher null for IV generators Herbert Xu
2016-07-12  5:17 ` [PATCH 15/30] crypto: null - Remove default null blkcipher Herbert Xu
2016-07-12  5:17 ` [PATCH 16/30] crypto: cts - Convert to skcipher Herbert Xu
2016-07-12  5:17 ` [PATCH 17/30] crypto: user - Remove crypto_lookup_skcipher call Herbert Xu
2016-07-12  5:17 ` [PATCH 18/30] crypto: skcipher - Remove top-level givcipher interface Herbert Xu
2016-07-12  5:17 ` [PATCH 19/30] crypto: simd - Add simd skcipher helper Herbert Xu
2016-07-12  5:17 ` [PATCH 20/30] crypto: omap - Stop using crypto scatterwalk_bytes_sglen Herbert Xu
2016-07-12  5:17 ` [PATCH 21/30] crypto: scatterwalk - Remove scatterwalk_bytes_sglen Herbert Xu
2016-07-12  5:17 ` [PATCH 22/30] crypto: scatterwalk - Add no-copy support to copychunks Herbert Xu
2016-07-12  5:17 ` [PATCH 23/30] crypto: api - Optimise away crypto_yield when hard preemption is on Herbert Xu
2016-07-12  5:17 ` [PATCH 24/30] crypto: scatterwalk - Fix test in scatterwalk_done Herbert Xu
2016-07-12  5:17 ` [PATCH 25/30] crypto: scatterwalk - Remove unnecessary advance in scatterwalk_pagedone Herbert Xu
2016-07-12  5:17 ` [PATCH 26/30] crypto: scatterwalk - Remove unnecessary BUG in scatterwalk_start Herbert Xu
2016-07-12  5:18 ` [PATCH 27/30] crypto: scatterwalk - Inline start/map/done Herbert Xu
2016-07-12  5:18 ` [PATCH 28/30] crypto: skcipher - Add skcipher walk interface Herbert Xu
2016-07-12  5:18 ` Herbert Xu [this message]
2016-07-12  5:18 ` [PATCH 30/30] crypto: lrw - Convert to skcipher 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=E1bMq54-0007Vj-SY@gondolin.me.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.