]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_cryp.h
Merge commit '28203e909e83b1ac6becb45a3eadae23b190df32' into master-core-pull
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L0 / stm32l0xx_hal_cryp.h
1 /**
2 ******************************************************************************
3 * @file stm32l0xx_hal_cryp.h
4 * @author MCD Application Team
5 * @version V1.2.0
6 * @date 06-February-2015
7 * @brief Header file of CRYP HAL module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2015 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 __STM32L0xx_HAL_CRYP_H
40 #define __STM32L0xx_HAL_CRYP_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 #if defined (STM32L041xx) || defined (STM32L061xx) || defined (STM32L062xx) || defined (STM32L063xx) || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
47
48 /* Includes ------------------------------------------------------------------*/
49 #include "stm32l0xx_hal_def.h"
50
51 /** @addtogroup STM32L0xx_HAL_Driver
52 * @{
53 */
54
55 /** @addtogroup CRYP
56 * @{
57 */
58
59 /* Exported types ------------------------------------------------------------*/
60
61 /** @defgroup CRYP_Exported_Types CRYP Exported Types
62 * @{
63 */
64
65 /**
66 * @brief CRYP Configuration Structure definition
67 */
68 typedef struct
69 {
70 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
71 This parameter can be a value of @ref CRYP_Data_Type */
72
73 uint8_t* pKey; /*!< The key used for encryption/decryption */
74
75 uint8_t* pInitVect; /*!< The initialization vector used also as initialization
76 counter in CTR mode */
77
78 }CRYP_InitTypeDef;
79
80 /**
81 * @brief HAL CRYP State structures definition
82 */
83 typedef enum
84 {
85 HAL_CRYP_STATE_RESET = 0x00, /*!< CRYP not yet initialized or disabled */
86 HAL_CRYP_STATE_READY = 0x01, /*!< CRYP initialized and ready for use */
87 HAL_CRYP_STATE_BUSY = 0x02, /*!< CRYP internal processing is ongoing */
88 HAL_CRYP_STATE_TIMEOUT = 0x03, /*!< CRYP timeout state */
89 HAL_CRYP_STATE_ERROR = 0x04 /*!< CRYP error state */
90
91 }HAL_CRYP_STATETypeDef;
92
93 /**
94 * @brief HAL CRYP phase structures definition
95 */
96 typedef enum
97 {
98 HAL_CRYP_PHASE_READY = 0x01, /*!< CRYP peripheral is ready for initialization. */
99 HAL_CRYP_PHASE_PROCESS = 0x02, /*!< CRYP peripheral is in processing phase */
100 }HAL_PhaseTypeDef;
101
102 /**
103 * @brief CRYP handle Structure definition
104 */
105 typedef struct
106 {
107 AES_TypeDef *Instance; /*!< Register base address */
108
109 CRYP_InitTypeDef Init; /*!< CRYP required parameters */
110
111 uint8_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
112
113 uint8_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
114
115 __IO uint16_t CrypInCount; /*!< Counter of inputed data */
116
117 __IO uint16_t CrypOutCount; /*!< Counter of outputed data */
118
119 HAL_StatusTypeDef Status; /*!< CRYP peripheral status */
120
121 HAL_PhaseTypeDef Phase; /*!< CRYP peripheral phase */
122
123 DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */
124
125 DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */
126
127 HAL_LockTypeDef Lock; /*!< CRYP locking object */
128
129 __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */
130
131 }CRYP_HandleTypeDef;
132
133 /**
134 * @}
135 */
136
137 /* Exported constants --------------------------------------------------------*/
138
139 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
140 * @{
141 */
142
143 /** @defgroup CRYP_Data_Type CRYP Data Type
144 * @{
145 */
146 #define CRYP_DATATYPE_32B ((uint32_t)0x00000000)
147 #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0
148 #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1
149 #define CRYP_DATATYPE_1B AES_CR_DATATYPE
150
151 #define IS_CRYP_DATATYPE(DATATYPE) (((DATATYPE) == CRYP_DATATYPE_32B) || \
152 ((DATATYPE) == CRYP_DATATYPE_16B) || \
153 ((DATATYPE) == CRYP_DATATYPE_8B) || \
154 ((DATATYPE) == CRYP_DATATYPE_1B))
155 /**
156 * @}
157 */
158
159 /** @defgroup CRYP_AlgoModeDirection CRYP Algo Mode Direction
160 * @{
161 */
162 #define CRYP_CR_ALGOMODE_DIRECTION (uint32_t)(AES_CR_MODE|AES_CR_CHMOD)
163
164 #define CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT ((uint32_t)0x00000000)
165 #define CRYP_CR_ALGOMODE_AES_ECB_KEYDERDECRYPT (AES_CR_MODE)
166 #define CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT (AES_CR_CHMOD_0)
167 #define CRYP_CR_ALGOMODE_AES_CBC_KEYDERDECRYPT ((uint32_t)(AES_CR_CHMOD_0|AES_CR_MODE))
168 #define CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT (AES_CR_CHMOD_1)
169 #define CRYP_CR_ALGOMODE_AES_CTR_DECRYPT ((uint32_t)(AES_CR_CHMOD_1 | AES_CR_MODE_1))
170 /**
171 * @}
172 */
173
174 /** @defgroup CRYP_AES_Interrupts AES Interrupts
175 * @{
176 */
177 #define CRYP_IT_CC AES_CR_CCIE /*!< Computation Complete interrupt */
178 #define CRYP_IT_ERR AES_CR_ERRIE /*!< Error interrupt */
179
180 #define IS_CRYP_AES_IT(IT) ((((IT) & (uint32_t)0xFFFFF9FF) == 0x00000000) && ((IT) != 0x00000000))
181 #define IS_CRYP_AES_GET_IT(IT) (((IT) == CRYP_IT_CC) || ((IT) == CRYP_IT_ERR))
182
183 /**
184 * @}
185 */
186
187
188 /** @defgroup CRYP_AES_Flags AES Flags
189 * @{
190 */
191 #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation Complete Flag */
192 #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read Error Flag */
193 #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error Flag */
194
195 #define IS_CRYP_STATUS_FLAG(FLAG) (((FLAG) == CRYP_FLAG_CCF) || \
196 ((FLAG) == CRYP_FLAG_RDERR) || \
197 ((FLAG) == CRYP_FLAG_WRERR))
198 /**
199 * @}
200 */
201
202 /** @defgroup CRYP_AES_Clear_Flags AES Clear Flags
203 * @{
204 */
205 #define CRYP_CLEARFLAG_CCF AES_CR_CCFC /*!< Computation Complete Flag Clear */
206 #define CRYP_CLEARFLAG_RDERR AES_CR_ERRC /*!< Read Error Clear */
207 #define CRYP_CLEARFLAG_WRERR AES_CR_ERRC /*!< Write Error Clear */
208
209 /**
210 * @}
211 */
212
213 /**
214 * @}
215 */
216
217 /* Exported macro ------------------------------------------------------------*/
218
219 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
220 * @{
221 */
222
223 /** @brief Reset CRYP handle state
224 * @param __HANDLE__: specifies the CRYP handle.
225 * @retval None
226 */
227 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
228
229 /**
230 * @brief Enable/Disable the CRYP peripheral.
231 * @param __HANDLE__: specifies the CRYP handle.
232 * @retval None
233 */
234 #define __HAL_CRYP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR, AES_CR_EN)
235 #define __HAL_CRYP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR, AES_CR_EN)
236
237 /**
238 * @brief Set the algorithm mode: AES-ECB, AES-CBC, AES-CTR, DES-ECB, DES-CBC,...
239 * @param __HANDLE__: specifies the CRYP handle.
240 * @param __MODE__: The algorithm mode.
241 * @retval None
242 */
243 #define __HAL_CRYP_SET_MODE(__HANDLE__,__MODE__) SET_BIT((__HANDLE__)->Instance->CR, (__MODE__))
244
245
246 /** @brief Check whether the specified CRYP flag is set or not.
247 * @param __HANDLE__: specifies the CRYP handle.
248 * @param __FLAG__: specifies the flag to check.
249 * This parameter can be one of the following values:
250 * @arg CRYP_FLAG_CCF : Computation Complete Flag
251 * @arg CRYP_FLAG_RDERR : Read Error Flag
252 * @arg CRYP_FLAG_WRERR : Write Error Flag
253 * @retval The new state of __FLAG__ (TRUE or FALSE).
254 */
255 #define __HAL_CRYP_GET_FLAG(__HANDLE__,__FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
256
257 /** @brief Clear the CRYP pending flag.
258 * @param __HANDLE__: specifies the CRYP handle.
259 * @param __FLAG__: specifies the flag to clear.
260 * This parameter can be one of the following values:
261 * @arg CRYP_CLEARFLAG_CCF : Computation Complete Clear Flag
262 * @arg CRYP_CLEARFLAG_RDERR : Read Error Clear
263 * @arg CRYP_CLEARFLAG_WRERR : Write Error Clear
264 * @retval None
265 */
266 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__))
267
268 /**
269 * @brief Enable the CRYP interrupt.
270 * @param __HANDLE__: specifies the CRYP handle.
271 * @param __INTERRUPT__: CRYP Interrupt.
272 * @retval None
273 */
274 #define __HAL_CRYP_ENABLE_IT(__HANDLE__,__INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__))
275
276 /**
277 * @brief Disable the CRYP interrupt.
278 * @param __HANDLE__: specifies the CRYP handle.
279 * @param __INTERRUPT__: CRYP interrupt.
280 * @retval None
281 */
282 #define __HAL_CRYP_DISABLE_IT(__HANDLE__,__INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__))
283
284 /** @brief Checks if the specified CRYP interrupt source is enabled or disabled.
285 * @param __HANDLE__: specifies the CRYP handle.
286 * @param __INTERRUPT__: CRYP interrupt source to check
287 * This parameter can be one of the following values:
288 * @arg CRYP_IT_CC : Computation Complete interrupt
289 * @arg CRYP_IT_ERR : Error interrupt (used for RDERR and WRERR)
290 * @retval State of interruption (SET or RESET)
291 */
292 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
293 (( ((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__) \
294 )? SET : RESET \
295 )
296
297 /** @brief Clear the CRYP pending IT.
298 * @param __HANDLE__: specifies the CRYP handle.
299 * @param __IT__: specifies the IT to clear.
300 * This parameter can be one of the following values:
301 * @arg CRYP_CLEARFLAG_CCF : Computation Complete Clear Flag
302 * @arg CRYP_CLEARFLAG_RDERR : Read Error Clear
303 * @arg CRYP_CLEARFLAG_WRERR : Write Error Clear
304 * @retval None
305 */
306 #define __HAL_CRYP_CLEAR_IT(__HANDLE__, __IT__) SET_BIT((__HANDLE__)->Instance->CR, (__IT__))
307
308 /**
309 * @}
310 */
311
312 /* Include CRYP HAL Extension module */
313 #include "stm32l0xx_hal_cryp_ex.h"
314
315 /* Exported functions --------------------------------------------------------*/
316
317 /** @addtogroup CRYP_Exported_Functions
318 * @{
319 */
320
321 /** @addtogroup CRYP_Exported_Functions_Group1
322 * @{
323 */
324
325 /* Initialization/de-initialization functions *********************************/
326 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
327 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
328
329 /* MSP functions *************************************************************/
330 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
331 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
332
333 /**
334 * @}
335 */
336
337 /** @addtogroup CRYP_Exported_Functions_Group2
338 * @{
339 */
340
341 /* AES encryption/decryption using polling ***********************************/
342 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
343 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
344 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
345 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
346 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
347 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
348
349 /* AES encryption/decryption using interrupt *********************************/
350 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
351 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
352 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
353 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
354 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
355 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
356
357 /* AES encryption/decryption using DMA ***************************************/
358 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
359 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
360 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
361 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
362 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
363 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
364
365 /**
366 * @}
367 */
368
369 /** @addtogroup CRYP_Exported_Functions_Group3
370 * @{
371 */
372
373 /* CallBack functions ********************************************************/
374 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
375 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
376 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
377
378 /**
379 * @}
380 */
381
382 /** @addtogroup CRYP_Exported_Functions_Group4
383 * @{
384 */
385
386 /* Processing functions ********************************************************/
387 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
388
389 /**
390 * @}
391 */
392
393 /** @addtogroup CRYP_Exported_Functions_Group5
394 * @{
395 */
396
397 /* Peripheral State functions **************************************************/
398 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
399
400 /**
401 * @}
402 */
403
404 /**
405 * @}
406 */
407
408 /**
409 * @}
410 */
411
412 /**
413 * @}
414 */
415
416 #endif /* STM32L041xx || STM32L061xx || STM32L062xx || STM32L063xx || STM32L081xx || STM32L082xx || STM32L083xx */
417 #ifdef __cplusplus
418 }
419 #endif
420
421 #endif /* __STM32L0xx_HAL_CRYP_H */
422
423 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
424
Imprint / Impressum