annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_hash_ex.c @ 75:2b3f8ed4a0b8

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