NaCl: Networking and Cryptography library |
Computer Aided Cryptography Engineering |
ECRYPT II |
|
Secret-key single-message authentication: crypto_onetimeauthC++ interfaceC++ NaCl provides a crypto_onetimeauth function callable as follows:#include "crypto_onetimeauth.h" std::string k; std::string m; std::string a; a = crypto_onetimeauth(m,k); The crypto_onetimeauth function authenticates a message m using a secret key k, and returns an authenticator a. The authenticator length is always crypto_onetimeauth_BYTES. The function raises an exception if k.size() is not crypto_onetimeauth_KEYBYTES. C++ NaCl also provides a crypto_onetimeauth_verify function callable as follows: #include "crypto_onetimeauth.h" std::string k; std::string m; std::string a; crypto_onetimeauth_verify(a,m,k); This function checks that k.size() is crypto_onetimeauth_KEYBYTES; a.size() is crypto_onetimeauth_BYTES; and a is a correct authenticator of a message m under the secret key k. If any of these checks fail, the function raises an exception.
C interfaceC NaCl provides a crypto_onetimeauth function callable as follows:#include "crypto_onetimeauth.h" const unsigned char k[crypto_onetimeauth_KEYBYTES]; const unsigned char m[...]; unsigned long long mlen; unsigned char a[crypto_onetimeauth_BYTES]; crypto_onetimeauth(a,m,mlen,k); The crypto_onetimeauth function authenticates a message m[0], m[1], ..., m[mlen-1] using a secret key k[0], k[1], ..., k[crypto_onetimeauth_KEYBYTES-1]; puts the authenticator into a[0], a[1], ..., a[crypto_onetimeauth_BYTES-1]; and returns 0. C NaCl also provides a crypto_onetimeauth_verify function callable as follows: #include "crypto_onetimeauth.h" const unsigned char k[crypto_onetimeauth_KEYBYTES]; const unsigned char m[...]; unsigned long long mlen; const unsigned char a[crypto_onetimeauth_BYTES]; crypto_onetimeauth_verify(a,m,mlen,k); This function returns 0 if a[0], a[1], ..., a[crypto_onetimeauth_BYTES-1] is a correct authenticator of a message m[0], m[1], ..., m[mlen-1] under a secret key k[0], k[1], ..., k[crypto_onetimeauth_KEYBYTES-1]. Otherwise crypto_onetimeauth_verify returns -1.
Security modelThe crypto_onetimeauth function, viewed as a function of the message for a uniform random key, is designed to meet the standard notion of unforgeability after a single message. After the sender authenticates one message, an attacker cannot find authenticators for any other messages.The sender must not use crypto_onetimeauth to authenticate more than one message under the same key. Authenticators for two messages under the same key should be expected to reveal enough information to allow forgeries of authenticators on other messages. See Validation regarding safe message lengths. Selected primitivecrypto_onetimeauth is crypto_onetimeauth_poly1305, an authenticator specified in "Cryptography in NaCl", Section 9. This authenticator is proven to meet the standard notion of unforgeability after a single message.
Alternate primitivesNaCl supports the following secret-key single-message authentication functions:
VersionThis is version 2019.03.19 of the onetimeauth.html web page. |