Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/chacha20.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ defaults:
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-Dwarnings"
# NOTE: The mirror number changes with each version so keep these in sync
SDE_FULL_VERSION_MIRROR: "859732"
SDE_FULL_VERSION: "9.58.0-2025-06-16"

jobs:
build:
Expand Down Expand Up @@ -79,6 +82,43 @@ jobs:
- run: cargo check --target ${{ matrix.target }} --all-features
- run: cargo hack test --feature-powerset --target ${{ matrix.target }}

# Tests for the AVX-512 backend
avx512:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
rust: stable
RUSTFLAGS: "-Dwarnings --cfg chacha20_avx512"
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
steps:
- uses: actions/checkout@v4
- name: Install Intel SDE
run: |
curl -JLO "https://downloadmirror.intel.com/${{ env.SDE_FULL_VERSION_MIRROR }}/sde-external-${{ env.SDE_FULL_VERSION }}-lin.tar.xz"
tar xvf sde-external-${{ env.SDE_FULL_VERSION }}-lin.tar.xz -C /opt
echo "/opt/sde-external-${{ env.SDE_FULL_VERSION }}-lin" >> $GITHUB_PATH
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
# NOTE: Write a `.cargo/config.toml` to configure the target for AVX-512
# NOTE: We use intel-sde as the runner since not all GitHub CI hosts support AVX512
- name: write .cargo/config.toml
shell: bash
run: |
cd ../chacha20/..
mkdir -p .cargo
echo '[target.${{ matrix.target }}]' > .cargo/config.toml
echo 'runner = "sde64 -future --"' >> .cargo/config.toml
- run: ${{ matrix.deps }}
- run: cargo test --target ${{ matrix.target }}
- run: cargo test --target ${{ matrix.target }} --all-features

# Tests for the AVX2 backend
avx2:
runs-on: ubuntu-latest
Expand Down
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.

3 changes: 3 additions & 0 deletions chacha20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cipher = { version = "0.5.0-rc.1", features = ["dev"] }
hex-literal = "1"
proptest = "1"
rand_chacha = "0.9"
hex = "0.4"

[features]
default = ["cipher"]
Expand All @@ -48,9 +49,11 @@ rustdoc-args = ["--cfg", "docsrs"]
[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(chacha20_avx512)',
'cfg(chacha20_force_soft)',
'cfg(chacha20_force_sse2)',
'cfg(chacha20_force_avx2)',
'cfg(chacha20_force_avx512)',
]

[lints.clippy]
Expand Down
1 change: 1 addition & 0 deletions chacha20/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ work on stable Rust with the following `RUSTFLAGS`:
- `x86` / `x86_64`
- `avx2`: (~1.4cpb) `-Ctarget-cpu=haswell -Ctarget-feature=+avx2`
- `sse2`: (~1.6cpb) `-Ctarget-feature=+sse2` (on by default on x86 CPUs)
- `avx512`: `-Ctarget-feature=+avx512f,+avx512vl --cfg chacha20_avx512` requires Rust 1.89+
- `aarch64`
- `neon` (~2-3x faster than `soft`) requires Rust 1.61+ and the `neon` feature enabled
- Portable
Expand Down
9 changes: 8 additions & 1 deletion chacha20/src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ cfg_if! {
pub(crate) mod soft;
} else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
cfg_if! {
if #[cfg(chacha20_force_avx2)] {
if #[cfg(all(chacha20_avx512, chacha20_force_avx512))] {
pub(crate) mod avx512;
// AVX-2 backend needed for RNG if enabled
#[cfg(feature = "rng")]
pub(crate) mod avx2;
} else if #[cfg(chacha20_force_avx2)] {
pub(crate) mod avx2;
} else if #[cfg(chacha20_force_sse2)] {
pub(crate) mod sse2;
} else {
pub(crate) mod soft;
#[cfg(chacha20_avx512)]
pub(crate) mod avx512;
pub(crate) mod avx2;
pub(crate) mod sse2;
}
Expand Down
1 change: 1 addition & 0 deletions chacha20/src/backends/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const N: usize = PAR_BLOCKS / 2;
#[inline]
#[target_feature(enable = "avx2")]
#[cfg(feature = "cipher")]
#[cfg_attr(chacha20_force_avx512, expect(unused))]
pub(crate) unsafe fn inner<R, F, V>(state: &mut [u32; STATE_WORDS], f: F)
where
R: Rounds,
Expand Down
Loading
Loading