Skip to content

Commit 4ac5538

Browse files
authored
chacha20: use cargo hack in CI (#458)
To prevent bugs like #454 in the future, exhastively check all feature combinations to ensure they all work correctly. Additionally, this adds the needed feature gating so the crate passes tests with `--no-default-features`.
1 parent 8f63e23 commit 4ac5538

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

.github/workflows/chacha20.yml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ jobs:
3939
with:
4040
toolchain: ${{ matrix.rust }}
4141
targets: ${{ matrix.target }}
42-
- run: cargo build --target ${{ matrix.target }}
43-
- run: cargo build --target ${{ matrix.target }} --features zeroize
42+
- uses: RustCrypto/actions/cargo-hack-install@master
43+
- run: cargo hack build --feature-powerset --target ${{ matrix.target }}
4444

4545
minimal-versions:
46-
if: false # TODO: temp disabled due to unpublished prerelease dependencies
4746
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
4847
with:
4948
working-directory: ${{ github.workflow }}
5049

51-
# Tests for runtime AVX2 detection
50+
# Tests for runtime CPU feature detection
5251
autodetect:
5352
runs-on: ubuntu-latest
5453
strategy:
@@ -74,11 +73,10 @@ jobs:
7473
with:
7574
toolchain: ${{ matrix.rust }}
7675
targets: ${{ matrix.target }}
76+
- uses: RustCrypto/actions/cargo-hack-install@master
7777
- run: ${{ matrix.deps }}
7878
- run: cargo check --target ${{ matrix.target }} --all-features
79-
- run: cargo test --target ${{ matrix.target }}
80-
- run: cargo test --target ${{ matrix.target }} --features zeroize
81-
- run: cargo test --target ${{ matrix.target }} --all-features
79+
- run: cargo hack test --feature-powerset --target ${{ matrix.target }}
8280

8381
# Tests for the AVX2 backend
8482
avx2:
@@ -108,11 +106,10 @@ jobs:
108106
with:
109107
toolchain: ${{ matrix.rust }}
110108
targets: ${{ matrix.target }}
109+
- uses: RustCrypto/actions/cargo-hack-install@master
111110
- run: ${{ matrix.deps }}
112111
- run: cargo check --target ${{ matrix.target }} --all-features
113-
- run: cargo test --target ${{ matrix.target }}
114-
- run: cargo test --target ${{ matrix.target }} --features zeroize
115-
- run: cargo test --target ${{ matrix.target }} --all-features
112+
- run: cargo hack test --feature-powerset --target ${{ matrix.target }}
116113

117114
# Tests for the SSE2 backend
118115
sse2:
@@ -142,11 +139,10 @@ jobs:
142139
with:
143140
toolchain: ${{ matrix.rust }}
144141
targets: ${{ matrix.target }}
142+
- uses: RustCrypto/actions/cargo-hack-install@master
145143
- run: ${{ matrix.deps }}
146144
- run: cargo check --target ${{ matrix.target }} --all-features
147-
- run: cargo test --target ${{ matrix.target }}
148-
- run: cargo test --target ${{ matrix.target }} --features zeroize
149-
- run: cargo test --target ${{ matrix.target }} --all-features
145+
- run: cargo hack test --feature-powerset --target ${{ matrix.target }}
150146

151147
# Tests for the portable software backend
152148
soft:
@@ -176,11 +172,10 @@ jobs:
176172
with:
177173
toolchain: ${{ matrix.rust }}
178174
targets: ${{ matrix.target }}
175+
- uses: RustCrypto/actions/cargo-hack-install@master
179176
- run: ${{ matrix.deps }}
180177
- run: cargo check --target ${{ matrix.target }} --all-features
181-
- run: cargo test --target ${{ matrix.target }}
182-
- run: cargo test --target ${{ matrix.target }} --features zeroize
183-
- run: cargo test --target ${{ matrix.target }} --all-features
178+
- run: cargo hack test --feature-powerset --target ${{ matrix.target }}
184179

185180
# Cross-compiled tests
186181
cross:

chacha20/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rand_core-compatible RNGs based on those ciphers.
2222
cfg-if = "1"
2323
cipher = { version = "0.5.0-rc.1", optional = true, features = ["stream-wrapper"] }
2424
rand_core = { version = "0.9", optional = true, default-features = false }
25-
serde = { version = "1.0", features = ["derive"], optional = true }
25+
serde = { version = "1.0", optional = true, default-features = false, features = ["derive"] }
2626

2727
# `zeroize` is an explicit dependency because this crate may be used without the `cipher` crate
2828
zeroize = { version = "1.8.1", optional = true, default-features = false }

chacha20/src/backends.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(any(feature = "cipher", feature = "rng"))]
2+
13
use cfg_if::cfg_if;
24

35
cfg_if! {

chacha20/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub use legacy::{ChaCha20Legacy, LegacyNonce};
144144
pub use xchacha::{XChaCha8, XChaCha12, XChaCha20, XNonce, hchacha};
145145

146146
/// State initialization constant ("expand 32-byte k")
147+
#[cfg(any(feature = "cipher", feature = "rng"))]
147148
const CONSTANTS: [u32; 4] = [0x6170_7865, 0x3320_646e, 0x7962_2d32, 0x6b20_6574];
148149

149150
/// Number of 32-bit words in the ChaCha state
@@ -230,6 +231,7 @@ impl<R: Rounds, V: Variant> ChaChaCore<R, V> {
230231
/// Constructs a ChaChaCore with the specified key, iv, and amount of rounds.
231232
/// You must ensure that the iv is of the correct size when using this method
232233
/// directly.
234+
#[cfg(any(feature = "cipher", feature = "rng"))]
233235
fn new(key: &[u8; 32], iv: &[u8]) -> Self {
234236
let mut state = [0u32; STATE_WORDS];
235237

0 commit comments

Comments
 (0)