#digest #xx-hash #hash #xxh3 #fnv

noncrypto-digests

Implement Digest trait for non-cryptographic hashing functions like fnv and xxhash

5 releases

0.3.2 Jun 19, 2024
0.3.1 Dec 21, 2023
0.2.3 Dec 20, 2023
0.1.0 Dec 8, 2023

#1058 in Cryptography

Download history 48/week @ 2024-08-07 138/week @ 2024-08-14 42/week @ 2024-08-21 48/week @ 2024-08-28 65/week @ 2024-09-04 177/week @ 2024-09-11 90/week @ 2024-09-18 114/week @ 2024-09-25 61/week @ 2024-10-02 71/week @ 2024-10-09 152/week @ 2024-10-16 91/week @ 2024-10-23 64/week @ 2024-10-30 92/week @ 2024-11-06 173/week @ 2024-11-13 229/week @ 2024-11-20

558 downloads per month
Used in 2 crates (via sqlite-hashes)

MIT/Apache

15KB
263 lines

noncrypto-digests

GitHub crates.io version docs.rs docs crates.io version CI build

Implement digest::Digest trait for non-cryptographic hashing functions like fnv and xxhash. This allows users to use all cryptographic and non-cryptographic hashing functions polymorphically.

Usage

use digest::Digest;
use hex::ToHex;
use noncrypto_digests::{Fnv, Xxh3_64, Xxh3_128, Xxh32, Xxh64};

/// This function takes any Digest type, and returns a hex-encoded string.
pub fn hash<T: Digest>(data: impl AsRef<[u8]>) -> String {
    // Note that some hashers provide seed value set to 0 by default.
    // Use `...::from_hasher(hasher)` function to instantiate them.
    let mut hasher = T::new();
    hasher.update(data);
    hasher.finalize().to_vec().encode_hex_upper()
}

assert_eq!(hash::<Fnv>("password"), "4B1A493507B3A318");
assert_eq!(hash::<Xxh3_64>("password"), "336576D7E0E06F9A");
assert_eq!(hash::<Xxh3_128>("password"), "9CFA9055952177DA0B120BE86072A8F0");
assert_eq!(hash::<Xxh32>("password"), "106C6CED");
assert_eq!(hash::<Xxh64>("password"), "90007DAF3980EF1F");

Development

  • This project is easier to develop with just, a modern alternative to make. Install it with cargo install just.
  • To get a list of available commands, run just.
  • To run tests, use just test.
  • On git push, it will run a few validations, including cargo fmt, cargo clippy, and cargo test. Use git push --no-verify to skip these checks.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~285–380KB