stm32f2xx_hash.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /**
  2. ******************************************************************************
  3. * @file stm32f2xx_hash.c
  4. * @author MCD Application Team
  5. * @version V1.1.3
  6. * @date 31-December-2021
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the HASH / HMAC Processor (HASH) peripheral:
  9. * - Initialization and Configuration functions
  10. * - Message Digest generation functions
  11. * - context swapping functions
  12. * - DMA interface function
  13. * - Interrupts and flags management
  14. *
  15. * @verbatim
  16. *
  17. * ===================================================================
  18. * How to use this driver
  19. * ===================================================================
  20. * HASH operation :
  21. * ----------------
  22. * 1. Enable the HASH controller clock using
  23. * RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_HASH, ENABLE) function.
  24. *
  25. * 2. Initialise the HASH using HASH_Init() function.
  26. *
  27. * 3 . Reset the HASH processor core, so that the HASH will be ready
  28. * to compute he message digest of a new message by using
  29. * HASH_Reset() function.
  30. *
  31. * 4. Enable the HASH controller using the HASH_Cmd() function.
  32. *
  33. * 5. if using DMA for Data input transfer, Activate the DMA Request
  34. * using HASH_DMACmd() function
  35. *
  36. * 6. if DMA is not used for data transfer, use HASH_DataIn() function
  37. * to enter data to IN FIFO.
  38. *
  39. *
  40. * 7. Configure the Number of valid bits in last word of the message
  41. * using HASH_SetLastWordValidBitsNbr() function.
  42. *
  43. * 8. if the message length is not an exact multiple of 512 bits,
  44. * then the function HASH_StartDigest() must be called to
  45. * launch the computation of the final digest.
  46. *
  47. * 9. Once computed, the digest can be read using HASH_GetDigest()
  48. * function.
  49. *
  50. * 10. To control HASH events you can use one of the following
  51. * two methods:
  52. * a- Check on HASH flags using the HASH_GetFlagStatus() function.
  53. * b- Use HASH interrupts through the function HASH_ITConfig() at
  54. * initialization phase and HASH_GetITStatus() function into
  55. * interrupt routines in hashing phase.
  56. * After checking on a flag you should clear it using HASH_ClearFlag()
  57. * function. And after checking on an interrupt event you should
  58. * clear it using HASH_ClearITPendingBit() function.
  59. *
  60. * 11. Save and restore hash processor context using
  61. * HASH_SaveContext() and HASH_RestoreContext() functions.
  62. *
  63. *
  64. *
  65. * HMAC operation :
  66. * ----------------
  67. * The HMAC algorithm is used for message authentication, by
  68. * irreversibly binding the message being processed to a key chosen
  69. * by the user.
  70. * For HMAC specifications, refer to "HMAC: keyed-hashing for message
  71. * authentication, H. Krawczyk, M. Bellare, R. Canetti, February 1997"
  72. *
  73. * Basically, the HMAC algorithm consists of two nested hash operations:
  74. * HMAC(message) = Hash[((key | pad) XOR 0x5C) | Hash(((key | pad) XOR 0x36) | message)]
  75. * where:
  76. * - "pad" is a sequence of zeroes needed to extend the key to the
  77. * length of the underlying hash function data block (that is
  78. * 512 bits for both the SHA-1 and MD5 hash algorithms)
  79. * - "|" represents the concatenation operator
  80. *
  81. *
  82. * To compute the HMAC, four different phases are required:
  83. *
  84. * 1. Initialise the HASH using HASH_Init() function to do HMAC
  85. * operation.
  86. *
  87. * 2. The key (to be used for the inner hash function) is then given
  88. * to the core. This operation follows the same mechanism as the
  89. * one used to send the message in the hash operation (that is,
  90. * by HASH_DataIn() function and, finally,
  91. * HASH_StartDigest() function.
  92. *
  93. * 3. Once the last word has been entered and computation has started,
  94. * the hash processor elaborates the key. It is then ready to
  95. * accept the message text using the same mechanism as the one
  96. * used to send the message in the hash operation.
  97. *
  98. * 4. After the first hash round, the hash processor returns "ready"
  99. * to indicate that it is ready to receive the key to be used for
  100. * the outer hash function (normally, this key is the same as the
  101. * one used for the inner hash function). When the last word of
  102. * the key is entered and computation starts, the HMAC result is
  103. * made available using HASH_GetDigest() function.
  104. *
  105. *
  106. * @endverbatim
  107. *
  108. ******************************************************************************
  109. * @attention
  110. *
  111. * Copyright (c) 2012 STMicroelectronics.
  112. * All rights reserved.
  113. *
  114. * This software is licensed under terms that can be found in the LICENSE file
  115. * in the root directory of this software component.
  116. * If no LICENSE file comes with this software, it is provided AS-IS.
  117. *
  118. ******************************************************************************
  119. */
  120. /* Includes ------------------------------------------------------------------*/
  121. #include "stm32f2xx_hash.h"
  122. #include "stm32f2xx_rcc.h"
  123. /** @addtogroup STM32F2xx_StdPeriph_Driver
  124. * @{
  125. */
  126. /** @defgroup HASH
  127. * @brief HASH driver modules
  128. * @{
  129. */
  130. /* Private typedef -----------------------------------------------------------*/
  131. /* Private define ------------------------------------------------------------*/
  132. /* Private macro -------------------------------------------------------------*/
  133. /* Private variables ---------------------------------------------------------*/
  134. /* Private function prototypes -----------------------------------------------*/
  135. /* Private functions ---------------------------------------------------------*/
  136. /** @defgroup HASH_Private_Functions
  137. * @{
  138. */
  139. /** @defgroup HASH_Group1 Initialization and Configuration functions
  140. * @brief Initialization and Configuration functions
  141. *
  142. @verbatim
  143. ===============================================================================
  144. Initialization and Configuration functions
  145. ===============================================================================
  146. This section provides functions allowing to
  147. - Initialize the HASH peripheral
  148. - Configure the HASH Processor
  149. - MD5/SHA1,
  150. - HASH/HMAC,
  151. - datatype
  152. - HMAC Key (if mode = HMAC)
  153. - Reset the HASH Processor
  154. @endverbatim
  155. * @{
  156. */
  157. /**
  158. * @brief Deinitializes the HASH peripheral registers to their default reset values
  159. * @param None
  160. * @retval None
  161. */
  162. void HASH_DeInit(void)
  163. {
  164. /* Enable HASH reset state */
  165. RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_HASH, ENABLE);
  166. /* Release HASH from reset state */
  167. RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_HASH, DISABLE);
  168. }
  169. /**
  170. * @brief Initializes the HASH peripheral according to the specified parameters
  171. * in the HASH_InitStruct structure.
  172. * @note the hash processor is reset when calling this function so that the
  173. * HASH will be ready to compute the message digest of a new message.
  174. * There is no need to call HASH_Reset() function.
  175. * @param HASH_InitStruct: pointer to a HASH_InitTypeDef structure that contains
  176. * the configuration information for the HASH peripheral.
  177. * @note The field HASH_HMACKeyType in HASH_InitTypeDef must be filled only
  178. * if the algorithm mode is HMAC.
  179. * @retval None
  180. */
  181. void HASH_Init(HASH_InitTypeDef* HASH_InitStruct)
  182. {
  183. /* Check the parameters */
  184. assert_param(IS_HASH_ALGOSELECTION(HASH_InitStruct->HASH_AlgoSelection));
  185. assert_param(IS_HASH_DATATYPE(HASH_InitStruct->HASH_DataType));
  186. assert_param(IS_HASH_ALGOMODE(HASH_InitStruct->HASH_AlgoMode));
  187. /* Configure the Algorithm used, algorithm mode and the datatype */
  188. HASH->CR &= ~ (HASH_CR_ALGO | HASH_CR_DATATYPE | HASH_CR_MODE);
  189. HASH->CR |= (HASH_InitStruct->HASH_AlgoSelection | \
  190. HASH_InitStruct->HASH_DataType | \
  191. HASH_InitStruct->HASH_AlgoMode);
  192. /* if algorithm mode is HMAC, set the Key */
  193. if(HASH_InitStruct->HASH_AlgoMode == HASH_AlgoMode_HMAC)
  194. {
  195. assert_param(IS_HASH_HMAC_KEYTYPE(HASH_InitStruct->HASH_HMACKeyType));
  196. HASH->CR &= ~HASH_CR_LKEY;
  197. HASH->CR |= HASH_InitStruct->HASH_HMACKeyType;
  198. }
  199. /* Reset the HASH processor core, so that the HASH will be ready to compute
  200. the message digest of a new message */
  201. HASH->CR |= HASH_CR_INIT;
  202. }
  203. /**
  204. * @brief Fills each HASH_InitStruct member with its default value.
  205. * @param HASH_InitStruct : pointer to a HASH_InitTypeDef structure which will
  206. * be initialized.
  207. * @note The default values set are : Processor mode is HASH, Algorithm selected is SHA1,
  208. * Data type selected is 32b and HMAC Key Type is short key.
  209. * @retval None
  210. */
  211. void HASH_StructInit(HASH_InitTypeDef* HASH_InitStruct)
  212. {
  213. /* Initialize the HASH_AlgoSelection member */
  214. HASH_InitStruct->HASH_AlgoSelection = HASH_AlgoSelection_SHA1;
  215. /* Initialize the HASH_AlgoMode member */
  216. HASH_InitStruct->HASH_AlgoMode = HASH_AlgoMode_HASH;
  217. /* Initialize the HASH_DataType member */
  218. HASH_InitStruct->HASH_DataType = HASH_DataType_32b;
  219. /* Initialize the HASH_HMACKeyType member */
  220. HASH_InitStruct->HASH_HMACKeyType = HASH_HMACKeyType_ShortKey;
  221. }
  222. /**
  223. * @brief Resets the HASH processor core, so that the HASH will be ready
  224. * to compute the message digest of a new message.
  225. * @note Calling this function will clear the HASH_SR_DCIS (Digest calculation
  226. * completion interrupt status) bit corresponding to HASH_IT_DCI
  227. * interrupt and HASH_FLAG_DCIS flag.
  228. * @param None
  229. * @retval None
  230. */
  231. void HASH_Reset(void)
  232. {
  233. /* Reset the HASH processor core */
  234. HASH->CR |= HASH_CR_INIT;
  235. }
  236. /**
  237. * @}
  238. */
  239. /** @defgroup HASH_Group2 Message Digest generation functions
  240. * @brief Message Digest generation functions
  241. *
  242. @verbatim
  243. ===============================================================================
  244. Message Digest generation functions
  245. ===============================================================================
  246. This section provides functions allowing the generation of message digest:
  247. - Push data in the IN FIFO : using HASH_DataIn()
  248. - Get the number of words set in IN FIFO, use HASH_GetInFIFOWordsNbr()
  249. - set the last word valid bits number using HASH_SetLastWordValidBitsNbr()
  250. - start digest calculation : using HASH_StartDigest()
  251. - Get the Digest message : using HASH_GetDigest()
  252. @endverbatim
  253. * @{
  254. */
  255. /**
  256. * @brief Configure the Number of valid bits in last word of the message
  257. * @param ValidNumber: Number of valid bits in last word of the message.
  258. * This parameter must be a number between 0 and 0x1F.
  259. * - 0x00: All 32 bits of the last data written are valid
  260. * - 0x01: Only bit [0] of the last data written is valid
  261. * - 0x02: Only bits[1:0] of the last data written are valid
  262. * - 0x03: Only bits[2:0] of the last data written are valid
  263. * - ...
  264. * - 0x1F: Only bits[30:0] of the last data written are valid
  265. * @note The Number of valid bits must be set before to start the message
  266. * digest competition (in Hash and HMAC) and key treatment(in HMAC).
  267. * @retval None
  268. */
  269. void HASH_SetLastWordValidBitsNbr(uint16_t ValidNumber)
  270. {
  271. /* Check the parameters */
  272. assert_param(IS_HASH_VALIDBITSNUMBER(ValidNumber));
  273. /* Configure the Number of valid bits in last word of the message */
  274. HASH->STR &= ~(HASH_STR_NBW);
  275. HASH->STR |= ValidNumber;
  276. }
  277. /**
  278. * @brief Writes data in the Data Input FIFO
  279. * @param Data: new data of the message to be processed.
  280. * @retval None
  281. */
  282. void HASH_DataIn(uint32_t Data)
  283. {
  284. /* Write in the DIN register a new data */
  285. HASH->DIN = Data;
  286. }
  287. /**
  288. * @brief Returns the number of words already pushed into the IN FIFO.
  289. * @param None
  290. * @retval The value of words already pushed into the IN FIFO.
  291. */
  292. uint8_t HASH_GetInFIFOWordsNbr(void)
  293. {
  294. /* Return the value of NBW bits */
  295. return ((HASH->CR & HASH_CR_NBW) >> 8);
  296. }
  297. /**
  298. * @brief Provides the message digest result.
  299. * @note In MD5 mode, Data[4] filed of HASH_MsgDigest structure is not used
  300. * and is read as zero.
  301. * @param HASH_MessageDigest: pointer to a HASH_MsgDigest structure which will
  302. * hold the message digest result
  303. * @retval None
  304. */
  305. void HASH_GetDigest(HASH_MsgDigest* HASH_MessageDigest)
  306. {
  307. /* Get the data field */
  308. HASH_MessageDigest->Data[0] = HASH->HR[0];
  309. HASH_MessageDigest->Data[1] = HASH->HR[1];
  310. HASH_MessageDigest->Data[2] = HASH->HR[2];
  311. HASH_MessageDigest->Data[3] = HASH->HR[3];
  312. HASH_MessageDigest->Data[4] = HASH->HR[4];
  313. }
  314. /**
  315. * @brief Starts the message padding and calculation of the final message
  316. * @param None
  317. * @retval None
  318. */
  319. void HASH_StartDigest(void)
  320. {
  321. /* Start the Digest calculation */
  322. HASH->STR |= HASH_STR_DCAL;
  323. }
  324. /**
  325. * @}
  326. */
  327. /** @defgroup HASH_Group3 Context swapping functions
  328. * @brief Context swapping functions
  329. *
  330. @verbatim
  331. ===============================================================================
  332. Context swapping functions
  333. ===============================================================================
  334. This section provides functions allowing to save and store HASH Context
  335. It is possible to interrupt a HASH/HMAC process to perform another processing
  336. with a higher priority, and to complete the interrupted process later on, when
  337. the higher priority task is complete. To do so, the context of the interrupted
  338. task must be saved from the HASH registers to memory, and then be restored
  339. from memory to the HASH registers.
  340. 1. To save the current context, use HASH_SaveContext() function
  341. 2. To restore the saved context, use HASH_RestoreContext() function
  342. @endverbatim
  343. * @{
  344. */
  345. /**
  346. * @brief Save the Hash peripheral Context.
  347. * @note The context can be saved only when no block is currently being
  348. * processed. So user must wait for DINIS = 1 (the last block has been
  349. * processed and the input FIFO is empty) or NBW != 0 (the FIFO is not
  350. * full and no processing is ongoing).
  351. * @param HASH_ContextSave: pointer to a HASH_Context structure that contains
  352. * the repository for current context.
  353. * @retval None
  354. */
  355. void HASH_SaveContext(HASH_Context* HASH_ContextSave)
  356. {
  357. uint8_t i = 0;
  358. /* save context registers */
  359. HASH_ContextSave->HASH_IMR = HASH->IMR;
  360. HASH_ContextSave->HASH_STR = HASH->STR;
  361. HASH_ContextSave->HASH_CR = HASH->CR;
  362. for(i=0; i<=50;i++)
  363. {
  364. HASH_ContextSave->HASH_CSR[i] = HASH->CSR[i];
  365. }
  366. }
  367. /**
  368. * @brief Restore the Hash peripheral Context.
  369. * @note After calling this function, user can restart the processing from the
  370. * point where it has been interrupted.
  371. * @param HASH_ContextRestore: pointer to a HASH_Context structure that contains
  372. * the repository for saved context.
  373. * @retval None
  374. */
  375. void HASH_RestoreContext(HASH_Context* HASH_ContextRestore)
  376. {
  377. uint8_t i = 0;
  378. /* restore context registers */
  379. HASH->IMR = HASH_ContextRestore->HASH_IMR;
  380. HASH->STR = HASH_ContextRestore->HASH_STR;
  381. HASH->CR = HASH_ContextRestore->HASH_CR;
  382. /* Initialize the hash processor */
  383. HASH->CR |= HASH_CR_INIT;
  384. /* continue restoring context registers */
  385. for(i=0; i<=50;i++)
  386. {
  387. HASH->CSR[i] = HASH_ContextRestore->HASH_CSR[i];
  388. }
  389. }
  390. /**
  391. * @}
  392. */
  393. /** @defgroup HASH_Group4 HASH's DMA interface Configuration function
  394. * @brief HASH's DMA interface Configuration function
  395. *
  396. @verbatim
  397. ===============================================================================
  398. HASH's DMA interface Configuration function
  399. ===============================================================================
  400. This section provides functions allowing to configure the DMA interface for
  401. HASH/ HMAC data input transfer.
  402. When the DMA mode is enabled (using the HASH_DMACmd() function), data can be
  403. sent to the IN FIFO using the DMA peripheral.
  404. @endverbatim
  405. * @{
  406. */
  407. /**
  408. * @brief Enables or disables the HASH DMA interface.
  409. * @note The DMA is disabled by hardware after the end of transfer.
  410. * @param NewState: new state of the selected HASH DMA transfer request.
  411. * This parameter can be: ENABLE or DISABLE.
  412. * @retval None
  413. */
  414. void HASH_DMACmd(FunctionalState NewState)
  415. {
  416. /* Check the parameters */
  417. assert_param(IS_FUNCTIONAL_STATE(NewState));
  418. if (NewState != DISABLE)
  419. {
  420. /* Enable the HASH DMA request */
  421. HASH->CR |= HASH_CR_DMAE;
  422. }
  423. else
  424. {
  425. /* Disable the HASH DMA request */
  426. HASH->CR &= ~HASH_CR_DMAE;
  427. }
  428. }
  429. /**
  430. * @}
  431. */
  432. /** @defgroup HASH_Group5 Interrupts and flags management functions
  433. * @brief Interrupts and flags management functions
  434. *
  435. @verbatim
  436. ===============================================================================
  437. Interrupts and flags management functions
  438. ===============================================================================
  439. This section provides functions allowing to configure the HASH Interrupts and
  440. to get the status and clear flags and Interrupts pending bits.
  441. The HASH provides 2 Interrupts sources and 5 Flags:
  442. Flags :
  443. ----------
  444. 1. HASH_FLAG_DINIS : set when 16 locations are free in the Data IN FIFO
  445. which means that a new block (512 bit) can be entered
  446. into the input buffer.
  447. 2. HASH_FLAG_DCIS : set when Digest calculation is complete
  448. 3. HASH_FLAG_DMAS : set when HASH's DMA interface is enabled (DMAE=1) or
  449. a transfer is ongoing.
  450. This Flag is cleared only by hardware.
  451. 4. HASH_FLAG_BUSY : set when The hash core is processing a block of data
  452. This Flag is cleared only by hardware.
  453. 5. HASH_FLAG_DINNE : set when Data IN FIFO is not empty which means that
  454. the Data IN FIFO contains at least one word of data.
  455. This Flag is cleared only by hardware.
  456. Interrupts :
  457. ------------
  458. 1. HASH_IT_DINI : if enabled, this interrupt source is pending when 16
  459. locations are free in the Data IN FIFO which means that
  460. a new block (512 bit) can be entered into the input buffer.
  461. This interrupt source is cleared using
  462. HASH_ClearITPendingBit(HASH_IT_DINI) function.
  463. 2. HASH_IT_DCI : if enabled, this interrupt source is pending when Digest
  464. calculation is complete.
  465. This interrupt source is cleared using
  466. HASH_ClearITPendingBit(HASH_IT_DCI) function.
  467. Managing the HASH controller events :
  468. ------------------------------------
  469. The user should identify which mode will be used in his application to manage
  470. the HASH controller events: Polling mode or Interrupt mode.
  471. 1. In the Polling Mode it is advised to use the following functions:
  472. - HASH_GetFlagStatus() : to check if flags events occur.
  473. - HASH_ClearFlag() : to clear the flags events.
  474. 2. In the Interrupt Mode it is advised to use the following functions:
  475. - HASH_ITConfig() : to enable or disable the interrupt source.
  476. - HASH_GetITStatus() : to check if Interrupt occurs.
  477. - HASH_ClearITPendingBit() : to clear the Interrupt pending Bit
  478. (corresponding Flag).
  479. @endverbatim
  480. * @{
  481. */
  482. /**
  483. * @brief Enables or disables the specified HASH interrupts.
  484. * @param HASH_IT: specifies the HASH interrupt source to be enabled or disabled.
  485. * This parameter can be any combination of the following values:
  486. * @arg HASH_IT_DINI: Data Input interrupt
  487. * @arg HASH_IT_DCI: Digest Calculation Completion Interrupt
  488. * @param NewState: new state of the specified HASH interrupt.
  489. * This parameter can be: ENABLE or DISABLE.
  490. * @retval None
  491. */
  492. void HASH_ITConfig(uint8_t HASH_IT, FunctionalState NewState)
  493. {
  494. /* Check the parameters */
  495. assert_param(IS_HASH_IT(HASH_IT));
  496. assert_param(IS_FUNCTIONAL_STATE(NewState));
  497. if (NewState != DISABLE)
  498. {
  499. /* Enable the selected HASH interrupt */
  500. HASH->IMR |= HASH_IT;
  501. }
  502. else
  503. {
  504. /* Disable the selected HASH interrupt */
  505. HASH->IMR &= (uint8_t) ~HASH_IT;
  506. }
  507. }
  508. /**
  509. * @brief Checks whether the specified HASH flag is set or not.
  510. * @param HASH_FLAG: specifies the HASH flag to check.
  511. * This parameter can be one of the following values:
  512. * @arg HASH_FLAG_DINIS: Data input interrupt status flag
  513. * @arg HASH_FLAG_DCIS: Digest calculation completion interrupt status flag
  514. * @arg HASH_FLAG_BUSY: Busy flag
  515. * @arg HASH_FLAG_DMAS: DMAS Status flag
  516. * @arg HASH_FLAG_DINNE: Data Input register (DIN) not empty status flag
  517. * @retval The new state of HASH_FLAG (SET or RESET)
  518. */
  519. FlagStatus HASH_GetFlagStatus(uint16_t HASH_FLAG)
  520. {
  521. FlagStatus bitstatus = RESET;
  522. uint32_t tempreg = 0;
  523. /* Check the parameters */
  524. assert_param(IS_HASH_GET_FLAG(HASH_FLAG));
  525. /* check if the FLAG is in CR register */
  526. if ((HASH_FLAG & HASH_FLAG_DINNE) != (uint16_t)RESET )
  527. {
  528. tempreg = HASH->CR;
  529. }
  530. else /* The FLAG is in SR register */
  531. {
  532. tempreg = HASH->SR;
  533. }
  534. /* Check the status of the specified HASH flag */
  535. if ((tempreg & HASH_FLAG) != (uint16_t)RESET)
  536. {
  537. /* HASH is set */
  538. bitstatus = SET;
  539. }
  540. else
  541. {
  542. /* HASH_FLAG is reset */
  543. bitstatus = RESET;
  544. }
  545. /* Return the HASH_FLAG status */
  546. return bitstatus;
  547. }
  548. /**
  549. * @brief Clears the HASH flags.
  550. * @param HASH_FLAG: specifies the flag to clear.
  551. * This parameter can be any combination of the following values:
  552. * @arg HASH_FLAG_DINIS: Data Input Flag
  553. * @arg HASH_FLAG_DCIS: Digest Calculation Completion Flag
  554. * @retval None
  555. */
  556. void HASH_ClearFlag(uint16_t HASH_FLAG)
  557. {
  558. /* Check the parameters */
  559. assert_param(IS_HASH_CLEAR_FLAG(HASH_FLAG));
  560. /* Clear the selected HASH flags */
  561. HASH->SR = ~(uint32_t)HASH_FLAG;
  562. }
  563. /**
  564. * @brief Checks whether the specified HASH interrupt has occurred or not.
  565. * @param HASH_IT: specifies the HASH interrupt source to check.
  566. * This parameter can be one of the following values:
  567. * @arg HASH_IT_DINI: Data Input interrupt
  568. * @arg HASH_IT_DCI: Digest Calculation Completion Interrupt
  569. * @retval The new state of HASH_IT (SET or RESET).
  570. */
  571. ITStatus HASH_GetITStatus(uint8_t HASH_IT)
  572. {
  573. ITStatus bitstatus = RESET;
  574. uint32_t tmpreg = 0;
  575. /* Check the parameters */
  576. assert_param(IS_HASH_GET_IT(HASH_IT));
  577. /* Check the status of the specified HASH interrupt */
  578. tmpreg = HASH->SR;
  579. if (((HASH->IMR & tmpreg) & HASH_IT) != RESET)
  580. {
  581. /* HASH_IT is set */
  582. bitstatus = SET;
  583. }
  584. else
  585. {
  586. /* HASH_IT is reset */
  587. bitstatus = RESET;
  588. }
  589. /* Return the HASH_IT status */
  590. return bitstatus;
  591. }
  592. /**
  593. * @brief Clears the HASH interrupt pending bit(s).
  594. * @param HASH_IT: specifies the HASH interrupt pending bit(s) to clear.
  595. * This parameter can be any combination of the following values:
  596. * @arg HASH_IT_DINI: Data Input interrupt
  597. * @arg HASH_IT_DCI: Digest Calculation Completion Interrupt
  598. * @retval None
  599. */
  600. void HASH_ClearITPendingBit(uint8_t HASH_IT)
  601. {
  602. /* Check the parameters */
  603. assert_param(IS_HASH_IT(HASH_IT));
  604. /* Clear the selected HASH interrupt pending bit */
  605. HASH->SR = (uint8_t)~HASH_IT;
  606. }
  607. /**
  608. * @}
  609. */
  610. /**
  611. * @}
  612. */
  613. /**
  614. * @}
  615. */
  616. /**
  617. * @}
  618. */