tape-sha256
Pure-Rust, hardware-accelerated SHA-256 for batch hashing and iterated hash chains.
tape-sha256 provides two kinds of hashing:
- Batch hashing processes many independent messages in parallel, one per SIMD lane. This is useful for Merkle trees, data verification, and other workloads that hash many inputs at once.
- Hash chains repeatedly hash a 32-byte digest, either as one serial chain or as many independent chains in parallel. This is useful for workloads such as Solana proof-of-history verification.
The crate automatically selects the best implementation available on the running CPU, with portable fallbacks for unsupported targets.
Installation
[]
= "0.2"
Batch hashing
Use hash_many to hash a group of independent messages:
use hash_many;
let messages: = vec!;
let mut digests = vec!;
hash_many;
When every message shares a prefix, hash_many_prefixed hashes
prefix || body without allocating or copying the concatenated inputs:
use hash_many_prefixed;
let leaves: = vec!;
let mut digests = vec!;
hash_many_prefixed;
For Merkle-tree parent nodes, hash_pairs similarly hashes
prefix || left || right without constructing temporary buffers.
Hash chains
Use hash_chain when each digest becomes the input to the next hash:
use hash_chain;
let seed = ;
let end = hash_chain;
When several chains are independent, hash_chains runs them in parallel:
use hash_chains;
let seeds = ;
let lengths = ;
let mut ends = ;
hash_chains;
Hardware acceleration
At runtime, tape-sha256 selects an implementation for the current platform,
including AVX-512, AVX2, SHA-NI, ARM SHA-2, NEON, WebAssembly SIMD, and portable
Rust backends.
The scalar, avx2, avx512, and neon Cargo features pin a backend at
compile time. A pinned backend must be supported by every CPU that runs the
binary; the default runtime selection is safer for general-purpose builds.
Use backend() and lane_width() to inspect the selected batch backend, or
chain_backend() to inspect the single-chain backend.
Performance and correctness
See BENCHMARKS.md for measurements, hardware-specific analysis, and methodology. WebAssembly results are documented in benches/wasm/README.md.
Every available backend is tested against the independent sha2 crate across
message lengths covering block and padding boundaries. Run the test suite with:
License
Apache-2.0