canic_utils/
hash.rs

1//!
2//! xxHash3 hashing utilities.
3//!
4//! These functions provide **fast, deterministic, non-cryptographic hashes**
5//! that work reliably on the Internet Computer.
6//!
7//! They are used across **canic** for tasks that require uniform and reproducible hashing
8//! such as:
9//!   - routing / sharding decisions,
10//!   - cache keys or internal identifiers,
11//!   - stable yet non-secure fingerprinting of data.
12//!
13//! ✅ Extremely fast (optimized for 64-bit architectures)
14//! ✅ Deterministic across replicas and platforms
15//! ⚠️ Not cryptographically secure — do not use for signatures or certified data
16//!
17//! Reference: <https://cyan4973.github.io/xxHash/>
18//!
19use xxhash_rust::xxh3::{xxh3_64, xxh3_128};
20
21pub use xxhash_rust::xxh3::Xxh3;
22
23/// Return a u64 hash from the provided bytes using the xxh3 hash algorithm.
24#[must_use]
25pub fn hash_u64(bytes: &[u8]) -> u64 {
26    xxh3_64(bytes)
27}
28
29/// Return a u128 hash from the provided bytes using the xxh3 hash algorithm.
30#[must_use]
31pub fn hash_u128(bytes: &[u8]) -> u128 {
32    xxh3_128(bytes)
33}