libsodium_crypto_onetimeauth (libsodium v3.0.1)
View SourceOne-time message authentication with the default construction, currently Poly1305.
A keybytes/0 byte key must be used to authenticate a single message
only; reusing it lets an attacker forge tags. Derive a fresh key per
message (for example from a stream cipher), or use
libsodium_crypto_auth for a reusable key.
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.
Key = libsodium_crypto_onetimeauth:keygen(),
Tag = libsodium_crypto_onetimeauth:crypto_onetimeauth(<<"message">>, Key),
0 = libsodium_crypto_onetimeauth:verify(Tag, <<"message">>, Key),
-1 = libsodium_crypto_onetimeauth:verify(Tag, <<"forged">>, Key),
State0 = libsodium_crypto_onetimeauth:init(Key),
State1 = libsodium_crypto_onetimeauth:update(State0, <<"mess">>),
State2 = libsodium_crypto_onetimeauth:update(State1, <<"age">>),
Tag = libsodium_crypto_onetimeauth:final(State2).
Summary
Types
A crypto_onetimeauth_BYTES (16-byte) binary.
A crypto_onetimeauth_KEYBYTES (32-byte) binary.
A crypto_onetimeauth_KEYBYTES (32-byte) binary.
A crypto_onetimeauth_BYTES (16-byte) binary.
An opaque native crypto_onetimeauth_state.
Functions
Return crypto_onetimeauth_bytes(), in bytes.
Compute the bytes/0 byte tag of In under the one-time keybytes/0 byte key K.
Finish the streaming authenticator in State, returning a bytes/0 byte tag.
Start a streaming authenticator with the one-time keybytes/0 byte Key.
Return crypto_onetimeauth_keybytes(), in bytes.
Generate a random keybytes/0 byte key.
Return crypto_onetimeauth_primitive() as an atom.
Return crypto_onetimeauth_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
-type h() :: <<_:128>>.
A crypto_onetimeauth_BYTES (16-byte) binary.
-type k() :: <<_:256>>.
A crypto_onetimeauth_KEYBYTES (32-byte) binary.
-type key() :: <<_:256>>.
A crypto_onetimeauth_KEYBYTES (32-byte) binary.
-type out() :: <<_:128>>.
A crypto_onetimeauth_BYTES (16-byte) binary.
-type state() :: libsodium_nif:crypto_onetimeauth_state().
An opaque native crypto_onetimeauth_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 :: 16.
Return crypto_onetimeauth_bytes(), in bytes.
Compute the bytes/0 byte tag of In under the one-time keybytes/0 byte key K.
Finish the streaming authenticator in State, returning a bytes/0 byte tag.
Start a streaming authenticator with the one-time keybytes/0 byte Key.
-spec keybytes() -> Result when Result :: 32.
Return crypto_onetimeauth_keybytes(), in bytes.
-spec keygen() -> Result when Result :: k().
Generate a random keybytes/0 byte key.
-spec primitive() -> Result when Result :: poly1305.
Return crypto_onetimeauth_primitive() as an atom.
-spec statebytes() -> Result when Result :: 256.
Return crypto_onetimeauth_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.