PSOC E8XXGP Device Support Library

| PSOC E8XXGP Device Support Library

Functions
Functions
PDL API Reference » Crypto (Cryptography) » Direct Crypto Core Access » Message Authentication Code (CMAC, HMAC)

## General Description

## Functions
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Cmac (CRYPTO_Type *base, uint8_t const *message, uint32_t messageSize, uint8_t const *key, cy_en_crypto_aes_key_length_t keyLength, uint8_t *cmac, cy_stc_crypto_aes_state_t *aesState)
| Calculates the AES Cipher-based Message Authentication Code (CMAC) on the input message with the provided key. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Cmac_Init (CRYPTO_Type *base, void *cmacState, void *buffer)
| The function for initialization of CMAC operation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Cmac_Start (CRYPTO_Type *base, void *cmacState, uint8_t const *aesKey, cy_en_crypto_aes_key_length_t keyLength)
| Starts CMAC calculation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Cmac_Update (CRYPTO_Type *base, void *cmacState, uint8_t const *message, uint32_t messageSize)
| Performs cmac update for multi stage operation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Cmac_Finish (CRYPTO_Type *base, void *cmacState, uint8_t *cmac)
| Completes CMAC calculation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Cmac_Free (CRYPTO_Type *base, void *cmacState)
| When D-Cache is enabled parameter cmac must align and end in 32 byte boundary. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Hmac (CRYPTO_Type *base, uint8_t *hmac, uint8_t const *message, uint32_t messageSize, uint8_t const *key, uint32_t keyLength, cy_en_crypto_sha_mode_t mode)
| Performs the HMAC calculation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Hmac_Init (CRYPTO_Type *base, cy_stc_crypto_hmac_state_t *hmacState, cy_en_crypto_sha_mode_t mode, void *hmacBuffer)
| The function to initialize the HMAC operation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Hmac_Start (CRYPTO_Type *base, cy_stc_crypto_hmac_state_t *hmacState, uint8_t const *key, uint32_t keyLength)
| Initializes the HMAC key. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Hmac_Update (CRYPTO_Type *base, cy_stc_crypto_hmac_state_t *hmacState, uint8_t const *message, uint32_t messageSize)
| Performs the multipart hmac operation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Hmac_Finish (CRYPTO_Type *base, cy_stc_crypto_hmac_state_t *hmacState, uint8_t *hmac)
| Finishes the hmac operation. More...
__STATIC_INLINE cy_en_crypto_status_t | Cy_Crypto_Core_Hmac_Free (CRYPTO_Type *base, cy_stc_crypto_hmac_state_t *hmacState)
| Frees the internally stored buffers in hmac context. More...

## Function Documentation

## ◆ Cy_Crypto_Core_Cmac()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac | ( | CRYPTO_Type * | base,
|  | uint8_t const * | message,
|  | uint32_t | messageSize,
|  | uint8_t const * | key,
|  | cy_en_crypto_aes_key_length_t | keyLength,
|  | uint8_t * | cmac,
|  | cy_stc_crypto_aes_state_t * | aesState
| ) |  |

Calculates the AES Cipher-based Message Authentication Code (CMAC) on the input message with the provided key.

Parameters

  base | The pointer to the CRYPTO instance.
  message | The pointer to the source plain text. Must be 4-byte aligned.
  messageSize | The size of the source plain text in bytes.
  key | The pointer to the encryption key. Must be 4-byte aligned.
  keyLength | cy_en_crypto_aes_key_length_t
  cmac | The pointer to the calculated CMAC.
  aesState | The pointer to the AES state structure allocated by the user. The user must not modify anything in this structure.

Returns
  cy_en_crypto_status_t

