Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Qingfang Deng <qingfang.deng@linux.dev>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-crypto@vger.kernel.org, linux-arm-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] lib/crypto: arm64/ghash: Aggregate 4 blocks per loop
Date: Fri, 27 Nov 2026 11:08:12 -0800	[thread overview]
Message-ID: <20261127190812.GB8300@quark> (raw)
In-Reply-To: <20261123095409.2518-1-qingfang.deng@linux.dev>

On Mon, Nov 23, 2026 at 05:53:55PM +0800, Qingfang Deng wrote:
> The byte-PMULL GHASH implementation reconstructs and reduces a field
> product for every input block. Aggregate four blocks using precomputed
> powers of the hash key, which the ARM64 CE version already uses:
> 
>   (Y ^ X1) * H^4 ^ X2 * H^3 ^ X3 * H^2 ^ X4 * H
> 
> Split each polynomial multiplication into 32-bit Karatsuba products,
> pair them in SIMD lanes and accumulate them before reconstruction.
> Reconstruct three 128-bit products and perform one Montgomery reduction
> for the group. Use three byte PMULL instructions with 0xc2 for reduction
> modulo x^128 + x^127 + x^126 + x^121 + 1.
> 
> Retain the low and high halves of H^4 through H, and their XORs, in
> x4-x15. Use x16-x17 to construct the inner 32-bit cross operands while
> independent SIMD products retire. Prepare each next key operand in
> v9-v11. This avoids an expanded table of key rotations and needs no
> register spills. Use the existing single-block pmull_ghash_update_p8
> helper for tails.
> 
> Compare the single-block and this four-block path in the same userspace
> harness on a Cortex-A53 at 1.2 GHz. Median throughput in Gbit/s:
> 
>   Bytes   Baseline   4-block
>      16   0.850016   0.844973
>      64   1.015665   1.723762
>    1440   1.081407   1.968001
>   16384   1.085286   2.032019
>   65536   1.083460   2.025681
> 
> The four-block loop uses 296 instructions, and reaches about 0.980
> instructions per cycle in 64 KiB measurements on Cortex-A53.
> 
> Assisted-by: LLM
> Signed-off-by: Qingfang Deng <qingfang.deng@linux.dev>

Thanks.  I'd like to wait a bit before taking this, since this will
likely change when the arm64 AES-GCM code is migrated into lib/crypto/.
I am doing x86 first, but I'll look at arm64 afterwards.

- Eric

      reply	other threads:[~2026-11-27 19:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  9:53 [RFC PATCH] lib/crypto: arm64/ghash: Aggregate 4 blocks per loop Qingfang Deng
2026-11-27 19:08 ` 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=20261127190812.GB8300@quark \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-kernel@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=qingfang.deng@linux.dev \
    /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