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

Update Clippy and fix lints #378

Merged
merged 1 commit into from
Aug 7, 2023
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
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.63.0
toolchain: 1.71.0
components: clippy
- run: cargo clippy --all --exclude aes --all-features -- -D warnings

Expand Down
18 changes: 9 additions & 9 deletions cast5/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn rfc2144_b1() {
let ct40 = GenericArray::from(hex!("7AC816D16E9B302E"));
let pt = GenericArray::from(hex!("0123456789ABCDEF"));

let mut buf = pt.clone();
let mut buf = pt;

let c = Cast5::new_from_slice(&key128).unwrap();
c.encrypt_block(&mut buf);
Expand Down Expand Up @@ -50,25 +50,25 @@ fn full_maintance_test() {
let (al, ar) = a.split_at_mut(8);
let (bl, br) = b.split_at_mut(8);

let mut al = GenericArray::from_mut_slice(al);
let mut ar = GenericArray::from_mut_slice(ar);
let al = GenericArray::from_mut_slice(al);
let ar = GenericArray::from_mut_slice(ar);

let mut bl = GenericArray::from_mut_slice(bl);
let mut br = GenericArray::from_mut_slice(br);
let bl = GenericArray::from_mut_slice(bl);
let br = GenericArray::from_mut_slice(br);

for _ in 0..count {
let mut k = GenericArray::from([0u8; 16]);
k[..8].copy_from_slice(bl);
k[8..].copy_from_slice(br);
let c = Cast5::new(&k);
c.encrypt_block(&mut al);
c.encrypt_block(&mut ar);
c.encrypt_block(al);
c.encrypt_block(ar);

k[..8].copy_from_slice(al);
k[8..].copy_from_slice(ar);
let c = Cast5::new(&k);
c.encrypt_block(&mut bl);
c.encrypt_block(&mut br);
c.encrypt_block(bl);
c.encrypt_block(br);
}

assert_eq!(&al[..], &verify_a[..8]);
Expand Down
2 changes: 1 addition & 1 deletion des/src/des.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn round(input: u64, key: u64) -> u64 {
}

fn f(input: u64, key: u64) -> u64 {
let mut val = e(input as u64);
let mut val = e(input);
val ^= key;
val = apply_sboxes(val);
p(val)
Expand Down
4 changes: 2 additions & 2 deletions kuznyechik/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ fn kuznyechik() {
});
}

let mut blocks2 = blocks.clone();
let blocks_cpy = blocks.clone();
let mut blocks2 = blocks;
let blocks_cpy = blocks;

cipher.encrypt_blocks(&mut blocks);
assert!(blocks[..] != blocks_cpy[..]);
Expand Down
2 changes: 1 addition & 1 deletion rc2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Rc2 {
}

fn expand_key(key: &[u8], t1: usize) -> [u16; 64] {
let key_len = key.len() as usize;
let key_len = key.len();

let t8: usize = (t1 + 7) >> 3;

Expand Down
2 changes: 1 addition & 1 deletion rc2/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro_rules! new_tests {
fn rc2() {
let tests = new_tests!("1", "2", "3", "7");
for test in &tests {
let cipher = rc2::Rc2::new_from_slice(&test.key).unwrap();
let cipher = rc2::Rc2::new_from_slice(test.key).unwrap();

let mut buf = GenericArray::clone_from_slice(test.input);
cipher.encrypt_block(&mut buf);
Expand Down
9 changes: 3 additions & 6 deletions serpent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,16 @@ impl Serpent {
let mut k = [0u32; 132];
for i in 0..r {
let sbox_index = (ROUNDS + 3 - i) % ROUNDS;
let a = words[(4 * i) as usize];
let b = words[(4 * i + 1) as usize];
let c = words[(4 * i + 2) as usize];
let d = words[(4 * i + 3) as usize];
let [a, b, c, d]: [u32; 4] = words[4 * i..][..4].try_into().unwrap();
// calculate keys in bitslicing mode
for j in 0..32 {
let input = get_bit(a as usize, j)
| get_bit(b as usize, j) << 1
| get_bit(c as usize, j) << 2
| get_bit(d as usize, j) << 3;
let output = apply_s(sbox_index, input as u8);
let output = apply_s(sbox_index, input);
for l in 0..4 {
k[(4 * i + l) as usize] |= u32::from(get_bit(output as usize, l)) << j;
k[4 * i + l] |= u32::from(get_bit(output as usize, l)) << j;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions sm4/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use sm4::Sm4;
#[test]
fn sm4_example_1() {
let key = hex!("0123456789abcdeffedcba9876543210");
let plaintext = key.clone();
let plaintext = key;
let ciphertext = hex!("681EDF34D206965E86B3E94F536E4246");
let cipher = Sm4::new(&key.into());

let mut block = plaintext.clone().into();
let mut block = plaintext.into();
cipher.encrypt_block(&mut block);

assert_eq!(&ciphertext, block.as_slice());
Expand All @@ -23,12 +23,12 @@ fn sm4_example_1() {
#[test]
fn sm4_example_2() {
let key = hex!("0123456789abcdeffedcba9876543210");
let plaintext = key.clone();
let plaintext = key;
let ciphertext = hex!("595298c7c6fd271f0402f804c33d3f66");

let cipher = Sm4::new(&key.into());

let mut block = plaintext.clone().into();
let mut block = plaintext.into();
for _ in 0..1_000_000 {
cipher.encrypt_block(&mut block);
}
Expand Down