From: Eric Biggers <ebiggers@kernel.org>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-riscv@lists.infradead.org,
"Palmer Dabbelt" <palmer@dabbelt.com>,
linux-crypto@vger.kernel.org,
"Jerry Shih" <jerry.shih@sifive.com>,
"Christoph Müllner" <christoph.muellner@vrull.eu>,
"Heiko Stuebner" <heiko@sntech.de>,
"Phoebe Chen" <phoebe.chen@sifive.com>,
"Andy Chiu" <andy.chiu@sifive.com>
Subject: Re: [PATCH riscv/for-next] crypto: riscv - add vector crypto accelerated AES-CBC-CTS
Date: Wed, 14 Feb 2024 14:42:27 -0800 [thread overview]
Message-ID: <20240214224227.GA1638@sol.localdomain> (raw)
In-Reply-To: <CAMj1kXEjEhZY6zoQQzJioBB6QVGJbCmO2w5T3+T0=iPxHmvYJQ@mail.gmail.com>
On Wed, Feb 14, 2024 at 05:34:03PM +0100, Ard Biesheuvel wrote:
> On Tue, 13 Feb 2024 at 06:57, Eric Biggers <ebiggers@kernel.org> wrote:
> >
> > From: Eric Biggers <ebiggers@google.com>
> >
> > Add an implementation of cts(cbc(aes)) accelerated using the Zvkned
> > RISC-V vector crypto extension. This is mainly useful for fscrypt,
> > where cts(cbc(aes)) is the "default" filenames encryption algorithm. In
> > that use case, typically most messages are short and are block-aligned.
>
> Does this mean the storage space for filenames is rounded up to AES block size?
Yes, in most cases. fscrypt allows the filenames padding to be configured to be
4, 8, 16, or 32 bytes. If it's 16 or 32, which is recommended, then the sizes
of encrypted filenames are multiples of the AES block size, except for filenames
longer than 240 bytes which get rounded up to 255 bytes.
>
> > The CBC-CTS variant implemented is CS3; this is the variant Linux uses.
> >
> > To perform well on short messages, the new implementation processes the
> > full message in one call to the assembly function if the data is
> > contiguous. Otherwise it falls back to CBC operations followed by CTS
> > at the end. For decryption, to further improve performance on short
> > messages, especially block-aligned messages, the CBC-CTS assembly
> > function parallelizes the AES decryption of all full blocks.
>
> Nice!
>
> > This
> > improves on the arm64 implementation of cts(cbc(aes)), which always
> > splits the CBC part(s) from the CTS part, doing the AES decryptions for
> > the last two blocks serially and usually loading the round keys twice.
> >
>
> So is the overhead of this sub-optimal approach mostly in the
> redundant loading of the round keys? Or are there other significant
> benefits?
>
> If there are, I suppose we might port this improvement to x86 too, but
> otherwise, I guess it'll only make sense for arm64.
I expect that the serialization of the last two AES decryptions makes the
biggest difference, followed by the other sources of overhead (loading round
keys, skcipher_walk, kernel_neon_begin). It needs to be measured, though.
I'd like to try the same optimization for arm64 and x86. It's not fun going
back to SIMD after working with the RISC-V Vector Extension, though!
- Eric
next prev parent reply other threads:[~2024-02-14 22:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-13 5:54 [PATCH riscv/for-next] crypto: riscv - add vector crypto accelerated AES-CBC-CTS Eric Biggers
2024-02-14 16:34 ` Ard Biesheuvel
2024-02-14 22:42 ` Eric Biggers [this message]
2024-03-20 20:50 ` patchwork-bot+linux-riscv
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=20240214224227.GA1638@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=andy.chiu@sifive.com \
--cc=ardb@kernel.org \
--cc=christoph.muellner@vrull.eu \
--cc=heiko@sntech.de \
--cc=jerry.shih@sifive.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=phoebe.chen@sifive.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox