MCUX CLNS
MCUX Crypto Library Normal Secure
Loading...
Searching...
No Matches
mcuxCsslDataIntegrity_SecureCounter.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/* Copyright 2023-2024 NXP */
3/* */
4/* SPDX-License-Identifier: BSD-3-Clause */
5/* */
6/* Redistribution and use in source and binary forms, with or without */
7/* modification, are permitted provided that the following conditions are */
8/* met: */
9/* */
10/* 1. Redistributions of source code must retain the above copyright */
11/* notice, this list of conditions and the following disclaimer. */
12/* */
13/* 2. Redistributions in binary form must reproduce the above copyright */
14/* notice, this list of conditions and the following disclaimer in the */
15/* documentation and/or other materials provided with the distribution. */
16/* */
17/* 3. Neither the name of the copyright holder nor the names of its */
18/* contributors may be used to endorse or promote products derived from */
19/* this software without specific prior written permission. */
20/* */
21/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS */
22/* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
23/* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
24/* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
25/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
26/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
27/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
28/* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
29/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
30/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
31/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
32/*--------------------------------------------------------------------------*/
33
38
39#ifndef MCUXCSSLDATAINTEGRITY_SECURECOUNTER_H_
40#define MCUXCSSLDATAINTEGRITY_SECURECOUNTER_H_
41
42#include <mcuxCsslAnalysis.h>
44
45#if (1 == MCUX_CSSL_SC_USE_SW_LOCAL) && (0 == MCUX_CSSL_FP_USE_SECURE_COUNTER)
46 #error "Local SW SC is not supported for DI when FP does not use this local SW SC, as SC_ALLOC would be missing."
47#endif
48
56
57
63
64
65/****************************************************************************/
66/* Constants */
67/****************************************************************************/
68
74#define MCUX_CSSL_DI_CHECK_PASSED_IMPL (MCUX_CSSL_SC_CHECK_PASSED)
75
81#define MCUX_CSSL_DI_CHECK_FAILED_IMPL (MCUX_CSSL_SC_CHECK_FAILED)
82
83
84/****************************************************************************/
85/* Macros that depend on the implementation of the secure counter mechanism */
86/****************************************************************************/
87
88#if (1 == MCUX_CSSL_SC_USE_HW_SCM)
97#define MCUX_CSSL_DI_BACKUP_SC(backupValue) \
98 uint32_t backupValue = MCUX_CSSL_SC_REF_VALUE_IMPL(); \
99 MCUX_CSSL_SC_REF_VALUE_IMPL() = MCUX_CSSL_SC_VALUE()
100
108#define MCUX_CSSL_DI_RESTORE_SC_REF(reference) \
109 MCUX_CSSL_SC_REF_VALUE_IMPL() = (reference)
110
111#else
119#define MCUX_CSSL_DI_BACKUP_SC(backupValue) \
120 uint32_t backupValue = MCUX_CSSL_SC_VALUE()
121
129#define MCUX_CSSL_DI_RESTORE_SC_REF(reference)
130
131#endif
132
133/****************************************************************************/
134/* Initialization */
135/****************************************************************************/
136
137#if (1 == MCUX_CSSL_FP_USE_SECURE_COUNTER)
149#define MCUX_CSSL_DI_INIT_IMPL(backupValue) \
150 uint32_t backupValue = 0u
151#else
163#define MCUX_CSSL_DI_INIT_IMPL(backupValue) \
164 MCUX_CSSL_DI_BACKUP_SC(backupValue)
165#endif
166
167
168/****************************************************************************/
169/* Check */
170/****************************************************************************/
171
181#define MCUX_CSSL_DI_CHECK_IMPL(reference) \
182 MCUX_CSSL_SC_CHECK(reference)
183
184#if (1 == MCUX_CSSL_FP_USE_SECURE_COUNTER)
196#define MCUX_CSSL_DI_CHECK_EXIT_IMPL(id, reference, fail) \
197 (void)(reference)
198#else
214#define MCUX_CSSL_DI_CHECK_EXIT_IMPL(id, reference, fail) \
215 if (MCUX_CSSL_DI_CHECK_PASSED != MCUX_CSSL_DI_CHECK(reference)) \
216 { \
217 MCUX_CSSL_FP_FUNCTION_EXIT(id, fail); \
218 } \
219 MCUX_CSSL_DI_RESTORE_SC_REF(reference);
220#endif
221
222
223/****************************************************************************/
224/* Updates */
225/****************************************************************************/
226
232
241#define MCUX_CSSL_DI_RECORD_IMPL(identifier, value) \
242 MCUX_CSSL_ANALYSIS_START_PATTERN_DI_CAST() \
243 MCUX_CSSL_SC_ADD(value) \
244 MCUX_CSSL_ANALYSIS_STOP_PATTERN_DI_CAST()
245
254#define MCUX_CSSL_DI_EXPUNGE_IMPL(identifier, value) \
255 MCUX_CSSL_ANALYSIS_START_PATTERN_DI_CAST() \
256 MCUX_CSSL_SC_SUB(value) \
257 MCUX_CSSL_ANALYSIS_STOP_PATTERN_DI_CAST()
258
259#endif /* MCUXCSSLDATAINTEGRITY_SECURECOUNTER_H_ */
Provides the API for the CSSL flow protection mechanism.