From 703b6f2fe26c0c5387d1b3e82b46f50be86888a4 Mon Sep 17 00:00:00 2001 From: Guilleag01 Date: Sat, 7 Mar 2026 11:25:19 +0100 Subject: [PATCH] Revert "Merge branch 'master' of github.com:Guilleag01/sha3" This reverts commit c344498fb62b4455a404c5aa7073218c1dfb5df2, reversing changes made to 315b85b2f525112b02a7927085f23c4a50d5e7d2. --- src/consts.rs | 31 ------------------------------- src/sha3.rs | 26 ++++++++++++-------------- 2 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/consts.rs b/src/consts.rs index a9d6f7f..d769441 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -256,34 +256,3 @@ pub const LFSR_LUT: [(bool, u8); 256] = [ (false, 0x8d), (true, 0x8f), ]; - -pub const R_TABLE: [usize; 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, -]; - -pub const XOR_TABLE: [u64; 24] = [ - 0x1, - 0x8083, - 0x8000000000000009, - 0x80008009, - 0x80000082, - 0x83, - 0x8000000080008002, - 0x8000000b, - 0x80000081, - 0x80000009, - 0x8000, - 0x8000800a, - 0x81, - 0x800000000000000a, - 0x8083, - 0x8000000000000080, - 0x8082, - 0x8000000000008002, - 0x8000000000000008, - 0x80000002, - 0x8000000000008083, - 0x3, - 0x80000002, - 0x800000000000800a, -]; diff --git a/src/sha3.rs b/src/sha3.rs index a65a080..41edbdc 100644 --- a/src/sha3.rs +++ b/src/sha3.rs @@ -3,7 +3,7 @@ use std::array; -use crate::consts::*; +use crate::consts::LFSR_LUT; const RATE_256: usize = 136; const TOTAL_STATE_SIZE: usize = 200; @@ -82,11 +82,11 @@ fn keccak_permute(input: &mut [u8; TOTAL_STATE_SIZE]) { for _ in 0..ROUNDS { // θ step let c: [u64; 5] = array::from_fn(|x| { - get_lane(lanes, x, 0) - ^ get_lane(lanes, x, 1) - ^ get_lane(lanes, x, 2) - ^ get_lane(lanes, x, 3) - ^ get_lane(lanes, x, 4) + get_lane2(lanes, x, 0) + ^ get_lane2(lanes, x, 1) + ^ get_lane2(lanes, x, 2) + ^ get_lane2(lanes, x, 3) + ^ get_lane2(lanes, x, 4) }); let mut d: u64; @@ -95,13 +95,13 @@ fn keccak_permute(input: &mut [u8; TOTAL_STATE_SIZE]) { d = c[(x + 4) % 5] ^ rol64(c[(x + 1) % 5], 1); for y in 0..5 { - xor_lane(d, lanes, x, y); + xor_lane2(d, lanes, x, y); } } // ρ and π steps let (mut x, mut y) = (1, 0); - let mut current = get_lane(lanes, x, y); + let mut current = get_lane2(lanes, x, y); let mut temp: u64; for t in 0..24 { @@ -110,8 +110,8 @@ fn keccak_permute(input: &mut [u8; TOTAL_STATE_SIZE]) { x = y; y = y2; - temp = get_lane(lanes, x, y); - set_lane(rol64(current, r), x, y, lanes); + temp = get_lane2(lanes, x, y); + set_lane2(rol64(current, r), x, y, lanes); current = temp; } @@ -119,7 +119,7 @@ fn keccak_permute(input: &mut [u8; TOTAL_STATE_SIZE]) { for y in 0..5 { let temp2: [u64; 5] = array::from_fn(|x| get_lane2(lanes, x, y)); for x in 0..5 { - set_lane( + set_lane2( temp2[x] ^ ((!temp2[(x + 1) % 5]) & temp2[(x + 2) % 5]), x, y, @@ -130,8 +130,8 @@ fn keccak_permute(input: &mut [u8; TOTAL_STATE_SIZE]) { // ι step - // println!("aaaa"); for j in 0..7 { + let bit_pos: usize = (1 << j) - 1; let (lfsr_out, new_lfsr) = LFSR_LUT[lfsr_state as usize]; lfsr_state = new_lfsr; @@ -139,8 +139,6 @@ fn keccak_permute(input: &mut [u8; TOTAL_STATE_SIZE]) { xor_lane2((1_u64) << bit_pos, lanes, 0, 0); } } - // lanes[0] ^= XOR_TABLE[round]; - // println!("bbbb"); } }