libsodium_crypto_hash_sha256 (libsodium v3.0.1)
View SourceSHA-256, 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-256 is
required for interoperability, prefer libsodium_crypto_generichash.
Digest = libsodium_crypto_hash_sha256:crypto_hash_sha256(<<"hello world">>),
32 = byte_size(Digest),
State0 = libsodium_crypto_hash_sha256:init(),
State1 = libsodium_crypto_hash_sha256:update(State0, <<"hello ">>),
State2 = libsodium_crypto_hash_sha256:update(State1, <<"world">>),
Digest = libsodium_crypto_hash_sha256:final(State2).
Summary
Functions
Return crypto_hash_sha256_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_sha256_statebytes(), in bytes.
Absorb In into State and return the updated state.
Types
-type out() :: <<_:256>>.
A crypto_hash_sha256_BYTES (32-byte) binary.
-type state() :: libsodium_nif:crypto_hash_sha256_state().
An opaque native crypto_hash_sha256_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_hash_sha256_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 :: 104.
Return crypto_hash_sha256_statebytes(), in bytes.
Absorb In into State and return the updated state.