From: david laight <david.laight@runbox.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Eric Biggers <ebiggers@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Ard Biesheuvel <ardb@kernel.org>, Kees Cook <kees@kernel.org>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH libcrypto 1/2] array_size: introduce min_array_size() function decoration
Date: Wed, 19 Nov 2025 23:02:05 +0000 [thread overview]
Message-ID: <20251119230205.2551d7eb@pumpkin> (raw)
In-Reply-To: <aR4UvNzdLLofbRpW@zx2c4.com>
On Wed, 19 Nov 2025 20:04:28 +0100
"Jason A. Donenfeld" <Jason@zx2c4.com> wrote:
> On Wed, Nov 19, 2025 at 12:31:11AM +0100, Jason A. Donenfeld wrote:
> > There's also this other approach from 2001 that the C committee I guess
> > shot down: https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_205.htm
> > It is basically:
> >
> > #define __at_least static
> >
> > We could attempt to do the same with `at_least`...
> >
> > It kind of feels like we're just inventing a language at that point
> > though.
>
> Actually, you know, the more this apparently terrible idea sits in my
> head, the more I like it.
>
> Which of these is most readable to you?
>
> bool __must_check xchacha20poly1305_decrypt(
> u8 *dst, const u8 *src, const size_t src_len, const u8 *ad,
> const size_t ad_len, const u8 nonce[min_array_size(XCHACHA20POLY1305_NONCE_SIZE)],
> const u8 key[min_array_size(CHACHA20POLY1305_KEY_SIZE)]);
>
> bool __must_check xchacha20poly1305_decrypt(
> u8 *dst, const u8 *src, const size_t src_len, const u8 *ad,
> const size_t ad_len, const u8 nonce[static XCHACHA20POLY1305_NONCE_SIZE],
> const u8 key[static CHACHA20POLY1305_KEY_SIZE]);
>
> bool __must_check xchacha20poly1305_decrypt(
> u8 *dst, const u8 *src, const size_t src_len, const u8 *ad,
> const size_t ad_len, const u8 nonce[at_least XCHACHA20POLY1305_NONCE_SIZE],
> const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);
While bikeshedding...
I'd drop the pointless 'const' and always try to put a ptr/len pair on the same line.
So end up with:
bool __must_check xchacha20poly1305_decrypt(u8 *dst, const u8 *src, size_t src_len,
const u8 *ad, size_t ad_len,
const u8 nonce[at_least XCHACHA20POLY1305_NONCE_SIZE],
const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);
or perhaps:
bool __must_check xchacha20poly1305_decrypt(u8 *dst,
const u8 *src, size_t src_len, const u8 *ad, size_t ad_len,
const u8 nonce[at_least XCHACHA20POLY1305_NONCE_SIZE],
const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);
but I don't know what defines the length of '*ad'.
David
>
> The macro function syntax of the first one means nested bracket brain
> parsing. The second one means more `static` usage that might be
> unfamiliar. The third one actually makes it kind of clear what's up.
> It's got that weird-but-nice Objective-C-style sentence programming
> thing.
>
> Would somebody jump in here to tell me to stop sniffing glue? I feel
> silly actually considering this, but here I am. Maybe this is actually
> an okay idea?
>
> Jason
>
next prev parent reply other threads:[~2025-11-19 23:02 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-18 17:02 [PATCH libcrypto 1/2] array_size: introduce min_array_size() function decoration Jason A. Donenfeld
2025-11-18 17:02 ` [PATCH libcrypto 2/2] crypto: chacha20poly1305: statically check fixed array lengths Jason A. Donenfeld
2025-11-19 10:36 ` kernel test robot
2025-11-19 12:45 ` kernel test robot
2025-11-19 16:22 ` Linus Torvalds
2025-11-19 16:46 ` Jason A. Donenfeld
2025-11-19 16:57 ` Linus Torvalds
2025-11-19 18:45 ` Nathan Chancellor
2025-11-18 23:24 ` [PATCH libcrypto 1/2] array_size: introduce min_array_size() function decoration Eric Biggers
2025-11-18 23:31 ` Jason A. Donenfeld
2025-11-19 19:04 ` Jason A. Donenfeld
2025-11-19 19:10 ` Ard Biesheuvel
2025-11-19 23:02 ` david laight [this message]
2025-11-18 23:32 ` Linus Torvalds
2025-11-22 2:37 ` 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=20251119230205.2551d7eb@pumpkin \
--to=david.laight@runbox.com \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=ebiggers@kernel.org \
--cc=kees@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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