From: Ard Biesheuvel <ardb+git@google.com>
To: linux-crypto@vger.kernel.org
Cc: ebiggers@kernel.org, herbert@gondor.apana.org.au,
Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 2/2] crypto/crc32c: Provide crc32c-base alias to enable fuzz testing
Date: Tue, 15 Oct 2024 16:15:17 +0200 [thread overview]
Message-ID: <20241015141514.3000757-6-ardb+git@google.com> (raw)
In-Reply-To: <20241015141514.3000757-4-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
crc32-generic is backed by the architecture's CRC-32c library, which may
offer a variety of implementations depending on the capabilities of the
platform. These are not covered by the crypto subsystem's fuzz testing
capabilities because crc32c-generic is the reference driver that the
fuzzing logic uses as a source of truth.
Fix this by proving a crc32c-base implementation which is always based
on the generic C implementation, and wire it up as the reference
implementation for the fuzz tester.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
crypto/crc32c_generic.c | 72 ++++++++++++++------
crypto/testmgr.c | 1 +
2 files changed, 51 insertions(+), 22 deletions(-)
diff --git a/crypto/crc32c_generic.c b/crypto/crc32c_generic.c
index a8c90b3f4c6c..0a7543dbc515 100644
--- a/crypto/crc32c_generic.c
+++ b/crypto/crc32c_generic.c
@@ -80,6 +80,17 @@ static int chksum_setkey(struct crypto_shash *tfm, const u8 *key,
return 0;
}
+#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
+static int chksum_update_base(struct shash_desc *desc, const u8 *data,
+ unsigned int length)
+{
+ struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
+
+ ctx->crc = __crc32c_le_base(ctx->crc, data, length);
+ return 0;
+}
+#endif
+
static int chksum_update(struct shash_desc *desc, const u8 *data,
unsigned int length)
{
@@ -127,35 +138,52 @@ static int crc32c_cra_init(struct crypto_tfm *tfm)
return 0;
}
-static struct shash_alg alg = {
- .digestsize = CHKSUM_DIGEST_SIZE,
- .setkey = chksum_setkey,
- .init = chksum_init,
- .update = chksum_update,
- .final = chksum_final,
- .finup = chksum_finup,
- .digest = chksum_digest,
- .descsize = sizeof(struct chksum_desc_ctx),
- .base = {
- .cra_name = "crc32c",
- .cra_driver_name = "crc32c-generic",
- .cra_priority = 100,
- .cra_flags = CRYPTO_ALG_OPTIONAL_KEY,
- .cra_blocksize = CHKSUM_BLOCK_SIZE,
- .cra_ctxsize = sizeof(struct chksum_ctx),
- .cra_module = THIS_MODULE,
- .cra_init = crc32c_cra_init,
- }
-};
+static struct shash_alg algs[] = {{
+ .digestsize = CHKSUM_DIGEST_SIZE,
+ .setkey = chksum_setkey,
+ .init = chksum_init,
+ .update = chksum_update,
+ .final = chksum_final,
+ .finup = chksum_finup,
+ .digest = chksum_digest,
+ .descsize = sizeof(struct chksum_desc_ctx),
+
+ .base.cra_name = "crc32c",
+ .base.cra_driver_name = "crc32c-generic",
+ .base.cra_priority = 100,
+ .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY,
+ .base.cra_blocksize = CHKSUM_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct chksum_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_init = crc32c_cra_init,
+#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
+}, {
+ .digestsize = CHKSUM_DIGEST_SIZE,
+ .setkey = chksum_setkey,
+ .init = chksum_init,
+ .update = chksum_update_base,
+ .final = chksum_final,
+ .digest = chksum_digest,
+ .descsize = sizeof(struct chksum_desc_ctx),
+
+ .base.cra_name = "crc32c",
+ .base.cra_driver_name = "crc32c-base",
+ .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY,
+ .base.cra_blocksize = CHKSUM_BLOCK_SIZE,
+ .base.cra_ctxsize = sizeof(struct chksum_ctx),
+ .base.cra_module = THIS_MODULE,
+ .base.cra_init = crc32c_cra_init,
+#endif
+}};
static int __init crc32c_mod_init(void)
{
- return crypto_register_shash(&alg);
+ return crypto_register_shashes(algs, ARRAY_SIZE(algs));
}
static void __exit crc32c_mod_fini(void)
{
- crypto_unregister_shash(&alg);
+ crypto_unregister_shashes(algs, ARRAY_SIZE(algs));
}
subsys_initcall(crc32c_mod_init);
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index e0d6bfcc13e6..c3f1cfe9e17e 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -4700,6 +4700,7 @@ static const struct alg_test_desc alg_test_descs[] = {
}
}, {
.alg = "crc32c",
+ .generic_driver = "crc32c-base",
.test = alg_test_crc32c,
.fips_allowed = 1,
.suite = {
--
2.47.0.rc1.288.g06298d1525-goog
next prev parent reply other threads:[~2024-10-15 14:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 14:15 [PATCH 0/2] crypto: Enable fuzz testing for generic crc32/crc32c Ard Biesheuvel
2024-10-15 14:15 ` [PATCH 1/2] crypto/crc32: Provide crc32-base alias to enable fuzz testing Ard Biesheuvel
2024-10-16 2:21 ` Eric Biggers
2024-10-18 23:55 ` kernel test robot
2024-10-15 14:15 ` Ard Biesheuvel [this message]
2024-10-19 11:16 ` [PATCH 2/2] crypto/crc32c: Provide crc32c-base " kernel test robot
2024-10-16 2:20 ` [PATCH 0/2] crypto: Enable fuzz testing for generic crc32/crc32c Eric Biggers
2024-10-16 4:15 ` 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=20241015141514.3000757-6-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).