annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_hash.c @ 40:da86a7adc4fa

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