1 | /**
|
---|
2 | ******************************************************************************
|
---|
3 | * @file stm32f4xx_hal_cryp.h
|
---|
4 | * @author MCD Application Team
|
---|
5 | * @brief Header file of CRYP HAL module.
|
---|
6 | ******************************************************************************
|
---|
7 | * @attention
|
---|
8 | *
|
---|
9 | * <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
---|
10 | * All rights reserved.</center></h2>
|
---|
11 | *
|
---|
12 | * This software component is licensed by ST under BSD 3-Clause license,
|
---|
13 | * the "License"; You may not use this file except in compliance with the
|
---|
14 | * License. You may obtain a copy of the License at:
|
---|
15 | * opensource.org/licenses/BSD-3-Clause
|
---|
16 | *
|
---|
17 | ******************************************************************************
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Define to prevent recursive inclusion -------------------------------------*/
|
---|
21 | #ifndef __STM32F4xx_HAL_CRYP_H
|
---|
22 | #define __STM32F4xx_HAL_CRYP_H
|
---|
23 |
|
---|
24 | #ifdef __cplusplus
|
---|
25 | extern "C" {
|
---|
26 | #endif
|
---|
27 |
|
---|
28 |
|
---|
29 | /* Includes ------------------------------------------------------------------*/
|
---|
30 | #include "stm32f4xx_hal_def.h"
|
---|
31 |
|
---|
32 | /** @addtogroup STM32F4xx_HAL_Driver
|
---|
33 | * @{
|
---|
34 | */
|
---|
35 | #if defined (AES) || defined (CRYP)
|
---|
36 | /** @addtogroup CRYP
|
---|
37 | * @{
|
---|
38 | */
|
---|
39 |
|
---|
40 | /* Exported types ------------------------------------------------------------*/
|
---|
41 |
|
---|
42 | /** @defgroup CRYP_Exported_Types CRYP Exported Types
|
---|
43 | * @{
|
---|
44 | */
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * @brief CRYP Init Structure definition
|
---|
48 | */
|
---|
49 |
|
---|
50 | typedef struct
|
---|
51 | {
|
---|
52 | uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
|
---|
53 | This parameter can be a value of @ref CRYP_Data_Type */
|
---|
54 | uint32_t KeySize; /*!< Used only in AES mode : 128, 192 or 256 bit key length in CRYP1.
|
---|
55 | 128 or 256 bit key length in TinyAES This parameter can be a value of @ref CRYP_Key_Size */
|
---|
56 | uint32_t *pKey; /*!< The key used for encryption/decryption */
|
---|
57 | uint32_t *pInitVect; /*!< The initialization vector used also as initialization
|
---|
58 | counter in CTR mode */
|
---|
59 | uint32_t Algorithm; /*!< DES/ TDES Algorithm ECB/CBC
|
---|
60 | AES Algorithm ECB/CBC/CTR/GCM or CCM
|
---|
61 | This parameter can be a value of @ref CRYP_Algorithm_Mode */
|
---|
62 | uint32_t *Header; /*!< used only in AES GCM and CCM Algorithm for authentication,
|
---|
63 | GCM : also known as Additional Authentication Data
|
---|
64 | CCM : named B1 composed of the associated data length and Associated Data. */
|
---|
65 | uint32_t HeaderSize; /*!< The size of header buffer in word */
|
---|
66 | uint32_t *B0; /*!< B0 is first authentication block used only in AES CCM mode */
|
---|
67 | uint32_t DataWidthUnit; /*!< Data With Unit, this parameter can be value of @ref CRYP_Data_Width_Unit*/
|
---|
68 | uint32_t HeaderWidthUnit; /*!< Header Width Unit, this parameter can be value of @ref CRYP_Header_Width_Unit*/
|
---|
69 | uint32_t KeyIVConfigSkip; /*!< CRYP peripheral Key and IV configuration skip, to config Key and Initialization
|
---|
70 | Vector only once and to skip configuration for consecutive processings.
|
---|
71 | This parameter can be a value of @ref CRYP_Configuration_Skip */
|
---|
72 |
|
---|
73 | } CRYP_ConfigTypeDef;
|
---|
74 |
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * @brief CRYP State Structure definition
|
---|
78 | */
|
---|
79 |
|
---|
80 | typedef enum
|
---|
81 | {
|
---|
82 | HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */
|
---|
83 | HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */
|
---|
84 | HAL_CRYP_STATE_BUSY = 0x02U /*!< CRYP BUSY, internal processing is ongoing */
|
---|
85 | } HAL_CRYP_STATETypeDef;
|
---|
86 |
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * @brief CRYP handle Structure definition
|
---|
90 | */
|
---|
91 |
|
---|
92 | typedef struct __CRYP_HandleTypeDef
|
---|
93 | {
|
---|
94 | #if defined (CRYP)
|
---|
95 | CRYP_TypeDef *Instance; /*!< CRYP registers base address */
|
---|
96 | #else /* AES*/
|
---|
97 | AES_TypeDef *Instance; /*!< AES Register base address */
|
---|
98 | #endif /* End AES or CRYP */
|
---|
99 |
|
---|
100 | CRYP_ConfigTypeDef Init; /*!< CRYP required parameters */
|
---|
101 |
|
---|
102 | FunctionalState AutoKeyDerivation; /*!< Used only in TinyAES to allows to bypass or not key write-up before decryption.
|
---|
103 | This parameter can be a value of ENABLE/DISABLE */
|
---|
104 |
|
---|
105 | uint32_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
|
---|
106 |
|
---|
107 | uint32_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
|
---|
108 |
|
---|
109 | __IO uint16_t CrypHeaderCount; /*!< Counter of header data */
|
---|
110 |
|
---|
111 | __IO uint16_t CrypInCount; /*!< Counter of input data */
|
---|
112 |
|
---|
113 | __IO uint16_t CrypOutCount; /*!< Counter of output data */
|
---|
114 |
|
---|
115 | uint16_t Size; /*!< length of input data in word */
|
---|
116 |
|
---|
117 | uint32_t Phase; /*!< CRYP peripheral phase */
|
---|
118 |
|
---|
119 | DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */
|
---|
120 |
|
---|
121 | DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */
|
---|
122 |
|
---|
123 | HAL_LockTypeDef Lock; /*!< CRYP locking object */
|
---|
124 |
|
---|
125 | __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */
|
---|
126 |
|
---|
127 | __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */
|
---|
128 |
|
---|
129 | uint32_t KeyIVConfig; /*!< CRYP peripheral Key and IV configuration flag, used when
|
---|
130 | configuration can be skipped */
|
---|
131 |
|
---|
132 | uint32_t SizesSum; /*!< Sum of successive payloads lengths (in bytes), stored
|
---|
133 | for a single signature computation after several
|
---|
134 | messages processing */
|
---|
135 |
|
---|
136 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
|
---|
137 | void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Input FIFO transfer completed callback */
|
---|
138 | void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Output FIFO transfer completed callback */
|
---|
139 | void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Error callback */
|
---|
140 |
|
---|
141 | void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp Init callback */
|
---|
142 | void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp DeInit callback */
|
---|
143 |
|
---|
144 | #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */
|
---|
145 | } CRYP_HandleTypeDef;
|
---|
146 |
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * @}
|
---|
150 | */
|
---|
151 |
|
---|
152 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
|
---|
153 | /** @defgroup HAL_CRYP_Callback_ID_enumeration_definition HAL CRYP Callback ID enumeration definition
|
---|
154 | * @brief HAL CRYP Callback ID enumeration definition
|
---|
155 | * @{
|
---|
156 | */
|
---|
157 | typedef enum
|
---|
158 | {
|
---|
159 | HAL_CRYP_INPUT_COMPLETE_CB_ID = 0x01U, /*!< CRYP Input FIFO transfer completed callback ID */
|
---|
160 | HAL_CRYP_OUTPUT_COMPLETE_CB_ID = 0x02U, /*!< CRYP Output FIFO transfer completed callback ID */
|
---|
161 | HAL_CRYP_ERROR_CB_ID = 0x03U, /*!< CRYP Error callback ID */
|
---|
162 |
|
---|
163 | HAL_CRYP_MSPINIT_CB_ID = 0x04U, /*!< CRYP MspInit callback ID */
|
---|
164 | HAL_CRYP_MSPDEINIT_CB_ID = 0x05U /*!< CRYP MspDeInit callback ID */
|
---|
165 |
|
---|
166 | } HAL_CRYP_CallbackIDTypeDef;
|
---|
167 | /**
|
---|
168 | * @}
|
---|
169 | */
|
---|
170 |
|
---|
171 | /** @defgroup HAL_CRYP_Callback_pointer_definition HAL CRYP Callback pointer definition
|
---|
172 | * @brief HAL CRYP Callback pointer definition
|
---|
173 | * @{
|
---|
174 | */
|
---|
175 |
|
---|
176 | typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp); /*!< pointer to a common CRYP callback function */
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * @}
|
---|
180 | */
|
---|
181 |
|
---|
182 | #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
|
---|
183 |
|
---|
184 | /* Exported constants --------------------------------------------------------*/
|
---|
185 | /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
|
---|
186 | * @{
|
---|
187 | */
|
---|
188 |
|
---|
189 | /** @defgroup CRYP_Error_Definition CRYP Error Definition
|
---|
190 | * @{
|
---|
191 | */
|
---|
192 | #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */
|
---|
193 | #define HAL_CRYP_ERROR_WRITE 0x00000001U /*!< Write error */
|
---|
194 | #define HAL_CRYP_ERROR_READ 0x00000002U /*!< Read error */
|
---|
195 | #define HAL_CRYP_ERROR_DMA 0x00000004U /*!< DMA error */
|
---|
196 | #define HAL_CRYP_ERROR_BUSY 0x00000008U /*!< Busy flag error */
|
---|
197 | #define HAL_CRYP_ERROR_TIMEOUT 0x00000010U /*!< Timeout error */
|
---|
198 | #define HAL_CRYP_ERROR_NOT_SUPPORTED 0x00000020U /*!< Not supported mode */
|
---|
199 | #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U /*!< Sequence are not respected only for GCM or CCM */
|
---|
200 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
|
---|
201 | #define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U) /*!< Invalid Callback error */
|
---|
202 | #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
|
---|
203 | /**
|
---|
204 | * @}
|
---|
205 | */
|
---|
206 |
|
---|
207 | /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit
|
---|
208 | * @{
|
---|
209 | */
|
---|
210 |
|
---|
211 | #define CRYP_DATAWIDTHUNIT_WORD 0x00000000U /*!< By default, size unit is word */
|
---|
212 | #define CRYP_DATAWIDTHUNIT_BYTE 0x00000001U /*!< By default, size unit is word */
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * @}
|
---|
216 | */
|
---|
217 |
|
---|
218 | /** @defgroup CRYP_Header_Width_Unit CRYP Header Width Unit
|
---|
219 | * @{
|
---|
220 | */
|
---|
221 |
|
---|
222 | #define CRYP_HEADERWIDTHUNIT_WORD 0x00000000U /*!< By default, header size unit is word */
|
---|
223 | #define CRYP_HEADERWIDTHUNIT_BYTE 0x00000001U /*!< By default, header size unit is byte */
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * @}
|
---|
227 | */
|
---|
228 |
|
---|
229 | /** @defgroup CRYP_Algorithm_Mode CRYP Algorithm Mode
|
---|
230 | * @{
|
---|
231 | */
|
---|
232 | #if defined(CRYP)
|
---|
233 |
|
---|
234 | #define CRYP_DES_ECB CRYP_CR_ALGOMODE_DES_ECB
|
---|
235 | #define CRYP_DES_CBC CRYP_CR_ALGOMODE_DES_CBC
|
---|
236 | #define CRYP_TDES_ECB CRYP_CR_ALGOMODE_TDES_ECB
|
---|
237 | #define CRYP_TDES_CBC CRYP_CR_ALGOMODE_TDES_CBC
|
---|
238 | #define CRYP_AES_ECB CRYP_CR_ALGOMODE_AES_ECB
|
---|
239 | #define CRYP_AES_CBC CRYP_CR_ALGOMODE_AES_CBC
|
---|
240 | #define CRYP_AES_CTR CRYP_CR_ALGOMODE_AES_CTR
|
---|
241 | #if defined (CRYP_CR_ALGOMODE_AES_GCM)
|
---|
242 | #define CRYP_AES_GCM CRYP_CR_ALGOMODE_AES_GCM
|
---|
243 | #define CRYP_AES_CCM CRYP_CR_ALGOMODE_AES_CCM
|
---|
244 | #endif /* GCM CCM defined*/
|
---|
245 | #else /* AES*/
|
---|
246 | #define CRYP_AES_ECB 0x00000000U /*!< Electronic codebook chaining algorithm */
|
---|
247 | #define CRYP_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */
|
---|
248 | #define CRYP_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */
|
---|
249 | #define CRYP_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */
|
---|
250 | #define CRYP_AES_CCM AES_CR_CHMOD_2 /*!< Counter with Cipher Mode */
|
---|
251 | #endif /* End AES or CRYP */
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * @}
|
---|
255 | */
|
---|
256 |
|
---|
257 | /** @defgroup CRYP_Key_Size CRYP Key Size
|
---|
258 | * @{
|
---|
259 | */
|
---|
260 | #if defined(CRYP)
|
---|
261 | #define CRYP_KEYSIZE_128B 0x00000000U
|
---|
262 | #define CRYP_KEYSIZE_192B CRYP_CR_KEYSIZE_0
|
---|
263 | #define CRYP_KEYSIZE_256B CRYP_CR_KEYSIZE_1
|
---|
264 | #else /* AES*/
|
---|
265 | #define CRYP_KEYSIZE_128B 0x00000000U /*!< 128-bit long key */
|
---|
266 | #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */
|
---|
267 | #endif /* End AES or CRYP */
|
---|
268 | /**
|
---|
269 | * @}
|
---|
270 | */
|
---|
271 |
|
---|
272 | /** @defgroup CRYP_Data_Type CRYP Data Type
|
---|
273 | * @{
|
---|
274 | */
|
---|
275 | #if defined(CRYP)
|
---|
276 | #define CRYP_DATATYPE_32B 0x00000000U
|
---|
277 | #define CRYP_DATATYPE_16B CRYP_CR_DATATYPE_0
|
---|
278 | #define CRYP_DATATYPE_8B CRYP_CR_DATATYPE_1
|
---|
279 | #define CRYP_DATATYPE_1B CRYP_CR_DATATYPE
|
---|
280 | #else /* AES*/
|
---|
281 | #define CRYP_DATATYPE_32B 0x00000000U /*!< 32-bit data type (no swapping) */
|
---|
282 | #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */
|
---|
283 | #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */
|
---|
284 | #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */
|
---|
285 | #endif /* End AES or CRYP */
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * @}
|
---|
289 | */
|
---|
290 |
|
---|
291 | /** @defgroup CRYP_Interrupt CRYP Interrupt
|
---|
292 | * @{
|
---|
293 | */
|
---|
294 | #if defined (CRYP)
|
---|
295 | #define CRYP_IT_INI CRYP_IMSCR_INIM /*!< Input FIFO Interrupt */
|
---|
296 | #define CRYP_IT_OUTI CRYP_IMSCR_OUTIM /*!< Output FIFO Interrupt */
|
---|
297 | #else /* AES*/
|
---|
298 | #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */
|
---|
299 | #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */
|
---|
300 | #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */
|
---|
301 | #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */
|
---|
302 | #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */
|
---|
303 | #endif /* End AES or CRYP */
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * @}
|
---|
307 | */
|
---|
308 |
|
---|
309 | /** @defgroup CRYP_Flags CRYP Flags
|
---|
310 | * @{
|
---|
311 | */
|
---|
312 | #if defined (CRYP)
|
---|
313 | /* Flags in the SR register */
|
---|
314 | #define CRYP_FLAG_IFEM CRYP_SR_IFEM /*!< Input FIFO is empty */
|
---|
315 | #define CRYP_FLAG_IFNF CRYP_SR_IFNF /*!< Input FIFO is not Full */
|
---|
316 | #define CRYP_FLAG_OFNE CRYP_SR_OFNE /*!< Output FIFO is not empty */
|
---|
317 | #define CRYP_FLAG_OFFU CRYP_SR_OFFU /*!< Output FIFO is Full */
|
---|
318 | #define CRYP_FLAG_BUSY CRYP_SR_BUSY /*!< The CRYP core is currently processing a block of data
|
---|
319 | or a key preparation (for AES decryption). */
|
---|
320 | /* Flags in the RISR register */
|
---|
321 | #define CRYP_FLAG_OUTRIS 0x01000002U /*!< Output FIFO service raw interrupt status */
|
---|
322 | #define CRYP_FLAG_INRIS 0x01000001U /*!< Input FIFO service raw interrupt status*/
|
---|
323 | #else /* AES*/
|
---|
324 | /* status flags */
|
---|
325 | #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */
|
---|
326 | #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */
|
---|
327 | #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */
|
---|
328 | #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */
|
---|
329 | /* clearing flags */
|
---|
330 | #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */
|
---|
331 | #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */
|
---|
332 | #endif /* End AES or CRYP */
|
---|
333 |
|
---|
334 | /**
|
---|
335 | * @}
|
---|
336 | */
|
---|
337 |
|
---|
338 | /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode
|
---|
339 | * @{
|
---|
340 | */
|
---|
341 |
|
---|
342 | #define CRYP_KEYIVCONFIG_ALWAYS 0x00000000U /*!< Peripheral Key and IV configuration to do systematically */
|
---|
343 | #define CRYP_KEYIVCONFIG_ONCE 0x00000001U /*!< Peripheral Key and IV configuration to do only once */
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * @}
|
---|
347 | */
|
---|
348 |
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * @}
|
---|
352 | */
|
---|
353 |
|
---|
354 | /* Exported macros -----------------------------------------------------------*/
|
---|
355 | /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
|
---|
356 | * @{
|
---|
357 | */
|
---|
358 |
|
---|
359 | /** @brief Reset CRYP handle state
|
---|
360 | * @param __HANDLE__ specifies the CRYP handle.
|
---|
361 | * @retval None
|
---|
362 | */
|
---|
363 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
|
---|
364 | #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\
|
---|
365 | (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\
|
---|
366 | (__HANDLE__)->MspInitCallback = NULL;\
|
---|
367 | (__HANDLE__)->MspDeInitCallback = NULL;\
|
---|
368 | }while(0)
|
---|
369 | #else
|
---|
370 | #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET)
|
---|
371 | #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * @brief Enable/Disable the CRYP peripheral.
|
---|
375 | * @param __HANDLE__: specifies the CRYP handle.
|
---|
376 | * @retval None
|
---|
377 | */
|
---|
378 | #if defined(CRYP)
|
---|
379 | #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_CRYPEN)
|
---|
380 | #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~CRYP_CR_CRYPEN)
|
---|
381 | #else /* AES*/
|
---|
382 | #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= AES_CR_EN)
|
---|
383 | #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~AES_CR_EN)
|
---|
384 | #endif /* End AES or CRYP */
|
---|
385 |
|
---|
386 | /** @brief Check whether the specified CRYP status flag is set or not.
|
---|
387 | * @param __FLAG__: specifies the flag to check.
|
---|
388 | * This parameter can be one of the following values for TinyAES:
|
---|
389 | * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden
|
---|
390 | * @arg @ref CRYP_IT_WRERR Write Error
|
---|
391 | * @arg @ref CRYP_IT_RDERR Read Error
|
---|
392 | * @arg @ref CRYP_IT_CCF Computation Complete
|
---|
393 | * This parameter can be one of the following values for CRYP:
|
---|
394 | * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data
|
---|
395 | * or a key preparation (for AES decryption).
|
---|
396 | * @arg CRYP_FLAG_IFEM: Input FIFO is empty
|
---|
397 | * @arg CRYP_FLAG_IFNF: Input FIFO is not full
|
---|
398 | * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending
|
---|
399 | * @arg CRYP_FLAG_OFNE: Output FIFO is not empty
|
---|
400 | * @arg CRYP_FLAG_OFFU: Output FIFO is full
|
---|
401 | * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending
|
---|
402 | * @retval The state of __FLAG__ (TRUE or FALSE).
|
---|
403 | */
|
---|
404 | #define CRYP_FLAG_MASK 0x0000001FU
|
---|
405 | #if defined(CRYP)
|
---|
406 | #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 24)) == 0x01U)?((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \
|
---|
407 | ((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)))
|
---|
408 | #else /* AES*/
|
---|
409 | #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
|
---|
410 | #endif /* End AES or CRYP */
|
---|
411 |
|
---|
412 | /** @brief Clear the CRYP pending status flag.
|
---|
413 | * @param __FLAG__: specifies the flag to clear.
|
---|
414 | * This parameter can be one of the following values:
|
---|
415 | * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
|
---|
416 | * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
|
---|
417 | * @param __HANDLE__: specifies the CRYP handle.
|
---|
418 | * @retval None
|
---|
419 | */
|
---|
420 |
|
---|
421 | #if defined(AES)
|
---|
422 | #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__))
|
---|
423 |
|
---|
424 |
|
---|
425 | /** @brief Check whether the specified CRYP interrupt source is enabled or not.
|
---|
426 | * @param __INTERRUPT__: CRYP interrupt source to check
|
---|
427 | * This parameter can be one of the following values for TinyAES:
|
---|
428 | * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
|
---|
429 | * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
|
---|
430 | * @param __HANDLE__: specifies the CRYP handle.
|
---|
431 | * @retval State of interruption (TRUE or FALSE).
|
---|
432 | */
|
---|
433 |
|
---|
434 | #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR\
|
---|
435 | & (__INTERRUPT__)) == (__INTERRUPT__))
|
---|
436 |
|
---|
437 | #endif /* AES */
|
---|
438 |
|
---|
439 | /** @brief Check whether the specified CRYP interrupt is set or not.
|
---|
440 | * @param __INTERRUPT__: specifies the interrupt to check.
|
---|
441 | * This parameter can be one of the following values for TinyAES:
|
---|
442 | * @arg @ref CRYP_IT_WRERR Write Error
|
---|
443 | * @arg @ref CRYP_IT_RDERR Read Error
|
---|
444 | * @arg @ref CRYP_IT_CCF Computation Complete
|
---|
445 | * This parameter can be one of the following values for CRYP:
|
---|
446 | * @arg CRYP_IT_INI: Input FIFO service masked interrupt status
|
---|
447 | * @arg CRYP_IT_OUTI: Output FIFO service masked interrupt status
|
---|
448 | * @param __HANDLE__: specifies the CRYP handle.
|
---|
449 | * @retval The state of __INTERRUPT__ (TRUE or FALSE).
|
---|
450 | */
|
---|
451 | #if defined(CRYP)
|
---|
452 | #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->MISR\
|
---|
453 | & (__INTERRUPT__)) == (__INTERRUPT__))
|
---|
454 | #else /* AES*/
|
---|
455 | #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
|
---|
456 | #endif /* End AES or CRYP */
|
---|
457 |
|
---|
458 | /**
|
---|
459 | * @brief Enable the CRYP interrupt.
|
---|
460 | * @param __INTERRUPT__: CRYP Interrupt.
|
---|
461 | * This parameter can be one of the following values for TinyAES:
|
---|
462 | * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
|
---|
463 | * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
|
---|
464 | * This parameter can be one of the following values for CRYP:
|
---|
465 | * @ CRYP_IT_INI : Input FIFO service interrupt mask.
|
---|
466 | * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt.
|
---|
467 | * @param __HANDLE__: specifies the CRYP handle.
|
---|
468 | * @retval None
|
---|
469 | */
|
---|
470 | #if defined(CRYP)
|
---|
471 | #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) |= (__INTERRUPT__))
|
---|
472 | #else /* AES*/
|
---|
473 | #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
|
---|
474 | #endif /* End AES or CRYP */
|
---|
475 |
|
---|
476 | /**
|
---|
477 | * @brief Disable the CRYP interrupt.
|
---|
478 | * @param __INTERRUPT__: CRYP Interrupt.
|
---|
479 | * This parameter can be one of the following values for TinyAES:
|
---|
480 | * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
|
---|
481 | * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
|
---|
482 | * This parameter can be one of the following values for CRYP:
|
---|
483 | * @ CRYP_IT_INI : Input FIFO service interrupt mask.
|
---|
484 | * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt.
|
---|
485 | * @param __HANDLE__: specifies the CRYP handle.
|
---|
486 | * @retval None
|
---|
487 | */
|
---|
488 | #if defined(CRYP)
|
---|
489 | #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) &= ~(__INTERRUPT__))
|
---|
490 | #else /* AES*/
|
---|
491 | #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
|
---|
492 | #endif /* End AES or CRYP */
|
---|
493 |
|
---|
494 | /**
|
---|
495 | * @}
|
---|
496 | */
|
---|
497 | #if defined (CRYP_CR_ALGOMODE_AES_GCM)|| defined (AES)
|
---|
498 | /* Include CRYP HAL Extended module */
|
---|
499 | #include "stm32f4xx_hal_cryp_ex.h"
|
---|
500 | #endif /* AES or GCM CCM defined*/
|
---|
501 | /* Exported functions --------------------------------------------------------*/
|
---|
502 | /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
|
---|
503 | * @{
|
---|
504 | */
|
---|
505 |
|
---|
506 | /** @addtogroup CRYP_Exported_Functions_Group1
|
---|
507 | * @{
|
---|
508 | */
|
---|
509 | HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
|
---|
510 | HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
|
---|
511 | void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
|
---|
512 | void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
|
---|
513 | HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
|
---|
514 | HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
|
---|
515 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
|
---|
516 | HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID,
|
---|
517 | pCRYP_CallbackTypeDef pCallback);
|
---|
518 | HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID);
|
---|
519 | #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
|
---|
520 | /**
|
---|
521 | * @}
|
---|
522 | */
|
---|
523 |
|
---|
524 | /** @addtogroup CRYP_Exported_Functions_Group2
|
---|
525 | * @{
|
---|
526 | */
|
---|
527 |
|
---|
528 | /* encryption/decryption ***********************************/
|
---|
529 | HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output,
|
---|
530 | uint32_t Timeout);
|
---|
531 | HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output,
|
---|
532 | uint32_t Timeout);
|
---|
533 | HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
|
---|
534 | HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
|
---|
535 | HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
|
---|
536 | HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
|
---|
537 |
|
---|
538 | /**
|
---|
539 | * @}
|
---|
540 | */
|
---|
541 |
|
---|
542 |
|
---|
543 | /** @addtogroup CRYP_Exported_Functions_Group3
|
---|
544 | * @{
|
---|
545 | */
|
---|
546 | /* Interrupt Handler functions **********************************************/
|
---|
547 | void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
|
---|
548 | HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
|
---|
549 | void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
|
---|
550 | void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
|
---|
551 | void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
|
---|
552 | uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp);
|
---|
553 |
|
---|
554 | /**
|
---|
555 | * @}
|
---|
556 | */
|
---|
557 |
|
---|
558 | /**
|
---|
559 | * @}
|
---|
560 | */
|
---|
561 |
|
---|
562 | /* Private macros --------------------------------------------------------*/
|
---|
563 | /** @defgroup CRYP_Private_Macros CRYP Private Macros
|
---|
564 | * @{
|
---|
565 | */
|
---|
566 |
|
---|
567 | /** @defgroup CRYP_IS_CRYP_Definitions CRYP Private macros to check input parameters
|
---|
568 | * @{
|
---|
569 | */
|
---|
570 | #if defined(CRYP)
|
---|
571 | #if defined (CRYP_CR_ALGOMODE_AES_GCM)
|
---|
572 | #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_DES_ECB) || \
|
---|
573 | ((ALGORITHM) == CRYP_DES_CBC) || \
|
---|
574 | ((ALGORITHM) == CRYP_TDES_ECB) || \
|
---|
575 | ((ALGORITHM) == CRYP_TDES_CBC) || \
|
---|
576 | ((ALGORITHM) == CRYP_AES_ECB) || \
|
---|
577 | ((ALGORITHM) == CRYP_AES_CBC) || \
|
---|
578 | ((ALGORITHM) == CRYP_AES_CTR) || \
|
---|
579 | ((ALGORITHM) == CRYP_AES_GCM) || \
|
---|
580 | ((ALGORITHM) == CRYP_AES_CCM))
|
---|
581 | #else /*NO GCM CCM */
|
---|
582 | #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_DES_ECB) || \
|
---|
583 | ((ALGORITHM) == CRYP_DES_CBC) || \
|
---|
584 | ((ALGORITHM) == CRYP_TDES_ECB) || \
|
---|
585 | ((ALGORITHM) == CRYP_TDES_CBC) || \
|
---|
586 | ((ALGORITHM) == CRYP_AES_ECB) || \
|
---|
587 | ((ALGORITHM) == CRYP_AES_CBC) || \
|
---|
588 | ((ALGORITHM) == CRYP_AES_CTR))
|
---|
589 | #endif /* GCM CCM defined*/
|
---|
590 | #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \
|
---|
591 | ((KEYSIZE) == CRYP_KEYSIZE_192B) || \
|
---|
592 | ((KEYSIZE) == CRYP_KEYSIZE_256B))
|
---|
593 | #else /* AES*/
|
---|
594 | #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \
|
---|
595 | ((ALGORITHM) == CRYP_AES_CBC) || \
|
---|
596 | ((ALGORITHM) == CRYP_AES_CTR) || \
|
---|
597 | ((ALGORITHM) == CRYP_AES_GCM_GMAC)|| \
|
---|
598 | ((ALGORITHM) == CRYP_AES_CCM))
|
---|
599 |
|
---|
600 |
|
---|
601 | #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \
|
---|
602 | ((KEYSIZE) == CRYP_KEYSIZE_256B))
|
---|
603 | #endif /* End AES or CRYP */
|
---|
604 |
|
---|
605 | #define IS_CRYP_DATATYPE(DATATYPE)(((DATATYPE) == CRYP_DATATYPE_32B) || \
|
---|
606 | ((DATATYPE) == CRYP_DATATYPE_16B) || \
|
---|
607 | ((DATATYPE) == CRYP_DATATYPE_8B) || \
|
---|
608 | ((DATATYPE) == CRYP_DATATYPE_1B))
|
---|
609 |
|
---|
610 | #define IS_CRYP_INIT(CONFIG)(((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \
|
---|
611 | ((CONFIG) == CRYP_KEYIVCONFIG_ONCE))
|
---|
612 | /**
|
---|
613 | * @}
|
---|
614 | */
|
---|
615 |
|
---|
616 | /**
|
---|
617 | * @}
|
---|
618 | */
|
---|
619 |
|
---|
620 |
|
---|
621 | /* Private constants ---------------------------------------------------------*/
|
---|
622 | /** @defgroup CRYP_Private_Constants CRYP Private Constants
|
---|
623 | * @{
|
---|
624 | */
|
---|
625 |
|
---|
626 | /**
|
---|
627 | * @}
|
---|
628 | */
|
---|
629 | /* Private defines -----------------------------------------------------------*/
|
---|
630 | /** @defgroup CRYP_Private_Defines CRYP Private Defines
|
---|
631 | * @{
|
---|
632 | */
|
---|
633 |
|
---|
634 | /**
|
---|
635 | * @}
|
---|
636 | */
|
---|
637 |
|
---|
638 | /* Private variables ---------------------------------------------------------*/
|
---|
639 | /** @defgroup CRYP_Private_Variables CRYP Private Variables
|
---|
640 | * @{
|
---|
641 | */
|
---|
642 |
|
---|
643 | /**
|
---|
644 | * @}
|
---|
645 | */
|
---|
646 | /* Private functions prototypes ----------------------------------------------*/
|
---|
647 | /** @defgroup CRYP_Private_Functions_Prototypes CRYP Private Functions Prototypes
|
---|
648 | * @{
|
---|
649 | */
|
---|
650 |
|
---|
651 | /**
|
---|
652 | * @}
|
---|
653 | */
|
---|
654 |
|
---|
655 | /* Private functions ---------------------------------------------------------*/
|
---|
656 | /** @defgroup CRYP_Private_Functions CRYP Private Functions
|
---|
657 | * @{
|
---|
658 | */
|
---|
659 |
|
---|
660 | /**
|
---|
661 | * @}
|
---|
662 | */
|
---|
663 |
|
---|
664 |
|
---|
665 | /**
|
---|
666 | * @}
|
---|
667 | */
|
---|
668 |
|
---|
669 |
|
---|
670 | /**
|
---|
671 | * @}
|
---|
672 | */
|
---|
673 | #endif /* TinyAES or CRYP*/
|
---|
674 |
|
---|
675 | /**
|
---|
676 | * @}
|
---|
677 | */
|
---|
678 |
|
---|
679 | #ifdef __cplusplus
|
---|
680 | }
|
---|
681 | #endif
|
---|
682 |
|
---|
683 | #endif /* __STM32F4xx_HAL_CRYP_H */
|
---|
684 |
|
---|
685 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|