Skip to content

Commit e14fdff

Browse files
committed
Migrate to intrinsics for VAES
1 parent 86d4c31 commit e14fdff

File tree

17 files changed

+1849
-161
lines changed

17 files changed

+1849
-161
lines changed

.github/workflows/aes.yml

Lines changed: 81 additions & 2 deletions
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
# Cancels CI jobs when new commits are pushed to a PR branch
2122
concurrency:
@@ -73,7 +74,7 @@ jobs:
7374
env:
7475
CARGO_INCREMENTAL: 0
7576
RUSTDOCFLAGS: "-C target-feature=+aes,+ssse3"
76-
RUSTFLAGS: "-Dwarnings -C target-feature=+aes,+ssse3"
77+
RUSTFLAGS: "-Dwarnings -C target-feature=+aes,+ssse3 --cfg aes_avx512_disable --cfg aes_avx256_disable"
7778
strategy:
7879
matrix:
7980
include:
@@ -102,6 +103,85 @@ jobs:
102103
- run: cargo test --target ${{ matrix.target }} --features hazmat
103104
- run: cargo test --target ${{ matrix.target }} --all-features
104105

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

168-
169248
# Cross-compiled tests
170249
cross:
171250
strategy:

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)", "cfg(aes_avx512)"]
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)