Skip to content

Algorithm - CMAC

Functions

Name
int wc_InitCmac(Cmac * cmac, const byte * key, word32 keySz, int type, void * unused)
Initialize the Cmac structure with defaults.
int wc_InitCmac_ex(Cmac * cmac, const byte * key, word32 keySz, int type, void * unused, void * heap, int devId)
Initialize the Cmac structure with defaults.
int wc_CmacUpdate(Cmac * cmac, const byte * in, word32 inSz)
Add Cipher-based Message Authentication Code input data.
int wc_CmacFinal(Cmac * cmac, byte * out, word32 * outSz)
Generate the final result using Cipher-based Message Authentication Code.
int wc_AesCmacGenerate(byte * out, word32 * outSz, const byte * in, word32 inSz, const byte * key, word32 keySz)
Single shot fuction for generating a CMAC.
int wc_AesCmacVerify(const byte * check, word32 checkSz, const byte * in, word32 inSz, const byte * key, word32 keySz)
Single shot fuction for validating a CMAC.
int wc_CMAC_Grow(Cmac * cmac, const byte * in, int inSz)
Only used with WOLFSSL_HASH_KEEP when hardware requires single-shot and the updates must be cached in memory.

Functions Documentation

function wc_InitCmac

int wc_InitCmac(
    Cmac * cmac,
    const byte * key,
    word32 keySz,
    int type,
    void * unused
)

Initialize the Cmac structure with defaults.

Parameters:

  • cmac pointer to the Cmac structure
  • key key pointer
  • keySz size of the key pointer (16, 24 or 32)
  • type Always WC_CMAC_AES = 1
  • unused not used, exists for potential future use around compatiblity

See:

Return: 0 on success

Example

Cmac cmac[1];
ret = wc_InitCmac(cmac, key, keySz, WC_CMAC_AES, NULL);
if (ret == 0) {
    ret = wc_CmacUpdate(cmac, in, inSz);
}
if (ret == 0) {
    ret = wc_CmacFinal(cmac, out, outSz);
}

function wc_InitCmac_ex

int wc_InitCmac_ex(
    Cmac * cmac,
    const byte * key,
    word32 keySz,
    int type,
    void * unused,
    void * heap,
    int devId
)

Initialize the Cmac structure with defaults.

Parameters:

  • cmac pointer to the Cmac structure
  • key key pointer
  • keySz size of the key pointer (16, 24 or 32)
  • type Always WC_CMAC_AES = 1
  • unused not used, exists for potential future use around compatiblity
  • heap pointer to the heap hint used for dynamic allocation. Typically used with our static memory option. Can be NULL.
  • devId ID to use with async hardware. Set to INVALID_DEVID if not using async hardware.

See:

Return: 0 on success

Example

Cmac cmac[1];
ret = wc_InitCmac_ex(cmac, key, keySz, WC_CMAC_AES, NULL, NULL, INVALID_DEVID);
if (ret == 0) {
    ret = wc_CmacUpdate(cmac, in, inSz);
}
if (ret == 0) {
    ret = wc_CmacFinal(cmac, out, &outSz);
}

function wc_CmacUpdate

int wc_CmacUpdate(
    Cmac * cmac,
    const byte * in,
    word32 inSz
)

Add Cipher-based Message Authentication Code input data.

Parameters:

  • cmac pointer to the Cmac structure
  • in input data to process
  • inSz size of input data

See:

Return: 0 on success

Example

ret = wc_CmacUpdate(cmac, in, inSz);

function wc_CmacFinal

int wc_CmacFinal(
    Cmac * cmac,
    byte * out,
    word32 * outSz
)

Generate the final result using Cipher-based Message Authentication Code.

Parameters:

  • cmac pointer to the Cmac structure
  • out pointer to return the result
  • outSz pointer size of output (in/out)

See:

Return: 0 on success

Example

ret = wc_CmacFinal(cmac, out, &outSz);

function wc_AesCmacGenerate

int wc_AesCmacGenerate(
    byte * out,
    word32 * outSz,
    const byte * in,
    word32 inSz,
    const byte * key,
    word32 keySz
)

Single shot fuction for generating a CMAC.

Parameters:

  • out pointer to return the result
  • outSz pointer size of output (in/out)
  • in input data to process
  • inSz size of input data
  • key key pointer
  • keySz size of the key pointer (16, 24 or 32)

See: wc_AesCmacVerify

Return: 0 on success

Example

ret = wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz);

function wc_AesCmacVerify

int wc_AesCmacVerify(
    const byte * check,
    word32 checkSz,
    const byte * in,
    word32 inSz,
    const byte * key,
    word32 keySz
)

Single shot fuction for validating a CMAC.

Parameters:

  • check pointer to return the result
  • checkSz size of checkout buffer
  • in input data to process
  • inSz size of input data
  • key key pointer
  • keySz size of the key pointer (16, 24 or 32)

See: wc_AesCmacGenerate

Return: 0 on success

Example

ret = wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz);

function wc_CMAC_Grow

int wc_CMAC_Grow(
    Cmac * cmac,
    const byte * in,
    int inSz
)

Only used with WOLFSSL_HASH_KEEP when hardware requires single-shot and the updates must be cached in memory.

Parameters:

  • in input data to process
  • inSz size of input data

Return: 0 on success

Example

ret = wc_CMAC_Grow(cmac, in, inSz)

Updated on 2022-09-26 at 08:30:55 +0000