libsodium_crypto_auth_hmacsha512256 (libsodium v3.0.1)

View Source

Secret-key message authentication with HMAC-SHA-512-256: HMAC-SHA-512 truncated to 256 bits. This is the construction used by libsodium_crypto_auth.

The one-shot functions take a keybytes/0 byte key and produce bytes/0 byte tags. The streaming functions thread an opaque state/0 through init/1, 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 the one-shot functions, init/1 accepts a key of any length, as HMAC does.

verify/3 compares tags in constant time.

Key = libsodium_crypto_auth_hmacsha512256:keygen(),
Tag = libsodium_crypto_auth_hmacsha512256:crypto_auth_hmacsha512256(<<"message">>, Key),
0 = libsodium_crypto_auth_hmacsha512256:verify(Tag, <<"message">>, Key),
-1 = libsodium_crypto_auth_hmacsha512256:verify(Tag, <<"forged">>, Key),
State0 = libsodium_crypto_auth_hmacsha512256:init(Key),
State1 = libsodium_crypto_auth_hmacsha512256:update(State0, <<"mess">>),
State2 = libsodium_crypto_auth_hmacsha512256:update(State1, <<"age">>),
Tag = libsodium_crypto_auth_hmacsha512256:final(State2).

Summary

Types

h()

A crypto_auth_hmacsha512256_BYTES (32-byte) binary.

k()

A crypto_auth_hmacsha512256_KEYBYTES (32-byte) binary.

A crypto_auth_hmacsha512256_BYTES (32-byte) binary.

An opaque native crypto_auth_hmacsha512256_state.

Functions

Return crypto_auth_hmacsha512256_bytes(), in bytes.

Compute the bytes/0 byte authentication tag of In under the keybytes/0 byte key K.

Finish the streaming authenticator in State, returning a bytes/0 byte tag.

Start a streaming authenticator keyed with Key, which may be of any length, and return its state.

Return crypto_auth_hmacsha512256_keybytes(), in bytes.

Generate a random keybytes/0 byte key.

Return crypto_auth_hmacsha512256_statebytes(), in bytes.

Absorb In into State and return the updated state.

Check in constant time that H is the tag of In under the key K. Returns 0 when it is valid and -1 otherwise.

Types

h()

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

A crypto_auth_hmacsha512256_BYTES (32-byte) binary.

k()

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

A crypto_auth_hmacsha512256_KEYBYTES (32-byte) binary.

out()

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

A crypto_auth_hmacsha512256_BYTES (32-byte) binary.

state()

An opaque native crypto_auth_hmacsha512256_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_auth_hmacsha512256_bytes(), in bytes.

crypto_auth_hmacsha512256(In, K)

-spec crypto_auth_hmacsha512256(In, K) -> Result when In :: binary(), K :: k(), Result :: out() | -1.

Compute the bytes/0 byte authentication tag of In under the keybytes/0 byte key K.

final(State)

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

Finish the streaming authenticator in State, returning a bytes/0 byte tag.

init(Key)

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

Start a streaming authenticator keyed with Key, which may be of any length, and return its state.

keybytes()

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

Return crypto_auth_hmacsha512256_keybytes(), in bytes.

keygen()

-spec keygen() -> Result when Result :: k().

Generate a random keybytes/0 byte key.

statebytes()

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

Return crypto_auth_hmacsha512256_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.

verify(H, In, K)

-spec verify(H, In, K) -> Result when H :: h(), In :: binary(), K :: k(), Result :: 0 | -1.

Check in constant time that H is the tag of In under the key K. Returns 0 when it is valid and -1 otherwise.