1 /**
2   ******************************************************************************
3   * @file    stm32h7rsxx_hal_cryp.h
4   * @author  MCD Application Team
5   * @brief   Header file of CRYP HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 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 STM32H7RSxx_HAL_CRYP_H
21 #define STM32H7RSxx_HAL_CRYP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #if defined(USE_HAL_SAES_ONLY) && (USE_HAL_SAES_ONLY == 1U)
28 #if !defined(USE_HAL_CRYP_ONLY)
29 #define USE_HAL_CRYP_ONLY       0U
30 #elif (USE_HAL_CRYP_ONLY == 1U)
31 #error ' USE_HAL_CRYP_ONLY and USE_HAL_SAES_ONLY cannot be set both to 1U '
32 #endif /* defined (USE_HAL_CRYP_ONLY) */
33 #endif /* defined (USE_HAL_SAES_ONLY) */
34 
35 #if defined(USE_HAL_CRYP_ONLY) && (USE_HAL_CRYP_ONLY == 1U)
36 #if !defined(USE_HAL_SAES_ONLY)
37 #define USE_HAL_SAES_ONLY       0U
38 #elif (USE_HAL_SAES_ONLY == 1U)
39 #error ' USE_HAL_CRYP_ONLY and USE_HAL_SAES_ONLY cannot be set both to 1U '
40 #endif /* defined (USE_HAL_SAES_ONLY) */
41 #endif /* defined (USE_HAL_CRYP_ONLY) */
42 
43 /* Includes ------------------------------------------------------------------*/
44 #include "stm32h7rsxx_hal_def.h"
45 
46 /** @addtogroup STM32H7RSxx_HAL_Driver
47   * @{
48   */
49 #if defined (CRYP)
50 /** @addtogroup CRYP
51   * @{
52   */
53 
54 /* Exported types ------------------------------------------------------------*/
55 /** @defgroup CRYP_Exported_Types CRYP Exported Types
56   * @{
57   */
58 
59 /**
60   * @brief CRYP Init Structure definition
61   */
62 
63 typedef struct
64 {
65   uint32_t DataType;                   /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
66                                         This parameter can be a value of @ref CRYP_Data_Type */
67   uint32_t KeySize;                    /*!< Used only in AES mode : 128, 192 or 256 bit key length in CRYP1.
68                                         This parameter can be a value of @ref CRYP_Key_Size */
69   uint32_t *pKey;                      /*!< The key used for encryption/decryption */
70   uint32_t *pInitVect;                 /*!< The initialization vector used also as initialization
71                                          counter in CTR mode */
72   uint32_t Algorithm;                  /*!< AES Algorithm ECB/CBC/CTR/GCM or CCM
73                                         This parameter can be a value of @ref CRYP_CR_ALGOMODE */
74   uint32_t *Header;                    /*!< used only in AES GCM and CCM Algorithm for authentication,
75                                         GCM : also known as Additional Authentication Data
76                                         CCM : named B1 composed of the associated data length and Associated Data. */
77   uint32_t HeaderSize;                 /*!< The size of header buffer in word  */
78   uint32_t *B0;                        /*!< B0 is first authentication block used only in AES CCM mode */
79   uint32_t DataWidthUnit;              /*!< Data With Unit, this parameter can be value of @ref CRYP_Data_Width_Unit*/
80   uint32_t HeaderWidthUnit;            /*!< Header Width Unit, this parameter can be value
81                                             of @ref CRYP_Header_Width_Unit */
82   uint32_t KeyIVConfigSkip;            /*!< CRYP peripheral Key and IV configuration skip,
83                                             to configure Key and Initialization
84                                             Vector only once and to skip configuration for consecutive processing.
85                                         This parameter can be a value of @ref CRYP_Configuration_Skip */
86   uint32_t KeyMode;                    /*!< Key mode selection, this parameter can be a value of @ref CRYP_Key_Mode */
87   uint32_t KeySelect;                  /*!< Only for SAES : Key selection, this parameter can be a value
88                                             of @ref CRYP_Key_Select */
89 
90 } CRYP_ConfigTypeDef;
91 
92 
93 /**
94   * @brief  CRYP State Structure definition
95   */
96 
97 typedef enum
98 {
99   HAL_CRYP_STATE_RESET             = 0x00U,  /*!< CRYP not yet initialized or disabled       */
100   HAL_CRYP_STATE_READY             = 0x01U,  /*!< CRYP initialized and ready for use         */
101   HAL_CRYP_STATE_BUSY              = 0x02U,  /*!< CRYP BUSY, internal processing is ongoing  */
102 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
103   HAL_CRYP_STATE_SUSPENDED         = 0x03U,  /*!< CRYP suspended                             */
104 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
105 } HAL_CRYP_STATETypeDef;
106 
107 
108 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
109 /**
110   * @brief HAL CRYP mode suspend definitions
111   */
112 
113 typedef enum
114 {
115   HAL_CRYP_SUSPEND_NONE            = 0x00U,    /*!< CRYP processing suspension not requested */
116   HAL_CRYP_SUSPEND                 = 0x01U     /*!< CRYP processing suspension requested     */
117 } HAL_SuspendTypeDef;
118 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
119 
120 /**
121   * @brief  CRYP handle Structure definition
122   */
123 
124 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
125 typedef struct __CRYP_HandleTypeDef
126 #else
127 typedef struct
128 #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */
129 {
130   void                              *Instance;        /*!< CRYP or SAES registers base address */
131 
132   CRYP_ConfigTypeDef                Init;             /*!< CRYP required parameters */
133 
134   uint32_t                          *pCrypInBuffPtr;  /*!< Pointer to CRYP processing (encryption, decryption,...)
135                                                            buffer */
136 
137   uint32_t                          *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...)
138                                                            buffer */
139 
140   __IO uint16_t                     CrypHeaderCount;  /*!< Counter of header data */
141 
142   __IO uint16_t                     CrypInCount;      /*!< Counter of input data */
143 
144   __IO uint16_t                     CrypOutCount;     /*!< Counter of output data */
145 
146   uint16_t                          Size;             /*!< length of input data in word or in byte,
147                                                            according to DataWidthUnit */
148 
149   uint32_t                          Phase;            /*!< CRYP peripheral phase */
150 
151   DMA_HandleTypeDef                 *hdmain;          /*!< CRYP In DMA handle parameters */
152 
153   DMA_HandleTypeDef                 *hdmaout;         /*!< CRYP Out DMA handle parameters */
154 
155   HAL_LockTypeDef                   Lock;             /*!< CRYP locking object */
156 
157   __IO  HAL_CRYP_STATETypeDef       State;            /*!< CRYP peripheral state */
158 
159   __IO uint32_t                     ErrorCode;        /*!< CRYP peripheral error code */
160 
161   uint32_t                          Version;          /*!< CRYP1 IP version*/
162 
163   uint32_t                          KeyIVConfig;      /*!< CRYP peripheral Key and IV configuration flag, used when
164                                                            configuration can be skipped */
165 
166   uint32_t                          SizesSum;         /*!< Sum of successive payloads lengths (in bytes), stored
167                                                            for a single signature computation after several
168                                                            messages processing */
169 
170 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
171   void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp);      /*!< CRYP Input FIFO transfer completed callback  */
172   void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp);     /*!< CRYP Output FIFO transfer completed callback */
173   void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp);       /*!< CRYP Error callback */
174 
175   void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp);    /*!< CRYP Msp Init callback  */
176   void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp);  /*!< CRYP Msp DeInit callback  */
177 
178 #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */
179 
180 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
181 
182   __IO HAL_SuspendTypeDef     SuspendRequest;          /*!< CRYP peripheral suspension request flag */
183 
184   CRYP_ConfigTypeDef          Init_saved;              /*!< copy of CRYP required parameters when processing
185                                                             is suspended */
186 
187   uint32_t                    *pCrypInBuffPtr_saved;   /*!< copy of CRYP input pointer when processing
188                                                             is suspended */
189 
190   uint32_t                    *pCrypOutBuffPtr_saved;  /*!< copy of CRYP output pointer when processing
191                                                             is suspended */
192 
193   uint32_t                    CrypInCount_saved;       /*!< copy of CRYP input data counter when processing
194                                                             is suspended */
195 
196   uint32_t                    CrypOutCount_saved;      /*!< copy of CRYP output data counter when processing
197                                                             is suspended */
198 
199   uint32_t                    Phase_saved;             /*!< copy of CRYP authentication phase when processing
200                                                             is suspended */
201 
202   __IO HAL_CRYP_STATETypeDef  State_saved;             /*!< copy of CRYP peripheral state when processing
203                                                             is suspended */
204 
205   uint32_t                    IV_saved[4];             /*!< copy of Initialisation Vector registers */
206 
207   uint32_t                    SUSPxR_saved[16];        /*!< copy of suspension registers */
208 
209   uint32_t                    CR_saved;                /*!< copy of CRYP control register  when processing
210                                                             is suspended*/
211 
212   uint32_t                    Key_saved[8];            /*!< copy of key registers */
213 
214   uint16_t                    Size_saved;              /*!< copy of input buffer size */
215 
216   uint16_t                    CrypHeaderCount_saved;   /*!< copy of CRYP header data counter when processing
217                                                             is suspended */
218 
219   uint32_t                    SizesSum_saved;          /*!< copy of SizesSum when processing is suspended */
220 
221   uint32_t                    ResumingFlag;            /*!< resumption flag to bypass steps already carried out */
222 
223   uint32_t                    SuspendedProcessing;     /*< Report whether interruption or DMA-mode processing
224                                                            was suspended */
225 #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
226 
227 } CRYP_HandleTypeDef;
228 
229 
230 /**
231   * @}
232   */
233 
234 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
235 /** @defgroup HAL_CRYP_Callback_ID_enumeration_definition HAL CRYP Callback ID enumeration definition
236   * @brief  HAL CRYP Callback ID enumeration definition
237   * @{
238   */
239 typedef enum
240 {
241   HAL_CRYP_INPUT_COMPLETE_CB_ID    = 0x01U,    /*!< CRYP Input FIFO transfer completed callback ID  */
242   HAL_CRYP_OUTPUT_COMPLETE_CB_ID   = 0x02U,    /*!< CRYP Output FIFO transfer completed callback ID */
243   HAL_CRYP_ERROR_CB_ID             = 0x03U,    /*!< CRYP Error callback ID                          */
244   HAL_CRYP_MSPINIT_CB_ID           = 0x04U,    /*!< CRYP MspInit callback ID                        */
245   HAL_CRYP_MSPDEINIT_CB_ID         = 0x05U     /*!< CRYP MspDeInit callback ID                      */
246 
247 } HAL_CRYP_CallbackIDTypeDef;
248 /**
249   * @}
250   */
251 
252 /** @defgroup HAL_CRYP_Callback_pointer_definition HAL CRYP Callback pointer definition
253   * @brief  HAL CRYP Callback pointer definition
254   * @{
255   */
256 
257 typedef  void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp);    /*!< pointer to a common CRYP callback function */
258 
259 /**
260   * @}
261   */
262 
263 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
264 
265 /* Exported constants --------------------------------------------------------*/
266 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
267   * @{
268   */
269 
270 /** @defgroup CRYP_Error_Definition   CRYP Error Definition
271   * @{
272   */
273 #define HAL_CRYP_ERROR_NONE              0x00000000U  /*!< No error        */
274 #define HAL_CRYP_ERROR_WRITE             0x00000001U  /*!< Write error     */
275 #define HAL_CRYP_ERROR_READ              0x00000002U  /*!< Read error      */
276 #define HAL_CRYP_ERROR_DMA               0x00000004U  /*!< DMA error      */
277 #define HAL_CRYP_ERROR_BUSY              0x00000008U  /*!< Busy flag error */
278 #define HAL_CRYP_ERROR_TIMEOUT           0x00000010U  /*!< Timeout error   */
279 #define HAL_CRYP_ERROR_NOT_SUPPORTED     0x00000020U  /*!< Not supported mode */
280 #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U  /*!< Sequence are not respected only for GCM or CCM */
281 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
282 #define  HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U)    /*!< Invalid Callback error  */
283 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
284 #define HAL_CRYP_ERROR_KEY               0x00000100U  /*!< Key error */
285 #define HAL_CRYP_ERROR_RNG               0x00000200U  /*!< RNG error */
286 
287 /**
288   * @}
289   */
290 
291 
292 /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit
293   * @{
294   */
295 
296 #define CRYP_DATAWIDTHUNIT_WORD   0x00000000U  /*!< By default, size unit is word */
297 #define CRYP_DATAWIDTHUNIT_BYTE   0x00000001U  /*!< By default, size unit is byte */
298 
299 /**
300   * @}
301   */
302 
303 /** @defgroup CRYP_Header_Width_Unit CRYP Header Width Unit
304   * @{
305   */
306 
307 #define CRYP_HEADERWIDTHUNIT_WORD   0x00000000U  /*!< By default, size unit is word */
308 #define CRYP_HEADERWIDTHUNIT_BYTE   0x00000001U  /*!< By default, size unit is byte */
309 
310 /**
311   * @}
312   */
313 
314 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1)
315 /** @defgroup SAES_CR_CHMOD SAES CHMOD Selection
316   * @{
317   */
318 
319 #define SAES_CR_CHMOD_AES_ECB     ((uint32_t)0x00000000)
320 #define SAES_CR_CHMOD_AES_CBC     (SAES_CR_CHMOD_0)
321 #define SAES_CR_CHMOD_AES_CTR     (SAES_CR_CHMOD_1)
322 #define SAES_CR_CHMOD_AES_GCM     (SAES_CR_CHMOD_0 | SAES_CR_CHMOD_1)
323 #define SAES_CR_CHMOD_AES_CCM     (SAES_CR_CHMOD_2)
324 
325 /**
326   * @}
327   */
328 #endif /* USE_HAL_SAES_ONLY */
329 
330 /** @defgroup CRYP_CR_ALGOMODE CRYP Algorithm Mode
331   * @{
332   */
333 
334 #define CRYP_AES_ECB              (CRYP_CR_ALGOMODE_2)
335 #define CRYP_AES_CBC              (CRYP_CR_ALGOMODE_0 | CRYP_CR_ALGOMODE_2)
336 #define CRYP_AES_CTR              (CRYP_CR_ALGOMODE_1 | CRYP_CR_ALGOMODE_2)
337 #define CRYP_AES_KEY              (CRYP_CR_ALGOMODE_0 | CRYP_CR_ALGOMODE_1 | CRYP_CR_ALGOMODE_2)
338 #define CRYP_AES_GCM              (CRYP_CR_ALGOMODE_3)
339 #define CRYP_AES_CCM              (CRYP_CR_ALGOMODE_0 | CRYP_CR_ALGOMODE_3)
340 
341 /**
342   * @}
343   */
344 
345 /** @defgroup CRYP_Key_Size CRYP Key Size
346   * @{
347   */
348 
349 #define CRYP_KEYSIZE_128B         0x00000000U
350 #define CRYP_KEYSIZE_192B         CRYP_CR_KEYSIZE_0
351 #define CRYP_KEYSIZE_256B         CRYP_CR_KEYSIZE_1
352 
353 /**
354   * @}
355   */
356 
357 /** @defgroup CRYP_Data_Type CRYP Data Type
358   * @{
359   */
360 
361 #define CRYP_DATATYPE_32B         0x00000000U
362 #define CRYP_DATATYPE_16B         CRYP_CR_DATATYPE_0
363 #define CRYP_DATATYPE_8B          CRYP_CR_DATATYPE_1
364 #define CRYP_DATATYPE_1B          CRYP_CR_DATATYPE
365 
366 #define CRYP_NO_SWAP              CRYP_DATATYPE_32B      /*!< 32-bit data type (no swapping)        */
367 #define CRYP_HALFWORD_SWAP        CRYP_DATATYPE_16B      /*!< 16-bit data type (half-word swapping) */
368 #define CRYP_BYTE_SWAP            CRYP_DATATYPE_8B       /*!< 8-bit data type (byte swapping)       */
369 #define CRYP_BIT_SWAP             CRYP_DATATYPE_1B       /*!< 1-bit data type (bit swapping)        */
370 /**
371   * @}
372   */
373 
374 /** @defgroup CRYP_Interrupt  CRYP and SAES peripherals interrupts
375   * @{
376   */
377 
378 #define CRYP_IT_INI       CRYP_IMSCR_INIM   /*!< CRYP peripheral input FIFO Interrupt */
379 #define CRYP_IT_OUTI      CRYP_IMSCR_OUTIM  /*!< CRYP peripheral output FIFO Interrupt */
380 
381 #define CRYP_IT_CCFIE     SAES_IER_CCFIE    /*!< SAES peripheral computation Complete interrupt enable */
382 #define CRYP_IT_RWEIE     SAES_IER_RWEIE    /*!< SAES peripheral read or write Error interrupt enable  */
383 #define CRYP_IT_KEIE      SAES_IER_KEIE     /*!< SAES peripheral key error interrupt enable  */
384 #define CRYP_IT_RNGEIE    SAES_IER_RNGEIE   /*!< SAES peripheral RNG error interrupt enable  */
385 
386 /**
387   * @}
388   */
389 
390 /** @defgroup CRYP_Flags CRYP & SAES Flags
391   * @{
392   */
393 
394 /* Flags in the SR register */
395 #define CRYP_FLAG_IFEM     CRYP_SR_IFEM      /*!< CRYP peripheral Input FIFO is empty */
396 #define CRYP_FLAG_IFNF     CRYP_SR_IFNF      /*!< CRYP peripheral Input FIFO is not Full */
397 #define CRYP_FLAG_OFNE     CRYP_SR_OFNE      /*!< CRYP peripheral Output FIFO is not empty */
398 #define CRYP_FLAG_OFFU     CRYP_SR_OFFU      /*!< CRYP peripheral Output FIFO is Full */
399 #define CRYP_FLAG_KERF     CRYP_SR_KERF      /*!< CRYP peripheral Key error flag */
400 /* Flags in the RISR register */
401 #define CRYP_FLAG_OUTRIS   0x01000002U  /*!< Output FIFO service raw interrupt status */
402 #define CRYP_FLAG_INRIS    0x01000001U  /*!< Input FIFO service raw interrupt status*/
403 
404 #define CRYP_FLAG_BUSY     CRYP_SR_BUSY      /*!< The CRYP peripheral is currently processing a block of data
405                                                  or a key preparation (for AES decryption). */
406 
407 
408 #define CRYP_FLAG_KEYVALID CRYP_SR_KEYVALID  /*!< CRYP or SAES peripheral Key valid flag */
409 
410 #define SAES_FLAG_BUSY     SAES_SR_BUSY      /*!< The SAES peripheral is currently processing a block of data
411                                                   or a key preparation (for AES decryption). */
412 
413 #define CRYP_FLAG_WRERR    (SAES_SR_WRERR | 0x80000000U) /*!< SAES peripheral Write Error flag */
414 #define CRYP_FLAG_RDERR    (SAES_SR_RDERR | 0x80000000U) /*!< SAES peripheral Read error flag */
415 #define CRYP_FLAG_CCF      SAES_SR_CCF                   /*!< SAES peripheral Computation completed flag
416                                                               as AES_ISR_CCF */
417 #define CRYP_FLAG_KEIF     SAES_ISR_KEIF                 /*!< SAES peripheral Key error interrupt flag */
418 #define CRYP_FLAG_RWEIF    SAES_ISR_RWEIF                /*!< SAES peripheral Read or Write error Interrupt flag */
419 #define CRYP_FLAG_RNGEIF   SAES_ISR_RNGEIF               /*!< SAES peripheral RNG error Interrupt flag */
420 /**
421   * @}
422   */
423 
424 /** @defgroup CRYP_CLEAR_Flags SAES peripheral Clear Flags
425   * @{
426   */
427 #define CRYP_CLEAR_CCF      SAES_ICR_CCF    /*!< SAES peripheral clear Computation Complete Flag */
428 #define CRYP_CLEAR_RWEIF    SAES_ICR_RWEIF  /*!< SAES peripheral clear Error Flag : RWEIF in SAES_ISR and
429                                               both RDERR and WRERR flags in SAES_SR */
430 #define CRYP_CLEAR_KEIF     SAES_ICR_KEIF   /*!< SAES peripheral clear Key Error Flag: KEIF in SAES_ISR */
431 #define CRYP_CLEAR_RNGEIF   SAES_ICR_RNGEIF /*!< SAES peripheral clear RNG error Flag  */
432 
433 /**
434   * @}
435   */
436 
437 
438 /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode
439   * @{
440   */
441 
442 #define CRYP_KEYIVCONFIG_ALWAYS        0x00000000U            /*!< Peripheral Key and IV configuration
443                                                                    to do systematically */
444 #define CRYP_KEYIVCONFIG_ONCE          0x00000001U            /*!< Peripheral Key and IV configuration
445                                                                    to do only once */
446 #define CRYP_KEYNOCONFIG               0x00000002U            /*!< Peripheral Key configuration to not do */
447 
448 /**
449   * @}
450   */
451 
452 /** @defgroup CRYP_Key_Mode CRYP or SAES Key Mode
453   * @{
454   */
455 
456 #define CRYP_KEYMODE_NORMAL         0x00000000U         /*!< Normal key usage, Key registers are freely usable */
457 #define CRYP_KEYMODE_WRAPPED        SAES_CR_KMOD_0      /*!< Only for SAES, Wrapped key: to encrypt
458                                                              or decrypt AES keys */
459 #define CRYP_KEYMODE_SHARED         SAES_CR_KMOD_1      /*!< Key shared by SAES peripheral */
460 /**
461   * @}
462   */
463 
464 /** @defgroup CRYP_Key_Select SAES Key Select
465   * @{
466   */
467 
468 #define CRYP_KEYSEL_NORMAL       0x00000000U            /*!< Normal key, key registers SAES_KEYx or CRYP_KEYx */
469 #define CRYP_KEYSEL_HW           SAES_CR_KEYSEL_0       /*!< Only for SAES, Hardware key : derived hardware
470                                                              unique key (DHUK 256-bit) */
471 #define CRYP_KEYSEL_SW           SAES_CR_KEYSEL_1       /*!< Only for SAES, Software key : boot hardware
472                                                              key BHK (256-bit) */
473 #define CRYP_KEYSEL_HSW          SAES_CR_KEYSEL_2       /*!< Only for SAES, DHUK XOR BHK Hardware unique
474                                                              key XOR software key */
475 #define CRYP_KEYSEL_AHK          (SAES_CR_KEYSEL_1|SAES_CR_KEYSEL_0)  /*!< Only for SAES, Software key :
476                                                                       application hardware key AHK (128- or 256-bit) */
477 #define CRYP_KEYSEL_DUK_AHK      (SAES_CR_KEYSEL_2|SAES_CR_KEYSEL_0)   /*!< Only for SAES, DHUK XOR AHK */
478 #define CRYP_KEYSEL_TEST_KEY     (SAES_CR_KEYSEL_2|SAES_CR_KEYSEL_1|SAES_CR_KEYSEL_0) /*!< Test mode key (256-bit
479                                                                                hardware constant key 0xA5A5...A5A5) */
480 /**
481   * @}
482   */
483 
484 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1)
485 /**
486   * @}
487   */
488 
489 /** @defgroup CRYP_Key_Shared SAES Key Shared with Peripheral
490   * @{
491   */
492 
493 #define CRYP_KEYSHARED_CRYP         0x00000000U     /*!< Only for SAES, key is shared with CRYP peripheral */
494 
495 /**
496   * @}
497   */
498 
499 /** @defgroup CRYP_Mode SAES processing mode
500   * @{
501   */
502 
503 #define CRYP_MODE_ENCRYPT                0x00000000U             /*!< SAES peripheral encryption mode   */
504 #define CRYP_MODE_KEY_DERIVATION         SAES_CR_MODE_0          /*!< SAES peripheral key derivation    */
505 #define CRYP_MODE_DECRYPT                SAES_CR_MODE_1          /*!< SAES peripheral decryption mode   */
506 
507 /**
508   * @}
509   */
510 #endif /* USE_HAL_SAES_ONLY */
511 
512 /** @defgroup CRYP_Mode SAES processing mode
513   * @{
514   */
515 
516 #define CRYP_OPERATINGMODE_ENCRYPT       0x00000000U             /*!< CRYP peripheral encryption mode   */
517 #define CRYP_OPERATINGMODE_DECRYPT       CRYP_CR_ALGODIR         /*!< CRYP peripheral decryption mode   */
518 
519 /**
520   * @}
521   */
522 
523 /* Exported macros -----------------------------------------------------------*/
524 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
525   * @{
526   */
527 
528 /**
529   * @brief  Inform about which IP is the current INSTANCE: CRYP or SAES.
530   * @param  INSTANCE: specifies the HW instance.
531   * @retval None
532   */
533 #define IS_CRYP_INSTANCE(INSTANCE) ((INSTANCE) == CRYP)
534 #define IS_SAES_INSTANCE(INSTANCE) ((INSTANCE) == SAES)
535 
536 /** @brief Reset CRYP handle state
537   * @param  __HANDLE__ specifies the CRYP handle.
538   * @retval None
539   */
540 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
541 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\
542                                                       (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\
543                                                       (__HANDLE__)->MspInitCallback = NULL;\
544                                                       (__HANDLE__)->MspDeInitCallback = NULL;\
545                                                      }while(0)
546 #else
547 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET)
548 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
549 
550 /**
551   * @brief  Enable/Disable the CRYP or SAES peripheral.
552   * @param  __HANDLE__: specifies the CRYP handle.
553   * @retval None
554   */
555 
556 #define __HAL_CRYP_ENABLE(__HANDLE__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ? \
557                                        (((CRYP_TypeDef *)((__HANDLE__)->Instance))->CR |=  CRYP_CR_CRYPEN) :\
558                                        (((SAES_TypeDef *)((__HANDLE__)->Instance))->CR |=  SAES_CR_EN))
559 
560 #define __HAL_CRYP_DISABLE(__HANDLE__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ? \
561                                         (((CRYP_TypeDef *)((__HANDLE__)->Instance))->CR &=  ~CRYP_CR_CRYPEN) :\
562                                         (((SAES_TypeDef *)((__HANDLE__)->Instance))->CR &=  ~SAES_CR_EN))
563 
564 /** @brief  Check whether the specified CRYP or SAES peripheral status flag is set or not.
565   * @param  __FLAG__: specifies the flag to check.
566   *         This parameter can be one of the following values:
567   *            @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data
568   *                                 or a key preparation (for AES decryption)
569   *            @arg @ref CRYP_FLAG_KEYVALID Key valid flag
570   *            @arg @ref CRYP_FLAG_KEIF Key error flag
571   *            @arg CRYP_FLAG_IFEM: Input FIFO is empty                           (CRYP peripheral only)
572   *            @arg CRYP_FLAG_IFNF: Input FIFO is not full                        (CRYP peripheral only)
573   *            @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending  (CRYP peripheral only)
574   *            @arg CRYP_FLAG_OFNE: Output FIFO is not empty                      (CRYP peripheral only)
575   *            @arg CRYP_FLAG_OFFU: Output FIFO is full                           (CRYP peripheral only)
576   *            @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending (CRYP peripheral only)
577   *            @arg @ref CRYP_FLAG_WRERR Write Error flag                         (SAES peripheral only)
578   *            @arg @ref CRYP_FLAG_RDERR Read Error flag                          (SAES peripheral only)
579   *            @arg @ref CRYP_FLAG_CCF Computation Complete flag                  (SAES peripheral only)
580   *            @arg @ref CRYP_FLAG_RWEIF Read/write Error flag                    (SAES peripheral only)
581   *            @arg @ref CRYP_FLAG_RNGEIF RNG Error flag                          (SAES peripheral only)
582   * @retval The state of __FLAG__ (TRUE or FALSE).
583   */
584 #define CRYP_FLAG_MASK  0x0000001FU
585 
586 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ?\
587                                                    ((__FLAG__) == CRYP_FLAG_KEYVALID )?((((((CRYP_TypeDef *) \
588                                                        ((__HANDLE__)->Instance))))->SR \
589                                                        & (CRYP_FLAG_KEYVALID)) == (CRYP_FLAG_KEYVALID)) : \
590                                                    ((__FLAG__) == CRYP_FLAG_BUSY )?((((((CRYP_TypeDef *) \
591                                                        ((__HANDLE__)->Instance))))->SR \
592                                                        & (CRYP_FLAG_BUSY)) == (CRYP_FLAG_BUSY)) : \
593                                                    ((__FLAG__) == CRYP_FLAG_KEIF )?((((((CRYP_TypeDef *) \
594                                                        ((__HANDLE__)->Instance))))->SR \
595                                                        & (CRYP_FLAG_KERF)) == (CRYP_FLAG_KERF)) : \
596                                                    ((((uint8_t)((__FLAG__) >> 24)) == 0x01U)?(((((CRYP_TypeDef *) \
597                                                        ((__HANDLE__)->Instance))->RISR) & ((__FLAG__) & \
598                                                            CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \
599                                                     (((((CRYP_TypeDef *)((__HANDLE__)->Instance))->RISR) & ((__FLAG__)\
600                                                         & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK))) :\
601                                                    (\
602                                                     ((__FLAG__) == CRYP_FLAG_KEYVALID )?((((SAES_TypeDef *)\
603                                                         (((SAES_TypeDef *)((__HANDLE__)->Instance))))->SR \
604                                                         & (CRYP_FLAG_KEYVALID)) == (CRYP_FLAG_KEYVALID)) : \
605                                                     ((__FLAG__) == CRYP_FLAG_BUSY )?((((SAES_TypeDef *) \
606                                                         ((__HANDLE__)->Instance))->SR \
607                                                         & (CRYP_FLAG_BUSY)) == (CRYP_FLAG_BUSY)) : \
608                                                     ((__FLAG__) == CRYP_FLAG_WRERR )?((((SAES_TypeDef *) \
609                                                         ((__HANDLE__)->Instance))->SR \
610                                                         & (CRYP_FLAG_WRERR & 0x7FFFFFFFU)) == \
611                                                         (CRYP_FLAG_WRERR & 0x7FFFFFFFU)) : \
612                                                     ((__FLAG__) == CRYP_FLAG_RDERR )?((((SAES_TypeDef *) \
613                                                         ((__HANDLE__)->Instance))->SR \
614                                                         & (CRYP_FLAG_RDERR & 0x7FFFFFFFU)) == \
615                                                         (CRYP_FLAG_RDERR & 0x7FFFFFFFU)) : \
616                                                     ((__FLAG__) == CRYP_FLAG_RNGEIF )?((((SAES_TypeDef *) \
617                                                         ((__HANDLE__)->Instance))->ISR \
618                                                         & (CRYP_FLAG_RNGEIF)) == (CRYP_FLAG_RNGEIF)) : \
619                                                     ((__FLAG__) == CRYP_FLAG_KEIF )?((((SAES_TypeDef *) \
620                                                         ((__HANDLE__)->Instance))->ISR \
621                                                         & (CRYP_FLAG_KEIF)) == (CRYP_FLAG_KEIF)) : \
622                                                     ((__FLAG__) == CRYP_FLAG_RWEIF )?((((SAES_TypeDef *) \
623                                                         ((__HANDLE__)->Instance))->ISR \
624                                                         & (CRYP_FLAG_RWEIF)) == (CRYP_FLAG_RWEIF)) : \
625                                                     ((((SAES_TypeDef *)((__HANDLE__)->Instance))->ISR & \
626                                                       (CRYP_FLAG_CCF)) == (CRYP_FLAG_CCF))))
627 
628 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1)
629 /** @brief  Clear the SAES peripheral pending status flag.
630   * @param  __HANDLE__ specifies the SAES handle.
631   * @param  __FLAG__ specifies the flag to clear.
632   *         This parameter can be one of the following values:
633   *            @arg @ref CRYP_CLEAR_RWEIF Read (RDERR), Write (WRERR) or Read/write (RWEIF) Error  Flag Clear
634   *            @arg @ref CRYP_CLEAR_CCF Computation Complete Flag (CCF) Clear
635   *            @arg @ref CRYP_CLEAR_KEIF Key error interrupt flag clear
636   *            @arg @ref CRYP_CLEAR_RNGEIF RNG error interrupt flag clear
637   * @retval None
638   */
639 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) WRITE_REG(((SAES_TypeDef *)((__HANDLE__)->Instance))->ICR,\
640                                                               (__FLAG__))
641 #endif /* USE_HAL_SAES_ONLY */
642 
643 #if !defined(USE_HAL_CRYP_ONLY) || (USE_HAL_CRYP_ONLY == 1)
644 /** @brief  Check whether the specified CRYP peripheral interrupt is set or not.
645   * @param  __HANDLE__: specifies the CRYP handle.
646   * @param  __INTERRUPT__: specifies the interrupt to check.
647   *         This parameter can be one of the following values:
648   *            @arg CRYP_IT_INI: Input FIFO service masked interrupt status
649   *            @arg CRYP_IT_OUTI: Output FIFO service masked interrupt status
650   * @retval The state of __INTERRUPT__ (TRUE or FALSE).
651   */
652 
653 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) ((((CRYP_TypeDef *)((__HANDLE__)->Instance))->MISR\
654                                                        & (__INTERRUPT__)) == (__INTERRUPT__))
655 #endif /* USE_HAL_CRYP_ONLY */
656 
657 /**
658   * @brief  Enable the CRYP or SAES peripheral interrupt.
659   * @param  __HANDLE__: specifies the CRYP handle.
660   * @param  __INTERRUPT__:  Interrupt.
661   *         This parameter can be one of the following values:
662   *            @arg @ref  CRYP_IT_INI    Input FIFO service interrupt mask          (CRYP peripheral only)
663   *            @arg @ref  CRYP_IT_OUTI   Output FIFO service interrupt mask         (CRYP peripheral only)
664   *            @arg @ref  CRYP_IT_RWEIE  Error interrupt (used for RDERR and WRERR) (SAES peripheral only)
665   *            @arg @ref  CRYP_IT_CCFIE  Computation Complete interrupt             (SAES peripheral only)
666   *            @arg @ref  CRYP_IT_KEIE   Key error interrupt                        (SAES peripheral only)
667   *            @arg @ref  CRYP_IT_RNGEIE RNG interrupt                              (SAES peripheral only)
668   * @retval None
669   */
670 
671 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__)  ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ?\
672                                                           ((((CRYP_TypeDef *)((__HANDLE__)->Instance))->IMSCR) |= \
673                                                               (__INTERRUPT__)) : ((((SAES_TypeDef *) \
674                                                                   ((__HANDLE__)->Instance))->IER) |= (__INTERRUPT__)))
675 
676 /**
677   * @brief  Disable the CRYP or SAES peripheral interrupt.
678   * @param  __HANDLE__: specifies the CRYP handle.
679   * @param  __INTERRUPT__:  Interrupt.
680   *         This parameter can be one of the following values:
681   *            @arg @ref  CRYP_IT_INI    Input FIFO service interrupt mask          (CRYP peripheral only)
682   *            @arg @ref  CRYP_IT_OUTI   Output FIFO service interrupt mask         (CRYP peripheral only)
683   *            @arg @ref  CRYP_IT_RWEIE  Error interrupt (used for RDERR and WRERR) (SAES peripheral only)
684   *            @arg @ref  CRYP_IT_CCFIE  Computation Complete interrupt             (SAES peripheral only)
685   *            @arg @ref  CRYP_IT_KEIE   Key error interrupt                        (SAES peripheral only)
686   *            @arg @ref  CRYP_IT_RNGEIE RNG interrupt                              (SAES peripheral only)
687   * @retval None
688   */
689 
690 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((IS_CRYP_INSTANCE((__HANDLE__)->Instance)) ?\
691                                                           ((((CRYP_TypeDef *)((__HANDLE__)->Instance))->IMSCR) &= \
692                                                               ~(__INTERRUPT__)) : ((((SAES_TypeDef *) \
693                                                                   ((__HANDLE__)->Instance))->IER) &= ~(__INTERRUPT__)))
694 
695 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1)
696 /** @brief  Check whether the specified SAES peripheral interrupt source is enabled or not.
697   * @param  __HANDLE__ specifies the CRYP handle.
698   * @param __INTERRUPT__  interrupt source to check
699   *         This parameter can be one of the following values for TinyAES:
700   *            @arg @ref CRYP_IT_RWEIE Error interrupt (used for RDERR and WRERR)
701   *            @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
702   *            @arg @ref CRYP_IT_KEIE Key error interrupt
703   *            @arg @ref CRYP_IT_RNGEIE RNG error interrupt
704   * @retval State of interruption (TRUE or FALSE).
705   */
706 
707 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((SAES_TypeDef *)((__HANDLE__)->Instance))->IER\
708                                                               & (__INTERRUPT__)) == (__INTERRUPT__))
709 #endif /* USE_HAL_SAES_ONLY */
710 /**
711   * @}
712   */
713 
714 /* Include CRYP HAL Extended module */
715 #include "stm32h7rsxx_hal_cryp_ex.h"
716 
717 /* Exported functions --------------------------------------------------------*/
718 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
719   * @{
720   */
721 
722 /** @addtogroup CRYP_Exported_Functions_Group1
723   * @{
724   */
725 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
726 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
727 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
728 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
729 HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
730 HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
731 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
732 HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID,
733                                             pCRYP_CallbackTypeDef pCallback);
734 HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID);
735 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
736 #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
737 void HAL_CRYP_ProcessSuspend(CRYP_HandleTypeDef *hcryp);
738 HAL_StatusTypeDef HAL_CRYP_DMAProcessSuspend(CRYP_HandleTypeDef *hcryp);
739 HAL_StatusTypeDef HAL_CRYP_Suspend(CRYP_HandleTypeDef *hcryp);
740 HAL_StatusTypeDef HAL_CRYP_Resume(CRYP_HandleTypeDef *hcryp);
741 #endif /* defined (USE_HAL_CRYP_SUSPEND_RESUME) */
742 /**
743   * @}
744   */
745 
746 /** @addtogroup CRYP_Exported_Functions_Group2
747   * @{
748   */
749 
750 /* encryption/decryption ***********************************/
751 HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output,
752                                    uint32_t Timeout);
753 HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output,
754                                    uint32_t Timeout);
755 HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
756 HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
757 HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
758 HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
759 
760 /**
761   * @}
762   */
763 
764 
765 /** @addtogroup CRYP_Exported_Functions_Group3
766   * @{
767   */
768 /* Interrupt Handler functions  **********************************************/
769 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
770 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(const CRYP_HandleTypeDef *hcryp);
771 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
772 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
773 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
774 uint32_t HAL_CRYP_GetError(const CRYP_HandleTypeDef *hcryp);
775 
776 /**
777   * @}
778   */
779 
780 /**
781   * @}
782   */
783 
784 /* Private macros --------------------------------------------------------*/
785 /** @defgroup CRYP_Private_Macros   CRYP Private Macros
786   * @{
787   */
788 
789 /** @defgroup CRYP_IS_CRYP_Definitions CRYP Private macros to check input parameters
790   * @{
791   */
792 
793 #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM)  == CRYP_AES_ECB)   || \
794                                       ((ALGORITHM)  == CRYP_AES_CBC)   || \
795                                       ((ALGORITHM)  == CRYP_AES_CTR)   || \
796                                       ((ALGORITHM)  == CRYP_AES_GCM)   || \
797                                       ((ALGORITHM)  == CRYP_AES_CCM))
798 
799 #define IS_CRYP_KEYSIZE(KEYSIZE) (((KEYSIZE) == CRYP_KEYSIZE_128B)   || \
800                                   ((KEYSIZE) == CRYP_KEYSIZE_192B)   || \
801                                   ((KEYSIZE) == CRYP_KEYSIZE_256B))
802 
803 #define IS_CRYP_DATATYPE(DATATYPE) (((DATATYPE) == CRYP_DATATYPE_32B) || \
804                                     ((DATATYPE) == CRYP_DATATYPE_16B) || \
805                                     ((DATATYPE) == CRYP_DATATYPE_8B)  || \
806                                     ((DATATYPE) == CRYP_DATATYPE_1B))
807 
808 #define IS_CRYP_INIT(CONFIG) (((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \
809                               ((CONFIG) == CRYP_KEYIVCONFIG_ONCE)   || \
810                               ((CONFIG) == CRYP_KEYNOCONFIG))
811 
812 #define IS_CRYP_KEYIVCONFIG(CONFIG) (((KEYSIZE) == CRYP_KEYSIZE_128B) || \
813                                      ((KEYSIZE) == CRYP_KEYSIZE_192B)  || \
814                                      ((KEYSIZE) == CRYP_KEYSIZE_256B))
815 
816 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1)
817 #define IS_CRYP_KEYMODE(MODE) (((MODE) == CRYP_KEYMODE_NORMAL) || \
818                                ((MODE) == CRYP_KEYMODE_SHARED))
819 
820 #define IS_SAES_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB)   || \
821                                       ((ALGORITHM) == CRYP_AES_CBC)   || \
822                                       ((ALGORITHM) == CRYP_AES_CTR)   || \
823                                       ((ALGORITHM) == CRYP_AES_GCM)   || \
824                                       ((ALGORITHM) == CRYP_AES_CCM))
825 
826 #define IS_SAES_KEYSIZE(KEYSIZE) (((KEYSIZE) == CRYP_KEYSIZE_128B)  || \
827                                   ((KEYSIZE) == CRYP_KEYSIZE_256B))
828 
829 #define IS_SAES_DATATYPE(DATATYPE) (((DATATYPE) == SAES_DATATYPE_32B) || \
830                                     ((DATATYPE) == SAES_DATATYPE_16B) || \
831                                     ((DATATYPE) == SAES_DATATYPE_8B)  || \
832                                     ((DATATYPE) == SAES_DATATYPE_1B))
833 
834 #define IS_SAES_KEYMODE(MODE) (((MODE) == CRYP_KEYMODE_NORMAL)  || \
835                                ((MODE) == CRYP_KEYMODE_WRAPPED) || \
836                                ((MODE) == CRYP_KEYMODE_SHARED))
837 
838 #define IS_SAES_KEYPROT(PROTECTION) (((PROTECTION) == CRYP_KEYPROT_ENABLE)  || \
839                                      ((PROTECTION) == CRYP_KEYPROT_DISABLE))
840 
841 #define IS_SAES_KEYSEL(SELECTION) (((SELECTION) == CRYP_KEYSEL_NORMAL)   || \
842                                    ((SELECTION) == CRYP_KEYSEL_HW)       || \
843                                    ((SELECTION) == CRYP_KEYSEL_SW)       || \
844                                    ((SELECTION) == CRYP_KEYSEL_HSW)      || \
845                                    ((SELECTION) == CRYP_KEYSEL_AHK)      || \
846                                    ((SELECTION) == CRYP_KEYSEL_DUK_AHK)  || \
847                                    ((SELECTION) == CRYP_KEYSEL_TEST_KEY))
848 
849 #define IS_SAES_KEYSHARED(PERIPHERAL) ((PERIPHERAL) == CRYP_KEYSHARED_CRYP)
850 /**
851   * @}
852   */
853 #endif /* USE_HAL_SAES_ONLY */
854 
855 /** @defgroup SAES_CONV_Definitions SAES Private macros to convert input parameters from CRYP peripheral to
856      SAES peripheral format
857   * @{
858   */
859 #if !defined(USE_HAL_SAES_ONLY) || (USE_HAL_SAES_ONLY == 1)
860 #define SAES_CONV_DATATYPE(__DATATYPE__) ((__DATATYPE__) >> (CRYP_CR_DATATYPE_Pos - SAES_CR_DATATYPE_Pos))
861 
862 #define SAES_CONV_KEYSIZE(__KEY__) (((__KEY__)\
863                                      & CRYP_CR_KEYSIZE_1) << (SAES_CR_KEYSIZE_Pos - (CRYP_CR_KEYSIZE_Pos + 1U)))
864 
865 #define SAES_CONV_ALGO(__ALGO__) (((__ALGO__)\
866                                    & (CRYP_CR_ALGOMODE_1 | CRYP_CR_ALGOMODE_0)) << (SAES_CR_CHMOD_Pos - \
867                                        CRYP_CR_ALGOMODE_Pos))
868 #endif /* USE_HAL_SAES_ONLY */
869 #define CRYP_CONV_ALGODIR(__ALGODIR__) (((__ALGODIR__)\
870                                          & SAES_CR_MODE_1) >> ((SAES_CR_MODE_Pos + 1U) - CRYP_CR_ALGODIR_Pos))
871 
872 /**
873   * @}
874   */
875 
876 
877 /**
878   * @}
879   */
880 
881 
882 /* Private constants ---------------------------------------------------------*/
883 /** @defgroup CRYP_Private_Constants CRYP Private Constants
884   * @{
885   */
886 
887 /**
888   * @}
889   */
890 /* Private defines -----------------------------------------------------------*/
891 /** @defgroup CRYP_Private_Defines CRYP Private Defines
892   * @{
893   */
894 
895 /**
896   * @}
897   */
898 
899 /* Private variables ---------------------------------------------------------*/
900 /** @defgroup CRYP_Private_Variables CRYP Private Variables
901   * @{
902   */
903 
904 /**
905   * @}
906   */
907 /* Private functions prototypes ----------------------------------------------*/
908 /** @defgroup CRYP_Private_Functions_Prototypes CRYP Private Functions Prototypes
909   * @{
910   */
911 
912 /**
913   * @}
914   */
915 
916 /* Private functions ---------------------------------------------------------*/
917 /** @defgroup CRYP_Private_Functions CRYP Private Functions
918   * @{
919   */
920 
921 /**
922   * @}
923   */
924 
925 
926 /**
927   * @}
928   */
929 
930 
931 #endif /* CRYP */
932 /**
933   * @}
934   */
935 
936 #ifdef __cplusplus
937 }
938 #endif
939 
940 /**
941   * @}
942   */
943 
944 #endif /* STM32H7RSxx_HAL_CRYP_H */
945