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::{DefaultGenericHash, Key};
// The key type must be specified because `None` does not identify it.
let hash = DefaultGenericHash::hash_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::{DefaultGenericHash, Key};
// The key type must be specified because `None` does not identify it.
let mut hasher = DefaultGenericHash::new::<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="
);Modules§
- protected
protected - Protected memory type aliases for
GenericHash
Structs§
- Generic
Hash - Provides a generic hash function implementation based on Blake2b. Compatible with libsodium’s generic hash.
Type Aliases§
- Default
Generic Hash GenericHashwith libsodium’s recommended key length (CRYPTO_GENERICHASH_KEYBYTES) and output length (CRYPTO_GENERICHASH_BYTES).- Hash
- Stack-allocated hash output of the recommended output length.
- Key
- Stack-allocated secret key for use with the generic hash algorithm.