.\"
.\" ----------------------------------------------------------------------------
.\"
-.\" Copyright (c) 2019 Fabio Scotoni
+.\" Copyright (c) 2019-2020 Fabio Scotoni
.\" All rights reserved.
.\"
.\"
.\"
.\" ----------------------------------------------------------------------------
.\"
-.\" Written in 2019 by Fabio Scotoni
+.\" Written in 2019-2020 by Fabio Scotoni
.\"
.\" To the extent possible under law, the author(s) have dedicated all copyright
.\" and related neighboring rights to this software to the public domain
.\" with this software. If not, see
.\" <https://creativecommons.org/publicdomain/zero/1.0/>
.\"
-.Dd December 12, 2019
+.Dd March 2, 2020
.Dt CRYPTO_HMAC_SHA512 3MONOCYPHER
.Os
.Sh NAME
.Sh RETURN VALUES
These functions return nothing.
.Sh EXAMPLES
+The following examples assume the existence of
+.Fn arc4random_buf ,
+which fills the given buffer with cryptographically secure random bytes.
+If
+.Fn arc4random_buf
+does not exist on your system, see
+.Xr intro 3monocypher
+for advice about how to generate cryptographically secure random bytes.
+.Pp
Computing a message authentication code all at once:
.Bd -literal -offset indent
-uint8_t hash [ 64]; /* Output hash (between 1 and 64 bytes) */
-uint8_t key [ 32]; /* Optional key (between 0 and 64 bytes) */
-uint8_t message[500]; /* Message to hash */
+uint8_t hash [64]; /* Output hash (between 1 and 64 bytes) */
+uint8_t key [32]; /* Key (at least 1 byte) */
+uint8_t message[10] = "Lorem ipsu"; /* Message to authenticate */
+arc4random_buf(key, 32);
crypto_hmac_sha512(hash, key, 32, message, 500);
/* Wipe secrets if they are no longer needed */
crypto_wipe(message, 500);
.Pp
Computing a message authentication code incrementally:
.Bd -literal -offset indent
-uint8_t hash [ 64]; /* Output hash (between 1 and 64 bytes) */
-uint8_t key [ 32]; /* Optional key (between 0 and 64 bytes) */
-uint8_t message[500]; /* Message to hash */
+uint8_t hash [64]; /* Output hash (between 1 and 64 bytes) */
+uint8_t key [32]; /* Key (at least 1 byte) */
+uint8_t message[500] = {1}; /* Message to authenticate */
crypto_hmac_sha512_ctx ctx;
+arc4random_buf(key, 32);
crypto_hmac_sha512_init(&ctx, key, 32);
/* Wipe the key */
crypto_wipe(key, 32);