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

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

Example constant-time memory set (CSSL component mcuxCsslMemory)

/*--------------------------------------------------------------------------*/
/* Copyright 2023, 2025 NXP */
/* */
/* SPDX-License-Identifier: BSD-3-Clause */
/* */
/* Redistribution and use in source and binary forms, with or without */
/* modification, are permitted provided that the following conditions are */
/* met: */
/* */
/* 1. Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* */
/* 2. Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* 3. Neither the name of the copyright holder nor the names of its */
/* contributors may be used to endorse or promote products derived from */
/* this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS */
/* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
/* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
/* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
/* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/*--------------------------------------------------------------------------*/
#include <mcuxClToolchain.h>
#include <mcuxCsslMemory.h>
#include <mcuxCsslMemory_Examples.h>
MCUXCSSL_MEMORY_EX_FUNCTION(mcuxCsslMemory_Set_example)
{
/* Define data array */
ALIGNED uint8_t arr[33] = { 0u };
/* Try to set nothing (length = 0 bytes) => should return success */
/* mcuxCsslParamIntegrity_Checksum_t chk */ MCUX_CSSL_PI_PROTECT(arr, 42u, 0u, sizeof(arr)),
/* void * pDst */ arr,
/* uint8_t val */ 42u,
/* uint32_t length */ 0u,
/* uint32_t bufLength */ sizeof(arr)
));
/* Check the return code of mcuxCsslMemory_Set */
{
return MCUXCSSLMEMORY_EX_ERROR;
}
/* Try to call the function with NULL as destination => should return invalid parameter error */
MCUX_CSSL_ANALYSIS_START_SUPPRESS_NULL_POINTER_CONSTANT("NULL is used in code")
/* mcuxCsslParamIntegrity_Checksum_t chk */ MCUX_CSSL_PI_PROTECT(NULL, 42u, sizeof(arr), sizeof(arr)),
/* void * pDst */ NULL,
/* uint8_t val */ 42u,
/* uint32_t length */ sizeof(arr),
/* uint32_t bufLength */ sizeof(arr)
));
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_NULL_POINTER_CONSTANT()
/* Check the return code of mcuxCsslMemory_Set */
{
return MCUXCSSLMEMORY_EX_ERROR;
}
/* Set all bytes in the buffer to 42 => should return success */
/* mcuxCsslParamIntegrity_Checksum_t chk */ MCUX_CSSL_PI_PROTECT(arr, 42u, sizeof(arr), sizeof(arr)),
/* void * pDst */ arr,
/* uint8_t val */ 42u,
/* uint32_t length */ sizeof(arr),
/* uint32_t bufLength */ sizeof(arr)
));
/* Check the return code of mcuxCsslMemory_Set */
{
return MCUXCSSLMEMORY_EX_ERROR;
}
return MCUXCSSLMEMORY_EX_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:643
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:797
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:678
#define MCUXCSSLMEMORY_STATUS_INVALID_PARAMETER
A parameter was invalid.
Definition mcuxCsslMemory_Constants.h:72
#define MCUXCSSLMEMORY_STATUS_OK
The operation was successful.
Definition mcuxCsslMemory_Constants.h:68
mcuxCsslMemory_Status_t mcuxCsslMemory_Set(mcuxCsslParamIntegrity_Checksum_t chk, void *pDst, uint8_t val, uint32_t length, uint32_t bufLength)
Set length bytes of data at pDst.