From nobody Tue Dec 16 22:12:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE8D2235079; Fri, 30 May 2025 16:12:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748621531; cv=none; b=BEFG24PauOgb8wFOvVXGC5HoziFpvqADCtF5qewy539BMyeNwgChVZtZZXQsGdiKi8O7RvZ/gIuoF6iVwNPSSs2yMOtNYA2faKti+hfZf0NRaPrSALOIhbH0mct4x/rNdAIaBiKvHIDv0J85gqhOuGbKLJSEsum8jQkE2QoKNww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748621531; c=relaxed/simple; bh=Z7hYRToBzVndugVw9/+VL1oIDvZ/G481tYi7Xm5XtUw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dnHrdQ4hxGlcQ5V6g7McHVNL8K4TgYnFfyr2qCDoDP3snS8I8Pf/Cms2bQCBQEGfCg5xa/GgdfXHrg0l6x6+QwulhpjDA5plL/Rqu0SCmvynq56BE8v41pyATIJcyCOdld4hOJF1Ct1duVKefxVY4Y1HMRoN9C+qYM0RoLj5nOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VmVzKZei; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VmVzKZei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F50AC4CEE9; Fri, 30 May 2025 16:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748621530; bh=Z7hYRToBzVndugVw9/+VL1oIDvZ/G481tYi7Xm5XtUw=; h=From:To:Cc:Subject:Date:From; b=VmVzKZeioeqaHpjIhbGPFl5Vfs4b4wDFUxHMnpf9qmBaVUAe1Ei+dxIhB80qmZxZP b2EUuibXcVdoxa7/QqrA+MrPEfmCSOWxBvDq2Ujudd1rP1/Q+iM3eE0lbDVSlAButU Yk41dX94rrDXLbpl2WIbMW52IIb0usKL2rnStsZIPUIM3tbLv5crN0YY4NvWReLLeP bFj914ylOovL2Wc5HiWCg6p6obELgB8WnJFPMsbvNf5Pc6asIBl6NsAyluUJTVSbCU /ZWJyESI3BWrdrfddgfHgrO5Urs8vQFmW14I6ZDYf++BOaHOaloiugciw4CVVv42KL Lzghx6VtbBOhg== From: Eric Biggers To: linux-kernel@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Ard Biesheuvel Subject: [PATCH] crypto/crc32c: register only one shash_alg Date: Fri, 30 May 2025 09:10:42 -0700 Message-ID: <20250530161042.13106-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Eric Biggers Stop unnecessarily registering a "crc32c-generic" shash_alg when a "crc32c-$(ARCH)" shash_alg is registered too. While every algorithm does need to have a generic implementation to ensure uniformity of support across platforms, that doesn't mean that we need to make the generic implementation available through crypto_shash when an optimized implementation is also available. Registering the generic shash_alg did allow users of the crypto_shash or crypto_ahash APIs to request the generic implementation specifically, instead of an optimized one. However, the only known use case for that was the differential fuzz tests in crypto/testmgr.c. Equivalent test coverage is now provided by crc_kunit. Signed-off-by: Eric Biggers --- I'm planning to take this through the crc tree. crypto/crc32c.c | 70 +++++++------------------------------------------ 1 file changed, 10 insertions(+), 60 deletions(-) diff --git a/crypto/crc32c.c b/crypto/crc32c.c index e5377898414a2..e160695682f16 100644 --- a/crypto/crc32c.c +++ b/crypto/crc32c.c @@ -83,19 +83,10 @@ static int chksum_setkey(struct crypto_shash *tfm, cons= t u8 *key, static int chksum_update(struct shash_desc *desc, const u8 *data, unsigned int length) { struct chksum_desc_ctx *ctx =3D shash_desc_ctx(desc); =20 - ctx->crc =3D crc32c_base(ctx->crc, data, length); - return 0; -} - -static int chksum_update_arch(struct shash_desc *desc, const u8 *data, - unsigned int length) -{ - struct chksum_desc_ctx *ctx =3D shash_desc_ctx(desc); - ctx->crc =3D crc32c(ctx->crc, data, length); return 0; } =20 static int chksum_final(struct shash_desc *desc, u8 *out) @@ -105,17 +96,10 @@ static int chksum_final(struct shash_desc *desc, u8 *o= ut) put_unaligned_le32(~ctx->crc, out); return 0; } =20 static int __chksum_finup(u32 *crcp, const u8 *data, unsigned int len, u8 = *out) -{ - put_unaligned_le32(~crc32c_base(*crcp, data, len), out); - return 0; -} - -static int __chksum_finup_arch(u32 *crcp, const u8 *data, unsigned int len, - u8 *out) { put_unaligned_le32(~crc32c(*crcp, data, len), out); return 0; } =20 @@ -125,98 +109,64 @@ static int chksum_finup(struct shash_desc *desc, cons= t u8 *data, struct chksum_desc_ctx *ctx =3D shash_desc_ctx(desc); =20 return __chksum_finup(&ctx->crc, data, len, out); } =20 -static int chksum_finup_arch(struct shash_desc *desc, const u8 *data, - unsigned int len, u8 *out) -{ - struct chksum_desc_ctx *ctx =3D shash_desc_ctx(desc); - - return __chksum_finup_arch(&ctx->crc, data, len, out); -} - static int chksum_digest(struct shash_desc *desc, const u8 *data, unsigned int length, u8 *out) { struct chksum_ctx *mctx =3D crypto_shash_ctx(desc->tfm); =20 return __chksum_finup(&mctx->key, data, length, out); } =20 -static int chksum_digest_arch(struct shash_desc *desc, const u8 *data, - unsigned int length, u8 *out) -{ - struct chksum_ctx *mctx =3D crypto_shash_ctx(desc->tfm); - - return __chksum_finup_arch(&mctx->key, data, length, out); -} - static int crc32c_cra_init(struct crypto_tfm *tfm) { struct chksum_ctx *mctx =3D crypto_tfm_ctx(tfm); =20 mctx->key =3D ~0; return 0; } =20 -static struct shash_alg algs[] =3D {{ +static struct shash_alg alg =3D { .digestsize =3D CHKSUM_DIGEST_SIZE, .setkey =3D chksum_setkey, .init =3D chksum_init, .update =3D chksum_update, .final =3D chksum_final, .finup =3D chksum_finup, .digest =3D chksum_digest, .descsize =3D sizeof(struct chksum_desc_ctx), =20 .base.cra_name =3D "crc32c", - .base.cra_driver_name =3D "crc32c-generic", .base.cra_priority =3D 100, .base.cra_flags =3D CRYPTO_ALG_OPTIONAL_KEY, .base.cra_blocksize =3D CHKSUM_BLOCK_SIZE, .base.cra_ctxsize =3D sizeof(struct chksum_ctx), .base.cra_module =3D THIS_MODULE, .base.cra_init =3D crc32c_cra_init, -}, { - .digestsize =3D CHKSUM_DIGEST_SIZE, - .setkey =3D chksum_setkey, - .init =3D chksum_init, - .update =3D chksum_update_arch, - .final =3D chksum_final, - .finup =3D chksum_finup_arch, - .digest =3D chksum_digest_arch, - .descsize =3D sizeof(struct chksum_desc_ctx), - - .base.cra_name =3D "crc32c", - .base.cra_driver_name =3D "crc32c-" __stringify(ARCH), - .base.cra_priority =3D 150, - .base.cra_flags =3D CRYPTO_ALG_OPTIONAL_KEY, - .base.cra_blocksize =3D CHKSUM_BLOCK_SIZE, - .base.cra_ctxsize =3D sizeof(struct chksum_ctx), - .base.cra_module =3D THIS_MODULE, - .base.cra_init =3D crc32c_cra_init, -}}; - -static int num_algs; +}; =20 static int __init crc32c_mod_init(void) { - /* register the arch flavor only if it differs from the generic one */ - num_algs =3D 1 + ((crc32_optimizations() & CRC32C_OPTIMIZATION) !=3D 0); + const char *driver_name =3D + (crc32_optimizations() & CRC32C_OPTIMIZATION) ? + "crc32c-" __stringify(ARCH) : + "crc32c-generic"; + + strscpy(alg.base.cra_driver_name, driver_name, CRYPTO_MAX_ALG_NAME); =20 - return crypto_register_shashes(algs, num_algs); + return crypto_register_shash(&alg); } =20 static void __exit crc32c_mod_fini(void) { - crypto_unregister_shashes(algs, num_algs); + crypto_unregister_shash(&alg); } =20 module_init(crc32c_mod_init); module_exit(crc32c_mod_fini); =20 MODULE_AUTHOR("Clay Haapala "); MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations wrapper for lib/crc32= c"); MODULE_LICENSE("GPL"); MODULE_ALIAS_CRYPTO("crc32c"); -MODULE_ALIAS_CRYPTO("crc32c-generic"); base-commit: f66bc387efbee59978e076ce9bf123ac353b389c --=20 2.49.0