Function Usage
  uint8_t cmacKey[CY_CRYPTO_AES_256_KEY_SIZE] =
  {
  0x60u, 0x3Du, 0xEBu, 0x10u, 0x15u, 0xCAu, 0x71u, 0xBEu,
  0x2Bu, 0x73u, 0xAEu, 0xF0u, 0x85u, 0x7Du, 0x77u, 0x81u,
  0x1Fu, 0x35u, 0x2Cu, 0x07u, 0x3Bu, 0x61u, 0x08u, 0xD7u,
  0x2Du, 0x98u, 0x10u, 0xA3u, 0x09u, 0x14u, 0xDFu, 0xF4u
  };
  uint8_t cmac256PlainText[16] =
  {
  0x6Bu, 0xC1u, 0xBEu, 0xE2u, 0x2Eu, 0x40u, 0x9Fu, 0x96u,
  0xE9u, 0x3Du, 0x7Eu, 0x11u, 0x73u, 0x93u, 0x17u, 0x2Au
  };
  /* Calculated CMAC */
  uint8_t cmac[CY_CRYPTO_AES_BLOCK_SIZE] = {0};
  cy_en_crypto_status_t cryptoStatus;
  cy_stc_crypto_aes_state_t aesState;
  /* CMAC from the text message using AES-256 */
  cryptoStatus = Cy_Crypto_Core_Cmac(
  CRYPTO_HW, /* Pointer to Crypto instance */
  cmac256PlainText, /* Pointer to plain text */
  sizeof(cmac256PlainText), /* Size of plain text */
  cmacKey, /* Pointer to encryption key */
  CY_CRYPTO_KEY_AES_256, /* Size of encryption key */
  cmac, /* Pointer to calculated CMAC */
  &aesState); /* Pointer to AES state structure */
  /* ... check for errors... */
  cy_stc_crypto_aes_state_t
  Definition: cy_crypto_common.h:768
  cy_en_crypto_status_t
  cy_en_crypto_status_t
  Errors of the Crypto block.
  Definition: cy_crypto_common.h:532
  CY_CRYPTO_KEY_AES_256
  @ CY_CRYPTO_KEY_AES_256
  The AES key size is 256 bits.
  Definition: cy_crypto_common.h:476
  Cy_Crypto_Core_Cmac
  __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac(CRYPTO_Type *base, uint8_t const *message, uint32_t messageSize, uint8_t const *key, cy_en_crypto_aes_key_length_t keyLength, uint8_t *cmac, cy_stc_crypto_aes_state_t *aesState)
  Calculates the AES Cipher-based Message Authentication Code (CMAC) on the input message with the prov...
  Definition: cy_crypto_core_cmac.h:99
  CY_CRYPTO_AES_256_KEY_SIZE
  #define CY_CRYPTO_AES_256_KEY_SIZE
  Defines the Crypto AES_256 key maximum size (in bytes)
  Definition: cy_crypto_common.h:145
  CY_CRYPTO_AES_BLOCK_SIZE
  #define CY_CRYPTO_AES_BLOCK_SIZE
  Defines the Crypto AES block size (in bytes)
  Definition: cy_crypto_common.h:136

## ◆ Cy_Crypto_Core_Cmac_Init()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Init | ( | CRYPTO_Type * | base,
|  | void * | cmacState,
|  | void * | buffer
| ) |  |

The function for initialization of CMAC operation.

Parameters

  base | The pointer to the CRYPTO instance.
  cmacState | The pointer to the structure which stores the CMAC context.
  buffer | The pointer to the cmac buffer.

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Cmac_Start()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Start | ( | CRYPTO_Type * | base,
|  | void * | cmacState,
|  | uint8_t const * | aesKey,
|  | cy_en_crypto_aes_key_length_t | keyLength
| ) |  |

Starts CMAC calculation.

Parameters

  base | The pointer to the CRYPTO instance.
  cmacState | The pointer to the structure which stores the CMAC context.
  aesKey | The pointer to the cmac key.
  keyLength | cy_en_crypto_aes_key_length_t

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Cmac_Update()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Update | ( | CRYPTO_Type * | base,
|  | void * | cmacState,
|  | uint8_t const * | message,
|  | uint32_t | messageSize
| ) |  |

Performs cmac update for multi stage operation.

When D-Cache is enabled parameter message must align and end in 32 byte boundary.

Parameters

  base | The pointer to the CRYPTO instance.
  cmacState | The pointer to the structure which stores the CMAC context.
  message | The pointer to the message whose CMAC is being computed.
  messageSize | The size of the message whose CMAC is being computed.

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Cmac_Finish()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Finish | ( | CRYPTO_Type * | base,
|  | void * | cmacState,
|  | uint8_t * | cmac
| ) |  |

Completes CMAC calculation.

When D-Cache is enabled parameter cmac must align and end in 32 byte boundary.

Parameters

  cmacState | The pointer to the structure which stores the CMAC context.
  base | The pointer to the CRYPTO instance.
  cmac | The pointer to the computed CMAC value.

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Cmac_Free()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Cmac_Free | ( | CRYPTO_Type * | base,
|  | void * | cmacState
| ) |  |

When D-Cache is enabled parameter cmac must align and end in 32 byte boundary.

Parameters

  base | The pointer to the CRYPTO instance.
  cmacState | The pointer to the structure which stores the CMAC context.

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Hmac()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac | ( | CRYPTO_Type * | base,
|  | uint8_t * | hmac,
|  | uint8_t const * | message,
|  | uint32_t | messageSize,
|  | uint8_t const * | key,
|  | uint32_t | keyLength,
|  | cy_en_crypto_sha_mode_t | mode
| ) |  |

Performs the HMAC calculation.

Parameters

  base | The pointer to the CRYPTO instance.
  hmac | The pointer to the calculated HMAC. Must be 4-byte aligned.
  message | The pointer to the message whose hash value is being computed.
  messageSize | The size of the message.
  key | The pointer to the key.
  keyLength | The length of the key.
  mode | cy_en_crypto_sha_mode_t

Returns
  cy_en_crypto_status_t

