1 /**
2   ******************************************************************************
3   * @file    stm32u5xx_hal_cryp.h
4   * @author  MCD Application Team
5   * @brief   Header file of CRYP HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2021 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32U5xx_HAL_CRYP_H
21 #define STM32U5xx_HAL_CRYP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32u5xx_hal_def.h"
29 
30 /** @addtogroup STM32U5xx_HAL_Driver
31   * @{
32   */
33 
34 #if defined(AES)
35 
36 /** @defgroup CRYP CRYP
37   * @brief CRYP HAL module driver.
38   * @{
39   */
40 
41 /* Exported types ------------------------------------------------------------*/
42 
43 /** @defgroup CRYP_Exported_Types CRYP Exported Types
44   * @{
45   */
46 
47 /**
48   * @brief CRYP Init Structure definition
49   */
50 
51 typedef struct
52 {
53   uint32_t DataType;                   /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
54                                         This parameter can be a value of @ref CRYP_Data_Type */
55   uint32_t KeySize;                    /*!< Used only in AES mode : 128, 192 or 256 bit key length in CRYP1.
56                                         128 or 256 bit key length in TinyAES This parameter can be a value
57                                         of @ref CRYP_Key_Size */
58   uint32_t *pKey;                      /*!< The key used for encryption/decryption */
59   uint32_t *pInitVect;                 /*!< The initialization vector used also as initialization
60                                          counter in CTR mode */
61   uint32_t Algorithm;                  /*!<  DES/ TDES Algorithm ECB/CBC
62                                         AES Algorithm ECB/CBC/CTR/GCM or CCM
63                                         This parameter can be a value of @ref CRYP_Algorithm_Mode */
64   uint32_t *Header;                    /*!< used only in AES GCM and CCM Algorithm for authentication,
65                                         GCM : also known as Additional Authentication Data
66                                         CCM : named B1 composed of the associated data length and Associated Data. */
67   uint32_t HeaderSize;                 /*!< The size of header buffer */
68   uint32_t *B0;                        /*!< B0 is first authentication block used only  in AES CCM mode */
69   uint32_t DataWidthUnit;              /*!< Payload Data Width Unit, this parameter can be value of @ref CRYP_Data_Width_Unit */
70   uint32_t HeaderWidthUnit;            /*!< Header Width Unit, this parameter can be value of @ref CRYP_Header_Width_Unit */
71   uint32_t KeyIVConfigSkip;            /*!< CRYP peripheral Key and IV configuration skip, to config Key and Initialization
72                                             Vector only once and to skip configuration for consecutive processings.
73                                             This parameter can be a value of @ref CRYP_Configuration_Skip */
74   uint32_t KeyMode;                    /*!< Key mode selection, this parameter can be value of @ref CRYP_Key_Mode */
75   uint32_t KeySelect;                  /*!< Only for SAES : Key selection, this parameter can be value of @ref CRYP_Key_Select */
76   uint32_t KeyProtection;              /*!< Only for SAES : Key protection, this parameter can be value of @ref CRYP_Key_Protection */
77 
78 } CRYP_ConfigTypeDef;
79 
80 
81 /**
82   * @brief  CRYP State Structure definition
83   */
84 
85 typedef enum
86 {
87   HAL_CRYP_STATE_RESET             = 0x00U,  /*!< CRYP not yet initialized or disabled  */
88   HAL_CRYP_STATE_READY             = 0x01U,  /*!< CRYP initialized and ready for use    */
89   HAL_CRYP_STATE_BUSY              = 0x02U,  /*!< CRYP BUSY, internal processing is ongoing  */
90 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
91   HAL_CRYP_STATE_SUSPENDED         = 0x03U,   /*!< CRYP suspended                        */
92 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
93 } HAL_CRYP_STATETypeDef;
94 
95 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
96 /**
97   * @brief HAL CRYP mode suspend definitions
98   */
99 typedef enum
100 {
101   HAL_CRYP_SUSPEND_NONE            = 0x00U,    /*!< CRYP processing suspension not requested */
102   HAL_CRYP_SUSPEND                 = 0x01U     /*!< CRYP processing suspension requested     */
103 } HAL_SuspendTypeDef;
104 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
105 
106 /**
107   * @brief  CRYP handle Structure definition
108   */
109 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
110 typedef struct __CRYP_HandleTypeDef
111 #else
112 typedef struct
113 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
114 {
115   AES_TypeDef                       *Instance;        /*!< AES Register base address */
116 
117   CRYP_ConfigTypeDef                Init;             /*!< CRYP required parameters */
118   uint32_t                          *pCrypInBuffPtr;  /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
119 
120   uint32_t                          *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
121 
122   __IO uint16_t                     CrypHeaderCount;   /*!< Counter of header data in words */
123 
124   __IO uint16_t                     CrypInCount;      /*!< Counter of input data in words */
125 
126   __IO uint16_t                     CrypOutCount;     /*!< Counter of output data in words */
127 
128   uint16_t                          Size;             /*!< length of input data in word or in byte, according to DataWidthUnit */
129 
130   uint32_t                          Phase;            /*!< CRYP peripheral phase */
131 
132   DMA_HandleTypeDef                 *hdmain;          /*!< CRYP In DMA handle parameters */
133 
134   DMA_HandleTypeDef                 *hdmaout;         /*!< CRYP Out DMA handle parameters */
135 
136   HAL_LockTypeDef                   Lock;             /*!< CRYP locking object */
137 
138   __IO  HAL_CRYP_STATETypeDef       State;            /*!< CRYP peripheral state */
139 
140   __IO uint32_t                     ErrorCode;        /*!< CRYP peripheral error code */
141 
142   uint32_t                          KeyIVConfig;      /*!< CRYP peripheral Key and IV configuration flag, used when
143                                                            configuration can be skipped */
144 
145   uint32_t                          SizesSum;         /*!< Sum of successive payloads lengths (in bytes), stored
146                                                            for a single signature computation after several
147                                                            messages processing */
148 
149 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
150   void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp);      /*!< CRYP Input FIFO transfer completed callback  */
151   void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp);     /*!< CRYP Output FIFO transfer completed callback */
152   void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp);       /*!< CRYP Error callback */
153 
154   void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp);    /*!< CRYP Msp Init callback  */
155   void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp);  /*!< CRYP Msp DeInit callback  */
156 
157 #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */
158 
159 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
160 
161   __IO HAL_SuspendTypeDef     SuspendRequest;          /*!< CRYP peripheral suspension request flag */
162 
163   CRYP_ConfigTypeDef          Init_saved;              /*!< copy of CRYP required parameters when processing is suspended */
164 
165   uint32_t                    *pCrypInBuffPtr_saved;   /*!< copy of CRYP input pointer when processing is suspended */
166 
167   uint32_t                    *pCrypOutBuffPtr_saved;  /*!< copy of CRYP output pointer when processing is suspended */
168 
169   uint32_t                    CrypInCount_saved;       /*!< copy of CRYP input data counter when processing is suspended */
170 
171   uint32_t                    CrypOutCount_saved;      /*!< copy of CRYP output data counter when processing is suspended */
172 
173   uint32_t                    Phase_saved;             /*!< copy of CRYP authentication phase when processing is suspended */
174 
175   __IO HAL_CRYP_STATETypeDef  State_saved;             /*!< copy of CRYP peripheral state when processing is suspended */
176 
177   uint32_t                    IV_saved[4];             /*!< copy of Initialisation Vector registers */
178 
179   uint32_t                    SUSPxR_saved[8];         /*!< copy of suspension registers */
180 
181   uint32_t                    CR_saved;                /*!< copy of CRYP control register  when processing is suspended*/
182 
183   uint32_t                    Key_saved[8];            /*!< copy of key registers */
184 
185   uint16_t                    Size_saved;              /*!< copy of input buffer size */
186 
187   uint16_t                    CrypHeaderCount_saved;   /*!< copy of CRYP header data counter when processing is suspended */
188 
189   uint32_t                    SizesSum_saved;          /*!< copy of SizesSum when processing is suspended */
190 
191   uint32_t                    ResumingFlag;            /*!< resumption flag to bypass steps already carried out */
192 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
193 
194 } CRYP_HandleTypeDef;
195 
196 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
197 
198 /**
199   * @brief  HAL CRYP Callback ID enumeration definition
200   */
201 typedef enum
202 {
203   HAL_CRYP_MSPINIT_CB_ID           = 0x00U,    /*!< CRYP MspInit callback ID                        */
204   HAL_CRYP_MSPDEINIT_CB_ID         = 0x01U,     /*!< CRYP MspDeInit callback ID                      */
205   HAL_CRYP_INPUT_COMPLETE_CB_ID    = 0x02U,    /*!< CRYP Input FIFO transfer completed callback ID  */
206   HAL_CRYP_OUTPUT_COMPLETE_CB_ID   = 0x03U,    /*!< CRYP Output FIFO transfer completed callback ID */
207   HAL_CRYP_ERROR_CB_ID             = 0x04U,    /*!< CRYP Error callback ID                          */
208 } HAL_CRYP_CallbackIDTypeDef;
209 
210 /**
211   * @brief  HAL CRYP Callback pointer definition
212   */
213 typedef  void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp);    /*!< pointer to a common CRYP callback function */
214 
215 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
216 
217 /**
218   * @}
219   */
220 
221 /* Exported constants --------------------------------------------------------*/
222 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
223   * @{
224   */
225 
226 /** @defgroup CRYP_Error_Definition   CRYP Error Definition
227   * @{
228   */
229 #define HAL_CRYP_ERROR_NONE              0x00000000U  /*!< No error        */
230 #define HAL_CRYP_ERROR_WRITE             0x00000001U  /*!< Write error     */
231 #define HAL_CRYP_ERROR_READ              0x00000002U  /*!< Read error      */
232 #define HAL_CRYP_ERROR_DMA               0x00000004U  /*!< DMA error       */
233 #define HAL_CRYP_ERROR_BUSY              0x00000008U  /*!< Busy flag error */
234 #define HAL_CRYP_ERROR_TIMEOUT           0x00000010U  /*!< Timeout error */
235 #define HAL_CRYP_ERROR_NOT_SUPPORTED     0x00000020U  /*!< Not supported mode */
236 #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U  /*!< Sequence are not respected only for GCM or CCM */
237 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
238 #define HAL_CRYP_ERROR_INVALID_CALLBACK  ((uint32_t)0x00000080U)    /*!< Invalid Callback error  */
239 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
240 #define HAL_CRYP_ERROR_KEY               0x00000100U  /*!< Key error        */
241 /**
242   * @}
243   */
244 
245 /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit
246   * @{
247   */
248 
249 #define CRYP_DATAWIDTHUNIT_WORD   0x00000000U  /*!< By default, size unit is word */
250 #define CRYP_DATAWIDTHUNIT_BYTE   0x00000001U  /*!< By default, size unit is byte */
251 
252 /**
253   * @}
254   */
255 
256 /** @defgroup CRYP_Header_Width_Unit CRYP Header Width Unit
257   * @{
258   */
259 
260 #define CRYP_HEADERWIDTHUNIT_WORD   0x00000000U  /*!< By default, header size unit is word */
261 #define CRYP_HEADERWIDTHUNIT_BYTE   0x00000001U  /*!< By default, header size unit is byte */
262 
263 /**
264   * @}
265   */
266 
267 /** @defgroup CRYP_Algorithm_Mode CRYP Algorithm Mode
268   * @{
269   */
270 
271 #define CRYP_AES_ECB            0x00000000U                       /*!< Electronic codebook chaining algorithm                   */
272 #define CRYP_AES_CBC            AES_CR_CHMOD_0                    /*!< Cipher block chaining algorithm                          */
273 #define CRYP_AES_CTR            AES_CR_CHMOD_1                    /*!< Counter mode chaining algorithm                          */
274 #define CRYP_AES_GCM_GMAC       (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */
275 #define CRYP_AES_CCM            AES_CR_CHMOD_2                    /*!< Counter with Cipher Mode                                 */
276 
277 /**
278   * @}
279   */
280 
281 /** @defgroup CRYP_Key_Size CRYP Key Size
282   * @{
283   */
284 
285 #define CRYP_KEYSIZE_128B         0x00000000U          /*!< 128-bit long key */
286 #define CRYP_KEYSIZE_256B         AES_CR_KEYSIZE       /*!< 256-bit long key */
287 
288 /**
289   * @}
290   */
291 
292 /** @defgroup CRYP_Key_Mode CRYP Key Mode
293   * @{
294   */
295 
296 #define CRYP_KEYMODE_NORMAL         0x00000000U         /*!< Normal key usage, Key registers are freely usable */
297 #define CRYP_KEYMODE_SHARED         AES_CR_KMOD_1       /*!< Shared key */
298 #define CRYP_KEYMODE_WRAPPED        AES_CR_KMOD_0       /*!< Only for SAES, Wrapped key: to encrypt or decrypt AES keys */
299 
300 /**
301   * @}
302   */
303 
304 /** @defgroup CRYP_Key_Select CRYP Key Select
305   * @{
306   */
307 
308 #define CRYP_KEYSEL_NORMAL       0x00000000U           /*!< Normal key, key registers SAES_KEYx or CRYP_KEYx */
309 #define CRYP_KEYSEL_HW           AES_CR_KEYSEL_0       /*!< Only for SAES, Hardware key : derived hardware unique key (DHUK 256-bit) */
310 #define CRYP_KEYSEL_SW           AES_CR_KEYSEL_1       /*!< Only for SAES, Software key : boot hardware key BHK (256-bit) */
311 #define CRYP_KEYSEL_HSW          AES_CR_KEYSEL_2       /*!< Only for SAES, DHUK XOR BHK Hardware unique key XOR software key */
312 
313 /**
314   * @}
315   */
316 
317 /** @defgroup CRYP_Key_ShareID CRYP Key Share ID
318   * @{
319   */
320 
321 #define CRYP_KSHAREID_AES         0x00000000U          /*!< Share SAES Key with AES peripheral */
322 
323 /**
324   * @}
325   */
326 
327 /** @defgroup CRYP_Key_Protection CRYP Key Protection
328   * @{
329   */
330 
331 #define CRYP_KEYPROT_ENABLE         AES_CR_KEYPROT      /*!< Only for SAES, Key protection between 2 applications with different security contexts */
332 #define CRYP_KEYPROT_DISABLE        0x00000000U         /*!< Only for SAES, Key not protected between 2 applications with different security contexts */
333 /**
334   * @}
335   */
336 
337 
338 /** @defgroup CRYP_Data_Type CRYP Data Type
339   * @{
340   */
341 
342 #define CRYP_NO_SWAP         0x00000000U             /*!< 32-bit data type (no swapping)        */
343 #define CRYP_HALFWORD_SWAP   AES_CR_DATATYPE_0       /*!< 16-bit data type (half-word swapping) */
344 #define CRYP_BYTE_SWAP       AES_CR_DATATYPE_1       /*!< 8-bit data type (byte swapping)       */
345 #define CRYP_BIT_SWAP        AES_CR_DATATYPE         /*!< 1-bit data type (bit swapping)        */
346 
347 /**
348   * @}
349   */
350 
351 /** @defgroup CRYP_Interrupt  CRYP Interrupt
352   * @{
353   */
354 #define CRYP_IT_CCFIE     AES_IER_CCFIE /*!< Computation Complete interrupt enable */
355 #define CRYP_IT_RWEIE     AES_IER_RWEIE /*!< Read or write Error interrupt enable  */
356 #define CRYP_IT_KEIE      AES_IER_KEIE /*!< Key error interrupt enable  */
357 
358 /**
359   * @}
360   */
361 
362 /** @defgroup CRYP_Flags CRYP Flags
363   * @{
364   */
365 
366 #define CRYP_FLAG_BUSY    AES_SR_BUSY   /*!< GCM process suspension forbidden
367                                              also set when transferring a shared key from SAES peripheral   */
368 #define CRYP_FLAG_WRERR   (AES_SR_WRERR | 0x80000000U)  /*!< Write Error flag                     */
369 #define CRYP_FLAG_RDERR   (AES_SR_RDERR | 0x80000000U) /*!< Read error  flag                     */
370 #define CRYP_FLAG_CCF     AES_SR_CCF    /*!< Computation completed flag as  AES_ISR_CCF         */
371 #define CRYP_FLAG_KEYVALID     AES_SR_KEYVALID    /*!< Key Valid flag            */
372 #define CRYP_FLAG_KEIF     AES_ISR_KEIF  /*Key error interrupt flag */
373 #define CRYP_FLAG_RWEIF    AES_ISR_RWEIF /*Read or write error Interrupt flag */
374 
375 
376 /**
377   * @}
378   */
379 
380 /** @defgroup CRYP_CLEAR_Flags CRYP CLEAR Flags
381   * @{
382   */
383 
384 #define CRYP_CLEAR_CCF      AES_ICR_CCF    /* Computation Complete Flag Clear */
385 #define CRYP_CLEAR_RWEIF    AES_ICR_RWEIF  /* Clear Error Flag : RWEIF in AES_ISR and
386                                               both RDERR and WRERR flags in AES_SR */
387 #define CRYP_CLEAR_KEIF     AES_ICR_KEIF   /* Clear Key Error Flag: KEIF in AES_ISR */
388 
389 /**
390   * @}
391   */
392 
393 /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode
394   * @{
395   */
396 
397 #define CRYP_KEYIVCONFIG_ALWAYS        0x00000000U            /*!< Peripheral Key and IV configuration to do systematically */
398 #define CRYP_KEYIVCONFIG_ONCE          0x00000001U            /*!< Peripheral Key and IV configuration to do only once      */
399 #define CRYP_KEYNOCONFIG               0x00000002U            /*!< Peripheral Key configuration to not do */
400 
401 /**
402   * @}
403   */
404 
405 
406 /**
407   * @}
408   */
409 
410 /* Exported macros -----------------------------------------------------------*/
411 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
412   * @{
413   */
414 
415 /** @brief Reset CRYP handle state
416   * @param  __HANDLE__ specifies the CRYP handle.
417   * @retval None
418   */
419 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
420 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\
421                                                       (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\
422                                                       (__HANDLE__)->MspInitCallback = NULL;\
423                                                       (__HANDLE__)->MspDeInitCallback = NULL;\
424                                                      }while(0U)
425 #else
426 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET)
427 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
428 
429 /**
430   * @brief  Enable/Disable the CRYP peripheral.
431   * @param  __HANDLE__ specifies the CRYP handle.
432   * @retval None
433   */
434 
435 #define __HAL_CRYP_ENABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR |=  AES_CR_EN)
436 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &=  ~AES_CR_EN)
437 
438 
439 /** @brief  Check whether the specified CRYP status flag is set or not.
440   * @param  __HANDLE__ specifies the CRYP handle.
441   * @param  __FLAG__ specifies the flag to check.
442   *         This parameter can be one of the following values for TinyAES:
443   *            @arg @ref CRYP_FLAG_KEYVALID Key valid flag
444   *            @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden or
445   *                                     transferring a shared key from SAES IP.
446   *            @arg @ref CRYP_FLAG_WRERR Write Error flag
447   *            @arg @ref CRYP_FLAG_RDERR Read Error flag
448   *            @arg @ref CRYP_FLAG_CCF Computation Complete flag
449   *            @arg @ref CRYP_FLAG_KEIF Key error flag
450   *            @arg @ref CRYP_FLAG_RWEIF Read/write Error flag
451 
452   * @retval The state of __FLAG__ (TRUE or FALSE).
453   */
454 
455 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (\
456                                                    ((__FLAG__) == CRYP_FLAG_KEYVALID )?(((__HANDLE__)->Instance->SR \
457                                                        & (CRYP_FLAG_KEYVALID)) == (CRYP_FLAG_KEYVALID)) : \
458                                                    ((__FLAG__) == CRYP_FLAG_BUSY )?(((__HANDLE__)->Instance->SR \
459                                                        & (CRYP_FLAG_BUSY)) == (CRYP_FLAG_BUSY)) : \
460                                                    ((__FLAG__) == CRYP_FLAG_WRERR )?(((__HANDLE__)->Instance->SR \
461                                                        & (CRYP_FLAG_WRERR & 0x7FFFFFFFU)) == \
462                                                        (CRYP_FLAG_WRERR & 0x7FFFFFFFU)) : \
463                                                    ((__FLAG__) == CRYP_FLAG_RDERR )?(((__HANDLE__)->Instance->SR \
464                                                        & (CRYP_FLAG_RDERR & 0x7FFFFFFFU)) == \
465                                                        (CRYP_FLAG_RDERR & 0x7FFFFFFFU)) : \
466                                                    ((__FLAG__) == CRYP_FLAG_KEIF )?(((__HANDLE__)->Instance->ISR \
467                                                        & (CRYP_FLAG_KEIF)) == (CRYP_FLAG_KEIF)) : \
468                                                    ((__FLAG__) == CRYP_FLAG_RWEIF )?(((__HANDLE__)->Instance->ISR \
469                                                        & (CRYP_FLAG_RWEIF)) == (CRYP_FLAG_RWEIF)) : \
470                                                    (((__HANDLE__)->Instance->ISR & (CRYP_FLAG_CCF)) == (CRYP_FLAG_CCF)))
471 
472 /** @brief  Clear the CRYP pending status flag.
473   * @param  __HANDLE__ specifies the CRYP handle.
474   * @param  __FLAG__ specifies the flag to clear.
475   *         This parameter can be one of the following values:
476   *            @arg @ref CRYP_CLEAR_RWEIF Read (RDERR), Write (WRERR) or Read/write (RWEIF) Error  Flag Clear
477   *            @arg @ref CRYP_CLEAR_CCF Computation Complete Flag (CCF) Clear
478   *            @arg @ref CRYP_CLEAR_KEIF Key error interrupt flag clear
479   * @retval None
480   */
481 
482 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->ICR, (__FLAG__))
483 
484 
485 /** @brief  Check whether the specified CRYP interrupt source is enabled or not.
486   * @param  __HANDLE__ specifies the CRYP handle.
487   * @param __INTERRUPT__ CRYP interrupt source to check
488   *         This parameter can be one of the following values for TinyAES:
489   *            @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR)
490   *            @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
491   *            @arg @ref CRYP_IT_KEIE Key error interrupt
492   * @retval State of interruption (TRUE or FALSE).
493   */
494 
495 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER\
496                                                               & (__INTERRUPT__)) == (__INTERRUPT__))
497 
498 /**
499   * @brief  Enable the CRYP interrupt.
500   * @param  __HANDLE__ specifies the CRYP handle.
501   * @param  __INTERRUPT__ CRYP Interrupt.
502   *         This parameter can be one of the following values for TinyAES:
503   *            @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR)
504   *            @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
505   *            @arg @ref CRYP_IT_KEIE Key error interrupt
506   * @retval None
507   */
508 
509 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
510 
511 /**
512   * @brief  Disable the CRYP interrupt.
513   * @param  __HANDLE__ specifies the CRYP handle.
514   * @param  __INTERRUPT__ CRYP Interrupt.
515   *         This parameter can be one of the following values for TinyAES:
516   *            @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR)
517   *            @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
518   *            @arg @ref CRYP_IT_KEIE Key error interrupt
519   * @retval None
520   */
521 
522 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
523 
524 /**
525   * @}
526   */
527 
528 /* Include CRYP HAL Extended module */
529 #include "stm32u5xx_hal_cryp_ex.h"
530 
531 /* Exported functions --------------------------------------------------------*/
532 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
533   * @{
534   */
535 
536 /** @addtogroup CRYP_Exported_Functions_Group1
537   * @{
538   */
539 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
540 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
541 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
542 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
543 HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
544 HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
545 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
546 HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID,
547                                             pCRYP_CallbackTypeDef pCallback);
548 HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID);
549 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
550 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
551 void HAL_CRYP_ProcessSuspend(CRYP_HandleTypeDef *hcryp);
552 HAL_StatusTypeDef HAL_CRYP_Suspend(CRYP_HandleTypeDef *hcryp);
553 HAL_StatusTypeDef HAL_CRYP_Resume(CRYP_HandleTypeDef *hcryp);
554 #endif /* defined (USE_HAL_CRYP_SUSPEND_RESUME) */
555 /**
556   * @}
557   */
558 
559 /** @addtogroup CRYP_Exported_Functions_Group2
560   * @{
561   */
562 
563 /* encryption/decryption ***********************************/
564 HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput,
565                                    uint32_t Timeout);
566 HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput,
567                                    uint32_t Timeout);
568 HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput);
569 HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput);
570 HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput);
571 HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *pInput, uint16_t Size, uint32_t *pOutput);
572 
573 /**
574   * @}
575   */
576 
577 
578 /** @addtogroup CRYP_Exported_Functions_Group3
579   * @{
580   */
581 /* Interrupt Handler functions  **********************************************/
582 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
583 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
584 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
585 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
586 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
587 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp);
588 
589 /**
590   * @}
591   */
592 
593 /**
594   * @}
595   */
596 
597 /* Private macros --------------------------------------------------------*/
598 /** @defgroup CRYP_Private_Macros CRYP Private Macros
599   * @{
600   */
601 
602 #define IS_CRYP_INSTANCE(INSTANCE)(((INSTANCE) == AES)   || \
603                                    ((INSTANCE) == SAES))
604 
605 #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB)      || \
606                                       ((ALGORITHM)  == CRYP_AES_CBC)     || \
607                                       ((ALGORITHM)  == CRYP_AES_CTR)     || \
608                                       ((ALGORITHM)  == CRYP_AES_GCM_GMAC)|| \
609                                       ((ALGORITHM)  == CRYP_AES_CCM))
610 
611 
612 #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B)   || \
613                                  ((KEYSIZE) == CRYP_KEYSIZE_256B))
614 
615 #define IS_CRYP_DATATYPE(DATATYPE)(((DATATYPE) == CRYP_NO_SWAP) || \
616                                    ((DATATYPE) == CRYP_HALFWORD_SWAP) || \
617                                    ((DATATYPE) == CRYP_BYTE_SWAP)  || \
618                                    ((DATATYPE) == CRYP_BIT_SWAP))
619 
620 #define IS_CRYP_INIT(CONFIG)(((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \
621                              ((CONFIG) == CRYP_KEYIVCONFIG_ONCE))
622 
623 #define IS_CRYP_BUFFERSIZE(ALGO, DATAWIDTH, SIZE)                                             \
624   (((((ALGO) == CRYP_AES_CTR)) &&                                             \
625     ((((DATAWIDTH) == CRYP_DATAWIDTHUNIT_WORD) && (((SIZE) % 4U) == 0U))           || \
626      (((DATAWIDTH) == CRYP_DATAWIDTHUNIT_BYTE) && (((SIZE) % 16U) == 0U))))        || \
627    (((ALGO) == CRYP_AES_ECB) || ((ALGO) == CRYP_AES_CBC)                  || \
628     ((ALGO)== CRYP_AES_GCM_GMAC) || ((ALGO) == CRYP_AES_CCM)))
629 
630 
631 /**
632   * @}
633   */
634 
635 
636 /* Private constants ---------------------------------------------------------*/
637 /* Private defines -----------------------------------------------------------*/
638 /** @defgroup CRYP_Private_Defines CRYP Private Defines
639   * @{
640   */
641 
642 /**
643   * @}
644   */
645 
646 /* Private variables ---------------------------------------------------------*/
647 /* Private functions ---------------------------------------------------------*/
648 /** @defgroup CRYP_Private_Functions CRYP Private Functions
649   * @{
650   */
651 
652 /**
653   * @}
654   */
655 
656 /**
657   * @}
658   */
659 
660 #endif /* AES */
661 /**
662   * @}
663   */
664 
665 #ifdef __cplusplus
666 }
667 #endif
668 
669 #endif /* STM32U5xx_HAL_CRYP_H */
670