Skip to content

Commit

Permalink
aes: use cfg-if crate (#203)
Browse files Browse the repository at this point in the history
Simplifies cfg-based gating
  • Loading branch information
tarcieri authored Nov 25, 2020
1 parent 67bf555 commit ed88fb0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ keywords = ["crypto", "aes", "rijndael", "block-cipher"]
categories = ["cryptography", "no-std"]

[dependencies]
cfg-if = "1"
cipher = "0.2"
ctr = { version = "0.6", optional = true }
opaque-debug = "0.3"
Expand Down
64 changes: 22 additions & 42 deletions aes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,33 @@
)]
#![warn(missing_docs, rust_2018_idioms)]

#[cfg(all(
target_feature = "aes",
target_feature = "sse2",
any(target_arch = "x86_64", target_arch = "x86"),
))]
mod ni;
use cfg_if::cfg_if;

#[cfg(not(all(
target_feature = "aes",
target_feature = "sse2",
any(target_arch = "x86_64", target_arch = "x86"),
)))]
mod soft;

#[cfg(not(all(
target_feature = "aes",
target_feature = "sse2",
any(target_arch = "x86_64", target_arch = "x86"),
)))]
pub use soft::{Aes128, Aes192, Aes256};

#[cfg(all(
target_feature = "aes",
target_feature = "sse2",
any(target_arch = "x86_64", target_arch = "x86"),
))]
pub use ni::{Aes128, Aes192, Aes256};

#[cfg(all(
feature = "ctr",
not(all(
cfg_if! {
if #[cfg(all(
target_feature = "aes",
target_feature = "sse2",
target_feature = "ssse3",
any(target_arch = "x86_64", target_arch = "x86"),
))
))]
pub use soft::{Aes128Ctr, Aes192Ctr, Aes256Ctr};
))] {
mod ni;
pub use ni::{Aes128, Aes192, Aes256};

#[cfg(feature = "ctr")]
cfg_if! {
if #[cfg(target_feature = "ssse3")] {
pub use ni::{Aes128Ctr, Aes192Ctr, Aes256Ctr};
} else {
compile_error!("Please enable the +ssse3 target feature to use `ctr` with AES-NI")
}
}
} else {
mod soft;
pub use soft::{Aes128, Aes192, Aes256};

#[cfg(all(
feature = "ctr",
target_feature = "aes",
target_feature = "sse2",
target_feature = "ssse3",
any(target_arch = "x86_64", target_arch = "x86"),
))]
pub use ni::{Aes128Ctr, Aes192Ctr, Aes256Ctr};
#[cfg(feature = "ctr")]
pub use soft::{Aes128Ctr, Aes192Ctr, Aes256Ctr};
}
}

pub use cipher::{self, BlockCipher, NewBlockCipher};

Expand Down

0 comments on commit ed88fb0

Please sign in to comment.