sha1_asm/
lib.rs

1//! Assembly implementation of the [SHA-1] compression function.
2//!
3//! This crate is not intended for direct use, most users should
4//! prefer the [`sha-1`] crate with enabled `asm` feature instead.
5//!
6//! Only x86, x86-64, and AArch64 architectures are currently supported.
7//!
8//! [SHA-1]: https://en.wikipedia.org/wiki/SHA-1
9//! [`sha-1`]: https://crates.io/crates/sha-1
10
11#![no_std]
12#[cfg(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64")))]
13compile_error!("crate can only be used on x86, x86_64 and AArch64 architectures");
14
15#[cfg(target_os = "windows")]
16compile_error!("crate does not support Windows targets");
17
18#[link(name = "sha1", kind = "static")]
19extern "C" {
20    fn sha1_compress(state: &mut [u32; 5], block: &[u8; 64]);
21}
22
23/// Safe wrapper around assembly implementation of SHA-1 compression function
24#[inline]
25pub fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
26    for block in blocks {
27        unsafe {
28            sha1_compress(state, block);
29        }
30    }
31}