libsodium_crypto_generichash (libsodium v3.0.1)
View SourceGeneric hashing with BLAKE2b, optionally keyed.
The one-shot crypto_generichash/1,2,3 functions hash a complete input.
The streaming functions thread an opaque state/0 through init/0,1,2, update/2, and final/1,2; each call returns a
new state and leaves its argument unchanged. Updates over large inputs
yield to other processes between chunks.
Output lengths must be between bytes_min/0 and bytes_max/0; keys may
be empty or between keybytes_min/0 and keybytes_max/0 bytes.
Digest = libsodium_crypto_generichash:crypto_generichash(<<"hello world">>),
State0 = libsodium_crypto_generichash:init(),
State1 = libsodium_crypto_generichash:update(State0, <<"hello ">>),
State2 = libsodium_crypto_generichash:update(State1, <<"world">>),
Digest = libsodium_crypto_generichash:final(State2).
Summary
Functions
Return crypto_generichash_bytes(), in bytes.
Return crypto_generichash_bytes_max(), in bytes.
Return crypto_generichash_bytes_min(), in bytes.
Hash In with the optional Key, producing Outlen bytes.
Hash In with the optional Key, producing Outlen bytes.
Hash In with the optional Key, producing Outlen bytes.
Start a streaming hash with the optional Key that will produce
Outlen bytes. Defaults to bytes/0 bytes of output and no key.
Start a streaming hash with the optional Key that will produce
Outlen bytes. Defaults to bytes/0 bytes of output and no key.
Start a streaming hash with the optional Key that will produce
Outlen bytes. Defaults to bytes/0 bytes of output and no key.
Return crypto_generichash_keybytes(), in bytes.
Return crypto_generichash_keybytes_max(), in bytes.
Return crypto_generichash_keybytes_min(), in bytes.
Generate a random keybytes/0 byte key.
Return crypto_generichash_primitive() as an atom.
Return crypto_generichash_statebytes(), in bytes.
Absorb In into State and return the updated state.
Types
-type k() :: <<_:256>>.
A crypto_generichash_KEYBYTES (32-byte) binary.
-type state() :: libsodium_nif:crypto_generichash_state().
An opaque native crypto_generichash_state.
Operations never modify a state: each returns a new one, so earlier states remain valid and can be reused or shared between processes. States cannot be serialized; they exist only within the running VM.
Functions
-spec bytes() -> Result when Result :: 32.
Return crypto_generichash_bytes(), in bytes.
-spec bytes_max() -> Result when Result :: 64.
Return crypto_generichash_bytes_max(), in bytes.
-spec bytes_min() -> Result when Result :: 16.
Return crypto_generichash_bytes_min(), in bytes.
Hash In with the optional Key, producing Outlen bytes.
Defaults to bytes/0 bytes of output and no key.
-spec crypto_generichash(In, Key) -> Result when In :: binary(), Key :: binary(), Result :: binary() | -1.
Hash In with the optional Key, producing Outlen bytes.
Defaults to bytes/0 bytes of output and no key.
-spec crypto_generichash(Outlen, In, Key) -> Result when Outlen :: 16..64, In :: binary(), Key :: binary(), Result :: binary() | -1.
Hash In with the optional Key, producing Outlen bytes.
Defaults to bytes/0 bytes of output and no key.
Finish the streaming hash in State, producing Outlen bytes. The
length must match the one passed to init/2 (default bytes/0).
-spec final(State, Outlen) -> Result when State :: state(), Outlen :: 16..64, Result :: binary() | -1.
Finish the streaming hash in State, producing Outlen bytes. The
length must match the one passed to init/2 (default bytes/0).
-spec init() -> Result when Result :: state() | -1.
Start a streaming hash with the optional Key that will produce
Outlen bytes. Defaults to bytes/0 bytes of output and no key.
Start a streaming hash with the optional Key that will produce
Outlen bytes. Defaults to bytes/0 bytes of output and no key.
Start a streaming hash with the optional Key that will produce
Outlen bytes. Defaults to bytes/0 bytes of output and no key.
-spec keybytes() -> Result when Result :: 32.
Return crypto_generichash_keybytes(), in bytes.
-spec keybytes_max() -> Result when Result :: 64.
Return crypto_generichash_keybytes_max(), in bytes.
-spec keybytes_min() -> Result when Result :: 16.
Return crypto_generichash_keybytes_min(), in bytes.
-spec keygen() -> Result when Result :: k().
Generate a random keybytes/0 byte key.
-spec primitive() -> Result when Result :: blake2b.
Return crypto_generichash_primitive() as an atom.
-spec statebytes() -> Result when Result :: 384.
Return crypto_generichash_statebytes(), in bytes.
Absorb In into State and return the updated state.