Skip to content

ascon: improve performance of permutation#118

Open
Gusted wants to merge 1 commit intoRustCrypto:masterfrom
Gusted:improve-perf
Open

ascon: improve performance of permutation#118
Gusted wants to merge 1 commit intoRustCrypto:masterfrom
Gusted:improve-perf

Conversation

@Gusted
Copy link

@Gusted Gusted commented Mar 22, 2026

Use a slightly different substitution implementation that is slightly more efficient. This does require that the function is now strictly seperated in the three layers.

The assembly with -C opt-level=2 shows no weird instructions, permute_12 without soft-compact is fully unrolled and from and to arrays is skipped. With soft-compat it's not unrolled but does also skip from and to arrays between the iterations.

Benchmarks with and without soft-compat are quite similair (to the point I'm guessing I'm not even running it correctly).

Permutation/1 round     time:   [4.6049 ns 4.6597 ns 4.7094 ns]
                        change: [-17.040% -15.975% -14.976%] (p = 0.00 < 0.05)
Permutation/6 rounds    time:   [17.179 ns 17.301 ns 17.452 ns]
                        change: [-27.748% -26.520% -25.229%] (p = 0.00 < 0.05)
Permutation/8 rounds    time:   [23.835 ns 23.979 ns 24.109 ns]
                        change: [-24.968% -24.238% -23.588%] (p = 0.00 < 0.05)
Permutation/12 rounds   time:   [33.011 ns 33.458 ns 33.882 ns]
                        change: [-25.656% -24.646% -23.615%] (p = 0.00 < 0.05)

Use a slightly different substitution implementation that is slightly
more efficient. This does require that the function is now strictly
seperated in the three layers.

The assembly with `-C opt-level=2` shows no weird instructions,
`permute_12` without `soft-compact` is fully unrolled and from and to
arrays is skipped. With `soft-compat` it's not unrolled but does also
skip from and to arrays between the iterations.

Benchmarks with and without soft-compat are quite similair (to the
point I'm guessing I'm not even running it correctly).

Permutation/1 round     time:   [4.6049 ns 4.6597 ns 4.7094 ns]
                        change: [-17.040% -15.975% -14.976%] (p = 0.00 < 0.05)
Permutation/6 rounds    time:   [17.179 ns 17.301 ns 17.452 ns]
                        change: [-27.748% -26.520% -25.229%] (p = 0.00 < 0.05)
Permutation/8 rounds    time:   [23.835 ns 23.979 ns 24.109 ns]
                        change: [-24.968% -24.238% -23.588%] (p = 0.00 < 0.05)
Permutation/12 rounds   time:   [33.011 ns 33.458 ns 33.882 ns]
                        change: [-25.656% -24.646% -23.615%] (p = 0.00 < 0.05)
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.

1 participant