Example for the Function functionality of the Flow Protection component.
#include <mcuxCsslExamples.h>
#define MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY 0xC0DEu
#define MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY1 0x2EDEu
#define MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY2 0x0002u
#define MCUXCLCSSLFLOWPROTECTION_FAULT_ATTACK 0xF0FAu
uint32_t functionOnly(void);
uint32_t functionOnly(void)
{
return MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY;
}
{
}
{
}
{
}
{
);
}
{
);
);
uint32_t result = functionOnly();
);
MCUX_CSSL_ANALYSIS_START_SUPPRESS_INTEGER_OVERFLOW("Calculation does not overflow")
result += result1 + result2 + result1_ + result2_;
MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_INTEGER_OVERFLOW()
);
}
MCUX_CSSL_EX_FUNCTION(mcuxCsslFlowProtection_Function_example)
{
const uint32_t rOnly = functionOnly();
(void) rOnly;
(void) functionCall();
const uint32_t expectedReturnCode = MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY
+ MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY1
+ MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY2
+ MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY1
+ MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY2;
if (expectedReturnCode != returnCode)
{
return MCUX_CSSL_EX_ERROR;
}
#if !defined(MCUX_CSSL_FP_USE_CODE_SIGNATURE) && !defined(MCUX_CSSL_FP_USE_NONE)
{
return MCUX_CSSL_EX_ERROR;
}
#else
(void) token;
#endif
functionPointerType_t funcPtr = functionOnly2;
if (MCUXCLCSSLFLOWPROTECTION_RET_FUNCTION_ONLY2 != returnCode1)
{
return MCUX_CSSL_EX_ERROR;
}
#if !defined(MCUX_CSSL_FP_USE_CODE_SIGNATURE) && !defined(MCUX_CSSL_FP_USE_NONE)
if (!(funcPtrToken == token1))
{
return MCUX_CSSL_EX_ERROR;
}
#else
(void) token1;
#endif
return MCUX_CSSL_EX_OK;
}
Provides the API for the CSSL flow protection mechanism.
Definition of function identifiers for the flow protection mechanism.
#define MCUX_CSSL_FP_FUNCTION_DECL(...)
Declaration of a flow protected function.
Definition mcuxCsslFlowProtection.h:166
#define MCUX_CSSL_FP_FUNCTION_ENTRY(...)
Flow protection handler for the function entry point.
Definition mcuxCsslFlowProtection.h:285
#define MCUX_CSSL_FP_FUNCTION_EXIT_VOID(...)
Flow protection handler for the exit point of functions with the return type void.
Definition mcuxCsslFlowProtection.h:407
#define MCUX_CSSL_FP_PROTECTED_TYPE(resultType)
Based on a given base type, builds a return type with flow protection.
Definition mcuxCsslFlowProtection.h:138
#define MCUX_CSSL_FP_FUNCTION_DEF(...)
Definition of a flow protected function.
Definition mcuxCsslFlowProtection.h:200
#define MCUX_CSSL_FP_FUNCTION_EXIT_WITH_CHECK(...)
Flow protection handler for the function exit point which includes an actual check of the code flow.
Definition mcuxCsslFlowProtection.h:367
#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_CALL_VOID(...)
Call a flow protected void function.
Definition mcuxCsslFlowProtection.h:509
#define MCUX_CSSL_FP_FUNCTION_CALL(...)
Call a flow protected function.
Definition mcuxCsslFlowProtection.h:474
#define MCUX_CSSL_FP_FUNCTION_EXIT(...)
Flow protection handler for the function exit point.
Definition mcuxCsslFlowProtection.h:328
#define MCUX_CSSL_FP_FUNCTION_POINTER(type, definition)
Definition of a flow protected function pointer.
Definition mcuxCsslFlowProtection.h:236
#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 MCUX_CSSL_FP_FUNCTION_CALL_PROTECTED(...)
Call a flow protected function from unprotected code.
Definition mcuxCsslFlowProtection.h:547
#define MCUX_CSSL_FP_EXPECT(...)
Declaration(s) of expected code flow behavior.
Definition mcuxCsslFlowProtection.h:1420