MCUX CLNS
MCUX Crypto Library Normal Secure
Loading...
Searching...
No Matches
mcuxCsslMemory_Copy_example.c

Example constant-time memory copy (CSSL component mcuxCsslMemory).

Example constant-time memory copy (CSSL component mcuxCsslMemory)

/*--------------------------------------------------------------------------*/
/* Copyright 2021, 2025 NXP */
/* */
/* NXP Confidential and Proprietary. This software is owned or controlled */
/* by NXP and may only be used strictly in accordance with the applicable */
/* license terms. By expressly accepting such terms or by downloading, */
/* installing, activating and/or otherwise using the software, you are */
/* agreeing that you have read, and that you agree to comply with and are */
/* bound by, such license terms. If you do not agree to be bound by the */
/* applicable license terms, then you may not retain, install, activate or */
/* otherwise use the software. */
/*--------------------------------------------------------------------------*/
#include <mcuxClToolchain.h>
#include <stdbool.h>
#include <stdint.h>
#include <mcuxCsslMemory.h>
#include <mcuxCsslMemory_Examples.h>
#define EXIT_CODE_ERROR false
#define EXIT_CODE_OK true
MCUXCSSL_MEMORY_EX_FUNCTION(mcuxCsslMemory_Copy_example)
{
/* Define data arrays */
ALIGNED uint8_t arr1[] = {0xe4u, 0xf9u, 0x26u, 0x4cu, 0x65u, 0xe2u, 0x13u, 0xa3u,
0x9au, 0x40u, 0xd7u, 0x87u, 0xccu, 0x0bu, 0x31u, 0x18u,
0xacu, 0x55u, 0xb5u, 0x7du, 0x06u, 0x7fu, 0xceu, 0xe4u,
0xb2u, 0x7eu, 0xd5u, 0xaau, 0x90u, 0x9au, 0x42u, 0x56u,
0x76u};
ALIGNED uint8_t arr2[sizeof(arr1)] = {0u};
/* Provoke buffer overflow => should return invalid parameter error */
/* mcuxCsslParamIntegrity_Checksum_t chk,*/ MCUX_CSSL_PI_PROTECT(arr1, arr2, sizeof(arr1), sizeof(arr1) + 1u),
/* void const * src, */ arr1,
/* void * dst, */ arr2,
/* uint32_t dstLength, */ sizeof(arr1),
/* uint32_t length */ sizeof(arr1) + 1u));
/* Check the return code of mcuxCsslMemory_Copy */
{
return EXIT_CODE_ERROR;
}
/* Try to copy nothing (length = 0 bytes) => should return success */
/* mcuxCsslParamIntegrity_Checksum_t chk,*/ MCUX_CSSL_PI_PROTECT(arr1, arr2, sizeof(arr1), 0u),
/* void const * src, */ arr1,
/* void * dst, */ arr2,
/* uint32_t dstLength, */ sizeof(arr1),
/* uint32_t length */ 0u));
/* Check the return code of mcuxCsslMemory_Copy */
{
return EXIT_CODE_ERROR;
}
/* Copy arr1 to arr2 => should return success */
/* mcuxCsslParamIntegrity_Checksum_t chk,*/ MCUX_CSSL_PI_PROTECT(arr1, arr2, sizeof(arr1), sizeof(arr1)),
/* void const * src, */ arr1,
/* void * dst, */ arr2,
/* uint32_t dstLength, */ sizeof(arr1),
/* uint32_t length */ sizeof(arr1)));
/* Check the return code of mcuxCsslMemory_Copy */
{
return EXIT_CODE_ERROR;
}
/* No error occurred during execution, exit with EXIT_CODE_OK */
return EXIT_CODE_OK;
}
Provides the API for the CSSL flow protection mechanism.
Definition of function identifiers for the flow protection mechanism.
Top-level include file for the CSSL memory functions.
Top-level include file for the parameter integrity protection mechanism.
#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
#define MCUXCSSLMEMORY_STATUS_INVALID_PARAMETER
A parameter was invalid.
Definition mcuxCsslMemory_Constants.h:52
#define MCUXCSSLMEMORY_STATUS_OK
The operation was successful.
Definition mcuxCsslMemory_Constants.h:48
mcuxCsslMemory_Status_t mcuxCsslMemory_Copy(mcuxCsslParamIntegrity_Checksum_t chk, void const *pSrc, void *pDst, uint32_t dstLength, uint32_t length)
Copies length bytes of data from pSrc to pDst.