MCPcopy Create free account
hub / github.com/BitVM/BitVM / chunk_message

Function chunk_message

bitvm/src/hash/blake3.rs:223–238  ·  view source on GitHub ↗

Transforms the given message into a format that BLAKE3 understands.

(message_bytes: &[u8])

Source from the content-addressed store, hash-verified

221
222/// Transforms the given message into a format that BLAKE3 understands.
223fn chunk_message(message_bytes: &[u8]) -> Vec<[u8; 64]> {
224 let len = message_bytes.len();
225 let needed_padding_bytes = if len % 64 == 0 { 0 } else { 64 - (len % 64) };
226
227 message_bytes
228 .iter()
229 .copied()
230 .chain(std::iter::repeat_n(0u8, needed_padding_bytes))
231 .chunks(4) // reverse 4-byte chunks
232 .into_iter()
233 .flat_map(|chunk| chunk.collect::<Vec<u8>>().into_iter().rev())
234 .chunks(64) // collect 64-byte chunks
235 .into_iter()
236 .map(|mut chunk| std::array::from_fn(|_| chunk.next().unwrap()))
237 .collect()
238}
239
240/// Returns a script that pushes the given message onto the stack for BLAKE3.
241///

Callers 1

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected