From: Eric Biggers <ebiggers3@gmail.com>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: Theodore Ts'o <tytso@mit.edu>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Martin Willi <martin@strongswan.org>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
linux-kernel@vger.kernel.org, Eric Biggers <ebiggers@google.com>
Subject: [PATCH 1/5] crypto: chacha20 - Fix unaligned access when loading constants
Date: Wed, 22 Nov 2017 11:51:35 -0800 [thread overview]
Message-ID: <20171122195139.121269-2-ebiggers3@gmail.com> (raw)
In-Reply-To: <20171122195139.121269-1-ebiggers3@gmail.com>
From: Eric Biggers <ebiggers@google.com>
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>
---
crypto/chacha20_generic.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/crypto/chacha20_generic.c b/crypto/chacha20_generic.c
index 4a45fa4890c0..ec84e7837aac 100644
--- a/crypto/chacha20_generic.c
+++ b/crypto/chacha20_generic.c
@@ -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)
{
- 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];
--
2.15.0.448.gf294e3d99a-goog
next prev parent reply other threads:[~2017-11-22 19:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-22 19:51 [PATCH 0/5] crypto: chacha20 - Alignment fixes Eric Biggers
2017-11-22 19:51 ` Eric Biggers [this message]
2017-11-22 20:26 ` [PATCH 1/5] crypto: chacha20 - Fix unaligned access when loading constants Ard Biesheuvel
2017-11-22 19:51 ` [PATCH 2/5] crypto: chacha20 - Use unaligned access macros when loading key and IV Eric Biggers
2017-11-22 20:27 ` Ard Biesheuvel
2017-11-22 19:51 ` [PATCH 3/5] crypto: chacha20 - Remove cra_alignmask Eric Biggers
2017-11-22 20:30 ` Ard Biesheuvel
2017-11-22 19:51 ` [PATCH 4/5] crypto: x86/chacha20 " Eric Biggers
2017-11-22 20:31 ` Ard Biesheuvel
2017-11-22 19:51 ` [PATCH 5/5] crypto: chacha20 - Fix keystream alignment for chacha20_block() Eric Biggers
2017-11-22 20:51 ` Ard Biesheuvel
2017-11-22 21:29 ` Eric Biggers
2017-11-22 22:06 ` Ard Biesheuvel
2017-11-29 6:39 ` [PATCH 0/5] crypto: chacha20 - Alignment fixes Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171122195139.121269-2-ebiggers3@gmail.com \
--to=ebiggers3@gmail.com \
--cc=Jason@zx2c4.com \
--cc=ard.biesheuvel@linaro.org \
--cc=ebiggers@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin@strongswan.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).