interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / sha2 / src / sha256.rs

43 lines · 1460 bytes Raw Blame History
1use digest::{generic_array::GenericArray, typenum::U64};
2
3cfg_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")))]
37pub fn compress256(state: &mut [u32; 8], blocks: &[GenericArray<u8, U64>]) {
38 // SAFETY: GenericArray<u8, U64> and [u8; 64] have
39 // exactly the same memory layout
40 let p = blocks.as_ptr() as *const [u8; 64];
41 let blocks = unsafe { core::slice::from_raw_parts(p, blocks.len()) };
42 compress(state, blocks)
43}