m2mb API docs  25.20.008
m2mb API sets documentation
M2MB_CMAC

Ciphered MAC implementation, per FIPS pub 198.
More...

Modules

 M2MB_AES
 AES CBC & ECB algorithm implementation.
http://csrc.nist.gov/encryption/aes/rijndael/Rijndael.pdf http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf.
 
 M2MB_DES
 DES & 3DES CBC & ECB algorithm implementation.

 

Enumerations

enum  M2MB_CRYPTO_CMAC_ALG_E { M2MB_CRYPTO_CMAC_ALG_AES_128 = 1, M2MB_CRYPTO_CMAC_ALG_AES_192 = 2, M2MB_CRYPTO_CMAC_ALG_AES_256 = 3 }
 

Functions

M2MB_RESULT_E m2mb_crypto_cmac_init (M2MB_CRYPTO_CMAC_CONTEXT *ctx)
 Allocates a M2MB_CRYPTO_CMAC_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_setup (M2MB_CRYPTO_CMAC_CONTEXT ctx, const UINT8 *key, SIZE_T keylen)
 Sets up an M2MB_CRYPTO_CMAC_CONTEXT structure. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_update (M2MB_CRYPTO_CMAC_CONTEXT ctx, const UINT8 *data, SIZE_T len)
 continuously CMAC of data. This function can be called repeatedly similar to streaming More...
 
M2MB_RESULT_E m2mb_crypto_cmac_final (M2MB_CRYPTO_CMAC_CONTEXT ctx, UINT8 *cmac)
 This function computes the final CMAC for all previously provided messages for the given context. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_reset (M2MB_CRYPTO_CMAC_CONTEXT ctx)
 Prepare to run CMAC for a new message. More...
 
M2MB_RESULT_E m2mb_crypto_cmac_deinit (M2MB_CRYPTO_CMAC_CONTEXT ctx)
 This function free an CMAC context. More...
 
UINT8 * m2mb_crypto_cmac (M2MB_CRYPTO_CMAC_ALG_E cmac_alg, const UINT8 *key, const SIZE_T keylen, const UINT8 *input, const SIZE_T inlen, UINT8 *cmac)
 This function will compute the CMAC in one shot without needing any context. More...
 

Detailed Description

Ciphered MAC implementation, per FIPS pub 198.

Function Documentation

◆ m2mb_crypto_cmac()

UINT8* m2mb_crypto_cmac ( M2MB_CRYPTO_CMAC_ALG_E  cmac_alg,
const UINT8 *  key,
const SIZE_T  keylen,
const UINT8 *  input,
const SIZE_T  inlen,
UINT8 *  cmac 
)

This function will compute the CMAC in one shot without needing any context.

This function is used to calculate an CMAC for a given data, key & hash algorithm.
If cmac is NULL, the CMAC is placed in a static array.
This function is similar to running the following function flow:
m2mb_crypto_cmac_init();
m2mb_crypto_cmac_setup();
m2mb_crypto_cmac_update();
m2mb_crypto_cmac_final();
m2mb_crypto_cmac_deinit();

Parameters
[in]keyThe symmetric key to use for the CMAC
[in]keylenThe length of the provided key.
[in]inputBuffer holding the data to compute CMAC for
[in]inlenlength of the provided data
[out]cmacThe calculated CMAC
Returns
If cmac is NULL, Upon successful completion returns a pointer to a static array containing the CMAC, 0 otherwise.
Note
Setting cmac to NULL is not thread safe.

Example

<C code example>

◆ m2mb_crypto_cmac_deinit()

M2MB_RESULT_E m2mb_crypto_cmac_deinit ( M2MB_CRYPTO_CMAC_CONTEXT  ctx)

This function free an CMAC context.

This function free the provided context memory.

Parameters
[in]ctxPointer to a previously initialized context structure to free
Returns
M2MB_RESULT_E: it returns M2MB_RESULT_SUCCESS on success, a different value on error.
Note
<Notes>

