Skip to content

Commit 89a85f7

Browse files
committed
Add a testing harness with github workflows
Using docker for testing, Intel SDE for x86
1 parent bc6c2d6 commit 89a85f7

17 files changed

+489
-248
lines changed

.github/workflows/runtest.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Run Test
2+
on:
3+
workflow_call:
4+
inputs:
5+
arch:
6+
required: true
7+
type: string
8+
target:
9+
required: true
10+
type: string
11+
channel:
12+
required: true
13+
type: string
14+
target-features:
15+
required: false
16+
type: string
17+
default: ''
18+
19+
jobs:
20+
test:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install Rust
26+
uses: actions-rs/toolchain@v1
27+
with:
28+
profile: minimal
29+
toolchain: ${{ inputs.channel }}
30+
default: true
31+
target: ${{ inputs.target }}
32+
33+
- run: echo "RUSTFLAGS=-C target-feature=${{ inputs.target-features }}" >> $GITHUB_ENV
34+
shell: bash
35+
36+
- name: Test
37+
run: |
38+
chmod 777 ./ci/run-docker.sh
39+
./ci/run-docker.sh ${{ inputs.arch }} ${{ inputs.target }} ${{ inputs.channel == 'nightly' && '--features=nightly' || '' }}
40+
shell: bash

.github/workflows/rust.yml

+132-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,141 @@
1-
name: Rust
1+
name: Check
22

33
on:
4-
push:
5-
branches: [ "master" ]
64
pull_request:
7-
branches: [ "master" ]
8-
9-
env:
10-
CARGO_TERM_COLOR: always
5+
push:
6+
branches:
7+
- master
118

129
jobs:
13-
build:
10+
style:
11+
name: Check Style
12+
runs-on: ubuntu-latest
1413

14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Rustfmt Check
18+
run: cargo fmt --all --check
19+
20+
clippy:
21+
name: Clippy Check of ${{ matrix.impl.name }}
1522
runs-on: ubuntu-latest
1623

