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

Example for the secure set function.

Example for the secure set function

/*--------------------------------------------------------------------------*/
/* Copyright 2022-2023, 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 <stdbool.h>
#include <stdint.h>
#include <mcuxCsslMemory.h>
#include <mcuxCsslMemory_Examples.h>
MCUXCSSL_MEMORY_EX_FUNCTION(mcuxCsslMemory_SecureSet_example)
{
/* Define data array */
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_SecureSet */
{
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_SecureSet */
{
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_SecureSet */
{
return MCUXCSSLMEMORY_EX_ERROR;
}
/* Check that the function works as expected */
for (uint32_t i = 0u; i < sizeof(arr); ++i) {
if (arr[i] != 42u) {
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: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_SecureSet(mcuxCsslParamIntegrity_Checksum_t chk, void *pDst, uint8_t val, uint32_t length, uint32_t bufLength)
Set length bytes of data at pDst.