Skip to content

Commit

Permalink
aes: enable ARMv8 backend by default; MSRV 1.72 (#395)
Browse files Browse the repository at this point in the history
Removes `cfg(aes_armv8)` and instead enables it by default. This means
it "just works" without any additional configuration.

The backend is MSRV 1.72, so for consistency's sake bumps the crate's
MSRV to 1.72, i.e. the MSRV where it will work consistently on all
platforms. We've done varying MSRVs for specific features in the past,
but that gets complicated and confusing (e.g. if we were to say the
crate's MSRV varies by target).

Benchmarks:

test aes128_decrypt_block  ... bench:         839 ns/iter (+/- 32) = 19528 MB/s
test aes128_decrypt_blocks ... bench:         858 ns/iter (+/- 58) = 19095 MB/s
test aes128_encrypt_block  ... bench:         839 ns/iter (+/- 34) = 19528 MB/s
test aes128_encrypt_blocks ... bench:         855 ns/iter (+/- 57) = 19162 MB/s
test aes128_new            ... bench:          72 ns/iter (+/- 2)
test aes192_decrypt_block  ... bench:         997 ns/iter (+/- 47) = 16433 MB/s
test aes192_decrypt_blocks ... bench:       1,002 ns/iter (+/- 56) = 16351 MB/s
test aes192_encrypt_block  ... bench:         990 ns/iter (+/- 31) = 16549 MB/s
test aes192_encrypt_blocks ... bench:       1,003 ns/iter (+/- 32) = 16334 MB/s
test aes192_new            ... bench:          68 ns/iter (+/- 2)
test aes256_decrypt_block  ... bench:       1,163 ns/iter (+/- 34) = 14087 MB/s
test aes256_decrypt_blocks ... bench:       1,151 ns/iter (+/- 65) = 14234 MB/s
test aes256_encrypt_block  ... bench:       1,166 ns/iter (+/- 38) = 14051 MB/s
test aes256_encrypt_blocks ... bench:       1,155 ns/iter (+/- 81) = 14185 MB/s
test aes256_new            ... bench:          91 ns/iter (+/- 4)
  • Loading branch information
tarcieri authored Jan 7, 2024
1 parent 8a5dab4 commit d2756ce
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 37 deletions.
24 changes: 11 additions & 13 deletions .github/workflows/aes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
rust:
- 1.65.0 # MSRV
- 1.72.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand Down Expand Up @@ -73,15 +73,15 @@ jobs:
include:
# 32-bit Linux
- target: i686-unknown-linux-gnu
rust: 1.65.0 # MSRV
rust: 1.72.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib
- target: i686-unknown-linux-gnu
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
- target: x86_64-unknown-linux-gnu
rust: 1.65.0 # MSRV
rust: 1.72.0 # MSRV
- target: x86_64-unknown-linux-gnu
rust: stable
steps:
Expand All @@ -104,15 +104,15 @@ jobs:
include:
# 32-bit Linux
- target: i686-unknown-linux-gnu
rust: 1.65.0 # MSRV
rust: 1.72.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib
- target: i686-unknown-linux-gnu
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
- target: x86_64-unknown-linux-gnu
rust: 1.65.0 # MSRV
rust: 1.72.0 # MSRV
- target: x86_64-unknown-linux-gnu
rust: stable
steps:
Expand All @@ -137,15 +137,15 @@ jobs:
include:
# 32-bit Linux
- target: i686-unknown-linux-gnu
rust: 1.65.0 # MSRV
rust: 1.72.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib
- target: i686-unknown-linux-gnu
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
- target: x86_64-unknown-linux-gnu
rust: 1.65.0 # MSRV
rust: 1.72.0 # MSRV
- target: x86_64-unknown-linux-gnu
rust: stable
steps:
Expand All @@ -167,13 +167,13 @@ jobs:
include:
# ARM64
- target: aarch64-unknown-linux-gnu
rust: 1.65.0 # MSRV
rust: 1.72.0 # MSRV
- target: aarch64-unknown-linux-gnu
rust: stable

# PPC32
- target: powerpc-unknown-linux-gnu
rust: 1.65.0 # MSRV
rust: 1.72.0 # MSRV
- target: powerpc-unknown-linux-gnu
rust: stable
runs-on: ubuntu-latest
Expand Down Expand Up @@ -211,13 +211,11 @@ jobs:
# ARMv8 cross-compiled tests for AES intrinsics
armv8:
env:
RUSTFLAGS: "-Dwarnings --cfg aes_armv8"
strategy:
matrix:
include:
- target: aarch64-unknown-linux-gnu
rust: 1.72.0 # MSRV for `aes_armv8`
rust: 1.72.0 # MSRV
runs-on: ubuntu-latest
# Cross mounts only current package, i.e. by default it ignores workspace's Cargo.toml
defaults:
Expand Down Expand Up @@ -245,6 +243,6 @@ jobs:
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.65.0 # MSRV
toolchain: 1.72.0 # MSRV
components: clippy
- run: cargo clippy --features hazmat -- -D warnings
2 changes: 1 addition & 1 deletion aes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Pure Rust implementation of the Advanced Encryption Standard (a.k
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.72"
readme = "README.md"
documentation = "https://docs.rs/aes"
repository = "https://github.com/RustCrypto/block-ciphers"
Expand Down
4 changes: 2 additions & 2 deletions aes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using a portable implementation based on bitslicing.

## Minimum Supported Rust Version

Rust **1.65** or higher.
Rust **1.72** or higher.

Minimum supported Rust version can be changed in future releases, but it will
be done with a minor version bump.
Expand Down Expand Up @@ -75,7 +75,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/aes/badge.svg
[docs-link]: https://docs.rs/aes/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.72+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers
[build-image]: https://github.com/RustCrypto/block-ciphers/workflows/aes/badge.svg?branch=master&event=push
Expand Down
2 changes: 1 addition & 1 deletion aes/src/autodetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cipher::{
use core::fmt;
use core::mem::ManuallyDrop;

#[cfg(all(target_arch = "aarch64", aes_armv8))]
#[cfg(target_arch = "aarch64")]
use crate::armv8 as intrinsics;

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
Expand Down
14 changes: 3 additions & 11 deletions aes/src/hazmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@
use crate::{soft::fixslice::hazmat as soft, Block, Block8};

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

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

#[cfg(all(
any(
target_arch = "x86",
target_arch = "x86_64",
all(target_arch = "aarch64", aes_armv8)
),
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"),
not(aes_force_soft)
))]
cpufeatures::new!(aes_intrinsics, "aes");
Expand All @@ -34,11 +30,7 @@ cpufeatures::new!(aes_intrinsics, "aes");
macro_rules! if_intrinsics_available {
($body:expr) => {{
#[cfg(all(
any(
target_arch = "x86",
target_arch = "x86_64",
all(target_arch = "aarch64", aes_armv8)
),
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"),
not(aes_force_soft)
))]
if aes_intrinsics::get() {
Expand Down
15 changes: 6 additions & 9 deletions aes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
//! ## ARMv8 intrinsics (Rust 1.61+)
//! On `aarch64` targets including `aarch64-apple-darwin` (Apple M1) and Linux
//! targets such as `aarch64-unknown-linux-gnu` and `aarch64-unknown-linux-musl`,
//! support for using AES intrinsics provided by the ARMv8 Cryptography Extensions
//! is available when using Rust 1.61 or above, and can be enabled using the
//! `aes_armv8` configuration flag.
//! support for using AES intrinsics provided by the ARMv8 Cryptography Extensions.
//!
//! On Linux and macOS, when the `aes_armv8` flag is enabled support for AES
//! intrinsics is autodetected at runtime. On other platforms the `aes`
//! target feature must be enabled via RUSTFLAGS.
//! On Linux and macOS, support for ARMv8 AES intrinsics is autodetected at
//! runtime. On other platforms the `aes` target feature must be enabled via
//! RUSTFLAGS.
//!
//! ## `x86`/`x86_64` intrinsics (AES-NI)
//! By default this crate uses runtime detection on `i686`/`x86_64` targets
Expand Down Expand Up @@ -101,7 +99,6 @@
//!
//! You can modify crate using the following configuration flags:
//!
//! - `aes_armv8`: enable ARMv8 AES intrinsics (Rust 1.61+).
//! - `aes_force_soft`: force software implementation.
//! - `aes_compact`: reduce code size at the cost of slower performance
//! (affects only software backend).
Expand Down Expand Up @@ -131,7 +128,7 @@ mod soft;
use cfg_if::cfg_if;

cfg_if! {
if #[cfg(all(target_arch = "aarch64", aes_armv8, not(aes_force_soft)))] {
if #[cfg(all(target_arch = "aarch64", not(aes_force_soft)))] {
mod armv8;
mod autodetect;
pub use autodetect::*;
Expand Down Expand Up @@ -212,7 +209,7 @@ mod tests {
}
}

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

Expand Down

0 comments on commit d2756ce

Please sign in to comment.