ring/digest/sha2/
sha2_32.rs1use super::{BlockLen, CHAINING_WORDS};
16use crate::{cpu, polyfill::slice::AsChunks};
17use cfg_if::cfg_if;
18use core::num::Wrapping;
19
20pub(in super::super) const SHA256_BLOCK_LEN: BlockLen = BlockLen::_512;
21
22pub type State32 = [Wrapping<u32>; CHAINING_WORDS];
23
24pub(crate) fn block_data_order_32(
25 state: &mut State32,
26 data: AsChunks<u8, { SHA256_BLOCK_LEN.into() }>,
27 cpu: cpu::Features,
28) {
29 cfg_if! {
30 if #[cfg(all(target_arch = "aarch64", target_endian = "little"))] {
31 use cpu::{GetFeature as _, arm::Sha256};
32 if let Some(cpu) = cpu.get_feature() {
33 sha2_32_ffi!(unsafe { Sha256 => sha256_block_data_order_hw }, state, data, cpu)
34 } else {
35 sha2_32_ffi!(unsafe { () => sha256_block_data_order_nohw }, state, data, ())
36 }
37 } else if #[cfg(all(target_arch = "arm", target_endian = "little"))] {
38 use cpu::{GetFeature as _, arm::Neon};
39 if let Some(cpu) = cpu.get_feature() {
40 sha2_32_ffi!(unsafe { Neon => sha256_block_data_order_neon }, state, data, cpu)
41 } else {
42 sha2_32_ffi!(unsafe { () => sha256_block_data_order_nohw }, state, data, ())
43 }
44 } else if #[cfg(target_arch = "x86_64")] {
45 use cpu::{GetFeature as _, intel::{Avx, IntelCpu, Sha, Ssse3 }};
46 let cpu = cpu.values();
47 if let Some(cpu) = cpu.get_feature() {
48 sha2_32_ffi!(unsafe { (Sha, Ssse3) => sha256_block_data_order_hw }, state, data, cpu)
49 } else if let Some(cpu) = cpu.get_feature() {
50 sha2_32_ffi!(unsafe { (Avx, IntelCpu) => sha256_block_data_order_avx }, state, data, cpu)
53 } else if let Some(cpu) = cpu.get_feature() {
54 sha2_32_ffi!(unsafe { Ssse3 => sha256_block_data_order_ssse3 }, state, data, cpu)
55 } else {
56 sha2_32_ffi!(unsafe { () => sha256_block_data_order_nohw }, state, data, ())
57 }
58 } else {
59 let _ = cpu; *state = super::fallback::block_data_order(*state, data)
61 }
62 }
63}