You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32l1xx_hal_cryp.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_cryp.h
  4. * @author MCD Application Team
  5. * @brief Header file of CRYP HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32L1xx_HAL_CRYP_H
  21. #define __STM32L1xx_HAL_CRYP_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #if defined(STM32L162xC) || defined(STM32L162xCA) || defined(STM32L162xD) || defined(STM32L162xE) || defined(STM32L162xDX)
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "stm32l1xx_hal_def.h"
  28. /** @addtogroup STM32L1xx_HAL_Driver
  29. * @{
  30. */
  31. /** @addtogroup CRYP
  32. * @{
  33. */
  34. /* Exported types ------------------------------------------------------------*/
  35. /** @defgroup CRYP_Exported_Types CRYP Exported Types
  36. * @{
  37. */
  38. /**
  39. * @brief CRYP Configuration Structure definition
  40. */
  41. typedef struct
  42. {
  43. uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
  44. This parameter can be a value of @ref CRYP_Data_Type */
  45. uint8_t* pKey; /*!< The key used for encryption/decryption */
  46. uint8_t* pInitVect; /*!< The initialization vector used also as initialization
  47. counter in CTR mode */
  48. }CRYP_InitTypeDef;
  49. /**
  50. * @brief HAL CRYP State structures definition
  51. */
  52. typedef enum
  53. {
  54. HAL_CRYP_STATE_RESET = 0x00, /*!< CRYP not yet initialized or disabled */
  55. HAL_CRYP_STATE_READY = 0x01, /*!< CRYP initialized and ready for use */
  56. HAL_CRYP_STATE_BUSY = 0x02, /*!< CRYP internal processing is ongoing */
  57. HAL_CRYP_STATE_TIMEOUT = 0x03, /*!< CRYP timeout state */
  58. HAL_CRYP_STATE_ERROR = 0x04 /*!< CRYP error state */
  59. }HAL_CRYP_STATETypeDef;
  60. /**
  61. * @brief HAL CRYP phase structures definition
  62. */
  63. typedef enum
  64. {
  65. HAL_CRYP_PHASE_READY = 0x01, /*!< CRYP peripheral is ready for initialization. */
  66. HAL_CRYP_PHASE_PROCESS = 0x02, /*!< CRYP peripheral is in processing phase */
  67. }HAL_PhaseTypeDef;
  68. /**
  69. * @brief CRYP handle Structure definition
  70. */
  71. typedef struct
  72. {
  73. AES_TypeDef *Instance; /*!< Register base address */
  74. CRYP_InitTypeDef Init; /*!< CRYP required parameters */
  75. uint8_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
  76. uint8_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
  77. __IO uint16_t CrypInCount; /*!< Counter of inputed data */
  78. __IO uint16_t CrypOutCount; /*!< Counter of outputed data */
  79. HAL_StatusTypeDef Status; /*!< CRYP peripheral status */
  80. HAL_PhaseTypeDef Phase; /*!< CRYP peripheral phase */
  81. DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */
  82. DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */
  83. HAL_LockTypeDef Lock; /*!< CRYP locking object */
  84. __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */
  85. }CRYP_HandleTypeDef;
  86. /**
  87. * @}
  88. */
  89. /* Exported constants --------------------------------------------------------*/
  90. /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
  91. * @{
  92. */
  93. /** @defgroup CRYP_Data_Type CRYP Data Type
  94. * @{
  95. */
  96. #define CRYP_DATATYPE_32B (0x00000000U)
  97. #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0
  98. #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1
  99. #define CRYP_DATATYPE_1B AES_CR_DATATYPE
  100. #define IS_CRYP_DATATYPE(DATATYPE) (((DATATYPE) == CRYP_DATATYPE_32B) || \
  101. ((DATATYPE) == CRYP_DATATYPE_16B) || \
  102. ((DATATYPE) == CRYP_DATATYPE_8B) || \
  103. ((DATATYPE) == CRYP_DATATYPE_1B))
  104. /**
  105. * @}
  106. */
  107. /** @defgroup CRYP_AlgoModeDirection CRYP Algo Mode Direction
  108. * @{
  109. */
  110. #define CRYP_CR_ALGOMODE_DIRECTION (uint32_t)(AES_CR_MODE|AES_CR_CHMOD)
  111. #define CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT (0x00000000U)
  112. #define CRYP_CR_ALGOMODE_AES_ECB_KEYDERDECRYPT (AES_CR_MODE)
  113. #define CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT (AES_CR_CHMOD_0)
  114. #define CRYP_CR_ALGOMODE_AES_CBC_KEYDERDECRYPT ((uint32_t)(AES_CR_CHMOD_0|AES_CR_MODE))
  115. #define CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT (AES_CR_CHMOD_1)
  116. #define CRYP_CR_ALGOMODE_AES_CTR_DECRYPT ((uint32_t)(AES_CR_CHMOD_1 | AES_CR_MODE_1))
  117. /**
  118. * @}
  119. */
  120. /** @defgroup CRYP_AES_Interrupts AES Interrupts
  121. * @{
  122. */
  123. #define CRYP_IT_CC AES_CR_CCIE /*!< Computation Complete interrupt */
  124. #define CRYP_IT_ERR AES_CR_ERRIE /*!< Error interrupt */
  125. /**
  126. * @}
  127. */
  128. /** @defgroup CRYP_AES_Flags AES Flags
  129. * @{
  130. */
  131. #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation Complete Flag */
  132. #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read Error Flag */
  133. #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error Flag */
  134. /**
  135. * @}
  136. */
  137. /** @defgroup CRYP_AES_Clear_Flags AES Clear Flags
  138. * @{
  139. */
  140. #define CRYP_CLEARFLAG_CCF AES_CR_CCFC /*!< Computation Complete Flag Clear */
  141. #define CRYP_CLEARFLAG_RDERR AES_CR_ERRC /*!< Read Error Clear */
  142. #define CRYP_CLEARFLAG_WRERR AES_CR_ERRC /*!< Write Error Clear */
  143. /**
  144. * @}
  145. */
  146. /**
  147. * @}
  148. */
  149. /* Exported macro ------------------------------------------------------------*/
  150. /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
  151. * @{
  152. */
  153. /** @brief Reset CRYP handle state
  154. * @param __HANDLE__ specifies the CRYP handle.
  155. * @retval None
  156. */
  157. #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
  158. /**
  159. * @brief Enable/Disable the CRYP peripheral.
  160. * @param __HANDLE__ specifies the CRYP handle.
  161. * @retval None
  162. */
  163. #define __HAL_CRYP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR, AES_CR_EN)
  164. #define __HAL_CRYP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR, AES_CR_EN)
  165. /**
  166. * @brief Set the algorithm mode: AES-ECB, AES-CBC, AES-CTR, DES-ECB, DES-CBC,...
  167. * @param __HANDLE__ specifies the CRYP handle.
  168. * @param __MODE__ The algorithm mode.
  169. * @retval None
  170. */
  171. #define __HAL_CRYP_SET_MODE(__HANDLE__,__MODE__) SET_BIT((__HANDLE__)->Instance->CR, (__MODE__))
  172. /** @brief Check whether the specified CRYP flag is set or not.
  173. * @param __HANDLE__ specifies the CRYP handle.
  174. * @param __FLAG__ specifies the flag to check.
  175. * This parameter can be one of the following values:
  176. * @arg CRYP_FLAG_CCF : Computation Complete Flag
  177. * @arg CRYP_FLAG_RDERR : Read Error Flag
  178. * @arg CRYP_FLAG_WRERR : Write Error Flag
  179. * @retval The new state of __FLAG__ (TRUE or FALSE).
  180. */
  181. #define __HAL_CRYP_GET_FLAG(__HANDLE__,__FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  182. /** @brief Clear the CRYP pending flag.
  183. * @param __HANDLE__ specifies the CRYP handle.
  184. * @param __FLAG__ specifies the flag to clear.
  185. * This parameter can be one of the following values:
  186. * @arg CRYP_CLEARFLAG_CCF : Computation Complete Clear Flag
  187. * @arg CRYP_CLEARFLAG_RDERR : Read Error Clear
  188. * @arg CRYP_CLEARFLAG_WRERR : Write Error Clear
  189. * @retval None
  190. */
  191. #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__))
  192. /**
  193. * @brief Enable the CRYP interrupt.
  194. * @param __HANDLE__ specifies the CRYP handle.
  195. * @param __INTERRUPT__ CRYP Interrupt.
  196. * @retval None
  197. */
  198. #define __HAL_CRYP_ENABLE_IT(__HANDLE__,__INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__))
  199. /**
  200. * @brief Disable the CRYP interrupt.
  201. * @param __HANDLE__ specifies the CRYP handle.
  202. * @param __INTERRUPT__ CRYP interrupt.
  203. * @retval None
  204. */
  205. #define __HAL_CRYP_DISABLE_IT(__HANDLE__,__INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__))
  206. /** @brief Checks if the specified CRYP interrupt source is enabled or disabled.
  207. * @param __HANDLE__ specifies the CRYP handle.
  208. * @param __INTERRUPT__: CRYP interrupt source to check
  209. * This parameter can be one of the following values:
  210. * @arg CRYP_IT_CC : Computation Complete interrupt
  211. * @arg CRYP_IT_ERR : Error interrupt (used for RDERR and WRERR)
  212. * @retval State of interruption (SET or RESET)
  213. */
  214. #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
  215. (( ((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__) \
  216. )? SET : RESET \
  217. )
  218. /** @brief Clear the CRYP pending IT.
  219. * @param __HANDLE__ specifies the CRYP handle.
  220. * @param __IT__ specifies the IT to clear.
  221. * This parameter can be one of the following values:
  222. * @arg CRYP_CLEARFLAG_CCF : Computation Complete Clear Flag
  223. * @arg CRYP_CLEARFLAG_RDERR : Read Error Clear
  224. * @arg CRYP_CLEARFLAG_WRERR : Write Error Clear
  225. * @retval None
  226. */
  227. #define __HAL_CRYP_CLEAR_IT(__HANDLE__, __IT__) SET_BIT((__HANDLE__)->Instance->CR, (__IT__))
  228. /**
  229. * @}
  230. */
  231. /* Include CRYP HAL Extension module */
  232. #include "stm32l1xx_hal_cryp_ex.h"
  233. /* Exported functions --------------------------------------------------------*/
  234. /** @addtogroup CRYP_Exported_Functions
  235. * @{
  236. */
  237. /** @addtogroup CRYP_Exported_Functions_Group1
  238. * @{
  239. */
  240. /* Initialization/de-initialization functions *********************************/
  241. HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
  242. HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
  243. /* MSP functions *************************************************************/
  244. void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
  245. void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
  246. /**
  247. * @}
  248. */
  249. /** @addtogroup CRYP_Exported_Functions_Group2
  250. * @{
  251. */
  252. /* AES encryption/decryption using polling ***********************************/
  253. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  254. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  255. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  256. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  257. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  258. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  259. /* AES encryption/decryption using interrupt *********************************/
  260. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  261. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  262. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  263. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  264. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  265. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  266. /* AES encryption/decryption using DMA ***************************************/
  267. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  268. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  269. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  270. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  271. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  272. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  273. /**
  274. * @}
  275. */
  276. /** @addtogroup CRYP_Exported_Functions_Group3
  277. * @{
  278. */
  279. /* CallBack functions ********************************************************/
  280. void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
  281. void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
  282. void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
  283. /**
  284. * @}
  285. */
  286. /** @addtogroup CRYP_Exported_Functions_Group4
  287. * @{
  288. */
  289. /* Processing functions ********************************************************/
  290. void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
  291. /**
  292. * @}
  293. */
  294. /** @addtogroup CRYP_Exported_Functions_Group5
  295. * @{
  296. */
  297. /* Peripheral State functions **************************************************/
  298. HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
  299. /**
  300. * @}
  301. */
  302. /**
  303. * @}
  304. */
  305. /**
  306. * @}
  307. */
  308. /**
  309. * @}
  310. */
  311. #endif /* STM32L162xC || STM32L162xCA || STM32L162xD || STM32L162xE || STM32L162xDX*/
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. #endif /* __STM32L1xx_HAL_CRYP_H */
  316. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/