1use crate::{Block, BlockSizeUser, Sha1Core};
2use digest::typenum::Unsigned;
3
4cfg_if::cfg_if! {
5 if #[cfg(feature = "force-soft")] {
6 mod soft;
7 use soft::compress as compress_inner;
8 } else if #[cfg(all(feature = "asm", target_arch = "aarch64"))] {
9 mod soft;
10 mod aarch64;
11 use aarch64::compress as compress_inner;
12 } else if #[cfg(all(feature = "loongarch64_asm", target_arch = "loongarch64"))] {
13 mod loongarch64_asm;
14 use loongarch64_asm::compress as compress_inner;
15 } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
16 #[cfg(not(feature = "asm"))]
17 mod soft;
18 #[cfg(feature = "asm")]
19 mod soft {
20 pub use sha1_asm::compress;
21 }
22 mod x86;
23 use x86::compress as compress_inner;
24 } else {
25 mod soft;
26 use soft::compress as compress_inner;
27 }
28}
29
30const BLOCK_SIZE: usize = <Sha1Core as BlockSizeUser>::BlockSize::USIZE;
31
32/// SHA-1 compression function
33#[cfg_attr(docsrs, doc(cfg(feature = "compress")))]
34pub fn compress(state: &mut [u32; 5], blocks: &[Block<Sha1Core>]) {
35 // SAFETY: GenericArray<u8, U64> and [u8; 64] have
36 // exactly the same memory layout
37 let blocks: &[[u8; BLOCK_SIZE]] =
38 unsafe { &*(blocks as *const _ as *const [[u8; BLOCK_SIZE]]) };
39 compress_inner(state, blocks);
40}
41