diff mbox series

crypto: arm64/sha2-ce - implement ->digest for sha256

Message ID 20231009075327.446840-1-ebiggers@kernel.org
State New
Headers show
Series crypto: arm64/sha2-ce - implement ->digest for sha256 | expand

Commit Message

Eric Biggers Oct. 9, 2023, 7:53 a.m. UTC
From: Eric Biggers <ebiggers@google.com>

Implement a ->digest function for sha256-ce.  This improves the
performance of crypto_shash_digest() with this algorithm by reducing the
number of indirect calls that are made.  This only adds ~112 bytes of
code, mostly for the inlined init, as the finup function is tail-called.

For now, don't bother with this for sha224, since sha224 is rarely used.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 arch/arm64/crypto/sha2-ce-glue.c | 8 ++++++++
 1 file changed, 8 insertions(+)


base-commit: 8468516f9f93a41dc65158b6428a1a1039c68f20

Comments

Herbert Xu Oct. 20, 2023, 5:51 a.m. UTC | #1
Eric Biggers <ebiggers@kernel.org> wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Implement a ->digest function for sha256-ce.  This improves the
> performance of crypto_shash_digest() with this algorithm by reducing the
> number of indirect calls that are made.  This only adds ~112 bytes of
> code, mostly for the inlined init, as the finup function is tail-called.
> 
> For now, don't bother with this for sha224, since sha224 is rarely used.
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> arch/arm64/crypto/sha2-ce-glue.c | 8 ++++++++
> 1 file changed, 8 insertions(+)

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/arch/arm64/crypto/sha2-ce-glue.c b/arch/arm64/crypto/sha2-ce-glue.c
index c57a6119fefc5..f2f118b0e1c1f 100644
--- a/arch/arm64/crypto/sha2-ce-glue.c
+++ b/arch/arm64/crypto/sha2-ce-glue.c
@@ -109,20 +109,27 @@  static int sha256_ce_final(struct shash_desc *desc, u8 *out)
 	if (!crypto_simd_usable()) {
 		sha256_base_do_finalize(desc, __sha256_block_data_order);
 		return sha256_base_finish(desc, out);
 	}
 
 	sctx->finalize = 0;
 	sha256_base_do_finalize(desc, __sha2_ce_transform);
 	return sha256_base_finish(desc, out);
 }
 
+static int sha256_ce_digest(struct shash_desc *desc, const u8 *data,
+			    unsigned int len, u8 *out)
+{
+	sha256_base_init(desc);
+	return sha256_ce_finup(desc, data, len, out);
+}
+
 static int sha256_ce_export(struct shash_desc *desc, void *out)
 {
 	struct sha256_ce_state *sctx = shash_desc_ctx(desc);
 
 	memcpy(out, &sctx->sst, sizeof(struct sha256_state));
 	return 0;
 }
 
 static int sha256_ce_import(struct shash_desc *desc, const void *in)
 {
@@ -148,20 +155,21 @@  static struct shash_alg algs[] = { {
 		.cra_driver_name	= "sha224-ce",
 		.cra_priority		= 200,
 		.cra_blocksize		= SHA256_BLOCK_SIZE,
 		.cra_module		= THIS_MODULE,
 	}
 }, {
 	.init			= sha256_base_init,
 	.update			= sha256_ce_update,
 	.final			= sha256_ce_final,
 	.finup			= sha256_ce_finup,
+	.digest			= sha256_ce_digest,
 	.export			= sha256_ce_export,
 	.import			= sha256_ce_import,
 	.descsize		= sizeof(struct sha256_ce_state),
 	.statesize		= sizeof(struct sha256_state),
 	.digestsize		= SHA256_DIGEST_SIZE,
 	.base			= {
 		.cra_name		= "sha256",
 		.cra_driver_name	= "sha256-ce",
 		.cra_priority		= 200,
 		.cra_blocksize		= SHA256_BLOCK_SIZE,