Skip to content

Commit 84a132e

Browse files
committed
aes: Implement ARMv9 backend
1 parent 1f7c695 commit 84a132e

File tree

11 files changed

+1118
-7
lines changed

11 files changed

+1118
-7
lines changed

.github/workflows/aes.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,37 @@ jobs:
310310
- run: cross test --package aes --target ${{ matrix.target }} --features hazmat
311311
- run: cross test --package aes --target ${{ matrix.target }} --all-features
312312

313+
armv9:
314+
strategy:
315+
matrix:
316+
include:
317+
- target: aarch64-unknown-linux-gnu
318+
rustflags: ''
319+
rust: 1.85.0 # MSRV
320+
- target: aarch64-unknown-linux-gnu
321+
rustflags: '-Ctarget-cpu=fujitsu-monaka -Ctarget-feature=+sve2-aes'
322+
rust: nightly
323+
- target: aarch64-unknown-linux-gnu
324+
rustflags: '-Ctarget-cpu=fujitsu-monaka -Ctarget-feature=+sve2-aes --cfg=armv9_sve2_aes'
325+
rust: nightly
326+
runs-on: ubuntu-latest
327+
defaults:
328+
run:
329+
working-directory: .
330+
steps:
331+
- uses: actions/checkout@v4
332+
- uses: RustCrypto/actions/cargo-cache@master
333+
- uses: dtolnay/rust-toolchain@master
334+
with:
335+
toolchain: ${{ matrix.rust }}
336+
targets: ${{ matrix.target }}
337+
- run: cargo install cross --git https://github.com/cross-rs/cross --rev e281947ca900da425e4ecea7483cfde646c8a1ea
338+
env:
339+
RUSTFLAGS: "-Dwarnings -Astatic-mut-refs"
340+
- run: cross test --package aes --target ${{ matrix.target }}
341+
env:
342+
RUSTFLAGS: "-Dwarnings ${{ matrix.rustflags }}"
343+
313344
clippy:
314345
env:
315346
RUSTFLAGS: "-Dwarnings --cfg aes_compact"

aes/Cargo.toml

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

3232
[lints.rust.unexpected_cfgs]
3333
level = "warn"
34-
check-cfg = ["cfg(aes_compact)", "cfg(aes_force_soft)", "cfg(aes_avx256_disable)", "cfg(aes_avx512_disable)"]
34+
check-cfg = [
35+
"cfg(aes_compact)",
36+
"cfg(aes_force_soft)",
37+
"cfg(aes_avx256_disable)",
38+
"cfg(aes_avx512_disable)",
39+
"cfg(armv9_sve2_aes)",
40+
]
3541

3642
[package.metadata.docs.rs]
3743
all-features = true

aes/src/armv8.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#[cfg(feature = "hazmat")]
1313
pub(crate) mod hazmat;
1414

15-
mod encdec;
16-
mod expand;
15+
pub(crate) mod encdec;
16+
pub(crate) mod expand;
1717
#[cfg(test)]
1818
mod test_expand;
1919

aes/src/armv8/encdec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use core::{arch::aarch64::*, mem};
1313

1414
/// Perform AES encryption using the given expanded keys.
1515
#[target_feature(enable = "aes")]
16-
pub(super) unsafe fn encrypt<const KEYS: usize>(
16+
pub(crate) unsafe fn encrypt<const KEYS: usize>(
1717
keys: &[uint8x16_t; KEYS],
1818
block: InOut<'_, '_, Block>,
1919
) {
@@ -38,7 +38,7 @@ pub(super) unsafe fn encrypt<const KEYS: usize>(
3838

3939
/// Perform AES decryption using the given expanded keys.
4040
#[target_feature(enable = "aes")]
41-
pub(super) unsafe fn decrypt<const KEYS: usize>(
41+
pub(crate) unsafe fn decrypt<const KEYS: usize>(
4242
keys: &[uint8x16_t; KEYS],
4343
block: InOut<'_, '_, Block>,
4444
) {

aes/src/armv8/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub unsafe fn expand_key<const L: usize, const N: usize>(key: &[u8; L]) -> [uint
5757
/// This is the reverse of the encryption keys, with the Inverse Mix Columns
5858
/// operation applied to all but the first and last expanded key.
5959
#[target_feature(enable = "aes")]
60-
pub(super) unsafe fn inv_expanded_keys<const N: usize>(keys: &[uint8x16_t; N]) -> [uint8x16_t; N] {
60+
pub unsafe fn inv_expanded_keys<const N: usize>(keys: &[uint8x16_t; N]) -> [uint8x16_t; N] {
6161
assert!(N == 11 || N == 13 || N == 15);
6262

6363
let mut inv_keys: [uint8x16_t; N] = core::mem::zeroed();

0 commit comments

Comments
 (0)