From: Eric Biggers <ebiggers@google.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Martin Willi <martin@strongswan.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-crypto@vger.kernel.org, David Miller <davem@davemloft.net>,
WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Re: [PATCH] poly1305: generic C can be faster on chips with slow unaligned access
Date: Mon, 7 Nov 2016 10:26:46 -0800 [thread overview]
Message-ID: <20161107182646.GA34388@google.com> (raw)
In-Reply-To: <CAHmME9oejs+USiGJX2P0TgvnR6XRzV1HYZPrq=c-CjGzq59=NQ@mail.gmail.com>
On Mon, Nov 07, 2016 at 07:08:22PM +0100, Jason A. Donenfeld wrote:
> Hmm... The general data flow that strikes me as most pertinent is
> something like:
>
> struct sk_buff *skb = get_it_from_somewhere();
> skb = skb_share_check(skb, GFP_ATOMIC);
> num_frags = skb_cow_data(skb, ..., ...);
> struct scatterlist sg[num_frags];
> sg_init_table(sg, num_frags);
> skb_to_sgvec(skb, sg, ..., ...);
> blkcipher_walk_init(&walk, sg, sg, len);
> blkcipher_walk_virt_block(&desc, &walk, BLOCK_SIZE);
> while (walk.nbytes >= BLOCK_SIZE) {
> size_t chunk_len = rounddown(walk.nbytes, BLOCK_SIZE);
> poly1305_update(&poly1305_state, walk.src.virt.addr, chunk_len);
> blkcipher_walk_done(&desc, &walk, walk.nbytes % BLOCK_SIZE);
> }
> if (walk.nbytes) {
> poly1305_update(&poly1305_state, walk.src.virt.addr, walk.nbytes);
> blkcipher_walk_done(&desc, &walk, 0);
> }
>
> Is your suggestion that that in the final if block, walk.src.virt.addr
> might be unaligned? Like in the case of the last fragment being 67
> bytes long?
I was not referring to any users in particular, only what users could do. As an
example, if you did crypto_shash_update() with 32, 15, then 17 bytes, and the
underlying algorithm is poly1305-generic, the last block would end up
misaligned. This doesn't appear possible with your pseudocode because it only
passes in multiples of the block size until the very end. However I don't see
it claimed anywhere that shash API users have to do that.
Eric
WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@google.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Martin Willi <martin@strongswan.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-crypto@vger.kernel.org, David Miller <davem@davemloft.net>,
WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Re: [WireGuard] [PATCH] poly1305: generic C can be faster on chips with slow unaligned access
Date: Mon, 7 Nov 2016 10:26:46 -0800 [thread overview]
Message-ID: <20161107182646.GA34388@google.com> (raw)
In-Reply-To: <CAHmME9oejs+USiGJX2P0TgvnR6XRzV1HYZPrq=c-CjGzq59=NQ@mail.gmail.com>
On Mon, Nov 07, 2016 at 07:08:22PM +0100, Jason A. Donenfeld wrote:
> Hmm... The general data flow that strikes me as most pertinent is
> something like:
>
> struct sk_buff *skb = get_it_from_somewhere();
> skb = skb_share_check(skb, GFP_ATOMIC);
> num_frags = skb_cow_data(skb, ..., ...);
> struct scatterlist sg[num_frags];
> sg_init_table(sg, num_frags);
> skb_to_sgvec(skb, sg, ..., ...);
> blkcipher_walk_init(&walk, sg, sg, len);
> blkcipher_walk_virt_block(&desc, &walk, BLOCK_SIZE);
> while (walk.nbytes >= BLOCK_SIZE) {
> size_t chunk_len = rounddown(walk.nbytes, BLOCK_SIZE);
> poly1305_update(&poly1305_state, walk.src.virt.addr, chunk_len);
> blkcipher_walk_done(&desc, &walk, walk.nbytes % BLOCK_SIZE);
> }
> if (walk.nbytes) {
> poly1305_update(&poly1305_state, walk.src.virt.addr, walk.nbytes);
> blkcipher_walk_done(&desc, &walk, 0);
> }
>
> Is your suggestion that that in the final if block, walk.src.virt.addr
> might be unaligned? Like in the case of the last fragment being 67
> bytes long?
I was not referring to any users in particular, only what users could do. As an
example, if you did crypto_shash_update() with 32, 15, then 17 bytes, and the
underlying algorithm is poly1305-generic, the last block would end up
misaligned. This doesn't appear possible with your pseudocode because it only
passes in multiples of the block size until the very end. However I don't see
it claimed anywhere that shash API users have to do that.
Eric
WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@google.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: "David Miller" <davem@davemloft.net>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
linux-crypto@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
"Martin Willi" <martin@strongswan.org>,
"WireGuard mailing list" <wireguard@lists.zx2c4.com>,
"René van Dorst" <opensource@vdorst.com>
Subject: Re: [PATCH] poly1305: generic C can be faster on chips with slow unaligned access
Date: Mon, 7 Nov 2016 10:26:46 -0800 [thread overview]
Message-ID: <20161107182646.GA34388@google.com> (raw)
In-Reply-To: <CAHmME9oejs+USiGJX2P0TgvnR6XRzV1HYZPrq=c-CjGzq59=NQ@mail.gmail.com>
On Mon, Nov 07, 2016 at 07:08:22PM +0100, Jason A. Donenfeld wrote:
> Hmm... The general data flow that strikes me as most pertinent is
> something like:
>
> struct sk_buff *skb = get_it_from_somewhere();
> skb = skb_share_check(skb, GFP_ATOMIC);
> num_frags = skb_cow_data(skb, ..., ...);
> struct scatterlist sg[num_frags];
> sg_init_table(sg, num_frags);
> skb_to_sgvec(skb, sg, ..., ...);
> blkcipher_walk_init(&walk, sg, sg, len);
> blkcipher_walk_virt_block(&desc, &walk, BLOCK_SIZE);
> while (walk.nbytes >= BLOCK_SIZE) {
> size_t chunk_len = rounddown(walk.nbytes, BLOCK_SIZE);
> poly1305_update(&poly1305_state, walk.src.virt.addr, chunk_len);
> blkcipher_walk_done(&desc, &walk, walk.nbytes % BLOCK_SIZE);
> }
> if (walk.nbytes) {
> poly1305_update(&poly1305_state, walk.src.virt.addr, walk.nbytes);
> blkcipher_walk_done(&desc, &walk, 0);
> }
>
> Is your suggestion that that in the final if block, walk.src.virt.addr
> might be unaligned? Like in the case of the last fragment being 67
> bytes long?
I was not referring to any users in particular, only what users could do. As an
example, if you did crypto_shash_update() with 32, 15, then 17 bytes, and the
underlying algorithm is poly1305-generic, the last block would end up
misaligned. This doesn't appear possible with your pseudocode because it only
passes in multiples of the block size until the very end. However I don't see
it claimed anywhere that shash API users have to do that.
Eric
next prev parent reply other threads:[~2016-11-07 18:26 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-02 17:58 [PATCH] poly1305: generic C can be faster on chips with slow unaligned access Jason A. Donenfeld
2016-11-02 20:09 ` Herbert Xu
2016-11-02 20:47 ` Sandy Harris
2016-11-02 21:06 ` Jason A. Donenfeld
2016-11-02 21:08 ` Herbert Xu
2016-11-02 21:25 ` Jason A. Donenfeld
2016-11-02 21:26 ` Herbert Xu
2016-11-02 22:00 ` Jason A. Donenfeld
2016-11-03 0:49 ` Herbert Xu
2016-11-03 7:24 ` Jason A. Donenfeld
2016-11-03 17:08 ` David Miller
2016-11-03 22:20 ` Jason A. Donenfeld
2016-11-03 22:20 ` Jason A. Donenfeld
2016-11-03 22:20 ` [WireGuard] " Jason A. Donenfeld
2016-11-04 17:37 ` Eric Biggers
2016-11-04 17:37 ` [WireGuard] " Eric Biggers
2016-11-07 18:08 ` Jason A. Donenfeld
2016-11-07 18:08 ` Jason A. Donenfeld
2016-11-07 18:08 ` [WireGuard] " Jason A. Donenfeld
2016-11-07 18:23 ` Jason A. Donenfeld
2016-11-07 18:23 ` Jason A. Donenfeld
2016-11-07 18:23 ` [WireGuard] " Jason A. Donenfeld
2016-11-07 18:26 ` Eric Biggers [this message]
2016-11-07 18:26 ` Eric Biggers
2016-11-07 18:26 ` [WireGuard] " Eric Biggers
2016-11-07 19:02 ` Jason A. Donenfeld
2016-11-07 19:02 ` Jason A. Donenfeld
2016-11-07 19:02 ` [WireGuard] " Jason A. Donenfeld
2016-11-07 19:25 ` Eric Biggers
2016-11-07 19:25 ` Eric Biggers
2016-11-07 19:25 ` [WireGuard] " Eric Biggers
2016-11-07 19:41 ` Jason A. Donenfeld
2016-11-07 19:41 ` Jason A. Donenfeld
2016-11-07 19:41 ` [WireGuard] " Jason A. Donenfeld
2016-11-07 19:12 ` [PATCH v2] " Jason A. Donenfeld
2016-11-07 19:43 ` [PATCH v3] " Jason A. Donenfeld
2016-11-12 23:27 ` kbuild test robot
2016-11-07 19:47 ` [PATCH v4] " Jason A. Donenfeld
2016-11-07 20:40 ` Eric Biggers
2016-11-08 7:52 ` Martin Willi
2016-11-08 17:26 ` Eric Biggers
2016-11-13 11:29 ` 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=20161107182646.GA34388@google.com \
--to=ebiggers@google.com \
--cc=Jason@zx2c4.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin@strongswan.org \
--cc=wireguard@lists.zx2c4.com \
/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.