stm32l4xx_hal_hash.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_hash.h
  4. * @author MCD Application Team
  5. * @brief Header file of HASH 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. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32L4xx_HAL_HASH_H
  20. #define STM32L4xx_HAL_HASH_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l4xx_hal_def.h"
  26. /** @addtogroup STM32L4xx_HAL_Driver
  27. * @{
  28. */
  29. #if defined (HASH)
  30. /** @addtogroup HASH
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup HASH_Exported_Types HASH Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief HASH Configuration Structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit data.
  43. This parameter can be a value of @ref HASH_Data_Type. */
  44. uint32_t KeySize; /*!< The key size is used only in HMAC operation. */
  45. uint8_t *pKey; /*!< The key is used only in HMAC operation. */
  46. } HASH_InitTypeDef;
  47. /**
  48. * @brief HAL State structures definition
  49. */
  50. typedef enum
  51. {
  52. HAL_HASH_STATE_RESET = 0x00U, /*!< Peripheral is not initialized */
  53. HAL_HASH_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
  54. HAL_HASH_STATE_BUSY = 0x02U, /*!< Processing (hashing) is ongoing */
  55. HAL_HASH_STATE_TIMEOUT = 0x06U, /*!< Timeout state */
  56. HAL_HASH_STATE_ERROR = 0x07U, /*!< Error state */
  57. HAL_HASH_STATE_SUSPENDED = 0x08U /*!< Suspended state */
  58. } HAL_HASH_StateTypeDef;
  59. /**
  60. * @brief HAL phase structures definition
  61. */
  62. typedef enum
  63. {
  64. HAL_HASH_PHASE_READY = 0x01U, /*!< HASH peripheral is ready to start */
  65. HAL_HASH_PHASE_PROCESS = 0x02U, /*!< HASH peripheral is in HASH processing phase */
  66. HAL_HASH_PHASE_HMAC_STEP_1 = 0x03U, /*!< HASH peripheral is in HMAC step 1 processing phase
  67. (step 1 consists in entering the inner hash function key) */
  68. HAL_HASH_PHASE_HMAC_STEP_2 = 0x04U, /*!< HASH peripheral is in HMAC step 2 processing phase
  69. (step 2 consists in entering the message text) */
  70. HAL_HASH_PHASE_HMAC_STEP_3 = 0x05U /*!< HASH peripheral is in HMAC step 3 processing phase
  71. (step 3 consists in entering the outer hash function key) */
  72. } HAL_HASH_PhaseTypeDef;
  73. /**
  74. * @brief HAL HASH mode suspend definitions
  75. */
  76. typedef enum
  77. {
  78. HAL_HASH_SUSPEND_NONE = 0x00U, /*!< HASH peripheral suspension not requested */
  79. HAL_HASH_SUSPEND = 0x01U /*!< HASH peripheral suspension is requested */
  80. } HAL_HASH_SuspendTypeDef;
  81. #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
  82. /**
  83. * @brief HAL HASH common Callback ID enumeration definition
  84. */
  85. typedef enum
  86. {
  87. HAL_HASH_MSPINIT_CB_ID = 0x00U, /*!< HASH MspInit callback ID */
  88. HAL_HASH_MSPDEINIT_CB_ID = 0x01U, /*!< HASH MspDeInit callback ID */
  89. HAL_HASH_INPUTCPLT_CB_ID = 0x02U, /*!< HASH input completion callback ID */
  90. HAL_HASH_DGSTCPLT_CB_ID = 0x03U, /*!< HASH digest computation completion callback ID */
  91. HAL_HASH_ERROR_CB_ID = 0x04U, /*!< HASH error callback ID */
  92. } HAL_HASH_CallbackIDTypeDef;
  93. #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
  94. /**
  95. * @brief HASH Handle Structure definition
  96. */
  97. #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
  98. typedef struct __HASH_HandleTypeDef
  99. #else
  100. typedef struct
  101. #endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */
  102. {
  103. HASH_InitTypeDef Init; /*!< HASH required parameters */
  104. uint8_t *pHashInBuffPtr; /*!< Pointer to input buffer */
  105. uint8_t *pHashOutBuffPtr; /*!< Pointer to output buffer (digest) */
  106. uint8_t *pHashKeyBuffPtr; /*!< Pointer to key buffer (HMAC only) */
  107. uint8_t *pHashMsgBuffPtr; /*!< Pointer to message buffer (HMAC only) */
  108. uint32_t HashBuffSize; /*!< Size of buffer to be processed */
  109. __IO uint32_t HashInCount; /*!< Counter of inputted data */
  110. __IO uint32_t HashITCounter; /*!< Counter of issued interrupts */
  111. __IO uint32_t HashKeyCount; /*!< Counter for Key inputted data (HMAC only) */
  112. HAL_StatusTypeDef Status; /*!< HASH peripheral status */
  113. HAL_HASH_PhaseTypeDef Phase; /*!< HASH peripheral phase */
  114. DMA_HandleTypeDef *hdmain; /*!< HASH In DMA Handle parameters */
  115. HAL_LockTypeDef Lock; /*!< Locking object */
  116. __IO HAL_HASH_StateTypeDef State; /*!< HASH peripheral state */
  117. HAL_HASH_SuspendTypeDef SuspendRequest; /*!< HASH peripheral suspension request flag */
  118. FlagStatus DigestCalculationDisable; /*!< Digest calculation phase skip (MDMAT bit control) for multi-buffers DMA-based HMAC computation */
  119. __IO uint32_t NbWordsAlreadyPushed; /*!< Numbers of words already pushed in FIFO before inputting new block */
  120. __IO uint32_t ErrorCode; /*!< HASH Error code */
  121. __IO uint32_t Accumulation; /*!< HASH multi buffers accumulation flag */
  122. #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
  123. void (* InCpltCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH input completion callback */
  124. void (* DgstCpltCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH digest computation completion callback */
  125. void (* ErrorCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH error callback */
  126. void (* MspInitCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH Msp Init callback */
  127. void (* MspDeInitCallback)(struct __HASH_HandleTypeDef *hhash); /*!< HASH Msp DeInit callback */
  128. #endif /* (USE_HAL_HASH_REGISTER_CALLBACKS) */
  129. } HASH_HandleTypeDef;
  130. #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
  131. /**
  132. * @brief HAL HASH Callback pointer definition
  133. */
  134. typedef void (*pHASH_CallbackTypeDef)(HASH_HandleTypeDef *hhash); /*!< pointer to a HASH common callback functions */
  135. #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
  136. /**
  137. * @}
  138. */
  139. /* Exported constants --------------------------------------------------------*/
  140. /** @defgroup HASH_Exported_Constants HASH Exported Constants
  141. * @{
  142. */
  143. /** @defgroup HASH_Algo_Selection HASH algorithm selection
  144. * @{
  145. */
  146. #define HASH_ALGOSELECTION_SHA1 0x00000000U /*!< HASH function is SHA1 */
  147. #define HASH_ALGOSELECTION_MD5 HASH_CR_ALGO_0 /*!< HASH function is MD5 */
  148. #define HASH_ALGOSELECTION_SHA224 HASH_CR_ALGO_1 /*!< HASH function is SHA224 */
  149. #define HASH_ALGOSELECTION_SHA256 HASH_CR_ALGO /*!< HASH function is SHA256 */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup HASH_Algorithm_Mode HASH algorithm mode
  154. * @{
  155. */
  156. #define HASH_ALGOMODE_HASH 0x00000000U /*!< Algorithm is HASH */
  157. #define HASH_ALGOMODE_HMAC HASH_CR_MODE /*!< Algorithm is HMAC */
  158. /**
  159. * @}
  160. */
  161. /** @defgroup HASH_Data_Type HASH input data type
  162. * @{
  163. */
  164. #define HASH_DATATYPE_32B 0x00000000U /*!< 32-bit data. No swapping */
  165. #define HASH_DATATYPE_16B HASH_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped */
  166. #define HASH_DATATYPE_8B HASH_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped */
  167. #define HASH_DATATYPE_1B HASH_CR_DATATYPE /*!< 1-bit data. In the word all bits are swapped */
  168. /**
  169. * @}
  170. */
  171. /** @defgroup HASH_HMAC_Long_key_only_for_HMAC_mode HMAC key length type
  172. * @{
  173. */
  174. #define HASH_HMAC_KEYTYPE_SHORTKEY 0x00000000U /*!< HMAC Key size is <= 64 bytes */
  175. #define HASH_HMAC_KEYTYPE_LONGKEY HASH_CR_LKEY /*!< HMAC Key size is > 64 bytes */
  176. /**
  177. * @}
  178. */
  179. /** @defgroup HASH_flags_definition HASH flags definitions
  180. * @{
  181. */
  182. #define HASH_FLAG_DINIS HASH_SR_DINIS /*!< 16 locations are free in the DIN : a new block can be entered in the Peripheral */
  183. #define HASH_FLAG_DCIS HASH_SR_DCIS /*!< Digest calculation complete */
  184. #define HASH_FLAG_DMAS HASH_SR_DMAS /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing */
  185. #define HASH_FLAG_BUSY HASH_SR_BUSY /*!< The hash core is Busy, processing a block of data */
  186. #define HASH_FLAG_DINNE HASH_CR_DINNE /*!< DIN not empty : the input buffer contains at least one word of data */
  187. /**
  188. * @}
  189. */
  190. /** @defgroup HASH_interrupts_definition HASH interrupts definitions
  191. * @{
  192. */
  193. #define HASH_IT_DINI HASH_IMR_DINIE /*!< A new block can be entered into the input buffer (DIN) */
  194. #define HASH_IT_DCI HASH_IMR_DCIE /*!< Digest calculation complete */
  195. /**
  196. * @}
  197. */
  198. /** @defgroup HASH_Error_Definition HASH Error Definition
  199. * @{
  200. */
  201. #define HAL_HASH_ERROR_NONE 0x00000000U /*!< No error */
  202. #define HAL_HASH_ERROR_IT 0x00000001U /*!< IT-based process error */
  203. #define HAL_HASH_ERROR_DMA 0x00000002U /*!< DMA-based process error */
  204. #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1U)
  205. #define HAL_HASH_ERROR_INVALID_CALLBACK 0x00000004U /*!< Invalid Callback error */
  206. #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
  207. /**
  208. * @}
  209. */
  210. /**
  211. * @}
  212. */
  213. /* Exported macros -----------------------------------------------------------*/
  214. /** @defgroup HASH_Exported_Macros HASH Exported Macros
  215. * @{
  216. */
  217. /** @brief Check whether or not the specified HASH flag is set.
  218. * @param __FLAG__ specifies the flag to check.
  219. * This parameter can be one of the following values:
  220. * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer.
  221. * @arg @ref HASH_FLAG_DCIS Digest calculation complete.
  222. * @arg @ref HASH_FLAG_DMAS DMA interface is enabled (DMAE=1) or a transfer is ongoing.
  223. * @arg @ref HASH_FLAG_BUSY The hash core is Busy : processing a block of data.
  224. * @arg @ref HASH_FLAG_DINNE DIN not empty : the input buffer contains at least one word of data.
  225. * @retval The new state of __FLAG__ (TRUE or FALSE).
  226. */
  227. #define __HAL_HASH_GET_FLAG(__FLAG__) (((__FLAG__) > 8U) ? \
  228. ((HASH->CR & (__FLAG__)) == (__FLAG__)) :\
  229. ((HASH->SR & (__FLAG__)) == (__FLAG__)) )
  230. /** @brief Clear the specified HASH flag.
  231. * @param __FLAG__ specifies the flag to clear.
  232. * This parameter can be one of the following values:
  233. * @arg @ref HASH_FLAG_DINIS A new block can be entered into the input buffer.
  234. * @arg @ref HASH_FLAG_DCIS Digest calculation complete
  235. * @retval None
  236. */
  237. #define __HAL_HASH_CLEAR_FLAG(__FLAG__) CLEAR_BIT(HASH->SR, (__FLAG__))
  238. /** @brief Enable the specified HASH interrupt.
  239. * @param __INTERRUPT__ specifies the HASH interrupt source to enable.
  240. * This parameter can be one of the following values:
  241. * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN)
  242. * @arg @ref HASH_IT_DCI Digest calculation complete
  243. * @retval None
  244. */
  245. #define __HAL_HASH_ENABLE_IT(__INTERRUPT__) SET_BIT(HASH->IMR, (__INTERRUPT__))
  246. /** @brief Disable the specified HASH interrupt.
  247. * @param __INTERRUPT__ specifies the HASH interrupt source to disable.
  248. * This parameter can be one of the following values:
  249. * @arg @ref HASH_IT_DINI A new block can be entered into the input buffer (DIN)
  250. * @arg @ref HASH_IT_DCI Digest calculation complete
  251. * @retval None
  252. */
  253. #define __HAL_HASH_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(HASH->IMR, (__INTERRUPT__))
  254. /** @brief Reset HASH handle state.
  255. * @param __HANDLE__ HASH handle.
  256. * @retval None
  257. */
  258. #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
  259. #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) do{\
  260. (__HANDLE__)->State = HAL_HASH_STATE_RESET;\
  261. (__HANDLE__)->MspInitCallback = NULL; \
  262. (__HANDLE__)->MspDeInitCallback = NULL; \
  263. }while(0)
  264. #else
  265. #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET)
  266. #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
  267. /** @brief Reset HASH handle status.
  268. * @param __HANDLE__ HASH handle.
  269. * @retval None
  270. */
  271. #define __HAL_HASH_RESET_HANDLE_STATUS(__HANDLE__) ((__HANDLE__)->Status = HAL_OK)
  272. /**
  273. * @brief Enable the multi-buffer DMA transfer mode.
  274. * @note This bit is set when hashing large files when multiple DMA transfers are needed.
  275. * @retval None
  276. */
  277. #define __HAL_HASH_SET_MDMAT() SET_BIT(HASH->CR, HASH_CR_MDMAT)
  278. /**
  279. * @brief Disable the multi-buffer DMA transfer mode.
  280. * @retval None
  281. */
  282. #define __HAL_HASH_RESET_MDMAT() CLEAR_BIT(HASH->CR, HASH_CR_MDMAT)
  283. /**
  284. * @brief Start the digest computation.
  285. * @retval None
  286. */
  287. #define __HAL_HASH_START_DIGEST() SET_BIT(HASH->STR, HASH_STR_DCAL)
  288. /**
  289. * @brief Set the number of valid bits in the last word written in data register DIN.
  290. * @param __SIZE__ size in bytes of last data written in Data register.
  291. * @retval None
  292. */
  293. #define __HAL_HASH_SET_NBVALIDBITS(__SIZE__) MODIFY_REG(HASH->STR, HASH_STR_NBLW, 8U * ((__SIZE__) % 4U))
  294. /**
  295. * @brief Reset the HASH core.
  296. * @retval None
  297. */
  298. #define __HAL_HASH_INIT() SET_BIT(HASH->CR, HASH_CR_INIT)
  299. /**
  300. * @}
  301. */
  302. /* Private macros --------------------------------------------------------*/
  303. /** @defgroup HASH_Private_Macros HASH Private Macros
  304. * @{
  305. */
  306. /**
  307. * @brief Return digest length in bytes.
  308. * @retval Digest length
  309. */
  310. #define HASH_DIGEST_LENGTH() ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA1) ? 20U : \
  311. ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA224) ? 28U : \
  312. ((READ_BIT(HASH->CR, HASH_CR_ALGO) == HASH_ALGOSELECTION_SHA256) ? 32U : 16U ) ) )
  313. /**
  314. * @brief Return number of words already pushed in the FIFO.
  315. * @retval Number of words already pushed in the FIFO
  316. */
  317. #define HASH_NBW_PUSHED() ((READ_BIT(HASH->CR, HASH_CR_NBW)) >> 8U)
  318. /**
  319. * @brief Ensure that HASH input data type is valid.
  320. * @param __DATATYPE__ HASH input data type.
  321. * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid)
  322. */
  323. #define IS_HASH_DATATYPE(__DATATYPE__) (((__DATATYPE__) == HASH_DATATYPE_32B)|| \
  324. ((__DATATYPE__) == HASH_DATATYPE_16B)|| \
  325. ((__DATATYPE__) == HASH_DATATYPE_8B) || \
  326. ((__DATATYPE__) == HASH_DATATYPE_1B))
  327. /**
  328. * @brief Ensure that input data buffer size is valid for multi-buffer HASH
  329. * processing in DMA mode.
  330. * @note This check is valid only for multi-buffer HASH processing in DMA mode.
  331. * @param __SIZE__ input data buffer size.
  332. * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
  333. */
  334. #define IS_HASH_DMA_MULTIBUFFER_SIZE(__SIZE__) ((READ_BIT(HASH->CR, HASH_CR_MDMAT) == 0U) || (((__SIZE__) % 4U) == 0U))
  335. /**
  336. * @brief Ensure that input data buffer size is valid for multi-buffer HMAC
  337. * processing in DMA mode.
  338. * @note This check is valid only for multi-buffer HMAC processing in DMA mode.
  339. * @param __HANDLE__ HASH handle.
  340. * @param __SIZE__ input data buffer size.
  341. * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
  342. */
  343. #define IS_HMAC_DMA_MULTIBUFFER_SIZE(__HANDLE__,__SIZE__) ((((__HANDLE__)->DigestCalculationDisable) == RESET)\
  344. || (((__SIZE__) % 4U) == 0U))
  345. /**
  346. * @brief Ensure that handle phase is set to HASH processing.
  347. * @param __HANDLE__ HASH handle.
  348. * @retval SET (handle phase is set to HASH processing) or RESET (handle phase is not set to HASH processing)
  349. */
  350. #define IS_HASH_PROCESSING(__HANDLE__) ((__HANDLE__)->Phase == HAL_HASH_PHASE_PROCESS)
  351. /**
  352. * @brief Ensure that handle phase is set to HMAC processing.
  353. * @param __HANDLE__ HASH handle.
  354. * @retval SET (handle phase is set to HMAC processing) or RESET (handle phase is not set to HMAC processing)
  355. */
  356. #define IS_HMAC_PROCESSING(__HANDLE__) (((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_1) || \
  357. ((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_2) || \
  358. ((__HANDLE__)->Phase == HAL_HASH_PHASE_HMAC_STEP_3))
  359. /**
  360. * @}
  361. */
  362. /* Include HASH HAL Extended module */
  363. #include "stm32l4xx_hal_hash_ex.h"
  364. /* Exported functions --------------------------------------------------------*/
  365. /** @addtogroup HASH_Exported_Functions HASH Exported Functions
  366. * @{
  367. */
  368. /** @addtogroup HASH_Exported_Functions_Group1 Initialization and de-initialization functions
  369. * @{
  370. */
  371. /* Initialization/de-initialization methods **********************************/
  372. HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash);
  373. HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash);
  374. void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash);
  375. void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash);
  376. void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash);
  377. void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash);
  378. void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash);
  379. /* Callbacks Register/UnRegister functions ***********************************/
  380. #if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
  381. HAL_StatusTypeDef HAL_HASH_RegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID,
  382. pHASH_CallbackTypeDef pCallback);
  383. HAL_StatusTypeDef HAL_HASH_UnRegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID);
  384. #endif /* USE_HAL_HASH_REGISTER_CALLBACKS */
  385. /**
  386. * @}
  387. */
  388. /** @addtogroup HASH_Exported_Functions_Group2 HASH processing functions in polling mode
  389. * @{
  390. */
  391. /* HASH processing using polling *********************************************/
  392. HAL_StatusTypeDef HAL_HASH_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
  393. uint32_t Timeout);
  394. HAL_StatusTypeDef HAL_HASH_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
  395. uint32_t Timeout);
  396. HAL_StatusTypeDef HAL_HASH_MD5_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
  397. HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
  398. HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
  399. uint8_t *pOutBuffer, uint32_t Timeout);
  400. HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
  401. uint8_t *pOutBuffer, uint32_t Timeout);
  402. /**
  403. * @}
  404. */
  405. /** @addtogroup HASH_Exported_Functions_Group3 HASH processing functions in interrupt mode
  406. * @{
  407. */
  408. /* HASH processing using IT **************************************************/
  409. HAL_StatusTypeDef HAL_HASH_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
  410. uint8_t *pOutBuffer);
  411. HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
  412. HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
  413. uint8_t *pOutBuffer);
  414. HAL_StatusTypeDef HAL_HASH_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
  415. uint8_t *pOutBuffer);
  416. HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
  417. HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
  418. uint8_t *pOutBuffer);
  419. void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash);
  420. /**
  421. * @}
  422. */
  423. /** @addtogroup HASH_Exported_Functions_Group4 HASH processing functions in DMA mode
  424. * @{
  425. */
  426. /* HASH processing using DMA *************************************************/
  427. HAL_StatusTypeDef HAL_HASH_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
  428. HAL_StatusTypeDef HAL_HASH_SHA1_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout);
  429. HAL_StatusTypeDef HAL_HASH_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
  430. HAL_StatusTypeDef HAL_HASH_MD5_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout);
  431. /**
  432. * @}
  433. */
  434. /** @addtogroup HASH_Exported_Functions_Group5 HMAC processing functions in polling mode
  435. * @{
  436. */
  437. /* HASH-MAC processing using polling *****************************************/
  438. HAL_StatusTypeDef HAL_HMAC_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
  439. uint32_t Timeout);
  440. HAL_StatusTypeDef HAL_HMAC_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
  441. uint32_t Timeout);
  442. /**
  443. * @}
  444. */
  445. /** @addtogroup HASH_Exported_Functions_Group6 HMAC processing functions in interrupt mode
  446. * @{
  447. */
  448. HAL_StatusTypeDef HAL_HMAC_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
  449. uint8_t *pOutBuffer);
  450. HAL_StatusTypeDef HAL_HMAC_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
  451. uint8_t *pOutBuffer);
  452. /**
  453. * @}
  454. */
  455. /** @addtogroup HASH_Exported_Functions_Group7 HMAC processing functions in DMA mode
  456. * @{
  457. */
  458. /* HASH-HMAC processing using DMA ********************************************/
  459. HAL_StatusTypeDef HAL_HMAC_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
  460. HAL_StatusTypeDef HAL_HMAC_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
  461. /**
  462. * @}
  463. */
  464. /** @addtogroup HASH_Exported_Functions_Group8 Peripheral states functions
  465. * @{
  466. */
  467. /* Peripheral State methods **************************************************/
  468. HAL_HASH_StateTypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash);
  469. HAL_StatusTypeDef HAL_HASH_GetStatus(HASH_HandleTypeDef *hhash);
  470. void HAL_HASH_ContextSaving(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer);
  471. void HAL_HASH_ContextRestoring(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer);
  472. void HAL_HASH_SwFeed_ProcessSuspend(HASH_HandleTypeDef *hhash);
  473. HAL_StatusTypeDef HAL_HASH_DMAFeed_ProcessSuspend(HASH_HandleTypeDef *hhash);
  474. uint32_t HAL_HASH_GetError(HASH_HandleTypeDef *hhash);
  475. /**
  476. * @}
  477. */
  478. /**
  479. * @}
  480. */
  481. /* Private functions -----------------------------------------------------------*/
  482. /** @addtogroup HASH_Private_Functions HASH Private Functions
  483. * @{
  484. */
  485. /* Private functions */
  486. HAL_StatusTypeDef HASH_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
  487. uint32_t Timeout, uint32_t Algorithm);
  488. HAL_StatusTypeDef HASH_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
  489. HAL_StatusTypeDef HASH_Accumulate_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
  490. HAL_StatusTypeDef HASH_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
  491. uint32_t Algorithm);
  492. HAL_StatusTypeDef HASH_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
  493. HAL_StatusTypeDef HASH_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout);
  494. HAL_StatusTypeDef HMAC_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
  495. uint32_t Timeout, uint32_t Algorithm);
  496. HAL_StatusTypeDef HMAC_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
  497. uint32_t Algorithm);
  498. HAL_StatusTypeDef HMAC_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm);
  499. /**
  500. * @}
  501. */
  502. /**
  503. * @}
  504. */
  505. #endif /* HASH*/
  506. /**
  507. * @}
  508. */
  509. #ifdef __cplusplus
  510. }
  511. #endif
  512. #endif /* STM32L4xx_HAL_HASH_H */