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