Coverage Report

Created: 2025-12-31 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sha2-0.10.8/src/sha256.rs
Line
Count
Source
1
use digest::{generic_array::GenericArray, typenum::U64};
2
3
cfg_if::cfg_if! {
4
    if #[cfg(feature = "force-soft")] {
5
        mod soft;
6
        use soft::compress;
7
    } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
8
        #[cfg(not(feature = "asm"))]
9
        mod soft;
10
        #[cfg(feature = "asm")]
11
        mod soft {
12
            pub(crate) use sha2_asm::compress256 as compress;
13
        }
14
        mod x86;
15
        use x86::compress;
16
    } else if #[cfg(all(feature = "asm", target_arch = "aarch64"))] {
17
        mod soft;
18
        mod aarch64;
19
        use aarch64::compress;
20
    } else if #[cfg(all(feature = "loongarch64_asm", target_arch = "loongarch64"))] {
21
        mod loongarch64_asm;
22
        use loongarch64_asm::compress;
23
    } else {
24
        mod soft;
25
        use soft::compress;
26
    }
27
}
28
29
/// Raw SHA-256 compression function.
30
///
31
/// This is a low-level "hazmat" API which provides direct access to the core
32
/// functionality of SHA-256.
33
#[cfg_attr(docsrs, doc(cfg(feature = "compress")))]
34
1.10M
pub fn compress256(state: &mut [u32; 8], blocks: &[GenericArray<u8, U64>]) {
35
    // SAFETY: GenericArray<u8, U64> and [u8; 64] have
36
    // exactly the same memory layout
37
1.10M
    let p = blocks.as_ptr() as *const [u8; 64];
38
1.10M
    let blocks = unsafe { core::slice::from_raw_parts(p, blocks.len()) };
39
1.10M
    compress(state, blocks)
40
1.10M
}