]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L1/stm32l1xx_hal_cryp.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L1 / stm32l1xx_hal_cryp.h
1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_hal_cryp.h
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @date    5-September-2014
7   * @brief   Header file of CRYP 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 __STM32L1xx_HAL_CRYP_H
40 #define __STM32L1xx_HAL_CRYP_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45    
46 #if defined(STM32L162xC) || defined(STM32L162xCA) || defined(STM32L162xD) || defined(STM32L162xE)
47
48 /* Includes ------------------------------------------------------------------*/
49 #include "stm32l1xx_hal_def.h"
50
51 /** @addtogroup STM32L1xx_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   CRYP_InitTypeDef            Init;             /*!< CRYP required parameters */
108
109   uint8_t                     *pCrypInBuffPtr;  /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
110
111   uint8_t                     *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
112
113   __IO uint16_t               CrypInCount;      /*!< Counter of inputed data */
114
115   __IO uint16_t               CrypOutCount;     /*!< Counter of outputed data */
116
117   HAL_StatusTypeDef           Status;           /*!< CRYP peripheral status */
118
119   HAL_PhaseTypeDef            Phase;            /*!< CRYP peripheral phase */
120
121   DMA_HandleTypeDef           *hdmain;          /*!< CRYP In DMA handle parameters */
122
123   DMA_HandleTypeDef           *hdmaout;         /*!< CRYP Out DMA handle parameters */
124
125   HAL_LockTypeDef             Lock;             /*!< CRYP locking object */
126
127   __IO  HAL_CRYP_STATETypeDef State;            /*!< CRYP peripheral state */
128
129 }CRYP_HandleTypeDef;
130
131 /**
132   * @}
133   */
134
135 /* Exported constants --------------------------------------------------------*/
136
137 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
138   * @{
139   */
140
141 /** @defgroup CRYP_Data_Type CRYP Data Type
142   * @{
143   */
144 #define CRYP_DATATYPE_32B         ((uint32_t)0x00000000)
145 #define CRYP_DATATYPE_16B         AES_CR_DATATYPE_0
146 #define CRYP_DATATYPE_8B          AES_CR_DATATYPE_1
147 #define CRYP_DATATYPE_1B          AES_CR_DATATYPE
148
149 #define IS_CRYP_DATATYPE(DATATYPE) (((DATATYPE) == CRYP_DATATYPE_32B) || \
150                                     ((DATATYPE) == CRYP_DATATYPE_16B) || \
151                                     ((DATATYPE) == CRYP_DATATYPE_8B)  || \
152                                     ((DATATYPE) == CRYP_DATATYPE_1B))  
153 /**
154   * @}
155   */
156
157 /** @defgroup CRYP_AlgoModeDirection CRYP Algo Mode Direction
158   * @{
159   */ 
160 #define CRYP_CR_ALGOMODE_DIRECTION              (uint32_t)(AES_CR_MODE|AES_CR_CHMOD)
161
162 #define CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT        ((uint32_t)0x00000000)
163 #define CRYP_CR_ALGOMODE_AES_ECB_KEYDERDECRYPT  (AES_CR_MODE)
164 #define CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT        (AES_CR_CHMOD_0)
165 #define CRYP_CR_ALGOMODE_AES_CBC_KEYDERDECRYPT  ((uint32_t)(AES_CR_CHMOD_0|AES_CR_MODE))
166 #define CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT        (AES_CR_CHMOD_1)
167 #define CRYP_CR_ALGOMODE_AES_CTR_DECRYPT        ((uint32_t)(AES_CR_CHMOD_1 | AES_CR_MODE_1))
168 /**
169   * @}
170   */
171   
172 /** @defgroup CRYP_AES_Interrupts AES Interrupts
173   * @{
174   */ 
175 #define AES_IT_CC                          AES_CR_CCIE  /*!< Computation Complete interrupt */
176 #define AES_IT_ERR                         AES_CR_ERRIE /*!< Error interrupt                */
177
178 /**
179   * @}
180   */
181
182
183 /** @defgroup CRYP_AES_Flags AES Flags
184   * @{
185   */ 
186 #define AES_FLAG_CCF                       AES_SR_CCF    /*!< Computation Complete Flag */
187 #define AES_FLAG_RDERR                     AES_SR_RDERR  /*!< Read Error Flag           */
188 #define AES_FLAG_WRERR                     AES_SR_WRERR  /*!< Write Error Flag          */
189
190 /**
191   * @}
192   */ 
193
194 /** @defgroup CRYP_AES_Clear_Flags AES Clear Flags
195   * @{
196   */ 
197 #define AES_CLEARFLAG_CCF                       AES_CR_CCFC   /*!< Computation Complete Flag Clear */
198 #define AES_CLEARFLAG_RDERR                     AES_CR_ERRC   /*!< Read Error Clear           */
199 #define AES_CLEARFLAG_WRERR                     AES_CR_ERRC   /*!< Write Error Clear          */
200
201 /**
202   * @}
203   */ 
204
205 /**
206   * @}
207   */
208
209 /* Exported macro ------------------------------------------------------------*/
210
211 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
212   * @{
213   */
214
215 /** @brief Reset CRYP handle state
216   * @param  __HANDLE__: specifies the CRYP Handle.
217   * @retval None
218   */
219 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
220
221 /**
222   * @brief  Enable/Disable the CRYP peripheral.
223   * @retval None
224   */
225 #define __HAL_CRYP_ENABLE()                   SET_BIT(AES->CR, AES_CR_EN)
226 #define __HAL_CRYP_DISABLE()                  CLEAR_BIT(AES->CR, AES_CR_EN)
227
228 /**
229   * @brief  Set the algorithm mode: AES-ECB, AES-CBC, AES-CTR, DES-ECB, DES-CBC,...
230   * @param  __MODE__: The algorithm mode.
231   * @retval None
232   */
233 #define __HAL_CRYP_SET_MODE(__MODE__)             SET_BIT(AES->CR, (__MODE__))
234
235
236 /** @brief  Check whether the specified CRYP flag is set or not.
237   * @param  __FLAG__: specifies the flag to check.
238   *         This parameter can be one of the following values:
239   *            @arg AES_FLAG_CCF   : Computation Complete Flag
240   *            @arg AES_FLAG_RDERR : Read Error Flag
241   *            @arg AES_FLAG_WRERR : Write Error Flag
242   * @retval The new state of __FLAG__ (TRUE or FALSE).
243   */
244 #define __HAL_CRYP_GET_FLAG(__FLAG__)         ((AES->SR & (__FLAG__)) == (__FLAG__))
245
246 /** @brief  Clear the CRYP pending flag.
247   * @param  __HANDLE__: specifies the CRYP handle.
248   * @param  __FLAG__: specifies the flag to clear.
249   *         This parameter can be one of the following values:
250   *            @arg AES_CLEARFLAG_CCF   : Computation Complete Clear Flag
251   *            @arg AES_CLEARFLAG_RDERR : Read Error Clear
252   *            @arg AES_CLEARFLAG_WRERR : Write Error Clear
253   * @retval None
254   */
255 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT(AES->CR, (__FLAG__))
256
257 /**
258   * @brief  Enable the CRYP interrupt.
259   * @param  __INTERRUPT__: CRYP Interrupt.
260   * @retval None
261   */
262 #define __HAL_CRYP_ENABLE_IT(__INTERRUPT__)   SET_BIT(AES->CR, (__INTERRUPT__))
263
264 /**
265   * @brief  Disable the CRYP interrupt.
266   * @param  __INTERRUPT__: CRYP interrupt.
267   * @retval None
268   */
269 #define __HAL_CRYP_DISABLE_IT(__INTERRUPT__)  CLEAR_BIT(AES->CR, (__INTERRUPT__))
270
271 /** @brief  Checks if the specified CRYP interrupt source is enabled or disabled.
272   * @param __HANDLE__: CRYP handle
273   * @param __INTERRUPT__: CRYP interrupt source to check
274   *         This parameter can be one of the following values:
275   *            @arg AES_IT_CC   : Computation Complete interrupt
276   *            @arg AES_IT_ERR : Error interrupt (used for RDERR and WRERR)
277   * @retval State of interruption (SET or RESET)
278   */
279 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
280     (( (AES->CR & (__INTERRUPT__)) == (__INTERRUPT__)       \
281      )? SET : RESET                                         \
282     )
283          
284 /** @brief  Clear the CRYP pending IT.
285   * @param  __HANDLE__: specifies the CRYP handle.
286   * @param  __IT__: specifies the IT to clear.
287   *         This parameter can be one of the following values:
288   *            @arg AES_CLEARFLAG_CCF   : Computation Complete Clear Flag
289   *            @arg AES_CLEARFLAG_RDERR : Read Error Clear
290   *            @arg AES_CLEARFLAG_WRERR : Write Error Clear
291   * @retval None
292   */
293 #define __HAL_CRYP_CLEAR_IT(__HANDLE__, __IT__) SET_BIT(AES->CR, (__IT__))
294
295 /**
296   * @}
297   */
298
299 /* Include CRYP HAL Extension module */
300 #include "stm32l1xx_hal_cryp_ex.h"
301
302 /* Exported functions --------------------------------------------------------*/
303
304 /** @addtogroup CRYP_Exported_Functions
305   * @{
306   */
307
308 /** @addtogroup CRYP_Exported_Functions_Group1
309   * @{
310   */
311
312 /* Initialization/de-initialization functions *********************************/
313 HAL_StatusTypeDef     HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
314 HAL_StatusTypeDef     HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
315
316 /* MSP functions  *************************************************************/
317 void                  HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
318 void                  HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
319
320 /**
321   * @}
322   */ 
323
324 /** @addtogroup CRYP_Exported_Functions_Group2
325   * @{
326   */
327
328 /* AES encryption/decryption using polling  ***********************************/
329 HAL_StatusTypeDef     HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
330 HAL_StatusTypeDef     HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
331 HAL_StatusTypeDef     HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
332 HAL_StatusTypeDef     HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
333 HAL_StatusTypeDef     HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
334 HAL_StatusTypeDef     HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
335
336 /* AES encryption/decryption using interrupt  *********************************/
337 HAL_StatusTypeDef     HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
338 HAL_StatusTypeDef     HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
339 HAL_StatusTypeDef     HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
340 HAL_StatusTypeDef     HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
341 HAL_StatusTypeDef     HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
342 HAL_StatusTypeDef     HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
343
344 /* AES encryption/decryption using DMA  ***************************************/
345 HAL_StatusTypeDef     HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
346 HAL_StatusTypeDef     HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
347 HAL_StatusTypeDef     HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
348 HAL_StatusTypeDef     HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
349 HAL_StatusTypeDef     HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
350 HAL_StatusTypeDef     HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
351
352 /**
353   * @}
354   */ 
355
356 /** @addtogroup CRYP_Exported_Functions_Group3
357   * @{
358   */
359
360 /* CallBack functions  ********************************************************/
361 void                  HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
362 void                  HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
363 void                  HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
364
365 /**
366   * @}
367   */ 
368
369 /** @addtogroup CRYP_Exported_Functions_Group4
370   * @{
371   */
372
373 /* Processing functions  ********************************************************/
374 void                  HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
375
376 /**
377   * @}
378   */ 
379
380 /** @addtogroup CRYP_Exported_Functions_Group5
381   * @{
382   */
383
384 /* Peripheral State functions  **************************************************/
385 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
386
387 /**
388   * @}
389   */ 
390
391 /**
392   * @}
393   */ 
394
395 /**
396   * @}
397   */ 
398
399 /**
400   * @}
401   */ 
402   
403 #endif /* STM32L162xC || STM32L162xCA || STM32L162xD || STM32L162xE*/
404
405 #ifdef __cplusplus
406 }
407 #endif
408
409 #endif /* __STM32L1xx_HAL_CRYP_H */
410
411 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/