diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/sha2/src/sha256.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/sha2/src/sha256.rs')
-rw-r--r-- | third_party/rust/sha2/src/sha256.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/third_party/rust/sha2/src/sha256.rs b/third_party/rust/sha2/src/sha256.rs new file mode 100644 index 0000000000..a45331e17a --- /dev/null +++ b/third_party/rust/sha2/src/sha256.rs @@ -0,0 +1,37 @@ +use digest::{generic_array::GenericArray, typenum::U64}; + +cfg_if::cfg_if! { + if #[cfg(feature = "force-soft")] { + mod soft; + use soft::compress; + } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { + #[cfg(not(feature = "asm"))] + mod soft; + #[cfg(feature = "asm")] + mod soft { + pub(crate) use sha2_asm::compress256 as compress; + } + mod x86; + use x86::compress; + } else if #[cfg(all(feature = "asm", target_arch = "aarch64"))] { + mod soft; + mod aarch64; + use aarch64::compress; + } else { + mod soft; + use soft::compress; + } +} + +/// Raw SHA-256 compression function. +/// +/// This is a low-level "hazmat" API which provides direct access to the core +/// functionality of SHA-256. +#[cfg_attr(docsrs, doc(cfg(feature = "compress")))] +pub fn compress256(state: &mut [u32; 8], blocks: &[GenericArray<u8, U64>]) { + // SAFETY: GenericArray<u8, U64> and [u8; 64] have + // exactly the same memory layout + let p = blocks.as_ptr() as *const [u8; 64]; + let blocks = unsafe { core::slice::from_raw_parts(p, blocks.len()) }; + compress(state, blocks) +} |