AHSAH
ahsah is a small Rust hashing crate built around incremental digest contexts.
Supported algorithms:
Md5Sha224Sha256Sha384Sha512
The crate includes:
- typed digest contexts with
new,update,finalize,finalize_hex, anddigest - raw digest bytes via
DigestBytes - reader helpers for hashing
Readstreams - compatibility shims for the legacy
HashBuilderAPI - optional SIMD-assisted block decoding through the
simdfeature
Installation
[]
= "2.0.0"
Optional features:
args: enablesclap-based example argument parsing helperssimd: enables optional SIMD-assisted block decoding on supportedx86/x86_64CPUs, with scalar fallback everywhere else
Quick Start
One-shot hashing
use Sha256;
Incremental hashing
use ;
Hashing any Read
use ;
use Cursor;
Raw digest bytes
use Sha224;
Legacy Compatibility
The older builder API is still available during the transition:
use HashBuilder;
The deprecated ahsah::hashes::HashBuilder path also continues to work.
Examples
Run the examples with:
cargo run --example string-hasher -- "hello"
cargo run --example stdin-hasher
cargo run --example reader-hasher --features args -- --algo sha256 --file ./res/test.txt
cargo run --example file-hasher --features args -- --algo sha512 --file ./res/test.txt
Algorithms accepted by the args feature examples:
md5sha224sha256sha384sha512
Notes on SIMD
The simd feature is optional and conservative:
- scalar implementations remain the canonical fallback
- current SIMD work accelerates block word decoding on supported
x86/x86_64CPUs - digest outputs are covered by parity tests against the scalar path
Testing
cargo test --tests --lib
cargo test --tests --lib --features simd
cargo test --examples --features args
Benchmarks
Criterion benchmarks live in benches/digest_benchmarks.rs.
They currently cover:
Md5,Sha224,Sha256,Sha384, andSha512- one-shot hashing and incremental chunked hashing
- input sizes
0,64,1024, and16 KiB
Run them with:
cargo bench --bench digest_benchmarks
cargo bench --bench digest_benchmarks --features simd