mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 03:40:35 +09:00
random: initialize ChaCha20 constants with correct endianness
commit a181e0fdb2 upstream.
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>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
@@ -817,7 +817,7 @@ static bool __init crng_init_try_arch_early(struct crng_state *crng)
|
||||
|
||||
static void crng_initialize_secondary(struct crng_state *crng)
|
||||
{
|
||||
memcpy(&crng->state[0], "expand 32-byte k", 16);
|
||||
chacha_init_consts(crng->state);
|
||||
_get_random_bytes(&crng->state[4], sizeof(__u32) * 12);
|
||||
crng_init_try_arch(crng);
|
||||
crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
|
||||
@@ -827,7 +827,7 @@ static void numa_crng_init(void);
|
||||
|
||||
static void __init crng_initialize_primary(struct crng_state *crng)
|
||||
{
|
||||
memcpy(&crng->state[0], "expand 32-byte k", 16);
|
||||
chacha_init_consts(crng->state);
|
||||
_extract_entropy(&input_pool, &crng->state[4], sizeof(__u32) * 12, 0);
|
||||
if (crng_init_try_arch_early(crng) && trust_cpu && crng_init < 2) {
|
||||
invalidate_batched_entropy();
|
||||
|
||||
@@ -24,4 +24,12 @@ int crypto_chacha20_setkey(struct crypto_tfm *tfm, const u8 *key,
|
||||
int crypto_chacha20_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
|
||||
struct scatterlist *src, unsigned int nbytes);
|
||||
|
||||
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" */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user