diff options
author | Eric Biggers <ebiggers@google.com> | 2021-03-21 22:13:47 -0700 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2021-04-02 18:28:12 +1100 |
commit | a181e0fdb2164268274453b5b291589edbb9b22d (patch) | |
tree | 009f7411d6ede6a6446c09125dfa3acd0a7ea95f /include/crypto | |
parent | 30d0f6a956fc74bb2e948398daf3278c6b08c7e9 (diff) | |
download | linux-stable-a181e0fdb2164268274453b5b291589edbb9b22d.tar.gz linux-stable-a181e0fdb2164268274453b5b291589edbb9b22d.tar.bz2 linux-stable-a181e0fdb2164268274453b5b291589edbb9b22d.zip |
random: initialize ChaCha20 constants with correct endianness
On big endian CPUs, the ChaCha20-based CRNG is using the wrong
endianness for the ChaCha20 constants.
This doesn't matter cryptographically, but technically it means it's not
ChaCha20 anymore. Fix it to always use the standard constants.
Cc: linux-crypto@vger.kernel.org
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Jann Horn <jannh@google.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto')
-rw-r--r-- | include/crypto/chacha.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/include/crypto/chacha.h b/include/crypto/chacha.h index 3a1c72fdb7cf..dabaee698718 100644 --- a/include/crypto/chacha.h +++ b/include/crypto/chacha.h @@ -47,13 +47,18 @@ static inline void hchacha_block(const u32 *state, u32 *out, int nrounds) hchacha_block_generic(state, out, nrounds); } -void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv); -static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv) +static inline void chacha_init_consts(u32 *state) { state[0] = 0x61707865; /* "expa" */ state[1] = 0x3320646e; /* "nd 3" */ state[2] = 0x79622d32; /* "2-by" */ state[3] = 0x6b206574; /* "te k" */ +} + +void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv); +static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv) +{ + chacha_init_consts(state); state[4] = key[0]; state[5] = key[1]; state[6] = key[2]; |