Skip to content

Commit 3cfbdaa

Browse files
committed
Add a testing harness with github workflows
1 parent bc6c2d6 commit 3cfbdaa

13 files changed

+440
-257
lines changed

.github/workflows/common.yml

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
name: Check
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
style:
11+
name: Check Style
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Install rust
18+
run: rustup update
19+
20+
- name: Rustfmt Check
21+
run: cargo fmt --all --check
22+
23+
clippy:
24+
name: Clippy Check of ${{ matrix.impl.name }}
25+
runs-on: ubuntu-latest
26+
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
impl:
31+
- name: AES-NI
32+
target: x86_64-unknown-linux-gnu
33+
caps: X86_64_UNKNOWN_LINUX_GNU
34+
target-features: +sse4.1,+aes
35+
- name: AES-NI with VAES
36+
target: x86_64-unknown-linux-gnu
37+
caps: X86_64_UNKNOWN_LINUX_GNU
38+
target-features: +vaes
39+
- name: AES-NI with VAES and AVX-512
40+
target: x86_64-unknown-linux-gnu
41+
caps: X86_64_UNKNOWN_LINUX_GNU
42+
target-features: +vaes,+avx512f
43+
- name: Neon
44+
target: aarch64-unknown-linux-gnu
45+
caps: AARCH64_UNKNOWN_LINUX_GNU
46+
target-features: +aes
47+
- name: RV64
48+
target: riscv64gc-unknown-linux-gnu
49+
caps: RISCV64GC_UNKNOWN_LINUX_GNU
50+
target-features: +zkne,+zknd
51+
- name: RV32
52+
target: riscv32i-unknown-none-elf
53+
caps: RISCV32I_UNKNOWN_NONE_ELF
54+
target-features: +zkne,+zknd
55+
- name: Software
56+
target: x86_64-unknown-linux-gnu
57+
caps: X86_64_UNKNOWN_LINUX_GNU
58+
target-features: ''
59+
steps:
60+
- uses: actions/checkout@v3
61+
62+
- run: ${{ format('echo "CARGO_TARGET_{0}_RUSTFLAGS=-C target-feature={1}" >> $GITHUB_ENV', matrix.impl.caps, matrix.impl.target-features) }}
63+
64+
- name: Install Rust
65+
uses: actions-rs/toolchain@v1
66+
with:
67+
toolchain: nightly
68+
target: ${{ matrix.impl.target }}
69+
components: clippy
70+
profile: minimal
71+
override: true
72+
73+
- name: Clippy Check
74+
run: cargo clippy --target ${{ matrix.impl.target }} --features=nightly --no-deps -- -D clippy::pedantic
75+
76+
test-aesni:
77+
strategy:
78+
matrix:
79+
channel: [ stable, beta, nightly ]
80+
name: Test of AESNI with ${{ matrix.channel }}
81+
uses: ./.github/workflows/runtest.yml
82+
with:
83+
target: x86_64-unknown-linux-gnu
84+
channel: ${{ matrix.channel }}
85+
env-vars: CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS=-C target-feature=+sse4.1,+aes
86+
87+
test-aesni-vaes:
88+
name: Test of AESNI with VAES
89+
uses: ./.github/workflows/runtest.yml
90+
with:
91+
target: x86_64-unknown-linux-gnu
92+
channel: nightly
93+
env-vars: CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS=-C target-feature=+vaes
94+
95+
test-aesni-vaes-avx512:
96+
name: Test of AESNI with VAES and AVX512F
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v4
100+
101+
- name: Install Rust
102+
run: |
103+
rustup update nightly --no-self-update
104+
rustup default nightly
105+
106+
- name: Download SDE
107+
run: |
108+
wget https://downloadmirror.intel.com/813591/sde-external-9.33.0-2024-01-07-lin.tar.xz
109+
tar -xJf sde-external-9.33.0-2024-01-07-lin.tar.xz
110+
echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER=./sde-external-9.33.0-2024-01-07-lin/sde64 -future --" >> $GITHUB_ENV
111+
112+
- name: Test
113+
run: |
114+
echo "RUSTFLAGS=-C target-feature=+avx512f,+vaes" >> $GITHUB_ENV
115+
cargo test --features=nightly
116+
117+
test-neon:
118+
strategy:
119+
matrix:
120+
channel: [ stable, beta, nightly ]
121+
name: Test of Neon on AArch64 with ${{ matrix.channel }}
122+
uses: ./.github/workflows/runtest.yml
123+
with:
124+
target: aarch64-unknown-linux-gnu
125+
channel: ${{ matrix.channel }}
126+
env-vars: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS=-C target-feature=+aes
127+
128+
test-armv8:
129+
name: Test of Neon on ${{ matrix.target.triple }}
130+
strategy:
131+
fail-fast: false
132+
matrix:
133+
target:
134+
- triple: armv7-linux-androideabi
135+
caps: ARMV7_LINUX_ANDROIDEABI
136+
- triple: armv7-unknown-linux-gnueabihf
137+
caps: ARMV7_UNKNOWN_LINUX_GNUEABIHF
138+
- triple: thumbv7neon-linux-androideabi
139+
caps: THUMBV7NEON_LINUX_ANDROIDEABI
140+
- triple: thumbv7neon-unknown-linux-gnueabihf
141+
caps: THUMBV7NEON_UNKNOWN_LINUX_GNUEABIHF
142+
uses: ./.github/workflows/runtest.yml
143+
with:
144+
target: ${{ matrix.target.triple }}
145+
channel: nightly
146+
env-vars: ${{ format('CARGO_TARGET_{0}_RUSTFLAGS=-C target-feature=+v8,+aes', matrix.target.caps) }}
147+
148+
test-riscv64:
149+
name: Test of RV64
150+
uses: ./.github/workflows/runtest.yml
151+
with:
152+
target: riscv64gc-unknown-linux-gnu
153+
channel: nightly
154+
env-vars: |
155+
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUSTFLAGS=-C target-feature=+zkne,+zknd
156+
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER=qemu-riscv64 -cpu max
157+
158+
test-software:
159+
strategy:
160+
matrix:
161+
channel: [ stable, beta, nightly ]
162+
target:
163+
- x86_64-unknown-linux-gnu
164+
- powerpc64-unknown-linux-gnu
165+
name: Test of Software AES on ${{ matrix.target }} with ${{ matrix.channel }} Rust
166+
uses: ./.github/workflows/runtest.yml
167+
with:
168+
target: ${{ matrix.target }}
169+
channel: ${{ matrix.channel }}

.github/workflows/runtest.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run Test
2+
on:
3+
workflow_call:
4+
inputs:
5+
target:
6+
required: true
7+
type: string
8+
channel:
9+
required: true
10+
type: string
11+
env-vars:
12+
required: false
13+
type: string
14+
default: ''
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Install Rust
23+
run: |
24+
rustup update ${{ inputs.channel }} --no-self-update
25+
rustup default ${{ inputs.channel }}
26+
27+
- run: echo "${{ inputs.env-vars }}" >> $GITHUB_ENV
28+
29+
- name: Test
30+
uses: actions-rs/cargo@v1
31+
with:
32+
use-cross: true
33+
command: test
34+
args: --target ${{ inputs.target }} ${{ inputs.channel == 'nightly' && '--features=nightly' || '' }}

.github/workflows/rust.yml

-22
This file was deleted.

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) })

src/aes_default.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#![allow(clippy::unreadable_literal, clippy::cast_possible_truncation)]
12
use core::ops::{BitAnd, BitOr, BitXor, Not};
23

34
#[derive(Copy, Clone, PartialEq, Eq)]
45
#[repr(C, align(16))]
6+
#[must_use]
57
pub struct AesBlock(u32, u32, u32, u32);
68

79
#[inline(always)]
@@ -104,11 +106,12 @@ impl AesBlock {
104106
}
105107

106108
#[inline]
109+
#[must_use]
107110
pub fn is_zero(self) -> bool {
108111
(self.0 | self.1 | self.2 | self.3) == 0
109112
}
110113

111-
/// Performs one round of AES encryption function (ShiftRows->SubBytes->MixColumns->AddRoundKey)
114+
/// Performs one round of AES encryption function (`ShiftRows`->`SubBytes`->`MixColumns`->`AddRoundKey`)
112115
#[inline]
113116
pub fn enc(self, round_key: Self) -> Self {
114117
Self(
@@ -119,7 +122,7 @@ impl AesBlock {
119122
)
120123
}
121124

122-
/// Performs one round of AES encryption function without MixColumns (ShiftRows->SubBytes->AddRoundKey)
125+
/// Performs one round of AES encryption function without `MixColumns` (`ShiftRows`->`SubBytes`->`AddRoundKey`)
123126
#[inline]
124127
pub fn enc_last(self, round_key: Self) -> Self {
125128
Self(
@@ -146,7 +149,7 @@ impl AesBlock {
146149
)
147150
}
148151

149-
/// Performs one round of AES decryption function (InvShiftRows->InvSubBytes->InvMixColumns->AddRoundKey)
152+
/// Performs one round of AES decryption function (`InvShiftRows`->`InvSubBytes`->`InvMixColumn`s->`AddRoundKey`)
150153
#[inline]
151154
pub fn dec(self, round_key: Self) -> Self {
152155
Self(
@@ -157,7 +160,7 @@ impl AesBlock {
157160
)
158161
}
159162

160-
/// Performs one round of AES decryption function without InvMixColumns (InvShiftRows->InvSubBytes->AddRoundKey)
163+
/// Performs one round of AES decryption function without `InvMixColumn`s (`InvShiftRows`->`InvSubBytes`->`AddRoundKey`)
161164
#[inline]
162165
pub fn dec_last(self, round_key: Self) -> Self {
163166
Self(
@@ -184,7 +187,7 @@ impl AesBlock {
184187
)
185188
}
186189

187-
/// Performs the MixColumns operation
190+
/// Performs the `MixColumns` operation
188191
#[inline]
189192
pub fn mc(self) -> Self {
190193
Self(
@@ -207,7 +210,7 @@ impl AesBlock {
207210
)
208211
}
209212

210-
/// Performs the InvMixColumns operation
213+
/// Performs the `InvMixColumn`s operation
211214
#[inline]
212215
pub fn imc(self) -> Self {
213216
Self(

0 commit comments

Comments
 (0)