# Re: \[PATCH\] selftests: vDSO: Also test counter in vdso\_test\_chacha

- From: Jason A. Donenfeld \<Jason@zx2c4.com\>
- Date: 2024-09-01 18:08:18 
- List: linuxppc-dev
- Page: https://ratatoskr.run/linuxppc-dev/2024/09/2730406
- Thread: https://ratatoskr.run/linuxppc-dev/2024/09/2730392/t.md

```text
On Sun, Sep 01, 2024 at 07:40:33PM +0200, Christophe Leroy wrote:
> -static void reference_chacha20_blocks(uint8_t *dst_bytes, const uint32_t *key, size_t nblocks)
> +static void reference_chacha20_blocks(uint8_t *dst_bytes, const uint32_t *key, uint32_t *counter, size_t nblocks)
>  {
>  	uint32_t s[16] = {
>  		0x61707865U, 0x3320646eU, 0x79622d32U, 0x6b206574U,
> -		key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]
> +		key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7],
> +		counter[0], counter[1],

While you're doing this, also add the remaining, `0, 0` elements.

> +			if (memcmp(output1, output2, sizeof(output1)) ||
> +			    memcmp(counter2, counter2, sizeof(counter1)))

counter2 will always be counter2. You meant for the first argument to be
counter1.

> +	reference_chacha20_blocks(output1, key, counter1, BLOCKS);
> +	__arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS);
> +	if (memcmp(output1, output2, sizeof(output1)) ||
> +	    memcmp(counter2, counter2, sizeof(counter1)))
> +		return KSFT_FAIL;
> +
> +	reference_chacha20_blocks(output1, key, counter1, BLOCKS);
> +	__arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS);
> +	if (memcmp(output1, output2, sizeof(output1)) ||
> +	    memcmp(counter2, counter2, sizeof(counter1)))
> +		return KSFT_FAIL;
> +

Why repeat these two stanzas? Also, same issue with counter2 used twice
in that memcmp.

```
