Skip to content

{bp-20193} arch/arm64: AES using the Armv8 Cryptography Extension - #20313

Merged
xiaoxiang781216 merged 2 commits into
apache:releases/13.1from
jerpelea:bp-20193
Sep 24, 2026
Merged

xiaoxiang781216 merged 2 commits into
apache:releases/13.1from
jerpelea:bp-20193

Conversation

@jerpelea

@jerpelea jerpelea commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

NuttX emits no AES instruction on any core. arm64 has no runtime feature dispatch, so a part that implements the Cryptography Extension still runs https://github.com/apache/nuttx/blob/master/crypto/rijndael.c, which indexes eight 256-entry tables with key-dependent values and so has cache-dependent timing.

How

aes_cypher() for ECB, CBC and CTR on AESE, AESD and the MixColumns pair, registered with /dev/crypto beside https://github.com/apache/nuttx/blob/master/arch/arm/src/stm32h7/stm32_crypto.c, https://github.com/apache/nuttx/blob/master/arch/arm/src/sam34/sam_crypto.c and https://github.com/apache/nuttx/blob/master/arch/xtensa/src/esp32/esp32_crypto.c.

ID_AA64ISAR0_EL1.AES is read on every call, returning -ENOTSUP rather than trapping.

Point |   -- | -- the first version defined the crypto/aes.h entry points | same five symbols as https://github.com/apache/nuttx/blob/master/crypto/aes.c, independent Kconfig gates, so enabling both failed to link. The aes_cypher() shape has no such clash SubWord borrows AESE with a zero round key | that yields the substituted word only if ShiftRows has nothing to move, so the word is replicated across all four columns first the CTR counter is the last four bytes | as https://github.com/apache/nuttx/blob/master/crypto/xform.c does, so both agree on what a stream looks like

Open, and why this is still a draft: xform.c, gmac.c, cmac.c and key_wrap.c reach AES through AES_CTX and keep the table version. Gating crypto/aes.c off when an arch provides those entry points would cover them. Happy to add that here.

includes
#20192

Impact

RELEASE

Testing

CI

up_addrenv_va_to_pa() is declared in include/nuttx/arch.h but implemented
only by armv7-a, so no arm64 port can map a virtual address to a physical
one. A driver whose device addresses memory physically has nothing to call.

The translation is asked of the MMU with AT S1E1R rather than walked in
software, so it answers for whatever is actually mapped: any granule size,
block or page, at any level, and it cannot drift from the tables in use.

PAR_EL1 is one register per CPU, so nothing may run between the translation
and reading the result. Interrupts are banked with it, so masking them
locally is sufficient and SMP needs nothing further.

Returns zero for an address that is not mapped for a privileged read, which
is what the declaration in arch.h specifies. Note this differs from the
armv7-a implementation, which returns the virtual address unchanged.

Signed-off-by: Royyan Zahir <royzah@gmail.com>
NuttX emits no AES instruction on any arm64 core. There is no runtime
feature dispatch in arch/arm64, so every AES goes through crypto/rijndael.c
or crypto/aes.c, and the table-driven one indexes memory with key-dependent
values, so its timing follows the cache.

Provide aes_cypher() for ECB, CBC and CTR built on AESE, AESD and the
MixColumns pair, and register it with /dev/crypto as a hardware driver
alongside the existing stm32h7, sam34 and esp32 modules.

ID_AA64ISAR0_EL1.AES is read on every call, which returns -ENOTSUP rather
than trapping on a core without the extension.

Verified against the NIST SP 800-38A appendix F vectors for ECB-128,
ECB-256, CBC-128, CBC-192 and CTR-128, encrypt and decrypt, in place and
out of place.

Signed-off-by: Royyan Zahir <royzah@gmail.com>
@github-actions github-actions Bot added Arch: arm64 Issues related to ARM64 (64-bit) architecture Size: L The size of the change in this PR is large labels Sep 23, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@xiaoxiang781216
xiaoxiang781216 merged commit e47e4a1 into apache:releases/13.1 Sep 24, 2026
25 checks passed
@jerpelea
jerpelea deleted the bp-20193 branch September 24, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm64 Issues related to ARM64 (64-bit) architecture Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants