From: Eric Biggers <ebiggers@kernel.org>
To: Nathan Huckleberry <nhuck@google.com>
Cc: linux-crypto@vger.kernel.org,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-arm-kernel@lists.infradead.org,
Paul Crowley <paulcrowley@google.com>,
Sami Tolvanen <samitolvanen@google.com>,
Ard Biesheuvel <ardb@kernel.org>
Subject: Re: [RFC PATCH v2 7/7] crypto: arm64/polyval: Add PMULL accelerated implementation of POLYVAL
Date: Fri, 18 Feb 2022 17:21:17 -0800 [thread overview]
Message-ID: <YhBGDbNOs2crcmzd@sol.localdomain> (raw)
In-Reply-To: <20220210232812.798387-8-nhuck@google.com>
A lot of the comments I made on the x86_64 version apply to the arm64 version,
but a few more comments below:
On Thu, Feb 10, 2022 at 11:28:12PM +0000, Nathan Huckleberry wrote:
> Add hardware accelerated version of POLYVAL for ARM64 CPUs with
> Crypto Extension support.
Nit: It's "Crypto Extensions", not "Crypto Extension".
> +config CRYPTO_POLYVAL_ARM64_CE
> + tristate "POLYVAL using ARMv8 Crypto Extensions (for HCTR2)"
> + depends on KERNEL_MODE_NEON
> + select CRYPTO_CRYPTD
> + select CRYPTO_HASH
> + select CRYPTO_POLYVAL
CRYPTO_POLYVAL selects CRYPTO_HASH already, so there's no need to select it
here.
> /*
> * Handle any extra blocks before
> * full_stride loop.
> */
> .macro partial_stride
> eor LO.16b, LO.16b, LO.16b
> eor MI.16b, MI.16b, MI.16b
> eor HI.16b, HI.16b, HI.16b
> add KEY_START, x1, #(NUM_PRECOMPUTE_POWERS << 4)
> sub KEY_START, KEY_START, PARTIAL_LEFT, lsl #4
> ld1 {v0.16b}, [KEY_START]
> mov v1.16b, SUM.16b
> karatsuba1 v0 v1
> karatsuba2
> montgomery_reduction
> mov SUM.16b, PH.16b
> eor LO.16b, LO.16b, LO.16b
> eor MI.16b, MI.16b, MI.16b
> eor HI.16b, HI.16b, HI.16b
> mov IND, XZR
> .LloopPartial:
> cmp IND, PARTIAL_LEFT
> bge .LloopExitPartial
>
> sub TMP, IND, PARTIAL_LEFT
>
> cmp TMP, #-4
> bgt .Lgt4Partial
> ld1 {M0.16b, M1.16b, M2.16b, M3.16b}, [x0], #64
> // Clobber key registers
> ld1 {KEY8.16b, KEY7.16b, KEY6.16b, KEY5.16b}, [KEY_START], #64
> karatsuba1 M0 KEY8
> karatsuba1 M1 KEY7
> karatsuba1 M2 KEY6
> karatsuba1 M3 KEY5
> add IND, IND, #4
> b .LoutPartial
>
> .Lgt4Partial:
> cmp TMP, #-3
> bgt .Lgt3Partial
> ld1 {M0.16b, M1.16b, M2.16b}, [x0], #48
> // Clobber key registers
> ld1 {KEY8.16b, KEY7.16b, KEY6.16b}, [KEY_START], #48
> karatsuba1 M0 KEY8
> karatsuba1 M1 KEY7
> karatsuba1 M2 KEY6
> add IND, IND, #3
> b .LoutPartial
>
> .Lgt3Partial:
> cmp TMP, #-2
> bgt .Lgt2Partial
> ld1 {M0.16b, M1.16b}, [x0], #32
> // Clobber key registers
> ld1 {KEY8.16b, KEY7.16b}, [KEY_START], #32
> karatsuba1 M0 KEY8
> karatsuba1 M1 KEY7
> add IND, IND, #2
> b .LoutPartial
>
> .Lgt2Partial:
> ld1 {M0.16b}, [x0], #16
> // Clobber key registers
> ld1 {KEY8.16b}, [KEY_START], #16
> karatsuba1 M0 KEY8
> add IND, IND, #1
> .LoutPartial:
> b .LloopPartial
> .LloopExitPartial:
> karatsuba2
> montgomery_reduction
> eor SUM.16b, SUM.16b, PH.16b
> .endm
This sort of logic for handling different message lengths is necessary, but it's
partly why I think that testing different message lengths is so important --
there could be bugs that are specific to particular message lengths.
With CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y, we do get test coverage from the fuzz
tests that compare implementations to the corresponding generic implementation.
But, it's preferable to not rely on that and have good default test vectors too.
It looks like you already do a relatively good job with the message lengths in
the polyval test vectors. But it might be worth adding a test vector where the
length mod 128 is 112, so that the case where partial_stride processes 7 blocks
is tested. Also one where the message length is greater than 128 (or even 256)
bytes but isn't a multiple of 128, so that the case where *both* partial_stride
and full_stride are executed is tested.
- Eric
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
prev parent reply other threads:[~2022-02-19 1:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-10 23:28 [RFC PATCH v2 0/7] crypto: HCTR2 support Nathan Huckleberry
2022-02-10 23:28 ` [RFC PATCH v2 1/7] crypto: xctr - Add XCTR support Nathan Huckleberry
2022-02-16 23:00 ` Eric Biggers
2022-02-17 7:07 ` Arnd Bergmann
2022-02-10 23:28 ` [RFC PATCH v2 2/7] crypto: polyval - Add POLYVAL support Nathan Huckleberry
2022-02-16 23:16 ` Eric Biggers
2022-02-10 23:28 ` [RFC PATCH v2 3/7] crypto: hctr2 - Add HCTR2 support Nathan Huckleberry
2022-02-17 1:07 ` Eric Biggers
2022-02-10 23:28 ` [RFC PATCH v2 4/7] crypto: x86/aesni-xctr: Add accelerated implementation of XCTR Nathan Huckleberry
2022-02-19 1:28 ` Eric Biggers
2022-02-10 23:28 ` [RFC PATCH v2 5/7] crypto: arm64/aes-xctr: " Nathan Huckleberry
2022-02-11 11:48 ` Ard Biesheuvel
2022-02-11 20:30 ` Nathan Huckleberry
2022-02-12 10:08 ` Ard Biesheuvel
2022-02-10 23:28 ` [RFC PATCH v2 6/7] crypto: x86/polyval: Add PCLMULQDQ accelerated implementation of POLYVAL Nathan Huckleberry
2022-02-19 0:34 ` Eric Biggers
2022-02-19 0:54 ` Eric Biggers
2022-02-10 23:28 ` [RFC PATCH v2 7/7] crypto: arm64/polyval: Add PMULL " Nathan Huckleberry
2022-02-19 1:21 ` Eric Biggers [this message]
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=YhBGDbNOs2crcmzd@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=ardb@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=nhuck@google.com \
--cc=paulcrowley@google.com \
--cc=samitolvanen@google.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