| 1 | use crate::{CVWords, IncrementCounter, BLOCK_LEN, OUT_LEN}; |
| 2 | |
| 3 | // Note that there is no AVX2 implementation of compress_in_place or |
| 4 | // compress_xof. |
| 5 | |
| 6 | // Unsafe because this may only be called on platforms supporting AVX2. |
| 7 | pub unsafe fn hash_many<const N: usize>( |
| 8 | inputs: &[&[u8; N]], |
| 9 | key: &CVWords, |
| 10 | counter: u64, |
| 11 | increment_counter: IncrementCounter, |
| 12 | flags: u8, |
| 13 | flags_start: u8, |
| 14 | flags_end: u8, |
| 15 | out: &mut [u8], |
| 16 | ) { |
| 17 | // The Rust hash_many implementations do bounds checking on the `out` |
| 18 | // array, but the C implementations don't. Even though this is an unsafe |
| 19 | // function, assert the bounds here. |
| 20 | assert!(out.len() >= inputs.len() * OUT_LEN); |
| 21 | ffi::blake3_hash_many_avx2( |
| 22 | inputs.as_ptr() as *const *const u8, |
| 23 | num_inputs:inputs.len(), |
| 24 | N / BLOCK_LEN, |
| 25 | key.as_ptr(), |
| 26 | counter, |
| 27 | increment_counter.yes(), |
| 28 | flags, |
| 29 | flags_start, |
| 30 | flags_end, |
| 31 | out.as_mut_ptr(), |
| 32 | ) |
| 33 | } |
| 34 | |
| 35 | pub mod ffi { |
| 36 | unsafeextern "C" { |
| 37 | pub unsafefn blake3_hash_many_avx2( |
| 38 | inputs: *const *const u8, |
| 39 | num_inputs: usize, |
| 40 | blocks: usize, |
| 41 | key: *const u32, |
| 42 | counter: u64, |
| 43 | increment_counter: bool, |
| 44 | flags: u8, |
| 45 | flags_start: u8, |
| 46 | flags_end: u8, |
| 47 | out: *mut u8, |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | #[cfg (test)] |
| 53 | mod test { |
| 54 | use super::*; |
| 55 | |
| 56 | #[test ] |
| 57 | fn test_hash_many() { |
| 58 | if !crate::platform::avx2_detected() { |
| 59 | return; |
| 60 | } |
| 61 | crate::test::test_hash_many_fn(hash_many, hash_many); |
| 62 | } |
| 63 | } |
| 64 | |