libsodium_crypto_auth (libsodium v3.0.1)

View Source

Secret-key message authentication with the default construction, currently HMAC-SHA-512-256.

crypto_auth/2 computes a bytes/0 byte tag for a message under a keybytes/0 byte key, and verify/3 checks one in constant time. The same key can authenticate many messages; for a streaming interface, use libsodium_crypto_auth_hmacsha512256.

Key = libsodium_crypto_auth:keygen(),
Tag = libsodium_crypto_auth:crypto_auth(<<"message">>, Key),
0 = libsodium_crypto_auth:verify(Tag, <<"message">>, Key),
-1 = libsodium_crypto_auth:verify(Tag, <<"forged">>, Key).

Summary

Types

h()

A crypto_auth_BYTES (32-byte) binary.

k()

A crypto_auth_KEYBYTES (32-byte) binary.

A crypto_auth_BYTES (32-byte) binary.

Functions

Return crypto_auth_bytes(), in bytes.

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

Return crypto_auth_keybytes(), in bytes.

Generate a random keybytes/0 byte key.

Return crypto_auth_primitive() as an atom.

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_BYTES (32-byte) binary.

k()

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

A crypto_auth_KEYBYTES (32-byte) binary.

out()

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

A crypto_auth_BYTES (32-byte) binary.

Functions

bytes()

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

Return crypto_auth_bytes(), in bytes.

crypto_auth(In, K)

-spec crypto_auth(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.

keybytes()

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

Return crypto_auth_keybytes(), in bytes.

keygen()

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

Generate a random keybytes/0 byte key.

primitive()

-spec primitive() -> Result when Result :: hmacsha512256.

Return crypto_auth_primitive() as an atom.

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.