Coverage Report

Created: 2026-07-13 08:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/blake3-1.8.4/src/ffi_sse2.rs
Line
Count
Source
1
use crate::{CVWords, IncrementCounter, BLOCK_LEN, OUT_LEN};
2
3
// Unsafe because this may only be called on platforms supporting SSE2.
4
0
pub unsafe fn compress_in_place(
5
0
    cv: &mut CVWords,
6
0
    block: &[u8; BLOCK_LEN],
7
0
    block_len: u8,
8
0
    counter: u64,
9
0
    flags: u8,
10
0
) {
11
    unsafe {
12
0
        ffi::blake3_compress_in_place_sse2(
13
0
            cv.as_mut_ptr(),
14
0
            block.as_ptr(),
15
0
            block_len,
16
0
            counter,
17
0
            flags,
18
        )
19
    }
20
0
}
21
22
// Unsafe because this may only be called on platforms supporting SSE2.
23
0
pub unsafe fn compress_xof(
24
0
    cv: &CVWords,
25
0
    block: &[u8; BLOCK_LEN],
26
0
    block_len: u8,
27
0
    counter: u64,
28
0
    flags: u8,
29
0
) -> [u8; 64] {
30
    unsafe {
31
0
        let mut out = [0u8; 64];
32
0
        ffi::blake3_compress_xof_sse2(
33
0
            cv.as_ptr(),
34
0
            block.as_ptr(),
35
0
            block_len,
36
0
            counter,
37
0
            flags,
38
0
            out.as_mut_ptr(),
39
        );
40
0
        out
41
    }
42
0
}
43
44
// Unsafe because this may only be called on platforms supporting SSE2.
45
0
pub unsafe fn hash_many<const N: usize>(
46
0
    inputs: &[&[u8; N]],
47
0
    key: &CVWords,
48
0
    counter: u64,
49
0
    increment_counter: IncrementCounter,
50
0
    flags: u8,
51
0
    flags_start: u8,
52
0
    flags_end: u8,
53
0
    out: &mut [u8],
54
0
) {
55
    unsafe {
56
        // The Rust hash_many implementations do bounds checking on the `out`
57
        // array, but the C implementations don't. Even though this is an unsafe
58
        // function, assert the bounds here.
59
0
        assert!(out.len() >= inputs.len() * OUT_LEN);
60
0
        ffi::blake3_hash_many_sse2(
61
0
            inputs.as_ptr() as *const *const u8,
62
0
            inputs.len(),
63
0
            N / BLOCK_LEN,
64
0
            key.as_ptr(),
65
0
            counter,
66
0
            increment_counter.yes(),
67
0
            flags,
68
0
            flags_start,
69
0
            flags_end,
70
0
            out.as_mut_ptr(),
71
        )
72
    }
73
0
}
Unexecuted instantiation: blake3::sse2::hash_many::<1024>
Unexecuted instantiation: blake3::sse2::hash_many::<64>
74
75
pub mod ffi {
76
    unsafe extern "C" {
77
        pub fn blake3_compress_in_place_sse2(
78
            cv: *mut u32,
79
            block: *const u8,
80
            block_len: u8,
81
            counter: u64,
82
            flags: u8,
83
        );
84
        pub fn blake3_compress_xof_sse2(
85
            cv: *const u32,
86
            block: *const u8,
87
            block_len: u8,
88
            counter: u64,
89
            flags: u8,
90
            out: *mut u8,
91
        );
92
        pub fn blake3_hash_many_sse2(
93
            inputs: *const *const u8,
94
            num_inputs: usize,
95
            blocks: usize,
96
            key: *const u32,
97
            counter: u64,
98
            increment_counter: bool,
99
            flags: u8,
100
            flags_start: u8,
101
            flags_end: u8,
102
            out: *mut u8,
103
        );
104
    }
105
}
106
107
#[cfg(test)]
108
mod test {
109
    use super::*;
110
111
    #[test]
112
    fn test_compress() {
113
        if !crate::platform::sse2_detected() {
114
            return;
115
        }
116
        crate::test::test_compress_fn(compress_in_place, compress_xof);
117
    }
118
119
    #[test]
120
    fn test_hash_many() {
121
        if !crate::platform::sse2_detected() {
122
            return;
123
        }
124
        crate::test::test_hash_many_fn(hash_many, hash_many);
125
    }
126
}