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