stm32g0xx_hal_cryp.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_hal_cryp.h
  4. * @author MCD Application Team
  5. * @brief Header file of CRYP HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32G0xx_HAL_CRYP_H
  20. #define STM32G0xx_HAL_CRYP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g0xx_hal_def.h"
  26. /** @addtogroup STM32G0xx_HAL_Driver
  27. * @{
  28. */
  29. #if defined(AES)
  30. /** @defgroup CRYP CRYP
  31. * @brief CRYP HAL module driver.
  32. * @{
  33. */
  34. /* Exported types ------------------------------------------------------------*/
  35. /** @defgroup CRYP_Exported_Types CRYP Exported Types
  36. * @{
  37. */
  38. /**
  39. * @brief CRYP Init 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. uint32_t KeySize; /*!< Used only in AES mode : 128, 192 or 256 bit key length in CRYP1.
  46. 128 or 256 bit key length in TinyAES
  47. This parameter can be a value of @ref CRYP_Key_Size */
  48. uint32_t *pKey; /*!< The key used for encryption/decryption */
  49. uint32_t *pInitVect; /*!< The initialization vector used also as initialization
  50. counter in CTR mode */
  51. uint32_t Algorithm; /*!< DES/ TDES Algorithm ECB/CBC
  52. AES Algorithm ECB/CBC/CTR/GCM or CCM
  53. This parameter can be a value of @ref CRYP_Algorithm_Mode */
  54. uint32_t *Header; /*!< used only in AES GCM and CCM Algorithm for authentication,
  55. GCM : also known as Additional Authentication Data
  56. CCM : named B1 composed of the associated data length and Associated Data. */
  57. uint32_t HeaderSize; /*!< The size of header buffer */
  58. uint32_t *B0; /*!< B0 is first authentication block used only in AES CCM mode */
  59. uint32_t DataWidthUnit; /*!< Payload Data Width Unit, this parameter can be value of @ref CRYP_Data_Width_Unit*/
  60. uint32_t HeaderWidthUnit; /*!< Header Width Unit, this parameter can be value of @ref CRYP_Header_Width_Unit*/
  61. uint32_t KeyIVConfigSkip; /*!< CRYP peripheral Key and IV configuration skip, to config Key and Initialization
  62. Vector only once and to skip configuration for consecutive processings.
  63. This parameter can be a value of @ref CRYP_Configuration_Skip */
  64. } CRYP_ConfigTypeDef;
  65. /**
  66. * @brief CRYP State Structure definition
  67. */
  68. typedef enum
  69. {
  70. HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */
  71. HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */
  72. HAL_CRYP_STATE_BUSY = 0x02U, /*!< CRYP BUSY, internal processing is ongoing */
  73. #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
  74. HAL_CRYP_STATE_SUSPENDED = 0x03U, /*!< CRYP suspended */
  75. #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
  76. } HAL_CRYP_STATETypeDef;
  77. #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
  78. /**
  79. * @brief HAL CRYP mode suspend definitions
  80. */
  81. typedef enum
  82. {
  83. HAL_CRYP_SUSPEND_NONE = 0x00U, /*!< CRYP processing suspension not requested */
  84. HAL_CRYP_SUSPEND = 0x01U /*!< CRYP processing suspension requested */
  85. } HAL_SuspendTypeDef;
  86. #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
  87. /**
  88. * @brief CRYP handle Structure definition
  89. */
  90. #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
  91. typedef struct __CRYP_HandleTypeDef
  92. #else
  93. typedef struct
  94. #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
  95. {
  96. AES_TypeDef *Instance; /*!< AES Register base address */
  97. CRYP_ConfigTypeDef Init; /*!< CRYP required parameters */
  98. FunctionalState AutoKeyDerivation; /*!< Used only in TinyAES to allow to bypass or not key write-up before decryption.
  99. This parameter can be a value of ENABLE/DISABLE */
  100. uint32_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
  101. uint32_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
  102. __IO uint16_t CrypHeaderCount; /*!< Counter of header data in words */
  103. __IO uint16_t CrypInCount; /*!< Counter of input data in words */
  104. __IO uint16_t CrypOutCount; /*!< Counter of output data in words */
  105. uint16_t Size; /*!< Length of input data */
  106. uint32_t Phase; /*!< CRYP peripheral phase */
  107. DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */
  108. DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */
  109. HAL_LockTypeDef Lock; /*!< CRYP locking object */
  110. __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */
  111. __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */
  112. uint32_t KeyIVConfig; /*!< CRYP peripheral Key and IV configuration flag, used when
  113. configuration can be skipped */
  114. uint32_t SizesSum; /*!< Sum of successive payloads lengths (in bytes), stored
  115. for a single signature computation after several
  116. messages processing */
  117. #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
  118. void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Input FIFO transfer completed callback */
  119. void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Output FIFO transfer completed callback */
  120. void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Error callback */
  121. void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp Init callback */
  122. void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp DeInit callback */
  123. #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */
  124. #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
  125. __IO HAL_SuspendTypeDef SuspendRequest; /*!< CRYP peripheral suspension request flag */
  126. CRYP_ConfigTypeDef Init_saved; /*!< copy of CRYP required parameters when processing is suspended */
  127. uint32_t *pCrypInBuffPtr_saved; /*!< copy of CRYP input pointer when processing is suspended */
  128. uint32_t *pCrypOutBuffPtr_saved; /*!< copy of CRYP output pointer when processing is suspended */
  129. uint32_t CrypInCount_saved; /*!< copy of CRYP input data counter when processing is suspended */
  130. uint32_t CrypOutCount_saved; /*!< copy of CRYP output data counter when processing is suspended */
  131. uint32_t Phase_saved; /*!< copy of CRYP authentication phase when processing is suspended */
  132. __IO HAL_CRYP_STATETypeDef State_saved; /*!< copy of CRYP peripheral state when processing is suspended */
  133. uint32_t IV_saved[4]; /*!< copy of Initialisation Vector registers */
  134. uint32_t SUSPxR_saved[8]; /*!< copy of suspension registers */
  135. uint32_t CR_saved; /*!< copy of CRYP control register when processing is suspended*/
  136. uint32_t Key_saved[8]; /*!< copy of key registers */
  137. uint16_t Size_saved; /*!< copy of input buffer size */
  138. uint16_t CrypHeaderCount_saved; /*!< copy of CRYP header data counter when processing is suspended */
  139. uint32_t SizesSum_saved; /*!< copy of SizesSum when processing is suspended */
  140. uint32_t ResumingFlag; /*!< resumption flag to bypass steps already carried out */
  141. FunctionalState AutoKeyDerivation_saved; /*!< copy of CRYP handle auto key derivation parameter */
  142. #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
  143. } CRYP_HandleTypeDef;
  144. #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
  145. /** @defgroup HAL_CRYP_Callback_ID_enumeration_definition HAL CRYP Callback ID enumeration definition
  146. * @brief HAL CRYP Callback ID enumeration definition
  147. * @{
  148. */
  149. typedef enum
  150. {
  151. HAL_CRYP_MSPINIT_CB_ID = 0x00U, /*!< CRYP MspInit callback ID */
  152. HAL_CRYP_MSPDEINIT_CB_ID = 0x01U, /*!< CRYP MspDeInit callback ID */
  153. HAL_CRYP_INPUT_COMPLETE_CB_ID = 0x02U, /*!< CRYP Input FIFO transfer completed callback ID */
  154. HAL_CRYP_OUTPUT_COMPLETE_CB_ID = 0x03U, /*!< CRYP Output FIFO transfer completed callback ID */
  155. HAL_CRYP_ERROR_CB_ID = 0x04U, /*!< CRYP Error callback ID */
  156. } HAL_CRYP_CallbackIDTypeDef;
  157. /**
  158. * @}
  159. */
  160. /** @defgroup HAL_CRYP_Callback_pointer_definition HAL CRYP Callback pointer definition
  161. * @brief HAL CRYP Callback pointer definition
  162. * @{
  163. */
  164. typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp); /*!< pointer to a common CRYP callback function */
  165. /**
  166. * @}
  167. */
  168. #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
  169. /**
  170. * @}
  171. */
  172. /* Exported constants --------------------------------------------------------*/
  173. /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
  174. * @{
  175. */
  176. /** @defgroup CRYP_Error_Definition CRYP Error Definition
  177. * @{
  178. */
  179. #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */
  180. #define HAL_CRYP_ERROR_WRITE 0x00000001U /*!< Write error */
  181. #define HAL_CRYP_ERROR_READ 0x00000002U /*!< Read error */
  182. #define HAL_CRYP_ERROR_DMA 0x00000004U /*!< DMA error */
  183. #define HAL_CRYP_ERROR_BUSY 0x00000008U /*!< Busy flag error */
  184. #define HAL_CRYP_ERROR_TIMEOUT 0x00000010U /*!< Timeout error */
  185. #define HAL_CRYP_ERROR_NOT_SUPPORTED 0x00000020U /*!< Not supported mode */
  186. #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U /*!< Sequence are not respected only for GCM or CCM */
  187. #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
  188. #define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U) /*!< Invalid Callback error */
  189. #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
  190. /**
  191. * @}
  192. */
  193. /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit
  194. * @{
  195. */
  196. #define CRYP_DATAWIDTHUNIT_WORD 0x00000000U /*!< By default, size unit is word */
  197. #define CRYP_DATAWIDTHUNIT_BYTE 0x00000001U /*!< By default, size unit is byte */
  198. /**
  199. * @}
  200. */
  201. /** @defgroup CRYP_Header_Width_Unit CRYP Header Width Unit
  202. * @{
  203. */
  204. #define CRYP_HEADERWIDTHUNIT_WORD 0x00000000U /*!< By default, header size unit is word */
  205. #define CRYP_HEADERWIDTHUNIT_BYTE 0x00000001U /*!< By default, header size unit is byte */
  206. /**
  207. * @}
  208. */
  209. /** @defgroup CRYP_Algorithm_Mode CRYP Algorithm Mode
  210. * @{
  211. */
  212. #define CRYP_AES_ECB 0x00000000U /*!< Electronic codebook chaining algorithm */
  213. #define CRYP_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */
  214. #define CRYP_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */
  215. #define CRYP_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */
  216. #define CRYP_AES_CCM AES_CR_CHMOD_2 /*!< Counter with Cipher Mode */
  217. /**
  218. * @}
  219. */
  220. /** @defgroup CRYP_Key_Size CRYP Key Size
  221. * @{
  222. */
  223. #define CRYP_KEYSIZE_128B 0x00000000U /*!< 128-bit long key */
  224. #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */
  225. /**
  226. * @}
  227. */
  228. /** @defgroup CRYP_Data_Type CRYP Data Type
  229. * @{
  230. */
  231. #define CRYP_DATATYPE_32B 0x00000000U /*!< 32-bit data type (no swapping) */
  232. #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */
  233. #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */
  234. #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */
  235. /**
  236. * @}
  237. */
  238. /** @defgroup CRYP_Interrupt CRYP Interrupt
  239. * @{
  240. */
  241. #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */
  242. #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */
  243. #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */
  244. #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */
  245. #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */
  246. /**
  247. * @}
  248. */
  249. /** @defgroup CRYP_Flags CRYP Flags
  250. * @{
  251. */
  252. /* status flags */
  253. #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */
  254. #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */
  255. #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */
  256. #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */
  257. /* clearing flags */
  258. #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */
  259. #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */
  260. /**
  261. * @}
  262. */
  263. /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode
  264. * @{
  265. */
  266. #define CRYP_KEYIVCONFIG_ALWAYS 0x00000000U /*!< Peripheral Key and IV configuration to do systematically */
  267. #define CRYP_KEYIVCONFIG_ONCE 0x00000001U /*!< Peripheral Key and IV configuration to do only once */
  268. /**
  269. * @}
  270. */
  271. /**
  272. * @}
  273. */
  274. /* Exported macros -----------------------------------------------------------*/
  275. /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
  276. * @{
  277. */
  278. /** @brief Reset CRYP handle state
  279. * @param __HANDLE__ specifies the CRYP handle.
  280. * @retval None
  281. */
  282. #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
  283. #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\
  284. (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\
  285. (__HANDLE__)->MspInitCallback = NULL;\
  286. (__HANDLE__)->MspDeInitCallback = NULL;\
  287. }while(0U)
  288. #else
  289. #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET)
  290. #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
  291. /**
  292. * @brief Enable/Disable the CRYP peripheral.
  293. * @param __HANDLE__ specifies the CRYP handle.
  294. * @retval None
  295. */
  296. #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= AES_CR_EN)
  297. #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~AES_CR_EN)
  298. /** @brief Check whether the specified CRYP status flag is set or not.
  299. * @param __HANDLE__ specifies the CRYP handle.
  300. * @param __FLAG__ specifies the flag to check.
  301. * This parameter can be one of the following values for TinyAES:
  302. * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden
  303. * @arg @ref CRYP_IT_WRERR Write Error
  304. * @arg @ref CRYP_IT_RDERR Read Error
  305. * @arg @ref CRYP_IT_CCF Computation Complete
  306. * This parameter can be one of the following values for CRYP:
  307. * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data
  308. * or a key preparation (for AES decryption).
  309. * @arg CRYP_FLAG_IFEM: Input FIFO is empty
  310. * @arg CRYP_FLAG_IFNF: Input FIFO is not full
  311. * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending
  312. * @arg CRYP_FLAG_OFNE: Output FIFO is not empty
  313. * @arg CRYP_FLAG_OFFU: Output FIFO is full
  314. * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending
  315. * @retval The state of __FLAG__ (TRUE or FALSE).
  316. */
  317. #define CRYP_FLAG_MASK 0x0000001FU
  318. #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  319. /** @brief Clear the CRYP pending status flag.
  320. * @param __HANDLE__ specifies the CRYP handle.
  321. * @param __FLAG__ specifies the flag to clear.
  322. * This parameter can be one of the following values:
  323. * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
  324. * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
  325. * @retval None
  326. */
  327. #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__))
  328. /** @brief Check whether the specified CRYP interrupt source is enabled or not.
  329. * @param __HANDLE__ specifies the CRYP handle.
  330. * @param __INTERRUPT__ CRYP interrupt source to check
  331. * This parameter can be one of the following values for TinyAES:
  332. * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
  333. * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
  334. * @retval State of interruption (TRUE or FALSE).
  335. */
  336. #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR &\
  337. (__INTERRUPT__)) == (__INTERRUPT__))
  338. /** @brief Check whether the specified CRYP interrupt is set or not.
  339. * @param __HANDLE__ specifies the CRYP handle.
  340. * @param __INTERRUPT__ specifies the interrupt to check.
  341. * This parameter can be one of the following values for TinyAES:
  342. * @arg @ref CRYP_IT_WRERR Write Error
  343. * @arg @ref CRYP_IT_RDERR Read Error
  344. * @arg @ref CRYP_IT_CCF Computation Complete
  345. * This parameter can be one of the following values for CRYP:
  346. * @arg CRYP_IT_INI: Input FIFO service masked interrupt status
  347. * @arg CRYP_IT_OUTI: Output FIFO service masked interrupt status
  348. * @retval The state of __INTERRUPT__ (TRUE or FALSE).
  349. */
  350. #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
  351. /**
  352. * @brief Enable the CRYP interrupt.
  353. * @param __HANDLE__ specifies the CRYP handle.
  354. * @param __INTERRUPT__ CRYP Interrupt.
  355. * This parameter can be one of the following values for TinyAES:
  356. * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
  357. * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
  358. * This parameter can be one of the following values for CRYP:
  359. * @ CRYP_IT_INI : Input FIFO service interrupt mask.
  360. * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt.
  361. * @retval None
  362. */
  363. #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
  364. /**
  365. * @brief Disable the CRYP interrupt.
  366. * @param __HANDLE__ specifies the CRYP handle.
  367. * @param __INTERRUPT__ CRYP Interrupt.
  368. * This parameter can be one of the following values for TinyAES:
  369. * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
  370. * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
  371. * This parameter can be one of the following values for CRYP:
  372. * @ CRYP_IT_INI : Input FIFO service interrupt mask.
  373. * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt.
  374. * @retval None
  375. */
  376. #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
  377. /**
  378. * @}
  379. */
  380. /* Include CRYP HAL Extended module */
  381. #include "stm32g0xx_hal_cryp_ex.h"
  382. /* Exported functions --------------------------------------------------------*/
  383. /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
  384. * @{
  385. */
  386. /** @addtogroup CRYP_Exported_Functions_Group1
  387. * @{
  388. */
  389. HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
  390. HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
  391. void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
  392. void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
  393. HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
  394. HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
  395. #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
  396. HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID,
  397. pCRYP_CallbackTypeDef pCallback);
  398. HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID);
  399. #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
  400. #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
  401. void HAL_CRYP_ProcessSuspend(CRYP_HandleTypeDef *hcryp);
  402. HAL_StatusTypeDef HAL_CRYP_Suspend(CRYP_HandleTypeDef *hcryp);
  403. HAL_StatusTypeDef HAL_CRYP_Resume(CRYP_HandleTypeDef *hcryp);
  404. #endif /* defined (USE_HAL_CRYP_SUSPEND_RESUME) */
  405. /**
  406. * @}
  407. */
  408. /** @addtogroup CRYP_Exported_Functions_Group2
  409. * @{
  410. */
  411. /* encryption/decryption ***********************************/
  412. HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output,
  413. uint32_t Timeout);
  414. HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output,
  415. uint32_t Timeout);
  416. HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
  417. HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
  418. HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
  419. HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
  420. /**
  421. * @}
  422. */
  423. /** @addtogroup CRYP_Exported_Functions_Group3
  424. * @{
  425. */
  426. /* Interrupt Handler functions **********************************************/
  427. void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
  428. HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
  429. void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
  430. void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
  431. void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
  432. uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp);
  433. /**
  434. * @}
  435. */
  436. /**
  437. * @}
  438. */
  439. /* Private macros --------------------------------------------------------*/
  440. /** @defgroup CRYP_Private_Macros CRYP Private Macros
  441. * @{
  442. */
  443. /** @defgroup CRYP_IS_CRYP_Definitions CRYP Private macros to check input parameters
  444. * @{
  445. */
  446. #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \
  447. ((ALGORITHM) == CRYP_AES_CBC) || \
  448. ((ALGORITHM) == CRYP_AES_CTR) || \
  449. ((ALGORITHM) == CRYP_AES_GCM_GMAC)|| \
  450. ((ALGORITHM) == CRYP_AES_CCM))
  451. #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \
  452. ((KEYSIZE) == CRYP_KEYSIZE_256B))
  453. #define IS_CRYP_DATATYPE(DATATYPE)(((DATATYPE) == CRYP_DATATYPE_32B) || \
  454. ((DATATYPE) == CRYP_DATATYPE_16B) || \
  455. ((DATATYPE) == CRYP_DATATYPE_8B) || \
  456. ((DATATYPE) == CRYP_DATATYPE_1B))
  457. #define IS_CRYP_INIT(CONFIG)(((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \
  458. ((CONFIG) == CRYP_KEYIVCONFIG_ONCE))
  459. #define IS_CRYP_BUFFERSIZE(ALGO, DATAWIDTH, SIZE) \
  460. (((((ALGO) == CRYP_AES_CTR)) && \
  461. ((((DATAWIDTH) == CRYP_DATAWIDTHUNIT_WORD) && (((SIZE) % 4U) == 0U)) || \
  462. (((DATAWIDTH) == CRYP_DATAWIDTHUNIT_BYTE) && (((SIZE) % 16U) == 0U)))) || \
  463. (((ALGO) == CRYP_AES_ECB) || ((ALGO) == CRYP_AES_CBC) || \
  464. ((ALGO)== CRYP_AES_GCM_GMAC) || ((ALGO) == CRYP_AES_CCM)))
  465. /**
  466. * @}
  467. */
  468. /**
  469. * @}
  470. */
  471. /* Private constants ---------------------------------------------------------*/
  472. /** @defgroup CRYP_Private_Constants CRYP Private Constants
  473. * @{
  474. */
  475. /**
  476. * @}
  477. */
  478. /* Private defines -----------------------------------------------------------*/
  479. /** @defgroup CRYP_Private_Defines CRYP Private Defines
  480. * @{
  481. */
  482. /**
  483. * @}
  484. */
  485. /* Private variables ---------------------------------------------------------*/
  486. /** @defgroup CRYP_Private_Variables CRYP Private Variables
  487. * @{
  488. */
  489. /**
  490. * @}
  491. */
  492. /* Private functions ---------------------------------------------------------*/
  493. /** @defgroup CRYP_Private_Functions CRYP Private Functions
  494. * @{
  495. */
  496. /**
  497. * @}
  498. */
  499. /**
  500. * @}
  501. */
  502. #endif /* AES */
  503. /**
  504. * @}
  505. */
  506. #ifdef __cplusplus
  507. }
  508. #endif
  509. #endif /* STM32G0xx_HAL_CRYP_H */