Skip to main content

hash_counter_range

Function hash_counter_range 

Source
pub fn hash_counter_range(
    mode: Mode<'_>,
    template: &[u8],
    counter_word: usize,
    start: u32,
    out: &mut [[u8; 32]],
)
Expand description

Hash out.len() single-block messages derived from template (4..=64 bytes) in mode, replacing the 4-byte little-endian word at byte offset counter_word * 4 with start.wrapping_add(i) (modulo 2^32) for i in 0..out.len().

On AVX-512, AVX2, Apple/AArch64 SME2, and AArch64 NEON, full SIMD groups broadcast the template once into registers or L1 stack storage and advance only the counter word between groups, avoiding caller-side buffer stamping and input memory traffic in proof-of-work and counter-grinding loops; any remaining tail hashes serially.

Panics if template.len() > BLOCK_LEN, counter_word >= 16, or counter_word * 4 + 4 > template.len() (checked in every build, even when out is empty).

ยงExample

use blake3_servil_core::{Mode, convenience, throughput};
let mut template = [0u8; 52];
template[..48].fill(0xab);
let mut digests = [[0u8; 32]; 16];
throughput::hash_counter_range(Mode::Plain, &template, 12, 100, &mut digests);
template[48..52].copy_from_slice(&103u32.to_le_bytes());
assert_eq!(digests[3], *convenience::hash(&template).as_bytes());