1use digest::{generic_array::GenericArray, typenum::U64};
2
3cfg_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 {
21 mod soft;
22 use soft::compress;
23 }
24}
25
26/// Raw SHA-256 compression function.
27///
28/// This is a low-level "hazmat" API which provides direct access to the core
29/// functionality of SHA-256.
30#[cfg_attr(docsrs, doc(cfg(feature = "compress")))]
31pub fn compress256(state: &mut [u32; 8], blocks: &[GenericArray<u8, U64>]) {
32 // SAFETY: GenericArray<u8, U64> and [u8; 64] have
33 // exactly the same memory layout
34 let p: *const [u8; 64] = blocks.as_ptr() as *const [u8; 64];
35 let blocks: &[[u8; 64]] = unsafe { core::slice::from_raw_parts(data:p, blocks.len()) };
36 compress(state, blocks)
37}
38