All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: linux-crypto@vger.kernel.org
Cc: herbert@gondor.apana.org.au, ebiggers@kernel.org,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [RFC PATCH 18/20] crypto: arm/aes-ce - provide a synchronous version of ctr(aes)
Date: Wed, 12 Jun 2019 14:48:36 +0200	[thread overview]
Message-ID: <20190612124838.2492-19-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20190612124838.2492-1-ard.biesheuvel@linaro.org>

AES in CTR mode is used by modes such as GCM and CCM, which are often
used in contexts where only synchronous ciphers are permitted. So
provide a synchronous version of ctr(aes) based on the existing code.
This requires a non-SIMD fallback to deal with invocations occurring
from a context where SIMD instructions may not be used. We have a
helper for this now in the AES library, so wire that up.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm/crypto/aes-ce-glue.c | 36 ++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/arch/arm/crypto/aes-ce-glue.c b/arch/arm/crypto/aes-ce-glue.c
index 04ba66903674..cdcc4b09e7db 100644
--- a/arch/arm/crypto/aes-ce-glue.c
+++ b/arch/arm/crypto/aes-ce-glue.c
@@ -10,6 +10,7 @@
 
 #include <asm/hwcap.h>
 #include <asm/neon.h>
+#include <asm/simd.h>
 #include <crypto/aes.h>
 #include <crypto/internal/simd.h>
 #include <crypto/internal/skcipher.h>
@@ -292,6 +293,23 @@ static int ctr_encrypt(struct skcipher_request *req)
 	return err;
 }
 
+static int ctr_encrypt_sync(struct skcipher_request *req)
+{
+	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
+	struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
+
+	if (!crypto_simd_usable()) {
+		struct skcipher_walk walk;
+		int err;
+
+		err = skcipher_walk_virt(&walk, req, true);
+		if (err)
+			return err;
+		return skcipher_encrypt_aes_ctr(&walk, ctx);
+	}
+	return ctr_encrypt(req);
+}
+
 static int xts_encrypt(struct skcipher_request *req)
 {
 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
@@ -381,6 +399,21 @@ static struct skcipher_alg aes_algs[] = { {
 	.setkey			= ce_aes_setkey,
 	.encrypt		= ctr_encrypt,
 	.decrypt		= ctr_encrypt,
+}, {
+	.base.cra_name		= "ctr(aes)",
+	.base.cra_driver_name	= "ctr-aes-ce-sync",
+	.base.cra_priority	= 300 - 1,
+	.base.cra_blocksize	= 1,
+	.base.cra_ctxsize	= sizeof(struct crypto_aes_ctx),
+	.base.cra_module	= THIS_MODULE,
+
+	.min_keysize		= AES_MIN_KEY_SIZE,
+	.max_keysize		= AES_MAX_KEY_SIZE,
+	.ivsize			= AES_BLOCK_SIZE,
+	.chunksize		= AES_BLOCK_SIZE,
+	.setkey			= ce_aes_setkey,
+	.encrypt		= ctr_encrypt_sync,
+	.decrypt		= ctr_encrypt_sync,
 }, {
 	.base.cra_name		= "__xts(aes)",
 	.base.cra_driver_name	= "__xts-aes-ce",
@@ -424,6 +457,9 @@ static int __init aes_init(void)
 		return err;
 
 	for (i = 0; i < ARRAY_SIZE(aes_algs); i++) {
+		if (!(aes_algs[i].base.cra_flags & CRYPTO_ALG_INTERNAL))
+			continue;
+
 		algname = aes_algs[i].base.cra_name + 2;
 		drvname = aes_algs[i].base.cra_driver_name + 2;
 		basename = aes_algs[i].base.cra_driver_name;
-- 
2.20.1


  parent reply	other threads:[~2019-06-12 12:49 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-12 12:48 [RFC PATCH 00/20] AES cleanup Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 01/20] crypto: arm/aes-ce - cosmetic/whitespace cleanup Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 02/20] crypto: arm/aes - rename local routines to prevent future clashes Ard Biesheuvel
2019-06-12 15:23   ` Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 03/20] crypto: aes/fixed-time - align key schedule with other implementations Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 04/20] crypto: aes - create AES library based on the fixed time AES code Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 05/20] crypto: x86/aes-ni - switch to generic for fallback and key routines Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 06/20] crypto: x86/aes - drop scalar assembler implementations Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 07/20] crypto: padlock/aes - switch to library version of key expansion routine Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 08/20] crypto: cesa/aes " Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 09/20] crypto: safexcel/aes " Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 10/20] crypto: arm64/ghash - switch to AES library Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 11/20] crypto: arm/aes-neonbs - switch to library version of key expansion routine Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 12/20] crypto: arm64/aes-ccm - switch to AES library Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 13/20] crypto: arm64/aes-neonbs - switch to library version of key expansion routine Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 14/20] crypto: arm64/aes-ce " Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 15/20] crypto: generic/aes - drop key expansion routine in favor of library version Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 16/20] crypto: arm64/aes-ce-cipher - use AES library as fallback Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 17/20] crypto: aes - move ctr(aes) non-SIMD fallback to AES library Ard Biesheuvel
2019-06-12 12:48 ` Ard Biesheuvel [this message]
2019-06-12 12:48 ` [RFC PATCH 19/20] crypto: arm/aes-neonbs - provide a synchronous version of ctr(aes) Ard Biesheuvel
2019-06-12 12:48 ` [RFC PATCH 20/20] crypto: arm/ghash - provide a synchronous version Ard Biesheuvel
2019-06-12 13:58 ` [RFC PATCH 00/20] AES cleanup Herbert Xu
2019-06-12 14:00   ` Ard Biesheuvel
2019-06-12 17:08     ` Ard Biesheuvel

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=20190612124838.2492-19-ard.biesheuvel@linaro.org \
    --to=ard.biesheuvel@linaro.org \
    --cc=ebiggers@kernel.org \
    --cc=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.