limb 0.2.0

2024-01-09

hmac(3)
limb manual
hmac(3)

NAME

hmac - compute the HMAC of a given message using given hasher and key

SYNOPSIS

#include <limb/hmac.h>
void hmac(char *out, hasher *hr, const void *key, size_t klen, const void *msg, size_t mlen)

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.

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).

EXAMPLE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)

limb 0.1.0
2023-07-24
hmac(3)