All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers3@gmail.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: "linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Theodore Ts'o <tytso@mit.edu>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	Martin Willi <martin@strongswan.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Eric Biggers <ebiggers@google.com>
Subject: Re: [PATCH 5/5] crypto: chacha20 - Fix keystream alignment for chacha20_block()
Date: Wed, 22 Nov 2017 13:29:50 -0800	[thread overview]
Message-ID: <20171122212950.GA74584@gmail.com> (raw)
In-Reply-To: <CAKv+Gu__YdYWXgGfNSng8fDj9F0pw-i4zbAaN+uxES+r6mRMpw@mail.gmail.com>

On Wed, Nov 22, 2017 at 08:51:57PM +0000, Ard Biesheuvel wrote:
> On 22 November 2017 at 19:51, Eric Biggers <ebiggers3@gmail.com> wrote:
> > From: Eric Biggers <ebiggers@google.com>
> >
> > When chacha20_block() outputs the keystream block, it uses 'u32' stores
> > directly.  However, the callers (crypto/chacha20_generic.c and
> > drivers/char/random.c) declare the keystream buffer as a 'u8' array,
> > which is not guaranteed to have the needed alignment.
> >
> > Fix it by having both callers declare the keystream as a 'u32' array.
> > For now this is preferable to switching over to the unaligned access
> > macros because chacha20_block() is only being used in cases where we can
> > easily control the alignment (stack buffers).
> >
> 
> Given this paragraph, I think we agree the correct way to fix this
> would be to make chacha20_block() adhere to its prototype, so if we
> deviate from that, there should be a good reason. On which
> architecture that cares about alignment is this expected to result in
> a measurable performance benefit?
> 

Well, variables on the stack tend to be 4 or even 8-byte aligned anyway, so this
change probably doesn't make a difference in practice currently.  But it still
should be fixed, in case it does become a problem.

We could certainly leave the type as u8 array and use put_unaligned_le32()
instead; that would be a simpler change.  But that would be slower on
architectures where a potentially-unaligned access requires multiple
instructions.

Eric

  reply	other threads:[~2017-11-22 21:29 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 ` [PATCH 1/5] crypto: chacha20 - Fix unaligned access when loading constants Eric Biggers
2017-11-22 20:26   ` 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 [this message]
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=20171122212950.GA74584@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.