Replace no_unroll feature(s) with soft-compact cfg (#105)

The following crates now have a new `cfg` for backend selection:
- `ascon`: `--cfg ascon_backend="soft-compact"`
- `keccak`: `--cfg keccak_backend="soft-compact"`

This replaces the previous crate features, as suggested in #85
This commit is contained in:
Tony Arcieri 2026-02-13 12:00:57 -07:00 committed by GitHub
parent b27e9bff49
commit a1be08a742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 124 additions and 44 deletions

View File

@ -41,7 +41,10 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo build --no-default-features --target ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }}
- env:
RUSTFLAGS: '-Dwarnings --cfg ascon_backend="soft-compact"'
run: cargo build --target ${{ matrix.target }}
minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
@ -62,31 +65,29 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- run: cargo test --no-default-features
- run: cargo test
- run: cargo test --all-features
- env:
RUSTFLAGS: '-Dwarnings --cfg ascon_backend="soft-compact"'
run: cargo test
- run: cargo test --release
miri:
test-miri:
runs-on: ubuntu-latest
env:
MIRIFLAGS: "-Zmiri-symbolic-alignment-check -Zmiri-strict-provenance"
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- armv7-unknown-linux-gnueabi
- s390x-unknown-linux-gnu
- x86_64-unknown-linux-gnu
steps:
- uses: actions/checkout@v4
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
- name: Install Miri
run: |
rustup component add miri
cargo miri setup
- name: Test with Miri
run: |
cargo miri test --target ${{ matrix.target }} --no-default-features
cargo miri test --target ${{ matrix.target }}
cargo miri test --target ${{ matrix.target }} --all-features
- run: rustup component add miri
- run: cargo miri setup
- run: cargo miri test --target ${{ matrix.target }}
- env:
RUSTFLAGS: '-Dwarnings --cfg ascon_backend="soft-compact"'
run: cargo miri test --target ${{ matrix.target }}

View File

@ -41,7 +41,10 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo build --no-default-features --target ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }}
- env:
RUSTFLAGS: '-Dwarnings --cfg keccak_backend="soft-compact"'
run: cargo build --target ${{ matrix.target }}
minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
@ -76,13 +79,14 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo check --no-default-features --target ${{ matrix.target }}
- run: cargo check --features asm,no_unroll --target ${{ matrix.target }}
- run: cargo check --features asm --target ${{ matrix.target }}
- run: cargo test --no-default-features --target ${{ matrix.target }}
- run: cargo test --target ${{ matrix.target }}
- run: cargo test --features asm --target ${{ matrix.target }}
- run: cargo test --features no_unroll --target ${{ matrix.target }}
- run: cargo test --features asm,no_unroll --target ${{ matrix.target }}
- run: cargo test --features asm --release --target ${{ matrix.target }}
- env:
RUSTFLAGS: '-Dwarnings --cfg keccak_backend="soft-compact"'
run: cargo test --release --target ${{ matrix.target }}
test-simd:
runs-on: ubuntu-latest
@ -95,7 +99,7 @@ jobs:
- run: cargo check --features simd
- run: cargo test --features simd
miri:
test-miri:
runs-on: ubuntu-latest
env:
MIRIFLAGS: "-Zmiri-symbolic-alignment-check -Zmiri-strict-provenance"
@ -117,8 +121,10 @@ jobs:
run: |
cargo miri test --target ${{ matrix.target }} --no-default-features
cargo miri test --target ${{ matrix.target }}
cargo miri test --target ${{ matrix.target }} --features no_unroll
cargo miri test --target ${{ matrix.target }} --features simd
- env:
RUSTFLAGS: '-Dwarnings --cfg keccak_backend="soft-compact"'
run: cargo miri test --release --target ${{ matrix.target }}
aarch64-sha3:
needs: set-msrv

View File

