From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] random: vDSO: move prototype of arch chacha function to vdso/getrandom.h
Date: Tue, 27 Aug 2024 18:53:54 +0200 [thread overview]
Message-ID: <ea693ce2-61dd-4885-805f-28aa7e60ea28@csgroup.eu> (raw)
In-Reply-To: <20240827154822.3330270-1-Jason@zx2c4.com>
Le 27/08/2024 à 17:47, Jason A. Donenfeld a écrit :
> Having the prototype for __arch_chacha20_blocks_nostack in
> arch/x86/include/asm/vdso/getrandom.h meant that the prototype and large
> doc comment were cloned by every architecture, which has been causing
> unnecessary churn. Instead move it into include/vdso/getrandom.h, where
> it can be shared by all archs implementing it.
>
> As a side bonus, this then lets us use that prototype in the
> vdso_test_chacha self test, to ensure that it matches the source, and
> indeed doing so turned up some inconsistencies, which are rectified
> here.
Side bonus that I dislike. Or ... it is all that u32 key stuff that I
dislike.
If it was really u32 I would be able to read it with a LWZ instruction
(Load Word Zero extended). That's what I did at the begining. But if I
want the selftest to work, I have to use LWBRX (Load Word Byte Reversed
...)instead because the bytes in the word are in reversed order in reality.
So either it is a table of 32 bytes, or it is as defined in RFC 7539:
A 256-bit key, treated as a concatenation of eight 32-bit
little-endian integers.
And in that case it is not a table of 8x u32 but table of 8x __le32
>
> Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> diff --git a/tools/testing/selftests/vDSO/vdso_test_chacha.c b/tools/testing/selftests/vDSO/vdso_test_chacha.c
> index e38f44e5f803..ca5639d02969 100644
> --- a/tools/testing/selftests/vDSO/vdso_test_chacha.c
> +++ b/tools/testing/selftests/vDSO/vdso_test_chacha.c
> @@ -7,16 +7,20 @@
> #include <sys/random.h>
> #include <string.h>
> #include <stdint.h>
> +#include <stdbool.h>
> #include "../kselftest.h"
>
> -extern void __arch_chacha20_blocks_nostack(uint8_t *dst_bytes, const uint8_t *key, uint32_t *counter, size_t nblocks);
> +typedef uint8_t u8;
> +typedef uint32_t u32;
> +typedef uint64_t u64;
> +#include <vdso/getrandom.h>
>
> int main(int argc, char *argv[])
> {
> enum { TRIALS = 1000, BLOCKS = 128, BLOCK_SIZE = 64 };
> static const uint8_t nonce[8] = { 0 };
> uint32_t counter[2];
> - uint8_t key[32];
> + uint32_t key[8];
> uint8_t output1[BLOCK_SIZE * BLOCKS], output2[BLOCK_SIZE * BLOCKS];
>
> ksft_print_header();
> @@ -27,7 +31,7 @@ int main(int argc, char *argv[])
> printf("getrandom() failed!\n");
> return KSFT_SKIP;
> }
> - crypto_stream_chacha20(output1, sizeof(output1), nonce, key);
> + crypto_stream_chacha20(output1, sizeof(output1), nonce, (uint8_t *)key);
> for (unsigned int split = 0; split < BLOCKS; ++split) {
> memset(output2, 'X', sizeof(output2));
> memset(counter, 0, sizeof(counter));
next prev parent reply other threads:[~2024-08-27 16:53 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 18:10 [PATCH] aarch64: vdso: Wire up getrandom() vDSO implementation Adhemerval Zanella
2024-08-26 20:27 ` Jason A. Donenfeld
2024-08-27 13:17 ` Adhemerval Zanella Netto
2024-08-27 13:34 ` Jason A. Donenfeld
2024-08-27 13:39 ` Adhemerval Zanella Netto
2024-08-27 14:00 ` Christophe Leroy
2024-08-27 14:01 ` Adhemerval Zanella Netto
2024-08-27 14:10 ` Christophe Leroy
2024-08-27 14:14 ` Adhemerval Zanella Netto
2024-08-27 14:28 ` Jason A. Donenfeld
2024-08-27 14:30 ` Adhemerval Zanella Netto
2024-08-27 14:32 ` Jason A. Donenfeld
2024-08-27 14:35 ` Adhemerval Zanella Netto
2024-08-27 14:41 ` [PATCH] selftests/vDSO: separate LDLIBS from CFLAGS for libsodium Jason A. Donenfeld
2024-08-27 14:45 ` Adhemerval Zanella Netto
2024-08-27 14:52 ` Jason A. Donenfeld
2024-08-27 13:52 ` [PATCH] aarch64: vdso: Wire up getrandom() vDSO implementation Christophe Leroy
2024-08-26 20:55 ` Jason A. Donenfeld
2024-08-27 8:46 ` Christophe Leroy
2024-08-27 8:53 ` Jason A. Donenfeld
2024-08-27 15:16 ` Jason A. Donenfeld
2024-08-27 15:18 ` [PATCH] random: vDSO: move prototype of arch chacha function to vdso/getrandom.h Jason A. Donenfeld
2024-08-27 15:47 ` [PATCH v2] " Jason A. Donenfeld
2024-08-27 16:53 ` Christophe Leroy [this message]
2024-08-27 16:55 ` Jason A. Donenfeld
2024-08-27 14:07 ` [PATCH] aarch64: vdso: Wire up getrandom() vDSO implementation Adhemerval Zanella Netto
2024-08-27 13:51 ` Ard Biesheuvel
2024-08-27 14:00 ` Mark Rutland
2024-08-27 14:05 ` Adhemerval Zanella Netto
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=ea693ce2-61dd-4885-805f-28aa7e60ea28@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=Jason@zx2c4.com \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®