libsodium_crypto_auth (libsodium v3.0.1)
View SourceSecret-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
A crypto_auth_BYTES (32-byte) binary.
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
Functions
-spec bytes() -> Result when Result :: 32.
Return crypto_auth_bytes(), in bytes.
Compute the bytes/0 byte authentication tag of In under the keybytes/0 byte key K.
-spec keybytes() -> Result when Result :: 32.
Return crypto_auth_keybytes(), in bytes.
-spec keygen() -> Result when Result :: k().
Generate a random keybytes/0 byte key.
-spec primitive() -> Result when Result :: hmacsha512256.
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.