diff --git a/.github/actions/cross-tests/action.yml b/.github/actions/cross-tests/action.yml new file mode 100644 index 0000000..580676b --- /dev/null +++ b/.github/actions/cross-tests/action.yml @@ -0,0 +1,41 @@ +name: "cross-tests" + +inputs: + rust: + required: true + package: + required: true + target: + required: true + features: + required: true + +runs: + using: "composite" + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ inputs.rust }} + target: ${{ inputs.target }} + override: true + - name: Install precompiled cross + run: | + export URL=$(curl -s https://api.github.com/repos/cross-rs/cross/releases/latest | \ + jq -r '.assets[] | select(.name | contains("x86_64-unknown-linux-gnu.tar.gz")) | .browser_download_url') + wget -O /tmp/binaries.tar.gz $URL + tar -C /tmp -xzf /tmp/binaries.tar.gz + mv /tmp/cross ~/.cargo/bin + shell: bash + - if: ${{ inputs.features != 'NO_FEATURE' }} + run: | + cd ${{ inputs.package }} + cross test --target ${{ inputs.target }} --no-default-features \ + --features ${{ inputs.features }} + shell: bash + - if: ${{ inputs.features == 'NO_FEATURE' }} + run: | + cd ${{ inputs.package }} + cross test --target ${{ inputs.target }} --no-default-features + shell: bash diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5cde165 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: +- package-ecosystem: cargo + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/.github/workflows/keccak.yml b/.github/workflows/keccak.yml new file mode 100644 index 0000000..680370d --- /dev/null +++ b/.github/workflows/keccak.yml @@ -0,0 +1,101 @@ +name: keccak + +on: + pull_request: + paths: + - ".github/workflows/keccak.yml" + - "keccak/**" + - "Cargo.*" + push: + branches: master + +defaults: + run: + working-directory: keccak + +env: + MSRV: 1.41.0 + RUSTFLAGS: "-Dwarnings" + CARGO_INCREMENTAL: 0 + +jobs: + set-msrv: + runs-on: ubuntu-latest + outputs: + msrv: ${{ steps.msrv.outputs.msrv }} + steps: + - uses: actions/checkout@v2 + - id: msrv + run: echo "::set-output name=msrv::$(echo $MSRV)" + + build: + needs: set-msrv + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - ${{needs.set-msrv.outputs.msrv}} + - stable + target: + - thumbv7em-none-eabi + - wasm32-unknown-unknown + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + override: true + - run: cargo build --no-default-features --target ${{ matrix.target }} + + test: + needs: set-msrv + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - ${{needs.set-msrv.outputs.msrv}} + - stable + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + - run: cargo check --all-features + - run: cargo test --no-default-features + - run: cargo test + - run: cargo test --all-features + + # Cross-compiled tests + cross: + needs: set-msrv + strategy: + matrix: + rust: + - ${{needs.set-msrv.outputs.msrv}} + - stable + target: + - i686-unknown-linux-gnu + - x86_64-unknown-linux-gnu + - aarch64-unknown-linux-gnu + - mips-unknown-linux-gnu + features: + - no_unroll + - 'NO_FEATURE' + + runs-on: ubuntu-latest + defaults: + run: + # Cross mounts only current package, i.e. by default it ignores workspace's Cargo.toml + working-directory: . + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/cross-tests + with: + rust: ${{ matrix.rust }} + package: ${{ github.workflow }} + target: ${{ matrix.target }} + features: ${{ matrix.features }} diff --git a/.github/workflows/security-audit.yml b/.github/workflows/security-audit.yml new file mode 100644 index 0000000..0d82d54 --- /dev/null +++ b/.github/workflows/security-audit.yml @@ -0,0 +1,24 @@ +name: Security Audit +on: + pull_request: + paths: Cargo.lock + push: + branches: master + paths: Cargo.lock + schedule: + - cron: "0 0 * * *" + +jobs: + security_audit: + name: Security Audit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Cache cargo bin + uses: actions/cache@v1 + with: + path: ~/.cargo/bin + key: ${{ runner.os }}-cargo-audit-v0.12.0 + - uses: actions-rs/audit-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml new file mode 100644 index 0000000..ff7810a --- /dev/null +++ b/.github/workflows/workspace.yml @@ -0,0 +1,43 @@ +name: Workspace + +on: + pull_request: + paths-ignore: + - README.md + push: + branches: master + paths-ignore: + - README.md + +jobs: + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + profile: minimal + override: true + - run: cargo clippy --all -- -D warnings + + rustfmt: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v1 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + profile: minimal + override: true + + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cda0e8f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: rust -services: docker -sudo: required - -matrix: - include: - - env: TARGET=i686-unknown-linux-gnu - rust: stable - - env: TARGET=x86_64-unknown-linux-gnu - rust: stable - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.15.0 - - env: TARGET=x86_64-unknown-linux-gnu - rust: nightly - - env: TARGET=powerpc-unknown-linux-gnu - rust: stable - - env: TARGET=powerpc64-unknown-linux-gnu - rust: stable - - env: TARGET=thumbv7em-none-eabi - rust: nightly - script: ./build_nostd.sh - install: - - cargo install xargo --force - - rustup target install armv7-unknown-linux-gnueabihf - - rustup component add rust-src - -install: - - curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git japaric/cross --force - - source ~/.cargo/env || true - -script: - - cross test --verbose --all --release --target $TARGET - -cache: cargo diff --git a/build_nostd.sh b/build_nostd.sh deleted file mode 100755 index 2fce0cf..0000000 --- a/build_nostd.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -# Due to the fact that cargo does not disable default features when we use -# cargo build --all --no-default-features we have to explicitly iterate over -# all crates (see https://github.com/rust-lang/cargo/issues/4753 ) -DIRS=`ls -d */` -TARGET="thumbv7em-none-eabi" -cargo clean - -for dir in $DIRS; do - # disable check for aesni, as it requires x86 - if [ $dir = "target/" ] - then - continue - fi - cd $dir - xargo build --no-default-features --verbose --target $TARGET || { - echo $dir failed - exit 1 - } - cd .. -done diff --git a/keccak/Cargo.toml b/keccak/Cargo.toml index 2747543..bef8d52 100644 --- a/keccak/Cargo.toml +++ b/keccak/Cargo.toml @@ -11,6 +11,3 @@ categories = ["cryptography", "no-std"] [features] no_unroll = [] - -[badges] -travis-ci = { repository = "RustCrypto/sponges" } diff --git a/keccak/src/lib.rs b/keccak/src/lib.rs index 48df9d6..1ea00b8 100644 --- a/keccak/src/lib.rs +++ b/keccak/src/lib.rs @@ -38,16 +38,17 @@ #![no_std] #![allow(non_upper_case_globals)] +#[rustfmt::skip] +mod unroll; + const PLEN: usize = 25; const RHO: [u32; 24] = [ - 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, - 39, 61, 20, 44, + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44, ]; const PI: [usize; 24] = [ - 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, - 22, 9, 6, 1, + 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1, ]; const RC: [u64; 24] = [ @@ -77,67 +78,12 @@ const RC: [u64; 24] = [ 0x8000000080008008, ]; -#[cfg(not(feature = "no_unroll"))] -macro_rules! unroll5 { - ($var:ident, $body:block) => { - { const $var: usize = 0; $body; } - { const $var: usize = 1; $body; } - { const $var: usize = 2; $body; } - { const $var: usize = 3; $body; } - { const $var: usize = 4; $body; } - }; -} - -#[cfg(feature = "no_unroll")] -macro_rules! unroll5 { - ($var:ident, $body:block) => { - for $var in 0..5 $body - } -} - -#[cfg(not(feature = "no_unroll"))] -macro_rules! unroll24 { - ($var: ident, $body: block) => { - { const $var: usize = 0; $body; } - { const $var: usize = 1; $body; } - { const $var: usize = 2; $body; } - { const $var: usize = 3; $body; } - { const $var: usize = 4; $body; } - { const $var: usize = 5; $body; } - { const $var: usize = 6; $body; } - { const $var: usize = 7; $body; } - { const $var: usize = 8; $body; } - { const $var: usize = 9; $body; } - { const $var: usize = 10; $body; } - { const $var: usize = 11; $body; } - { const $var: usize = 12; $body; } - { const $var: usize = 13; $body; } - { const $var: usize = 14; $body; } - { const $var: usize = 15; $body; } - { const $var: usize = 16; $body; } - { const $var: usize = 17; $body; } - { const $var: usize = 18; $body; } - { const $var: usize = 19; $body; } - { const $var: usize = 20; $body; } - { const $var: usize = 21; $body; } - { const $var: usize = 22; $body; } - { const $var: usize = 23; $body; } - }; -} - -#[cfg(feature = "no_unroll")] -macro_rules! unroll24 { - ($var:ident, $body:block) => { - for $var in 0..24 $body - } -} - #[allow(unused_assignments)] /// Keccak-f[1600] sponge function pub fn f1600(a: &mut [u64; PLEN]) { // not unrolling this loop results in a much smaller function, plus // it positively influences performance due to the smaller load on I-cache - for i in 0..24 { + for rc in &RC { let mut array = [0u64; 5]; // Theta @@ -179,6 +125,6 @@ pub fn f1600(a: &mut [u64; PLEN]) { }); // Iota - a[0] ^= RC[i]; + a[0] ^= rc; } } diff --git a/keccak/src/unroll.rs b/keccak/src/unroll.rs new file mode 100644 index 0000000..58a774f --- /dev/null +++ b/keccak/src/unroll.rs @@ -0,0 +1,58 @@ +#[cfg(not(feature = "no_unroll"))] +#[macro_export] +macro_rules! unroll5 { + ($var:ident, $body:block) => { + { const $var: usize = 0; $body; } + { const $var: usize = 1; $body; } + { const $var: usize = 2; $body; } + { const $var: usize = 3; $body; } + { const $var: usize = 4; $body; } + }; +} + +#[cfg(feature = "no_unroll")] +#[macro_export] +macro_rules! unroll5 { + ($var:ident, $body:block) => { + for $var in 0..5 $body + } +} + +#[cfg(not(feature = "no_unroll"))] +#[macro_export] +macro_rules! unroll24 { + ($var: ident, $body: block) => { + { const $var: usize = 0; $body; } + { const $var: usize = 1; $body; } + { const $var: usize = 2; $body; } + { const $var: usize = 3; $body; } + { const $var: usize = 4; $body; } + { const $var: usize = 5; $body; } + { const $var: usize = 6; $body; } + { const $var: usize = 7; $body; } + { const $var: usize = 8; $body; } + { const $var: usize = 9; $body; } + { const $var: usize = 10; $body; } + { const $var: usize = 11; $body; } + { const $var: usize = 12; $body; } + { const $var: usize = 13; $body; } + { const $var: usize = 14; $body; } + { const $var: usize = 15; $body; } + { const $var: usize = 16; $body; } + { const $var: usize = 17; $body; } + { const $var: usize = 18; $body; } + { const $var: usize = 19; $body; } + { const $var: usize = 20; $body; } + { const $var: usize = 21; $body; } + { const $var: usize = 22; $body; } + { const $var: usize = 23; $body; } + }; +} + +#[cfg(feature = "no_unroll")] +#[macro_export] +macro_rules! unroll24 { + ($var:ident, $body:block) => { + for $var in 0..24 $body + } +} diff --git a/rustfmt.toml b/rustfmt.toml deleted file mode 100644 index 273a22e..0000000 --- a/rustfmt.toml +++ /dev/null @@ -1,8 +0,0 @@ -max_width = 80 -force_explicit_abi = false -fn_single_line = true -fn_args_density = "Compressed" -match_block_trailing_comma = true -normalize_comments = false -imports_indent = "Block" -where_single_line = true \ No newline at end of file