Example for the mcuxClAeadModes component.
#include <mcuxClCore_Examples.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_RNG_Helper.h>
static const uint8_t plain[24] = {
0x20U, 0x21U, 0x22U, 0x23U, 0x24U, 0x25U, 0x26U, 0x27U,
0x28U, 0x29U, 0x2aU, 0x2bU, 0x2cU, 0x2dU, 0x2eU, 0x2fU,
0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U
};
static const uint8_t adata[20] = {
0x00U, 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U,
0x08U, 0x09U, 0x0aU, 0x0bU, 0x0cU, 0x0dU, 0x0eU, 0x0fU,
0x10U, 0x11U, 0x12U, 0x13U
};
static const uint8_t nonce[12] = {
0x10U, 0x11U, 0x12U, 0x13U, 0x14U, 0x15U, 0x16U, 0x17U,
0x18U, 0x19U, 0x1aU, 0x1bU
};
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[8] = {
0x48U, 0x43U, 0x92U, 0xfbU, 0xc1U, 0xb0U, 0x99U, 0x51U
};
static const uint8_t encryptedReference[24] = {
0xe3U, 0xb2U, 0x01U, 0xa9U, 0xf5U, 0xb7U, 0x1aU, 0x7aU,
0x9bU, 0x1cU, 0xeaU, 0xecU, 0xcdU, 0x97U, 0xe7U, 0x0bU,
0x61U, 0x76U, 0xaaU, 0xd9U, 0xa4U, 0x42U, 0x8aU, 0xa5U
};
MCUXCLEXAMPLE_FUNCTION(mcuxClAeadModes_Ccm_Aes128_Multipart_example)
{
mcuxClSession_Descriptor_t sessionDesc;
MCUXCLEXAMPLE_ALLOCATE_AND_INITIALIZE_SESSION(session, MCUXCLEXAMPLE_MAX_WA(MCUXCLAEAD_MAX_CPU_WA_BUFFER_SIZE, MCUXCLRANDOM_NCINIT_WACPU_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;
}
uint32_t encryptedSize = 0U;
uint32_t encryptedMultipartSize = 0U;
uint8_t encryptedMultipartData[sizeof(encryptedReference)];
MCUXCLBUFFER_INIT(encryptedMultipartDataBuf, session, encryptedMultipartData,
sizeof(encryptedMultipartData));
uint8_t tagMultipartData[sizeof(tagReference)];
MCUXCLBUFFER_INIT(tagMultipartDataBuf, session, tagMultipartData,
sizeof(tagMultipartData));
uint8_t ctxBuf[MCUXCLAEAD_CONTEXT_SIZE];
MCUX_CSSL_ANALYSIS_START_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
MCUX_CSSL_ANALYSIS_STOP_PATTERN_REINTERPRET_MEMORY_OF_OPAQUE_TYPES()
session,
ctx,
key,
nonceBuf,
sizeof(nonce),
sizeof(plain),
sizeof(adata),
sizeof(tagReference))
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_encrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
adataBuf,
sizeof(adata)/3U)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_encrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
adataBuf,
sizeof(adata) - sizeof(adata)/3U)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_encrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
plainBuf,
sizeof(plain)/2U,
encryptedMultipartDataBuf,
&encryptedSize)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW("Calculation does not overflow")
encryptedMultipartSize += encryptedSize;
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_encrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
plainBuf,
sizeof(plain) - sizeof(plain)/2U,
encryptedMultipartDataBuf2,
&encryptedSize)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW("Calculation does not overflow")
encryptedMultipartSize += encryptedSize;
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_encrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
encryptedMultipartDataBuf3,
&encryptedSize,
tagMultipartDataBuf)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW("Calculation does not overflow")
encryptedMultipartSize += encryptedSize;
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
uint32_t decryptedSize = 0U;
uint32_t decryptedMultipartSize = 0U;
uint8_t decryptedMultipartData[sizeof(plain)];
MCUXCLBUFFER_INIT(decryptedMultipartDataBuf, session, decryptedMultipartData, sizeof(decryptedMultipartData));
session,
ctx,
key,
nonceBuf,
sizeof(nonce),
sizeof(plain),
sizeof(adata),
sizeof(tagReference))
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_decrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
adataBuf2,
sizeof(adata)/2U)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_decrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
adataBuf2,
sizeof(adata) - sizeof(adata)/2U)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_decrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by MCUXCLBUFFER_DERIVE_RO")
encryptedMultipartData_InBuf,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
encryptedMultipartSize/2U,
decryptedMultipartDataBuf,
&decryptedMultipartSize)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW("Calculation does not overflow")
decryptedMultipartSize += decryptedSize;
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_decrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by MCUXCLBUFFER_DERIVE_RO")
encryptedMultipartData_InBuf,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW("Calculation does not wrap")
encryptedMultipartSize - encryptedMultipartSize/2U,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
decryptedMultipartDataBuf2,
&decryptedSize)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW("Calculation does not overflow")
decryptedMultipartSize += decryptedSize;
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
session,
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initialized by mcuxClAead_init_decrypt")
ctx,
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
tagMultipartDataBuf,
decryptedMultipartDataBuf3,
&decryptedSize)
);
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW("Calculation does not overflow")
decryptedMultipartSize += decryptedSize;
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
if(!mcuxClExample_Session_Clean(session))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initilized by MCUXCLBUFFER_INIT")
if (!mcuxClCore_assertEqual(encryptedMultipartData, encryptedReference, sizeof(encryptedReference)))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
MCUX_CSSL_ANALYSIS_START_SUPPRESS_ALREADY_INITIALIZED("Initilized by MCUXCLBUFFER_INIT")
if (!mcuxClCore_assertEqual(tagMultipartData, tagReference, sizeof(tagReference)))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_ALREADY_INITIALIZED()
if (sizeof(encryptedReference) != encryptedMultipartSize)
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if (!mcuxClCore_assertEqual(plain, decryptedMultipartData, sizeof(plain)))
{
return MCUXCLEXAMPLE_STATUS_ERROR;
}
if (sizeof(plain) != decryptedMultipartSize)
{
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_init_encrypt(mcuxClSession_Handle_t session, mcuxClAead_Context_t *const pContext, mcuxClKey_Handle_t key, mcuxClAead_Mode_t mode, mcuxCl_InputBuffer_t pNonce, uint32_t nonceLength, uint32_t inLength, uint32_t adataLength, uint32_t tagLength)
Multi-part authenticated encryption initialization function.
mcuxClAead_Status_t mcuxClAead_finish(mcuxClSession_Handle_t session, mcuxClAead_Context_t *const pContext, mcuxCl_Buffer_t pOut, uint32_t *const pOutLength, mcuxCl_Buffer_t pTag)
Multi-part authenticated encryption/decryption finalization function.
mcuxClAead_Status_t mcuxClAead_process_adata(mcuxClSession_Handle_t session, mcuxClAead_Context_t *const pContext, mcuxCl_InputBuffer_t pAdata, uint32_t adataLength)
Multi-part authenticated encryption/decryption processing function for the associated data (authentic...
mcuxClAead_Status_t mcuxClAead_init_decrypt(mcuxClSession_Handle_t session, mcuxClAead_Context_t *const pContext, mcuxClKey_Handle_t key, mcuxClAead_Mode_t mode, mcuxCl_InputBuffer_t pNonce, uint32_t nonceLength, uint32_t inLength, uint32_t adataLength, uint32_t tagLength)
Multi-part authenticated decryption initialization function.
mcuxClAead_Status_t mcuxClAead_process(mcuxClSession_Handle_t session, mcuxClAead_Context_t *const pContext, mcuxCl_InputBuffer_t pIn, uint32_t inLength, mcuxCl_Buffer_t pOut, uint32_t *const pOutLength)
Multi-part authenticated encryption/decryption processing function for the regular data (authenticate...
mcuxClAead_Status_t mcuxClAead_verify(mcuxClSession_Handle_t session, mcuxClAead_Context_t *const pContext, mcuxCl_InputBuffer_t pTag, mcuxCl_Buffer_t pOut, uint32_t *const pOutLength)
Multi-part authenticated decryption verification function.
struct mcuxClAead_Context mcuxClAead_Context_t
AEAD context type.
Definition mcuxClAead_Types.h:102
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 MCUXCLBUFFER_DERIVE_RW(name, original, offset)
Derive a new input/output buffer object from an existing one (updated with the given offset).
Definition mcuxClBuffer.h:227
#define MCUXCLBUFFER_DERIVE_RO(name, original, offset)
Derive a new input buffer object from an existing one (updated with the given offset).
Definition mcuxClBuffer.h:214
#define MCUXCLBUFFER_UPDATE(name, offset)
Update the buffer pointer with the given offset.
Definition mcuxClBuffer.h:201
#define MCUXCLKEY_STATUS_OK
Key operation successful.
Definition mcuxClKey_Constants.h:40
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_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