Skip to content

Commit 0d9eb9d

Browse files
authored
chacha20: Add NEON implementation for aarch64 (#274)
Processes four blocks in parallel. Adapted from the SUPERCOP `dolbeau` backend (public domain). Placed behind a new `neon` feature flag, as aarch64 SIMD intrinsics are not yet stable.
1 parent f67debd commit 0d9eb9d

File tree

5 files changed

+656
-3
lines changed

5 files changed

+656
-3
lines changed

.github/workflows/chacha20.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ jobs:
163163
- target: aarch64-unknown-linux-gnu
164164
rust: stable
165165

166+
# ARM64 with NEON backend
167+
- target: aarch64-unknown-linux-gnu
168+
rust: nightly
169+
features: --features neon
170+
166171
# PPC32
167172
- target: powerpc-unknown-linux-gnu
168173
rust: 1.51.0 # MSRV
@@ -180,7 +185,7 @@ jobs:
180185
profile: minimal
181186
override: true
182187
- run: cargo install cross
183-
- run: cross test --target ${{ matrix.target }} --release
188+
- run: cross test --target ${{ matrix.target }} --release ${{ matrix.features }}
184189
- run: cross test --target ${{ matrix.target }} --release --features force-soft
185190
- run: cross test --target ${{ matrix.target }} --release --features rng
186191
- run: cross test --target ${{ matrix.target }} --release --features std

chacha20/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ expose-core = []
3737
force-soft = []
3838
hchacha = ["cipher"]
3939
legacy = ["cipher"]
40+
neon = []
4041
rng = ["rand_core"]
4142
std = ["cipher/std"]
4243

chacha20/src/backend.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
use cfg_if::cfg_if;
77

8+
pub(crate) mod soft;
9+
810
cfg_if! {
911
if #[cfg(all(
1012
any(target_arch = "x86", target_arch = "x86_64"),
@@ -14,12 +16,19 @@ cfg_if! {
1416
pub(crate) mod autodetect;
1517
pub(crate) mod avx2;
1618
pub(crate) mod sse2;
17-
pub(crate) mod soft;
1819

1920
pub(crate) use self::autodetect::BUFFER_SIZE;
2021
pub use self::autodetect::Core;
22+
} else if #[cfg(all(
23+
feature = "neon",
24+
target_arch = "aarch64",
25+
target_feature = "neon",
26+
not(feature = "force-soft")
27+
))] {
28+
pub(crate) mod neon;
29+
pub(crate) use self::neon::BUFFER_SIZE;
30+
pub use self::neon::Core;
2131
} else {
22-
pub(crate) mod soft;
2332
pub(crate) use self::soft::BUFFER_SIZE;
2433
pub use self::soft::Core;
2534
}

0 commit comments

Comments
 (0)