Skip to content

aes: only select VAES backends when AES-NI is available - #610

Closed
zmanian wants to merge 1 commit into
RustCrypto:masterfrom
zmanian:aes-vaes-require-aesni
Closed

zmanian wants to merge 1 commit into
RustCrypto:masterfrom
zmanian:aes-vaes-require-aesni

Conversation

@zmanian

@zmanian zmanian commented Nov 25, 2026

Copy link
Copy Markdown

KeyInit::new initializes the aes (AES-NI) variant of the inner union only when the aes CPU feature is detected, and the soft variant otherwise. The VAES encrypt/decrypt paths are selected by the vaes256 / vaes512 tokens alone, and they read self.inner.aes.enc_rk / dec_rk and call the AES-NI single-block routines.

So on a CPU (or a VM whose hypervisor masks CPUID bits) that reports VAES (and AVX-512 state for the 512-bit path) without AES-NI, the cipher is keyed through the soft backend and then encrypted through VAES reading the uninitialized aes variant. The union has no repr, so depending on layout this either runs AES rounds over a soft-schedule-derived key (silently wrong output; the instructions still execute when the CPUID bit is masked) or reads uninitialized memory. Bare-metal CPUs with VAES also have AES-NI, so this matters mainly under virtualization or confidential-computing guests where the host influences CPUID.

This makes the VAES tokens also require aes, plus avx2 for the 256-bit backend (vaes implies aes, avx and avx2 as target features), so the VAES paths can only run when the AES-NI round keys were initialized.

Tested: cargo test -p aes --target x86_64-apple-darwin, clippy (--lib --tests, -D warnings) and cargo check --target x86_64-unknown-linux-gnu. There is no regression test, because the tokens come from cpufeatures and can't be forced without a test-only constructor; happy to add one if you'd like that shape. I left the CHANGELOG for the release.

🤖 Generated with Claude Code

The VAES encrypt/decrypt paths read the `aes` variant of the inner
union (the AES-NI round keys) and call the AES-NI single-block routines,
but `KeyInit::new` only initializes that variant when the `aes` CPU
feature is detected. On a CPU or hypervisor that reports VAES without
AES-NI, the cipher was keyed through the soft backend and then encrypted
through VAES reading the uninitialized `aes` variant.

Require `aes` (and `avx2` for the 256-bit backend, which `vaes`
implies as a target feature) in the VAES feature tokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@newpavlov

Copy link
Copy Markdown
Member

vaes target feature implies aes.

@newpavlov newpavlov closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants