Skip to content

Commit 3ff33ae

Browse files
authored
chacha20: add chacha20_force_neon cfg attribute (#317)
Adds an attribute consistent with the other target-specific cfg attributes for enabling the NEON backend. This unblocks releasing NEON support as a feature.
1 parent 0b24338 commit 3ff33ae

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

.github/workflows/chacha20.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ jobs:
189189
# ARM64 with NEON backend
190190
- target: aarch64-unknown-linux-gnu
191191
rust: stable
192-
features: --features neon
192+
rustflags: --cfg chacha20_force_neon
193193

194194
# PPC32
195195
- target: powerpc-unknown-linux-gnu
@@ -210,12 +210,5 @@ jobs:
210210
with:
211211
toolchain: ${{ matrix.rust }}
212212
targets: ${{ matrix.target }}
213-
- name: Install precompiled cross
214-
run: |
215-
export URL=$(curl -s https://api.github.com/repos/cross-rs/cross/releases/latest | \
216-
jq -r '.assets[] | select(.name | contains("x86_64-unknown-linux-gnu.tar.gz")) | .browser_download_url')
217-
wget -O /tmp/binaries.tar.gz $URL
218-
tar -C /tmp -xzf /tmp/binaries.tar.gz
219-
mv /tmp/cross ~/.cargo/bin
220-
shell: bash
221-
- run: cross test --package chacha20 --target ${{ matrix.target }} ${{ matrix.features }}
213+
- uses: RustCrypto/actions/cross-install@master
214+
- run: RUSTFLAGS="${{ matrix.rustflags }}" cross test --package chacha20 --target ${{ matrix.target }}

chacha20/src/backends.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cfg_if! {
1515
pub(crate) mod sse2;
1616
}
1717
}
18-
} else if #[cfg(all(feature = "neon", target_arch = "aarch64", target_feature = "neon"))] {
18+
} else if #[cfg(all(chacha20_force_neon, target_arch = "aarch64", target_feature = "neon"))] {
1919
pub(crate) mod neon;
2020
} else {
2121
pub(crate) mod soft;

chacha20/src/backends/neon.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
//! NEON-optimized implementation for aarch64 CPUs adapted from the Crypto++ `chacha_simd`
2-
//! implementation by Jack Lloyd and Jeffrey Walton (public domain).
1+
//! NEON-optimized implementation for aarch64 CPUs.
2+
//!
3+
//! Adapted from the Crypto++ `chacha_simd` implementation by Jack Lloyd and
4+
//! Jeffrey Walton (public domain).
5+
36
use crate::{Block, StreamClosure, Unsigned, STATE_WORDS};
47
use cipher::{
58
consts::{U4, U64},
69
BlockSizeUser, ParBlocks, ParBlocksSizeUser, StreamBackend,
710
};
8-
use core::marker::PhantomData;
9-
10-
use core::arch::aarch64::*;
11+
use core::{arch::aarch64::*, marker::PhantomData};
1112

1213
#[inline]
1314
#[target_feature(enable = "neon")]

chacha20/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@
8383
//!
8484
//! You can modify crate using the following configuration flags:
8585
//!
86+
//! - `chacha20_force_avx2`: force AVX2 backend on x86/x86_64 targets.
87+
//! Requires enabled AVX2 target feature. Ignored on non-x86(-64) targets.
88+
//! - `chacha20_force_neon`: force NEON backend on ARM targets.
89+
//! Requires enabled NEON target feature. Ignored on non-ARM targets. Nightly-only.
8690
//! - `chacha20_force_soft`: force software backend.
87-
//! - `chacha20_force_sse2`: force SSE2 backend. Requires enabled SSE2 target feature,
88-
//! ignored on non-x86(-64) targets.
89-
//! - `chacha20_force_avx2`: force AVX2 backend. Requires enabled AVX2 target feature,
90-
//! ignored on non-x86(-64) targets.
91+
//! - `chacha20_force_sse2`: force SSE2 backend on x86/x86_64 targets.
92+
//! Requires enabled SSE2 target feature. Ignored on non-x86(-64) targets.
9193
//!
9294
//! The flags can be enabled using `RUSTFLAGS` environmental variable
9395
//! (e.g. `RUSTFLAGS="--cfg chacha20_force_avx2"`) or by modifying `.cargo/config`.
@@ -278,7 +280,7 @@ impl<R: Unsigned> StreamCipherCore for ChaChaCore<R> {
278280
}
279281
}
280282
}
281-
} else if #[cfg(all(feature = "neon", target_arch = "aarch64", target_feature = "neon"))] {
283+
} else if #[cfg(all(chacha20_force_neon, target_arch = "aarch64", target_feature = "neon"))] {
282284
unsafe {
283285
backends::neon::inner::<R, _>(&mut self.state, f);
284286
}

0 commit comments

Comments
 (0)