Module dryoc::generichash

source ·
Expand description

Generic hashing

GenericHash implements libsodium’s generic hashing, based on the Blake2b algorithm. Can also be used as an HMAC function, if a key is provided.

Rustaceous API example, one-time interface

use base64::engine::general_purpose;
use base64::Engine as _;
use dryoc::generichash::{GenericHash, Key};

// NOTE: The type for `key` param must be specified, the compiler cannot infer it when
// we pass `None`.
let hash =
    GenericHash::hash_with_defaults_to_vec::<_, Key>(b"hello", None).expect("hash failed");

assert_eq!(
    general_purpose::STANDARD.encode(&hash),
    "Mk3PAn3UowqTLEQfNlol6GsXPe+kuOWJSCU0cbgbcs8="
);

Rustaceous API example, incremental interface

use base64::engine::general_purpose;
use base64::Engine as _;
use dryoc::generichash::{GenericHash, Key};

// The compiler cannot infer the `Key` type, so we pass it below.
let mut hasher = GenericHash::new_with_defaults::<Key>(None).expect("new failed");
hasher.update(b"hello");
let hash = hasher.finalize_to_vec().expect("finalize failed");

assert_eq!(
    general_purpose::STANDARD.encode(&hash),
    "Mk3PAn3UowqTLEQfNlol6GsXPe+kuOWJSCU0cbgbcs8="
);

Re-exports

Modules

Structs

  • Provides a generic hash function implementation based on Blake2b. Compatible with libsodium’s generic hash.

Type Aliases

  • Stack-allocated hash output of the recommended output length.
  • Stack-allocated secret key for use with the generic hash algorithm.