apple_cryptokit/hashing/
sha1.rs1use super::HashFunction;
4
5pub const SHA1_OUTPUT_SIZE: usize = 20;
7
8extern "C" {
10 #[link_name = "sha1_hash"]
11 fn swift_sha1_hash(data: *const u8, length: i32, out_hash: *mut u8);
12}
13
14pub fn sha1_hash(data: &[u8]) -> [u8; 20] {
16 let mut output = [0u8; 20];
17 sha1_hash_to(data, &mut output);
18 output
19}
20
21pub fn sha1_hash_to(data: &[u8], output: &mut [u8]) {
29 assert!(
30 output.len() >= SHA1_OUTPUT_SIZE,
31 "Output buffer too small: {} < {}",
32 output.len(),
33 SHA1_OUTPUT_SIZE
34 );
35 unsafe {
36 swift_sha1_hash(data.as_ptr(), data.len() as i32, output.as_mut_ptr());
37 }
38}
39
40pub struct SHA1;
42
43impl HashFunction for SHA1 {
44 const OUTPUT_SIZE: usize = SHA1_OUTPUT_SIZE;
45
46 fn hash_to(data: &[u8], output: &mut [u8]) {
47 sha1_hash_to(data, output)
48 }
49}
50
51pub use SHA1 as Sha1Algorithm;