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 both **canic** (runtime layer) and **mimic**
8//! (framework layer) for tasks that require uniform and reproducible hashing
9//! such as:
10//! - routing / sharding decisions,
11//! - cache keys or internal identifiers,
12//! - stable yet non-secure fingerprinting of data.
13//!
14//! ✅ Extremely fast (optimized for 64-bit architectures)
15//! ✅ Deterministic across replicas and platforms
16//! ⚠️ Not cryptographically secure — do not use for signatures or certified data
17//!
18//! Reference: <https://cyan4973.github.io/xxHash/>
19//!
20use xxhash_rust::xxh3::{xxh3_64, xxh3_128};
21
22pub use xxhash_rust::xxh3::Xxh3;
23
24/// Return a u64 hash from the provided bytes using the xxh3 hash algorithm.
25#[must_use]
26pub fn hash_u64(bytes: &[u8]) -> u64 {
27 xxh3_64(bytes)
28}
29
30/// Return a u128 hash from the provided bytes using the xxh3 hash algorithm.
31#[must_use]
32pub fn hash_u128(bytes: &[u8]) -> u128 {
33 xxh3_128(bytes)
34}