libsodium_crypto_hash_sha3256 (libsodium v3.0.1)

View Source

SHA3-256 (FIPS 202), 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.

Unlike SHA-2, SHA-3 is not vulnerable to length extension attacks. Use it when SHA-3 is required for interoperability; otherwise libsodium_crypto_generichash is faster.

Digest = libsodium_crypto_hash_sha3256:crypto_hash_sha3256(<<"hello world">>),
32 = byte_size(Digest),
State0 = libsodium_crypto_hash_sha3256:init(),
State1 = libsodium_crypto_hash_sha3256:update(State0, <<"hello ">>),
State2 = libsodium_crypto_hash_sha3256:update(State1, <<"world">>),
Digest = libsodium_crypto_hash_sha3256:final(State2).

Summary

Types

A crypto_hash_sha3256_BYTES (32-byte) binary.

An opaque native crypto_hash_sha3256_state.

Functions

Return crypto_hash_sha3256_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 its state.

Return crypto_hash_sha3256_statebytes(), in bytes.

Absorb In into State and return the updated state.

Types

out()

-type out() :: <<_:256>>.

A crypto_hash_sha3256_BYTES (32-byte) binary.

state()

An opaque native crypto_hash_sha3256_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

bytes()

-spec bytes() -> Result when Result :: 32.

Return crypto_hash_sha3256_bytes(), in bytes.

crypto_hash_sha3256(In)

-spec crypto_hash_sha3256(In) -> Result when In :: binary(), Result :: out() | -1.

Hash In, returning a bytes/0 byte digest.

final(State)

-spec final(State) -> Result when State :: state(), Result :: out() | -1.

Finish the streaming hash in State, returning a bytes/0 byte digest.

init()

-spec init() -> Result when Result :: state() | -1.

Start a streaming hash, returning its state.

statebytes()

-spec statebytes() -> Result when Result :: 256.

Return crypto_hash_sha3256_statebytes(), in bytes.

update(State, In)

-spec update(State, In) -> Result when State :: state(), In :: binary(), Result :: state() | -1.

Absorb In into State and return the updated state.