Skip to main content

Module generichash

Module generichash 

Source
Expand description

§Generic hashing

GenericHash implements libsodium’s generic hashing with BLAKE2b. Without a key, it produces a general-purpose cryptographic hash. With a secret key, it acts as a message authentication code (MAC) or pseudorandom function (PRF). Keyed BLAKE2b is not HMAC.

§Rustaceous API example, single-part interface

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

// The key type must be specified because `None` does not identify it.
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 as _;
use base64::engine::general_purpose;
use dryoc::generichash::{GenericHash, Key};

// The key type must be specified because `None` does not identify it.
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§

pub use crate::types::*;

Modules§

protectedprotected
Protected memory type aliases for GenericHash

Structs§

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

Type Aliases§

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