Modified version of the mbed library for use with the Nucleo boards.

Dependents:   EEPROMWrite Full-Project

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Aug 20 10:45:13 2015 +0100
Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade

Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/

Nordic: update application start address in GCC linker script

Who changed what in which revision?

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