stm32f4xx_hal_cryp_ex.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_cryp_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of CRYP HAL Extension module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F4xx_HAL_CRYP_EX_H
  37. #define __STM32F4xx_HAL_CRYP_EX_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f4xx_hal_def.h"
  43. #if defined(CRYP)
  44. /** @addtogroup STM32F4xx_HAL_Driver
  45. * @{
  46. */
  47. /** @addtogroup CRYPEx
  48. * @{
  49. */
  50. /* Exported types ------------------------------------------------------------*/
  51. /* Exported constants --------------------------------------------------------*/
  52. /** @defgroup CRYPEx_Exported_Constants CRYPEx Exported Constants
  53. * @{
  54. */
  55. /** @defgroup CRYPEx_Exported_Constants_Group1 CRYP AlgoModeDirection
  56. * @{
  57. */
  58. #define CRYP_CR_ALGOMODE_AES_GCM_ENCRYPT 0x00080000U
  59. #define CRYP_CR_ALGOMODE_AES_GCM_DECRYPT 0x00080004U
  60. #define CRYP_CR_ALGOMODE_AES_CCM_ENCRYPT 0x00080008U
  61. #define CRYP_CR_ALGOMODE_AES_CCM_DECRYPT 0x0008000CU
  62. /**
  63. * @}
  64. */
  65. /** @defgroup CRYPEx_Exported_Constants_Group3 CRYP PhaseConfig
  66. * @brief The phases are relevant only to AES-GCM and AES-CCM
  67. * @{
  68. */
  69. #define CRYP_PHASE_INIT 0x00000000U
  70. #define CRYP_PHASE_HEADER CRYP_CR_GCM_CCMPH_0
  71. #define CRYP_PHASE_PAYLOAD CRYP_CR_GCM_CCMPH_1
  72. #define CRYP_PHASE_FINAL CRYP_CR_GCM_CCMPH
  73. /**
  74. * @}
  75. */
  76. /**
  77. * @}
  78. */
  79. /* Exported macro ------------------------------------------------------------*/
  80. /** @defgroup CRYPEx_Exported_Macros CRYP Exported Macros
  81. * @{
  82. */
  83. /**
  84. * @brief Set the phase: Init, header, payload, final.
  85. * This is relevant only for GCM and CCM modes.
  86. * @param __HANDLE__ specifies the CRYP handle.
  87. * @param __PHASE__ The phase.
  88. * @retval None
  89. */
  90. #define __HAL_CRYP_SET_PHASE(__HANDLE__, __PHASE__) do{(__HANDLE__)->Instance->CR &= (uint32_t)(~CRYP_CR_GCM_CCMPH);\
  91. (__HANDLE__)->Instance->CR |= (uint32_t)(__PHASE__);\
  92. }while(0)
  93. /**
  94. * @}
  95. */
  96. /* Exported functions --------------------------------------------------------*/
  97. /** @defgroup CRYPEx_Exported_Functions CRYPEx Exported Functions
  98. * @{
  99. */
  100. /** @addtogroup CRYPEx_Exported_Functions_Group1
  101. * @{
  102. */
  103. /* AES encryption/decryption using polling ***********************************/
  104. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  105. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  106. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Finish(CRYP_HandleTypeDef *hcryp, uint32_t Size, uint8_t *AuthTag, uint32_t Timeout);
  107. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  108. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  109. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Finish(CRYP_HandleTypeDef *hcryp, uint8_t *AuthTag, uint32_t Timeout);
  110. /* AES encryption/decryption using interrupt *********************************/
  111. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  112. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  113. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  114. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  115. /* AES encryption/decryption using DMA ***************************************/
  116. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  117. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  118. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  119. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  120. /**
  121. * @}
  122. */
  123. /** @addtogroup CRYPEx_Exported_Functions_Group2
  124. * @{
  125. */
  126. void HAL_CRYPEx_GCMCCM_IRQHandler(CRYP_HandleTypeDef *hcryp);
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. /* Private types -------------------------------------------------------------*/
  134. /** @defgroup CRYPEx_Private_Types CRYPEx Private Types
  135. * @{
  136. */
  137. /**
  138. * @}
  139. */
  140. /* Private variables ---------------------------------------------------------*/
  141. /** @defgroup CRYPEx_Private_Variables CRYPEx Private Variables
  142. * @{
  143. */
  144. /**
  145. * @}
  146. */
  147. /* Private constants ---------------------------------------------------------*/
  148. /** @defgroup CRYPEx_Private_Constants CRYPEx Private Constants
  149. * @{
  150. */
  151. /**
  152. * @}
  153. */
  154. /* Private macros ------------------------------------------------------------*/
  155. /** @defgroup CRYPEx_Private_Macros CRYPEx Private Macros
  156. * @{
  157. */
  158. /**
  159. * @}
  160. */
  161. /* Private functions ---------------------------------------------------------*/
  162. /** @defgroup CRYPEx_Private_Functions CRYPEx Private Functions
  163. * @{
  164. */
  165. /**
  166. * @}
  167. */
  168. #endif /* CRYP */
  169. #if defined (AES)
  170. /** @addtogroup CRYPEx_Exported_Functions
  171. * @{
  172. */
  173. /** @addtogroup CRYPEx_Exported_Functions_Group1
  174. * @{
  175. */
  176. /* CallBack functions ********************************************************/
  177. void HAL_CRYPEx_ComputationCpltCallback(CRYP_HandleTypeDef *hcryp);
  178. /**
  179. * @}
  180. */
  181. /** @addtogroup CRYPEx_Exported_Functions_Group2
  182. * @{
  183. */
  184. /* AES encryption/decryption processing functions ****************************/
  185. HAL_StatusTypeDef HAL_CRYPEx_AES(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData, uint32_t Timeout);
  186. HAL_StatusTypeDef HAL_CRYPEx_AES_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData);
  187. HAL_StatusTypeDef HAL_CRYPEx_AES_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData);
  188. /* AES encryption/decryption/authentication processing functions *************/
  189. HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData, uint32_t Timeout);
  190. HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData);
  191. HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData);
  192. /**
  193. * @}
  194. */
  195. /** @addtogroup CRYPEx_Exported_Functions_Group3
  196. * @{
  197. */
  198. /* AES suspension/resumption functions ***************************************/
  199. void HAL_CRYPEx_Read_IVRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output);
  200. void HAL_CRYPEx_Write_IVRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input);
  201. void HAL_CRYPEx_Read_SuspendRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output);
  202. void HAL_CRYPEx_Write_SuspendRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input);
  203. void HAL_CRYPEx_Read_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output, uint32_t KeySize);
  204. void HAL_CRYPEx_Write_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint32_t KeySize);
  205. void HAL_CRYPEx_Read_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Output);
  206. void HAL_CRYPEx_Write_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Input);
  207. void HAL_CRYPEx_ProcessSuspend(CRYP_HandleTypeDef *hcryp);
  208. /**
  209. * @}
  210. */
  211. /**
  212. * @}
  213. */
  214. /* Private functions -----------------------------------------------------------*/
  215. /** @addtogroup CRYPEx_Private_Functions CRYPEx Private Functions
  216. * @{
  217. */
  218. HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp);
  219. /**
  220. * @}
  221. */
  222. #endif /* AES */
  223. /**
  224. * @}
  225. */
  226. /**
  227. * @}
  228. */
  229. #ifdef __cplusplus
  230. }
  231. #endif
  232. #endif /* __STM32F4xx_HAL_CRYP_EX_H */
  233. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/