diff options
| author | Eric Biggers <ebiggers@kernel.org> | 2026-10-14 17:26:04 +0200 |
|---|---|---|
| committer | Eric Biggers <ebiggers@kernel.org> | 2026-10-15 23:16:46 -0700 |
| commit | e42003dba6dd11380b8c2a39f3bc1bf11a6d0b0f (patch) | |
| tree | c87f6e89cac6a039590745056d6409ce09bd3720 /include | |
| parent | 0b58c136c2f9067b1a5253bffa322f6bf3e2cc74 (diff) | |
lib/crypto: chacha: Use size_t length
Upgrade the ChaCha functions from 32-bit lengths to size_t.
'size_t' is the best practice for buffer lengths, and it's what the rest
of the crypto library uses.
Moreover, all the 64-bit ChaCha assembly functions actually already
treated the length as 64-bit, despite it being declared as 32-bit in C
on arm64, ppc64, and x86_64. For arm64 and x86_64, this caused
unspecified behavior due to the high 32 bits of the corresponding
register having an unspecified value in those architectures' ABIs.
However, in practice these bits are always zero and no issue occurred.
(ppc64 was fine too, since there the ABI zero-extends 32-bit arguments.)
These issues date to the original introduction of the ChaCha code.
However, as noted above, they don't have any real-world impact
currently; so this is an API robustness improvement only.
Reported-by: Vladimir Kukharenko <vladimir@genproof.com>
Closes: https://lore.kernel.org/r/20261012-libcrypto-4gib-lengths-v1-0-ea566c129a2e@genproof.com
Tested-by: Vladimir Kukharenko <vladimir@genproof.com>
Link: https://patch.msgid.link/20261014152604.323310-3-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/crypto/chacha.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/include/crypto/chacha.h b/include/crypto/chacha.h index 1cc301a48469..bacf253781d5 100644 --- a/include/crypto/chacha.h +++ b/include/crypto/chacha.h @@ -86,10 +86,10 @@ static inline void chacha_init(struct chacha_state *state, } void chacha_crypt(struct chacha_state *state, u8 *dst, const u8 *src, - unsigned int bytes, int nrounds); + size_t bytes, int nrounds); -static inline void chacha20_crypt(struct chacha_state *state, - u8 *dst, const u8 *src, unsigned int bytes) +static inline void chacha20_crypt(struct chacha_state *state, u8 *dst, + const u8 *src, size_t bytes) { chacha_crypt(state, dst, src, bytes, 20); } |
