Portable AES-128 primitive

cdk-rsx-crypto-aes supplies AES-128 encryption with borrowed buffers and no allocation or host crypto. This is a block primitive, without an encryption mode or authentication.

Feature Type Parallel blocks Expanded key
fixslice32 Aes128 2 352 bytes, owned and wiped
simd128 Aes128Simd 8 1,408 bytes, owned and wiped
simd128 ZeroKeyAes128Simd 8 Immutable public-zero-key schedule; owner is zero-sized
simd128-vpaes SIMD types above Byte-vector 1/2/4; Boolean 8 Same owners; compact public-zero schedule

The SIMD types add borrowed/in-place encrypt_eight to the one/two/four-block methods below. With simd128 alone, smaller calls use public zero dummy lanes. No secret selects addresses, branch directions or shuffle indices. Named secret scratch and owned schedules wipe at the end of their lifetime; compiler temporaries and register erasure are outside that guarantee. The Wasm64 SIMD feature uses the repository's pinned nightly compiler; native u128 emulation is a correctness path, not an IC performance result.

The optional simd128-vpaes feature selects an OpenSSL-vpaes-derived nibble mapping for one/two/four-block methods, including in-place calls. Eight-block methods keep the Boolean equations. Secret swizzle indices require hardware register-swizzle lowering on the execution engine; this is a supported-host assumption, not a universal Wasm-host constant-time guarantee. Native emulation uses fixed masked scans. The qualified engine/source chain and actual target checks are retained in the round5 report. The optional implementation ID is openssl-vpaes-rustcrypto-aes128-simd128-hybrid-v1. Secret schedules, caller ownership and byte contracts remain unchanged.

The Boolean SIMD path uses the pinned RustCrypto S-box with a byte-oriented fixsliced linear layer. Scratch owners are reused across the nine full rounds and wiped once per encryption call. SIMD provenance records its derivation, source and tests. The measured comparison qualifies public-zero-key GC operations. Target tests additionally check the general-key constructor, borrowed eight-block calls and borrowed/in-place one/two/four-block methods; all typed APIs have separate native known-answer/differential tests. Public-zero-key construction costs are not general secret-key expansion costs.

The default feature set exposes no cipher implementation. All backends use the same FIPS 197 AES bytes. The remaining source detail describes the fixed fixslice32 reference profile rustcrypto-aes128-fixslice32-v1 (PROFILE_ID).

Aes128::new(&[u8; 16]) borrows a general 128-bit key and caches its 352-byte expanded schedule. The owner has no Clone, Debug or serialization traits. Its Drop implementation wipes the schedule using zeroize. The original key remains caller-owned.

The borrowed-buffer methods are:

fn encrypt_block(&self, input: &[u8; 16], output: &mut [u8; 16]);
fn encrypt_two(&self, input: &[[u8; 16]; 2], output: &mut [[u8; 16]; 2]);
fn encrypt_four(&self, input: &[[u8; 16]; 4], output: &mut [[u8; 16]; 4]);
fn encrypt_block_in_place(&self, block: &mut [u8; 16]);
fn encrypt_two_in_place(&self, blocks: &mut [[u8; 16]; 2]);
fn encrypt_four_in_place(&self, blocks: &mut [[u8; 16]; 4]);

One call into the u32 arithmetic encrypts exactly two independent blocks. A single-block operation supplies one zero dummy block and discards its result; two-block operations use both lanes; four-block operations use two pairs. Public array sizes determine all indexing and work. Byte arrays need no alignment beyond one byte. The wrapper allocates no heap buffers and acquires no randomness or host cryptography. Its own 32-byte input/output scratch owners wipe on drop; caller buffers remain caller-owned. The upstream internal state and compiler temporary-erasure behavior are unchanged; this does not claim to erase every temporary register or stack copy.

The RustCrypto 0.8.4 software dispatch selects its u64/four-block backend on 64-bit targets. This crate deliberately selects the pinned u32/two-block implementation on every target. RustCrypto describes the software algorithm as constant-time bitwise arithmetic without lookup tables or secret-dependent branches in its versioned documentation. The fixslicing paper supplies background; its results on other processors are not measurements of this crate or the IC. No default performance recommendation follows from the smaller batch width.

The vendor file is copied byte-for-byte from aes 0.8.4, source commit f2dbee516b4d0cf4cb4f3045d09e35b5fd80087b. Both upstream licenses are retained under vendor/. UPSTREAM.json records file hashes, exact dependencies and the source/function map. The vendor file's AES-128 encryption comment says four blocks; its U2 batch type and code process two blocks. The wrapper documents the actual width without modifying the frozen source. Unused AES-192/256, decryption and round helpers remain private. The preserved aes_compact and hazmat configuration inputs are explicitly registered with the compiler, but selecting either is rejected; this profile has one arithmetic variant.

Crate-local tests cover the FIPS AES-128 example, all four SP 800-38A F.1.1 blocks, the zero key/block answer, lane reversal, 256 nibble-pattern key/block combinations, all 128 key/block bit positions and 256 deterministic full-byte cases. Every corpus case checks all six methods against registry aes = 0.8.4. The native oracle may select hardware AES; a matched portable control uses the existing aes_force_soft compiler configuration. Unaligned byte buffers and adjacent sentinels are checked separately.

The workspace build owner runs validation, for example:

cargo test --manifest-path cdk-rsx/Cargo.toml \
  -p cdk-rsx-crypto-aes --features fixslice32 --locked --offline

Native vectors, actual installed-Wasm byte comparisons and measured IC costs are separate qualification steps. No build or timing result is implied by this source record; dated benchmark receipts record completed runs.