stm32f7xx_hal_cryp.h 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_cryp.h
  4. * @author MCD Application Team
  5. * @version V1.2.0
  6. * @date 30-December-2016
  7. * @brief Header file of CRYP HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_CRYP_H
  39. #define __STM32F7xx_HAL_CRYP_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. #if defined (CRYP)
  46. /** @addtogroup STM32F7xx_HAL_Driver
  47. * @{
  48. */
  49. /** @addtogroup CRYP
  50. * @{
  51. */
  52. /* Exported types ------------------------------------------------------------*/
  53. /** @defgroup CRYP_Exported_Types CRYP Exported Types
  54. * @{
  55. */
  56. /** @defgroup CRYP_Exported_Types_Group1 CRYP Configuration Structure definition
  57. * @{
  58. */
  59. typedef struct
  60. {
  61. uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
  62. This parameter can be a value of @ref CRYP_Data_Type */
  63. uint32_t KeySize; /*!< Used only in AES mode only : 128, 192 or 256 bit key length.
  64. This parameter can be a value of @ref CRYP_Key_Size */
  65. uint8_t* pKey; /*!< The key used for encryption/decryption */
  66. uint8_t* pInitVect; /*!< The initialization vector used also as initialization
  67. counter in CTR mode */
  68. uint8_t IVSize; /*!< The size of initialization vector.
  69. This parameter (called nonce size in CCM) is used only
  70. in AES-128/192/256 encryption/decryption CCM mode */
  71. uint8_t TagSize; /*!< The size of returned authentication TAG.
  72. This parameter is used only in AES-128/192/256
  73. encryption/decryption CCM mode */
  74. uint8_t* Header; /*!< The header used in GCM and CCM modes */
  75. uint32_t HeaderSize; /*!< The size of header buffer in bytes */
  76. uint8_t* pScratch; /*!< Scratch buffer used to append the header. It's size must be equal to header size + 21 bytes.
  77. This parameter is used only in AES-128/192/256 encryption/decryption CCM mode */
  78. }CRYP_InitTypeDef;
  79. /**
  80. * @}
  81. */
  82. /** @defgroup CRYP_Exported_Types_Group2 CRYP State structures definition
  83. * @{
  84. */
  85. typedef enum
  86. {
  87. HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */
  88. HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */
  89. HAL_CRYP_STATE_BUSY = 0x02U, /*!< CRYP internal processing is ongoing */
  90. HAL_CRYP_STATE_TIMEOUT = 0x03U, /*!< CRYP timeout state */
  91. HAL_CRYP_STATE_ERROR = 0x04U /*!< CRYP error state */
  92. }HAL_CRYP_STATETypeDef;
  93. /**
  94. * @}
  95. */
  96. /** @defgroup CRYP_Exported_Types_Group3 CRYP phase structures definition
  97. * @{
  98. */
  99. typedef enum
  100. {
  101. HAL_CRYP_PHASE_READY = 0x01U, /*!< CRYP peripheral is ready for initialization. */
  102. HAL_CRYP_PHASE_PROCESS = 0x02U, /*!< CRYP peripheral is in processing phase */
  103. HAL_CRYP_PHASE_FINAL = 0x03U /*!< CRYP peripheral is in final phase
  104. This is relevant only with CCM and GCM modes */
  105. }HAL_PhaseTypeDef;
  106. /**
  107. * @}
  108. */
  109. /** @defgroup CRYP_Exported_Types_Group4 CRYP handle Structure definition
  110. * @{
  111. */
  112. typedef struct
  113. {
  114. CRYP_TypeDef *Instance; /*!< CRYP registers base address */
  115. CRYP_InitTypeDef Init; /*!< CRYP required parameters */
  116. uint8_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
  117. uint8_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
  118. __IO uint16_t CrypInCount; /*!< Counter of input data */
  119. __IO uint16_t CrypOutCount; /*!< Counter of output data */
  120. HAL_StatusTypeDef Status; /*!< CRYP peripheral status */
  121. HAL_PhaseTypeDef Phase; /*!< CRYP peripheral phase */
  122. DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */
  123. DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */
  124. HAL_LockTypeDef Lock; /*!< CRYP locking object */
  125. __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */
  126. }CRYP_HandleTypeDef;
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. /* Exported constants --------------------------------------------------------*/
  134. /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
  135. * @{
  136. */
  137. /** @defgroup CRYP_Key_Size CRYP Key Size
  138. * @{
  139. */
  140. #define CRYP_KEYSIZE_128B ((uint32_t)0x00000000U)
  141. #define CRYP_KEYSIZE_192B CRYP_CR_KEYSIZE_0
  142. #define CRYP_KEYSIZE_256B CRYP_CR_KEYSIZE_1
  143. /**
  144. * @}
  145. */
  146. /** @defgroup CRYP_Data_Type CRYP Data Type
  147. * @{
  148. */
  149. #define CRYP_DATATYPE_32B ((uint32_t)0x00000000U)
  150. #define CRYP_DATATYPE_16B CRYP_CR_DATATYPE_0
  151. #define CRYP_DATATYPE_8B CRYP_CR_DATATYPE_1
  152. #define CRYP_DATATYPE_1B CRYP_CR_DATATYPE
  153. /**
  154. * @}
  155. */
  156. /** @defgroup CRYP_Exported_Constants_Group3 CRYP CRYP_AlgoModeDirection
  157. * @{
  158. */
  159. #define CRYP_CR_ALGOMODE_DIRECTION ((uint32_t)0x0008003CU)
  160. #define CRYP_CR_ALGOMODE_TDES_ECB_ENCRYPT ((uint32_t)0x00000000U)
  161. #define CRYP_CR_ALGOMODE_TDES_ECB_DECRYPT ((uint32_t)0x00000004U)
  162. #define CRYP_CR_ALGOMODE_TDES_CBC_ENCRYPT ((uint32_t)0x00000008U)
  163. #define CRYP_CR_ALGOMODE_TDES_CBC_DECRYPT ((uint32_t)0x0000000CU)
  164. #define CRYP_CR_ALGOMODE_DES_ECB_ENCRYPT ((uint32_t)0x00000010U)
  165. #define CRYP_CR_ALGOMODE_DES_ECB_DECRYPT ((uint32_t)0x00000014U)
  166. #define CRYP_CR_ALGOMODE_DES_CBC_ENCRYPT ((uint32_t)0x00000018U)
  167. #define CRYP_CR_ALGOMODE_DES_CBC_DECRYPT ((uint32_t)0x0000001CU)
  168. #define CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT ((uint32_t)0x00000020U)
  169. #define CRYP_CR_ALGOMODE_AES_ECB_DECRYPT ((uint32_t)0x00000024U)
  170. #define CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT ((uint32_t)0x00000028U)
  171. #define CRYP_CR_ALGOMODE_AES_CBC_DECRYPT ((uint32_t)0x0000002CU)
  172. #define CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT ((uint32_t)0x00000030U)
  173. #define CRYP_CR_ALGOMODE_AES_CTR_DECRYPT ((uint32_t)0x00000034U)
  174. /**
  175. * @}
  176. */
  177. /** @defgroup CRYP_Exported_Constants_Group4 CRYP CRYP_Interrupt
  178. * @{
  179. */
  180. #define CRYP_IT_INI ((uint32_t)CRYP_IMSCR_INIM) /*!< Input FIFO Interrupt */
  181. #define CRYP_IT_OUTI ((uint32_t)CRYP_IMSCR_OUTIM) /*!< Output FIFO Interrupt */
  182. /**
  183. * @}
  184. */
  185. /** @defgroup CRYP_Exported_Constants_Group5 CRYP CRYP_Flags
  186. * @{
  187. */
  188. #define CRYP_FLAG_BUSY ((uint32_t)0x00000010U) /*!< The CRYP core is currently
  189. processing a block of data
  190. or a key preparation (for
  191. AES decryption). */
  192. #define CRYP_FLAG_IFEM ((uint32_t)0x00000001U) /*!< Input FIFO is empty */
  193. #define CRYP_FLAG_IFNF ((uint32_t)0x00000002U) /*!< Input FIFO is not Full */
  194. #define CRYP_FLAG_OFNE ((uint32_t)0x00000004U) /*!< Output FIFO is not empty */
  195. #define CRYP_FLAG_OFFU ((uint32_t)0x00000008U) /*!< Output FIFO is Full */
  196. #define CRYP_FLAG_OUTRIS ((uint32_t)0x01000002U) /*!< Output FIFO service raw
  197. interrupt status */
  198. #define CRYP_FLAG_INRIS ((uint32_t)0x01000001U) /*!< Input FIFO service raw
  199. interrupt status */
  200. /**
  201. * @}
  202. */
  203. /**
  204. * @}
  205. */
  206. /* Exported macro ------------------------------------------------------------*/
  207. /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
  208. * @{
  209. */
  210. /** @brief Reset CRYP handle state
  211. * @param __HANDLE__: specifies the CRYP handle.
  212. * @retval None
  213. */
  214. #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
  215. /**
  216. * @brief Enable/Disable the CRYP peripheral.
  217. * @param __HANDLE__: specifies the CRYP handle.
  218. * @retval None
  219. */
  220. #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_CRYPEN)
  221. #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~CRYP_CR_CRYPEN)
  222. /**
  223. * @brief Flush the data FIFO.
  224. * @param __HANDLE__: specifies the CRYP handle.
  225. * @retval None
  226. */
  227. #define __HAL_CRYP_FIFO_FLUSH(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_FFLUSH)
  228. /**
  229. * @brief Set the algorithm mode: AES-ECB, AES-CBC, AES-CTR, DES-ECB, DES-CBC.
  230. * @param __HANDLE__: specifies the CRYP handle.
  231. * @param MODE: The algorithm mode.
  232. * @retval None
  233. */
  234. #define __HAL_CRYP_SET_MODE(__HANDLE__, MODE) ((__HANDLE__)->Instance->CR |= (uint32_t)(MODE))
  235. /** @brief Check whether the specified CRYP flag is set or not.
  236. * @param __HANDLE__: specifies the CRYP handle.
  237. * @param __FLAG__: specifies the flag to check.
  238. * This parameter can be one of the following values:
  239. * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data
  240. * or a key preparation (for AES decryption).
  241. * @arg CRYP_FLAG_IFEM: Input FIFO is empty
  242. * @arg CRYP_FLAG_IFNF: Input FIFO is not full
  243. * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending
  244. * @arg CRYP_FLAG_OFNE: Output FIFO is not empty
  245. * @arg CRYP_FLAG_OFFU: Output FIFO is full
  246. * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending
  247. * @retval The new state of __FLAG__ (TRUE or FALSE).
  248. */
  249. #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 24)) == 0x01U)?((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \
  250. ((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)))
  251. /** @brief Check whether the specified CRYP interrupt is set or not.
  252. * @param __HANDLE__: specifies the CRYP handle.
  253. * @param __INTERRUPT__: specifies the interrupt to check.
  254. * This parameter can be one of the following values:
  255. * @arg CRYP_IT_INRIS: Input FIFO service raw interrupt is pending
  256. * @arg CRYP_IT_OUTRIS: Output FIFO service raw interrupt is pending
  257. * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
  258. */
  259. #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->MISR & (__INTERRUPT__)) == (__INTERRUPT__))
  260. /**
  261. * @brief Enable the CRYP interrupt.
  262. * @param __HANDLE__: specifies the CRYP handle.
  263. * @param __INTERRUPT__: CRYP Interrupt.
  264. * @retval None
  265. */
  266. #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) |= (__INTERRUPT__))
  267. /**
  268. * @brief Disable the CRYP interrupt.
  269. * @param __HANDLE__: specifies the CRYP handle.
  270. * @param __INTERRUPT__: CRYP interrupt.
  271. * @retval None
  272. */
  273. #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) &= ~(__INTERRUPT__))
  274. /**
  275. * @}
  276. */
  277. /* Include CRYP HAL Extension module */
  278. #include "stm32f7xx_hal_cryp_ex.h"
  279. /* Exported functions --------------------------------------------------------*/
  280. /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
  281. * @{
  282. */
  283. /** @addtogroup CRYP_Exported_Functions_Group1
  284. * @{
  285. */
  286. HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
  287. HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
  288. void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
  289. void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
  290. /**
  291. * @}
  292. */
  293. /** @addtogroup CRYP_Exported_Functions_Group2
  294. * @{
  295. */
  296. /* AES encryption/decryption using polling ***********************************/
  297. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  298. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  299. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  300. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  301. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  302. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  303. /* AES encryption/decryption using interrupt *********************************/
  304. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  305. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  306. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  307. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  308. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  309. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  310. /* AES encryption/decryption using DMA ***************************************/
  311. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  312. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  313. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  314. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  315. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  316. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  317. /**
  318. * @}
  319. */
  320. /** @addtogroup CRYP_Exported_Functions_Group3
  321. * @{
  322. */
  323. /* DES encryption/decryption using polling ***********************************/
  324. HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  325. HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  326. HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  327. HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  328. /* DES encryption/decryption using interrupt *********************************/
  329. HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  330. HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  331. HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  332. HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  333. /* DES encryption/decryption using DMA ***************************************/
  334. HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  335. HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  336. HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  337. HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  338. /**
  339. * @}
  340. */
  341. /** @addtogroup CRYP_Exported_Functions_Group4
  342. * @{
  343. */
  344. /* TDES encryption/decryption using polling **********************************/
  345. HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  346. HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  347. HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  348. HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  349. /* TDES encryption/decryption using interrupt ********************************/
  350. HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  351. HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  352. HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  353. HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  354. /* TDES encryption/decryption using DMA **************************************/
  355. HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  356. HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  357. HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  358. HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  359. /**
  360. * @}
  361. */
  362. /** @addtogroup CRYP_Exported_Functions_Group5
  363. * @{
  364. */
  365. void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
  366. void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
  367. void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
  368. /**
  369. * @}
  370. */
  371. /** @addtogroup CRYP_Exported_Functions_Group6
  372. * @{
  373. */
  374. void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
  375. /**
  376. * @}
  377. */
  378. /** @addtogroup CRYP_Exported_Functions_Group7
  379. * @{
  380. */
  381. HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
  382. /**
  383. * @}
  384. */
  385. /**
  386. * @}
  387. */
  388. /* Private types -------------------------------------------------------------*/
  389. /** @defgroup CRYP_Private_Types CRYP Private Types
  390. * @{
  391. */
  392. /**
  393. * @}
  394. */
  395. /* Private variables ---------------------------------------------------------*/
  396. /** @defgroup CRYP_Private_Variables CRYP Private Variables
  397. * @{
  398. */
  399. /**
  400. * @}
  401. */
  402. /* Private constants ---------------------------------------------------------*/
  403. /** @defgroup CRYP_Private_Constants CRYP Private Constants
  404. * @{
  405. */
  406. #define CRYP_FLAG_MASK ((uint32_t)0x0000001F)
  407. /**
  408. * @}
  409. */
  410. /* Private macros ------------------------------------------------------------*/
  411. /** @defgroup CRYP_Private_Macros CRYP Private Macros
  412. * @{
  413. */
  414. #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \
  415. ((__KEYSIZE__) == CRYP_KEYSIZE_192B) || \
  416. ((__KEYSIZE__) == CRYP_KEYSIZE_256B))
  417. #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \
  418. ((__DATATYPE__) == CRYP_DATATYPE_16B) || \
  419. ((__DATATYPE__) == CRYP_DATATYPE_8B) || \
  420. ((__DATATYPE__) == CRYP_DATATYPE_1B))
  421. /**
  422. * @}
  423. */
  424. /* Private functions ---------------------------------------------------------*/
  425. /** @defgroup CRYP_Private_Functions CRYP Private Functions
  426. * @{
  427. */
  428. /**
  429. * @}
  430. */
  431. /**
  432. * @}
  433. */
  434. #endif /* CRYP */
  435. /**
  436. * @}
  437. */
  438. #if defined (AES)
  439. /** @addtogroup STM32F7xx_HAL_Driver
  440. * @{
  441. */
  442. /** @addtogroup CRYP
  443. * @{
  444. */
  445. /* Exported types ------------------------------------------------------------*/
  446. /** @defgroup CRYP_Exported_Types CRYP Exported Types
  447. * @{
  448. */
  449. /**
  450. * @brief CRYP Configuration Structure definition
  451. */
  452. typedef struct
  453. {
  454. uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
  455. This parameter can be a value of @ref CRYP_Data_Type */
  456. uint32_t KeySize; /*!< 128 or 256-bit key length.
  457. This parameter can be a value of @ref CRYP_Key_Size */
  458. uint32_t OperatingMode; /*!< AES operating mode.
  459. This parameter can be a value of @ref CRYP_AES_OperatingMode */
  460. uint32_t ChainingMode; /*!< AES chaining mode.
  461. This parameter can be a value of @ref CRYP_AES_ChainingMode */
  462. uint32_t KeyWriteFlag; /*!< Allows to bypass or not key write-up before decryption.
  463. This parameter can be a value of @ref CRYP_Key_Write */
  464. uint32_t GCMCMACPhase; /*!< Indicates the processing phase of the Galois Counter Mode (GCM),
  465. Galois Message Authentication Code (GMAC) or Cipher Message
  466. Authentication Code (CMAC) or Counter with Cipher Mode (CCM) when
  467. the latter is applicable.
  468. This parameter can be a value of @ref CRYP_GCM_CMAC_Phase */
  469. uint8_t* pKey; /*!< Encryption/Decryption Key */
  470. uint8_t* pInitVect; /*!< Initialization Vector used for CTR, CBC, GCM/GMAC, CMAC,
  471. (and CCM when applicable) modes */
  472. uint8_t* Header; /*!< Header used in GCM/GMAC, CMAC (and CCM when applicable) modes */
  473. uint64_t HeaderSize; /*!< Header size in bytes */
  474. }CRYP_InitTypeDef;
  475. /**
  476. * @brief HAL CRYP State structures definition
  477. */
  478. typedef enum
  479. {
  480. HAL_CRYP_STATE_RESET = 0x00, /*!< CRYP not yet initialized or disabled */
  481. HAL_CRYP_STATE_READY = 0x01, /*!< CRYP initialized and ready for use */
  482. HAL_CRYP_STATE_BUSY = 0x02, /*!< CRYP internal processing is ongoing */
  483. HAL_CRYP_STATE_TIMEOUT = 0x03, /*!< CRYP timeout state */
  484. HAL_CRYP_STATE_ERROR = 0x04, /*!< CRYP error state */
  485. HAL_CRYP_STATE_SUSPENDED = 0x05 /*!< CRYP suspended */
  486. }HAL_CRYP_STATETypeDef;
  487. /**
  488. * @brief HAL CRYP phase structures definition
  489. */
  490. typedef enum
  491. {
  492. HAL_CRYP_PHASE_READY = 0x01, /*!< CRYP peripheral is ready for initialization. */
  493. HAL_CRYP_PHASE_PROCESS = 0x02, /*!< CRYP peripheral is in processing phase */
  494. HAL_CRYP_PHASE_START = 0x03, /*!< CRYP peripheral has been initialized but
  495. GCM/GMAC/CMAC(/CCM) initialization phase has not started */
  496. HAL_CRYP_PHASE_INIT_OVER = 0x04, /*!< GCM/GMAC/CMAC(/CCM) init phase has been carried out */
  497. HAL_CRYP_PHASE_HEADER_OVER = 0x05, /*!< GCM/GMAC/CMAC(/CCM) header phase has been carried out */
  498. HAL_CRYP_PHASE_PAYLOAD_OVER = 0x06, /*!< GCM(/CCM) payload phase has been carried out */
  499. HAL_CRYP_PHASE_FINAL_OVER = 0x07, /*!< GCM/GMAC/CMAC(/CCM) final phase has been carried out */
  500. HAL_CRYP_PHASE_HEADER_SUSPENDED = 0x08, /*!< GCM/GMAC/CMAC(/CCM) header phase has been suspended */
  501. HAL_CRYP_PHASE_PAYLOAD_SUSPENDED = 0x09, /*!< GCM(/CCM) payload phase has been suspended */
  502. HAL_CRYP_PHASE_NOT_USED = 0x0a /*!< Phase is irrelevant to the current chaining mode */
  503. }HAL_PhaseTypeDef;
  504. /**
  505. * @brief HAL CRYP mode suspend definitions
  506. */
  507. typedef enum
  508. {
  509. HAL_CRYP_SUSPEND_NONE = 0x00, /*!< CRYP peripheral suspension not requested */
  510. HAL_CRYP_SUSPEND = 0x01 /*!< CRYP peripheral suspension requested */
  511. }HAL_SuspendTypeDef;
  512. /**
  513. * @brief HAL CRYP Error Codes definition
  514. */
  515. #define HAL_CRYP_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
  516. #define HAL_CRYP_WRITE_ERROR ((uint32_t)0x00000001) /*!< Write error */
  517. #define HAL_CRYP_READ_ERROR ((uint32_t)0x00000002) /*!< Read error */
  518. #define HAL_CRYP_DMA_ERROR ((uint32_t)0x00000004) /*!< DMA error */
  519. #define HAL_CRYP_BUSY_ERROR ((uint32_t)0x00000008) /*!< Busy flag error */
  520. /**
  521. * @brief CRYP handle Structure definition
  522. */
  523. typedef struct
  524. {
  525. AES_TypeDef *Instance; /*!< Register base address */
  526. CRYP_InitTypeDef Init; /*!< CRYP initialization parameters */
  527. uint8_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) input buffer */
  528. uint8_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) output buffer */
  529. uint32_t CrypInCount; /*!< Input data size in bytes or, after suspension, the remaining
  530. number of bytes to process */
  531. uint32_t CrypOutCount; /*!< Output data size in bytes */
  532. HAL_PhaseTypeDef Phase; /*!< CRYP peripheral processing phase for GCM, GMAC, CMAC
  533. (or CCM when applicable) modes.
  534. Indicates the last phase carried out to ease
  535. phase transitions */
  536. DMA_HandleTypeDef *hdmain; /*!< CRYP peripheral Input DMA handle parameters */
  537. DMA_HandleTypeDef *hdmaout; /*!< CRYP peripheral Output DMA handle parameters */
  538. HAL_LockTypeDef Lock; /*!< CRYP locking object */
  539. __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */
  540. __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */
  541. HAL_SuspendTypeDef SuspendRequest; /*!< CRYP peripheral suspension request flag */
  542. }CRYP_HandleTypeDef;
  543. /**
  544. * @}
  545. */
  546. /* Exported constants --------------------------------------------------------*/
  547. /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
  548. * @{
  549. */
  550. /** @defgroup CRYP_Key_Size Key size selection
  551. * @{
  552. */
  553. #define CRYP_KEYSIZE_128B ((uint32_t)0x00000000) /*!< 128-bit long key */
  554. #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */
  555. /**
  556. * @}
  557. */
  558. /** @defgroup CRYP_Data_Type AES Data Type selection
  559. * @{
  560. */
  561. #define CRYP_DATATYPE_32B ((uint32_t)0x00000000) /*!< 32-bit data type (no swapping) */
  562. #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */
  563. #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */
  564. #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */
  565. /**
  566. * @}
  567. */
  568. /** @defgroup CRYP_AES_State AES Enable state
  569. * @{
  570. */
  571. #define CRYP_AES_DISABLE ((uint32_t)0x00000000) /*!< Disable AES */
  572. #define CRYP_AES_ENABLE AES_CR_EN /*!< Enable AES */
  573. /**
  574. * @}
  575. */
  576. /** @defgroup CRYP_AES_OperatingMode AES operating mode
  577. * @{
  578. */
  579. #define CRYP_ALGOMODE_ENCRYPT ((uint32_t)0x00000000) /*!< Encryption mode */
  580. #define CRYP_ALGOMODE_KEYDERIVATION AES_CR_MODE_0 /*!< Key derivation mode */
  581. #define CRYP_ALGOMODE_DECRYPT AES_CR_MODE_1 /*!< Decryption */
  582. #define CRYP_ALGOMODE_KEYDERIVATION_DECRYPT AES_CR_MODE /*!< Key derivation and decryption */
  583. #define CRYP_ALGOMODE_TAG_GENERATION ((uint32_t)0x00000000) /*!< GMAC or CMAC authentication tag generation */
  584. /**
  585. * @}
  586. */
  587. /** @defgroup CRYP_AES_ChainingMode AES chaining mode
  588. * @{
  589. */
  590. #define CRYP_CHAINMODE_AES_ECB ((uint32_t)0x00000000) /*!< Electronic codebook chaining algorithm */
  591. #define CRYP_CHAINMODE_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */
  592. #define CRYP_CHAINMODE_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */
  593. #define CRYP_CHAINMODE_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */
  594. #define CRYP_CHAINMODE_AES_CMAC AES_CR_CHMOD_2 /*!< Cipher message authentication code */
  595. #if defined(AES_CR_NPBLB)
  596. #define CRYP_CHAINMODE_AES_CCM_CMAC AES_CR_CHMOD_2 /*!< Counter with Cipher Mode - Cipher message authentication code */
  597. #endif
  598. /**
  599. * @}
  600. */
  601. /** @defgroup CRYP_Key_Write AES decryption key write-up flag
  602. * @{
  603. */
  604. #define CRYP_KEY_WRITE_ENABLE ((uint32_t)0x00000000) /*!< Enable decryption key writing */
  605. #define CRYP_KEY_WRITE_DISABLE ((uint32_t)0x00000001) /*!< Disable decryption key writing */
  606. /**
  607. * @}
  608. */
  609. /** @defgroup CRYP_DMAIN DMA Input phase management enable state
  610. * @{
  611. */
  612. #define CRYP_DMAIN_DISABLE ((uint32_t)0x00000000) /*!< Disable DMA Input phase management */
  613. #define CRYP_DMAIN_ENABLE AES_CR_DMAINEN /*!< Enable DMA Input phase management */
  614. /**
  615. * @}
  616. */
  617. /** @defgroup CRYP_DMAOUT DMA Output phase management enable state
  618. * @{
  619. */
  620. #define CRYP_DMAOUT_DISABLE ((uint32_t)0x00000000) /*!< Disable DMA Output phase management */
  621. #define CRYP_DMAOUT_ENABLE AES_CR_DMAOUTEN /*!< Enable DMA Output phase management */
  622. /**
  623. * @}
  624. */
  625. /** @defgroup CRYP_GCM_CMAC_Phase GCM/GMAC and CMAC processing phase selection
  626. * @{
  627. */
  628. #define CRYP_GCM_INIT_PHASE ((uint32_t)0x00000000) /*!< GCM/GMAC (or CCM) init phase */
  629. #define CRYP_GCMCMAC_HEADER_PHASE AES_CR_GCMPH_0 /*!< GCM/GMAC or (CCM/)CMAC header phase */
  630. #define CRYP_GCM_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< GCM(/CCM) payload phase */
  631. #define CRYP_GCMCMAC_FINAL_PHASE AES_CR_GCMPH /*!< GCM/GMAC or (CCM/)CMAC final phase */
  632. /* Definitions duplication for code readibility's sake:
  633. supported or not supported chain modes are not specified for each phase */
  634. #define CRYP_INIT_PHASE ((uint32_t)0x00000000) /*!< Init phase */
  635. #define CRYP_HEADER_PHASE AES_CR_GCMPH_0 /*!< Header phase */
  636. #define CRYP_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< Payload phase */
  637. #define CRYP_FINAL_PHASE AES_CR_GCMPH /*!< Final phase */
  638. /**
  639. * @}
  640. */
  641. /** @defgroup CRYP_Flags AES status flags
  642. * @{
  643. */
  644. #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */
  645. #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */
  646. #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */
  647. #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */
  648. /**
  649. * @}
  650. */
  651. /** @defgroup CRYP_Clear_Flags AES clearing flags
  652. * @{
  653. */
  654. #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */
  655. #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */
  656. /**
  657. * @}
  658. */
  659. /** @defgroup AES_Interrupts_Enable AES Interrupts Enable bits
  660. * @{
  661. */
  662. #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */
  663. #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */
  664. /**
  665. * @}
  666. */
  667. /** @defgroup CRYP_Interrupts_Flags AES Interrupts flags
  668. * @{
  669. */
  670. #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */
  671. #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */
  672. #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */
  673. /**
  674. * @}
  675. */
  676. /**
  677. * @}
  678. */
  679. /* Exported macros -----------------------------------------------------------*/
  680. /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
  681. * @{
  682. */
  683. /** @brief Reset CRYP handle state.
  684. * @param __HANDLE__: specifies the CRYP handle.
  685. * @retval None
  686. */
  687. #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
  688. /**
  689. * @brief Enable the CRYP AES peripheral.
  690. * @retval None
  691. */
  692. #define __HAL_CRYP_ENABLE() (AES->CR |= AES_CR_EN)
  693. /**
  694. * @brief Disable the CRYP AES peripheral.
  695. * @retval None
  696. */
  697. #define __HAL_CRYP_DISABLE() (AES->CR &= ~AES_CR_EN)
  698. /**
  699. * @brief Set the algorithm operating mode.
  700. * @param __OPERATING_MODE__: specifies the operating mode
  701. * This parameter can be one of the following values:
  702. * @arg @ref CRYP_ALGOMODE_ENCRYPT encryption
  703. * @arg @ref CRYP_ALGOMODE_KEYDERIVATION key derivation
  704. * @arg @ref CRYP_ALGOMODE_DECRYPT decryption
  705. * @arg @ref CRYP_ALGOMODE_KEYDERIVATION_DECRYPT key derivation and decryption
  706. * @retval None
  707. */
  708. #define __HAL_CRYP_SET_OPERATINGMODE(__OPERATING_MODE__) MODIFY_REG(AES->CR, AES_CR_MODE, (__OPERATING_MODE__))
  709. /**
  710. * @brief Set the algorithm chaining mode.
  711. * @param __CHAINING_MODE__: specifies the chaining mode
  712. * This parameter can be one of the following values:
  713. * @arg @ref CRYP_CHAINMODE_AES_ECB Electronic CodeBook
  714. * @arg @ref CRYP_CHAINMODE_AES_CBC Cipher Block Chaining
  715. * @arg @ref CRYP_CHAINMODE_AES_CTR CounTeR mode
  716. * @arg @ref CRYP_CHAINMODE_AES_GCM_GMAC Galois Counter Mode or Galois Message Authentication Code
  717. * @arg @ref CRYP_CHAINMODE_AES_CMAC Cipher Message Authentication Code (or Counter with Cipher Mode when applicable)
  718. * @retval None
  719. */
  720. #define __HAL_CRYP_SET_CHAININGMODE(__CHAINING_MODE__) MODIFY_REG(AES->CR, AES_CR_CHMOD, (__CHAINING_MODE__))
  721. /** @brief Check whether the specified CRYP status flag is set or not.
  722. * @param __FLAG__: specifies the flag to check.
  723. * This parameter can be one of the following values:
  724. * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden
  725. * @arg @ref CRYP_IT_WRERR Write Error
  726. * @arg @ref CRYP_IT_RDERR Read Error
  727. * @arg @ref CRYP_IT_CCF Computation Complete
  728. * @retval The state of __FLAG__ (TRUE or FALSE).
  729. */
  730. #define __HAL_CRYP_GET_FLAG(__FLAG__) ((AES->SR & (__FLAG__)) == (__FLAG__))
  731. /** @brief Clear the CRYP pending status flag.
  732. * @param __FLAG__: specifies the flag to clear.
  733. * This parameter can be one of the following values:
  734. * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
  735. * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
  736. * @retval None
  737. */
  738. #define __HAL_CRYP_CLEAR_FLAG(__FLAG__) SET_BIT(AES->CR, (__FLAG__))
  739. /** @brief Check whether the specified CRYP interrupt source is enabled or not.
  740. * @param __INTERRUPT__: CRYP interrupt source to check
  741. * This parameter can be one of the following values:
  742. * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
  743. * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
  744. * @retval State of interruption (TRUE or FALSE).
  745. */
  746. #define __HAL_CRYP_GET_IT_SOURCE(__INTERRUPT__) ((AES->CR & (__INTERRUPT__)) == (__INTERRUPT__))
  747. /** @brief Check whether the specified CRYP interrupt is set or not.
  748. * @param __INTERRUPT__: specifies the interrupt to check.
  749. * This parameter can be one of the following values:
  750. * @arg @ref CRYP_IT_WRERR Write Error
  751. * @arg @ref CRYP_IT_RDERR Read Error
  752. * @arg @ref CRYP_IT_CCF Computation Complete
  753. * @retval The state of __INTERRUPT__ (TRUE or FALSE).
  754. */
  755. #define __HAL_CRYP_GET_IT(__INTERRUPT__) ((AES->SR & (__INTERRUPT__)) == (__INTERRUPT__))
  756. /** @brief Clear the CRYP pending interrupt.
  757. * @param __INTERRUPT__: specifies the IT to clear.
  758. * This parameter can be one of the following values:
  759. * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
  760. * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
  761. * @retval None
  762. */
  763. #define __HAL_CRYP_CLEAR_IT(__INTERRUPT__) SET_BIT(AES->CR, (__INTERRUPT__))
  764. /**
  765. * @brief Enable the CRYP interrupt.
  766. * @param __INTERRUPT__: CRYP Interrupt.
  767. * This parameter can be one of the following values:
  768. * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
  769. * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
  770. * @retval None
  771. */
  772. #define __HAL_CRYP_ENABLE_IT(__INTERRUPT__) ((AES->CR) |= (__INTERRUPT__))
  773. /**
  774. * @brief Disable the CRYP interrupt.
  775. * @param __INTERRUPT__: CRYP Interrupt.
  776. * This parameter can be one of the following values:
  777. * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
  778. * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
  779. * @retval None
  780. */
  781. #define __HAL_CRYP_DISABLE_IT(__INTERRUPT__) ((AES->CR) &= ~(__INTERRUPT__))
  782. /**
  783. * @}
  784. */
  785. /* Private macros --------------------------------------------------------*/
  786. /** @addtogroup CRYP_Private_Macros CRYP Private Macros
  787. * @{
  788. */
  789. /**
  790. * @brief Verify the key size length.
  791. * @param __KEYSIZE__: Ciphering/deciphering algorithm key size.
  792. * @retval SET (__KEYSIZE__ is a valid value) or RESET (__KEYSIZE__ is invalid)
  793. */
  794. #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \
  795. ((__KEYSIZE__) == CRYP_KEYSIZE_256B))
  796. /**
  797. * @brief Verify the input data type.
  798. * @param __DATATYPE__: Ciphering/deciphering algorithm input data type.
  799. * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid)
  800. */
  801. #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \
  802. ((__DATATYPE__) == CRYP_DATATYPE_16B) || \
  803. ((__DATATYPE__) == CRYP_DATATYPE_8B) || \
  804. ((__DATATYPE__) == CRYP_DATATYPE_1B))
  805. /**
  806. * @brief Verify the CRYP AES IP running mode.
  807. * @param __MODE__: CRYP AES IP running mode.
  808. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  809. */
  810. #define IS_CRYP_AES(__MODE__) (((__MODE__) == CRYP_AES_DISABLE) || \
  811. ((__MODE__) == CRYP_AES_ENABLE))
  812. /**
  813. * @brief Verify the selected CRYP algorithm.
  814. * @param __ALGOMODE__: Selected CRYP algorithm (ciphering, deciphering, key derivation or a combination of the latter).
  815. * @retval SET (__ALGOMODE__ is valid) or RESET (__ALGOMODE__ is invalid)
  816. */
  817. #define IS_CRYP_ALGOMODE(__ALGOMODE__) (((__ALGOMODE__) == CRYP_ALGOMODE_ENCRYPT) || \
  818. ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION) || \
  819. ((__ALGOMODE__) == CRYP_ALGOMODE_DECRYPT) || \
  820. ((__ALGOMODE__) == CRYP_ALGOMODE_TAG_GENERATION) || \
  821. ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION_DECRYPT))
  822. /**
  823. * @brief Verify the selected CRYP chaining algorithm.
  824. * @param __CHAINMODE__: Selected CRYP chaining algorithm.
  825. * @retval SET (__CHAINMODE__ is valid) or RESET (__CHAINMODE__ is invalid)
  826. */
  827. #if defined(AES_CR_NPBLB)
  828. #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \
  829. ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \
  830. ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \
  831. ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \
  832. ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CCM_CMAC))
  833. #else
  834. #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \
  835. ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \
  836. ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \
  837. ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \
  838. ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CMAC))
  839. #endif
  840. /**
  841. * @brief Verify the deciphering key write option.
  842. * @param __WRITE__: deciphering key write option.
  843. * @retval SET (__WRITE__ is valid) or RESET (__WRITE__ is invalid)
  844. */
  845. #define IS_CRYP_WRITE(__WRITE__) (((__WRITE__) == CRYP_KEY_WRITE_ENABLE) || \
  846. ((__WRITE__) == CRYP_KEY_WRITE_DISABLE))
  847. /**
  848. * @brief Verify the CRYP input data DMA mode.
  849. * @param __MODE__: CRYP input data DMA mode.
  850. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  851. */
  852. #define IS_CRYP_DMAIN(__MODE__) (((__MODE__) == CRYP_DMAIN_DISABLE) || \
  853. ((__MODE__) == CRYP_DMAIN_ENABLE))
  854. /**
  855. * @brief Verify the CRYP output data DMA mode.
  856. * @param __MODE__: CRYP output data DMA mode.
  857. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  858. */
  859. #define IS_CRYP_DMAOUT(__MODE__) (((__MODE__) == CRYP_DMAOUT_DISABLE) || \
  860. ((__MODE__) == CRYP_DMAOUT_ENABLE))
  861. /**
  862. * @brief Verify the CRYP AES ciphering/deciphering/authentication algorithm phase.
  863. * @param __PHASE__: CRYP AES ciphering/deciphering/authentication algorithm phase.
  864. * @retval SET (__PHASE__ is valid) or RESET (__PHASE__ is invalid)
  865. */
  866. #define IS_CRYP_GCMCMAC_PHASE(__PHASE__) (((__PHASE__) == CRYP_GCM_INIT_PHASE) || \
  867. ((__PHASE__) == CRYP_GCMCMAC_HEADER_PHASE) || \
  868. ((__PHASE__) == CRYP_GCM_PAYLOAD_PHASE) || \
  869. ((__PHASE__) == CRYP_GCMCMAC_FINAL_PHASE))
  870. /**
  871. * @}
  872. */
  873. /* Include CRYP HAL Extended module */
  874. #include "stm32f7xx_hal_cryp_ex.h"
  875. /* Exported functions --------------------------------------------------------*/
  876. /** @addtogroup CRYP_Exported_Functions CRYP Exported Functions
  877. * @{
  878. */
  879. /** @addtogroup CRYP_Exported_Functions_Group1 Initialization and deinitialization functions
  880. * @{
  881. */
  882. /* Initialization/de-initialization functions ********************************/
  883. HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
  884. HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
  885. /* MSP initialization/de-initialization functions ****************************/
  886. void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
  887. void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
  888. /**
  889. * @}
  890. */
  891. /** @addtogroup CRYP_Exported_Functions_Group2 AES processing functions
  892. * @{
  893. */
  894. /* AES encryption/decryption processing functions ****************************/
  895. /* AES encryption/decryption using polling ***********************************/
  896. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  897. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  898. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  899. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  900. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  901. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  902. /* AES encryption/decryption using interrupt *********************************/
  903. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  904. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  905. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  906. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  907. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  908. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  909. /* AES encryption/decryption using DMA ***************************************/
  910. HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  911. HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  912. HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  913. HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  914. HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  915. HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  916. /**
  917. * @}
  918. */
  919. /** @addtogroup CRYP_Exported_Functions_Group3 Callback functions
  920. * @{
  921. */
  922. /* CallBack functions ********************************************************/
  923. void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
  924. void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
  925. void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
  926. /**
  927. * @}
  928. */
  929. /** @addtogroup CRYP_Exported_Functions_Group4 CRYP IRQ handler
  930. * @{
  931. */
  932. /* AES interrupt handling function *******************************************/
  933. void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
  934. /**
  935. * @}
  936. */
  937. /** @addtogroup CRYP_Exported_Functions_Group5 Peripheral State functions
  938. * @{
  939. */
  940. /* Peripheral State functions ************************************************/
  941. HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
  942. uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp);
  943. /**
  944. * @}
  945. */
  946. /**
  947. * @}
  948. */
  949. /**
  950. * @}
  951. */
  952. /**
  953. * @}
  954. */
  955. #endif /* AES */
  956. #ifdef __cplusplus
  957. }
  958. #endif
  959. #endif /* __STM32F7xx_HAL_CRYP_H */
  960. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/