Skip to content

Commit

Permalink
Fix new Clippy lints (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Jul 29, 2024
1 parent d1b7596 commit 4ae792e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.71.0
toolchain: 1.80.0
components: clippy
- run: cargo clippy --all --exclude aes --all-features -- -D warnings

Expand Down
2 changes: 1 addition & 1 deletion aes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
//!
//! - `aes_force_soft`: force software implementation.
//! - `aes_compact`: reduce code size at the cost of slower performance
//! (affects only software backend).
//! (affects only software backend).
//!
//! It can be enabled using `RUSTFLAGS` environmental variable
//! (e.g. `RUSTFLAGS="--cfg aes_compact"`) or by modifying `.cargo/config`.
Expand Down
25 changes: 13 additions & 12 deletions aes/src/ni/aes192.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ macro_rules! expand_round {
}};
}

macro_rules! shuffle {
($a:expr, $b:expr, $imm:expr) => {
mem::transmute::<_, __m128i>(_mm_shuffle_pd(mem::transmute($a), mem::transmute($b), $imm))
};
#[inline(always)]
unsafe fn shuffle(a: __m128i, b: __m128i, i: usize) -> __m128i {
let a: [u64; 2] = mem::transmute(a);
let b: [u64; 2] = mem::transmute(b);
mem::transmute([a[i], b[0]])
}

#[inline]
Expand All @@ -144,31 +145,31 @@ pub(super) unsafe fn expand_key(key: &[u8; 24]) -> RoundKeys {
keys[0] = k0;

let (k1_2, k2r) = expand_round!(k0, k1l, 0x01);
keys[1] = shuffle!(k1l, k1_2, 0);
keys[2] = shuffle!(k1_2, k2r, 1);
keys[1] = shuffle(k1l, k1_2, 0);
keys[2] = shuffle(k1_2, k2r, 1);

let (k3, k4l) = expand_round!(k1_2, k2r, 0x02);
keys[3] = k3;

let (k4_5, k5r) = expand_round!(k3, k4l, 0x04);
let k4 = shuffle!(k4l, k4_5, 0);
let k5 = shuffle!(k4_5, k5r, 1);
let k4 = shuffle(k4l, k4_5, 0);
let k5 = shuffle(k4_5, k5r, 1);
keys[4] = k4;
keys[5] = k5;

let (k6, k7l) = expand_round!(k4_5, k5r, 0x08);
keys[6] = k6;

let (k7_8, k8r) = expand_round!(k6, k7l, 0x10);
keys[7] = shuffle!(k7l, k7_8, 0);
keys[8] = shuffle!(k7_8, k8r, 1);
keys[7] = shuffle(k7l, k7_8, 0);
keys[8] = shuffle(k7_8, k8r, 1);

let (k9, k10l) = expand_round!(k7_8, k8r, 0x20);
keys[9] = k9;

let (k10_11, k11r) = expand_round!(k9, k10l, 0x40);
keys[10] = shuffle!(k10l, k10_11, 0);
keys[11] = shuffle!(k10_11, k11r, 1);
keys[10] = shuffle(k10l, k10_11, 0);
keys[11] = shuffle(k10_11, k11r, 1);

let (k12, _) = expand_round!(k10_11, k11r, 0x80);
keys[12] = k12;
Expand Down
4 changes: 2 additions & 2 deletions des/src/des.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ impl Des {
for key in &self.keys {
data = round(data, *key);
}
fp((data << 32) | (data >> 32))
fp(data.rotate_right(32))
}

pub(crate) fn decrypt(&self, mut data: u64) -> u64 {
data = ip(data);
for key in self.keys.iter().rev() {
data = round(data, *key);
}
fp((data << 32) | (data >> 32))
fp(data.rotate_right(32))
}
}

Expand Down
2 changes: 1 addition & 1 deletion gift/benches/gift128enc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use criterion_cycles_per_byte::CyclesPerByte;
use gift_cipher::cipher::{BlockEncrypt, KeyInit};
use gift_cipher::cipher::{BlockCipherEncrypt, KeyInit};
use gift_cipher::Gift128;

const KB: usize = 1024;
Expand Down
16 changes: 8 additions & 8 deletions rc2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,28 @@ impl Rc2 {
.wrapping_add(r[3] & r[2])
.wrapping_add(!r[3] & r[1]);
*j += 1;
r[0] = (r[0] << 1) | (r[0] >> 15);
r[0] = r[0].rotate_left(1);

r[1] = r[1]
.wrapping_add(self.keys[*j])
.wrapping_add(r[0] & r[3])
.wrapping_add(!r[0] & r[2]);
*j += 1;
r[1] = (r[1] << 2) | (r[1] >> 14);
r[1] = r[1].rotate_left(2);

r[2] = r[2]
.wrapping_add(self.keys[*j])
.wrapping_add(r[1] & r[0])
.wrapping_add(!r[1] & r[3]);
*j += 1;
r[2] = (r[2] << 3) | (r[2] >> 13);
r[2] = r[2].rotate_left(3);

r[3] = r[3]
.wrapping_add(self.keys[*j])
.wrapping_add(r[2] & r[1])
.wrapping_add(!r[2] & r[0]);
*j += 1;
r[3] = (r[3] << 5) | (r[3] >> 11);
r[3] = r[3].rotate_left(5);
}

fn mash(&self, r: &mut [u16; 4]) {
Expand All @@ -115,28 +115,28 @@ impl Rc2 {
}

fn reverse_mix(&self, r: &mut [u16; 4], j: &mut usize) {
r[3] = (r[3] << 11) | (r[3] >> 5);
r[3] = r[3].rotate_right(5);
r[3] = r[3]
.wrapping_sub(self.keys[*j])
.wrapping_sub(r[2] & r[1])
.wrapping_sub(!r[2] & r[0]);
*j -= 1;

r[2] = (r[2] << 13) | (r[2] >> 3);
r[2] = r[2].rotate_right(3);
r[2] = r[2]
.wrapping_sub(self.keys[*j])
.wrapping_sub(r[1] & r[0])
.wrapping_sub(!r[1] & r[3]);
*j -= 1;

r[1] = (r[1] << 14) | (r[1] >> 2);
r[1] = r[1].rotate_right(2);
r[1] = r[1]
.wrapping_sub(self.keys[*j])
.wrapping_sub(r[0] & r[3])
.wrapping_sub(!r[0] & r[2]);
*j -= 1;

r[0] = (r[0] << 15) | (r[0] >> 1);
r[0] = r[0].rotate_right(1);
r[0] = r[0]
.wrapping_sub(self.keys[*j])
.wrapping_sub(r[3] & r[2])
Expand Down

0 comments on commit 4ae792e

Please sign in to comment.