crypto_Mac_Status_E Crypto_Mac_AesCmac_Final(
st_Crypto_Mac_Aes_ctx *ptr_aesCmacCtx_st,
uint8_t *ptr_outMac,
uint32_t macLen
);
Description
This API calculates the MAC using AES-CMAC. To use it, first initialize the context
by calling the Crypto_Mac_AesCmac_Init function. Then, call
Crypto_Mac_AesCmac_Cipher to calculate the MAC. Once this is done, the API can be
called. To verify the MAC, users can compare the generated MAC with the one received
from the sender along with the message.
Parameters
No. | Argument Type | Argument Name | Type | Description |
---|
1 | st_Crypto_Mac_Aes_ctx* | ptr_aesCmacCtx_st | Input | AES-CMAC
algorithm context |
2 | uint8_t* | ptr_outMac | Output | Pointer for
MAC |
3 | uint8_t* | macLen | Input | MAC length in
bytes, 16 bytes |
Returns
Return Type | Description |
---|
crypto_Mac_Status_E | Function
returns the status of the API. |
Prerequisites
- To use the HW handler, the
algorithm must be enabled in Crypto v4 in MPLAB® Code Configurator.
- To use the SW handler, the
algorithm must be enabled in wolfCrypt, and linked to Crypto V4 in MPLAB® Code
Configurator.
- Crypto_Mac_AesCmac_Init and Crypto_Mac_AesCmac_Update must be called before
calling Crypto_Mac_AesCmac_Final.
Example
#define sessionID 1
crypto_Mac_Status_E status;
crypto_HandlerType_E handlerType_en = CRYPTO_HANDLER_SW_WOLFCRYPT;
st_Crypto_Mac_Aes_ctx Mac_Ctx;
uint8_t inputData[32] = {/*data*/};
uint32_t dataLen = sizeof(inputData);
uint8_t key[32] = {/*data*/};
uint32_t keyLen = sizeof(key);
uint8_t mac[16];
uint32_t macLen = 16;
status = Crypto_Mac_AesCmac_Init(
&Mac_Ctx,
handlerType_en,
key,
keyLen,
sessionID
);
status = Crypto_Mac_AesCmac_Cipher(
&Mac_Ctx,
inputData,
dataLen
);
status = Crypto_Mac_AesCmac_Final(
&Mac_Ctx,
mac,
macLen
);