/src/spdm-rs/external/ring/src/aead/chacha/ffi.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2016-2025 Brian Smith. |
2 | | // |
3 | | // Permission to use, copy, modify, and/or distribute this software for any |
4 | | // purpose with or without fee is hereby granted, provided that the above |
5 | | // copyright notice and this permission notice appear in all copies. |
6 | | // |
7 | | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
8 | | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
9 | | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
10 | | // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
11 | | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
12 | | // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
13 | | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
14 | | |
15 | | use super::{super::overlapping::Overlapping, Counter, Key}; |
16 | | |
17 | | // `unsafe { (N, C, InOut) => f }` means that the function `f` is safe to call |
18 | | // iff the in/out length is at least `N`, the CPU features `C` are available, |
19 | | // and the input type is `InOut`. If `f` supports overlapping input/output then |
20 | | // `InOut` should be `Overlapping<'_, u8>`; otherwise it should be `&mut [u8]`. |
21 | | macro_rules! chacha20_ctr32_ffi { |
22 | | ( unsafe { ($MIN_LEN:expr, $Cpu:ty, $InOut:ty) => $f:ident }, |
23 | | $key:expr, $counter:expr, $in_out:expr, $cpu:expr ) => {{ |
24 | | prefixed_extern! { |
25 | | fn $f( |
26 | | out: *mut u8, |
27 | | in_: *const u8, |
28 | | in_len: crate::c::size_t, |
29 | | key: &[u32; 8], |
30 | | counter: &crate::aead::chacha::Counter, |
31 | | ); |
32 | | } |
33 | | // SAFETY: The user asserts that $f has the signature above and is safe |
34 | | // to call if additionally we have a value of type `$Cpu` and an in/out |
35 | | // value of the indicated type, which we do. |
36 | | unsafe { |
37 | | crate::aead::chacha::ffi::chacha20_ctr32_ffi::<$InOut, $Cpu, $MIN_LEN>( |
38 | | $key, $counter, $in_out, $cpu, $f, |
39 | | ) |
40 | | } |
41 | | }}; |
42 | | } |
43 | | |
44 | | // Panics if `in_out.len() < MIN_LEN`. The caller should have guarded against |
45 | | // that so that the assertion gets optimized away. |
46 | 0 | pub(super) unsafe fn chacha20_ctr32_ffi< |
47 | 0 | 'o, |
48 | 0 | InOut: 'o + Into<Overlapping<'o, u8>>, |
49 | 0 | Cpu, |
50 | 0 | const MIN_LEN: usize, |
51 | 0 | >( |
52 | 0 | key: &Key, |
53 | 0 | counter: Counter, |
54 | 0 | in_out: InOut, |
55 | 0 | cpu: Cpu, |
56 | 0 | f: unsafe extern "C" fn(*mut u8, *const u8, crate::c::size_t, &[u32; 8], &Counter), |
57 | 0 | ) { |
58 | 0 | assert!(MIN_LEN > 0); |
59 | 0 | let in_out: Overlapping<'_, u8> = in_out.into(); |
60 | 0 | in_out.with_input_output_len(|input, output, len| { |
61 | 0 | assert!(len >= MIN_LEN); |
62 | 0 | let key = key.words_less_safe(); |
63 | 0 | let _: Cpu = cpu; |
64 | 0 | unsafe { f(output, input, len, key, &counter) } |
65 | 0 | }); Unexecuted instantiation: ring::aead::chacha::ffi::chacha20_ctr32_ffi::<ring::aead::overlapping::base::Overlapping<u8>, ring::cpu::intel::Avx2, 129>::{closure#0} Unexecuted instantiation: ring::aead::chacha::ffi::chacha20_ctr32_ffi::<ring::aead::overlapping::base::Overlapping<u8>, ring::cpu::intel::Ssse3, 129>::{closure#0} Unexecuted instantiation: ring::aead::chacha::ffi::chacha20_ctr32_ffi::<ring::aead::overlapping::base::Overlapping<u8>, (), 1>::{closure#0} |
66 | 0 | } Unexecuted instantiation: ring::aead::chacha::ffi::chacha20_ctr32_ffi::<ring::aead::overlapping::base::Overlapping<u8>, ring::cpu::intel::Avx2, 129> Unexecuted instantiation: ring::aead::chacha::ffi::chacha20_ctr32_ffi::<ring::aead::overlapping::base::Overlapping<u8>, ring::cpu::intel::Ssse3, 129> Unexecuted instantiation: ring::aead::chacha::ffi::chacha20_ctr32_ffi::<ring::aead::overlapping::base::Overlapping<u8>, (), 1> |