pub fn find_counter_range(
mode: Mode<'_>,
template: &[u8],
counter_word: usize,
start: u32,
count: u64,
mask: u32,
target: u32,
matches: &mut [(u32, [u8; 32])],
) -> usizeExpand description
Search count consecutive 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(off as u32) for
off in 0..count, for digests whose first little-endian 32-bit word
word0 = u32::from_le_bytes(digest[..4]) satisfies
(word0 & mask) == target.
Matching (counter, digest) pairs are written to matches[..n] in
ascending search-offset order and the count n <= matches.len() is
returned. On AVX-512, AVX2, Apple/AArch64 SME2, and AArch64 NEON,
non-matching groups evaluate the predicate without writing digests to
output RAM and exit early as soon as matches is filled. If count > 2^32,
the 32-bit counter wraps and revisits earlier counter values.
Timing note: because this search stops early once matches is full, its
runtime depends on which counters satisfy the predicate; use it for public
nonce grinding and proof-of-work predicates rather than secret-dependent
searches.
Panics if template.len() > BLOCK_LEN, counter_word >= 16, or
counter_word * 4 + 4 > template.len() (checked in every build, even
when count == 0 or matches is empty).
ยงExample
use blake3_servil_core::{Mode, convenience, throughput};
let mut template = [0u8; 52];
template[..48].fill(0x2a);
let mut hits = [(0u32, [0u8; 32]); 1];
let found = throughput::find_counter_range(Mode::Plain, &template, 12, 0, 1024, 0x0000_000f, 0, &mut hits);
assert_eq!(found, 1);
template[48..52].copy_from_slice(&hits[0].0.to_le_bytes());
assert_eq!(hits[0].1, *convenience::hash(&template).as_bytes());
assert_eq!(u32::from_le_bytes(hits[0].1[..4].try_into().unwrap()) & 0xf, 0);