24+
strategy:
25+
matrix:
26+
impl:
27+
- name: AES-NI
28+
target: x86_64-unknown-linux-gnu
29+
caps: X86_64_UNKNOWN_LINUX_GNU
30+
target-features: +sse4.1,+aes
31+
- name: AES-NI with VAES
32+
target: x86_64-unknown-linux-gnu
33+
caps: X86_64_UNKNOWN_LINUX_GNU
34+
target-features: +vaes
35+
- name: AES-NI with VAES and AVX-512
36+
target: x86_64-unknown-linux-gnu
37+
caps: X86_64_UNKNOWN_LINUX_GNU
38+
target-features: +vaes,+avx512f
39+
- name: Neon
40+
target: aarch64-unknown-linux-gnu
41+
caps: AARCH64_UNKNOWN_LINUX_GNU
42+
target-features: +aes
43+
- name: RV64
44+
target: riscv64gc-unknown-linux-gnu
45+
caps: RISCV64GC_UNKNOWN_LINUX_GNU
46+
target-features: +zkne,+zknd
47+
- name: RV32
48+
target: riscv32i-unknown-none-elf
49+
caps: RISCV32I_UNKNOWN_NONE_ELF
50+
target-features: +zkne,+zknd
51+
- name: Software
52+
target: x86_64-unknown-linux-gnu
53+
caps: X86_64_UNKNOWN_LINUX_GNU
54+
target-features: ''
1755
steps:
18-
- uses: actions/checkout@v3
19-
- name: Build
20-
run: cargo build --verbose
21-
- name: Run tests
22-
run: cargo test --verbose
56+
- uses: actions/checkout@v3
57+
58+
- run: ${{ format('echo "CARGO_TARGET_{0}_RUSTFLAGS=-C target-feature={1}" >> $GITHUB_ENV', matrix.impl.caps, matrix.impl.target-features) }}
59+
60+
- name: Install Rust
61+
uses: actions-rs/toolchain@v1
62+
with:
63+
toolchain: nightly
64+
target: ${{ matrix.impl.target }}
65+
components: clippy
66+
profile: minimal
67+
override: true
68+
69+
- name: Clippy Check
70+
run: cargo clippy --target ${{ matrix.impl.target }} --features=nightly --no-deps -- -D clippy::pedantic
71+
72+
test-aesni:
73+
strategy:
74+
matrix:
75+
channel: [ stable, beta, nightly ]
76+
name: Test of AESNI with ${{ matrix.channel }}
77+
uses: ./.github/workflows/runtest.yml
78+
with:
79+
arch: x86_64
80+
target: x86_64-unknown-linux-gnu
81+
channel: ${{ matrix.channel }}
82+
target-features: +sse4.1,+aes
83+
84+
test-aesni-vaes:
85+
name: Test of AESNI with VAES
86+
uses: ./.github/workflows/runtest.yml
87+
with:
88+
arch: x86_64
89+
target: x86_64-unknown-linux-gnu
90+
channel: nightly
91+
target-features: +vaes
92+
93+
test-aesni-vaes-avx512:
94+
name: Test of AESNI with VAES and AVX512F
95+
uses: ./.github/workflows/runtest.yml
96+
with:
97+
arch: x86_64
98+
target: x86_64-unknown-linux-gnu
99+
channel: nightly
100+
target-features: +vaes,+avx512f
101+
102+
test-neon:
103+
strategy:
104+
matrix:
105+
channel: [ stable, beta, nightly ]
106+
name: Test of Neon on AArch64 with ${{ matrix.channel }}
107+
uses: ./.github/workflows/runtest.yml
108+
with:
109+
arch: aarch64
110+
target: aarch64-unknown-linux-gnu
111+
channel: ${{ matrix.channel }}
112+
target-features: +aes
113+
114+
test-armv8:
115+
name: Test of Neon on ARMv8
116+
uses: ./.github/workflows/runtest.yml
117+
with:
118+
arch: arm
119+
target: armv7-unknown-linux-gnueabihf
120+
channel: nightly
121+
target-features: +aes
122+
123+
test-riscv64:
124+
name: Test of RV64
125+
uses: ./.github/workflows/runtest.yml
126+
with:
127+
arch: riscv64
128+
target: riscv64gc-unknown-linux-gnu
129+
channel: nightly
130+
target-features: +zkne,+zknd
131+
132+
test-software:
133+
strategy:
134+
matrix:
135+
channel: [ stable, beta, nightly ]
136+
name: Test of Software Implementation with ${{ matrix.channel }}
137+
uses: ./.github/workflows/runtest.yml
138+
with:
139+
arch: x86_64
140+
target: x86_64-unknown-linux-gnu
141+
channel: ${{ matrix.channel }}

ci/aarch64-docker

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ubuntu:24.04
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
3+
gcc \
4+
ca-certificates \
5+
libc6-dev \
6+
gcc-aarch64-linux-gnu \
7+
libc6-dev-arm64-cross \
8+
qemu-user \
9+
make \
10+
file
11+
12+
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
13+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu"

ci/arm-docker

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ubuntu:24.04
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
3+
gcc \
4+
ca-certificates \
5+
libc6-dev \
6+
gcc-arm-linux-gnueabihf \
7+
libc6-dev-armhf-cross \
8+
qemu-user \
9+
make \
10+
file
11+
12+
ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
13+
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf"

ci/riscv64-docker

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ubuntu:24.04
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
3+
gcc \
4+
ca-certificates \
5+
libc6-dev \
6+
gcc-riscv64-linux-gnu \
7+
libc6-dev-riscv64-cross \
8+
qemu-user \
9+
make \
10+
file
11+
12+
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc \
13+
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER="qemu-riscv64 -L /usr/riscv64-linux-gnu -cpu rv64,zk=true"

