Re: [PATCH v2] crypto: sun8i-ce - Add AES-XTS for the H616
From: Herbert Xu
Date: Fri Nov 20 2026 - 04:50:28 EST
On Tue, Nov 10, 2026 at 06:25:05AM +0000, Arun Iyengar via B4 Relay wrote:
> From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
>
> The H616 crypto engine has a separate RAES unit (algorithm type 0x30)
> that does AES-ECB, AES-CBC and AES-XTS. Its XTS mode (symmetric mode
> 0b1001) takes the two keys back to back at the key address, the tweak
> at the IV address, and an xts_first/xts_last pair of flags that mark the
> first and the last block of a data unit. The key size field gives the
> size of one of the two keys: 128 or 256 bits, there is no 192-bit XTS.
>
> Register xts(aes) for the H616: each request is one data unit, so both
> flags are set and the request IV is the tweak of its first block. XTS
> returns no IV, so the CBC write-back of the last block is skipped.
> Ciphertext stealing (lengths that are not a multiple of the block size)
> and two 192-bit keys go to the fallback, as do the requests that the
> existing checks already send there.
>
> The engine is much slower at XTS than the CPU's ARMv8 AES instructions:
> 4 times slower for 64 KiB requests (213 against 861 MB/s), 8 times for
> 4 KiB and 17 times for 512 bytes. Register it below every CPU
> implementation of xts(aes) (priority 90), so that the CPU stays the
> default, for dm-crypt too, and the engine is only used when it is
> asked for by driver name.
>
> The other variants get CE_ID_NOTSUPP for the new mode, so nothing
> changes for them.
>
> Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
> ---
> The H616 crypto engine can do AES-XTS in its separate RAES unit. This
> patch registers xts(aes) for the H616, below the CPU implementations
> because the engine is slower than the ARMv8 Crypto Extensions; it stays
> available by driver name (xts-aes-sun8i-ce) for users who want to
> offload the CPU.
>
> Testing on an Orange Pi Zero2 (H616), v7.3-based kernel with this
> patch (sun8i-ce is unchanged between v7.3 and cryptodev-2.6):
> - the boot-time self-test of xts-aes-sun8i-ce passes, and the testmgr
> vectors run on the engine (debugfs request counters);
> - 21 known-answer vectors (IEEE 1619 and generated, including
> ciphertext stealing lengths, which go to the fallback) pass, and 3000
> random requests (10% with misaligned buffers) give the same result as
> xts-aes-ce;
> - dm-crypt with capi:xts-aes-sun8i-ce-plain64, 512 and 4096-byte
> sectors: 48 MiB written and read back with matching sha256, and the
> raw sectors decrypt with xts-aes-ce; with this priority, xts(aes)
> and plain aes-xts-plain64 resolve to the CPU's xts-aes-ce;
> - the existing ECB/CBC ciphers, hashes and the TRNG still match their
> software implementations.
> Throughput, engine against xts-aes-ce: 20/352 MB/s for 512-byte
> requests, 98/759 MB/s for 4 KiB, 213/861 MB/s for 64 KiB.
>
> This patch was developed with Claude (Anthropic) as a
> coding assistant: it investigated the problem, wrote the code and
> the commit messages. I reviewed it, and it was tested on an
> Orange Pi Zero2 (H616) as described above.
> ---
> Changes in v2:
> - Select CRYPTO_XTS: the xts(aes) transform allocates an xts(aes)
> fallback in sun8i_ce_cipher_init(), which fails without it (found by
> the Sashiko AI review).
> - Link to v1: https://patch.msgid.link/20261110-sun8i-ce-h616-xts-v1-1-2fff3eb0807a@xxxxxxxxx
>
> To: Corentin Labbe <clabbe.montjoie@xxxxxxxxx>
> To: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
> To: "David S. Miller" <davem@xxxxxxxxxxxxx>
> To: Chen-Yu Tsai <wens@xxxxxxxxxx>
> To: Jernej Skrabec <jernej.skrabec@xxxxxxxxx>
> To: Samuel Holland <samuel@xxxxxxxxxxxx>
> Cc: linux-crypto@xxxxxxxxxxxxxxx
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Cc: linux-sunxi@xxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> ---
> drivers/crypto/allwinner/Kconfig | 1 +
> .../crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 102 +++++++++++++++++----
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 44 +++++++--
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 21 ++++-
> 4 files changed, 142 insertions(+), 26 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt