Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix workflow #2

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/runtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run Test
on:
workflow_call:
inputs:
arch:
required: true
type: string
target:
required: true
type: string
channel:
required: true
type: string
target-features:
required: false
type: string
default: ''

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ inputs.channel }}
default: true
target: ${{ inputs.target }}

- run: echo "RUSTFLAGS=-C target-feature=${{ inputs.target-features }}" >> $GITHUB_ENV
shell: bash

- name: Test
run: |
chmod 777 ./ci/run-docker.sh
./ci/run-docker.sh ${{ inputs.arch }} ${{ inputs.target }} ${{ inputs.channel == 'nightly' && '--features=nightly' || '' }}
shell: bash
145 changes: 132 additions & 13 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,141 @@
name: Rust
name: Check

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always
push:
branches:
- master

jobs:
build:
style:
name: Check Style
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Rustfmt Check
run: cargo fmt --all --check

clippy:
name: Clippy Check of ${{ matrix.impl.name }}
runs-on: ubuntu-latest

strategy:
matrix:
impl:
- name: AES-NI
target: x86_64-unknown-linux-gnu
caps: X86_64_UNKNOWN_LINUX_GNU
target-features: +sse4.1,+aes
- name: AES-NI with VAES
target: x86_64-unknown-linux-gnu
caps: X86_64_UNKNOWN_LINUX_GNU
target-features: +vaes
- name: AES-NI with VAES and AVX-512
target: x86_64-unknown-linux-gnu
caps: X86_64_UNKNOWN_LINUX_GNU
target-features: +vaes,+avx512f
- name: Neon
target: aarch64-unknown-linux-gnu
caps: AARCH64_UNKNOWN_LINUX_GNU
target-features: +aes
- name: RV64
target: riscv64gc-unknown-linux-gnu
caps: RISCV64GC_UNKNOWN_LINUX_GNU
target-features: +zkne,+zknd
- name: RV32
target: riscv32i-unknown-none-elf
caps: RISCV32I_UNKNOWN_NONE_ELF
target-features: +zkne,+zknd
- name: Software
target: x86_64-unknown-linux-gnu
caps: X86_64_UNKNOWN_LINUX_GNU
target-features: ''
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v3

- run: ${{ format('echo "CARGO_TARGET_{0}_RUSTFLAGS=-C target-feature={1}" >> $GITHUB_ENV', matrix.impl.caps, matrix.impl.target-features) }}

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: ${{ matrix.impl.target }}
components: clippy
profile: minimal
override: true

- name: Clippy Check
run: cargo clippy --target ${{ matrix.impl.target }} --features=nightly --no-deps -- -D clippy::pedantic

test-aesni:
strategy:
matrix:
channel: [ stable, beta, nightly ]
name: Test of AESNI with ${{ matrix.channel }}
uses: ./.github/workflows/runtest.yml
with:
arch: x86_64
target: x86_64-unknown-linux-gnu
channel: ${{ matrix.channel }}
target-features: +sse4.1,+aes

test-aesni-vaes:
name: Test of AESNI with VAES
uses: ./.github/workflows/runtest.yml
with:
arch: x86_64
target: x86_64-unknown-linux-gnu
channel: nightly
target-features: +vaes

test-aesni-vaes-avx512:
name: Test of AESNI with VAES and AVX512F
uses: ./.github/workflows/runtest.yml
with:
arch: x86_64
target: x86_64-unknown-linux-gnu
channel: nightly
target-features: +vaes,+avx512f

test-neon:
strategy:
matrix:
channel: [ stable, beta, nightly ]
name: Test of Neon on AArch64 with ${{ matrix.channel }}
uses: ./.github/workflows/runtest.yml
with:
arch: aarch64
target: aarch64-unknown-linux-gnu
channel: ${{ matrix.channel }}
target-features: +aes

test-armv8:
name: Test of Neon on ARMv8
uses: ./.github/workflows/runtest.yml
with:
arch: arm
target: armv7-unknown-linux-gnueabihf
channel: nightly
target-features: +aes

test-riscv64:
name: Test of RiscV-64
uses: ./.github/workflows/runtest.yml
with:
arch: riscv64
target: riscv64gc-unknown-linux-gnu
channel: nightly
target-features: +zkne,+zknd

test-software:
strategy:
matrix:
channel: [ stable, beta, nightly ]
name: Test of Software Implementation with ${{ matrix.channel }}
uses: ./.github/workflows/runtest.yml
with:
arch: x86_64
target: x86_64-unknown-linux-gnu
channel: ${{ matrix.channel }}
13 changes: 13 additions & 0 deletions ci/docker/aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
ca-certificates \
libc6-dev \
gcc-aarch64-linux-gnu \
libc6-dev-arm64-cross \
qemu-user \
make \
file

ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu"
13 changes: 13 additions & 0 deletions ci/docker/arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
ca-certificates \
libc6-dev \
gcc-arm-linux-gnueabihf \
libc6-dev-armhf-cross \
qemu-user \
make \
file

ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf"
13 changes: 13 additions & 0 deletions ci/docker/riscv64
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
ca-certificates \
libc6-dev \
gcc-riscv64-linux-gnu \
libc6-dev-riscv64-cross \
qemu-user \
make \
file

ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc \
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER="qemu-riscv64 -L /usr/riscv64-linux-gnu -cpu rv64,zk=true"
13 changes: 13 additions & 0 deletions ci/docker/x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
ca-certificates \
libc6-dev \
wget \
xz-utils \
make \
file

RUN wget https://downloadmirror.intel.com/823664/sde-external-9.38.0-2024-04-18-lin.tar.xz
RUN tar -xJf sde-external-9.38.0-2024-04-18-lin.tar.xz
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="/sde-external-9.38.0-2024-04-18-lin/sde64 -future --"
28 changes: 28 additions & 0 deletions ci/run-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env sh

set -ex

if [ $# -lt 2 ]; then
>&2 echo "Usage: $0 <ARCH> <TARGET> [<FEATURE>]"
exit 1
fi

echo "Building docker container for ${1}"
docker build -t aes -f "ci/docker/${1}" ci/
mkdir -p target
echo "Running docker"
docker run \
--rm \
--user "$(id -u)":"$(id -g)" \
--env CARGO_HOME=/cargo \
--env CARGO_TARGET_DIR=/checkout/target \
--env RUSTFLAGS \
--volume "${HOME}/.cargo":/cargo \
--volume "$(rustc --print sysroot)":/rust:ro \
--volume "$(pwd)":/checkout:ro \
--volume "$(pwd)"/target:/checkout/target \
--init \
--workdir /checkout \
--privileged \
aes \
sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec cargo test --target ${2} ${3-}"
14 changes: 8 additions & 6 deletions src/aes_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core::{mem, slice};

#[derive(Copy, Clone)]
#[repr(transparent)]
#[must_use]
pub struct AesBlock(uint8x16_t);

impl PartialEq for AesBlock {
Expand Down Expand Up @@ -94,6 +95,7 @@ impl AesBlock {
}

#[inline]
#[must_use]
pub fn is_zero(self) -> bool {
#[cfg(not(target_arch = "arm"))]
unsafe {
Expand All @@ -120,7 +122,7 @@ impl AesBlock {
self.pre_enc_last(round_key).mc()
}

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

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

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

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

/// Performs the MixColumns operation
/// Performs the `MixColumns` operation
#[inline]
pub fn mc(self) -> Self {
Self(unsafe { vaesmcq_u8(self.0) })
}

/// Performs the InvMixColumns operation
/// Performs the `InvMixColumn`s operation
#[inline]
pub fn imc(self) -> Self {
Self(unsafe { vaesimcq_u8(self.0) })
Expand Down
Loading
Loading