训练营PLSR题目
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

684 рядки
27 KiB

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