@ -19,11 +19,45 @@ rust-version = "1.85"
[dependencies]
zeroize = { version = "1.6", default-features = false, optional = true }
[features]
no_unroll = [] # Do not unroll loops for binary size reduction
[lints.rust]
missing_copy_implementations = "warn"
missing_debug_implementations = "warn"
missing_docs = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
[lints]
workspace = true
[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ['cfg(ascon_backend, values("soft-compact"))']
[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
[lints.clippy]
borrow_as_ptr = "warn"
cast_lossless = "warn"
cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
cast_precision_loss = "warn"
cast_sign_loss = "warn"
checked_conversions = "warn"
from_iter_instead_of_collect = "warn"
implicit_saturating_sub = "warn"
manual_assert = "warn"
map_unwrap_or = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
mod_module_files = "warn"
must_use_candidate = "warn"
needless_range_loop = "allow"
ptr_as_ptr = "warn"
redundant_closure_for_method_calls = "warn"
ref_as_ptr = "warn"
return_self_not_must_use = "warn"
semicolon_if_nothing_returned = "warn"
trivially_copy_pass_by_ref = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
undocumented_unsafe_blocks = "warn"
unnecessary_safety_comment = "warn"
unwrap_in_result = "warn"
unwrap_used = "warn"

View File

@ -72,7 +72,7 @@ impl State {
}
}
#[cfg(not(feature = "no_unroll"))]
#[cfg(not(ascon_backend = "soft-compact"))]
/// Perform permutation with 12 rounds.
pub fn permute_12(&mut self) {
// We could in theory iter().fold() over an array of round constants,
@ -105,7 +105,7 @@ impl State {
);
}
#[cfg(feature = "no_unroll")]
#[cfg(ascon_backend = "soft-compact")]
/// Perform permutation with 12 rounds.
pub fn permute_12(&mut self) {
self.x = [
@ -115,7 +115,7 @@ impl State {
.fold(self.x, round);
}
#[cfg(not(feature = "no_unroll"))]
#[cfg(not(ascon_backend = "soft-compact"))]
/// Perform permutation with 8 rounds.
pub fn permute_8(&mut self) {
self.x = round(
@ -133,7 +133,7 @@ impl State {
);
}
#[cfg(feature = "no_unroll")]
#[cfg(ascon_backend = "soft-compact")]
/// Perform permutation with 8 rounds.
pub fn permute_8(&mut self) {
self.x = [0xb4, 0xa5, 0x96, 0x87, 0x78, 0x69, 0x5a, 0x4b]
@ -141,7 +141,7 @@ impl State {
.fold(self.x, round);
}
#[cfg(not(feature = "no_unroll"))]
#[cfg(not(ascon_backend = "soft-compact"))]
/// Perform permutation with 6 rounds.
pub fn permute_6(&mut self) {
self.x = round(
@ -153,7 +153,7 @@ impl State {
);
}
#[cfg(feature = "no_unroll")]
#[cfg(ascon_backend = "soft-compact")]
/// Perform permutation with 6 rounds.
pub fn permute_6(&mut self) {
self.x = [0x96, 0x87, 0x78, 0x69, 0x5a, 0x4b]

View File

@ -17,12 +17,51 @@ edition = "2024"
rust-version = "1.85"
[features]
asm = [] # Use optimized assembly when available (currently only ARMv8)
no_unroll = [] # Do no unroll loops for binary size reduction
simd = [] # Use core::simd (nightly-only)
asm = [] # Use optimized assembly when available (currently only ARMv8)
simd = [] # Use core::simd (nightly-only)
[target.'cfg(target_arch = "aarch64")'.dependencies]
cpufeatures = "0.3"
[lints]
workspace = true
[lints.rust]
missing_copy_implementations = "warn"
missing_debug_implementations = "warn"
missing_docs = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ['cfg(keccak_backend, values("soft-compact"))']
[lints.clippy]
borrow_as_ptr = "warn"
cast_lossless = "warn"
cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
cast_precision_loss = "warn"
cast_sign_loss = "warn"
checked_conversions = "warn"
from_iter_instead_of_collect = "warn"
implicit_saturating_sub = "warn"
manual_assert = "warn"
map_unwrap_or = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
mod_module_files = "warn"
must_use_candidate = "warn"
needless_range_loop = "allow"
ptr_as_ptr = "warn"
redundant_closure_for_method_calls = "warn"
ref_as_ptr = "warn"
return_self_not_must_use = "warn"
semicolon_if_nothing_returned = "warn"
trivially_copy_pass_by_ref = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
undocumented_unsafe_blocks = "warn"
unnecessary_safety_comment = "warn"
unwrap_in_result = "warn"
unwrap_used = "warn"

View File

@ -1,5 +1,5 @@
/// unroll5
#[cfg(not(feature = "no_unroll"))]
#[cfg(not(keccak_backend = "soft-compact"))]
#[macro_export]
macro_rules! unroll5 {
($var:ident, $body:block) => {
@ -12,7 +12,7 @@ macro_rules! unroll5 {
}
/// unroll5
#[cfg(feature = "no_unroll")]
#[cfg(keccak_backend = "soft-compact")]
#[macro_export]
macro_rules! unroll5 {
($var:ident, $body:block) => {
@ -21,7 +21,7 @@ macro_rules! unroll5 {
}
/// unroll24
#[cfg(not(feature = "no_unroll"))]
#[cfg(not(keccak_backend = "soft-compact"))]
#[macro_export]
macro_rules! unroll24 {
($var: ident, $body: block) => {
@ -53,7 +53,7 @@ macro_rules! unroll24 {
}
/// unroll24
#[cfg(feature = "no_unroll")]
#[cfg(keccak_backend = "soft-compact")]
#[macro_export]
macro_rules! unroll24 {
($var:ident, $body:block) => {