stm32f4xx_hal_cryp.h 27 KB

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