Example CMAC computation using functions of the mcuxClKey and mcuxClMac component.
Example CMAC computation using functions of the mcuxClKey and mcuxClMac component
#include <mcuxClToolchain.h>
#include <mcuxClCore_Examples.h>
#include <mcuxClMacModes.h>
#include <mcuxClExample_ELS_Helper.h>
#include <mcuxClExample_Key_Helper.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_RNG_Helper.h>
MCUXCLEXAMPLE_FUNCTION(mcuxClMacModes_Els_Cmac_Aes128_Oneshot_example)
{
0x7c, 0x0b, 0x7d, 0xb9,
0x81, 0x1f, 0x10, 0xd0,
0x0e, 0x47, 0x6c, 0x7a,
0x0d, 0x92, 0xf6, 0xe0
};
size_t cmacInputSize = 32u;
static ALIGNED uint8_t cmacInput16[] = {
0x1eu, 0xe0u, 0xecu, 0x46u,
0x6du, 0x46u, 0xfdu, 0x84u,
0x9bu, 0x40u, 0xc0u, 0x66u,
0xb4u, 0xfbu, 0xbdu, 0x22u,
0xa2u, 0x0au, 0x4du, 0x80u,
0xa0u, 0x08u, 0xacu, 0x9au,
0xf1u, 0x7eu, 0x4fu, 0xdfu,
0xd1u, 0x06u, 0x78u, 0x5eu
};
0xbau, 0xecu, 0xdcu, 0x91u,
0xe9u, 0xa1u, 0xfcu, 0x35u,
0x72u, 0xadu, 0xf1u, 0xe4u,
0x23u, 0x2au, 0xe2u, 0x85u
};
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(session, MCUXCLEXAMPLE_MAX_WA(MCUXCLMAC_MAX_CPU_WA_BUFFER_SIZE, MCUXCLRANDOMMODES_NCINIT_WACPU_SIZE), 0u);
MCUXCLEXAMPLE_INITIALIZE_PRNG(session);
uint32_t keyDesc[MCUXCLKEY_DESCRIPTOR_SIZE_IN_WORDS];
if(!mcuxClExample_Key_Init_And_Load(session,
key,
&cmac_key_properties,
key_buffer, MCUXCLEXAMPLE_CONST_EXTERNAL_KEY))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint32_t result_size = 0u;
session,
key,
cmacInput16Buf,
cmacInputSize,
resultBuf,
&result_size
));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(sizeof(cmacOutputReference16) != result_size)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClCore_assertEqual(cmacOutputReference16, result, sizeof(cmacOutputReference16)))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
key));
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Session_Clean(session))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Els_Disable())
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
static uint32_t const aes128_key[MCUXCLELS_CIPHER_KEY_SIZE_AES_128/sizeof(uint32_t)]
Key for the AES encryption.
Definition mcuxClEls_Cipher_Aes128_Ecb_Encrypt_example.c:42
static mcuxClEls_EccByte_t ecc_public_key_client[MCUXCLELS_ECC_PUBLICKEY_SIZE] ALIGNED
Destination buffer to receive the public key of the mcuxClEls_EccKeyGen_Async operation.
Definition mcuxClEls_Tls_Master_Key_Session_Keys_example.c:33
Top-level interface header for the mcuxClAes component.
Definition of function identifiers for the flow protection mechanism.
Top-level include file for the ELS driver.
Top-level include file for the mcuxClKey component.
Top-level include file for the mcuxClMac component.
Top-level include file for the mcuxClSession component.
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLAES_AES128_KEY_SIZE_IN_WORDS
AES-128 key size in words.
Definition mcuxClAes_Constants.h:42
#define MCUXCLAES_AES128_KEY_SIZE
AES-128 key size in bytes.
Definition mcuxClAes_Constants.h:41
static const mcuxClKey_Type_t mcuxClKey_Type_Aes128
Key type pointer for AES-128 based keys.
Definition mcuxClAes_KeyTypes.h:50
#define MCUXCLBUFFER_INIT(name, info, ptr, size)
Initialize an input/output buffer (mcuxCl_Buffer_t).
Definition mcuxClBuffer.h:71
#define MCUXCLBUFFER_INIT_RO(name, info, ptr, size)
Initialize an input buffer (mcuxCl_InputBuffer_t) with plain CPU handling.
Definition mcuxClBuffer.h:88
#define MCUXCLELS_CMAC_OUT_SIZE
Definition mcuxClEls_Cmac.h:73
#define MCUXCLELS_RESET_DO_NOT_CANCEL
Set this option at mcuxClEls_ResetOption_t to abort the requested command if another ELS operation is...
Definition mcuxClEls_Common.h:119
#define MCUXCLELS_KEYPROPERTY_CMAC_TRUE
This value of mcuxClEls_KeyProp_t.ucmac indicates that the key can be used for CMAC.
Definition mcuxClEls_Types.h:122
#define MCUXCLELS_KEYPROPERTY_KEY_SIZE_128
This value of mcuxClEls_KeyProp_t.ksize indicates a 128 bit key.
Definition mcuxClEls_Types.h:101
#define MCUXCLELS_KEYPROPERTY_ACTIVE_TRUE
This value of mcuxClEls_KeyProp_t.kactv indicates that the slot contains an active key.
Definition mcuxClEls_Types.h:106
#define MCUXCLKEY_STATUS_OK
Key operation successful.
Definition mcuxClKey_Constants.h:39
mcuxClKey_Status_t mcuxClKey_flush(mcuxClSession_Handle_t pSession, mcuxClKey_Handle_t key)
Flush key from destination which can be a key slot of coprocessor or memory buffer.
mcuxClKey_Descriptor_t *const mcuxClKey_Handle_t
Key handle type.
Definition mcuxClKey_Types.h:88
mcuxClMac_Status_t mcuxClMac_compute(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key, mcuxClMac_Mode_t mode, mcuxCl_InputBuffer_t pIn, uint32_t inLength, mcuxCl_Buffer_t pMac, uint32_t *const pMacLength)
One-shot message authentication code (MAC) computation function.
static mcuxClMac_Mode_t mcuxClMac_Mode_CMAC
CMAC mode.
Definition mcuxClMacModes_Modes.h:52
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:113
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:581
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:735
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:616
Type for ELS key store key properties.
Definition mcuxClEls_Types.h:226
uint32_t ksize
Key size.
Definition mcuxClEls_Types.h:237
struct mcuxClEls_KeyProp_t::@41 bits
Access mcuxClEls_KeyProp_t bit-wise.
uint32_t ucmac
Usage permission for CMAC.
Definition mcuxClEls_Types.h:252
uint32_t kactv
Status flag to indicate whether the key slot contains an active key or not.
Definition mcuxClEls_Types.h:240
struct mcuxClEls_KeyProp_t::@40 word
Access mcuxClEls_KeyProp_t word-wise.
uint32_t value
Accesses the bit field as a full word; initialize with a combination of constants from MCUXCLELS_KEYP...
Definition mcuxClEls_Types.h:229
Structure for mcuxClSession Descriptor.
Definition mcuxClSession_Types.h:121