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