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