Example for the mcuxClAeadModes component.
#include <mcuxClCore_Examples.h>
#include <mcuxClExample_Session_Helper.h>
#include <mcuxClExample_RNG_Helper.h>
static const uint8_t plain[] = {
0x6bU, 0xc1U, 0xbeU, 0xe2U, 0x2eU, 0x40U, 0x9fU, 0x96U,
0xe9U, 0x3dU, 0x7eU, 0x11U, 0x73U, 0x93U, 0x17U, 0x2aU
};
static const uint8_t adata[] = {
0xcaU, 0xeaU, 0x07U, 0x26U, 0x62U, 0xe2U, 0x20U, 0x06U,
0x2dU, 0x45U, 0x46U, 0x41U, 0x5eU, 0xffU, 0xfaU, 0xd2U
};
static const uint8_t nonce[] = {
0xf8U, 0xd2U, 0x68U, 0x76U, 0x81U, 0x6fU, 0x0fU, 0xbaU,
0x86U, 0x2bU, 0xd8U, 0xa3U
};
static const uint8_t keyBytes[] = {
0x2bU, 0x7eU, 0x15U, 0x16U, 0x28U, 0xaeU, 0xd2U, 0xa6U,
0xabU, 0xf7U, 0x15U, 0x88U, 0x09U, 0xcfU, 0x4fU, 0x3cU
};
static const uint8_t tagReference[] = {
0xb2U, 0xc5U, 0xcfU, 0xc3U, 0xf2U, 0x8cU, 0x9fU, 0x78U,
0xfcU, 0x25U, 0xbcU, 0x10U, 0xc9U, 0xcaU, 0xffU, 0xd5U
};
static const uint8_t encryptedReference[] = {
0x4fU, 0x74U, 0x2dU, 0xf6U, 0x9dU, 0x1cU, 0x03U, 0x6bU,
0x56U, 0xbcU, 0xc2U, 0x81U, 0x5fU, 0xdaU, 0x8dU, 0x6dU
};
MCUXCLEXAMPLE_FUNCTION(mcuxClAeadModes_Gcm_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),
0U ,
0U ,
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),
0U ,
0U ,
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;
}
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("Initialized 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("Initialized 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_GCM
GCM mode.
Definition mcuxClAeadModes_Modes.h:68
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