From 02b23813bf45af9f6acf46b3a2f0995ad2be9b8f Mon Sep 17 00:00:00 2001 From: ashWhiteHat Date: Sun, 9 Jul 2023 12:03:41 +0900 Subject: [PATCH] rc6: fix clippy and add github actions --- .github/workflows/rc6.yml | 59 +++++++++++++++++++++++++++++++++++++++ rc6/src/core/backend.rs | 4 +-- 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/rc6.yml diff --git a/.github/workflows/rc6.yml b/.github/workflows/rc6.yml new file mode 100644 index 00000000..9e664306 --- /dev/null +++ b/.github/workflows/rc6.yml @@ -0,0 +1,59 @@ +name: rc6 +on: + pull_request: + paths: + - "rc6/**" + - "Cargo.*" + push: + branches: master + +defaults: + run: + working-directory: rc6 + +env: + CARGO_INCREMENTAL: 0 + RUSTFLAGS: "-Dwarnings" + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - 1.56.0 # MSRV + - stable + target: + - thumbv7em-none-eabi + - wasm32-unknown-unknown + steps: + - uses: actions/checkout@v3 + - uses: RustCrypto/actions/cargo-cache@master + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + targets: ${{ matrix.target }} + - run: cargo build --no-default-features --release --target ${{ matrix.target }} + + minimal-versions: + uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master + with: + working-directory: ${{ github.workflow }} + + test: + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - 1.56.0 # MSRV + - stable + steps: + - uses: actions/checkout@v3 + - uses: RustCrypto/actions/cargo-cache@master + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + - run: cargo check --all-features + - run: cargo test --no-default-features + - run: cargo test + - run: cargo test --all-features diff --git a/rc6/src/core/backend.rs b/rc6/src/core/backend.rs index 929901b0..675d9d86 100644 --- a/rc6/src/core/backend.rs +++ b/rc6/src/core/backend.rs @@ -140,7 +140,7 @@ where pub fn encrypt(&self, mut block: InOut<'_, '_, Block>) { let (mut a, mut b, mut c, mut d) = Self::words_from_block(block.get_in()); let key = &self.key_table; - let log_w = W::from((W::Bytes::USIZE as f64 * 8 as f64).log2() as u8); + let log_w = W::from((usize::BITS - 1 - (W::Bytes::USIZE * 8).leading_zeros()) as u8); b = b.wrapping_add(key[0]); d = d.wrapping_add(key[1]); @@ -170,7 +170,7 @@ where pub fn decrypt(&self, mut block: InOut<'_, '_, Block>) { let (mut a, mut b, mut c, mut d) = Self::words_from_block(block.get_in()); let key = &self.key_table; - let log_w = W::from((W::Bytes::USIZE as f64 * 8 as f64).log2() as u8); + let log_w = W::from((usize::BITS - 1 - (W::Bytes::USIZE * 8).leading_zeros()) as u8); c = c.wrapping_sub(key[2 * R::USIZE + 3]); a = a.wrapping_sub(key[2 * R::USIZE + 2]);