001
targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_hash_ex.c@0:13413ea9a877, 2022-06-12 (annotated)
- Committer:
- ganlikun
- Date:
- Sun Jun 12 14:02:44 2022 +0000
- Revision:
- 0:13413ea9a877
00
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ganlikun | 0:13413ea9a877 | 1 | /** |
ganlikun | 0:13413ea9a877 | 2 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 3 | * @file stm32f4xx_hal_hash_ex.c |
ganlikun | 0:13413ea9a877 | 4 | * @author MCD Application Team |
ganlikun | 0:13413ea9a877 | 5 | * @version V1.7.1 |
ganlikun | 0:13413ea9a877 | 6 | * @date 14-April-2017 |
ganlikun | 0:13413ea9a877 | 7 | * @brief HASH HAL Extension module driver. |
ganlikun | 0:13413ea9a877 | 8 | * This file provides firmware functions to manage the following |
ganlikun | 0:13413ea9a877 | 9 | * functionalities of HASH peripheral: |
ganlikun | 0:13413ea9a877 | 10 | * + Extended HASH processing functions based on SHA224 Algorithm |
ganlikun | 0:13413ea9a877 | 11 | * + Extended HASH processing functions based on SHA256 Algorithm |
ganlikun | 0:13413ea9a877 | 12 | * |
ganlikun | 0:13413ea9a877 | 13 | @verbatim |
ganlikun | 0:13413ea9a877 | 14 | ============================================================================== |
ganlikun | 0:13413ea9a877 | 15 | ##### How to use this driver ##### |
ganlikun | 0:13413ea9a877 | 16 | ============================================================================== |
ganlikun | 0:13413ea9a877 | 17 | [..] |
ganlikun | 0:13413ea9a877 | 18 | The HASH HAL driver can be used as follows: |
ganlikun | 0:13413ea9a877 | 19 | (#)Initialize the HASH low level resources by implementing the HAL_HASH_MspInit(): |
ganlikun | 0:13413ea9a877 | 20 | (##) Enable the HASH interface clock using __HAL_RCC_HASH_CLK_ENABLE() |
ganlikun | 0:13413ea9a877 | 21 | (##) In case of using processing APIs based on interrupts (e.g. HAL_HMACEx_SHA224_Start()) |
ganlikun | 0:13413ea9a877 | 22 | (+++) Configure the HASH interrupt priority using HAL_NVIC_SetPriority() |
ganlikun | 0:13413ea9a877 | 23 | (+++) Enable the HASH IRQ handler using HAL_NVIC_EnableIRQ() |
ganlikun | 0:13413ea9a877 | 24 | (+++) In HASH IRQ handler, call HAL_HASH_IRQHandler() |
ganlikun | 0:13413ea9a877 | 25 | (##) In case of using DMA to control data transfer (e.g. HAL_HMACEx_SH224_Start_DMA()) |
ganlikun | 0:13413ea9a877 | 26 | (+++) Enable the DMAx interface clock using __DMAx_CLK_ENABLE() |
ganlikun | 0:13413ea9a877 | 27 | (+++) Configure and enable one DMA stream one for managing data transfer from |
ganlikun | 0:13413ea9a877 | 28 | memory to peripheral (input stream). Managing data transfer from |
ganlikun | 0:13413ea9a877 | 29 | peripheral to memory can be performed only using CPU |
ganlikun | 0:13413ea9a877 | 30 | (+++) Associate the initialized DMA handle to the HASH DMA handle |
ganlikun | 0:13413ea9a877 | 31 | using __HAL_LINKDMA() |
ganlikun | 0:13413ea9a877 | 32 | (+++) Configure the priority and enable the NVIC for the transfer complete |
ganlikun | 0:13413ea9a877 | 33 | interrupt on the DMA Stream: HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ() |
ganlikun | 0:13413ea9a877 | 34 | (#)Initialize the HASH HAL using HAL_HASH_Init(). This function configures mainly: |
ganlikun | 0:13413ea9a877 | 35 | (##) The data type: 1-bit, 8-bit, 16-bit and 32-bit. |
ganlikun | 0:13413ea9a877 | 36 | (##) For HMAC, the encryption key. |
ganlikun | 0:13413ea9a877 | 37 | (##) For HMAC, the key size used for encryption. |
ganlikun | 0:13413ea9a877 | 38 | (#)Three processing functions are available: |
ganlikun | 0:13413ea9a877 | 39 | (##) Polling mode: processing APIs are blocking functions |
ganlikun | 0:13413ea9a877 | 40 | i.e. they process the data and wait till the digest computation is finished |
ganlikun | 0:13413ea9a877 | 41 | e.g. HAL_HASHEx_SHA224_Start() |
ganlikun | 0:13413ea9a877 | 42 | (##) Interrupt mode: encryption and decryption APIs are not blocking functions |
ganlikun | 0:13413ea9a877 | 43 | i.e. they process the data under interrupt |
ganlikun | 0:13413ea9a877 | 44 | e.g. HAL_HASHEx_SHA224_Start_IT() |
ganlikun | 0:13413ea9a877 | 45 | (##) DMA mode: processing APIs are not blocking functions and the CPU is |
ganlikun | 0:13413ea9a877 | 46 | not used for data transfer i.e. the data transfer is ensured by DMA |
ganlikun | 0:13413ea9a877 | 47 | e.g. HAL_HASHEx_SHA224_Start_DMA() |
ganlikun | 0:13413ea9a877 | 48 | (#)When the processing function is called at first time after HAL_HASH_Init() |
ganlikun | 0:13413ea9a877 | 49 | the HASH peripheral is initialized and processes the buffer in input. |
ganlikun | 0:13413ea9a877 | 50 | After that, the digest computation is started. |
ganlikun | 0:13413ea9a877 | 51 | When processing multi-buffer use the accumulate function to write the |
ganlikun | 0:13413ea9a877 | 52 | data in the peripheral without starting the digest computation. In last |
ganlikun | 0:13413ea9a877 | 53 | buffer use the start function to input the last buffer ans start the digest |
ganlikun | 0:13413ea9a877 | 54 | computation. |
ganlikun | 0:13413ea9a877 | 55 | (##) e.g. HAL_HASHEx_SHA224_Accumulate() : write 1st data buffer in the peripheral without starting the digest computation |
ganlikun | 0:13413ea9a877 | 56 | (##) write (n-1)th data buffer in the peripheral without starting the digest computation |
ganlikun | 0:13413ea9a877 | 57 | (##) HAL_HASHEx_SHA224_Start() : write (n)th data buffer in the peripheral and start the digest computation |
ganlikun | 0:13413ea9a877 | 58 | (#)In HMAC mode, there is no Accumulate API. Only Start API is available. |
ganlikun | 0:13413ea9a877 | 59 | (#)In case of using DMA, call the DMA start processing e.g. HAL_HASHEx_SHA224_Start_DMA(). |
ganlikun | 0:13413ea9a877 | 60 | After that, call the finish function in order to get the digest value |
ganlikun | 0:13413ea9a877 | 61 | e.g. HAL_HASHEx_SHA224_Finish() |
ganlikun | 0:13413ea9a877 | 62 | (#)Call HAL_HASH_DeInit() to deinitialize the HASH peripheral. |
ganlikun | 0:13413ea9a877 | 63 | |
ganlikun | 0:13413ea9a877 | 64 | @endverbatim |
ganlikun | 0:13413ea9a877 | 65 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 66 | * @attention |
ganlikun | 0:13413ea9a877 | 67 | * |
ganlikun | 0:13413ea9a877 | 68 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
ganlikun | 0:13413ea9a877 | 69 | * |
ganlikun | 0:13413ea9a877 | 70 | * Redistribution and use in source and binary forms, with or without modification, |
ganlikun | 0:13413ea9a877 | 71 | * are permitted provided that the following conditions are met: |
ganlikun | 0:13413ea9a877 | 72 | * 1. Redistributions of source code must retain the above copyright notice, |
ganlikun | 0:13413ea9a877 | 73 | * this list of conditions and the following disclaimer. |
ganlikun | 0:13413ea9a877 | 74 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ganlikun | 0:13413ea9a877 | 75 | * this list of conditions and the following disclaimer in the documentation |
ganlikun | 0:13413ea9a877 | 76 | * and/or other materials provided with the distribution. |
ganlikun | 0:13413ea9a877 | 77 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
ganlikun | 0:13413ea9a877 | 78 | * may be used to endorse or promote products derived from this software |
ganlikun | 0:13413ea9a877 | 79 | * without specific prior written permission. |
ganlikun | 0:13413ea9a877 | 80 | * |
ganlikun | 0:13413ea9a877 | 81 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ganlikun | 0:13413ea9a877 | 82 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ganlikun | 0:13413ea9a877 | 83 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ganlikun | 0:13413ea9a877 | 84 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
ganlikun | 0:13413ea9a877 | 85 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ganlikun | 0:13413ea9a877 | 86 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
ganlikun | 0:13413ea9a877 | 87 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ganlikun | 0:13413ea9a877 | 88 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ganlikun | 0:13413ea9a877 | 89 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ganlikun | 0:13413ea9a877 | 90 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ganlikun | 0:13413ea9a877 | 91 | * |
ganlikun | 0:13413ea9a877 | 92 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 93 | */ |
ganlikun | 0:13413ea9a877 | 94 | |
ganlikun | 0:13413ea9a877 | 95 | /* Includes ------------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 96 | #include "stm32f4xx_hal.h" |
ganlikun | 0:13413ea9a877 | 97 | |
ganlikun | 0:13413ea9a877 | 98 | /** @addtogroup STM32F4xx_HAL_Driver |
ganlikun | 0:13413ea9a877 | 99 | * @{ |
ganlikun | 0:13413ea9a877 | 100 | */ |
ganlikun | 0:13413ea9a877 | 101 | |
ganlikun | 0:13413ea9a877 | 102 | /** @defgroup HASHEx HASHEx |
ganlikun | 0:13413ea9a877 | 103 | * @brief HASH Extension HAL module driver. |
ganlikun | 0:13413ea9a877 | 104 | * @{ |
ganlikun | 0:13413ea9a877 | 105 | */ |
ganlikun | 0:13413ea9a877 | 106 | |
ganlikun | 0:13413ea9a877 | 107 | #ifdef HAL_HASH_MODULE_ENABLED |
ganlikun | 0:13413ea9a877 | 108 | |
ganlikun | 0:13413ea9a877 | 109 | #if defined(STM32F437xx) || defined(STM32F439xx) || defined(STM32F479xx) |
ganlikun | 0:13413ea9a877 | 110 | |
ganlikun | 0:13413ea9a877 | 111 | /* Private typedef -----------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 112 | /* Private define ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 113 | /* Private macro -------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 114 | /* Private variables ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 115 | /* Private function prototypes -----------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 116 | /** @addtogroup HASHEx_Private_Functions |
ganlikun | 0:13413ea9a877 | 117 | * @{ |
ganlikun | 0:13413ea9a877 | 118 | */ |
ganlikun | 0:13413ea9a877 | 119 | static void HASHEx_DMAXferCplt(DMA_HandleTypeDef *hdma); |
ganlikun | 0:13413ea9a877 | 120 | static void HASHEx_WriteData(uint8_t *pInBuffer, uint32_t Size); |
ganlikun | 0:13413ea9a877 | 121 | static void HASHEx_GetDigest(uint8_t *pMsgDigest, uint8_t Size); |
ganlikun | 0:13413ea9a877 | 122 | static void HASHEx_DMAError(DMA_HandleTypeDef *hdma); |
ganlikun | 0:13413ea9a877 | 123 | /** |
ganlikun | 0:13413ea9a877 | 124 | * @} |
ganlikun | 0:13413ea9a877 | 125 | */ |
ganlikun | 0:13413ea9a877 | 126 | |
ganlikun | 0:13413ea9a877 | 127 | /* Private functions ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 128 | |
ganlikun | 0:13413ea9a877 | 129 | /** @addtogroup HASHEx_Private_Functions |
ganlikun | 0:13413ea9a877 | 130 | * @{ |
ganlikun | 0:13413ea9a877 | 131 | */ |
ganlikun | 0:13413ea9a877 | 132 | |
ganlikun | 0:13413ea9a877 | 133 | /** |
ganlikun | 0:13413ea9a877 | 134 | * @brief Writes the input buffer in data register. |
ganlikun | 0:13413ea9a877 | 135 | * @param pInBuffer: Pointer to input buffer |
ganlikun | 0:13413ea9a877 | 136 | * @param Size: The size of input buffer |
ganlikun | 0:13413ea9a877 | 137 | * @retval None |
ganlikun | 0:13413ea9a877 | 138 | */ |
ganlikun | 0:13413ea9a877 | 139 | static void HASHEx_WriteData(uint8_t *pInBuffer, uint32_t Size) |
ganlikun | 0:13413ea9a877 | 140 | { |
ganlikun | 0:13413ea9a877 | 141 | uint32_t buffercounter; |
ganlikun | 0:13413ea9a877 | 142 | uint32_t inputaddr = (uint32_t) pInBuffer; |
ganlikun | 0:13413ea9a877 | 143 | |
ganlikun | 0:13413ea9a877 | 144 | for(buffercounter = 0U; buffercounter < Size; buffercounter+=4U) |
ganlikun | 0:13413ea9a877 | 145 | { |
ganlikun | 0:13413ea9a877 | 146 | HASH->DIN = *(uint32_t*)inputaddr; |
ganlikun | 0:13413ea9a877 | 147 | inputaddr+=4U; |
ganlikun | 0:13413ea9a877 | 148 | } |
ganlikun | 0:13413ea9a877 | 149 | } |
ganlikun | 0:13413ea9a877 | 150 | |
ganlikun | 0:13413ea9a877 | 151 | /** |
ganlikun | 0:13413ea9a877 | 152 | * @brief Provides the message digest result. |
ganlikun | 0:13413ea9a877 | 153 | * @param pMsgDigest: Pointer to the message digest |
ganlikun | 0:13413ea9a877 | 154 | * @param Size: The size of the message digest in bytes |
ganlikun | 0:13413ea9a877 | 155 | * @retval None |
ganlikun | 0:13413ea9a877 | 156 | */ |
ganlikun | 0:13413ea9a877 | 157 | static void HASHEx_GetDigest(uint8_t *pMsgDigest, uint8_t Size) |
ganlikun | 0:13413ea9a877 | 158 | { |
ganlikun | 0:13413ea9a877 | 159 | uint32_t msgdigest = (uint32_t)pMsgDigest; |
ganlikun | 0:13413ea9a877 | 160 | |
ganlikun | 0:13413ea9a877 | 161 | switch(Size) |
ganlikun | 0:13413ea9a877 | 162 | { |
ganlikun | 0:13413ea9a877 | 163 | case 16U: |
ganlikun | 0:13413ea9a877 | 164 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 165 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[0U]); |
ganlikun | 0:13413ea9a877 | 166 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 167 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[1U]); |
ganlikun | 0:13413ea9a877 | 168 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 169 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[2U]); |
ganlikun | 0:13413ea9a877 | 170 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 171 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[3U]); |
ganlikun | 0:13413ea9a877 | 172 | break; |
ganlikun | 0:13413ea9a877 | 173 | case 20U: |
ganlikun | 0:13413ea9a877 | 174 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 175 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[0U]); |
ganlikun | 0:13413ea9a877 | 176 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 177 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[1U]); |
ganlikun | 0:13413ea9a877 | 178 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 179 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[2U]); |
ganlikun | 0:13413ea9a877 | 180 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 181 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[3U]); |
ganlikun | 0:13413ea9a877 | 182 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 183 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[4U]); |
ganlikun | 0:13413ea9a877 | 184 | break; |
ganlikun | 0:13413ea9a877 | 185 | case 28U: |
ganlikun | 0:13413ea9a877 | 186 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 187 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[0U]); |
ganlikun | 0:13413ea9a877 | 188 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 189 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[1U]); |
ganlikun | 0:13413ea9a877 | 190 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 191 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[2U]); |
ganlikun | 0:13413ea9a877 | 192 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 193 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[3U]); |
ganlikun | 0:13413ea9a877 | 194 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 195 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[4U]); |
ganlikun | 0:13413ea9a877 | 196 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 197 | *(uint32_t*)(msgdigest) = __REV(HASH_DIGEST->HR[5U]); |
ganlikun | 0:13413ea9a877 | 198 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 199 | *(uint32_t*)(msgdigest) = __REV(HASH_DIGEST->HR[6U]); |
ganlikun | 0:13413ea9a877 | 200 | break; |
ganlikun | 0:13413ea9a877 | 201 | case 32U: |
ganlikun | 0:13413ea9a877 | 202 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 203 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[0U]); |
ganlikun | 0:13413ea9a877 | 204 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 205 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[1U]); |
ganlikun | 0:13413ea9a877 | 206 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 207 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[2U]); |
ganlikun | 0:13413ea9a877 | 208 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 209 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[3U]); |
ganlikun | 0:13413ea9a877 | 210 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 211 | *(uint32_t*)(msgdigest) = __REV(HASH->HR[4U]); |
ganlikun | 0:13413ea9a877 | 212 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 213 | *(uint32_t*)(msgdigest) = __REV(HASH_DIGEST->HR[5U]); |
ganlikun | 0:13413ea9a877 | 214 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 215 | *(uint32_t*)(msgdigest) = __REV(HASH_DIGEST->HR[6U]); |
ganlikun | 0:13413ea9a877 | 216 | msgdigest+=4U; |
ganlikun | 0:13413ea9a877 | 217 | *(uint32_t*)(msgdigest) = __REV(HASH_DIGEST->HR[7U]); |
ganlikun | 0:13413ea9a877 | 218 | break; |
ganlikun | 0:13413ea9a877 | 219 | default: |
ganlikun | 0:13413ea9a877 | 220 | break; |
ganlikun | 0:13413ea9a877 | 221 | } |
ganlikun | 0:13413ea9a877 | 222 | } |
ganlikun | 0:13413ea9a877 | 223 | |
ganlikun | 0:13413ea9a877 | 224 | /** |
ganlikun | 0:13413ea9a877 | 225 | * @brief DMA HASH Input Data complete callback. |
ganlikun | 0:13413ea9a877 | 226 | * @param hdma: DMA handle |
ganlikun | 0:13413ea9a877 | 227 | * @retval None |
ganlikun | 0:13413ea9a877 | 228 | */ |
ganlikun | 0:13413ea9a877 | 229 | static void HASHEx_DMAXferCplt(DMA_HandleTypeDef *hdma) |
ganlikun | 0:13413ea9a877 | 230 | { |
ganlikun | 0:13413ea9a877 | 231 | HASH_HandleTypeDef* hhash = ( HASH_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
ganlikun | 0:13413ea9a877 | 232 | uint32_t inputaddr = 0U; |
ganlikun | 0:13413ea9a877 | 233 | uint32_t buffersize = 0U; |
ganlikun | 0:13413ea9a877 | 234 | |
ganlikun | 0:13413ea9a877 | 235 | if((HASH->CR & HASH_CR_MODE) != HASH_CR_MODE) |
ganlikun | 0:13413ea9a877 | 236 | { |
ganlikun | 0:13413ea9a877 | 237 | /* Disable the DMA transfer */ |
ganlikun | 0:13413ea9a877 | 238 | HASH->CR &= (uint32_t)(~HASH_CR_DMAE); |
ganlikun | 0:13413ea9a877 | 239 | |
ganlikun | 0:13413ea9a877 | 240 | /* Change HASH peripheral state */ |
ganlikun | 0:13413ea9a877 | 241 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 242 | |
ganlikun | 0:13413ea9a877 | 243 | /* Call Input data transfer complete callback */ |
ganlikun | 0:13413ea9a877 | 244 | HAL_HASH_InCpltCallback(hhash); |
ganlikun | 0:13413ea9a877 | 245 | } |
ganlikun | 0:13413ea9a877 | 246 | else |
ganlikun | 0:13413ea9a877 | 247 | { |
ganlikun | 0:13413ea9a877 | 248 | /* Increment Interrupt counter */ |
ganlikun | 0:13413ea9a877 | 249 | hhash->HashInCount++; |
ganlikun | 0:13413ea9a877 | 250 | /* Disable the DMA transfer before starting the next transfer */ |
ganlikun | 0:13413ea9a877 | 251 | HASH->CR &= (uint32_t)(~HASH_CR_DMAE); |
ganlikun | 0:13413ea9a877 | 252 | |
ganlikun | 0:13413ea9a877 | 253 | if(hhash->HashInCount <= 2U) |
ganlikun | 0:13413ea9a877 | 254 | { |
ganlikun | 0:13413ea9a877 | 255 | /* In case HashInCount = 1, set the DMA to transfer data to HASH DIN register */ |
ganlikun | 0:13413ea9a877 | 256 | if(hhash->HashInCount == 1U) |
ganlikun | 0:13413ea9a877 | 257 | { |
ganlikun | 0:13413ea9a877 | 258 | inputaddr = (uint32_t)hhash->pHashInBuffPtr; |
ganlikun | 0:13413ea9a877 | 259 | buffersize = hhash->HashBuffSize; |
ganlikun | 0:13413ea9a877 | 260 | } |
ganlikun | 0:13413ea9a877 | 261 | /* In case HashInCount = 2, set the DMA to transfer key to HASH DIN register */ |
ganlikun | 0:13413ea9a877 | 262 | else if(hhash->HashInCount == 2U) |
ganlikun | 0:13413ea9a877 | 263 | { |
ganlikun | 0:13413ea9a877 | 264 | inputaddr = (uint32_t)hhash->Init.pKey; |
ganlikun | 0:13413ea9a877 | 265 | buffersize = hhash->Init.KeySize; |
ganlikun | 0:13413ea9a877 | 266 | } |
ganlikun | 0:13413ea9a877 | 267 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 268 | MODIFY_REG(HASH->STR, HASH_STR_NBLW, 8U * (buffersize % 4U)); |
ganlikun | 0:13413ea9a877 | 269 | |
ganlikun | 0:13413ea9a877 | 270 | /* Set the HASH DMA transfer complete */ |
ganlikun | 0:13413ea9a877 | 271 | hhash->hdmain->XferCpltCallback = HASHEx_DMAXferCplt; |
ganlikun | 0:13413ea9a877 | 272 | |
ganlikun | 0:13413ea9a877 | 273 | /* Enable the DMA In DMA Stream */ |
ganlikun | 0:13413ea9a877 | 274 | HAL_DMA_Start_IT(hhash->hdmain, inputaddr, (uint32_t)&HASH->DIN, (buffersize%4U ? (buffersize+3U)/4U:buffersize/4U)); |
ganlikun | 0:13413ea9a877 | 275 | |
ganlikun | 0:13413ea9a877 | 276 | /* Enable DMA requests */ |
ganlikun | 0:13413ea9a877 | 277 | HASH->CR |= (HASH_CR_DMAE); |
ganlikun | 0:13413ea9a877 | 278 | } |
ganlikun | 0:13413ea9a877 | 279 | else |
ganlikun | 0:13413ea9a877 | 280 | { |
ganlikun | 0:13413ea9a877 | 281 | /* Disable the DMA transfer */ |
ganlikun | 0:13413ea9a877 | 282 | HASH->CR &= (uint32_t)(~HASH_CR_DMAE); |
ganlikun | 0:13413ea9a877 | 283 | |
ganlikun | 0:13413ea9a877 | 284 | /* Reset the InCount */ |
ganlikun | 0:13413ea9a877 | 285 | hhash->HashInCount = 0U; |
ganlikun | 0:13413ea9a877 | 286 | |
ganlikun | 0:13413ea9a877 | 287 | /* Change HASH peripheral state */ |
ganlikun | 0:13413ea9a877 | 288 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 289 | |
ganlikun | 0:13413ea9a877 | 290 | /* Call Input data transfer complete callback */ |
ganlikun | 0:13413ea9a877 | 291 | HAL_HASH_InCpltCallback(hhash); |
ganlikun | 0:13413ea9a877 | 292 | } |
ganlikun | 0:13413ea9a877 | 293 | } |
ganlikun | 0:13413ea9a877 | 294 | } |
ganlikun | 0:13413ea9a877 | 295 | |
ganlikun | 0:13413ea9a877 | 296 | /** |
ganlikun | 0:13413ea9a877 | 297 | * @brief DMA HASH communication error callback. |
ganlikun | 0:13413ea9a877 | 298 | * @param hdma: DMA handle |
ganlikun | 0:13413ea9a877 | 299 | * @retval None |
ganlikun | 0:13413ea9a877 | 300 | */ |
ganlikun | 0:13413ea9a877 | 301 | static void HASHEx_DMAError(DMA_HandleTypeDef *hdma) |
ganlikun | 0:13413ea9a877 | 302 | { |
ganlikun | 0:13413ea9a877 | 303 | HASH_HandleTypeDef* hhash = ( HASH_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
ganlikun | 0:13413ea9a877 | 304 | hhash->State= HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 305 | HAL_HASH_ErrorCallback(hhash); |
ganlikun | 0:13413ea9a877 | 306 | } |
ganlikun | 0:13413ea9a877 | 307 | |
ganlikun | 0:13413ea9a877 | 308 | /** |
ganlikun | 0:13413ea9a877 | 309 | * @} |
ganlikun | 0:13413ea9a877 | 310 | */ |
ganlikun | 0:13413ea9a877 | 311 | |
ganlikun | 0:13413ea9a877 | 312 | /* Exported functions --------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 313 | /** @addtogroup HASHEx_Exported_Functions |
ganlikun | 0:13413ea9a877 | 314 | * @{ |
ganlikun | 0:13413ea9a877 | 315 | */ |
ganlikun | 0:13413ea9a877 | 316 | |
ganlikun | 0:13413ea9a877 | 317 | /** @defgroup HASHEx_Group1 HASH processing functions |
ganlikun | 0:13413ea9a877 | 318 | * @brief processing functions using polling mode |
ganlikun | 0:13413ea9a877 | 319 | * |
ganlikun | 0:13413ea9a877 | 320 | @verbatim |
ganlikun | 0:13413ea9a877 | 321 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 322 | ##### HASH processing using polling mode functions ##### |
ganlikun | 0:13413ea9a877 | 323 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 324 | [..] This section provides functions allowing to calculate in polling mode |
ganlikun | 0:13413ea9a877 | 325 | the hash value using one of the following algorithms: |
ganlikun | 0:13413ea9a877 | 326 | (+) SHA224 |
ganlikun | 0:13413ea9a877 | 327 | (+) SHA256 |
ganlikun | 0:13413ea9a877 | 328 | |
ganlikun | 0:13413ea9a877 | 329 | @endverbatim |
ganlikun | 0:13413ea9a877 | 330 | * @{ |
ganlikun | 0:13413ea9a877 | 331 | */ |
ganlikun | 0:13413ea9a877 | 332 | |
ganlikun | 0:13413ea9a877 | 333 | /** |
ganlikun | 0:13413ea9a877 | 334 | * @brief Initializes the HASH peripheral in SHA224 mode |
ganlikun | 0:13413ea9a877 | 335 | * then processes pInBuffer. The digest is available in pOutBuffer |
ganlikun | 0:13413ea9a877 | 336 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 337 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 338 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 339 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 340 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 341 | * @param pOutBuffer: Pointer to the computed digest. Its size must be 28 bytes. |
ganlikun | 0:13413ea9a877 | 342 | * @param Timeout: Specify Timeout value |
ganlikun | 0:13413ea9a877 | 343 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 344 | */ |
ganlikun | 0:13413ea9a877 | 345 | HAL_StatusTypeDef HAL_HASHEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout) |
ganlikun | 0:13413ea9a877 | 346 | { |
ganlikun | 0:13413ea9a877 | 347 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 348 | |
ganlikun | 0:13413ea9a877 | 349 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 350 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 351 | |
ganlikun | 0:13413ea9a877 | 352 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 353 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 354 | |
ganlikun | 0:13413ea9a877 | 355 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 356 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 357 | { |
ganlikun | 0:13413ea9a877 | 358 | /* Select the SHA224 mode and reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 359 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 360 | HASH->CR |= HASH_ALGOSELECTION_SHA224 | HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 361 | } |
ganlikun | 0:13413ea9a877 | 362 | |
ganlikun | 0:13413ea9a877 | 363 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 364 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 365 | |
ganlikun | 0:13413ea9a877 | 366 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 367 | __HAL_HASH_SET_NBVALIDBITS(Size); |
ganlikun | 0:13413ea9a877 | 368 | |
ganlikun | 0:13413ea9a877 | 369 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 370 | HASHEx_WriteData(pInBuffer, Size); |
ganlikun | 0:13413ea9a877 | 371 | |
ganlikun | 0:13413ea9a877 | 372 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 373 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 374 | |
ganlikun | 0:13413ea9a877 | 375 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 376 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 377 | |
ganlikun | 0:13413ea9a877 | 378 | while((HASH->SR & HASH_FLAG_BUSY) == HASH_FLAG_BUSY) |
ganlikun | 0:13413ea9a877 | 379 | { |
ganlikun | 0:13413ea9a877 | 380 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 381 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 382 | { |
ganlikun | 0:13413ea9a877 | 383 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
ganlikun | 0:13413ea9a877 | 384 | { |
ganlikun | 0:13413ea9a877 | 385 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 386 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 387 | |
ganlikun | 0:13413ea9a877 | 388 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 389 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 390 | |
ganlikun | 0:13413ea9a877 | 391 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 392 | } |
ganlikun | 0:13413ea9a877 | 393 | } |
ganlikun | 0:13413ea9a877 | 394 | } |
ganlikun | 0:13413ea9a877 | 395 | |
ganlikun | 0:13413ea9a877 | 396 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 397 | HASHEx_GetDigest(pOutBuffer, 28U); |
ganlikun | 0:13413ea9a877 | 398 | |
ganlikun | 0:13413ea9a877 | 399 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 400 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 401 | |
ganlikun | 0:13413ea9a877 | 402 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 403 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 404 | |
ganlikun | 0:13413ea9a877 | 405 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 406 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 407 | } |
ganlikun | 0:13413ea9a877 | 408 | |
ganlikun | 0:13413ea9a877 | 409 | /** |
ganlikun | 0:13413ea9a877 | 410 | * @brief Initializes the HASH peripheral in SHA256 mode then processes pInBuffer. |
ganlikun | 0:13413ea9a877 | 411 | The digest is available in pOutBuffer. |
ganlikun | 0:13413ea9a877 | 412 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 413 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 414 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 415 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 416 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 417 | * @param pOutBuffer: Pointer to the computed digest. Its size must be 32 bytes. |
ganlikun | 0:13413ea9a877 | 418 | * @param Timeout: Specify Timeout value |
ganlikun | 0:13413ea9a877 | 419 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 420 | */ |
ganlikun | 0:13413ea9a877 | 421 | HAL_StatusTypeDef HAL_HASHEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout) |
ganlikun | 0:13413ea9a877 | 422 | { |
ganlikun | 0:13413ea9a877 | 423 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 424 | |
ganlikun | 0:13413ea9a877 | 425 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 426 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 427 | |
ganlikun | 0:13413ea9a877 | 428 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 429 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 430 | |
ganlikun | 0:13413ea9a877 | 431 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 432 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 433 | { |
ganlikun | 0:13413ea9a877 | 434 | /* Select the SHA256 mode and reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 435 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 436 | HASH->CR |= HASH_ALGOSELECTION_SHA256 | HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 437 | } |
ganlikun | 0:13413ea9a877 | 438 | |
ganlikun | 0:13413ea9a877 | 439 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 440 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 441 | |
ganlikun | 0:13413ea9a877 | 442 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 443 | __HAL_HASH_SET_NBVALIDBITS(Size); |
ganlikun | 0:13413ea9a877 | 444 | |
ganlikun | 0:13413ea9a877 | 445 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 446 | HASHEx_WriteData(pInBuffer, Size); |
ganlikun | 0:13413ea9a877 | 447 | |
ganlikun | 0:13413ea9a877 | 448 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 449 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 450 | |
ganlikun | 0:13413ea9a877 | 451 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 452 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 453 | |
ganlikun | 0:13413ea9a877 | 454 | while((HASH->SR & HASH_FLAG_BUSY) == HASH_FLAG_BUSY) |
ganlikun | 0:13413ea9a877 | 455 | { |
ganlikun | 0:13413ea9a877 | 456 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 457 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 458 | { |
ganlikun | 0:13413ea9a877 | 459 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
ganlikun | 0:13413ea9a877 | 460 | { |
ganlikun | 0:13413ea9a877 | 461 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 462 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 463 | |
ganlikun | 0:13413ea9a877 | 464 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 465 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 466 | |
ganlikun | 0:13413ea9a877 | 467 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 468 | } |
ganlikun | 0:13413ea9a877 | 469 | } |
ganlikun | 0:13413ea9a877 | 470 | } |
ganlikun | 0:13413ea9a877 | 471 | |
ganlikun | 0:13413ea9a877 | 472 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 473 | HASHEx_GetDigest(pOutBuffer, 32U); |
ganlikun | 0:13413ea9a877 | 474 | |
ganlikun | 0:13413ea9a877 | 475 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 476 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 477 | |
ganlikun | 0:13413ea9a877 | 478 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 479 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 480 | |
ganlikun | 0:13413ea9a877 | 481 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 482 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 483 | } |
ganlikun | 0:13413ea9a877 | 484 | |
ganlikun | 0:13413ea9a877 | 485 | |
ganlikun | 0:13413ea9a877 | 486 | /** |
ganlikun | 0:13413ea9a877 | 487 | * @brief Initializes the HASH peripheral in SHA224 mode |
ganlikun | 0:13413ea9a877 | 488 | * then processes pInBuffer. The digest is available in pOutBuffer |
ganlikun | 0:13413ea9a877 | 489 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 490 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 491 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 492 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 493 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 494 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 495 | */ |
ganlikun | 0:13413ea9a877 | 496 | HAL_StatusTypeDef HAL_HASHEx_SHA224_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) |
ganlikun | 0:13413ea9a877 | 497 | { |
ganlikun | 0:13413ea9a877 | 498 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 499 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 500 | |
ganlikun | 0:13413ea9a877 | 501 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 502 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 503 | |
ganlikun | 0:13413ea9a877 | 504 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 505 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 506 | { |
ganlikun | 0:13413ea9a877 | 507 | /* Select the SHA224 mode and reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 508 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 509 | HASH->CR |= HASH_ALGOSELECTION_SHA224 | HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 510 | } |
ganlikun | 0:13413ea9a877 | 511 | |
ganlikun | 0:13413ea9a877 | 512 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 513 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 514 | |
ganlikun | 0:13413ea9a877 | 515 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 516 | __HAL_HASH_SET_NBVALIDBITS(Size); |
ganlikun | 0:13413ea9a877 | 517 | |
ganlikun | 0:13413ea9a877 | 518 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 519 | HASHEx_WriteData(pInBuffer, Size); |
ganlikun | 0:13413ea9a877 | 520 | |
ganlikun | 0:13413ea9a877 | 521 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 522 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 523 | |
ganlikun | 0:13413ea9a877 | 524 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 525 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 526 | |
ganlikun | 0:13413ea9a877 | 527 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 528 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 529 | } |
ganlikun | 0:13413ea9a877 | 530 | |
ganlikun | 0:13413ea9a877 | 531 | |
ganlikun | 0:13413ea9a877 | 532 | /** |
ganlikun | 0:13413ea9a877 | 533 | * @brief Initializes the HASH peripheral in SHA256 mode then processes pInBuffer. |
ganlikun | 0:13413ea9a877 | 534 | The digest is available in pOutBuffer. |
ganlikun | 0:13413ea9a877 | 535 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 536 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 537 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 538 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 539 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 540 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 541 | */ |
ganlikun | 0:13413ea9a877 | 542 | HAL_StatusTypeDef HAL_HASHEx_SHA256_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) |
ganlikun | 0:13413ea9a877 | 543 | { |
ganlikun | 0:13413ea9a877 | 544 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 545 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 546 | |
ganlikun | 0:13413ea9a877 | 547 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 548 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 549 | |
ganlikun | 0:13413ea9a877 | 550 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 551 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 552 | { |
ganlikun | 0:13413ea9a877 | 553 | /* Select the SHA256 mode and reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 554 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 555 | HASH->CR |= HASH_ALGOSELECTION_SHA256 | HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 556 | } |
ganlikun | 0:13413ea9a877 | 557 | |
ganlikun | 0:13413ea9a877 | 558 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 559 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 560 | |
ganlikun | 0:13413ea9a877 | 561 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 562 | __HAL_HASH_SET_NBVALIDBITS(Size); |
ganlikun | 0:13413ea9a877 | 563 | |
ganlikun | 0:13413ea9a877 | 564 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 565 | HASHEx_WriteData(pInBuffer, Size); |
ganlikun | 0:13413ea9a877 | 566 | |
ganlikun | 0:13413ea9a877 | 567 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 568 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 569 | |
ganlikun | 0:13413ea9a877 | 570 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 571 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 572 | |
ganlikun | 0:13413ea9a877 | 573 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 574 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 575 | } |
ganlikun | 0:13413ea9a877 | 576 | |
ganlikun | 0:13413ea9a877 | 577 | |
ganlikun | 0:13413ea9a877 | 578 | /** |
ganlikun | 0:13413ea9a877 | 579 | * @} |
ganlikun | 0:13413ea9a877 | 580 | */ |
ganlikun | 0:13413ea9a877 | 581 | |
ganlikun | 0:13413ea9a877 | 582 | /** @defgroup HASHEx_Group2 HMAC processing functions using polling mode |
ganlikun | 0:13413ea9a877 | 583 | * @brief HMAC processing functions using polling mode . |
ganlikun | 0:13413ea9a877 | 584 | * |
ganlikun | 0:13413ea9a877 | 585 | @verbatim |
ganlikun | 0:13413ea9a877 | 586 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 587 | ##### HMAC processing using polling mode functions ##### |
ganlikun | 0:13413ea9a877 | 588 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 589 | [..] This section provides functions allowing to calculate in polling mode |
ganlikun | 0:13413ea9a877 | 590 | the HMAC value using one of the following algorithms: |
ganlikun | 0:13413ea9a877 | 591 | (+) SHA224 |
ganlikun | 0:13413ea9a877 | 592 | (+) SHA256 |
ganlikun | 0:13413ea9a877 | 593 | |
ganlikun | 0:13413ea9a877 | 594 | @endverbatim |
ganlikun | 0:13413ea9a877 | 595 | * @{ |
ganlikun | 0:13413ea9a877 | 596 | */ |
ganlikun | 0:13413ea9a877 | 597 | |
ganlikun | 0:13413ea9a877 | 598 | /** |
ganlikun | 0:13413ea9a877 | 599 | * @brief Initializes the HASH peripheral in HMAC SHA224 mode |
ganlikun | 0:13413ea9a877 | 600 | * then processes pInBuffer. The digest is available in pOutBuffer. |
ganlikun | 0:13413ea9a877 | 601 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 602 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 603 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 604 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 605 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 606 | * @param pOutBuffer: Pointer to the computed digest. Its size must be 20 bytes. |
ganlikun | 0:13413ea9a877 | 607 | * @param Timeout: Timeout value |
ganlikun | 0:13413ea9a877 | 608 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 609 | */ |
ganlikun | 0:13413ea9a877 | 610 | HAL_StatusTypeDef HAL_HMACEx_SHA224_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout) |
ganlikun | 0:13413ea9a877 | 611 | { |
ganlikun | 0:13413ea9a877 | 612 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 613 | |
ganlikun | 0:13413ea9a877 | 614 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 615 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 616 | |
ganlikun | 0:13413ea9a877 | 617 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 618 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 619 | |
ganlikun | 0:13413ea9a877 | 620 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 621 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 622 | { |
ganlikun | 0:13413ea9a877 | 623 | /* Check if key size is greater than 64 bytes */ |
ganlikun | 0:13413ea9a877 | 624 | if(hhash->Init.KeySize > 64U) |
ganlikun | 0:13413ea9a877 | 625 | { |
ganlikun | 0:13413ea9a877 | 626 | /* Select the HMAC SHA224 mode */ |
ganlikun | 0:13413ea9a877 | 627 | HASH->CR |= (HASH_ALGOSELECTION_SHA224 | HASH_ALGOMODE_HMAC | HASH_HMAC_KEYTYPE_LONGKEY | HASH_CR_INIT); |
ganlikun | 0:13413ea9a877 | 628 | } |
ganlikun | 0:13413ea9a877 | 629 | else |
ganlikun | 0:13413ea9a877 | 630 | { |
ganlikun | 0:13413ea9a877 | 631 | /* Select the HMAC SHA224 mode */ |
ganlikun | 0:13413ea9a877 | 632 | HASH->CR |= (HASH_ALGOSELECTION_SHA224 | HASH_ALGOMODE_HMAC | HASH_CR_INIT); |
ganlikun | 0:13413ea9a877 | 633 | } |
ganlikun | 0:13413ea9a877 | 634 | } |
ganlikun | 0:13413ea9a877 | 635 | |
ganlikun | 0:13413ea9a877 | 636 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 637 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 638 | |
ganlikun | 0:13413ea9a877 | 639 | /************************** STEP 1 ******************************************/ |
ganlikun | 0:13413ea9a877 | 640 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 641 | __HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 642 | |
ganlikun | 0:13413ea9a877 | 643 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 644 | HASHEx_WriteData(hhash->Init.pKey, hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 645 | |
ganlikun | 0:13413ea9a877 | 646 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 647 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 648 | |
ganlikun | 0:13413ea9a877 | 649 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 650 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 651 | |
ganlikun | 0:13413ea9a877 | 652 | while((HASH->SR & HASH_FLAG_BUSY) == HASH_FLAG_BUSY) |
ganlikun | 0:13413ea9a877 | 653 | { |
ganlikun | 0:13413ea9a877 | 654 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 655 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 656 | { |
ganlikun | 0:13413ea9a877 | 657 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
ganlikun | 0:13413ea9a877 | 658 | { |
ganlikun | 0:13413ea9a877 | 659 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 660 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 661 | |
ganlikun | 0:13413ea9a877 | 662 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 663 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 664 | |
ganlikun | 0:13413ea9a877 | 665 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 666 | } |
ganlikun | 0:13413ea9a877 | 667 | } |
ganlikun | 0:13413ea9a877 | 668 | } |
ganlikun | 0:13413ea9a877 | 669 | /************************** STEP 2 ******************************************/ |
ganlikun | 0:13413ea9a877 | 670 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 671 | __HAL_HASH_SET_NBVALIDBITS(Size); |
ganlikun | 0:13413ea9a877 | 672 | |
ganlikun | 0:13413ea9a877 | 673 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 674 | HASHEx_WriteData(pInBuffer, Size); |
ganlikun | 0:13413ea9a877 | 675 | |
ganlikun | 0:13413ea9a877 | 676 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 677 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 678 | |
ganlikun | 0:13413ea9a877 | 679 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 680 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 681 | |
ganlikun | 0:13413ea9a877 | 682 | while((HASH->SR & HASH_FLAG_BUSY) == HASH_FLAG_BUSY) |
ganlikun | 0:13413ea9a877 | 683 | { |
ganlikun | 0:13413ea9a877 | 684 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 685 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 686 | { |
ganlikun | 0:13413ea9a877 | 687 | if((HAL_GetTick() - tickstart ) > Timeout) |
ganlikun | 0:13413ea9a877 | 688 | { |
ganlikun | 0:13413ea9a877 | 689 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 690 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 691 | |
ganlikun | 0:13413ea9a877 | 692 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 693 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 694 | |
ganlikun | 0:13413ea9a877 | 695 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 696 | } |
ganlikun | 0:13413ea9a877 | 697 | } |
ganlikun | 0:13413ea9a877 | 698 | } |
ganlikun | 0:13413ea9a877 | 699 | /************************** STEP 3 ******************************************/ |
ganlikun | 0:13413ea9a877 | 700 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 701 | __HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 702 | |
ganlikun | 0:13413ea9a877 | 703 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 704 | HASHEx_WriteData(hhash->Init.pKey, hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 705 | |
ganlikun | 0:13413ea9a877 | 706 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 707 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 708 | |
ganlikun | 0:13413ea9a877 | 709 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 710 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 711 | |
ganlikun | 0:13413ea9a877 | 712 | while((HASH->SR & HASH_FLAG_BUSY) == HASH_FLAG_BUSY) |
ganlikun | 0:13413ea9a877 | 713 | { |
ganlikun | 0:13413ea9a877 | 714 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 715 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 716 | { |
ganlikun | 0:13413ea9a877 | 717 | if((HAL_GetTick() - tickstart ) > Timeout) |
ganlikun | 0:13413ea9a877 | 718 | { |
ganlikun | 0:13413ea9a877 | 719 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 720 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 721 | |
ganlikun | 0:13413ea9a877 | 722 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 723 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 724 | |
ganlikun | 0:13413ea9a877 | 725 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 726 | } |
ganlikun | 0:13413ea9a877 | 727 | } |
ganlikun | 0:13413ea9a877 | 728 | } |
ganlikun | 0:13413ea9a877 | 729 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 730 | HASHEx_GetDigest(pOutBuffer, 28U); |
ganlikun | 0:13413ea9a877 | 731 | |
ganlikun | 0:13413ea9a877 | 732 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 733 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 734 | |
ganlikun | 0:13413ea9a877 | 735 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 736 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 737 | |
ganlikun | 0:13413ea9a877 | 738 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 739 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 740 | } |
ganlikun | 0:13413ea9a877 | 741 | |
ganlikun | 0:13413ea9a877 | 742 | /** |
ganlikun | 0:13413ea9a877 | 743 | * @brief Initializes the HASH peripheral in HMAC SHA256 mode |
ganlikun | 0:13413ea9a877 | 744 | * then processes pInBuffer. The digest is available in pOutBuffer |
ganlikun | 0:13413ea9a877 | 745 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 746 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 747 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 748 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 749 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 750 | * @param pOutBuffer: Pointer to the computed digest. Its size must be 20 bytes. |
ganlikun | 0:13413ea9a877 | 751 | * @param Timeout: Timeout value |
ganlikun | 0:13413ea9a877 | 752 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 753 | */ |
ganlikun | 0:13413ea9a877 | 754 | HAL_StatusTypeDef HAL_HMACEx_SHA256_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout) |
ganlikun | 0:13413ea9a877 | 755 | { |
ganlikun | 0:13413ea9a877 | 756 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 757 | |
ganlikun | 0:13413ea9a877 | 758 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 759 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 760 | |
ganlikun | 0:13413ea9a877 | 761 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 762 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 763 | |
ganlikun | 0:13413ea9a877 | 764 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 765 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 766 | { |
ganlikun | 0:13413ea9a877 | 767 | /* Check if key size is greater than 64 bytes */ |
ganlikun | 0:13413ea9a877 | 768 | if(hhash->Init.KeySize > 64U) |
ganlikun | 0:13413ea9a877 | 769 | { |
ganlikun | 0:13413ea9a877 | 770 | /* Select the HMAC SHA256 mode */ |
ganlikun | 0:13413ea9a877 | 771 | HASH->CR |= (HASH_ALGOSELECTION_SHA256 | HASH_ALGOMODE_HMAC | HASH_HMAC_KEYTYPE_LONGKEY); |
ganlikun | 0:13413ea9a877 | 772 | } |
ganlikun | 0:13413ea9a877 | 773 | else |
ganlikun | 0:13413ea9a877 | 774 | { |
ganlikun | 0:13413ea9a877 | 775 | /* Select the HMAC SHA256 mode */ |
ganlikun | 0:13413ea9a877 | 776 | HASH->CR |= (HASH_ALGOSELECTION_SHA256 | HASH_ALGOMODE_HMAC); |
ganlikun | 0:13413ea9a877 | 777 | } |
ganlikun | 0:13413ea9a877 | 778 | /* Reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 779 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 780 | HASH->CR |= HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 781 | } |
ganlikun | 0:13413ea9a877 | 782 | |
ganlikun | 0:13413ea9a877 | 783 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 784 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 785 | |
ganlikun | 0:13413ea9a877 | 786 | /************************** STEP 1 ******************************************/ |
ganlikun | 0:13413ea9a877 | 787 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 788 | __HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 789 | |
ganlikun | 0:13413ea9a877 | 790 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 791 | HASHEx_WriteData(hhash->Init.pKey, hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 792 | |
ganlikun | 0:13413ea9a877 | 793 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 794 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 795 | |
ganlikun | 0:13413ea9a877 | 796 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 797 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 798 | |
ganlikun | 0:13413ea9a877 | 799 | while((HASH->SR & HASH_FLAG_BUSY) == HASH_FLAG_BUSY) |
ganlikun | 0:13413ea9a877 | 800 | { |
ganlikun | 0:13413ea9a877 | 801 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 802 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 803 | { |
ganlikun | 0:13413ea9a877 | 804 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
ganlikun | 0:13413ea9a877 | 805 | { |
ganlikun | 0:13413ea9a877 | 806 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 807 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 808 | |
ganlikun | 0:13413ea9a877 | 809 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 810 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 811 | |
ganlikun | 0:13413ea9a877 | 812 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 813 | } |
ganlikun | 0:13413ea9a877 | 814 | } |
ganlikun | 0:13413ea9a877 | 815 | } |
ganlikun | 0:13413ea9a877 | 816 | /************************** STEP 2 ******************************************/ |
ganlikun | 0:13413ea9a877 | 817 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 818 | __HAL_HASH_SET_NBVALIDBITS(Size); |
ganlikun | 0:13413ea9a877 | 819 | |
ganlikun | 0:13413ea9a877 | 820 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 821 | HASHEx_WriteData(pInBuffer, Size); |
ganlikun | 0:13413ea9a877 | 822 | |
ganlikun | 0:13413ea9a877 | 823 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 824 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 825 | |
ganlikun | 0:13413ea9a877 | 826 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 827 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 828 | |
ganlikun | 0:13413ea9a877 | 829 | while((HASH->SR & HASH_FLAG_BUSY) == HASH_FLAG_BUSY) |
ganlikun | 0:13413ea9a877 | 830 | { |
ganlikun | 0:13413ea9a877 | 831 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 832 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 833 | { |
ganlikun | 0:13413ea9a877 | 834 | if((HAL_GetTick() - tickstart ) > Timeout) |
ganlikun | 0:13413ea9a877 | 835 | { |
ganlikun | 0:13413ea9a877 | 836 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 837 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 838 | |
ganlikun | 0:13413ea9a877 | 839 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 840 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 841 | |
ganlikun | 0:13413ea9a877 | 842 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 843 | } |
ganlikun | 0:13413ea9a877 | 844 | } |
ganlikun | 0:13413ea9a877 | 845 | } |
ganlikun | 0:13413ea9a877 | 846 | /************************** STEP 3 ******************************************/ |
ganlikun | 0:13413ea9a877 | 847 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 848 | __HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 849 | |
ganlikun | 0:13413ea9a877 | 850 | /* Write input buffer in data register */ |
ganlikun | 0:13413ea9a877 | 851 | HASHEx_WriteData(hhash->Init.pKey, hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 852 | |
ganlikun | 0:13413ea9a877 | 853 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 854 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 855 | |
ganlikun | 0:13413ea9a877 | 856 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 857 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 858 | |
ganlikun | 0:13413ea9a877 | 859 | while((HASH->SR & HASH_FLAG_BUSY) == HASH_FLAG_BUSY) |
ganlikun | 0:13413ea9a877 | 860 | { |
ganlikun | 0:13413ea9a877 | 861 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 862 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 863 | { |
ganlikun | 0:13413ea9a877 | 864 | if((HAL_GetTick() - tickstart ) > Timeout) |
ganlikun | 0:13413ea9a877 | 865 | { |
ganlikun | 0:13413ea9a877 | 866 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 867 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 868 | |
ganlikun | 0:13413ea9a877 | 869 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 870 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 871 | |
ganlikun | 0:13413ea9a877 | 872 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 873 | } |
ganlikun | 0:13413ea9a877 | 874 | } |
ganlikun | 0:13413ea9a877 | 875 | } |
ganlikun | 0:13413ea9a877 | 876 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 877 | HASHEx_GetDigest(pOutBuffer, 32U); |
ganlikun | 0:13413ea9a877 | 878 | |
ganlikun | 0:13413ea9a877 | 879 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 880 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 881 | |
ganlikun | 0:13413ea9a877 | 882 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 883 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 884 | |
ganlikun | 0:13413ea9a877 | 885 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 886 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 887 | } |
ganlikun | 0:13413ea9a877 | 888 | |
ganlikun | 0:13413ea9a877 | 889 | /** |
ganlikun | 0:13413ea9a877 | 890 | * @} |
ganlikun | 0:13413ea9a877 | 891 | */ |
ganlikun | 0:13413ea9a877 | 892 | |
ganlikun | 0:13413ea9a877 | 893 | /** @defgroup HASHEx_Group3 HASH processing functions using interrupt mode |
ganlikun | 0:13413ea9a877 | 894 | * @brief processing functions using interrupt mode. |
ganlikun | 0:13413ea9a877 | 895 | * |
ganlikun | 0:13413ea9a877 | 896 | @verbatim |
ganlikun | 0:13413ea9a877 | 897 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 898 | ##### HASH processing using interrupt functions ##### |
ganlikun | 0:13413ea9a877 | 899 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 900 | [..] This section provides functions allowing to calculate in interrupt mode |
ganlikun | 0:13413ea9a877 | 901 | the hash value using one of the following algorithms: |
ganlikun | 0:13413ea9a877 | 902 | (+) SHA224 |
ganlikun | 0:13413ea9a877 | 903 | (+) SHA256 |
ganlikun | 0:13413ea9a877 | 904 | |
ganlikun | 0:13413ea9a877 | 905 | @endverbatim |
ganlikun | 0:13413ea9a877 | 906 | * @{ |
ganlikun | 0:13413ea9a877 | 907 | */ |
ganlikun | 0:13413ea9a877 | 908 | |
ganlikun | 0:13413ea9a877 | 909 | /** |
ganlikun | 0:13413ea9a877 | 910 | * @brief Initializes the HASH peripheral in SHA224 mode then processes pInBuffer. |
ganlikun | 0:13413ea9a877 | 911 | * The digest is available in pOutBuffer. |
ganlikun | 0:13413ea9a877 | 912 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 913 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 914 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 915 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 916 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 917 | * @param pOutBuffer: Pointer to the computed digest. Its size must be 20 bytes. |
ganlikun | 0:13413ea9a877 | 918 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 919 | */ |
ganlikun | 0:13413ea9a877 | 920 | HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer) |
ganlikun | 0:13413ea9a877 | 921 | { |
ganlikun | 0:13413ea9a877 | 922 | uint32_t inputaddr; |
ganlikun | 0:13413ea9a877 | 923 | uint32_t buffercounter; |
ganlikun | 0:13413ea9a877 | 924 | uint32_t inputcounter; |
ganlikun | 0:13413ea9a877 | 925 | |
ganlikun | 0:13413ea9a877 | 926 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 927 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 928 | |
ganlikun | 0:13413ea9a877 | 929 | if(hhash->State == HAL_HASH_STATE_READY) |
ganlikun | 0:13413ea9a877 | 930 | { |
ganlikun | 0:13413ea9a877 | 931 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 932 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 933 | |
ganlikun | 0:13413ea9a877 | 934 | hhash->HashInCount = Size; |
ganlikun | 0:13413ea9a877 | 935 | hhash->pHashInBuffPtr = pInBuffer; |
ganlikun | 0:13413ea9a877 | 936 | hhash->pHashOutBuffPtr = pOutBuffer; |
ganlikun | 0:13413ea9a877 | 937 | |
ganlikun | 0:13413ea9a877 | 938 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 939 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 940 | { |
ganlikun | 0:13413ea9a877 | 941 | /* Select the SHA224 mode */ |
ganlikun | 0:13413ea9a877 | 942 | HASH->CR |= HASH_ALGOSELECTION_SHA224; |
ganlikun | 0:13413ea9a877 | 943 | /* Reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 944 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 945 | HASH->CR |= HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 946 | } |
ganlikun | 0:13413ea9a877 | 947 | /* Reset interrupt counter */ |
ganlikun | 0:13413ea9a877 | 948 | hhash->HashITCounter = 0U; |
ganlikun | 0:13413ea9a877 | 949 | |
ganlikun | 0:13413ea9a877 | 950 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 951 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 952 | |
ganlikun | 0:13413ea9a877 | 953 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 954 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 955 | |
ganlikun | 0:13413ea9a877 | 956 | /* Enable Interrupts */ |
ganlikun | 0:13413ea9a877 | 957 | HASH->IMR = (HASH_IT_DINI | HASH_IT_DCI); |
ganlikun | 0:13413ea9a877 | 958 | |
ganlikun | 0:13413ea9a877 | 959 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 960 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 961 | } |
ganlikun | 0:13413ea9a877 | 962 | if(__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS)) |
ganlikun | 0:13413ea9a877 | 963 | { |
ganlikun | 0:13413ea9a877 | 964 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 965 | HASHEx_GetDigest(hhash->pHashOutBuffPtr, 28U); |
ganlikun | 0:13413ea9a877 | 966 | if(hhash->HashInCount == 0U) |
ganlikun | 0:13413ea9a877 | 967 | { |
ganlikun | 0:13413ea9a877 | 968 | /* Disable Interrupts */ |
ganlikun | 0:13413ea9a877 | 969 | HASH->IMR = 0U; |
ganlikun | 0:13413ea9a877 | 970 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 971 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 972 | /* Call digest computation complete callback */ |
ganlikun | 0:13413ea9a877 | 973 | HAL_HASH_DgstCpltCallback(hhash); |
ganlikun | 0:13413ea9a877 | 974 | |
ganlikun | 0:13413ea9a877 | 975 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 976 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 977 | |
ganlikun | 0:13413ea9a877 | 978 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 979 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 980 | } |
ganlikun | 0:13413ea9a877 | 981 | } |
ganlikun | 0:13413ea9a877 | 982 | if(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS)) |
ganlikun | 0:13413ea9a877 | 983 | { |
ganlikun | 0:13413ea9a877 | 984 | if(hhash->HashInCount >= 68U) |
ganlikun | 0:13413ea9a877 | 985 | { |
ganlikun | 0:13413ea9a877 | 986 | inputaddr = (uint32_t)hhash->pHashInBuffPtr; |
ganlikun | 0:13413ea9a877 | 987 | /* Write the Input block in the Data IN register */ |
ganlikun | 0:13413ea9a877 | 988 | for(buffercounter = 0U; buffercounter < 64U; buffercounter+=4U) |
ganlikun | 0:13413ea9a877 | 989 | { |
ganlikun | 0:13413ea9a877 | 990 | HASH->DIN = *(uint32_t*)inputaddr; |
ganlikun | 0:13413ea9a877 | 991 | inputaddr+=4U; |
ganlikun | 0:13413ea9a877 | 992 | } |
ganlikun | 0:13413ea9a877 | 993 | if(hhash->HashITCounter == 0U) |
ganlikun | 0:13413ea9a877 | 994 | { |
ganlikun | 0:13413ea9a877 | 995 | HASH->DIN = *(uint32_t*)inputaddr; |
ganlikun | 0:13413ea9a877 | 996 | |
ganlikun | 0:13413ea9a877 | 997 | if(hhash->HashInCount >= 68U) |
ganlikun | 0:13413ea9a877 | 998 | { |
ganlikun | 0:13413ea9a877 | 999 | /* Decrement buffer counter */ |
ganlikun | 0:13413ea9a877 | 1000 | hhash->HashInCount -= 68U; |
ganlikun | 0:13413ea9a877 | 1001 | hhash->pHashInBuffPtr+= 68U; |
ganlikun | 0:13413ea9a877 | 1002 | } |
ganlikun | 0:13413ea9a877 | 1003 | else |
ganlikun | 0:13413ea9a877 | 1004 | { |
ganlikun | 0:13413ea9a877 | 1005 | hhash->HashInCount = 0U; |
ganlikun | 0:13413ea9a877 | 1006 | hhash->pHashInBuffPtr+= hhash->HashInCount; |
ganlikun | 0:13413ea9a877 | 1007 | } |
ganlikun | 0:13413ea9a877 | 1008 | /* Set Interrupt counter */ |
ganlikun | 0:13413ea9a877 | 1009 | hhash->HashITCounter = 1U; |
ganlikun | 0:13413ea9a877 | 1010 | } |
ganlikun | 0:13413ea9a877 | 1011 | else |
ganlikun | 0:13413ea9a877 | 1012 | { |
ganlikun | 0:13413ea9a877 | 1013 | /* Decrement buffer counter */ |
ganlikun | 0:13413ea9a877 | 1014 | hhash->HashInCount -= 64U; |
ganlikun | 0:13413ea9a877 | 1015 | hhash->pHashInBuffPtr+= 64U; |
ganlikun | 0:13413ea9a877 | 1016 | } |
ganlikun | 0:13413ea9a877 | 1017 | } |
ganlikun | 0:13413ea9a877 | 1018 | else |
ganlikun | 0:13413ea9a877 | 1019 | { |
ganlikun | 0:13413ea9a877 | 1020 | /* Get the buffer address */ |
ganlikun | 0:13413ea9a877 | 1021 | inputaddr = (uint32_t)hhash->pHashInBuffPtr; |
ganlikun | 0:13413ea9a877 | 1022 | /* Get the buffer counter */ |
ganlikun | 0:13413ea9a877 | 1023 | inputcounter = hhash->HashInCount; |
ganlikun | 0:13413ea9a877 | 1024 | /* Disable Interrupts */ |
ganlikun | 0:13413ea9a877 | 1025 | HASH->IMR &= ~(HASH_IT_DINI); |
ganlikun | 0:13413ea9a877 | 1026 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 1027 | __HAL_HASH_SET_NBVALIDBITS(inputcounter); |
ganlikun | 0:13413ea9a877 | 1028 | |
ganlikun | 0:13413ea9a877 | 1029 | if((inputcounter > 4U) && (inputcounter%4U)) |
ganlikun | 0:13413ea9a877 | 1030 | { |
ganlikun | 0:13413ea9a877 | 1031 | inputcounter = (inputcounter+4U-inputcounter%4U); |
ganlikun | 0:13413ea9a877 | 1032 | } |
ganlikun | 0:13413ea9a877 | 1033 | else if ((inputcounter < 4U) && (inputcounter != 0U)) |
ganlikun | 0:13413ea9a877 | 1034 | { |
ganlikun | 0:13413ea9a877 | 1035 | inputcounter = 4U; |
ganlikun | 0:13413ea9a877 | 1036 | } |
ganlikun | 0:13413ea9a877 | 1037 | /* Write the Input block in the Data IN register */ |
ganlikun | 0:13413ea9a877 | 1038 | for(buffercounter = 0U; buffercounter < inputcounter/4U; buffercounter++) |
ganlikun | 0:13413ea9a877 | 1039 | { |
ganlikun | 0:13413ea9a877 | 1040 | HASH->DIN = *(uint32_t*)inputaddr; |
ganlikun | 0:13413ea9a877 | 1041 | inputaddr+=4U; |
ganlikun | 0:13413ea9a877 | 1042 | } |
ganlikun | 0:13413ea9a877 | 1043 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 1044 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 1045 | /* Reset buffer counter */ |
ganlikun | 0:13413ea9a877 | 1046 | hhash->HashInCount = 0U; |
ganlikun | 0:13413ea9a877 | 1047 | /* Call Input data transfer complete callback */ |
ganlikun | 0:13413ea9a877 | 1048 | HAL_HASH_InCpltCallback(hhash); |
ganlikun | 0:13413ea9a877 | 1049 | } |
ganlikun | 0:13413ea9a877 | 1050 | } |
ganlikun | 0:13413ea9a877 | 1051 | |
ganlikun | 0:13413ea9a877 | 1052 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1053 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1054 | |
ganlikun | 0:13413ea9a877 | 1055 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1056 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1057 | } |
ganlikun | 0:13413ea9a877 | 1058 | |
ganlikun | 0:13413ea9a877 | 1059 | |
ganlikun | 0:13413ea9a877 | 1060 | /** |
ganlikun | 0:13413ea9a877 | 1061 | * @brief Initializes the HASH peripheral in SHA256 mode then processes pInBuffer. |
ganlikun | 0:13413ea9a877 | 1062 | * The digest is available in pOutBuffer. |
ganlikun | 0:13413ea9a877 | 1063 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1064 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 1065 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 1066 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 1067 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 1068 | * @param pOutBuffer: Pointer to the computed digest. Its size must be 20 bytes. |
ganlikun | 0:13413ea9a877 | 1069 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1070 | */ |
ganlikun | 0:13413ea9a877 | 1071 | HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer) |
ganlikun | 0:13413ea9a877 | 1072 | { |
ganlikun | 0:13413ea9a877 | 1073 | uint32_t inputaddr; |
ganlikun | 0:13413ea9a877 | 1074 | uint32_t buffercounter; |
ganlikun | 0:13413ea9a877 | 1075 | uint32_t inputcounter; |
ganlikun | 0:13413ea9a877 | 1076 | |
ganlikun | 0:13413ea9a877 | 1077 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 1078 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1079 | |
ganlikun | 0:13413ea9a877 | 1080 | if(hhash->State == HAL_HASH_STATE_READY) |
ganlikun | 0:13413ea9a877 | 1081 | { |
ganlikun | 0:13413ea9a877 | 1082 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 1083 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 1084 | |
ganlikun | 0:13413ea9a877 | 1085 | hhash->HashInCount = Size; |
ganlikun | 0:13413ea9a877 | 1086 | hhash->pHashInBuffPtr = pInBuffer; |
ganlikun | 0:13413ea9a877 | 1087 | hhash->pHashOutBuffPtr = pOutBuffer; |
ganlikun | 0:13413ea9a877 | 1088 | |
ganlikun | 0:13413ea9a877 | 1089 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 1090 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 1091 | { |
ganlikun | 0:13413ea9a877 | 1092 | /* Select the SHA256 mode */ |
ganlikun | 0:13413ea9a877 | 1093 | HASH->CR |= HASH_ALGOSELECTION_SHA256; |
ganlikun | 0:13413ea9a877 | 1094 | /* Reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 1095 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 1096 | HASH->CR |= HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 1097 | } |
ganlikun | 0:13413ea9a877 | 1098 | /* Reset interrupt counter */ |
ganlikun | 0:13413ea9a877 | 1099 | hhash->HashITCounter = 0U; |
ganlikun | 0:13413ea9a877 | 1100 | |
ganlikun | 0:13413ea9a877 | 1101 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 1102 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 1103 | |
ganlikun | 0:13413ea9a877 | 1104 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1105 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1106 | |
ganlikun | 0:13413ea9a877 | 1107 | /* Enable Interrupts */ |
ganlikun | 0:13413ea9a877 | 1108 | HASH->IMR = (HASH_IT_DINI | HASH_IT_DCI); |
ganlikun | 0:13413ea9a877 | 1109 | |
ganlikun | 0:13413ea9a877 | 1110 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1111 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1112 | } |
ganlikun | 0:13413ea9a877 | 1113 | if(__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS)) |
ganlikun | 0:13413ea9a877 | 1114 | { |
ganlikun | 0:13413ea9a877 | 1115 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 1116 | HASHEx_GetDigest(hhash->pHashOutBuffPtr, 32U); |
ganlikun | 0:13413ea9a877 | 1117 | if(hhash->HashInCount == 0U) |
ganlikun | 0:13413ea9a877 | 1118 | { |
ganlikun | 0:13413ea9a877 | 1119 | /* Disable Interrupts */ |
ganlikun | 0:13413ea9a877 | 1120 | HASH->IMR = 0U; |
ganlikun | 0:13413ea9a877 | 1121 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 1122 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 1123 | /* Call digest computation complete callback */ |
ganlikun | 0:13413ea9a877 | 1124 | HAL_HASH_DgstCpltCallback(hhash); |
ganlikun | 0:13413ea9a877 | 1125 | |
ganlikun | 0:13413ea9a877 | 1126 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1127 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1128 | |
ganlikun | 0:13413ea9a877 | 1129 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1130 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1131 | } |
ganlikun | 0:13413ea9a877 | 1132 | } |
ganlikun | 0:13413ea9a877 | 1133 | if(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS)) |
ganlikun | 0:13413ea9a877 | 1134 | { |
ganlikun | 0:13413ea9a877 | 1135 | if(hhash->HashInCount >= 68U) |
ganlikun | 0:13413ea9a877 | 1136 | { |
ganlikun | 0:13413ea9a877 | 1137 | inputaddr = (uint32_t)hhash->pHashInBuffPtr; |
ganlikun | 0:13413ea9a877 | 1138 | /* Write the Input block in the Data IN register */ |
ganlikun | 0:13413ea9a877 | 1139 | for(buffercounter = 0U; buffercounter < 64U; buffercounter+=4U) |
ganlikun | 0:13413ea9a877 | 1140 | { |
ganlikun | 0:13413ea9a877 | 1141 | HASH->DIN = *(uint32_t*)inputaddr; |
ganlikun | 0:13413ea9a877 | 1142 | inputaddr+=4U; |
ganlikun | 0:13413ea9a877 | 1143 | } |
ganlikun | 0:13413ea9a877 | 1144 | if(hhash->HashITCounter == 0U) |
ganlikun | 0:13413ea9a877 | 1145 | { |
ganlikun | 0:13413ea9a877 | 1146 | HASH->DIN = *(uint32_t*)inputaddr; |
ganlikun | 0:13413ea9a877 | 1147 | |
ganlikun | 0:13413ea9a877 | 1148 | if(hhash->HashInCount >= 68U) |
ganlikun | 0:13413ea9a877 | 1149 | { |
ganlikun | 0:13413ea9a877 | 1150 | /* Decrement buffer counter */ |
ganlikun | 0:13413ea9a877 | 1151 | hhash->HashInCount -= 68U; |
ganlikun | 0:13413ea9a877 | 1152 | hhash->pHashInBuffPtr+= 68U; |
ganlikun | 0:13413ea9a877 | 1153 | } |
ganlikun | 0:13413ea9a877 | 1154 | else |
ganlikun | 0:13413ea9a877 | 1155 | { |
ganlikun | 0:13413ea9a877 | 1156 | hhash->HashInCount = 0U; |
ganlikun | 0:13413ea9a877 | 1157 | hhash->pHashInBuffPtr+= hhash->HashInCount; |
ganlikun | 0:13413ea9a877 | 1158 | } |
ganlikun | 0:13413ea9a877 | 1159 | /* Set Interrupt counter */ |
ganlikun | 0:13413ea9a877 | 1160 | hhash->HashITCounter = 1U; |
ganlikun | 0:13413ea9a877 | 1161 | } |
ganlikun | 0:13413ea9a877 | 1162 | else |
ganlikun | 0:13413ea9a877 | 1163 | { |
ganlikun | 0:13413ea9a877 | 1164 | /* Decrement buffer counter */ |
ganlikun | 0:13413ea9a877 | 1165 | hhash->HashInCount -= 64U; |
ganlikun | 0:13413ea9a877 | 1166 | hhash->pHashInBuffPtr+= 64U; |
ganlikun | 0:13413ea9a877 | 1167 | } |
ganlikun | 0:13413ea9a877 | 1168 | } |
ganlikun | 0:13413ea9a877 | 1169 | else |
ganlikun | 0:13413ea9a877 | 1170 | { |
ganlikun | 0:13413ea9a877 | 1171 | /* Get the buffer address */ |
ganlikun | 0:13413ea9a877 | 1172 | inputaddr = (uint32_t)hhash->pHashInBuffPtr; |
ganlikun | 0:13413ea9a877 | 1173 | /* Get the buffer counter */ |
ganlikun | 0:13413ea9a877 | 1174 | inputcounter = hhash->HashInCount; |
ganlikun | 0:13413ea9a877 | 1175 | /* Disable Interrupts */ |
ganlikun | 0:13413ea9a877 | 1176 | HASH->IMR &= ~(HASH_IT_DINI); |
ganlikun | 0:13413ea9a877 | 1177 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 1178 | __HAL_HASH_SET_NBVALIDBITS(inputcounter); |
ganlikun | 0:13413ea9a877 | 1179 | |
ganlikun | 0:13413ea9a877 | 1180 | if((inputcounter > 4U) && (inputcounter%4U)) |
ganlikun | 0:13413ea9a877 | 1181 | { |
ganlikun | 0:13413ea9a877 | 1182 | inputcounter = (inputcounter+4U-inputcounter%4U); |
ganlikun | 0:13413ea9a877 | 1183 | } |
ganlikun | 0:13413ea9a877 | 1184 | else if ((inputcounter < 4U) && (inputcounter != 0U)) |
ganlikun | 0:13413ea9a877 | 1185 | { |
ganlikun | 0:13413ea9a877 | 1186 | inputcounter = 4U; |
ganlikun | 0:13413ea9a877 | 1187 | } |
ganlikun | 0:13413ea9a877 | 1188 | /* Write the Input block in the Data IN register */ |
ganlikun | 0:13413ea9a877 | 1189 | for(buffercounter = 0U; buffercounter < inputcounter/4U; buffercounter++) |
ganlikun | 0:13413ea9a877 | 1190 | { |
ganlikun | 0:13413ea9a877 | 1191 | HASH->DIN = *(uint32_t*)inputaddr; |
ganlikun | 0:13413ea9a877 | 1192 | inputaddr+=4U; |
ganlikun | 0:13413ea9a877 | 1193 | } |
ganlikun | 0:13413ea9a877 | 1194 | /* Start the digest calculation */ |
ganlikun | 0:13413ea9a877 | 1195 | __HAL_HASH_START_DIGEST(); |
ganlikun | 0:13413ea9a877 | 1196 | /* Reset buffer counter */ |
ganlikun | 0:13413ea9a877 | 1197 | hhash->HashInCount = 0U; |
ganlikun | 0:13413ea9a877 | 1198 | /* Call Input data transfer complete callback */ |
ganlikun | 0:13413ea9a877 | 1199 | HAL_HASH_InCpltCallback(hhash); |
ganlikun | 0:13413ea9a877 | 1200 | } |
ganlikun | 0:13413ea9a877 | 1201 | } |
ganlikun | 0:13413ea9a877 | 1202 | |
ganlikun | 0:13413ea9a877 | 1203 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1204 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1205 | |
ganlikun | 0:13413ea9a877 | 1206 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1207 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1208 | } |
ganlikun | 0:13413ea9a877 | 1209 | |
ganlikun | 0:13413ea9a877 | 1210 | /** |
ganlikun | 0:13413ea9a877 | 1211 | * @brief This function handles HASH interrupt request. |
ganlikun | 0:13413ea9a877 | 1212 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1213 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 1214 | * @retval None |
ganlikun | 0:13413ea9a877 | 1215 | */ |
ganlikun | 0:13413ea9a877 | 1216 | void HAL_HASHEx_IRQHandler(HASH_HandleTypeDef *hhash) |
ganlikun | 0:13413ea9a877 | 1217 | { |
ganlikun | 0:13413ea9a877 | 1218 | switch(HASH->CR & HASH_CR_ALGO) |
ganlikun | 0:13413ea9a877 | 1219 | { |
ganlikun | 0:13413ea9a877 | 1220 | |
ganlikun | 0:13413ea9a877 | 1221 | case HASH_ALGOSELECTION_SHA224: |
ganlikun | 0:13413ea9a877 | 1222 | HAL_HASHEx_SHA224_Start_IT(hhash, NULL, 0U, NULL); |
ganlikun | 0:13413ea9a877 | 1223 | break; |
ganlikun | 0:13413ea9a877 | 1224 | |
ganlikun | 0:13413ea9a877 | 1225 | case HASH_ALGOSELECTION_SHA256: |
ganlikun | 0:13413ea9a877 | 1226 | HAL_HASHEx_SHA256_Start_IT(hhash, NULL, 0U, NULL); |
ganlikun | 0:13413ea9a877 | 1227 | break; |
ganlikun | 0:13413ea9a877 | 1228 | |
ganlikun | 0:13413ea9a877 | 1229 | default: |
ganlikun | 0:13413ea9a877 | 1230 | break; |
ganlikun | 0:13413ea9a877 | 1231 | } |
ganlikun | 0:13413ea9a877 | 1232 | } |
ganlikun | 0:13413ea9a877 | 1233 | |
ganlikun | 0:13413ea9a877 | 1234 | /** |
ganlikun | 0:13413ea9a877 | 1235 | * @} |
ganlikun | 0:13413ea9a877 | 1236 | */ |
ganlikun | 0:13413ea9a877 | 1237 | |
ganlikun | 0:13413ea9a877 | 1238 | /** @defgroup HASHEx_Group4 HASH processing functions using DMA mode |
ganlikun | 0:13413ea9a877 | 1239 | * @brief processing functions using DMA mode. |
ganlikun | 0:13413ea9a877 | 1240 | * |
ganlikun | 0:13413ea9a877 | 1241 | @verbatim |
ganlikun | 0:13413ea9a877 | 1242 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 1243 | ##### HASH processing using DMA functions ##### |
ganlikun | 0:13413ea9a877 | 1244 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 1245 | [..] This section provides functions allowing to calculate in DMA mode |
ganlikun | 0:13413ea9a877 | 1246 | the hash value using one of the following algorithms: |
ganlikun | 0:13413ea9a877 | 1247 | (+) SHA224 |
ganlikun | 0:13413ea9a877 | 1248 | (+) SHA256 |
ganlikun | 0:13413ea9a877 | 1249 | |
ganlikun | 0:13413ea9a877 | 1250 | @endverbatim |
ganlikun | 0:13413ea9a877 | 1251 | * @{ |
ganlikun | 0:13413ea9a877 | 1252 | */ |
ganlikun | 0:13413ea9a877 | 1253 | |
ganlikun | 0:13413ea9a877 | 1254 | |
ganlikun | 0:13413ea9a877 | 1255 | /** |
ganlikun | 0:13413ea9a877 | 1256 | * @brief Initializes the HASH peripheral in SHA224 mode then enables DMA to |
ganlikun | 0:13413ea9a877 | 1257 | control data transfer. Use HAL_HASH_SHA224_Finish() to get the digest. |
ganlikun | 0:13413ea9a877 | 1258 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1259 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 1260 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 1261 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 1262 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 1263 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1264 | */ |
ganlikun | 0:13413ea9a877 | 1265 | HAL_StatusTypeDef HAL_HASHEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) |
ganlikun | 0:13413ea9a877 | 1266 | { |
ganlikun | 0:13413ea9a877 | 1267 | uint32_t inputaddr = (uint32_t)pInBuffer; |
ganlikun | 0:13413ea9a877 | 1268 | |
ganlikun | 0:13413ea9a877 | 1269 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 1270 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1271 | |
ganlikun | 0:13413ea9a877 | 1272 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 1273 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 1274 | |
ganlikun | 0:13413ea9a877 | 1275 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 1276 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 1277 | { |
ganlikun | 0:13413ea9a877 | 1278 | /* Select the SHA224 mode and reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 1279 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 1280 | HASH->CR |= HASH_ALGOSELECTION_SHA224 | HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 1281 | } |
ganlikun | 0:13413ea9a877 | 1282 | |
ganlikun | 0:13413ea9a877 | 1283 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 1284 | __HAL_HASH_SET_NBVALIDBITS(Size); |
ganlikun | 0:13413ea9a877 | 1285 | |
ganlikun | 0:13413ea9a877 | 1286 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 1287 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 1288 | |
ganlikun | 0:13413ea9a877 | 1289 | /* Set the HASH DMA transfer complete callback */ |
ganlikun | 0:13413ea9a877 | 1290 | hhash->hdmain->XferCpltCallback = HASHEx_DMAXferCplt; |
ganlikun | 0:13413ea9a877 | 1291 | /* Set the DMA error callback */ |
ganlikun | 0:13413ea9a877 | 1292 | hhash->hdmain->XferErrorCallback = HASHEx_DMAError; |
ganlikun | 0:13413ea9a877 | 1293 | |
ganlikun | 0:13413ea9a877 | 1294 | /* Enable the DMA In DMA Stream */ |
ganlikun | 0:13413ea9a877 | 1295 | HAL_DMA_Start_IT(hhash->hdmain, inputaddr, (uint32_t)&HASH->DIN, (Size%4U ? (Size+3U)/4U:Size/4U)); |
ganlikun | 0:13413ea9a877 | 1296 | |
ganlikun | 0:13413ea9a877 | 1297 | /* Enable DMA requests */ |
ganlikun | 0:13413ea9a877 | 1298 | HASH->CR |= (HASH_CR_DMAE); |
ganlikun | 0:13413ea9a877 | 1299 | |
ganlikun | 0:13413ea9a877 | 1300 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1301 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1302 | |
ganlikun | 0:13413ea9a877 | 1303 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1304 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1305 | } |
ganlikun | 0:13413ea9a877 | 1306 | |
ganlikun | 0:13413ea9a877 | 1307 | /** |
ganlikun | 0:13413ea9a877 | 1308 | * @brief Returns the computed digest in SHA224 |
ganlikun | 0:13413ea9a877 | 1309 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1310 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 1311 | * @param pOutBuffer: Pointer to the computed digest. Its size must be 28 bytes. |
ganlikun | 0:13413ea9a877 | 1312 | * @param Timeout: Timeout value |
ganlikun | 0:13413ea9a877 | 1313 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1314 | */ |
ganlikun | 0:13413ea9a877 | 1315 | HAL_StatusTypeDef HAL_HASHEx_SHA224_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout) |
ganlikun | 0:13413ea9a877 | 1316 | { |
ganlikun | 0:13413ea9a877 | 1317 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 1318 | |
ganlikun | 0:13413ea9a877 | 1319 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 1320 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1321 | |
ganlikun | 0:13413ea9a877 | 1322 | /* Change HASH peripheral state */ |
ganlikun | 0:13413ea9a877 | 1323 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 1324 | |
ganlikun | 0:13413ea9a877 | 1325 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 1326 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 1327 | |
ganlikun | 0:13413ea9a877 | 1328 | while(HAL_IS_BIT_CLR(HASH->SR, HASH_FLAG_DCIS)) |
ganlikun | 0:13413ea9a877 | 1329 | { |
ganlikun | 0:13413ea9a877 | 1330 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 1331 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 1332 | { |
ganlikun | 0:13413ea9a877 | 1333 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
ganlikun | 0:13413ea9a877 | 1334 | { |
ganlikun | 0:13413ea9a877 | 1335 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 1336 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1337 | |
ganlikun | 0:13413ea9a877 | 1338 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1339 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1340 | |
ganlikun | 0:13413ea9a877 | 1341 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1342 | } |
ganlikun | 0:13413ea9a877 | 1343 | } |
ganlikun | 0:13413ea9a877 | 1344 | } |
ganlikun | 0:13413ea9a877 | 1345 | |
ganlikun | 0:13413ea9a877 | 1346 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 1347 | HASHEx_GetDigest(pOutBuffer, 28U); |
ganlikun | 0:13413ea9a877 | 1348 | |
ganlikun | 0:13413ea9a877 | 1349 | /* Change HASH peripheral state */ |
ganlikun | 0:13413ea9a877 | 1350 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 1351 | |
ganlikun | 0:13413ea9a877 | 1352 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1353 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1354 | |
ganlikun | 0:13413ea9a877 | 1355 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1356 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1357 | } |
ganlikun | 0:13413ea9a877 | 1358 | |
ganlikun | 0:13413ea9a877 | 1359 | /** |
ganlikun | 0:13413ea9a877 | 1360 | * @brief Initializes the HASH peripheral in SHA256 mode then enables DMA to |
ganlikun | 0:13413ea9a877 | 1361 | control data transfer. Use HAL_HASH_SHA256_Finish() to get the digest. |
ganlikun | 0:13413ea9a877 | 1362 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1363 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 1364 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 1365 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 1366 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 1367 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1368 | */ |
ganlikun | 0:13413ea9a877 | 1369 | HAL_StatusTypeDef HAL_HASHEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) |
ganlikun | 0:13413ea9a877 | 1370 | { |
ganlikun | 0:13413ea9a877 | 1371 | uint32_t inputaddr = (uint32_t)pInBuffer; |
ganlikun | 0:13413ea9a877 | 1372 | |
ganlikun | 0:13413ea9a877 | 1373 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 1374 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1375 | |
ganlikun | 0:13413ea9a877 | 1376 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 1377 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 1378 | |
ganlikun | 0:13413ea9a877 | 1379 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 1380 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 1381 | { |
ganlikun | 0:13413ea9a877 | 1382 | /* Select the SHA256 mode and reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 1383 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 1384 | HASH->CR |= HASH_ALGOSELECTION_SHA256 | HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 1385 | } |
ganlikun | 0:13413ea9a877 | 1386 | |
ganlikun | 0:13413ea9a877 | 1387 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 1388 | __HAL_HASH_SET_NBVALIDBITS(Size); |
ganlikun | 0:13413ea9a877 | 1389 | |
ganlikun | 0:13413ea9a877 | 1390 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 1391 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 1392 | |
ganlikun | 0:13413ea9a877 | 1393 | /* Set the HASH DMA transfer complete callback */ |
ganlikun | 0:13413ea9a877 | 1394 | hhash->hdmain->XferCpltCallback = HASHEx_DMAXferCplt; |
ganlikun | 0:13413ea9a877 | 1395 | /* Set the DMA error callback */ |
ganlikun | 0:13413ea9a877 | 1396 | hhash->hdmain->XferErrorCallback = HASHEx_DMAError; |
ganlikun | 0:13413ea9a877 | 1397 | |
ganlikun | 0:13413ea9a877 | 1398 | /* Enable the DMA In DMA Stream */ |
ganlikun | 0:13413ea9a877 | 1399 | HAL_DMA_Start_IT(hhash->hdmain, inputaddr, (uint32_t)&HASH->DIN, (Size%4U ? (Size+3U)/4U:Size/4U)); |
ganlikun | 0:13413ea9a877 | 1400 | |
ganlikun | 0:13413ea9a877 | 1401 | /* Enable DMA requests */ |
ganlikun | 0:13413ea9a877 | 1402 | HASH->CR |= (HASH_CR_DMAE); |
ganlikun | 0:13413ea9a877 | 1403 | |
ganlikun | 0:13413ea9a877 | 1404 | /* Process UnLock */ |
ganlikun | 0:13413ea9a877 | 1405 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1406 | |
ganlikun | 0:13413ea9a877 | 1407 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1408 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1409 | } |
ganlikun | 0:13413ea9a877 | 1410 | |
ganlikun | 0:13413ea9a877 | 1411 | /** |
ganlikun | 0:13413ea9a877 | 1412 | * @brief Returns the computed digest in SHA256. |
ganlikun | 0:13413ea9a877 | 1413 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1414 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 1415 | * @param pOutBuffer: Pointer to the computed digest. Its size must be 32 bytes. |
ganlikun | 0:13413ea9a877 | 1416 | * @param Timeout: Timeout value |
ganlikun | 0:13413ea9a877 | 1417 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1418 | */ |
ganlikun | 0:13413ea9a877 | 1419 | HAL_StatusTypeDef HAL_HASHEx_SHA256_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout) |
ganlikun | 0:13413ea9a877 | 1420 | { |
ganlikun | 0:13413ea9a877 | 1421 | uint32_t tickstart = 0U; |
ganlikun | 0:13413ea9a877 | 1422 | |
ganlikun | 0:13413ea9a877 | 1423 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 1424 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1425 | |
ganlikun | 0:13413ea9a877 | 1426 | /* Change HASH peripheral state */ |
ganlikun | 0:13413ea9a877 | 1427 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 1428 | |
ganlikun | 0:13413ea9a877 | 1429 | /* Get tick */ |
ganlikun | 0:13413ea9a877 | 1430 | tickstart = HAL_GetTick(); |
ganlikun | 0:13413ea9a877 | 1431 | |
ganlikun | 0:13413ea9a877 | 1432 | while(HAL_IS_BIT_CLR(HASH->SR, HASH_FLAG_DCIS)) |
ganlikun | 0:13413ea9a877 | 1433 | { |
ganlikun | 0:13413ea9a877 | 1434 | /* Check for the Timeout */ |
ganlikun | 0:13413ea9a877 | 1435 | if(Timeout != HAL_MAX_DELAY) |
ganlikun | 0:13413ea9a877 | 1436 | { |
ganlikun | 0:13413ea9a877 | 1437 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
ganlikun | 0:13413ea9a877 | 1438 | { |
ganlikun | 0:13413ea9a877 | 1439 | /* Change state */ |
ganlikun | 0:13413ea9a877 | 1440 | hhash->State = HAL_HASH_STATE_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1441 | |
ganlikun | 0:13413ea9a877 | 1442 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1443 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1444 | |
ganlikun | 0:13413ea9a877 | 1445 | return HAL_TIMEOUT; |
ganlikun | 0:13413ea9a877 | 1446 | } |
ganlikun | 0:13413ea9a877 | 1447 | } |
ganlikun | 0:13413ea9a877 | 1448 | } |
ganlikun | 0:13413ea9a877 | 1449 | |
ganlikun | 0:13413ea9a877 | 1450 | /* Read the message digest */ |
ganlikun | 0:13413ea9a877 | 1451 | HASHEx_GetDigest(pOutBuffer, 32U); |
ganlikun | 0:13413ea9a877 | 1452 | |
ganlikun | 0:13413ea9a877 | 1453 | /* Change HASH peripheral state */ |
ganlikun | 0:13413ea9a877 | 1454 | hhash->State = HAL_HASH_STATE_READY; |
ganlikun | 0:13413ea9a877 | 1455 | |
ganlikun | 0:13413ea9a877 | 1456 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1457 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1458 | |
ganlikun | 0:13413ea9a877 | 1459 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1460 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1461 | } |
ganlikun | 0:13413ea9a877 | 1462 | |
ganlikun | 0:13413ea9a877 | 1463 | |
ganlikun | 0:13413ea9a877 | 1464 | /** |
ganlikun | 0:13413ea9a877 | 1465 | * @} |
ganlikun | 0:13413ea9a877 | 1466 | */ |
ganlikun | 0:13413ea9a877 | 1467 | /** @defgroup HASHEx_Group5 HMAC processing functions using DMA mode |
ganlikun | 0:13413ea9a877 | 1468 | * @brief HMAC processing functions using DMA mode . |
ganlikun | 0:13413ea9a877 | 1469 | * |
ganlikun | 0:13413ea9a877 | 1470 | @verbatim |
ganlikun | 0:13413ea9a877 | 1471 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 1472 | ##### HMAC processing using DMA functions ##### |
ganlikun | 0:13413ea9a877 | 1473 | =============================================================================== |
ganlikun | 0:13413ea9a877 | 1474 | [..] This section provides functions allowing to calculate in DMA mode |
ganlikun | 0:13413ea9a877 | 1475 | the HMAC value using one of the following algorithms: |
ganlikun | 0:13413ea9a877 | 1476 | (+) SHA224 |
ganlikun | 0:13413ea9a877 | 1477 | (+) SHA256 |
ganlikun | 0:13413ea9a877 | 1478 | |
ganlikun | 0:13413ea9a877 | 1479 | @endverbatim |
ganlikun | 0:13413ea9a877 | 1480 | * @{ |
ganlikun | 0:13413ea9a877 | 1481 | */ |
ganlikun | 0:13413ea9a877 | 1482 | |
ganlikun | 0:13413ea9a877 | 1483 | /** |
ganlikun | 0:13413ea9a877 | 1484 | * @brief Initializes the HASH peripheral in HMAC SHA224 mode |
ganlikun | 0:13413ea9a877 | 1485 | * then enables DMA to control data transfer. |
ganlikun | 0:13413ea9a877 | 1486 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1487 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 1488 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 1489 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 1490 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 1491 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1492 | */ |
ganlikun | 0:13413ea9a877 | 1493 | HAL_StatusTypeDef HAL_HMACEx_SHA224_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) |
ganlikun | 0:13413ea9a877 | 1494 | { |
ganlikun | 0:13413ea9a877 | 1495 | uint32_t inputaddr; |
ganlikun | 0:13413ea9a877 | 1496 | |
ganlikun | 0:13413ea9a877 | 1497 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 1498 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1499 | |
ganlikun | 0:13413ea9a877 | 1500 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 1501 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 1502 | |
ganlikun | 0:13413ea9a877 | 1503 | /* Save buffer pointer and size in handle */ |
ganlikun | 0:13413ea9a877 | 1504 | hhash->pHashInBuffPtr = pInBuffer; |
ganlikun | 0:13413ea9a877 | 1505 | hhash->HashBuffSize = Size; |
ganlikun | 0:13413ea9a877 | 1506 | hhash->HashInCount = 0U; |
ganlikun | 0:13413ea9a877 | 1507 | |
ganlikun | 0:13413ea9a877 | 1508 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 1509 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 1510 | { |
ganlikun | 0:13413ea9a877 | 1511 | /* Check if key size is greater than 64 bytes */ |
ganlikun | 0:13413ea9a877 | 1512 | if(hhash->Init.KeySize > 64U) |
ganlikun | 0:13413ea9a877 | 1513 | { |
ganlikun | 0:13413ea9a877 | 1514 | /* Select the HMAC SHA224 mode */ |
ganlikun | 0:13413ea9a877 | 1515 | HASH->CR |= (HASH_ALGOSELECTION_SHA224 | HASH_ALGOMODE_HMAC | HASH_HMAC_KEYTYPE_LONGKEY | HASH_CR_INIT); |
ganlikun | 0:13413ea9a877 | 1516 | } |
ganlikun | 0:13413ea9a877 | 1517 | else |
ganlikun | 0:13413ea9a877 | 1518 | { |
ganlikun | 0:13413ea9a877 | 1519 | /* Select the HMAC SHA224 mode */ |
ganlikun | 0:13413ea9a877 | 1520 | HASH->CR |= (HASH_ALGOSELECTION_SHA224 | HASH_ALGOMODE_HMAC | HASH_CR_INIT); |
ganlikun | 0:13413ea9a877 | 1521 | } |
ganlikun | 0:13413ea9a877 | 1522 | } |
ganlikun | 0:13413ea9a877 | 1523 | |
ganlikun | 0:13413ea9a877 | 1524 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 1525 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 1526 | |
ganlikun | 0:13413ea9a877 | 1527 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 1528 | __HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 1529 | |
ganlikun | 0:13413ea9a877 | 1530 | /* Get the key address */ |
ganlikun | 0:13413ea9a877 | 1531 | inputaddr = (uint32_t)(hhash->Init.pKey); |
ganlikun | 0:13413ea9a877 | 1532 | |
ganlikun | 0:13413ea9a877 | 1533 | /* Set the HASH DMA transfer complete callback */ |
ganlikun | 0:13413ea9a877 | 1534 | hhash->hdmain->XferCpltCallback = HASHEx_DMAXferCplt; |
ganlikun | 0:13413ea9a877 | 1535 | /* Set the DMA error callback */ |
ganlikun | 0:13413ea9a877 | 1536 | hhash->hdmain->XferErrorCallback = HASHEx_DMAError; |
ganlikun | 0:13413ea9a877 | 1537 | |
ganlikun | 0:13413ea9a877 | 1538 | /* Enable the DMA In DMA Stream */ |
ganlikun | 0:13413ea9a877 | 1539 | HAL_DMA_Start_IT(hhash->hdmain, inputaddr, (uint32_t)&HASH->DIN, (hhash->Init.KeySize%4U ? (hhash->Init.KeySize+3U)/4U:hhash->Init.KeySize/4U)); |
ganlikun | 0:13413ea9a877 | 1540 | /* Enable DMA requests */ |
ganlikun | 0:13413ea9a877 | 1541 | HASH->CR |= (HASH_CR_DMAE); |
ganlikun | 0:13413ea9a877 | 1542 | |
ganlikun | 0:13413ea9a877 | 1543 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1544 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1545 | |
ganlikun | 0:13413ea9a877 | 1546 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1547 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1548 | } |
ganlikun | 0:13413ea9a877 | 1549 | |
ganlikun | 0:13413ea9a877 | 1550 | /** |
ganlikun | 0:13413ea9a877 | 1551 | * @brief Initializes the HASH peripheral in HMAC SHA256 mode |
ganlikun | 0:13413ea9a877 | 1552 | * then enables DMA to control data transfer. |
ganlikun | 0:13413ea9a877 | 1553 | * @param hhash: pointer to a HASH_HandleTypeDef structure that contains |
ganlikun | 0:13413ea9a877 | 1554 | * the configuration information for HASH module |
ganlikun | 0:13413ea9a877 | 1555 | * @param pInBuffer: Pointer to the input buffer (buffer to be hashed). |
ganlikun | 0:13413ea9a877 | 1556 | * @param Size: Length of the input buffer in bytes. |
ganlikun | 0:13413ea9a877 | 1557 | * If the Size is not multiple of 64 bytes, the padding is managed by hardware. |
ganlikun | 0:13413ea9a877 | 1558 | * @retval HAL status |
ganlikun | 0:13413ea9a877 | 1559 | */ |
ganlikun | 0:13413ea9a877 | 1560 | HAL_StatusTypeDef HAL_HMACEx_SHA256_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size) |
ganlikun | 0:13413ea9a877 | 1561 | { |
ganlikun | 0:13413ea9a877 | 1562 | uint32_t inputaddr; |
ganlikun | 0:13413ea9a877 | 1563 | |
ganlikun | 0:13413ea9a877 | 1564 | /* Process Locked */ |
ganlikun | 0:13413ea9a877 | 1565 | __HAL_LOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1566 | |
ganlikun | 0:13413ea9a877 | 1567 | /* Change the HASH state */ |
ganlikun | 0:13413ea9a877 | 1568 | hhash->State = HAL_HASH_STATE_BUSY; |
ganlikun | 0:13413ea9a877 | 1569 | |
ganlikun | 0:13413ea9a877 | 1570 | /* Save buffer pointer and size in handle */ |
ganlikun | 0:13413ea9a877 | 1571 | hhash->pHashInBuffPtr = pInBuffer; |
ganlikun | 0:13413ea9a877 | 1572 | hhash->HashBuffSize = Size; |
ganlikun | 0:13413ea9a877 | 1573 | hhash->HashInCount = 0U; |
ganlikun | 0:13413ea9a877 | 1574 | |
ganlikun | 0:13413ea9a877 | 1575 | /* Check if initialization phase has already been performed */ |
ganlikun | 0:13413ea9a877 | 1576 | if(hhash->Phase == HAL_HASH_PHASE_READY) |
ganlikun | 0:13413ea9a877 | 1577 | { |
ganlikun | 0:13413ea9a877 | 1578 | /* Check if key size is greater than 64 bytes */ |
ganlikun | 0:13413ea9a877 | 1579 | if(hhash->Init.KeySize > 64U) |
ganlikun | 0:13413ea9a877 | 1580 | { |
ganlikun | 0:13413ea9a877 | 1581 | /* Select the HMAC SHA256 mode */ |
ganlikun | 0:13413ea9a877 | 1582 | HASH->CR |= (HASH_ALGOSELECTION_SHA256 | HASH_ALGOMODE_HMAC | HASH_HMAC_KEYTYPE_LONGKEY); |
ganlikun | 0:13413ea9a877 | 1583 | } |
ganlikun | 0:13413ea9a877 | 1584 | else |
ganlikun | 0:13413ea9a877 | 1585 | { |
ganlikun | 0:13413ea9a877 | 1586 | /* Select the HMAC SHA256 mode */ |
ganlikun | 0:13413ea9a877 | 1587 | HASH->CR |= (HASH_ALGOSELECTION_SHA256 | HASH_ALGOMODE_HMAC); |
ganlikun | 0:13413ea9a877 | 1588 | } |
ganlikun | 0:13413ea9a877 | 1589 | /* Reset the HASH processor core, so that the HASH will be ready to compute |
ganlikun | 0:13413ea9a877 | 1590 | the message digest of a new message */ |
ganlikun | 0:13413ea9a877 | 1591 | HASH->CR |= HASH_CR_INIT; |
ganlikun | 0:13413ea9a877 | 1592 | } |
ganlikun | 0:13413ea9a877 | 1593 | |
ganlikun | 0:13413ea9a877 | 1594 | /* Set the phase */ |
ganlikun | 0:13413ea9a877 | 1595 | hhash->Phase = HAL_HASH_PHASE_PROCESS; |
ganlikun | 0:13413ea9a877 | 1596 | |
ganlikun | 0:13413ea9a877 | 1597 | /* Configure the number of valid bits in last word of the message */ |
ganlikun | 0:13413ea9a877 | 1598 | __HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize); |
ganlikun | 0:13413ea9a877 | 1599 | |
ganlikun | 0:13413ea9a877 | 1600 | /* Get the key address */ |
ganlikun | 0:13413ea9a877 | 1601 | inputaddr = (uint32_t)(hhash->Init.pKey); |
ganlikun | 0:13413ea9a877 | 1602 | |
ganlikun | 0:13413ea9a877 | 1603 | /* Set the HASH DMA transfer complete callback */ |
ganlikun | 0:13413ea9a877 | 1604 | hhash->hdmain->XferCpltCallback = HASHEx_DMAXferCplt; |
ganlikun | 0:13413ea9a877 | 1605 | /* Set the DMA error callback */ |
ganlikun | 0:13413ea9a877 | 1606 | hhash->hdmain->XferErrorCallback = HASHEx_DMAError; |
ganlikun | 0:13413ea9a877 | 1607 | |
ganlikun | 0:13413ea9a877 | 1608 | /* Enable the DMA In DMA Stream */ |
ganlikun | 0:13413ea9a877 | 1609 | HAL_DMA_Start_IT(hhash->hdmain, inputaddr, (uint32_t)&HASH->DIN, (hhash->Init.KeySize%4U ? (hhash->Init.KeySize+3U)/4U:hhash->Init.KeySize/4U)); |
ganlikun | 0:13413ea9a877 | 1610 | /* Enable DMA requests */ |
ganlikun | 0:13413ea9a877 | 1611 | HASH->CR |= (HASH_CR_DMAE); |
ganlikun | 0:13413ea9a877 | 1612 | |
ganlikun | 0:13413ea9a877 | 1613 | /* Process Unlocked */ |
ganlikun | 0:13413ea9a877 | 1614 | __HAL_UNLOCK(hhash); |
ganlikun | 0:13413ea9a877 | 1615 | |
ganlikun | 0:13413ea9a877 | 1616 | /* Return function status */ |
ganlikun | 0:13413ea9a877 | 1617 | return HAL_OK; |
ganlikun | 0:13413ea9a877 | 1618 | } |
ganlikun | 0:13413ea9a877 | 1619 | |
ganlikun | 0:13413ea9a877 | 1620 | /** |
ganlikun | 0:13413ea9a877 | 1621 | * @} |
ganlikun | 0:13413ea9a877 | 1622 | */ |
ganlikun | 0:13413ea9a877 | 1623 | |
ganlikun | 0:13413ea9a877 | 1624 | /** |
ganlikun | 0:13413ea9a877 | 1625 | * @} |
ganlikun | 0:13413ea9a877 | 1626 | */ |
ganlikun | 0:13413ea9a877 | 1627 | #endif /* STM32F437xx || STM32F439xx || STM32F479xx */ |
ganlikun | 0:13413ea9a877 | 1628 | |
ganlikun | 0:13413ea9a877 | 1629 | #endif /* HAL_HASH_MODULE_ENABLED */ |
ganlikun | 0:13413ea9a877 | 1630 | /** |
ganlikun | 0:13413ea9a877 | 1631 | * @} |
ganlikun | 0:13413ea9a877 | 1632 | */ |
ganlikun | 0:13413ea9a877 | 1633 | |
ganlikun | 0:13413ea9a877 | 1634 | /** |
ganlikun | 0:13413ea9a877 | 1635 | * @} |
ganlikun | 0:13413ea9a877 | 1636 | */ |
ganlikun | 0:13413ea9a877 | 1637 | |
ganlikun | 0:13413ea9a877 | 1638 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
ganlikun | 0:13413ea9a877 | 1639 |