[PATCH v12 1/9] stdlib: Add arc4random, arc4random_buf, and arc4random_uniform (BZ #4417)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Jul 22 13:00:50 GMT 2022
On 22/07/22 09:35, Florian Weimer wrote:
> * Adhemerval Zanella:
>
>> diff --git a/stdlib/chacha20.c b/stdlib/chacha20.c
>> new file mode 100644
>> index 0000000000..77e37655cd
>> --- /dev/null
>> +++ b/stdlib/chacha20.c
>> @@ -0,0 +1,179 @@
>
>> +static void
>> +chacha20_crypt (uint32_t *state, uint8_t *dst, const uint8_t *src)
>> +{
>> + size_t bytes = CHACHA20_BUFSIZE;
>> + while (bytes >= CHACHA20_BLOCK_SIZE)
>
> That doesn't look right. No bytes variable.
>
> The chacha20_crypt functions should probably use arguments in the style
> of
>
> uint8_t dst[static CHACHA20_BUFSIZE]
>
> for compiler size checking.
Would it be acceptable?
diff --git a/stdlib/chacha20.c b/stdlib/chacha20.c
index 07b7b203f2..4217ecb06f 100644
--- a/stdlib/chacha20.c
+++ b/stdlib/chacha20.c
@@ -166,14 +166,15 @@ chacha20_block (uint32_t *state, uint8_t *dst, const uint8_t *src)
static void
__attribute_maybe_unused__
-chacha20_crypt_generic (uint32_t *state, uint8_t *dst, const uint8_t *src)
+chacha20_crypt_generic (uint32_t *state, uint8_t dst[static CHACHA20_BUFSIZE],
+ const uint8_t *src)
{
- size_t bytes = CHACHA20_BUFSIZE;
- while (bytes >= CHACHA20_BLOCK_SIZE)
+ size_t dstlen = CHACHA20_BUFSIZE;
+ while (dstlen >= CHACHA20_BLOCK_SIZE)
{
chacha20_block (state, dst, src);
- bytes -= CHACHA20_BLOCK_SIZE;
+ dstlen -= CHACHA20_BLOCK_SIZE;
dst += CHACHA20_BLOCK_SIZE;
src += CHACHA20_BLOCK_SIZE;
}
More information about the Libc-alpha
mailing list