Coverage Report

Created: 2026-01-22 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sha3-0.10.8/src/state.rs
Line
Count
Source
1
use core::convert::TryInto;
2
3
const PLEN: usize = 25;
4
const DEFAULT_ROUND_COUNT: usize = 24;
5
6
#[derive(Clone)]
7
pub(crate) struct Sha3State {
8
    pub state: [u64; PLEN],
9
    round_count: usize,
10
}
11
12
impl Default for Sha3State {
13
70.1k
    fn default() -> Self {
14
70.1k
        Self {
15
70.1k
            state: [0u64; PLEN],
16
70.1k
            round_count: DEFAULT_ROUND_COUNT,
17
70.1k
        }
18
70.1k
    }
19
}
20
21
impl Sha3State {
22
0
    pub(crate) fn new(round_count: usize) -> Self {
23
0
        Self {
24
0
            state: [0u64; PLEN],
25
0
            round_count,
26
0
        }
27
0
    }
28
29
    #[inline(always)]
30
113k
    pub(crate) fn absorb_block(&mut self, block: &[u8]) {
31
113k
        debug_assert_eq!(block.len() % 8, 0);
32
33
2.04M
        for (b, s) in block.chunks_exact(8).zip(self.state.iter_mut()) {
34
2.04M
            *s ^= u64::from_le_bytes(b.try_into().unwrap());
35
2.04M
        }
36
37
113k
        keccak::p1600(&mut self.state, self.round_count);
38
113k
    }
39
40
    #[inline(always)]
41
148k
    pub(crate) fn as_bytes(&self, out: &mut [u8]) {
42
2.88M
        for (o, s) in out.chunks_mut(8).zip(self.state.iter()) {
43
2.88M
            o.copy_from_slice(&s.to_le_bytes()[..o.len()]);
44
2.88M
        }
45
148k
    }
46
47
    #[inline(always)]
48
140k
    pub(crate) fn permute(&mut self) {
49
140k
        keccak::p1600(&mut self.state, self.round_count);
50
140k
    }
51
}