From: Eric Biggers <ebiggers@kernel.org>
To: David Howells <dhowells@redhat.com>
Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>,
Ard Biesheuvel <ardb@kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
Stephan Mueller <smueller@chronox.de>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 0/8] crypto, lib/crypto: Add SHAKE128/256 support and move SHA3 to lib/crypto
Date: Thu, 2 Oct 2025 09:27:05 -0700 [thread overview]
Message-ID: <20251002162705.GB1697@sol> (raw)
In-Reply-To: <2636609.1759410884@warthog.procyon.org.uk>
On Thu, Oct 02, 2025 at 02:14:44PM +0100, David Howells wrote:
> Eric Biggers <ebiggers@kernel.org> wrote:
>
> > Have you had a chance to read this reply?
>
> I have.
>
> You held up your implementation of sha256 and sha224 as an example of how it
> perhaps should be implemented:
>
> It would be worth considering separating the APIs for the different
> algorithms that are part of SHA-3, similar to what I did with SHA-224
> and SHA-256.
>
> so I have followed that. That defines a type for each, so I'll leave it at
> that.
In v3, you were pretty clear that you don't like the six-types solution:
I have done what Eric required and made a separate wrapper struct
and set of wrapper functions for each algorithm, though I think this
is excessively bureaucratic as this multiplies the API load by 7
(and maybe 9 in the future[*]).
[*] The Kyber algorithm also uses CSHAKE variants in the SHA3 family - and
NIST mentions some other variants too.
This does, however, cause a problem for what I need to do as the
ML-DSA prehash is dynamically selectable by certificate OID, so I
have to add SHAKE128/256 support to the crypto shash API too -
though hopefully it will only require an output of 16 or 32 bytes
respectively for the prehash case and won't require multiple
squeezing.
So, I listened. And I realized that we can address my concern about the
digest vs. XOF confusion using just two types.
And I explained I didn't intend to require that we fully split the API
into all six variants, and apologized for not being clear.
Remember, we haven't done a SHA-3 library API before. We're both
learning as we go...
If you've now changed your mind and strongly prefer six types, I can
tolerate that too. But I want to make sure you actually want that, and
aren't choosing it just to try to prove a point or something.
> > All I'm really requesting is that we don't create footguns, like the
> > following that the API in the v2 patch permitted:
>
> The way you did a separate type for each removed one more footgun - and
> arguably a more important one - as the *type* enforces[1] the output buffer
> size and the sha3_*_final() function has the same sized-array as the
> convenience wrappers.
>
> It also eliminates the need to store the digest size as this is only needed at
> the final step for the digest variant algorithms.
>
> David
>
> [1] Inasmuch as this is effective in C.
Well, that "Inasmuch as this is effective in C" disclaimer is really
important, because it means it doesn't actually work properly.
Effectively, array bounds in function parameters are for humans, not the
compiler.
Which is still useful, but probably not to the extent that we should
have all those extra functions and types, vs. just documenting that
sha3_final() produces output of length matching the init function that
was called. (As I mentioned, the BLAKE2s API does something similar.)
- Eric
next prev parent reply other threads:[~2025-10-02 16:28 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-26 14:19 [PATCH v3 0/8] crypto, lib/crypto: Add SHAKE128/256 support and move SHA3 to lib/crypto David Howells
2025-09-26 14:19 ` [PATCH v3 1/8] s390/sha3: Rename conflicting functions David Howells
2025-09-29 11:39 ` Harald Freudenberger
2025-09-26 14:19 ` [PATCH v3 2/8] arm64/sha3: " David Howells
2025-09-26 14:19 ` [PATCH v3 3/8] lib/crypto: Add SHA3-224, SHA3-256, SHA3-384, SHA-512, SHAKE128, SHAKE256 David Howells
2025-09-26 21:09 ` Eric Biggers
2025-09-26 14:19 ` [PATCH v3 4/8] lib/crypto: Move the SHA3 Iota transform into the single round function David Howells
2025-09-26 14:19 ` [PATCH v3 5/8] lib/crypto: Add SHA3 kunit tests David Howells
2025-10-01 16:04 ` Eric Biggers
2025-10-01 16:08 ` Eric Biggers
2025-10-02 13:05 ` David Howells
2025-10-02 16:07 ` Eric Biggers
2025-09-26 14:19 ` [PATCH v3 6/8] crypto/sha3: Use lib/crypto/sha3 David Howells
2025-09-26 21:25 ` Eric Biggers
2025-09-26 14:19 ` [PATCH v3 7/8] crypto/sha3: Add SHAKE128/256 support David Howells
2025-09-26 21:14 ` Eric Biggers
2025-10-01 13:02 ` David Howells
2025-10-01 15:25 ` Eric Biggers
2025-09-26 14:19 ` [PATCH v3 8/8] crypto: SHAKE tests David Howells
2025-09-26 19:59 ` [PATCH v3 0/8] crypto, lib/crypto: Add SHAKE128/256 support and move SHA3 to lib/crypto Eric Biggers
2025-10-01 15:28 ` Eric Biggers
2025-10-02 13:14 ` David Howells
2025-10-02 16:27 ` Eric Biggers [this message]
2025-10-11 0:26 ` Eric Biggers
2025-10-16 12:35 ` David Howells
2025-10-16 14:34 ` David Howells
2025-10-16 14:56 ` Stephan Mueller
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=20251002162705.GB1697@sol \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=dhowells@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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).