Commit ecf3220d authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

crypto: chacha20 - Fix unaligned access when loading constants

The four 32-bit constants for the initial state of ChaCha20 were loaded
from a char array which is not guaranteed to have the needed alignment.

Fix it by just assigning the constants directly instead.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Acked-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent c3a53605
...@@ -41,12 +41,10 @@ static void chacha20_docrypt(u32 *state, u8 *dst, const u8 *src, ...@@ -41,12 +41,10 @@ static void chacha20_docrypt(u32 *state, u8 *dst, const u8 *src,
void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv) void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv)
{ {
static const char constant[16] = "expand 32-byte k"; state[0] = 0x61707865; /* "expa" */
state[1] = 0x3320646e; /* "nd 3" */
state[0] = le32_to_cpuvp(constant + 0); state[2] = 0x79622d32; /* "2-by" */
state[1] = le32_to_cpuvp(constant + 4); state[3] = 0x6b206574; /* "te k" */
state[2] = le32_to_cpuvp(constant + 8);
state[3] = le32_to_cpuvp(constant + 12);
state[4] = ctx->key[0]; state[4] = ctx->key[0];
state[5] = ctx->key[1]; state[5] = ctx->key[1];
state[6] = ctx->key[2]; state[6] = ctx->key[2];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment