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