#hash #hasher #deterministic

no-std deterministic-hash

Create deterministic hashes regardless of architecture

3 stable releases

1.0.2 Sep 24, 2025
1.0.1 Jul 12, 2021

#286 in Cryptography

Download history 1171/week @ 2025-06-30 1576/week @ 2025-07-07 1453/week @ 2025-07-14 816/week @ 2025-07-21 1442/week @ 2025-07-28 899/week @ 2025-08-04 1240/week @ 2025-08-11 1698/week @ 2025-08-18 1680/week @ 2025-08-25 1498/week @ 2025-09-01 1586/week @ 2025-09-08 1272/week @ 2025-09-15 1777/week @ 2025-09-22 1325/week @ 2025-09-29 727/week @ 2025-10-06 620/week @ 2025-10-13

4,457 downloads per month
Used in 7 crates (2 directly)

MIT license

6KB
66 lines

Tiny Rust library to create deterministic hashes regardless of architecture. This library is no-std compatible and uses no allocations or dependencies.

The default core::hash::Hasher implementation ensures a platform dependant hashing of datastructures that use #[derive(Hash)]. Most notably by:

  • using to_ne_bytes for u{8,16,32,64,128}.
  • using the native bytelength of usize.

The DeterministicHasher of this library forces the use of to_le_bytes and casts usize to u64 regardless of your platform. Hence the hasher will be less efficient, but will be deterministic when using the same library in different architecture contexts. I use a common dataprotocol library both on ARM embedded systems, wasm and x64.

From any hasher make it deterministic by inserting DeterministicHasher in between:

let hasher = crc::crc32::Digest::new(crc::crc32::KOOPMAN);
let hasher = deterministic_hash::DeterministicHasher::new(hasher);

deterministic-hash

Tiny Rust library to create deterministic hashes regardless of architecture. This library is no-std compatible and uses no allocations or dependencies.

The default core::hash::Hasher implementation ensures a platform dependant hashing of datastructures that use #[derive(Hash)]. Most notably by:

  • using to_ne_bytes for u{8,16,32,64,128}.
  • using the native bytelength of usize.

The DeterministicHasher of this library forces the use of to_le_bytes and casts usize to u64 regardless of your platform. Hence the hasher will be less efficient, but will be deterministic when using the same library in different architecture contexts. I use a common dataprotocol library both on ARM embedded systems, wasm and x64.

You can validate the operation of this library with cross by running:

cargo install cross
cross test --target=x86_64-unknown-linux-gnu
cross test --target=aarch64-unknown-linux-gnu
cross test --target=arm-unknown-linux-gnueabihf

No runtime deps