ci/run-docker.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
if [ $# -lt 2 ]; then
6+
>&2 echo "Usage: $0 <ARCH> <TARGET> [<FEATURE>]"
7+
exit 1
8+
fi
9+
10+
echo "Building docker container for ${1}"
11+
docker build -t aes -f "ci/${1}-docker" ci/
12+
mkdir -p target
13+
echo "Running docker"
14+
docker run \
15+
--rm \
16+
--user "$(id -u)":"$(id -g)" \
17+
--env CARGO_HOME=/cargo \
18+
--env CARGO_TARGET_DIR=/checkout/target \
19+
--env RUSTFLAGS \
20+
--volume "${HOME}/.cargo":/cargo \
21+
--volume "$(rustc --print sysroot)":/rust:ro \
22+
--volume "$(pwd)":/checkout:ro \
23+
--volume "$(pwd)"/target:/checkout/target \
24+
--init \
25+
--workdir /checkout \
26+
--privileged \
27+
aes \
28+
sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec cargo test --target ${2} ${3-}"

ci/x86_64-docker

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ubuntu:24.04
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
3+
gcc \
4+
ca-certificates \
5+
libc6-dev \
6+
wget \
7+
xz-utils \
8+
make \
9+
file
10+
11+
RUN wget https://downloadmirror.intel.com/823664/sde-external-9.38.0-2024-04-18-lin.tar.xz
12+
RUN tar -xJf sde-external-9.38.0-2024-04-18-lin.tar.xz
13+
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="/sde-external-9.38.0-2024-04-18-lin/sde64 -future --"

src/aes_arm.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use core::{mem, slice};
77

88
#[derive(Copy, Clone)]
99
#[repr(transparent)]
10+
#[must_use]
1011
pub struct AesBlock(uint8x16_t);
1112

1213
impl PartialEq for AesBlock {
@@ -94,6 +95,7 @@ impl AesBlock {
9495
}
9596

9697
#[inline]
98+
#[must_use]
9799
pub fn is_zero(self) -> bool {
98100
#[cfg(not(target_arch = "arm"))]
99101
unsafe {
@@ -120,7 +122,7 @@ impl AesBlock {
120122
self.pre_enc_last(round_key).mc()
121123
}
122124

123-
/// Performs one round of AES encryption function (ShiftRows->SubBytes->MixColumns->AddRoundKey)
125+
/// Performs one round of AES encryption function (`ShiftRows`->`SubBytes`->`MixColumns`->`AddRoundKey`)
124126
#[inline]
125127
pub fn enc(self, round_key: Self) -> Self {
126128
self.pre_enc(Self::zero()) ^ round_key
@@ -136,31 +138,31 @@ impl AesBlock {
136138
self.pre_dec_last(round_key).imc()
137139
}
138140

139-
/// Performs one round of AES decryption function (InvShiftRows->InvSubBytes->InvMixColumns->AddRoundKey)
141+
/// Performs one round of AES decryption function (`InvShiftRows`->`InvSubBytes`->`InvMixColumn`s->`AddRoundKey`)
140142
#[inline]
141143
pub fn dec(self, round_key: Self) -> Self {
142144
self.pre_dec(Self::zero()) ^ round_key
143145
}
144146

145-
/// Performs one round of AES encryption function without MixColumns (ShiftRows->SubBytes->AddRoundKey)
147+
/// Performs one round of AES encryption function without `MixColumns` (`ShiftRows`->`SubBytes`->`AddRoundKey`)
146148
#[inline]
147149
pub fn enc_last(self, round_key: Self) -> Self {
148150
self.pre_enc_last(Self::zero()) ^ round_key
149151
}
150152

151-
/// Performs one round of AES decryption function without InvMixColumns (InvShiftRows->InvSubBytes->AddRoundKey)
153+
/// Performs one round of AES decryption function without `InvMixColumn`s (`InvShiftRows`->`InvSubBytes`->`AddRoundKey`)
152154
#[inline]
153155
pub fn dec_last(self, round_key: Self) -> Self {
154156
self.pre_dec_last(Self::zero()) ^ round_key
155157
}
156158

157-
/// Performs the MixColumns operation
159+
/// Performs the `MixColumns` operation
158160
#[inline]
159161
pub fn mc(self) -> Self {
160162
Self(unsafe { vaesmcq_u8(self.0) })
161163
}
162164

163-
/// Performs the InvMixColumns operation
165+
/// Performs the `InvMixColumn`s operation
164166
#[inline]
165167
pub fn imc(self) -> Self {
166168
Self(unsafe { vaesimcq_u8(self.0) })

0 commit comments

Comments
 (0)