From: David Howells <dhowells@redhat.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: David Howells <dhowells@redhat.com>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Ard Biesheuvel <ardb@kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
Stephan Mueller <smueller@chronox.de>,
Lukas Wunner <lukas@wunner.de>,
Ignat Korchagin <ignat@cloudflare.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Petr Pavlu <petr.pavlu@suse.com>,
Daniel Gomez <da.gomez@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
linux-crypto@vger.kernel.org, keyrings@vger.kernel.org,
linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v6 09/17] crypto: SHAKE tests
Date: Fri, 17 Oct 2025 15:42:53 +0100 [thread overview]
Message-ID: <20251017144311.817771-10-dhowells@redhat.com> (raw)
In-Reply-To: <20251017144311.817771-1-dhowells@redhat.com>
---
crypto/sha3_generic.c | 14 ++++++++--
crypto/testmgr.c | 14 ++++++++++
crypto/testmgr.h | 59 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 85 insertions(+), 2 deletions(-)
diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c
index 3e5a23022596..3a338fb704c2 100644
--- a/crypto/sha3_generic.c
+++ b/crypto/sha3_generic.c
@@ -30,6 +30,16 @@ int crypto_sha3_init(struct shash_desc *desc)
}
EXPORT_SYMBOL(crypto_sha3_init);
+static int crypto_shake_init(struct shash_desc *desc)
+{
+ struct sha3_ctx *ctx = crypto_sha3_desc(desc);
+
+ memset(ctx, 0, sizeof(*ctx));
+ ctx->block_size = crypto_shash_blocksize(desc->tfm);
+ ctx->padding = 0x1f;
+ return 0;
+}
+
static int crypto_sha3_update(struct shash_desc *desc, const u8 *data,
unsigned int len)
{
@@ -97,7 +107,7 @@ static struct shash_alg algs[] = { {
.base.cra_module = THIS_MODULE,
}, {
.digestsize = SHAKE128_DEFAULT_SIZE,
- .init = crypto_sha3_init,
+ .init = crypto_shake_init,
.update = crypto_sha3_update,
.finup = crypto_sha3_finup,
.descsize = sizeof(struct sha3_ctx),
@@ -108,7 +118,7 @@ static struct shash_alg algs[] = { {
.base.cra_module = THIS_MODULE,
}, {
.digestsize = SHAKE256_DEFAULT_SIZE,
- .init = crypto_sha3_init,
+ .init = crypto_shake_init,
.update = crypto_sha3_update,
.finup = crypto_sha3_finup,
.descsize = sizeof(struct sha3_ctx),
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 6a490aaa71b9..88d412ceb6f2 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -5516,6 +5516,20 @@ static const struct alg_test_desc alg_test_descs[] = {
.suite = {
.hash = __VECS(sha512_tv_template)
}
+ }, {
+ .alg = "shake128",
+ .test = alg_test_hash,
+ .fips_allowed = 1,
+ .suite = {
+ .hash = __VECS(shake128_tv_template)
+ }
+ }, {
+ .alg = "shake256",
+ .test = alg_test_hash,
+ .fips_allowed = 1,
+ .suite = {
+ .hash = __VECS(shake256_tv_template)
+ }
}, {
.alg = "sm3",
.test = alg_test_hash,
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 268231227282..c0eca7f72aa0 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -4690,6 +4690,65 @@ static const struct hash_testvec sha3_512_tv_template[] = {
};
+/* From: https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values */
+static const struct hash_testvec shake128_tv_template[] = {
+ {
+ .plaintext = "",
+ .psize = 0,
+ .digest =
+ "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85\x3e",
+ }, {
+ .plaintext =
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
+ "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3",
+ .psize = 200,
+ .digest =
+ "\x13\x1a\xb8\xd2\xb5\x94\x94\x6b\x9c\x81\x33\x3f\x9b\xb6\xe0\xce",
+ }
+};
+
+/* From: https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values */
+static const struct hash_testvec shake256_tv_template[] = {
+ {
+ .plaintext = "",
+ .psize = 0,
+ .digest =
+ "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb\x24"
+ "\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5\x76\x2f"
+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
+};
+
+
/*
* MD5 test vectors from RFC1321
*/
next prev parent reply other threads:[~2025-10-17 14:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 14:42 [PATCH v6 00/17] lib/crypto: Move SHA3 to lib/crypto, add SHAKE* and add ML-DSA signing David Howells
2025-10-17 14:42 ` [PATCH v6 01/17] s390/sha3: Rename conflicting functions David Howells
2025-10-18 8:59 ` Christophe Leroy
2025-10-18 12:17 ` David Howells
2025-10-17 14:42 ` [PATCH v6 02/17] arm64/sha3: " David Howells
2025-10-18 9:00 ` Christophe Leroy
2025-10-17 14:42 ` [PATCH v6 03/17] lib/crypto: Add SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128, SHAKE256 David Howells
2025-10-17 14:42 ` [PATCH v6 04/17] lib/crypto: Move the SHA3 Iota transform into the single round function David Howells
2025-10-17 14:42 ` [PATCH v6 05/17] lib/crypto: Add SHA3 kunit tests David Howells
2025-10-17 14:42 ` [PATCH v6 06/17] crypto/jitterentropy: Use lib/crypto/sha3 David Howells
2025-10-17 14:42 ` [PATCH v6 07/17] crypto/sha3: " David Howells
2025-10-17 14:42 ` [PATCH v6 08/17] crypto/sha3: Add SHAKE128/256 support David Howells
2025-10-17 14:42 ` David Howells [this message]
2025-10-17 14:42 ` [PATCH v6 10/17] crypto: Add ML-DSA/Dilithium support David Howells
2025-10-17 14:42 ` [PATCH v6 11/17] crypto: Add ML-DSA/Dilithium keypair generation support David Howells
2025-10-17 14:42 ` [PATCH v6 12/17] crypto: Add ML-DSA-44 pure rejection test vectors as a kunit test David Howells
2025-10-17 14:42 ` [PATCH v6 13/17] crypto: Add ML-DSA-65 " David Howells
2025-10-17 14:42 ` [PATCH v6 14/17] crypto: Add ML-DSA-87 " David Howells
2025-10-17 14:42 ` [PATCH v6 15/17] pkcs7: Allow the signing algo to calculate the digest itself David Howells
2025-10-17 14:43 ` [PATCH v6 16/17] pkcs7, x509: Add ML-DSA support David Howells
2025-10-17 14:43 ` [PATCH v6 17/17] modsign: Enable ML-DSA module signing David Howells
2025-10-21 13:51 ` Petr Pavlu
2025-11-06 17:37 ` David Howells
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=20251017144311.817771-10-dhowells@redhat.com \
--to=dhowells@redhat.com \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=da.gomez@kernel.org \
--cc=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=ignat@cloudflare.com \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=mcgrof@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=samitolvanen@google.com \
--cc=smueller@chronox.de \
/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).