Coverage Report

Created: 2025-08-29 06:30

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