libsodium_crypto_hash_sha512 (libsodium v3.0.1)
View SourceSHA-512, producing bytes/0 byte digests, either in one shot or
incrementally.
The streaming functions thread an opaque state/0 through init/0, update/2, and final/1; each call returns a
new state and leaves its argument unchanged. Updates over large inputs
yield to other processes between chunks.
SHA-2 is vulnerable to length extension attacks; unless SHA-512 is
required for interoperability, prefer libsodium_crypto_generichash.
Digest = libsodium_crypto_hash_sha512:crypto_hash_sha512(<<"hello world">>),
64 = byte_size(Digest),
State0 = libsodium_crypto_hash_sha512:init(),
State1 = libsodium_crypto_hash_sha512:update(State0, <<"hello ">>),
State2 = libsodium_crypto_hash_sha512:update(State1, <<"world">>),
Digest = libsodium_crypto_hash_sha512:final(State2).
Summary
Functions
Return crypto_hash_sha512_bytes(), in bytes.
Hash In, returning a bytes/0 byte digest.
Finish the streaming hash in State, returning a bytes/0 byte digest.
Start a streaming hash, returning a statebytes/0 byte state.
Return crypto_hash_sha512_statebytes(), in bytes.
Absorb In into State and return the updated state.
Types
-type out() :: <<_:512>>.
A crypto_hash_sha512_BYTES (64-byte) binary.
-type state() :: libsodium_nif:crypto_hash_sha512_state().
An opaque native crypto_hash_sha512_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 :: 64.
Return crypto_hash_sha512_bytes(), in bytes.
Hash In, returning a bytes/0 byte digest.
Finish the streaming hash in State, returning a bytes/0 byte digest.
-spec init() -> Result when Result :: state() | -1.
Start a streaming hash, returning a statebytes/0 byte state.
-spec statebytes() -> Result when Result :: 208.
Return crypto_hash_sha512_statebytes(), in bytes.
Absorb In into State and return the updated state.