HMAC

Compute an HMAC over data using digest evp_md and key key.

Synopsis

Declared in <openssl/hmac.h>

unsigned char*
HMAC(
    EVP_MD const* evp_md,
    void const* key,
    int key_len,
    unsigned char const* data,
    size_t data_len,
    unsigned char* md,
    unsigned int* md_len);

Description

Uses the default OSSL_LIB_CTX; prefer EVP_Q_mac() when a library context is required.

Return Value

Pointer to the MAC bytes (md or the static buffer), or NULL on error.

Parameters

NameDescription
evp_mdMessage digest (e.g. EVP_sha256()); variable-length digests such as SHAKE are not supported.
keyHMAC key material, or NULL when key_len is 0.
key_lenLength of key in bytes.
dataMessage bytes to authenticate.
data_lenNumber of bytes at data.
mdOutput buffer of at least EVP_MAX_MD_SIZE bytes, or NULL to use a static buffer (not thread-safe).
md_lenReceives the MAC length in bytes; may be NULL.