wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
hmac.h File Reference

FIPS 198-1 HMAC-SHA-256, HMAC-SHA-384 and HMAC-SHA-512. More...

#include "common/bytes/span/span.h"
#include "crypto/symmetric/hash/hash/sha256.h"
#include "crypto/symmetric/hash/hash/sha384.h"

Go to the source code of this file.

Functions

void hmac_sha256 (wired_span key, wired_span msg, u8 out[SHA256_DIGEST])
 Compute HMAC-SHA-256(key, msg).
void hmac_sha256_truncated (wired_span key, wired_span msg, u8 *out, usz out_len)
 Compute HMAC-SHA-256(key, msg) truncated to its leftmost out_len bytes (FIPS 198-1 5, "Truncation of HMAC Output": MAC = leftmost Tlen bytes of HMAC(K, text)).
void hmac_sha384 (wired_span key, wired_span msg, u8 out[SHA384_DIGEST])
 Compute HMAC-SHA-384(key, msg) (RFC 2104, FIPS 180-4 SHA-384).
void hmac_sha512 (wired_span key, wired_span msg, u8 out[SHA512_DIGEST])
 Compute HMAC-SHA-512(key, msg) (RFC 2104, FIPS 180-4 SHA-512).

Detailed Description

FIPS 198-1 HMAC-SHA-256, HMAC-SHA-384 and HMAC-SHA-512.

Outputs are 32-byte, 48-byte and 64-byte MACs respectively.

Function Documentation

◆ hmac_sha256()

void hmac_sha256 ( wired_span key,
wired_span msg,
u8 out[SHA256_DIGEST] )

Compute HMAC-SHA-256(key, msg).

Parameters
keyMAC key (any length; keys longer than one block are hashed)
msgmessage to authenticate
outreceives the 32-byte MAC

◆ hmac_sha256_truncated()

void hmac_sha256_truncated ( wired_span key,
wired_span msg,
u8 * out,
usz out_len )

Compute HMAC-SHA-256(key, msg) truncated to its leftmost out_len bytes (FIPS 198-1 5, "Truncation of HMAC Output": MAC = leftmost Tlen bytes of HMAC(K, text)).

Parameters
keyMAC key (any length; keys longer than one block are hashed)
msgmessage to authenticate
outreceives the truncated MAC
out_lennumber of leftmost bytes to keep (0..SHA256_DIGEST)

◆ hmac_sha384()

void hmac_sha384 ( wired_span key,
wired_span msg,
u8 out[SHA384_DIGEST] )

Compute HMAC-SHA-384(key, msg) (RFC 2104, FIPS 180-4 SHA-384).

Parameters
keyMAC key (any length; keys longer than one block are hashed)
msgmessage to authenticate
outreceives the 48-byte MAC

◆ hmac_sha512()

void hmac_sha512 ( wired_span key,
wired_span msg,
u8 out[SHA512_DIGEST] )

Compute HMAC-SHA-512(key, msg) (RFC 2104, FIPS 180-4 SHA-512).

Parameters
keyMAC key (any length; keys longer than one block are hashed)
msgmessage to authenticate
outreceives the 64-byte MAC