Skip to content

Latest commit

 

History

History
54 lines (35 loc) · 1.11 KB

GUID-83F98304-D411-4DC1-A19B-BAB4CCC85B78.md

File metadata and controls

54 lines (35 loc) · 1.11 KB

CRYPT_HMAC_SetKey Function

Parent topic:MPLAB® Harmony Crypto Library

C

int CRYPT_HMAC_SetKey(
    CRYPT_HMAC_CTX* hmac, 
    int type, 
    const unsigned char* key, 
    unsigned int sz
);

Description

This function initializes the HMAC context and sets the key for the hash.

Preconditions

None.

Parameters

Parameters Description
hmac Pointer to context that saves state between calls.
type Type of SHA operation to use with HMAC. Must be one of the following: CRYPT_HMAC_SHA, CRYPT_HMAC_SHA256, CRYPT_HMAC_SHA384, or CRYPT_HMAC_SHA512
key Secret key used for the hash.
sz Size of the input data in bytes.

Returns

  • BAD_FUNC_ARG - An invalid pointer was passed to the function.

  • 0 - An invalid pointer was not passed to the function.

Remarks

None.

Example

CRYPT_HMAC_CTX mcHmac;
byte           mcDigest[CRYPT_SHA512_DIGEST_SIZE];

CRYPT_HMAC_SetKey(&mcHmac, CRYPT_HMAC_SHA, key, 4);
CRYPT_HMAC_DataAdd(&mcHmac, ourData, OUR_DATA_SIZE);
CRYPT_HMAC_Finalize(&mcHmac, mcDigest);