Skip to content

Commit c717b30

Browse files
authored
zeroize: add support for ARM64 SIMD registers (nightly-only) (#749)
Similar to the implementation for `x86`/`x86_64`, this commit adds nightly-only support for zeroizing ARM64 SIMD registers. Support is gated behind an `aarch64` feature so as to avoid breaking compilation on stable Rust. The feature is a no-op on non-`aarch64` targets.
1 parent 2b42893 commit c717b30

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

.github/workflows/zeroize.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,26 @@ jobs:
6464
override: true
6565
profile: minimal
6666
- run: cargo test --release
67-
- run: cargo test --release --all-features
67+
- run: cargo test --release --features alloc,derive
68+
69+
# Feature-gated ARM64 SIMD register support (nightly-only)
70+
aarch64:
71+
strategy:
72+
matrix:
73+
include:
74+
- target: aarch64-unknown-linux-gnu
75+
rust: nightly-2022-03-01
76+
runs-on: ubuntu-latest
77+
steps:
78+
- uses: actions/checkout@v2
79+
- uses: RustCrypto/actions/cargo-cache@master
80+
- run: ${{ matrix.deps }}
81+
- uses: actions-rs/toolchain@v1
82+
with:
83+
toolchain: ${{ matrix.rust }}
84+
target: ${{ matrix.target }}
85+
profile: minimal
86+
override: true
87+
- uses: RustCrypto/actions/cross-install@master
88+
- run: cross test --release --target ${{ matrix.target }} --features aarch64
89+
- run: cross test --release --target ${{ matrix.target }} --all-features

zeroize/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ zeroize_derive = { version = "1.3", path = "derive", optional = true }
2121

2222
[features]
2323
default = ["alloc"]
24+
aarch64 = []
2425
alloc = []
2526
derive = ["zeroize_derive"]
2627

zeroize/src/aarch64.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! [`Zeroize`] impls for ARM64 SIMD registers.
2+
//!
3+
//! Support for this is gated behind an `aarch64` feature because
4+
//! support for `core::arch::aarch64` is currently nightly-only.
5+
6+
use crate::{atomic_fence, volatile_write, Zeroize};
7+
8+
use core::arch::aarch64::*;
9+
10+
macro_rules! impl_zeroize_for_simd_register {
11+
($(($type:ty, $vdupq:ident)),+) => {
12+
$(
13+
#[cfg_attr(docsrs, doc(cfg(target_arch = "aarch64")))]
14+
#[cfg_attr(docsrs, doc(cfg(target_feature = "neon")))]
15+
impl Zeroize for $type {
16+
fn zeroize(&mut self) {
17+
volatile_write(self, unsafe { $vdupq(0) });
18+
atomic_fence();
19+
}
20+
}
21+
)+
22+
};
23+
}
24+
25+
// TODO(tarcieri): other NEON register types?
26+
impl_zeroize_for_simd_register! {
27+
(uint8x8_t, vdup_n_u8),
28+
(uint8x16_t, vdupq_n_u8),
29+
(uint16x4_t, vdup_n_u16),
30+
(uint16x8_t, vdupq_n_u16),
31+
(uint32x2_t, vdup_n_u32),
32+
(uint32x4_t, vdupq_n_u32),
33+
(uint64x1_t, vdup_n_u64),
34+
(uint64x2_t, vdupq_n_u64)
35+
}

zeroize/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ extern crate alloc;
238238
#[cfg_attr(docsrs, doc(cfg(feature = "zeroize_derive")))]
239239
pub use zeroize_derive::{Zeroize, ZeroizeOnDrop};
240240

241+
#[cfg(all(feature = "aarch64", target_arch = "aarch64"))]
242+
mod aarch64;
241243
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
242244
mod x86;
243245

0 commit comments

Comments
 (0)