You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

294 lines
10 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_cryp_ex.h
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief Header file of CRYP HAL Extension module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 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_EX_H
  39. #define __STM32F7xx_HAL_CRYP_EX_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 CRYPEx
  50. * @{
  51. */
  52. /* Exported types ------------------------------------------------------------*/
  53. /* Exported constants --------------------------------------------------------*/
  54. /** @defgroup CRYPEx_Exported_Constants CRYPEx Exported Constants
  55. * @{
  56. */
  57. /** @defgroup CRYPEx_Exported_Constants_Group1 CRYP AlgoModeDirection
  58. * @{
  59. */
  60. #define CRYP_CR_ALGOMODE_AES_GCM_ENCRYPT ((uint32_t)0x00080000U)
  61. #define CRYP_CR_ALGOMODE_AES_GCM_DECRYPT ((uint32_t)0x00080004U)
  62. #define CRYP_CR_ALGOMODE_AES_CCM_ENCRYPT ((uint32_t)0x00080008U)
  63. #define CRYP_CR_ALGOMODE_AES_CCM_DECRYPT ((uint32_t)0x0008000CU)
  64. /**
  65. * @}
  66. */
  67. /** @defgroup CRYPEx_Exported_Constants_Group3 CRYP PhaseConfig
  68. * @brief The phases are relevant only to AES-GCM and AES-CCM
  69. * @{
  70. */
  71. #define CRYP_PHASE_INIT ((uint32_t)0x00000000U)
  72. #define CRYP_PHASE_HEADER CRYP_CR_GCM_CCMPH_0
  73. #define CRYP_PHASE_PAYLOAD CRYP_CR_GCM_CCMPH_1
  74. #define CRYP_PHASE_FINAL CRYP_CR_GCM_CCMPH
  75. /**
  76. * @}
  77. */
  78. /**
  79. * @}
  80. */
  81. /* Exported macro ------------------------------------------------------------*/
  82. /** @defgroup CRYPEx_Exported_Macros CRYP Exported Macros
  83. * @{
  84. */
  85. /**
  86. * @brief Set the phase: Init, header, payload, final.
  87. * This is relevant only for GCM and CCM modes.
  88. * @param __HANDLE__: specifies the CRYP handle.
  89. * @param __PHASE__: The phase.
  90. * @retval None
  91. */
  92. #define __HAL_CRYP_SET_PHASE(__HANDLE__, __PHASE__) do{(__HANDLE__)->Instance->CR &= (uint32_t)(~CRYP_CR_GCM_CCMPH);\
  93. (__HANDLE__)->Instance->CR |= (uint32_t)(__PHASE__);\
  94. }while(0)
  95. /**
  96. * @}
  97. */
  98. /* Exported functions --------------------------------------------------------*/
  99. /** @defgroup CRYPEx_Exported_Functions CRYPEx Exported Functions
  100. * @{
  101. */
  102. /** @addtogroup CRYPEx_Exported_Functions_Group1
  103. * @{
  104. */
  105. /* AES encryption/decryption using polling ***********************************/
  106. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  107. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  108. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Finish(CRYP_HandleTypeDef *hcryp, uint32_t Size, uint8_t *AuthTag, uint32_t Timeout);
  109. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout);
  110. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout);
  111. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Finish(CRYP_HandleTypeDef *hcryp, uint8_t *AuthTag, uint32_t Timeout);
  112. /* AES encryption/decryption using interrupt *********************************/
  113. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  114. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  115. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  116. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  117. /* AES encryption/decryption using DMA ***************************************/
  118. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  119. HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  120. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData);
  121. HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData);
  122. /**
  123. * @}
  124. */
  125. /** @addtogroup CRYPEx_Exported_Functions_Group2
  126. * @{
  127. */
  128. void HAL_CRYPEx_GCMCCM_IRQHandler(CRYP_HandleTypeDef *hcryp);
  129. /**
  130. * @}
  131. */
  132. /**
  133. * @}
  134. */
  135. /* Private types -------------------------------------------------------------*/
  136. /** @defgroup CRYPEx_Private_Types CRYPEx Private Types
  137. * @{
  138. */
  139. /**
  140. * @}
  141. */
  142. /* Private variables ---------------------------------------------------------*/
  143. /** @defgroup CRYPEx_Private_Variables CRYPEx Private Variables
  144. * @{
  145. */
  146. /**
  147. * @}
  148. */
  149. /* Private constants ---------------------------------------------------------*/
  150. /** @defgroup CRYPEx_Private_Constants CRYPEx Private Constants
  151. * @{
  152. */
  153. /**
  154. * @}
  155. */
  156. /* Private macros ------------------------------------------------------------*/
  157. /** @defgroup CRYPEx_Private_Macros CRYPEx Private Macros
  158. * @{
  159. */
  160. /**
  161. * @}
  162. */
  163. /* Private functions ---------------------------------------------------------*/
  164. /** @defgroup CRYPEx_Private_Functions CRYPEx Private Functions
  165. * @{
  166. */
  167. /**
  168. * @}
  169. */
  170. /**
  171. * @}
  172. */
  173. #endif /* CRYP */
  174. #if defined (AES)
  175. /** @addtogroup CRYPEx_Exported_Functions
  176. * @{
  177. */
  178. /** @addtogroup CRYPEx_Exported_Functions_Group1
  179. * @{
  180. */
  181. /* CallBack functions ********************************************************/
  182. void HAL_CRYPEx_ComputationCpltCallback(CRYP_HandleTypeDef *hcryp);
  183. /**
  184. * @}
  185. */
  186. /** @addtogroup CRYPEx_Exported_Functions_Group2
  187. * @{
  188. */
  189. /* AES encryption/decryption processing functions ****************************/
  190. HAL_StatusTypeDef HAL_CRYPEx_AES(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData, uint32_t Timeout);
  191. HAL_StatusTypeDef HAL_CRYPEx_AES_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData);
  192. HAL_StatusTypeDef HAL_CRYPEx_AES_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData);
  193. /* AES encryption/decryption/authentication processing functions *************/
  194. HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData, uint32_t Timeout);
  195. HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData);
  196. HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData);
  197. /**
  198. * @}
  199. */
  200. /** @addtogroup CRYPEx_Exported_Functions_Group3
  201. * @{
  202. */
  203. /* AES suspension/resumption functions ***************************************/
  204. void HAL_CRYPEx_Read_IVRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output);
  205. void HAL_CRYPEx_Write_IVRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input);
  206. void HAL_CRYPEx_Read_SuspendRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output);
  207. void HAL_CRYPEx_Write_SuspendRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input);
  208. void HAL_CRYPEx_Read_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output, uint32_t KeySize);
  209. void HAL_CRYPEx_Write_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint32_t KeySize);
  210. void HAL_CRYPEx_Read_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Output);
  211. void HAL_CRYPEx_Write_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Input);
  212. void HAL_CRYPEx_ProcessSuspend(CRYP_HandleTypeDef *hcryp);
  213. /**
  214. * @}
  215. */
  216. /**
  217. * @}
  218. */
  219. /* Private functions -----------------------------------------------------------*/
  220. /** @addtogroup CRYPEx_Private_Functions CRYPEx Private Functions
  221. * @{
  222. */
  223. HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp);
  224. /**
  225. * @}
  226. */
  227. #endif /* AES */
  228. /**
  229. * @}
  230. */
  231. #ifdef __cplusplus
  232. }
  233. #endif
  234. #endif /* __STM32F7xx_HAL_CRYP_EX_H */
  235. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/