Transforms the given message into a format that BLAKE3 understands.
(message_bytes: &[u8])
| 221 | |
| 222 | /// Transforms the given message into a format that BLAKE3 understands. |
| 223 | fn 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 | /// |
no test coverage detected