% limb manual
% hmac(3)
% limb 0.1.0
% 2023-07-24
# NAME
hmac - compute the HMAC of a given message using given hasher and key
# SYNOPSIS
#include <limb/hmac.h>
```pre hl
void hmac(char *<em>out</em>, hasher *<em>hr</em>, const void *<em>key</em>, size_t <em>klen</em>, const void *<em>msg</em>, size_t <em>mlen</em>)
```
# DESCRIPTION
The `hmac`() function calculates the HMAC of message `msg` of length `mlen`,
using the secret key `key` of length `klen` and the cryptographic hasher `hr`,
as described in [RFC 2104][rfc2104].
The results if then copied into the buffer pointed by `out` which must be able
to hold at least the length of a message digest from the hash function used,
i.e. `hr->hlen` bytes.
For a list of available hashers, refer to [hasher_hash](3).
[rfc2104]: https://datatracker.ietf.org/doc/html/rfc2104
# EXAMPLE
```c
#include <limb/hmac.h>
#include <limb/hasher_sha1.h>
#include <limb/output.h>
int main(void)
{
const char *msg = "The quick brown fox jumps over the lazy dog";
const char *key = "key";
char out[sha1->hlen];
hmac(out, sha1, key, 3, msg, strlen(msg));
out("HMAC-SHA1(\"key\", \"", msg, "\") = ", HEX(out, sizeof(out)));
return 0;
}
```
# SEE ALSO
[pbkdf2](3), [poly1305_init](3)