/rust/registry/src/index.crates.io-6f17d22bba15001f/sha2-0.10.9/src/sha512.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use digest::{generic_array::GenericArray, typenum::U128}; |
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) fn compress(state: &mut [u64; 8], blocks: &[[u8; 128]]) { |
16 | | sha2_asm::compress512(state, blocks); |
17 | | } |
18 | | } |
19 | | mod x86; |
20 | | use x86::compress; |
21 | | } else if #[cfg(all(feature = "asm", target_arch = "aarch64"))] { |
22 | | mod soft; |
23 | | mod aarch64; |
24 | | use aarch64::compress; |
25 | | } else if #[cfg(all(feature = "loongarch64_asm", target_arch = "loongarch64"))] { |
26 | | mod loongarch64_asm; |
27 | | use loongarch64_asm::compress; |
28 | | } else { |
29 | | mod soft; |
30 | | use soft::compress; |
31 | | } |
32 | | } |
33 | | |
34 | | /// Raw SHA-512 compression function. |
35 | | /// |
36 | | /// This is a low-level "hazmat" API which provides direct access to the core |
37 | | /// functionality of SHA-512. |
38 | | #[cfg_attr(docsrs, doc(cfg(feature = "compress")))] |
39 | 0 | pub fn compress512(state: &mut [u64; 8], blocks: &[GenericArray<u8, U128>]) { |
40 | 0 | // SAFETY: GenericArray<u8, U64> and [u8; 64] have |
41 | 0 | // exactly the same memory layout |
42 | 0 | let p = blocks.as_ptr() as *const [u8; 128]; |
43 | 0 | let blocks = unsafe { core::slice::from_raw_parts(p, blocks.len()) }; |
44 | 0 | compress(state, blocks) |
45 | 0 | } |