Skip to content

refactor(aes): machine-word generic fixslice#560

Merged
newpavlov merged 5 commits into
RustCrypto:masterfrom
privacy-ethereum:refactor/fixslice-generic
Jul 24, 2026
Merged

refactor(aes): machine-word generic fixslice#560
newpavlov merged 5 commits into
RustCrypto:masterfrom
privacy-ethereum:refactor/fixslice-generic

Conversation

@sinui0

@sinui0 sinui0 commented May 15, 2026

Copy link
Copy Markdown
Contributor

This PR collapses the two fixslice impls into a single fixslice.rs parameterized over a Word trait that abstracts the machine-word width.

I tried to structure the commits to make it clear to the reviewer that this introduces no changes to the existing implementation logic.

This PR was motivated by #559 to support larger machine-word (SIMD) implementations without introducing major duplication and maintenance burden.

@tarcieri

Copy link
Copy Markdown
Member

This looks good to me as a general direction, though it may be some time before I can review it in detail.

I'm a bit confused how this broke the build the way it did, it seems somehow with only changes to the soft backend it broke things in the NEON backend somehow?

@sinui0

sinui0 commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

I haven't looked closely at the CI yet, but perhaps it is already broken on latest stable rustc prior to this PR?

@newpavlov

Copy link
Copy Markdown
Member

The CI failures were fixed in #562.

sinui0 added 4 commits May 26, 2026 09:11
Drop the cpubits-based selection between width-specific fixslice modules
in preparation for unifying both into a single width-generic implementation.
Refactor the fixslice AES implementation so the algorithm body is generic
over a `Word` trait, with a single `impl Word for u32` carrying all
width-specific code (row width, packing routines, bitslice/inv_bitslice).

The three-pass delta-swap pipeline used by `bitslice` and `inv_bitslice`
is extracted into a shared width-generic `bitslice_swaps` helper, with
mask constants derived from a `Word::byte_repeat` method. Each impl now
only carries the bytes-in/bytes-out routine.

This is a purely mechanical refactor: no logic changes, no behavior
changes, the only word width supported is still `u32`.
Add the second `Word` impl, `impl Word for u64`, which batches 4 blocks
per state versus 2 for `u32`. The concrete re-exports and the hazmat
helpers are gated by `target_pointer_width` via `cpubits!`, selecting
`u32` on 16/32-bit targets and `u64` on 64-bit.
@sinui0
sinui0 force-pushed the refactor/fixslice-generic branch from d237e81 to 0f8f6b9 Compare May 26, 2026 16:13
Comment thread aes/src/soft/fixslice.rs
type Blocks: ArraySize;

/// Width in bits of one row of the bitsliced state (8 for `u32`, 16 for `u64`).
const ROW_BITS: u32;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this could have a default? (could probably use an explanatory comment)

Suggested change
const ROW_BITS: u32;
const ROW_BITS: u32 = size_of::<Self>() * 2;

...or if HALF_ROW were defined this way it gets rid of the * 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I am a bit surprised that it works. I will fix it as part of #575.

@tarcieri tarcieri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the amount of duplication this gets rid of and would like to see it landed

@tarcieri tarcieri mentioned this pull request Jul 23, 2026
@newpavlov
newpavlov merged commit 8539fad into RustCrypto:master Jul 24, 2026
28 checks passed
@newpavlov newpavlov mentioned this pull request Jul 24, 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.

3 participants