author | Eric Biggers <ebiggers@google.com> | 2017-11-22 19:51:35 (GMT) |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2018-12-13 17:34:58 (GMT) |
commit | 73ae7b88eff40567e134ab3169549d95f1c0026f (patch) | |
tree | 323d627357f881e7a49e2728eaf7bddc13f1a965 | |
parent | 1634ff15387557980b5d21ddfe03d4c9b9f7cc89 (diff) | |
download | common-73ae7b88eff40567e134ab3169549d95f1c0026f.zip common-73ae7b88eff40567e134ab3169549d95f1c0026f.tar.gz common-73ae7b88eff40567e134ab3169549d95f1c0026f.tar.bz2 |
UPSTREAM: 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: Eric Biggers <ebiggers@google.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit ecf3220d882ae84844909ed6323032aac47aff93)
Bug: 112008522
Test: As series, see Ic61c13b53facfd2173065be715a7ee5f3af8760b
Change-Id: I01a70ca3762e03a0f934bcafc815e5a574362981
Signed-off-by: Eric Biggers <ebiggers@google.com>
-rw-r--r-- | crypto/chacha20_generic.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/crypto/chacha20_generic.c b/crypto/chacha20_generic.c index 1cab831..aa229e1 100644 --- a/crypto/chacha20_generic.c +++ b/crypto/chacha20_generic.c @@ -42,12 +42,10 @@ static void chacha20_docrypt(u32 *state, u8 *dst, const u8 *src, void crypto_chacha20_init(u32 *state, struct chacha20_ctx *ctx, u8 *iv) { - static const char constant[16] = "expand 32-byte k"; - - state[0] = le32_to_cpuvp(constant + 0); - state[1] = le32_to_cpuvp(constant + 4); - state[2] = le32_to_cpuvp(constant + 8); - state[3] = le32_to_cpuvp(constant + 12); + state[0] = 0x61707865; /* "expa" */ + state[1] = 0x3320646e; /* "nd 3" */ + state[2] = 0x79622d32; /* "2-by" */ + state[3] = 0x6b206574; /* "te k" */ state[4] = ctx->key[0]; state[5] = ctx->key[1]; state[6] = ctx->key[2]; |