1 /**
2   ******************************************************************************
3   * @file    stm32h5xx_hal_hash.h
4   * @author  MCD Application Team
5   * @brief   Header file of HASH HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2023 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32H5xx_HAL_HASH_H
22 #define STM32H5xx_HAL_HASH_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h5xx_hal_def.h"
30 
31 /** @addtogroup STM32H5xx_HAL_Driver
32   * @{
33   */
34 #if defined (HASH)
35 /** @defgroup HASH HASH
36   * @brief HASH HAL module driver.
37   * @{
38   */
39 
40 /* Exported types ------------------------------------------------------------*/
41 /** @defgroup HASH_Exported_Types HASH Exported Types
42   * @{
43   */
44 
45 /**
46   * @brief  HASH Configuration Structure definition
47   */
48 typedef struct
49 {
50   uint32_t DataType;    /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit data.
51                               This parameter can be a value of @ref HASH_Data_Type. */
52 
53   uint32_t KeySize;     /*!< The key size is used only in HMAC operation. */
54 
55   uint8_t *pKey;        /*!< The key is used only in HMAC operation. */
56 
57   uint32_t Algorithm;   /*!<  HASH Algorithm MD5, SAH1 or SHA2.
58                             This parameter can be a value of @ref HASH_Algorithm_Selection */
59 
60 
61 } HASH_ConfigTypeDef;
62 
63 /**
64   * @brief HAL State structures definition
65   */
66 typedef enum
67 {
68   HAL_HASH_STATE_RESET             = 0x00U,    /*!< Peripheral is not initialized            */
69   HAL_HASH_STATE_READY             = 0x01U,    /*!< Peripheral Initialized and ready for use */
70   HAL_HASH_STATE_BUSY              = 0x02U,    /*!< Processing (hashing) is ongoing          */
71   HAL_HASH_STATE_SUSPENDED         = 0x06U     /*!< Suspended state                          */
72 } HAL_HASH_StateTypeDef;
73 
74 /**
75   * @brief HAL phase structures definition
76   */
77 typedef enum
78 {
79   HAL_HASH_PHASE_READY             = 0x01U,    /*!< HASH peripheral is ready to start                    */
80   HAL_HASH_PHASE_PROCESS           = 0x02U,    /*!< HASH peripheral is in HASH processing phase          */
81   HAL_HASH_PHASE_HMAC_STEP_1       = 0x03U,    /*!< HASH peripheral is in HMAC step 1 processing phase
82                                               (step 1 consists in entering the inner hash function key) */
83   HAL_HASH_PHASE_HMAC_STEP_2       = 0x04U,    /*!< HASH peripheral is in HMAC step 2 processing phase
84                                               (step 2 consists in entering the message text) */
85   HAL_HASH_PHASE_HMAC_STEP_3       = 0x05U     /*!< HASH peripheral is in HMAC step 3 processing phase
86                                               (step 3 consists in entering the outer hash function key) */
87 
88 } HAL_HASH_PhaseTypeDef;
89 
90 #if (USE_HAL_HASH_SUSPEND_RESUME == 1U)
91 /**
92   * @brief HAL HASH mode suspend definitions
93   */
94 typedef enum
95 {
96   HAL_HASH_SUSPEND_NONE            = 0x00U,    /*!< HASH peripheral suspension not requested */
97   HAL_HASH_SUSPEND                 = 0x01U     /*!< HASH peripheral suspension is requested  */
98 } HAL_HASH_SuspendTypeDef;
99 #endif /* USE_HAL_HASH_SUSPEND_RESUME */
100 
101 
102 /**
103   * @brief  HASH Handle Structure definition
104   */
105 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
106 typedef struct __HASH_HandleTypeDef
107 #else
108 typedef struct
109 #endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */
110 {
111   HASH_TypeDef               *Instance;        /*!< HASH Register base address */
112 
113   HASH_ConfigTypeDef           Init;             /*!< HASH required parameters */
114 
115   uint8_t const              *pHashInBuffPtr;  /*!< Pointer to input buffer */
116 
117   uint8_t                    *pHashOutBuffPtr; /*!< Pointer to output buffer (digest) */
118 
119   __IO uint32_t              HashInCount;      /*!< Counter of inputted data */
120 
121   uint32_t                   Size;     /*!< Size of buffer to be processed */
122 
123   uint8_t                   *pHashKeyBuffPtr; /*!< Pointer to key buffer (HMAC only) */
124 
125   HAL_HASH_PhaseTypeDef      Phase;            /*!< HASH peripheral phase   */
126 
127   DMA_HandleTypeDef          *hdmain;          /*!< HASH In DMA Handle parameters */
128 
129   HAL_LockTypeDef            Lock;             /*!< Locking object */
130 
131   __IO  uint32_t             ErrorCode;        /*!< HASH Error code */
132 
133   __IO HAL_HASH_StateTypeDef State;            /*!< HASH peripheral state */
134 
135   __IO  uint32_t             Accumulation;     /*!< HASH multi buffers accumulation flag */
136 
137 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
138   void (* InCpltCallback)(struct __HASH_HandleTypeDef *hhash);         /*!< HASH input completion callback */
139 
140   void (* DgstCpltCallback)(struct __HASH_HandleTypeDef *hhash);       /*!< HASH digest computation complete callback */
141 
142   void (* ErrorCallback)(struct __HASH_HandleTypeDef *hhash);          /*!< HASH error callback */
143 
144   void (* MspInitCallback)(struct __HASH_HandleTypeDef *hhash);        /*!< HASH Msp Init callback */
145 
146   void (* MspDeInitCallback)(struct __HASH_HandleTypeDef *hhash);      /*!< HASH Msp DeInit callback */
147 
148 #endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */
149 #if (USE_HAL_HASH_SUSPEND_RESUME == 1U)
150   __IO HAL_HASH_SuspendTypeDef    SuspendRequest;    /*!< HASH peripheral suspension request flag */
151 
152   HASH_ConfigTypeDef           Init_saved;             /*!< HASH required parameters */
153 
154   uint8_t const              *pHashInBuffPtr_saved;  /*!< Pointer to input buffer */
155 
156   uint8_t                    *pHashOutBuffPtr_saved; /*!< Pointer to output buffer (digest) */
157 
158   __IO uint32_t              HashInCount_saved;      /*!< Counter of inputted data */
159 
160   uint32_t                   Size_saved;     /*!< Size of buffer to be processed */
161 
162   uint8_t                   *pHashKeyBuffPtr_saved; /*!< Pointer to key buffer (HMAC only) */
163 
164   HAL_HASH_PhaseTypeDef      Phase_saved;            /*!< HASH peripheral phase   */
165 #endif /* USE_HAL_HASH_SUSPEND_RESUME */
166 
167 } HASH_HandleTypeDef;
168 
169 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
170 /**
171   * @brief  HAL HASH common Callback ID enumeration definition
172   */
173 typedef enum
174 {
175   HAL_HASH_MSPINIT_CB_ID           = 0x00U,    /*!< HASH MspInit callback ID     */
176   HAL_HASH_MSPDEINIT_CB_ID         = 0x01U,    /*!< HASH MspDeInit callback ID   */
177   HAL_HASH_INPUTCPLT_CB_ID         = 0x02U,    /*!< HASH input completion callback ID */
178   HAL_HASH_DGSTCPLT_CB_ID          = 0x03U,    /*!< HASH digest computation completion callback ID */
179   HAL_HASH_ERROR_CB_ID             = 0x04U,    /*!< HASH error callback ID     */
180 } HAL_HASH_CallbackIDTypeDef;
181 
182 /**
183   * @brief  HAL HASH Callback pointer definition
184   */
185 typedef  void (*pHASH_CallbackTypeDef)(HASH_HandleTypeDef *hhash);  /*!< pointer to a HASH common callback functions */
186 
187 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
188 
189 
190 /**
191   * @}
192   */
193 
194 /* Exported constants --------------------------------------------------------*/
195 
196 /** @defgroup HASH_Exported_Constants  HASH Exported Constants
197   * @{
198   */
199 
200 /** @defgroup HASH_Error_Definition   HASH Error Definition
201   * @{
202   */
203 #define  HAL_HASH_ERROR_NONE             0x00000000U   /*!< No error                */
204 #define  HAL_HASH_ERROR_BUSY             0x00000001U   /*!< Busy flag error  */
205 #define  HAL_HASH_ERROR_DMA              0x00000002U   /*!< DMA-based process error */
206 #define  HAL_HASH_ERROR_TIMEOUT          0x00000010U   /*!< Timeout error */
207 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
208 #define  HAL_HASH_ERROR_INVALID_CALLBACK 0x00000004U   /*!< Invalid Callback error  */
209 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
210 /**
211   * @}
212   */
213 
214 /** @defgroup HASH_Algorithm_Selection   HASH algorithm selection
215   * @{
216   */
217 #define HASH_ALGOSELECTION_SHA1         0x00000000U                         /*!< HASH function is SHA1   */
218 #define HASH_ALGOSELECTION_SHA224       HASH_CR_ALGO_1                      /*!< HASH function is SHA224 */
219 #define HASH_ALGOSELECTION_SHA256       (HASH_CR_ALGO_0 | HASH_CR_ALGO_1)     /*!< HASH function is SHA256 */
220 #if defined (HASH_CR_ALGO_2)
221 #define HASH_ALGOSELECTION_SHA384       (HASH_CR_ALGO_2 |  HASH_CR_ALGO_3)  /*!< HASH function is SHA384 */
222 #define HASH_ALGOSELECTION_SHA512_224   (HASH_CR_ALGO_0 | HASH_CR_ALGO_2 |  HASH_CR_ALGO_3)
223 /*!< HASH function is SHA512_224 */
224 #define HASH_ALGOSELECTION_SHA512_256   (HASH_CR_ALGO_1 | HASH_CR_ALGO_2 |  HASH_CR_ALGO_3)
225 /*!< HASH function is SHA512_256 */
226 #define HASH_ALGOSELECTION_SHA512        HASH_CR_ALGO                       /*!< HASH function is SHA512 */
227 #endif /* defined (HASH_CR_ALGO_2) */
228 /**
229   * @}
230   */
231 
232 /** @defgroup HASH_Mode   HASH Mode
233   * @{
234   */
235 #define HASH_ALGOMODE_HASH         0x00000000U     /*!< HASH mode */
236 #define HASH_ALGOMODE_HMAC         HASH_CR_MODE    /*!< HMAC mode */
237 /**
238   * @}
239   */
240 
241 /** @defgroup HASH_Data_Type      HASH Data Type
242   * @{
243   */
244 #define HASH_NO_SWAP          0x00000000U        /*!< 32-bit data. No swapping                     */
245 #define HASH_HALFWORD_SWAP    HASH_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped       */
246 #define HASH_BYTE_SWAP        HASH_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped            */
247 #define HASH_BIT_SWAP         HASH_CR_DATATYPE   /*!< 1-bit data. In the word all bits are swapped */
248 /**
249   * @}
250   */
251 
252 /** @defgroup HASH_HMAC_KEY   key length only for HMAC mode
253   * @{
254   */
255 #define HASH_SHORTKEY      0x00000000U   /*!< HMAC Key size is <= block size (64 or 128 bytes) */
256 #define HASH_LONGKEY       HASH_CR_LKEY  /*!< HMAC Key size is > block size (64 or 128 bytes) */
257 /**
258   * @}
259   */
260 
261 /** @defgroup HASH_flags_definition  HASH flags definitions
262   * @{
263   */
264 #define HASH_FLAG_DINIS            HASH_SR_DINIS  /*!< 16 locations are free in the DIN : a new block can be entered in the Peripheral */
265 #define HASH_FLAG_DCIS             HASH_SR_DCIS   /*!< Digest calculation complete                                                     */
266 #define HASH_FLAG_DMAS             HASH_SR_DMAS   /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing                      */
267 #define HASH_FLAG_BUSY             HASH_SR_BUSY   /*!< The hash core is Busy, processing a block of data                               */
268 #define HASH_FLAG_DINNE            HASH_CR_DINNE  /*!< DIN not empty : the input buffer contains at least one word of data             */
269 /**
270   * @}
271   */
272 
273 /** @defgroup HASH_interrupts_definition   HASH interrupts definitions
274   * @{
275   */
276 #define HASH_IT_DINI               HASH_IMR_DINIE  /*!< A new block can be entered into the input buffer (DIN) */
277 #define HASH_IT_DCI                HASH_IMR_DCIE   /*!< Digest calculation complete                            */
278 
279 /**
280   * @}
281   */
282 
283 /**
284   * @}
285   */
286 
287 /* Exported macros -----------------------------------------------------------*/
288 /** @defgroup HASH_Exported_Macros HASH Exported Macros
289   * @{
290   */
291 
292 /** @brief  Check whether or not the specified HASH flag is set.
293   * @param  __HANDLE__ specifies the HASH handle.
294   * @param  __FLAG__ specifies the flag to check.
295   *        This parameter can be one of the following values:
296   *            @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer.
297   *            @arg @ref HASH_FLAG_DCIS Digest calculation complete.
298   *            @arg @ref HASH_FLAG_DMAS DMA interface is enabled (DMAE=1) or a transfer is ongoing.
299   *            @arg @ref HASH_FLAG_BUSY The hash core is Busy : processing a block of data.
300   *            @arg @ref HASH_FLAG_DINNE DIN not empty : the input buffer contains at least one word of data.
301   * @retval The new state of __FLAG__ (TRUE or FALSE).
302   */
303 #define __HAL_HASH_GET_FLAG(__HANDLE__, __FLAG__)  (((__FLAG__) > 8U)  ?                    \
304                                                     (((__HANDLE__)->Instance->CR & (__FLAG__)) == (__FLAG__)) :\
305                                                     (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) )
306 
307 
308 /** @brief  Clear the specified HASH flag.
309   * @param  __HANDLE__ specifies the HASH handle.
310   * @param  __FLAG__ specifies the flag to clear.
311   *        This parameter can be one of the following values:
312   *            @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer.
313   *            @arg @ref HASH_FLAG_DCIS Digest calculation complete
314   * @retval None
315   */
316 #define __HAL_HASH_CLEAR_FLAG(__HANDLE__, __FLAG__) CLEAR_BIT((__HANDLE__)->Instance->SR, (__FLAG__))
317 
318 /** @brief  Check whether the specified HASH interrupt source is enabled or not.
319   * @param  __HANDLE__ specifies the HASH handle.
320   * @param __INTERRUPT__ HASH interrupt source to check
321   *         This parameter can be one of the following values :
322   *            @arg @ref HASH_IT_DINI  A new block can be entered into the input buffer (DIN)
323   *            @arg @ref HASH_IT_DCI   Digest calculation complete
324   * @retval State of interruption (TRUE or FALSE).
325   */
326 
327 #define __HAL_HASH_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMR\
328                                                               & (__INTERRUPT__)) == (__INTERRUPT__))
329 
330 /** @brief  Enable the specified HASH interrupt.
331   * @param  __HANDLE__ specifies the HASH handle.
332   * @param  __INTERRUPT__ specifies the HASH interrupt source to enable.
333   *          This parameter can be one of the following values:
334   *            @arg @ref HASH_IT_DINI  A new block can be entered into the input buffer (DIN)
335   *            @arg @ref HASH_IT_DCI   Digest calculation complete
336   * @retval None
337   */
338 #define __HAL_HASH_ENABLE_IT(__HANDLE__, __INTERRUPT__)   SET_BIT((__HANDLE__)->Instance->IMR, (__INTERRUPT__))
339 
340 /** @brief  Disable the specified HASH interrupt.
341   * @param  __HANDLE__ specifies the HASH handle.
342   * @param  __INTERRUPT__ specifies the HASH interrupt source to disable.
343   *          This parameter can be one of the following values:
344   *            @arg @ref HASH_IT_DINI  A new block can be entered into the input buffer (DIN)
345   *            @arg @ref HASH_IT_DCI   Digest calculation complete
346   * @retval None
347   */
348 #define __HAL_HASH_DISABLE_IT(__HANDLE__, __INTERRUPT__)   CLEAR_BIT((__HANDLE__)->Instance->IMR, (__INTERRUPT__))
349 
350 /** @brief Reset HASH handle state.
351   * @param  __HANDLE__ HASH handle.
352   * @retval None
353   */
354 
355 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
356 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) do{\
357                                                       (__HANDLE__)->State = HAL_HASH_STATE_RESET;\
358                                                       (__HANDLE__)->MspInitCallback = NULL;      \
359                                                       (__HANDLE__)->MspDeInitCallback = NULL;    \
360                                                      }while(0)
361 #else
362 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET)
363 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
364 
365 
366 /**
367   * @brief  Enable the multi-buffer DMA transfer mode.
368   * @note   This bit is set when hashing large files when multiple DMA transfers are needed.
369   * @retval None
370   */
371 #define __HAL_HASH_SET_MDMAT()          SET_BIT(HASH->CR, HASH_CR_MDMAT)
372 
373 /**
374   * @brief  Disable the multi-buffer DMA transfer mode.
375   * @retval None
376   */
377 #define __HAL_HASH_RESET_MDMAT()        CLEAR_BIT(HASH->CR, HASH_CR_MDMAT)
378 
379 
380 /**
381   * @}
382  */
383 
384 /* Exported functions --------------------------------------------------------*/
385 
386 /** @addtogroup HASH_Exported_Functions HASH Exported Functions
387   * @{
388   */
389 
390 /** @addtogroup HASH_Exported_Functions_Group1 Initialization and de-initialization functions
391   * @{
392   */
393 HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash);
394 HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash);
395 void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash);
396 void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash);
397 HAL_StatusTypeDef HAL_HASH_GetConfig(HASH_HandleTypeDef *hhash, HASH_ConfigTypeDef *pConf);
398 HAL_StatusTypeDef HAL_HASH_SetConfig(HASH_HandleTypeDef *hhash, HASH_ConfigTypeDef *pConf);
399 
400 /* Callbacks Register/UnRegister functions  ***********************************/
401 #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
402 HAL_StatusTypeDef HAL_HASH_RegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID,
403                                             pHASH_CallbackTypeDef pCallback);
404 HAL_StatusTypeDef HAL_HASH_UnRegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID);
405 #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
406 
407 /**
408   * @}
409   */
410 
411 /** @addtogroup HASH_Exported_Functions_Group2 HASH processing functions
412   * @{
413   */
414 
415 HAL_StatusTypeDef HAL_HASH_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
416                                  uint8_t *const pOutBuffer,
417                                  uint32_t Timeout);
418 HAL_StatusTypeDef HAL_HASH_Start_IT(HASH_HandleTypeDef *hhash, const  uint8_t *const pInBuffer, uint32_t Size,
419                                     uint8_t  *const pOutBuffer);
420 HAL_StatusTypeDef HAL_HASH_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
421                                      uint8_t  *const pOutBuffer);
422 
423 HAL_StatusTypeDef HAL_HASH_Accumulate(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
424                                       uint32_t Timeout);
425 HAL_StatusTypeDef HAL_HASH_AccumulateLast(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
426                                           uint8_t *const pOutBuffer,
427                                           uint32_t Timeout);
428 HAL_StatusTypeDef HAL_HASH_AccumulateLast_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
429                                              uint8_t *const pOutBuffer);
430 HAL_StatusTypeDef HAL_HASH_Accumulate_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size);
431 
432 /**
433   * @}
434   */
435 
436 /** @addtogroup HASH_Exported_Functions_Group3 HMAC processing functions in interrupt mode
437   * @{
438   */
439 HAL_StatusTypeDef HAL_HASH_HMAC_Start(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
440                                       uint8_t  *const pOutBuffer,
441                                       uint32_t Timeout);
442 HAL_StatusTypeDef HAL_HASH_HMAC_Start_DMA(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
443                                           uint8_t *const pOutBuffer);
444 HAL_StatusTypeDef HAL_HASH_HMAC_Start_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
445                                          uint8_t *const pOutBuffer);
446 
447 HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
448                                            uint32_t Timeout);
449 HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size,
450                                                uint8_t *const pOutBuffer, uint32_t Timeout);
451 HAL_StatusTypeDef HAL_HASH_HMAC_Accumulate_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer, uint32_t Size);
452 HAL_StatusTypeDef HAL_HASH_HMAC_AccumulateLast_IT(HASH_HandleTypeDef *hhash, const uint8_t *const pInBuffer,
453                                                   uint32_t Size, uint8_t *const pOutBuffer);
454 
455 /**
456   * @}
457   */
458 
459 /** @addtogroup HASH_Exported_Functions_Group4 HASH IRQ handler management
460   * @{
461   */
462 
463 void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash);
464 void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash);
465 void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash);
466 void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash);
467 HAL_HASH_StateTypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash);
468 uint32_t HAL_HASH_GetError(HASH_HandleTypeDef *hhash);
469 
470 HAL_StatusTypeDef HAL_HASH_ProcessSuspend(HASH_HandleTypeDef *hhash);
471 void HAL_HASH_Resume(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer);
472 void HAL_HASH_Suspend(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer);
473 
474 
475 /**
476   * @}
477   */
478 
479 /**
480   * @}
481   */
482 
483 /* Private macros --------------------------------------------------------*/
484 /** @defgroup HASH_Private_Macros   HASH Private Macros
485   * @{
486   */
487 
488 /**
489   * @brief  Return digest length in bytes.
490   * @retval Digest length
491   */
492 #if defined(HASH_ALGOSELECTION_SHA512)
493 #define HASH_DIGEST_LENGTH(__HANDLE__) (((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA1) ?  20U : \
494                                          ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA224) ?  28U : \
495                                           ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA256) ?  32U : \
496                                            ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA384) ?  48U : \
497                                             ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA512_224) ?  28U : \
498                                              ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA512_256) ?  32U : \
499                                               ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA512) ?  64U : 20U ) ) ))))))
500 #else
501 #define HASH_DIGEST_LENGTH(__HANDLE__) (((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA1) ?  20U : \
502                                          ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA224) ?  28U : \
503                                           ((READ_BIT((__HANDLE__)->Instance->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA256) ?  32U :20U))))
504 #endif
505 
506 /**
507   * @brief Ensure that HASH input data type is valid.
508   * @param __DATATYPE__ HASH input data type.
509   * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid)
510   */
511 #define IS_HASH_DATATYPE(__DATATYPE__) (((__DATATYPE__) == HASH_NO_SWAP)|| \
512                                         ((__DATATYPE__) == HASH_HALFWORD_SWAP)|| \
513                                         ((__DATATYPE__) == HASH_BYTE_SWAP) || \
514                                         ((__DATATYPE__) == HASH_BIT_SWAP))
515 
516 /**
517   * @brief Ensure that HASH input Algorithm is valid.
518   * @param __ALGORITHM__ HASH Algorithm.
519   * @retval SET (__ALGORITHM__ is valid) or RESET (__ALGORITHM__ is invalid)
520   */
521 #if defined(HASH_ALGOSELECTION_SHA512)
522 #define IS_HASH_ALGORITHM(__ALGORITHM__) (((__ALGORITHM__) == HASH_ALGOSELECTION_SHA1)|| \
523                                           ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA224)|| \
524                                           ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA256)|| \
525                                           ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA384)|| \
526                                           ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512_224)|| \
527                                           ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512_256)|| \
528                                           ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA512))
529 #else
530 #define IS_HASH_ALGORITHM(__ALGORITHM__) (((__ALGORITHM__) == HASH_ALGOSELECTION_SHA1)|| \
531                                           ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA224)|| \
532                                           ((__ALGORITHM__) == HASH_ALGOSELECTION_SHA256))
533 #endif
534 
535 /**
536   * @}
537   */
538 
539 /* Private constants ---------------------------------------------------------*/
540 /** @defgroup HASH_Private_Constants HASH Private Constants
541   * @{
542   */
543 
544 /**
545   * @}
546   */
547 /* Private defines -----------------------------------------------------------*/
548 /** @defgroup HASH_Private_Defines HASH Private Defines
549   * @{
550   */
551 
552 /**
553   * @}
554   */
555 
556 /* Private variables ---------------------------------------------------------*/
557 /** @defgroup HASH_Private_Variables HASH Private Variables
558   * @{
559   */
560 
561 /**
562   * @}
563   */
564 /* Private functions -----------------------------------------------------------*/
565 
566 /** @addtogroup HASH_Private_Functions HASH Private Functions
567   * @{
568   */
569 
570 /**
571   * @}
572   */
573 
574 /**
575   * @}
576   */
577 #endif /*  HASH*/
578 /**
579   * @}
580   */
581 
582 
583 #ifdef __cplusplus
584 }
585 #endif
586 
587 
588 #endif /* STM32H5xx_HAL_HASH_H */