Skip to content

Commit ad83428

Browse files
authored
aes: implement VAES AVX and AVX512 backends (#482)
1 parent 73b104d commit ad83428

24 files changed

+5009
-741
lines changed

.github/workflows/aes.yml

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defaults:
1616
env:
1717
CARGO_INCREMENTAL: 0
1818
RUSTFLAGS: "-Dwarnings"
19+
SDE_FULL_VERSION: "9.53.0-2025-03-16"
1920

2021
jobs:
2122
# Builds for no_std platforms
@@ -68,7 +69,7 @@ jobs:
6869
env:
6970
CARGO_INCREMENTAL: 0
7071
RUSTDOCFLAGS: "-C target-feature=+aes,+ssse3"
71-
RUSTFLAGS: "-Dwarnings -C target-feature=+aes,+ssse3"
72+
RUSTFLAGS: "-Dwarnings -C target-feature=+aes,+ssse3 --cfg aes_avx512_disable --cfg aes_avx256_disable"
7273
strategy:
7374
matrix:
7475
include:
@@ -97,6 +98,80 @@ jobs:
9798
- run: cargo test --target ${{ matrix.target }} --features hazmat
9899
- run: cargo test --target ${{ matrix.target }} --all-features
99100

101+
# Tests for the VAES AVX backend
102+
vaes256:
103+
runs-on: ubuntu-latest
104+
env:
105+
CARGO_INCREMENTAL: 0
106+
RUSTFLAGS: "-Dwarnings --cfg aes_avx512_disable"
107+
strategy:
108+
matrix:
109+
include:
110+
- target: x86_64-unknown-linux-gnu
111+
rust: nightly-2025-05-28
112+
steps:
113+
- uses: actions/checkout@v4
114+
- name: Install Intel SDE
115+
run: |
116+
curl -JLO "https://downloadmirror.intel.com/850782/sde-external-${{ env.SDE_FULL_VERSION }}-lin.tar.xz"
117+
tar xvf sde-external-${{ env.SDE_FULL_VERSION }}-lin.tar.xz -C /opt
118+
echo "/opt/sde-external-${{ env.SDE_FULL_VERSION }}-lin" >> $GITHUB_PATH
119+
- uses: RustCrypto/actions/cargo-cache@master
120+
- uses: dtolnay/rust-toolchain@master
121+
with:
122+
toolchain: ${{ matrix.rust }}
123+
targets: ${{ matrix.target }}
124+
# NOTE: Write a `.cargo/config.toml` to configure the target for VAES
125+
# NOTE: We use intel-sde as the runner since not all GitHub CI hosts support AVX512
126+
- name: write .cargo/config.toml
127+
shell: bash
128+
run: |
129+
cd ../aes/..
130+
mkdir -p .cargo
131+
echo '[target.${{ matrix.target }}]' > .cargo/config.toml
132+
echo 'runner = "sde64 -future --"' >> .cargo/config.toml
133+
- run: ${{ matrix.deps }}
134+
- run: cargo test --target ${{ matrix.target }}
135+
- run: cargo test --target ${{ matrix.target }} --features hazmat
136+
- run: cargo test --target ${{ matrix.target }} --all-features
137+
138+
# Tests for the VAES AVX512 backend
139+
vaes512:
140+
runs-on: ubuntu-latest
141+
env:
142+
CARGO_INCREMENTAL: 0
143+
strategy:
144+
matrix:
145+
include:
146+
- target: x86_64-unknown-linux-gnu
147+
rust: nightly-2025-05-28
148+
steps:
149+
- uses: actions/checkout@v4
150+
- name: Install Intel SDE
151+
run: |
152+
curl -JLO "https://downloadmirror.intel.com/850782/sde-external-${{ env.SDE_FULL_VERSION }}-lin.tar.xz"
153+
tar xvf sde-external-${{ env.SDE_FULL_VERSION }}-lin.tar.xz -C /opt
154+
echo "/opt/sde-external-${{ env.SDE_FULL_VERSION }}-lin" >> $GITHUB_PATH
155+
- uses: RustCrypto/actions/cargo-cache@master
156+
- uses: dtolnay/rust-toolchain@master
157+
with:
158+
toolchain: ${{ matrix.rust }}
159+
targets: ${{ matrix.target }}
160+
# NOTE: Write a `.cargo/config.toml` to configure the target for VAES
161+
# NOTE: We use intel-sde as the runner since not all GitHub CI hosts support AVX512
162+
- name: write .cargo/config.toml
163+
shell: bash
164+
run: |
165+
cd ../aes/..
166+
mkdir -p .cargo
167+
echo '[target.${{ matrix.target }}]' > .cargo/config.toml
168+
echo 'runner = "sde64 -future --"' >> .cargo/config.toml
169+
- run: ${{ matrix.deps }}
170+
- run: cargo test --target ${{ matrix.target }}
171+
- run: cargo test --target ${{ matrix.target }} --features hazmat
172+
- run: cargo test --target ${{ matrix.target }} --all-features
173+
174+
100175
# Tests for CPU feature autodetection with fallback to portable software implementation
101176
autodetect:
102177
runs-on: ubuntu-latest

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ hazmat = [] # Expose cryptographically hazardous APIs
3131

3232
[lints.rust.unexpected_cfgs]
3333
level = "warn"
34-
check-cfg = ["cfg(aes_compact)", "cfg(aes_force_soft)"]
34+
check-cfg = ["cfg(aes_compact)", "cfg(aes_force_soft)", "cfg(aes_avx256_disable)", "cfg(aes_avx512_disable)"]
3535

3636
[package.metadata.docs.rs]
3737
all-features = true

aes/src/armv8.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ use cipher::{
2525
};
2626
use core::fmt;
2727

28+
pub(crate) mod features {
29+
cpufeatures::new!(features_aes, "aes");
30+
pub(crate) mod aes {
31+
pub use super::features_aes::*;
32+
}
33+
}
34+
2835
impl_backends!(
2936
enc_name = Aes128BackEnc,
3037
dec_name = Aes128BackDec,
@@ -86,18 +93,6 @@ macro_rules! define_aes_impl {
8693
decrypt: $name_back_dec,
8794
}
8895

89-
impl $name {
90-
#[inline(always)]
91-
pub(crate) fn get_enc_backend(&self) -> &$name_back_enc {
92-
&self.encrypt
93-
}
94-
95-
#[inline(always)]
96-
pub(crate) fn get_dec_backend(&self) -> &$name_back_dec {
97-
&self.decrypt
98-
}
99-
}
100-
10196
impl KeySizeUser for $name {
10297
type KeySize = $key_size;
10398
}
@@ -182,13 +177,6 @@ macro_rules! define_aes_impl {
182177
backend: $name_back_enc,
183178
}
184179

185-
impl $name_enc {
186-
#[inline(always)]
187-
pub(crate) fn get_enc_backend(&self) -> &$name_back_enc {
188-
&self.backend
189-
}
190-
}
191-
192180
impl KeySizeUser for $name_enc {
193181
type KeySize = $key_size;
194182
}
@@ -248,13 +236,6 @@ macro_rules! define_aes_impl {
248236
backend: $name_back_dec,
249237
}
250238

251-
impl $name_dec {
252-
#[inline(always)]
253-
pub(crate) fn get_dec_backend(&self) -> &$name_back_dec {
254-
&self.backend
255-
}
256-
}
257-
258239
impl KeySizeUser for $name_dec {
259240
type KeySize = $key_size;
260241
}

0 commit comments

Comments
 (0)