mbed library sources, include can_api for nucleo-f091rc

Dependents:   CanNucleoF0_example

Fork of mbed-src by mbed official

Committer:
ptpaterson
Date:
Thu Jan 07 05:49:05 2016 +0000
Revision:
645:13c87cbecd54
Parent:
610:813dcc80987e
corrected freeze on CAN_RECEIVE_IT

Who changed what in which revision?

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