Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .github/workflows/aes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ jobs:
cargo build --target ${{ matrix.target }}
cargo build --target ${{ matrix.target }} --features hazmat
- env:
RUSTFLAGS: "-Dwarnings --cfg aes_force_soft"
RUSTFLAGS: '-Dwarnings --cfg aes_backend="soft"'
run: |
cargo build --target ${{ matrix.target }}
cargo build --target ${{ matrix.target }} --features hazmat
- env:
RUSTFLAGS: "-Dwarnings --cfg aes_compact"
RUSTFLAGS: '-Dwarnings --cfg aes_compact'
run: |
cargo build --target ${{ matrix.target }}
cargo build --target ${{ matrix.target }} --features hazmat
- env:
RUSTFLAGS: "-Dwarnings --cfg aes_force_soft --cfg aes_compact"
RUSTFLAGS: '-Dwarnings --cfg aes_backend="soft" --cfg aes_compact'
run: |
cargo build --target ${{ matrix.target }}
cargo build --target ${{ matrix.target }} --features hazmat
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
include:
- target: x86_64-unknown-linux-gnu
rust: stable
RUSTFLAGS: "-Dwarnings --cfg aes_avx256"
RUSTFLAGS: '-Dwarnings --cfg aes_backend="avx256"'
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
Expand Down Expand Up @@ -150,10 +150,7 @@ jobs:
include:
- target: x86_64-unknown-linux-gnu
rust: stable
RUSTFLAGS: "-Dwarnings --cfg aes_avx512"
- target: x86_64-unknown-linux-gnu
rust: stable
RUSTFLAGS: "-Dwarnings --cfg aes_avx256 --cfg aes_avx512"
RUSTFLAGS: '-Dwarnings --cfg aes_backend="avx512"'
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
Expand Down Expand Up @@ -214,11 +211,11 @@ jobs:
- run: cargo test --target ${{ matrix.target }} --features hazmat
- run: cargo test --target ${{ matrix.target }} --all-features

# Tests for the portable software backend (i.e. `aes_force_soft`-only)
# Tests for the portable software backend (i.e. `aes_backend="soft"`-only)
soft:
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-Dwarnings --cfg aes_force_soft"
RUSTFLAGS: '-Dwarnings --cfg aes_backend="soft"'
strategy:
matrix:
include:
Expand Down Expand Up @@ -280,17 +277,17 @@ jobs:
cross test --package aes --target ${{ matrix.target }}
cross test --package aes --target ${{ matrix.target }} --features hazmat
- env:
RUSTFLAGS: "-Dwarnings --cfg aes_force_soft"
RUSTFLAGS: '-Dwarnings --cfg aes_backend="soft"'
run: |
cross test --package aes --target ${{ matrix.target }}
cross test --package aes --target ${{ matrix.target }} --features hazmat
- env:
RUSTFLAGS: "-Dwarnings --cfg aes_compact"
RUSTFLAGS: '-Dwarnings --cfg aes_compact'
run: |
cross test --package aes --target ${{ matrix.target }}
cross test --package aes --target ${{ matrix.target }} --features hazmat
- env:
RUSTFLAGS: "-Dwarnings --cfg aes_force_soft --cfg aes_compact"
RUSTFLAGS: '-Dwarnings --cfg aes_backend="soft" --cfg aes_compact'
run: |
cross test --package aes --target ${{ matrix.target }}
cross test --package aes --target ${{ matrix.target }} --features hazmat
Expand Down Expand Up @@ -322,7 +319,7 @@ jobs:

clippy:
env:
RUSTFLAGS: "-Dwarnings --cfg aes_compact"
RUSTFLAGS: '-Dwarnings --cfg aes_compact'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 1 addition & 3 deletions aes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ hazmat = [] # Expose cryptographically hazardous APIs
level = "warn"
check-cfg = [
'cfg(aes_compact)',
'cfg(aes_force_soft)',
'cfg(aes_avx256)',
'cfg(aes_avx512)',
'cfg(aes_backend, values("soft", "avx256", "avx512"))',
'cfg(cpubits, values("16", "32", "64"))'
]

Expand Down
11 changes: 7 additions & 4 deletions aes/src/hazmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ pub use crate::Block;
/// Eight 128-bit AES blocks
pub type Block8 = cipher::array::Array<Block, cipher::consts::U8>;

#[cfg(all(target_arch = "aarch64", not(aes_force_soft)))]
#[cfg(all(target_arch = "aarch64", not(aes_backend = "soft")))]
use crate::armv8::hazmat as intrinsics;

#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), not(aes_force_soft)))]
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(aes_backend = "soft")
))]
use crate::x86::ni::hazmat as intrinsics;

#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"),
not(aes_force_soft)
not(aes_backend = "soft")
))]
cpufeatures::new!(aes_intrinsics, "aes");

Expand All @@ -35,7 +38,7 @@ macro_rules! if_intrinsics_available {
($body:expr) => {{
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"),
not(aes_force_soft)
not(aes_backend = "soft")
))]
if aes_intrinsics::get() {
unsafe { $body }
Expand Down
15 changes: 9 additions & 6 deletions aes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//! will ensure that AESNI and VAES are always used.
//!
//! Note: Enabling VAES256 or VAES512 still requires specifying `--cfg
//! aes_avx256` or `--cfg aes_avx512` explicitly.
//! aes_backend = "avx256"` or `--cfg aes_backend = "avx512"` explicitly.
//!
//! Programs built in this manner will crash with an illegal instruction on
//! CPUs which do not have AES-NI and VAES enabled.
Expand Down Expand Up @@ -102,7 +102,7 @@
//!
//! You can modify crate using the following configuration flags:
//!
//! - `aes_force_soft`: force software implementation.
//! - `aes_backend = "soft"`: force software implementation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entry should list all supported values for aes_backend.

//! - `aes_compact`: reduce code size at the cost of slower performance
//! (affects only software backend).
//!
Expand Down Expand Up @@ -130,13 +130,13 @@ mod macros;
mod soft;

cpubits::cfg_if! {
if #[cfg(all(target_arch = "aarch64", not(aes_force_soft)))] {
if #[cfg(all(target_arch = "aarch64", not(aes_backend = "soft")))] {
mod armv8;
mod autodetect;
pub use autodetect::*;
} else if #[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(aes_force_soft)
not(aes_backend = "soft")
))] {
mod x86;
mod autodetect;
Expand Down Expand Up @@ -188,7 +188,10 @@ mod tests {
test_for(soft::Aes256Enc::new(&key_256));
test_for(soft::Aes256Dec::new(&key_256));

#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), not(aes_force_soft)))]
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(aes_backend = "soft")
))]
{
use super::x86;

Expand All @@ -206,7 +209,7 @@ mod tests {
}
}

#[cfg(all(target_arch = "aarch64", not(aes_force_soft)))]
#[cfg(all(target_arch = "aarch64", not(aes_backend = "soft")))]
{
use super::armv8;

Expand Down
Loading