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-2024 NXP */
/* */
/* NXP 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 <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 */ mcuxCsslParamIntegrity_Protect(4u, arr, 42u, 0u, sizeof(arr)),
/* void * pDst */ arr,
/* uint8_t val */ 42u,
/* size_t length */ 0u,
/* size_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_PATTERN_NULL_POINTER_CONSTANT()
/* mcuxCsslParamIntegrity_Checksum_t chk */ mcuxCsslParamIntegrity_Protect(4u, NULL, 42u, sizeof(arr), sizeof(arr)),
/* void * pDst */ NULL,
/* uint8_t val */ 42u,
/* size_t length */ sizeof(arr),
/* size_t bufLength */ sizeof(arr)
));
MCUX_CSSL_ANALYSIS_STOP_PATTERN_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 */ mcuxCsslParamIntegrity_Protect(4u, arr, 42u, sizeof(arr), sizeof(arr)),
/* void * pDst */ arr,
/* uint8_t val */ 42u,
/* size_t length */ sizeof(arr),
/* size_t bufLength */ sizeof(arr)
));
/* Check the return code of mcuxCsslMemory_Set */
{
return MCUXCSSLMEMORY_EX_ERROR;
}
return MCUXCSSLMEMORY_EX_OK;
}
static mcuxClEls_EccByte_t ecc_public_key_client[MCUXCLELS_ECC_PUBLICKEY_SIZE] ALIGNED
Destination buffer to receive the public key of the mcuxClEls_EccKeyGen_Async operation.
Definition mcuxClEls_Tls_Master_Key_Session_Keys_example.c:33
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:581
#define MCUX_CSSL_FP_FUNCTION_CALLED(...)
Expectation of a called function.
Definition mcuxCsslFlowProtection.h:735
#define MCUX_CSSL_FP_FUNCTION_CALL_END(...)
End a function call section started by MCUX_CSSL_FP_FUNCTION_CALL_BEGIN.
Definition mcuxCsslFlowProtection.h:616
#define MCUXCSSLMEMORY_STATUS_INVALID_PARAMETER
A parameter was invalid.
Definition mcuxCsslMemory_Constants.h:43
#define MCUXCSSLMEMORY_STATUS_OK
The operation was successful.
Definition mcuxCsslMemory_Constants.h:40
mcuxCsslMemory_Status_t mcuxCsslMemory_Set(mcuxCsslParamIntegrity_Checksum_t chk, void *pDst, uint8_t val, size_t length, size_t bufLength)
Set length bytes of data at pDst.
mcuxCsslParamIntegrity_Checksum_t mcuxCsslParamIntegrity_Protect(size_t nargs,...)
Calculates a parameter checksum.