]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_hash.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_hash.h
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_hash.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    19-June-2014
7   * @brief   Header file of HASH HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************
36   */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_HASH_H
40 #define __STM32F4xx_HAL_HASH_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 #if defined(STM32F415xx) || defined(STM32F417xx) || defined(STM32F437xx) || defined(STM32F439xx)
47
48 /* Includes ------------------------------------------------------------------*/
49 #include "stm32f4xx_hal_def.h"
50
51 /** @addtogroup STM32F4xx_HAL_Driver
52   * @{
53   */
54
55 /** @addtogroup HASH
56   * @{
57   */ 
58
59 /* Exported types ------------------------------------------------------------*/
60
61 /** 
62   * @brief  HASH Configuration Structure definition
63   */
64 typedef struct
65 {
66   uint32_t DataType;  /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
67                            This parameter can be a value of @ref HASH_Data_Type */
68
69   uint32_t KeySize;   /*!< The key size is used only in HMAC operation          */
70
71   uint8_t* pKey;      /*!< The key is used only in HMAC operation               */
72 }HASH_InitTypeDef;
73
74 /** 
75   * @brief HAL State structures definition
76   */ 
77 typedef enum
78 {
79   HAL_HASH_STATE_RESET     = 0x00,  /*!< HASH not yet initialized or disabled */
80   HAL_HASH_STATE_READY     = 0x01,  /*!< HASH initialized and ready for use   */
81   HAL_HASH_STATE_BUSY      = 0x02,  /*!< HASH internal process is ongoing     */
82   HAL_HASH_STATE_TIMEOUT   = 0x03,  /*!< HASH timeout state                   */
83   HAL_HASH_STATE_ERROR     = 0x04   /*!< HASH error state                     */
84 }HAL_HASH_STATETypeDef;
85
86 /** 
87   * @brief HAL phase structures definition
88   */
89 typedef enum
90 {
91   HAL_HASH_PHASE_READY     = 0x01,  /*!< HASH peripheral is ready for initialization */
92   HAL_HASH_PHASE_PROCESS   = 0x02,  /*!< HASH peripheral is in processing phase      */
93 }HAL_HASHPhaseTypeDef;
94
95 /** 
96   * @brief  HASH Handle Structure definition
97   */
98 typedef struct
99 {
100       HASH_InitTypeDef           Init;              /*!< HASH required parameters       */
101
102       uint8_t                    *pHashInBuffPtr;   /*!< Pointer to input buffer        */
103
104       uint8_t                    *pHashOutBuffPtr;  /*!< Pointer to input buffer        */
105
106      __IO uint32_t               HashBuffSize;      /*!< Size of buffer to be processed */
107
108      __IO uint32_t               HashInCount;       /*!< Counter of inputed data        */
109
110      __IO uint32_t               HashITCounter;     /*!< Counter of issued interrupts   */
111
112       HAL_StatusTypeDef          Status;            /*!< HASH peripheral status         */
113
114       HAL_HASHPhaseTypeDef       Phase;             /*!< HASH peripheral phase          */
115
116       DMA_HandleTypeDef          *hdmain;           /*!< HASH In DMA handle parameters  */
117
118       HAL_LockTypeDef            Lock;              /*!< HASH locking object            */
119
120      __IO HAL_HASH_STATETypeDef  State;             /*!< HASH peripheral state          */
121 } HASH_HandleTypeDef;
122
123 /* Exported constants --------------------------------------------------------*/
124
125 /** @defgroup HASH_Exported_Constants
126   * @{
127   */
128
129 /** @defgroup HASH_Algo_Selection
130   * @{
131   */
132 #define HASH_AlgoSelection_SHA1      ((uint32_t)0x0000)  /*!< HASH function is SHA1   */
133 #define HASH_AlgoSelection_SHA224    HASH_CR_ALGO_1      /*!< HASH function is SHA224 */
134 #define HASH_AlgoSelection_SHA256    HASH_CR_ALGO        /*!< HASH function is SHA256 */
135 #define HASH_AlgoSelection_MD5       HASH_CR_ALGO_0      /*!< HASH function is MD5    */
136
137 #define IS_HASH_ALGOSELECTION(ALGOSELECTION) (((ALGOSELECTION) == HASH_AlgoSelection_SHA1)   || \
138                                               ((ALGOSELECTION) == HASH_AlgoSelection_SHA224) || \
139                                               ((ALGOSELECTION) == HASH_AlgoSelection_SHA256) || \
140                                               ((ALGOSELECTION) == HASH_AlgoSelection_MD5))
141 /**
142   * @}
143   */
144
145 /** @defgroup HASH_Algorithm_Mode
146   * @{
147   */ 
148 #define HASH_AlgoMode_HASH         ((uint32_t)0x00000000)  /*!< Algorithm is HASH */ 
149 #define HASH_AlgoMode_HMAC         HASH_CR_MODE            /*!< Algorithm is HMAC */
150
151 #define IS_HASH_ALGOMODE(ALGOMODE) (((ALGOMODE) == HASH_AlgoMode_HASH) || \
152                                     ((ALGOMODE) == HASH_AlgoMode_HMAC))
153 /**
154   * @}
155   */
156
157 /** @defgroup HASH_Data_Type
158   * @{
159   */
160 #define HASH_DATATYPE_32B          ((uint32_t)0x0000) /*!< 32-bit data. No swapping                     */
161 #define HASH_DATATYPE_16B          HASH_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped       */
162 #define HASH_DATATYPE_8B           HASH_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped            */
163 #define HASH_DATATYPE_1B           HASH_CR_DATATYPE   /*!< 1-bit data. In the word all bits are swapped */
164
165 #define IS_HASH_DATATYPE(DATATYPE) (((DATATYPE) == HASH_DATATYPE_32B)|| \
166                                     ((DATATYPE) == HASH_DATATYPE_16B)|| \
167                                     ((DATATYPE) == HASH_DATATYPE_8B) || \
168                                     ((DATATYPE) == HASH_DATATYPE_1B))
169 /**
170   * @}
171   */
172
173 /** @defgroup HASH_HMAC_Long_key_only_for_HMAC_mode
174   * @{
175   */ 
176 #define HASH_HMACKeyType_ShortKey      ((uint32_t)0x00000000)  /*!< HMAC Key is <= 64 bytes */
177 #define HASH_HMACKeyType_LongKey       HASH_CR_LKEY            /*!< HMAC Key is > 64 bytes  */
178
179 #define IS_HASH_HMAC_KEYTYPE(KEYTYPE) (((KEYTYPE) == HASH_HMACKeyType_ShortKey) || \
180                                        ((KEYTYPE) == HASH_HMACKeyType_LongKey))
181 /**
182   * @}
183   */
184
185 /** @defgroup HASH_flags_definition
186   * @{
187   */
188 #define HASH_FLAG_DINIS            HASH_SR_DINIS  /*!< 16 locations are free in the DIN : A new block can be entered into the input buffer */
189 #define HASH_FLAG_DCIS             HASH_SR_DCIS   /*!< Digest calculation complete                                                         */
190 #define HASH_FLAG_DMAS             HASH_SR_DMAS   /*!< DMA interface is enabled (DMAE=1) or a transfer is ongoing                          */
191 #define HASH_FLAG_BUSY             HASH_SR_BUSY   /*!< The hash core is Busy : processing a block of data                                  */
192 #define HASH_FLAG_DINNE            HASH_CR_DINNE  /*!< DIN not empty : The input buffer contains at least one word of data                 */
193 /**
194   * @}
195   */
196
197 /** @defgroup HASH_interrupts_definition
198   * @{
199   */  
200 #define HASH_IT_DINI               HASH_IMR_DINIM  /*!< A new block can be entered into the input buffer (DIN) */
201 #define HASH_IT_DCI                HASH_IMR_DCIM   /*!< Digest calculation complete                            */
202 /**
203   * @}
204   */
205
206 /**
207   * @}
208   */
209
210 /* Exported macro ------------------------------------------------------------*/
211
212 /** @brief Reset HASH handle state
213   * @param  __HANDLE__: specifies the HASH handle.
214   * @retval None
215   */
216 #define __HAL_HASH_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_HASH_STATE_RESET)
217
218 /** @brief  Check whether the specified HASH flag is set or not.
219   * @param  __FLAG__: specifies the flag to check.
220   *         This parameter can be one of the following values:
221   *            @arg HASH_FLAG_DINIS: A new block can be entered into the input buffer. 
222   *            @arg HASH_FLAG_DCIS: Digest calculation complete
223   *            @arg HASH_FLAG_DMAS: DMA interface is enabled (DMAE=1) or a transfer is ongoing
224   *            @arg HASH_FLAG_BUSY: The hash core is Busy : processing a block of data
225   *            @arg HASH_FLAG_DINNE: DIN not empty : The input buffer contains at least one word of data
226   * @retval The new state of __FLAG__ (TRUE or FALSE).
227   */
228 #define __HAL_HASH_GET_FLAG(__FLAG__) ((HASH->SR & (__FLAG__)) == (__FLAG__))
229
230 /**
231   * @brief  Macros for HMAC finish.
232   * @param  None
233   * @retval None
234   */
235 #define HAL_HMAC_MD5_Finish          HAL_HASH_MD5_Finish
236 #define HAL_HMAC_SHA1_Finish         HAL_HASH_SHA1_Finish
237 #define HAL_HMAC_SHA224_Finish       HAL_HASH_SHA224_Finish
238 #define HAL_HMAC_SHA256_Finish       HAL_HASH_SHA256_Finish
239
240 /**
241   * @brief  Enable the multiple DMA mode. 
242   *         This feature is available only in STM32F429x and STM32F439x devices.
243   * @param  None
244   * @retval None
245   */
246 #define __HAL_HASH_SET_MDMAT()          HASH->CR |= HASH_CR_MDMAT
247
248 /**
249   * @brief  Disable the multiple DMA mode.
250   * @param  None
251   * @retval None
252   */
253 #define __HAL_HASH_RESET_MDMAT()        HASH->CR &= (uint32_t)(~HASH_CR_MDMAT)
254
255 /**
256   * @brief  Start the digest computation
257   * @param  None
258   * @retval None
259   */
260 #define __HAL_HASH_START_DIGEST()       HASH->STR |= HASH_STR_DCAL
261
262 /**
263   * @brief Set the number of valid bits in last word written in Data register
264   * @param  SIZE: size in byte of last data written in Data register.
265   * @retval None
266 */
267 #define __HAL_HASH_SET_NBVALIDBITS(SIZE) do{HASH->STR &= ~(HASH_STR_NBW);\
268                                             HASH->STR |= 8 * ((SIZE) % 4);\
269                                            }while(0)
270
271 /* Include HASH HAL Extension module */
272 #include "stm32f4xx_hal_hash_ex.h"
273
274 /* Exported functions --------------------------------------------------------*/
275
276 /* Initialization and de-initialization functions  **********************************/
277 HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash);
278 HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash);
279
280 /* HASH processing using polling  *********************************************/
281 HAL_StatusTypeDef HAL_HASH_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout);
282 HAL_StatusTypeDef HAL_HASH_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout);
283 HAL_StatusTypeDef HAL_HASH_MD5_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
284 HAL_StatusTypeDef HAL_HASH_SHA1_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
285
286 /* HASH-MAC processing using polling  *****************************************/
287 HAL_StatusTypeDef HAL_HMAC_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout);
288 HAL_StatusTypeDef HAL_HMAC_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer, uint32_t Timeout);
289
290 /* HASH processing using interrupt  *******************************************/
291 HAL_StatusTypeDef HAL_HASH_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer);
292 HAL_StatusTypeDef HAL_HASH_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t* pOutBuffer);
293
294 /* HASH processing using DMA  *************************************************/
295 HAL_StatusTypeDef HAL_HASH_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
296 HAL_StatusTypeDef HAL_HASH_SHA1_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout);
297 HAL_StatusTypeDef HAL_HASH_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
298 HAL_StatusTypeDef HAL_HASH_MD5_Finish(HASH_HandleTypeDef *hhash, uint8_t* pOutBuffer, uint32_t Timeout);
299
300 /* HASH-HMAC processing using DMA  ********************************************/
301 HAL_StatusTypeDef HAL_HMAC_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
302 HAL_StatusTypeDef HAL_HMAC_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
303
304 /* Processing functions  ******************************************************/
305 void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash);
306
307 /* Peripheral State functions  ************************************************/
308 HAL_HASH_STATETypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash);
309 void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash);
310 void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash);
311 void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash);
312 void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash);
313 void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash);
314
315 #endif /* STM32F415xx || STM32F417xx || STM32F437xx || STM32F439xx */
316 /**
317   * @}
318   */ 
319
320 /**
321   * @}
322   */
323   
324 #ifdef __cplusplus
325 }
326 #endif
327
328
329 #endif /* __STM32F4xx_HAL_HASH_H */
330
331 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/