1use digest::{generic_array::GenericArray, typenum::U128};
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) fn compress(state: &mut [u64; 8], blocks: &[[u8; 128]]) {
13 sha2_asm::compress512(state, blocks);
14 }
15 }
16 mod x86;
17 use x86::compress;
18 } else if #[cfg(all(feature = "asm", target_arch = "aarch64"))] {
19 mod soft;
20 mod aarch64;
21 use aarch64::compress;
22 } else {
23 mod soft;
24 use soft::compress;
25 }
26}
27
28/// Raw SHA-512 compression function.
29///
30/// This is a low-level "hazmat" API which provides direct access to the core
31/// functionality of SHA-512.
32#[cfg_attr(docsrs, doc(cfg(feature = "compress")))]
33pub fn compress512(state: &mut [u64; 8], blocks: &[GenericArray<u8, U128>]) {
34 // SAFETY: GenericArray<u8, U64> and [u8; 64] have
35 // exactly the same memory layout
36 let p: *const [u8; 128] = blocks.as_ptr() as *const [u8; 128];
37 let blocks: &[[u8; 128]] = unsafe { core::slice::from_raw_parts(data:p, blocks.len()) };
38 compress(state, blocks)
39}
40