Debian Codegraph @

debian/rust-vendor/blake3/src/ffi_neon.rs

raw
1 use crate::{BLOCK_LEN, CVWords, IncrementCounter, OUT_LEN};
2
3 // Unsafe because this may only be called on platforms supporting NEON.
4 pub unsafe fn hash_many<const N: usize>(
5 inputs: &[&[u8; N]],
6 key: &CVWords,
7 counter: u64,
8 increment_counter: IncrementCounter,
9 flags: u8,
10 flags_start: u8,
11 flags_end: u8,
12 out: &mut [u8],
13 ) {
14 // The Rust hash_many implementations do bounds checking on the `out`
15 // array, but the C implementations don't. Even though this is an unsafe
16 // function, assert the bounds here.
17 assert!(out.len() >= inputs.len() * OUT_LEN);
18 unsafe {
19 ffi::blake3_hash_many_neon(
20 inputs.as_ptr() as *const *const u8,
21 inputs.len(),
22 N / BLOCK_LEN,
23 key.as_ptr(),
24 counter,
25 increment_counter.yes(),
26 flags,
27 flags_start,
28 flags_end,
29 out.as_mut_ptr(),
30 )
31 }
32 }
33
34 // blake3_neon.c normally depends on blake3_portable.c, because the NEON
35 // implementation only provides 4x compression, and it relies on the portable
36 // implementation for 1x compression. However, we expose the portable Rust
37 // implementation here instead, to avoid linking in unnecessary code.
38 #[unsafe(no_mangle)]
39 pub extern "C" fn blake3_compress_in_place_portable(
40 cv: *mut u32,
41 block: *const u8,
42 block_len: u8,
43 counter: u64,
44 flags: u8,
45 ) {
46 unsafe {
47 crate::portable::compress_in_place(
48 &mut *(cv as *mut [u32; 8]),
49 &*(block as *const [u8; 64]),
50 block_len,
51 counter,
52 flags,
53 )
54 }
55 }
56
57 pub mod ffi {
58 unsafe extern "C" {
59 pub fn blake3_hash_many_neon(
60 inputs: *const *const u8,
61 num_inputs: usize,
62 blocks: usize,
63 key: *const u32,
64 counter: u64,
65 increment_counter: bool,
66 flags: u8,
67 flags_start: u8,
68 flags_end: u8,
69 out: *mut u8,
70 );
71 }
72 }
73
74 #[cfg(test)]
75 mod test {
76 use super::*;
77
78 #[test]
79 fn test_hash_many() {
80 // This entire file is gated on feature="neon", so NEON support is
81 // assumed here.
82 crate::test::test_hash_many_fn(hash_many, hash_many);
83 }
84 }