#include <CommonCrypto/CommonHMAC.h> also included by <CommonCrypto/CommonCrypto.h>

CommonCrypto/CommonHMAC.h

@header CommonHMAC.h @abstract Keyed Message Authentication Code (HMAC) functions.
4 functions · 2 typedefs · 1 enum · 1 macro · 1 struct

enum(anonymous)

@enum CCHmacAlgorithm @abstract Algorithms implemented in this module. @constant kCCHmacAlgSHA1 HMAC with SHA1 digest @constant kCCHmacAlgMD5 HMAC with MD5 digest @constant kCCHmacAlgSHA256 HMAC with SHA256 digest @constant kCCHmacAlgSHA384 HMAC with SHA384 digest @constant kCCHmacAlgSHA512 HMAC with SHA512 digest @constant kCCHmacAlgSHA224 HMAC with SHA224 digest
underlying type unsigned int
kCCHmacAlgSHA10
kCCHmacAlgMD51
kCCHmacAlgSHA2562
kCCHmacAlgSHA3843
kCCHmacAlgSHA5124
kCCHmacAlgSHA2245

typedefCCHmacAlgorithm

typedef uint32_t CCHmacAlgorithm

macroCC_HMAC_CONTEXT_SIZE

@typedef CCHmacContext @abstract HMAC context.
#define CC_HMAC_CONTEXT_SIZE 96

structCCHmacContext

size 384, align 4
uint32_t[96]ctx

typedefCCHmacContext

typedef struct CCHmacContext CCHmacContext;

functionCCHmacInit

API_AVAILABLE(macos(10.4), ios(2.0))
void CCHmacInit(
	CCHmacContext *ctx,
	CCHmacAlgorithm algorithm,
	const void *key,
	size_t keyLength
)
@function CCHmacInit @abstract Initialize an CCHmacContext with provided raw key bytes. @param ctx An HMAC context. @param algorithm HMAC algorithm to perform. @param key Raw key bytes. @param keyLength Length of raw key bytes; can be any length including zero.

functionCCHmacUpdate

API_AVAILABLE(macos(10.4), ios(2.0))
void CCHmacUpdate(CCHmacContext *ctx, const void *data, size_t dataLength)
@function CCHmacUpdate @abstract Process some data. @param ctx An HMAC context. @param data Data to process. @param dataLength Length of data to process, in bytes. @discussion This can be called multiple times.

functionCCHmacFinal

API_AVAILABLE(macos(10.4), ios(2.0))
void CCHmacFinal(CCHmacContext *ctx, void *macOut)
@function CCHmacFinal @abstract Obtain the final Message Authentication Code. @param ctx An HMAC context. @param macOut Destination of MAC; allocated by caller. @discussion The length of the MAC written to *macOut is the same as the digest length associated with the HMAC algorithm: kCCHmacAlgSHA1 : CC_SHA1_DIGEST_LENGTH kCCHmacAlgSHA256 : CC_SHA256_DIGEST_LENGTH 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.

functionCCHmac

/* MAC written here */ API_AVAILABLE(macos(10.4), ios(2.0))
void CCHmac(
	/* kCCHmacAlgSHA256, kCCHmacAlgSHA1 */
	CCHmacAlgorithm algorithm,
	/* kCCHmacAlgSHA256,
	/* length of key in bytes */
	kCCHmacAlgSHA1 */ const void *key,
	size_t keyLength,
	/* length of key in bytes */
	/* length of data in bytes */
	const void *data,
	/* MAC written here */
	size_t dataLength,
	/* length of data in bytes */
	void *macOut
)