inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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