Function Usage
  uint8_t hmac256Key[CY_CRYPTO_AES_256_KEY_SIZE] =
  {
  0x00u, 0x01u, 0x02u, 0x03u, 0x04u, 0x05u, 0x06u, 0x07u,
  0x08u, 0x09u, 0x0Au, 0x0Bu, 0x0Cu, 0x0Du, 0x0Eu, 0x0Fu,
  0x10u, 0x11u, 0x12u, 0x13u, 0x14u, 0x15u, 0x16u, 0x17u,
  0x18u, 0x19u, 0x1Au, 0x1Bu, 0x1Cu, 0x1Du, 0x1Eu, 0x1Fu
  };
  uint8_t hmac256PlainText[34] =
  {
  0x53u, 0x61u,
  0x6Du, 0x70u, 0x6Cu, 0x65u, 0x20u, 0x6Du, 0x65u, 0x73u,
  0x73u, 0x61u, 0x67u, 0x65u, 0x20u, 0x66u, 0x6Fu, 0x72u,
  0x20u, 0x6Bu, 0x65u, 0x79u, 0x6Cu, 0x65u, 0x6Eu, 0x3Cu,
  0x62u, 0x6Cu, 0x6Fu, 0x63u, 0x6Bu, 0x6Cu, 0x65u, 0x6Eu
  };
  /* Calculated HMAC */
  uint8_t hmac256[CY_CRYPTO_SHA256_DIGEST_SIZE] = {0};
  cy_en_crypto_status_t cryptoStatus;
  /* HMAC from the text message using SHA256 */
  cryptoStatus = Cy_Crypto_Core_Hmac(
  CRYPTO_HW, /* Pointer to Crypto instance */
  hmac256, /* Pointer to calculated HMAC */
  hmac256PlainText, /* Pointer to plain text */
  sizeof(hmac256PlainText), /* Size of plain text */
  hmac256Key, /* Pointer to encryption key */
  sizeof(hmac256Key), /* Size of encryption key */
  CY_CRYPTO_MODE_SHA256); /* SHA method */
  /* ... check for errors... */
  CY_CRYPTO_MODE_SHA256
  @ CY_CRYPTO_MODE_SHA256
  Sets the SHA256 mode.
  Definition: cy_crypto_common.h:499
  Cy_Crypto_Core_Hmac
  __STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac(CRYPTO_Type *base, uint8_t *hmac, uint8_t const *message, uint32_t messageSize, uint8_t const *key, uint32_t keyLength, cy_en_crypto_sha_mode_t mode)
  Performs the HMAC calculation.
  Definition: cy_crypto_core_hmac.h:94
  CY_CRYPTO_SHA256_DIGEST_SIZE
  #define CY_CRYPTO_SHA256_DIGEST_SIZE
  Hash size for the SHA256 mode (in bytes)
  Definition: cy_crypto_common.h:220

## ◆ Cy_Crypto_Core_Hmac_Init()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac_Init | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_hmac_state_t * | hmacState,
|  | cy_en_crypto_sha_mode_t | mode,
|  | void * | hmacBuffer
| ) |  |

The function to initialize the HMAC operation.

When D-Cache is enabled parameters hmacState and hmacBuffer must align and end in 32 byte boundary.

Parameters

  base | The pointer to the CRYPTO instance.
  hmacState | The pointer to the HMAC state.
  hmacBuffer | The pointer to the chmac buffer structure that stores all buffers for HMAC operation.
  mode | cy_en_crypto_sha_mode_t

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Hmac_Start()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac_Start | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_hmac_state_t * | hmacState,
|  | uint8_t const * | key,
|  | uint32_t | keyLength
| ) |  |

Initializes the HMAC key.

When D-Cache is enabled parameters key & hmacState (m0Key) must align and end in 32 byte boundary.

Parameters

  base | The pointer to the CRYPTO instance.
  hmacState | The pointer to the HMAC state.
  key | the pointer to the hmac key
  keyLength | the length of the key

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Hmac_Update()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac_Update | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_hmac_state_t * | hmacState,
|  | uint8_t const * | message,
|  | uint32_t | messageSize
| ) |  |

Performs the multipart hmac operation.

Parameters

  base | The pointer to the CRYPTO instance.
  hmacState | The pointer to the HMAC state.
  message | the pointer to the message
  messageSize | the length of the message

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Hmac_Finish()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac_Finish | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_hmac_state_t * | hmacState,
|  | uint8_t * | hmac
| ) |  |

Finishes the hmac operation.

Parameters

  base | The pointer to the CRYPTO instance.
  hmacState | The pointer to the HMAC state.
  hmac | the pointer to store the hmac.

Returns
  cy_en_crypto_status_t

## ◆ Cy_Crypto_Core_Hmac_Free()

__STATIC_INLINE cy_en_crypto_status_t Cy_Crypto_Core_Hmac_Free | ( | CRYPTO_Type * | base,
|  | cy_stc_crypto_hmac_state_t * | hmacState
| ) |  |

Frees the internally stored buffers in hmac context.

When D-Cache is enabled parameters hmacState must align and end in 32 byte boundary.

Parameters

  base | The pointer to the CRYPTO instance.
  hmacState | The pointer to the HMAC state.

Returns
  cy_en_crypto_status_t