Example for the mcuxClAeadModes component.
#include <mcuxClCore_Examples.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_RNG_Helper.h>
static const uint8_t plain[4] = {
0x20U, 0x21U, 0x22U, 0x23U
};
static const uint8_t adata[8] = {
0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U
};
static const uint8_t nonce[7] = {
0x10U, 0x11U, 0x12U, 0x13U, 0x14U, 0x15U, 0x16U
};
static const uint8_t keyBytes[16] = {
0x40U, 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U,
0x48U, 0x49U, 0x4AU, 0x4BU, 0x4CU, 0x4DU, 0x4EU, 0x4FU
};
static const uint8_t tagReference[4] = {
0x4DU, 0xACU, 0x25U, 0x5DU
};
static const uint8_t encryptedReference[4] = {
0x71U, 0x62U, 0x01U, 0x5BU
};
MCUXCLEXAMPLE_FUNCTION(mcuxClAeadModes_Ccm_Aes128_Oneshot_PreloadedKey_example)
{
mcuxClSession_Descriptor_t sessionDesc;
#define MCUXCLAEADMODES_EXAMPLE_MAX_CPU_WA_SIZE MCUXCLEXAMPLE_MAX_WA(MCUXCLKEY_LOADCOPRO_CPU_WA_SIZE, \
MCUXCLEXAMPLE_MAX_WA(MCUXCLAEAD_ENCRYPT_CPU_WA_BUFFER_SIZE, \
MCUXCLEXAMPLE_MAX_WA(MCUXCLAEAD_DECRYPT_CPU_WA_BUFFER_SIZE, \
MCUXCLRANDOM_NCINIT_WACPU_SIZE)))
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(session, MCUXCLAEADMODES_EXAMPLE_MAX_CPU_WA_SIZE, 0U);
MCUXCLEXAMPLE_INITIALIZE_PRNG(session);
uint32_t keyDesc[MCUXCLKEY_DESCRIPTOR_SIZE_IN_WORDS];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
session,
key,
keyBytes,
sizeof(keyBytes))
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
key,
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint32_t encryptedOneShotSize = 0U;
uint8_t encryptedOneshotData[sizeof(encryptedReference)];
MCUXCLBUFFER_INIT(encryptedOneshotDataBuf, session, encryptedOneshotData,
sizeof(encryptedOneshotData));
uint8_t tagOneshotData[sizeof(tagReference)];
MCUXCLBUFFER_INIT(tagOneshotDataBuf, session, tagOneshotData,
sizeof(tagOneshotData));
session,
key,
nonceBuf,
sizeof(nonce),
plainBuf,
sizeof(plain),
adataBuf,
sizeof(adata),
encryptedOneshotDataBuf,
&encryptedOneShotSize,
tagOneshotDataBuf,
sizeof(tagReference))
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
uint32_t decryptedOneshotSize = 0U;
uint8_t decryptedOneshotData[sizeof(plain)];
MCUXCLBUFFER_INIT(decryptedOneshotDataBuf, session, decryptedOneshotData,
sizeof(decryptedOneshotData));
session,
key,
nonceBuf,
sizeof(nonce),
encryptedOneshotDataBuf,
encryptedOneShotSize,
adataBuf,
sizeof(adata),
tagOneshotDataBuf,
sizeof(tagReference),
decryptedOneshotDataBuf,
&decryptedOneshotSize)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
key)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if(!mcuxClExample_Session_Clean(session))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by MCUXCLBUFFER_INIT")
if (!mcuxClCore_assertEqual(encryptedOneshotData, encryptedReference, sizeof(encryptedReference)))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by MCUXCLBUFFER_INIT")
if (!mcuxClCore_assertEqual(tagOneshotData, tagReference, sizeof(tagReference)))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
if (sizeof(encryptedReference) != encryptedOneShotSize)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if (!mcuxClCore_assertEqual(plain, decryptedOneshotData, sizeof(plain)))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if (sizeof(plain) != decryptedOneshotSize)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
return MCUXCLEXAMPLE_STATUS_OK;
}
Top-level include file for the mcuxClAead component.
Top-level include file for the mcuxClAeadModes component.
Top-level include file for the mcuxClAes component.
Top-level include file for the mcuxClBuffer component.
Definition of function identifiers for the flow protection mechanism.
Top-level include file for the mcuxClKey component.
Top-level include file for the mcuxClSession component.
Provides the API for the CSSL flow protection mechanism.
#define MCUXCLAEAD_STATUS_OK
Aead function returned successfully.
Definition mcuxClAead_Constants.h:32
mcuxClAead_Status_t mcuxClAead_encrypt(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key, mcuxClAead_Mode_t mode, mcuxCl_InputBuffer_t pNonce, uint32_t nonceLength, mcuxCl_InputBuffer_t pIn, uint32_t inLength, mcuxCl_InputBuffer_t pAdata, uint32_t adataLength, mcuxCl_Buffer_t pOut, uint32_t *const pOutLength, mcuxCl_Buffer_t pTag, uint32_t tagLength)
One-shot authenticated encryption function.
mcuxClAead_Status_t mcuxClAead_decrypt(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key, mcuxClAead_Mode_t mode, mcuxCl_InputBuffer_t pNonce, uint32_t nonceLength, mcuxCl_InputBuffer_t pIn, uint32_t inLength, mcuxCl_InputBuffer_t pAdata, uint32_t adataLength, mcuxCl_InputBuffer_t pTag, uint32_t tagLength, mcuxCl_Buffer_t pOut, uint32_t *const pOutLength)
One-shot authenticated decryption function.
static mcuxClAead_Mode_t mcuxClAead_Mode_CCM
AES-CCM mode.
Definition mcuxClAeadModes_Modes.h:50
static const mcuxClKey_Type_t mcuxClKey_Type_Aes128
Key type pointer for AES-128 based keys.
Definition mcuxClAes_KeyTypes.h:51
#define MCUXCLBUFFER_INIT(name, info, ptr, size)
Initialize an input/output buffer (mcuxCl_Buffer_t).
Definition mcuxClBuffer.h:67
#define MCUXCLBUFFER_INIT_RO(name, info, ptr, size)
Initialize an input buffer (mcuxCl_InputBuffer_t) with plain CPU handling.
Definition mcuxClBuffer.h:84
#define MCUXCLKEY_STATUS_OK
Key operation successful.
Definition mcuxClKey_Constants.h:40
#define MCUXCLKEY_LOADOPTION_SLOT_SGI_KEY_2
SGI key slot 2.
Definition mcuxClKey_Constants.h:174
mcuxClKey_Status_t mcuxClKey_init(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key, mcuxClKey_Type_t type, const uint8_t *pKeyData, uint32_t keyDataLength)
Initializes a key handle.
mcuxClKey_Status_t mcuxClKey_flush(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key)
Flush key from destination which can be a key slot of coprocessor or memory buffer.
mcuxClKey_Status_t mcuxClKey_loadCopro(mcuxClSession_Handle_t session, mcuxClKey_Handle_t key, uint32_t loadOptions)
Load key into destination key slot of a coprocessor.
mcuxClKey_Descriptor_t *const mcuxClKey_Handle_t
Key handle type.
Definition mcuxClKey_Types.h:91
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition mcuxClSession_Types.h:98
#define MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...)
Call a flow protected function and check the protection token.
Definition mcuxCsslFlowProtection.h:623
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:777
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:658