Skip to content

Commit f655326

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

File tree

17 files changed

+1850
-160
lines changed

17 files changed

+1850
-160
lines changed

.github/workflows/aes.yml

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ defaults:
1616
env:
1717
CARGO_INCREMENTAL: 0
1818
RUSTFLAGS: "-Dwarnings"
19+
# NOTE: The mirror number changes with each version so keep these in sync
20+
SDE_FULL_VERSION_MIRROR: "859732"
21+
SDE_FULL_VERSION: "9.58.0-2025-06-16"
1922

2023
# Cancels CI jobs when new commits are pushed to a PR branch
2124
concurrency:
@@ -102,6 +105,85 @@ jobs:
102105
- run: cargo test --target ${{ matrix.target }} --features hazmat
103106
- run: cargo test --target ${{ matrix.target }} --all-features
104107

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

168-
169250
# Cross-compiled tests
170251
cross:
171252
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)