aHash

A fast, DOS-resistant, AES-accelerated non-cryptographic hasher purpose-built for in-memory HashMaps

Library
Cargo
v0.8.12
1,342stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
48/100Fair
Development Activity0
Maintenance20
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture75
Code Quality68
Innovation78
Learning Curve80

aHash is a Rust hashing algorithm designed exclusively for in-memory hash maps and sets — it is not a cryptographic hash and is explicitly unsuitable for network protocols, persisted hash values, or anywhere a stable, verifiable digest is required. It uses hardware AES instructions where available to achieve very high throughput while remaining a keyed hash: each HashMap instance gets a randomized seed, so hash outputs can’t be predicted without knowing that seed, which is what gives it DOS resistance against hash-flooding attacks.

Because aHash has no fixed output specification, its internal algorithm can change between versions to improve speed or fix any discovered weakness, meaning hash values are not portable across machines or versions and should never be persisted or transmitted. It passes the full SMHasher test suite for statistical hash quality, and is notably the default hasher used internally by hashbrown (and therefore relevant to Rust’s std HashMap ecosystem via that dependency), making it one of the most widely-deployed hashers in the Rust ecosystem despite deliberately narrow intended use.

What You Get

  • A drop-in Hasher implementation plus AHashMap/AHashSet convenience wrappers around std collections
  • AES-hardware-accelerated hashing for high throughput on supported CPUs
  • Keyed, randomized hashing per HashMap instance to prevent hash-flooding DOS attacks
  • no_std-compatible builds and a compile-time-rng fallback for targets without runtime randomness
  • Optional serde support for the AHashMap/AHashSet wrapper types

Common Use Cases

  • Speeding up in-memory HashMap/HashSet-heavy Rust code where hashing overhead is a bottleneck
  • Protecting public-facing services from hash-collision DOS attacks via keyed, randomized hashing
  • Building on no_std or embedded targets that need a lightweight, allocation-free hasher
  • Underlying performance layer for other data-structure crates (e.g. hashbrown, which uses aHash by default)

Under The Hood

Architecture: aHash exposes an AHasher type implementing the standard library’s Hasher trait, combined with a RandomState type that generates a per-instance random seed so that HashMap<K, V, RandomState> (or the AHashMap/AHashSet wrappers) produce different hash outputs across different map instances — directly preventing the classic DoS pattern of feeding an application many keys engineered to collide under a fixed hash. Internally, the hash mixes input bytes using AES round instructions when the target CPU supports them, falling back to a portable non-AES implementation otherwise, with the exact algorithm treated as an implementation detail that may change between releases as faster or more DOS-resistant techniques are found.

Tech Stack: Nearly pure Rust (99.9% of tracked bytes), with feature flags for std (enables AHashMap/AHashSet, on by default), serde, runtime-rng (uses the getrandom crate for seeding, on by default), compile-time-rng (embeds compile-time-generated randomness for targets without OS randomness), and nightly-arm-aes for 32-bit ARM AES support. A no_std_test directory and smhasher subdirectory (containing the full SMHasher quality-test harness output) are checked directly into the repo.

Code Quality: Testing is comparatively lean for a widely-depended-upon crate — 3 test files under tests/ — but is supplemented by the checked-in SMHasher suite results demonstrating statistical hash-quality validation, and a compare/ directory benchmarking aHash against other hashers (FxHash, SipHash, etc.) with published performance charts in the README. With 45 contributors but 401 of the ~464 total commits from the single primary author, and zero recent commit velocity per the latest snapshot, this reads as a mature, feature-complete crate in low-churn maintenance mode rather than one under active development — consistent with a narrowly-scoped, already-optimized hashing primitive.

API Design: The library is designed as a true drop-in replacement — swapping std::collections::HashMap for HashMap<K, V, ahash::RandomState>, or using the AHashMap/AHashSet wrapper types, requires no other code changes, keeping adoption friction near zero. The README is explicit and prominent about aHash’s non-goals (not cryptographic, not for persisted/network hashes), which meaningfully reduces the risk of misuse despite the library exposing very few safety rails against it at the type level.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search