Skip to content

Commit 1c08e00

Browse files
committed
aes: use cpubits crate
The `cpubits` crate contains a macro for selecting between 32-bit and 64-bit backends, incorporating 64-bit overrides for certain natively 32-bit targets with native ISA support for operations "register pairs", namely ARMv7 and WASM. It also supports overriding the selection with `cfg(cpubits = "...")` This switches the selection of the 32-bit vs 64-bit soft backend, always compiled into the crate as it's used as a fallback implementation if intrinsics aren't available, to using `cpubits`. The crate contains a vendored copy of `cfg-if`, so this also replaces `cfg-if` as a dependency with `cpubits`.
1 parent d32271c commit 1c08e00

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

Cargo.lock

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aes/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ keywords = ["crypto", "aes", "rijndael", "block-cipher"]
1313
categories = ["cryptography", "no-std"]
1414

1515
[dependencies]
16-
cfg-if = "1"
1716
cipher = "0.5.0-rc.7"
17+
cpubits = "0.1.0-rc.3"
1818
zeroize = { version = "1.5.6", optional = true, default-features = false, features = ["aarch64"] }
1919

2020
[target.'cfg(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "x86"))'.dependencies]
@@ -29,7 +29,13 @@ hazmat = [] # Expose cryptographically hazardous APIs
2929

3030
[lints.rust.unexpected_cfgs]
3131
level = "warn"
32-
check-cfg = ["cfg(aes_compact)", "cfg(aes_force_soft)", "cfg(aes_avx256)", "cfg(aes_avx512)"]
32+
check-cfg = [
33+
'cfg(aes_compact)',
34+
'cfg(aes_force_soft)',
35+
'cfg(aes_avx256)',
36+
'cfg(aes_avx512)',
37+
'cfg(cpubits, values("16", "32", "64"))'
38+
]
3339

3440
[package.metadata.docs.rs]
3541
all-features = true

aes/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ pub mod hazmat;
129129
mod macros;
130130
mod soft;
131131

132-
use cfg_if::cfg_if;
133-
134-
cfg_if! {
132+
cpubits::cfg_if! {
135133
if #[cfg(all(target_arch = "aarch64", not(aes_force_soft)))] {
136134
mod armv8;
137135
mod autodetect;

aes/src/soft.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
99
#![deny(unsafe_code)]
1010

11-
#[cfg_attr(not(target_pointer_width = "64"), path = "soft/fixslice32.rs")]
12-
#[cfg_attr(target_pointer_width = "64", path = "soft/fixslice64.rs")]
13-
pub(crate) mod fixslice;
11+
cpubits::cpubits! {
12+
16 | 32 => {
13+
#[path = "soft/fixslice32.rs"]
14+
pub(crate) mod fixslice;
15+
}
16+
64 => {
17+
#[path = "soft/fixslice32.rs"]
18+
pub(crate) mod fixslice;
19+
}
20+
}
1421

1522
use crate::Block;
1623
use cipher::{

0 commit comments

Comments
 (0)