MCUX CLNS
MCUX Crypto Library Normal Secure
mcuxClHash_Types.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------*/
2 /* Copyright 2020 NXP */
3 /* */
4 /* NXP Confidential. This software is owned or controlled by NXP and may */
5 /* only be used strictly in accordance with the applicable license terms. */
6 /* By expressly accepting such terms or by downloading, installing, */
7 /* activating and/or otherwise using the software, you are agreeing that */
8 /* you have read, and that you agree to comply with and are bound by, such */
9 /* license terms. If you do not agree to be bound by the applicable license */
10 /* terms, then you may not retain, install, activate or otherwise use the */
11 /* software. */
12 /*--------------------------------------------------------------------------*/
13 
18 #ifndef MCUXCLHASH_TYPES_H_
19 #define MCUXCLHASH_TYPES_H_
20 
21 #include <stdint.h>
22 #include <stddef.h>
23 #include <stdbool.h>
24 #include <mcuxClSession_Types.h>
25 
33 /***********************************************************
34  * EXTERNAL TYPES
35  **********************************************************/
43 
51 
57 
64 typedef uint32_t mcuxClHash_Status_t;
65 
68 /***********************************************************
69  * MACROS RELATED TO FUNCTION STATUS
70  **********************************************************/
71 
78 #define MCUXCLHASH_STATUS_OK ((mcuxClHash_Status_t) 0xE1E1E1E1u )
79 #define MCUXCLHASH_STATUS_ERROR ((mcuxClHash_Status_t) 0xE1E11E1Eu )
80 #define MCUXCLHASH_STATUS_FAULT_ATTACK ((mcuxClHash_Status_t) 0xE1E1F0F0u )
81 
82 
85 /***********************************************************
86  * INTERNAL TYPES
87  **********************************************************/
88 
89 /*
90  * \defgroup InternalOptions mcuxClHash internal option values. Not used by external API
91  * @{
92  */
93 #define MCUXCLHASH_INIT 0x00000011u
94 #define MCUXCLHASH_UPDATE 0x00000022u
95 #define MCUXCLHASH_FINALIZE 0x00000088u
96 /*
97  * @}
98  */
99 
100 /*
101  * \defgroup InternalCounterlengh mcuxClHash internal counter size values used for padding. Not used by external API
102  * @{
103  */
104 #define MCUXCLHASH_COUNTER_SIZE_SHA_256 8
105 #define MCUXCLHASH_COUNTER_SIZE_SHA_224 MCUXCLHASH_COUNTER_SIZE_SHA_256
106 #define MCUXCLHASH_COUNTER_SIZE_SHA_512 16
107 #define MCUXCLHASH_COUNTER_SIZE_SHA_384 MCUXCLHASH_COUNTER_SIZE_SHA_512
108 /*
109  * @}
110  */
111 
112 /*
113  * @brief Hash Context data storage structure
114  *
115  * @if MCUXCL_FEATURE_HASH_PARTIAL
116  * Maintains the data buffers associated with the state of a hash computation when using the streaming API.
117  *
118  * See #mcuxClHash_init for information about the streaming API.
119  * @endif
120  */
122 {
123  uint8_t unprocessed[128u];
124  uint8_t state[64u];
126 
127 /*
128  * @brief Hash Context counter structure
129  *
130  * Maintains the counters associated with the state of a hash computation when using the streaming API. The counters
131  * are limited to 32 bits, so only up to 2^32 bytes of data can be hashed in a single context.
132  *
133  * See #mcuxClHash_init for information about the streaming API.
134  */
135 typedef struct mcuxClHash_ContextData {
136  uint32_t unprocessedLength;
137  uint32_t processedLength;
139 
140 /*
141  * @brief Hash Context structure
142  *
143  * Maintains the state of a hash computation when using the streaming API.
144  *
145  * See #mcuxClHash_init for information about the streaming API.
146  */
148 {
151  const mcuxClHash_Algo_t * algo;
152  /* if needed: const uint8_t *const iv, */
153 };
154 
155 /*
156  * @brief Hash Engine function type
157  *
158  * This function will process one or more blocks of the Hash algorithm
159  *
160  */
161 typedef mcuxClHash_Status_Protected_t (*mcuxClHash_AlgoEngine_t)(
162  uint32_t options,
163  const uint8_t *const in,
164  uint32_t inSize,
165  uint8_t *const out
166  );
167 
168 /*
169  * @brief Hash Skeleton function type
170  *
171  * This function will accumulate, padd, etc. the input message and then process it with the Hash engine function (mcuxClHash_AlgoEngine_t)
172  *
173  */
174 typedef mcuxClHash_Status_Protected_t (*mcuxClHash_AlgoSkeleton_t)(
175  mcuxClSession_Handle_t session,
176  const mcuxClHash_Algo_t *algo,
177  mcuxClHash_ContextData_t *context,
179  const uint8_t *const in,
180  uint32_t inSize,
181  uint8_t *const out,
182  uint8_t *const rtf,
183  uint32_t options
184  );
185 
186 /*
187  * @brief DMA protection function type
188  *
189  * This function will verify if the DMA transfer of the last hardware accelerator operation finished on the expected address
190  *
191  */
192 typedef mcuxClHash_Status_Protected_t (*mcuxClHash_AlgoDmaProtection_t)(
193  uint8_t *startAddress,
194  size_t expectedLength
195  );
196 
197 /*
198  * @brief Hash Algorithm structure
199  *
200  */
202 {
203  mcuxClHash_AlgoEngine_t engine;
204  mcuxClHash_AlgoSkeleton_t skeleton;
205  mcuxClHash_AlgoSkeleton_t streamingSkeleton;
206  size_t blockSize;
207  size_t hashSize;
208  size_t stateSize;
209  uint32_t counterSize;
210  uint32_t rtfSize;
214  // SHA-224 and SHA-512/t could be supported by adding an IV field
215 };
216 
217 
218 #endif /* MCUXCLHASH_TYPES_H_ */
uint32_t mcuxClHash_Status_t
Hash Status type.
Definition: mcuxClHash_Types.h:64
mcuxClSession_Descriptor_t *const mcuxClSession_Handle_t
Type for mcuxClSession Handle.
Definition: mcuxClSession_Types.h:110
uint32_t rtfSize
Size of the Runtime Fingerprint used by the hash function; has to be set to zero when not supported.
Definition: mcuxClHash_Types.h:210
Definition: mcuxClHash_Types.h:147
uint64_t mcuxClHash_Status_Protected_t
Hash Protected Status type.
Definition: mcuxClHash_Types.h:56
uint32_t protection_token_skeleton
Protection token value for the used one-shot skeleton.
Definition: mcuxClHash_Types.h:211
mcuxClHash_AlgoEngine_t engine
Hash engine function.
Definition: mcuxClHash_Types.h:203
size_t hashSize
Size of the output of the hash algorithm.
Definition: mcuxClHash_Types.h:207
Type definitions for the mcuxClSession component.
Definition: mcuxClHash_Types.h:135
uint32_t protection_token_engine
Protection token value for the used engine.
Definition: mcuxClHash_Types.h:213
size_t blockSize
Size of the block used by the hash algorithm.
Definition: mcuxClHash_Types.h:206
size_t stateSize
Size of the state used by the hash algorithm.
Definition: mcuxClHash_Types.h:208
uint32_t counterSize
Size of the counter used by the hash algorithm.
Definition: mcuxClHash_Types.h:209
mcuxClHash_AlgoSkeleton_t streamingSkeleton
Streaming hash skeleton function.
Definition: mcuxClHash_Types.h:205
Definition: mcuxClHash_Types.h:121
mcuxClHash_AlgoSkeleton_t skeleton
One-shot hash skeleton function.
Definition: mcuxClHash_Types.h:204
Definition: mcuxClHash_Types.h:201
uint32_t protection_token_streaming_skeleton
Protection token value for the used streaming skeleton.
Definition: mcuxClHash_Types.h:212