Example

<C code example>

◆ m2mb_crypto_cmac_final()

M2MB_RESULT_E m2mb_crypto_cmac_final ( M2MB_CRYPTO_CMAC_CONTEXT  ctx,
UINT8 *  cmac 
)

This function computes the final CMAC for all previously provided messages for the given context.

This function is the final step for CMAC calculation.
It will return the calculated CMAC based on all the previous messages (sent via m2mb_crypto_cmac_update)

Parameters
[in]ctxA previously allocated cmac context.
The context setup must be also done before using this function (using m2mb_crypto_cmac_setup)
[out]cmacThe calculated cmac.
Must be large enough to0 hold the CMAC per the selected message digest algorithm used for the setup.
Returns
M2MB_RESULT_E: it returns M2MB_RESULT_SUCCESS on success, a different value on error.
Note
<Notes>

Example

<C code example>

◆ m2mb_crypto_cmac_init()

M2MB_RESULT_E m2mb_crypto_cmac_init ( M2MB_CRYPTO_CMAC_CONTEXT ctx)

Allocates a M2MB_CRYPTO_CMAC_CONTEXT structure.

This function allocates an CMAC context to be later used by any CMAC function.

Parameters
[in]ctxPointer to a context structure to be allocated by this function.
Any consecutive call to CMAC function must use the context.
Returns
M2MB_RESULT_E: it returns M2MB_RESULT_SUCCESS on success, a different value on error.
Note
<Notes>

Example

<C code example>

◆ m2mb_crypto_cmac_reset()

M2MB_RESULT_E m2mb_crypto_cmac_reset ( M2MB_CRYPTO_CMAC_CONTEXT  ctx)

Prepare to run CMAC for a new message.

Resets all previously provided messages.
The same key & hash algorithm provided to m2mb_crypto_cmac_setup() remains and will be used for new CMAC.
Usually used after m2mb_crypto_cmac_final() and before m2mb_crypto_cmac_update()

Parameters
[in]ctxPointer to a previously allocated context structure to reset
Returns
M2MB_RESULT_E: it returns M2MB_RESULT_SUCCESS on success, a different value on error.
Note
<Notes>

Example

<C code example>

◆ m2mb_crypto_cmac_setup()

M2MB_RESULT_E m2mb_crypto_cmac_setup ( M2MB_CRYPTO_CMAC_CONTEXT  ctx,
const UINT8 *  key,
SIZE_T  keylen 
)

Sets up an M2MB_CRYPTO_CMAC_CONTEXT structure.

This function performs setup of a CMAC context providing the hash algorithm to use and the symmetric key.
Usually comes after m2mb_crypto_cmac_init() or m2mb_crypto_cmac_final().
Might also be called after m2mb_crypto_cmac_update() in order to restart the digest process.

Parameters
[in]ctxPointer to a previously allocated context structure
[in]keyThe symmetric key to use for the cmac.
[in]keylenThe length of the provided key. Only 128 & 256 are supported.
Returns
M2MB_RESULT_E: it returns M2MB_RESULT_SUCCESS on success, a different value on error.
Note
<Notes>

Example

<C code example>

◆ m2mb_crypto_cmac_update()

M2MB_RESULT_E m2mb_crypto_cmac_update ( M2MB_CRYPTO_CMAC_CONTEXT  ctx,
const UINT8 *  data,
SIZE_T  len 
)

continuously CMAC of data. This function can be called repeatedly similar to streaming

This function is used to continuously hash data (streaming data when not all buffer to be hashed is available in one shot).
This function can be called repeatedly.

Parameters
[in]ctxA previously allocated cmac context.
The context setup must be also done before using this function (using m2mb_crypto_cmac_setup)
[in]dataBuffer holding the data
[in]lenlength of the provided data
Returns
M2MB_RESULT_E: it returns M2MB_RESULT_SUCCESS on success, a different value on error.
Note
<Notes>

Example

<C code example>