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