Skip to content

Commit 8569b1c

Browse files
authored
ARMv8 Cryptography Extensions support (#250)
Adds a new nightly-only backend which uses ARMv8 Cryptography Extensions gated under the newly introduced `armv8` crate feature. Support is provided for AES-128, AES-192, and AES-256, with runtime CPU feature detection on Linux and macOS targets. These extensions are supported on both 32-bit and 64-bit ARM targets, however the current implementation is gated on `aarch64` (as that's the only architecture it's been tested on so far). However, it could be easily extended to 32-bit ARMv8 targets as well.
1 parent ad3e71e commit 8569b1c

File tree

13 files changed

+830
-71
lines changed

13 files changed

+830
-71
lines changed

.github/workflows/aes.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ jobs:
3636
target: ${{ matrix.target }}
3737
profile: minimal
3838
override: true
39-
- run: cargo check --all-features
39+
- run: cargo check --features compact,ctr,force-soft
4040
- run: cargo build --release --target ${{ matrix.target }}
4141
- run: cargo build --release --target ${{ matrix.target }} --features compact
4242
- run: cargo build --release --target ${{ matrix.target }} --features ctr
4343
- run: cargo build --release --target ${{ matrix.target }} --features force-soft
44-
- run: cargo build --release --target ${{ matrix.target }} --all-features
44+
- run: cargo build --release --target ${{ matrix.target }} --features compact,ctr,force-soft
4545

4646
# Tests for the AES-NI backend
4747
aesni:
@@ -79,7 +79,6 @@ jobs:
7979
- run: cargo test --release --target ${{ matrix.target }} --features compact
8080
- run: cargo test --release --target ${{ matrix.target }} --features ctr
8181
- run: cargo test --release --target ${{ matrix.target }} --features force-soft
82-
- run: cargo test --release --target ${{ matrix.target }} --all-features
8382

8483
# Tests for CPU feature autodetection with fallback to portable software implementation
8584
autodetect:
@@ -144,7 +143,7 @@ jobs:
144143
- run: cargo test --release --target ${{ matrix.target }} --features force-soft
145144
- run: cargo test --release --target ${{ matrix.target }} --features force-soft,compact
146145
- run: cargo test --release --target ${{ matrix.target }} --features force-soft,ctr
147-
- run: cargo test --release --target ${{ matrix.target }} --all-features
146+
- run: cargo build --release --target ${{ matrix.target }} --features compact,ctr,force-soft
148147

149148
# Cross-compiled tests
150149
cross:
@@ -162,7 +161,6 @@ jobs:
162161
rust: 1.49.0 # MSRV
163162
- target: powerpc-unknown-linux-gnu
164163
rust: stable
165-
166164
runs-on: ubuntu-latest
167165
steps:
168166
- uses: actions/checkout@v1
@@ -178,4 +176,40 @@ jobs:
178176
- run: cross test --release --target ${{ matrix.target }} --features compact
179177
- run: cross test --release --target ${{ matrix.target }} --features ctr
180178
- run: cross test --release --target ${{ matrix.target }} --features force-soft
179+
- run: cross test --release --target ${{ matrix.target }} --features compact,ctr,force-soft
180+
181+
# ARMv8 cross-compiled tests for AES intrinsics (nightly-only)
182+
armv8:
183+
strategy:
184+
matrix:
185+
include:
186+
- target: aarch64-unknown-linux-gnu
187+
rust: nightly
188+
runs-on: ubuntu-latest
189+
steps:
190+
- uses: actions/checkout@v1
191+
- run: ${{ matrix.deps }}
192+
- uses: actions-rs/toolchain@v1
193+
with:
194+
toolchain: ${{ matrix.rust }}
195+
target: ${{ matrix.target }}
196+
profile: minimal
197+
override: true
198+
- run: cargo install cross
199+
- run: cross test --release --target ${{ matrix.target }}
200+
- run: cross test --release --target ${{ matrix.target }} --features armv8,compact
201+
- run: cross test --release --target ${{ matrix.target }} --features armv8,ctr
202+
- run: cross test --release --target ${{ matrix.target }} --features armv8,force-soft
181203
- run: cross test --release --target ${{ matrix.target }} --all-features
204+
205+
clippy:
206+
runs-on: ubuntu-latest
207+
steps:
208+
- uses: actions/checkout@v1
209+
- uses: actions-rs/toolchain@v1
210+
with:
211+
toolchain: 1.49.0 # MSRV
212+
components: clippy
213+
override: true
214+
profile: minimal
215+
- run: cargo clippy --features compact,ctr,force-soft -- -D warnings

.github/workflows/workspace.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
components: clippy
2121
override: true
2222
profile: minimal
23-
- run: cargo clippy --all --all-features -- -D warnings
23+
- run: cargo clippy --all --exclude aes --all-features -- -D warnings
2424

2525
rustfmt:
2626
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
/target/
2-
aes/aesni/target/
3-
aes/aes/target/
1+
target/

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aes/Cargo.lock

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aes/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ opaque-debug = "0.3"
2222

2323
[dev-dependencies]
2424
cipher = { version = "0.3", features = ["dev"] }
25+
hex-literal = "0.2"
2526

26-
[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dependencies]
27-
cpufeatures = "0.1"
27+
[target.'cfg(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "x86"))'.dependencies]
28+
cpufeatures = "0.1.4"
2829

2930
[features]
30-
compact = [] # Reduce code size at the cost of slower performance
31+
armv8 = [] # Enable ARMv8 AES intrinsics (nightly-only)
32+
compact = [] # Reduce code size at the cost of slower performance
3133
force-soft = [] # Disable support for AES hardware intrinsics
3234

3335
[package.metadata.docs.rs]

0 commit comments

Comments
 (0)