Skip to content

Commit

Permalink
fix rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
SymmetricChaos committed Oct 16, 2024
1 parent 8edf347 commit 212b95f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
25 changes: 13 additions & 12 deletions ciphers/src/digital/block_ciphers/rc2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ fn mix_round_inv(state: &mut [u16; 4], key: &[u16], j: &mut usize) {
}

fn mash_round(state: &mut [u16; 4], key: &[u16]) {
state[0] = state[0].wrapping_add(key[state[3] as usize] & 63);
state[1] = state[1].wrapping_add(key[state[0] as usize] & 63);
state[2] = state[2].wrapping_add(key[state[1] as usize] & 63);
state[3] = state[3].wrapping_add(key[state[2] as usize] & 63);
state[0] = state[0].wrapping_add(key[state[3] as usize & 63]);
state[1] = state[1].wrapping_add(key[state[0] as usize & 63]);
state[2] = state[2].wrapping_add(key[state[1] as usize & 63]);
state[3] = state[3].wrapping_add(key[state[2] as usize & 63]);
}

fn mash_round_inv(state: &mut [u16; 4], key: &[u16]) {
state[3] = state[3].wrapping_add(key[state[2] as usize] & 63);
state[2] = state[2].wrapping_add(key[state[1] as usize] & 63);
state[1] = state[1].wrapping_add(key[state[0] as usize] & 63);
state[0] = state[0].wrapping_add(key[state[3] as usize] & 63);
state[3] = state[3].wrapping_add(key[state[2] as usize & 63]);
state[2] = state[2].wrapping_add(key[state[1] as usize & 63]);
state[1] = state[1].wrapping_add(key[state[0] as usize & 63]);
state[0] = state[0].wrapping_add(key[state[3] as usize & 63]);
}

pub struct Rc2 {
Expand Down Expand Up @@ -224,7 +224,8 @@ crate::impl_cipher_for_block_cipher!(Rc2, 8);

// }

// crate::test_block_cipher!(
// test_1, Rc2::default(),

// );
crate::test_block_cipher!(
test_1, Rc2::default().with_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
[0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff];
);
16 changes: 16 additions & 0 deletions ciphers/src/ids/cipher_descriptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,22 @@
"Polyalphabetic"
]
},
"RC2": {
"Names": [
"RC2",
"Rivest Cipher 2",
"ARC2",
"ARCTWO",
"Alleged RC2"
],
"Description": "RC2 (Rivest Cipher 2) is an early digital block cipher created by Ronald Rivest in 1987.",
"Authors": "Ronald Rivest",
"Publication": "1987",
"Traits": [
"Block Cipher",
"Feistel"
]
},
"RC4": {
"Names": [
"RC4",
Expand Down

0 comments on commit 212b95f

Please sign in to comment.