MCPcopy Create free account
hub / github.com/RustCrypto/utils / squeeze_read_partial

Function squeeze_read_partial

sponge-cursor/src/u64_le_utils.rs:78–105  ·  view source on GitHub ↗
(
    state: &[u64; N],
    offset: usize,
    dst: &mut [u8],
)

Source from the content-addressed store, hash-verified

76
77#[inline(always)]
78pub(crate) fn squeeze_read_partial<const N: usize, const RATE: usize>(
79 state: &[u64; N],
80 offset: usize,
81 dst: &mut [u8],
82) {
83 const {
84 assert!(size_of::<[u8; RATE]>() <= size_of::<[u64; N]>());
85 assert!(RATE % size_of::<u64>() == 0);
86 };
87
88 let mut buf = [0u8; RATE];
89
90 let sub_state: &[u8; RATE] = if cfg!(target_endian = "little") {
91 // SAFETY: casting of `&[u64; N]` into `&[u8; M]` is safe if
92 // `size_of::<[u8; M]>() <= size_of::<[u64; N]>())`
93 unsafe { &*(state.as_ptr().cast::<[u8; RATE]>()) }
94 } else {
95 let mut chunks = buf.chunks_exact_mut(size_of::<u64>());
96 for (src, dst) in state.iter().zip(&mut chunks) {
97 dst.copy_from_slice(&src.to_le_bytes());
98 }
99 assert!(chunks.into_remainder().is_empty());
100 &buf
101 };
102
103 let src = &sub_state[offset..][..dst.len()];
104 dst.copy_from_slice(src);
105}
106
107#[inline(always)]
108pub(crate) fn squeeze_xor_full<const N: usize, const RATE: usize>(

Callers

nothing calls this directly

Calls 2

zipMethod · 0.80
lenMethod · 0.80

Tested by

no test coverage detected