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