---
name: "CCHmac"
section: "3cc"
platform: "macos"
package: "CommonCrypto"
version: "600035"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/CCHmac"
---

# CCHmac(3cc)

Common HMAC Algorithm Interfaces

## NAME

**CCHmacInit**, **CCHmacUpdate**, **CCHmacFinal**, **CCHmac** – Common HMAC Algorithm Interfaces

## LIBRARY

These functions are found in libSystem.

## SYNOPSIS

**#include \<CommonCrypto/CommonHMAC.h\>**

*void*\

**CCHmacInit**(*CCHmacContext \*ctx*, *CCHmacAlgorithm algorithm*, *const void \*key*, *size\_t keyLength*);

*void*\

**CCHmacUpdate**(*CCHmacContext \*ctx*, *const void \*data*, *size\_t dataLength*);

*void*\

**CCHmacFinal**(*CCHmacContext \*ctx*, *void \*macOut*);

*void*\

**CCHmac**(*CCHmacAlgorithm algorithm*, *const void \*key*, *size\_t keyLength*, *const void \*data*, *size\_t dataLength*, *void \*macOut*);

## DESCRIPTION

This interface provides access to a number of HMAC algorithms. The following algorithms are available:

- kCCHmacAlgSHA1

  \- HMAC with SHA1 digest

- kCCHmacAlgMD5

  \- HMAC with MD5 digest

- kCCHmacAlgSHA256

  \- HMAC with SHA256 digest

- kCCHmacAlgSHA384

  \- HMAC with SHA384 digest

- kCCHmacAlgSHA224

  \- HMAC with SHA224 digest

- kCCHmacAlgSHA512

  \- HMAC with SHA512 digest

The MAC must be verified by comparing the computed and expected values using **timingsafe\_bcmp**() Other comparison functions (e.g. **memcmp**() ) must not be used as they may be vulnerable to practical timing attacks, leading to MAC forgery.

The object declared in this interface, CCHmacContext, provides a handle for use with the **CCHmacInit**() **CCHmacUpdate**() and **CCHmacFinal**() calls to complete the HMAC operation.  In addition there is a one shot function, **CCHmac**() that performs a complete HMAC on a single piece of data.

## HISTORY

These functions are available in OS X 10.5 and later.

## SEE ALSO

[CC\_MD5(3cc)](/CC_MD5/3cc.md), [CC\_SHA(3cc)](/CC_SHA/3cc.md), [CC\_crypto(3cc)](/CC_crypto/3cc.md), CCCrypto(3cc)
