Coverage Report

Created: 2026-06-10 07:04

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