2 ******************************************************************************
3 * @file stm32f7xx_hal_cryp.h
4 * @author MCD Application Team
7 * @brief Header file of CRYP HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F7xx_HAL_CRYP_H
40 #define __STM32F7xx_HAL_CRYP_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f7xx_hal_def.h"
50 /** @addtogroup STM32F7xx_HAL_Driver
58 /* Exported types ------------------------------------------------------------*/
60 /** @defgroup CRYP_Exported_Types CRYP Exported Types
64 /** @defgroup CRYP_Exported_Types_Group1 CRYP Configuration Structure definition
70 uint32_t DataType
; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
71 This parameter can be a value of @ref CRYP_Data_Type */
73 uint32_t KeySize
; /*!< Used only in AES mode only : 128, 192 or 256 bit key length.
74 This parameter can be a value of @ref CRYP_Key_Size */
76 uint8_t* pKey
; /*!< The key used for encryption/decryption */
78 uint8_t* pInitVect
; /*!< The initialization vector used also as initialization
79 counter in CTR mode */
81 uint8_t IVSize
; /*!< The size of initialization vector.
82 This parameter (called nonce size in CCM) is used only
83 in AES-128/192/256 encryption/decryption CCM mode */
85 uint8_t TagSize
; /*!< The size of returned authentication TAG.
86 This parameter is used only in AES-128/192/256
87 encryption/decryption CCM mode */
89 uint8_t* Header
; /*!< The header used in GCM and CCM modes */
91 uint32_t HeaderSize
; /*!< The size of header buffer in bytes */
93 uint8_t* pScratch
; /*!< Scratch buffer used to append the header. It's size must be equal to header size + 21 bytes.
94 This parameter is used only in AES-128/192/256 encryption/decryption CCM mode */
101 /** @defgroup CRYP_Exported_Types_Group2 CRYP State structures definition
108 HAL_CRYP_STATE_RESET
= 0x00U
, /*!< CRYP not yet initialized or disabled */
109 HAL_CRYP_STATE_READY
= 0x01U
, /*!< CRYP initialized and ready for use */
110 HAL_CRYP_STATE_BUSY
= 0x02U
, /*!< CRYP internal processing is ongoing */
111 HAL_CRYP_STATE_TIMEOUT
= 0x03U
, /*!< CRYP timeout state */
112 HAL_CRYP_STATE_ERROR
= 0x04U
/*!< CRYP error state */
113 }HAL_CRYP_STATETypeDef
;
119 /** @defgroup CRYP_Exported_Types_Group3 CRYP phase structures definition
126 HAL_CRYP_PHASE_READY
= 0x01U
, /*!< CRYP peripheral is ready for initialization. */
127 HAL_CRYP_PHASE_PROCESS
= 0x02U
, /*!< CRYP peripheral is in processing phase */
128 HAL_CRYP_PHASE_FINAL
= 0x03U
/*!< CRYP peripheral is in final phase
129 This is relevant only with CCM and GCM modes */
136 /** @defgroup CRYP_Exported_Types_Group4 CRYP handle Structure definition
142 CRYP_TypeDef
*Instance
; /*!< CRYP registers base address */
144 CRYP_InitTypeDef Init
; /*!< CRYP required parameters */
146 uint8_t *pCrypInBuffPtr
; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
148 uint8_t *pCrypOutBuffPtr
; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
150 __IO
uint16_t CrypInCount
; /*!< Counter of input data */
152 __IO
uint16_t CrypOutCount
; /*!< Counter of output data */
154 HAL_StatusTypeDef Status
; /*!< CRYP peripheral status */
156 HAL_PhaseTypeDef Phase
; /*!< CRYP peripheral phase */
158 DMA_HandleTypeDef
*hdmain
; /*!< CRYP In DMA handle parameters */
160 DMA_HandleTypeDef
*hdmaout
; /*!< CRYP Out DMA handle parameters */
162 HAL_LockTypeDef Lock
; /*!< CRYP locking object */
164 __IO HAL_CRYP_STATETypeDef State
; /*!< CRYP peripheral state */
175 /* Exported constants --------------------------------------------------------*/
176 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
180 /** @defgroup CRYP_Key_Size CRYP Key Size
183 #define CRYP_KEYSIZE_128B ((uint32_t)0x00000000U)
184 #define CRYP_KEYSIZE_192B CRYP_CR_KEYSIZE_0
185 #define CRYP_KEYSIZE_256B CRYP_CR_KEYSIZE_1
190 /** @defgroup CRYP_Data_Type CRYP Data Type
193 #define CRYP_DATATYPE_32B ((uint32_t)0x00000000U)
194 #define CRYP_DATATYPE_16B CRYP_CR_DATATYPE_0
195 #define CRYP_DATATYPE_8B CRYP_CR_DATATYPE_1
196 #define CRYP_DATATYPE_1B CRYP_CR_DATATYPE
201 /** @defgroup CRYP_Exported_Constants_Group3 CRYP CRYP_AlgoModeDirection
204 #define CRYP_CR_ALGOMODE_DIRECTION ((uint32_t)0x0008003CU)
205 #define CRYP_CR_ALGOMODE_TDES_ECB_ENCRYPT ((uint32_t)0x00000000U)
206 #define CRYP_CR_ALGOMODE_TDES_ECB_DECRYPT ((uint32_t)0x00000004U)
207 #define CRYP_CR_ALGOMODE_TDES_CBC_ENCRYPT ((uint32_t)0x00000008U)
208 #define CRYP_CR_ALGOMODE_TDES_CBC_DECRYPT ((uint32_t)0x0000000CU)
209 #define CRYP_CR_ALGOMODE_DES_ECB_ENCRYPT ((uint32_t)0x00000010U)
210 #define CRYP_CR_ALGOMODE_DES_ECB_DECRYPT ((uint32_t)0x00000014U)
211 #define CRYP_CR_ALGOMODE_DES_CBC_ENCRYPT ((uint32_t)0x00000018U)
212 #define CRYP_CR_ALGOMODE_DES_CBC_DECRYPT ((uint32_t)0x0000001CU)
213 #define CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT ((uint32_t)0x00000020U)
214 #define CRYP_CR_ALGOMODE_AES_ECB_DECRYPT ((uint32_t)0x00000024U)
215 #define CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT ((uint32_t)0x00000028U)
216 #define CRYP_CR_ALGOMODE_AES_CBC_DECRYPT ((uint32_t)0x0000002CU)
217 #define CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT ((uint32_t)0x00000030U)
218 #define CRYP_CR_ALGOMODE_AES_CTR_DECRYPT ((uint32_t)0x00000034U)
223 /** @defgroup CRYP_Exported_Constants_Group4 CRYP CRYP_Interrupt
226 #define CRYP_IT_INI ((uint32_t)CRYP_IMSCR_INIM) /*!< Input FIFO Interrupt */
227 #define CRYP_IT_OUTI ((uint32_t)CRYP_IMSCR_OUTIM) /*!< Output FIFO Interrupt */
232 /** @defgroup CRYP_Exported_Constants_Group5 CRYP CRYP_Flags
235 #define CRYP_FLAG_BUSY ((uint32_t)0x00000010U) /*!< The CRYP core is currently
236 processing a block of data
237 or a key preparation (for
239 #define CRYP_FLAG_IFEM ((uint32_t)0x00000001U) /*!< Input FIFO is empty */
240 #define CRYP_FLAG_IFNF ((uint32_t)0x00000002U) /*!< Input FIFO is not Full */
241 #define CRYP_FLAG_OFNE ((uint32_t)0x00000004U) /*!< Output FIFO is not empty */
242 #define CRYP_FLAG_OFFU ((uint32_t)0x00000008U) /*!< Output FIFO is Full */
243 #define CRYP_FLAG_OUTRIS ((uint32_t)0x01000002U) /*!< Output FIFO service raw
245 #define CRYP_FLAG_INRIS ((uint32_t)0x01000001U) /*!< Input FIFO service raw
255 /* Exported macro ------------------------------------------------------------*/
256 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
260 /** @brief Reset CRYP handle state
261 * @param __HANDLE__: specifies the CRYP handle.
264 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
267 * @brief Enable/Disable the CRYP peripheral.
268 * @param __HANDLE__: specifies the CRYP handle.
271 #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_CRYPEN)
272 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~CRYP_CR_CRYPEN)
275 * @brief Flush the data FIFO.
276 * @param __HANDLE__: specifies the CRYP handle.
279 #define __HAL_CRYP_FIFO_FLUSH(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_FFLUSH)
282 * @brief Set the algorithm mode: AES-ECB, AES-CBC, AES-CTR, DES-ECB, DES-CBC.
283 * @param __HANDLE__: specifies the CRYP handle.
284 * @param MODE: The algorithm mode.
287 #define __HAL_CRYP_SET_MODE(__HANDLE__, MODE) ((__HANDLE__)->Instance->CR |= (uint32_t)(MODE))
289 /** @brief Check whether the specified CRYP flag is set or not.
290 * @param __HANDLE__: specifies the CRYP handle.
291 * @param __FLAG__: specifies the flag to check.
292 * This parameter can be one of the following values:
293 * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data
294 * or a key preparation (for AES decryption).
295 * @arg CRYP_FLAG_IFEM: Input FIFO is empty
296 * @arg CRYP_FLAG_IFNF: Input FIFO is not full
297 * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending
298 * @arg CRYP_FLAG_OFNE: Output FIFO is not empty
299 * @arg CRYP_FLAG_OFFU: Output FIFO is full
300 * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending
301 * @retval The new state of __FLAG__ (TRUE or FALSE).
304 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 24)) == 0x01U)?((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \
305 ((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)))
307 /** @brief Check whether the specified CRYP interrupt is set or not.
308 * @param __HANDLE__: specifies the CRYP handle.
309 * @param __INTERRUPT__: specifies the interrupt to check.
310 * This parameter can be one of the following values:
311 * @arg CRYP_IT_INRIS: Input FIFO service raw interrupt is pending
312 * @arg CRYP_IT_OUTRIS: Output FIFO service raw interrupt is pending
313 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
315 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->MISR & (__INTERRUPT__)) == (__INTERRUPT__))
318 * @brief Enable the CRYP interrupt.
319 * @param __HANDLE__: specifies the CRYP handle.
320 * @param __INTERRUPT__: CRYP Interrupt.
323 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) |= (__INTERRUPT__))
326 * @brief Disable the CRYP interrupt.
327 * @param __HANDLE__: specifies the CRYP handle.
328 * @param __INTERRUPT__: CRYP interrupt.
331 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) &= ~(__INTERRUPT__))
337 /* Include CRYP HAL Extension module */
338 #include "stm32f7xx_hal_cryp_ex.h"
340 /* Exported functions --------------------------------------------------------*/
341 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
345 /** @addtogroup CRYP_Exported_Functions_Group1
348 HAL_StatusTypeDef
HAL_CRYP_Init(CRYP_HandleTypeDef
*hcryp
);
349 HAL_StatusTypeDef
HAL_CRYP_DeInit(CRYP_HandleTypeDef
*hcryp
);
350 void HAL_CRYP_MspInit(CRYP_HandleTypeDef
*hcryp
);
351 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef
*hcryp
);
356 /** @addtogroup CRYP_Exported_Functions_Group2
359 /* AES encryption/decryption using polling ***********************************/
360 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
361 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
362 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
363 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
364 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
365 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
367 /* AES encryption/decryption using interrupt *********************************/
368 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
369 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
370 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
371 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
372 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
373 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
375 /* AES encryption/decryption using DMA ***************************************/
376 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
377 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
378 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
379 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
380 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
381 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
386 /** @addtogroup CRYP_Exported_Functions_Group3
389 /* DES encryption/decryption using polling ***********************************/
390 HAL_StatusTypeDef
HAL_CRYP_DESECB_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
391 HAL_StatusTypeDef
HAL_CRYP_DESECB_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
392 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
393 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
395 /* DES encryption/decryption using interrupt *********************************/
396 HAL_StatusTypeDef
HAL_CRYP_DESECB_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
397 HAL_StatusTypeDef
HAL_CRYP_DESECB_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
398 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
399 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
401 /* DES encryption/decryption using DMA ***************************************/
402 HAL_StatusTypeDef
HAL_CRYP_DESECB_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
403 HAL_StatusTypeDef
HAL_CRYP_DESECB_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
404 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
405 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
410 /** @addtogroup CRYP_Exported_Functions_Group4
413 /* TDES encryption/decryption using polling **********************************/
414 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
415 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
416 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
417 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
419 /* TDES encryption/decryption using interrupt ********************************/
420 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
421 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
422 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
423 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
425 /* TDES encryption/decryption using DMA **************************************/
426 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
427 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
428 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
429 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
434 /** @addtogroup CRYP_Exported_Functions_Group5
437 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef
*hcryp
);
438 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef
*hcryp
);
439 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef
*hcryp
);
444 /** @addtogroup CRYP_Exported_Functions_Group6
447 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef
*hcryp
);
452 /** @addtogroup CRYP_Exported_Functions_Group7
455 HAL_CRYP_STATETypeDef
HAL_CRYP_GetState(CRYP_HandleTypeDef
*hcryp
);
464 /* Private types -------------------------------------------------------------*/
465 /** @defgroup CRYP_Private_Types CRYP Private Types
473 /* Private variables ---------------------------------------------------------*/
474 /** @defgroup CRYP_Private_Variables CRYP Private Variables
482 /* Private constants ---------------------------------------------------------*/
483 /** @defgroup CRYP_Private_Constants CRYP Private Constants
486 #define CRYP_FLAG_MASK ((uint32_t)0x0000001F)
491 /* Private macros ------------------------------------------------------------*/
492 /** @defgroup CRYP_Private_Macros CRYP Private Macros
496 #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \
497 ((__KEYSIZE__) == CRYP_KEYSIZE_192B) || \
498 ((__KEYSIZE__) == CRYP_KEYSIZE_256B))
501 #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \
502 ((__DATATYPE__) == CRYP_DATATYPE_16B) || \
503 ((__DATATYPE__) == CRYP_DATATYPE_8B) || \
504 ((__DATATYPE__) == CRYP_DATATYPE_1B))
511 /* Private functions ---------------------------------------------------------*/
512 /** @defgroup CRYP_Private_Functions CRYP Private Functions
532 /** @addtogroup STM32F7xx_HAL_Driver
540 /* Exported types ------------------------------------------------------------*/
541 /** @defgroup CRYP_Exported_Types CRYP Exported Types
546 * @brief CRYP Configuration Structure definition
550 uint32_t DataType
; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
551 This parameter can be a value of @ref CRYP_Data_Type */
553 uint32_t KeySize
; /*!< 128 or 256-bit key length.
554 This parameter can be a value of @ref CRYP_Key_Size */
556 uint32_t OperatingMode
; /*!< AES operating mode.
557 This parameter can be a value of @ref CRYP_AES_OperatingMode */
559 uint32_t ChainingMode
; /*!< AES chaining mode.
560 This parameter can be a value of @ref CRYP_AES_ChainingMode */
562 uint32_t KeyWriteFlag
; /*!< Allows to bypass or not key write-up before decryption.
563 This parameter can be a value of @ref CRYP_Key_Write */
565 uint32_t GCMCMACPhase
; /*!< Indicates the processing phase of the Galois Counter Mode (GCM),
566 Galois Message Authentication Code (GMAC) or Cipher Message
567 Authentication Code (CMAC) or Counter with Cipher Mode (CCM) when
568 the latter is applicable.
569 This parameter can be a value of @ref CRYP_GCM_CMAC_Phase */
571 uint8_t* pKey
; /*!< Encryption/Decryption Key */
573 uint8_t* pInitVect
; /*!< Initialization Vector used for CTR, CBC, GCM/GMAC, CMAC,
574 (and CCM when applicable) modes */
576 uint8_t* Header
; /*!< Header used in GCM/GMAC, CMAC (and CCM when applicable) modes */
578 uint64_t HeaderSize
; /*!< Header size in bytes */
583 * @brief HAL CRYP State structures definition
587 HAL_CRYP_STATE_RESET
= 0x00, /*!< CRYP not yet initialized or disabled */
588 HAL_CRYP_STATE_READY
= 0x01, /*!< CRYP initialized and ready for use */
589 HAL_CRYP_STATE_BUSY
= 0x02, /*!< CRYP internal processing is ongoing */
590 HAL_CRYP_STATE_TIMEOUT
= 0x03, /*!< CRYP timeout state */
591 HAL_CRYP_STATE_ERROR
= 0x04, /*!< CRYP error state */
592 HAL_CRYP_STATE_SUSPENDED
= 0x05 /*!< CRYP suspended */
593 }HAL_CRYP_STATETypeDef
;
596 * @brief HAL CRYP phase structures definition
600 HAL_CRYP_PHASE_READY
= 0x01, /*!< CRYP peripheral is ready for initialization. */
601 HAL_CRYP_PHASE_PROCESS
= 0x02, /*!< CRYP peripheral is in processing phase */
602 HAL_CRYP_PHASE_START
= 0x03, /*!< CRYP peripheral has been initialized but
603 GCM/GMAC/CMAC(/CCM) initialization phase has not started */
604 HAL_CRYP_PHASE_INIT_OVER
= 0x04, /*!< GCM/GMAC/CMAC(/CCM) init phase has been carried out */
605 HAL_CRYP_PHASE_HEADER_OVER
= 0x05, /*!< GCM/GMAC/CMAC(/CCM) header phase has been carried out */
606 HAL_CRYP_PHASE_PAYLOAD_OVER
= 0x06, /*!< GCM(/CCM) payload phase has been carried out */
607 HAL_CRYP_PHASE_FINAL_OVER
= 0x07, /*!< GCM/GMAC/CMAC(/CCM) final phase has been carried out */
608 HAL_CRYP_PHASE_HEADER_SUSPENDED
= 0x08, /*!< GCM/GMAC/CMAC(/CCM) header phase has been suspended */
609 HAL_CRYP_PHASE_PAYLOAD_SUSPENDED
= 0x09, /*!< GCM(/CCM) payload phase has been suspended */
610 HAL_CRYP_PHASE_NOT_USED
= 0x0a /*!< Phase is irrelevant to the current chaining mode */
614 * @brief HAL CRYP mode suspend definitions
618 HAL_CRYP_SUSPEND_NONE
= 0x00, /*!< CRYP peripheral suspension not requested */
619 HAL_CRYP_SUSPEND
= 0x01 /*!< CRYP peripheral suspension requested */
624 * @brief HAL CRYP Error Codes definition
626 #define HAL_CRYP_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
627 #define HAL_CRYP_WRITE_ERROR ((uint32_t)0x00000001) /*!< Write error */
628 #define HAL_CRYP_READ_ERROR ((uint32_t)0x00000002) /*!< Read error */
629 #define HAL_CRYP_DMA_ERROR ((uint32_t)0x00000004) /*!< DMA error */
630 #define HAL_CRYP_BUSY_ERROR ((uint32_t)0x00000008) /*!< Busy flag error */
633 * @brief CRYP handle Structure definition
637 AES_TypeDef
*Instance
; /*!< Register base address */
639 CRYP_InitTypeDef Init
; /*!< CRYP initialization parameters */
641 uint8_t *pCrypInBuffPtr
; /*!< Pointer to CRYP processing (encryption, decryption,...) input buffer */
643 uint8_t *pCrypOutBuffPtr
; /*!< Pointer to CRYP processing (encryption, decryption,...) output buffer */
645 uint32_t CrypInCount
; /*!< Input data size in bytes or, after suspension, the remaining
646 number of bytes to process */
648 uint32_t CrypOutCount
; /*!< Output data size in bytes */
650 HAL_PhaseTypeDef Phase
; /*!< CRYP peripheral processing phase for GCM, GMAC, CMAC
651 (or CCM when applicable) modes.
652 Indicates the last phase carried out to ease
655 DMA_HandleTypeDef
*hdmain
; /*!< CRYP peripheral Input DMA handle parameters */
657 DMA_HandleTypeDef
*hdmaout
; /*!< CRYP peripheral Output DMA handle parameters */
659 HAL_LockTypeDef Lock
; /*!< CRYP locking object */
661 __IO HAL_CRYP_STATETypeDef State
; /*!< CRYP peripheral state */
663 __IO
uint32_t ErrorCode
; /*!< CRYP peripheral error code */
665 HAL_SuspendTypeDef SuspendRequest
; /*!< CRYP peripheral suspension request flag */
673 /* Exported constants --------------------------------------------------------*/
674 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
678 /** @defgroup CRYP_Key_Size Key size selection
681 #define CRYP_KEYSIZE_128B ((uint32_t)0x00000000) /*!< 128-bit long key */
682 #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */
687 /** @defgroup CRYP_Data_Type AES Data Type selection
690 #define CRYP_DATATYPE_32B ((uint32_t)0x00000000) /*!< 32-bit data type (no swapping) */
691 #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */
692 #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */
693 #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */
698 /** @defgroup CRYP_AES_State AES Enable state
701 #define CRYP_AES_DISABLE ((uint32_t)0x00000000) /*!< Disable AES */
702 #define CRYP_AES_ENABLE AES_CR_EN /*!< Enable AES */
707 /** @defgroup CRYP_AES_OperatingMode AES operating mode
710 #define CRYP_ALGOMODE_ENCRYPT ((uint32_t)0x00000000) /*!< Encryption mode */
711 #define CRYP_ALGOMODE_KEYDERIVATION AES_CR_MODE_0 /*!< Key derivation mode */
712 #define CRYP_ALGOMODE_DECRYPT AES_CR_MODE_1 /*!< Decryption */
713 #define CRYP_ALGOMODE_KEYDERIVATION_DECRYPT AES_CR_MODE /*!< Key derivation and decryption */
714 #define CRYP_ALGOMODE_TAG_GENERATION ((uint32_t)0x00000000) /*!< GMAC or CMAC authentication tag generation */
719 /** @defgroup CRYP_AES_ChainingMode AES chaining mode
722 #define CRYP_CHAINMODE_AES_ECB ((uint32_t)0x00000000) /*!< Electronic codebook chaining algorithm */
723 #define CRYP_CHAINMODE_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */
724 #define CRYP_CHAINMODE_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */
725 #define CRYP_CHAINMODE_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */
726 #define CRYP_CHAINMODE_AES_CMAC AES_CR_CHMOD_2 /*!< Cipher message authentication code */
727 #if defined(AES_CR_NPBLB)
728 #define CRYP_CHAINMODE_AES_CCM_CMAC AES_CR_CHMOD_2 /*!< Counter with Cipher Mode - Cipher message authentication code */
734 /** @defgroup CRYP_Key_Write AES decryption key write-up flag
737 #define CRYP_KEY_WRITE_ENABLE ((uint32_t)0x00000000) /*!< Enable decryption key writing */
738 #define CRYP_KEY_WRITE_DISABLE ((uint32_t)0x00000001) /*!< Disable decryption key writing */
743 /** @defgroup CRYP_DMAIN DMA Input phase management enable state
746 #define CRYP_DMAIN_DISABLE ((uint32_t)0x00000000) /*!< Disable DMA Input phase management */
747 #define CRYP_DMAIN_ENABLE AES_CR_DMAINEN /*!< Enable DMA Input phase management */
752 /** @defgroup CRYP_DMAOUT DMA Output phase management enable state
755 #define CRYP_DMAOUT_DISABLE ((uint32_t)0x00000000) /*!< Disable DMA Output phase management */
756 #define CRYP_DMAOUT_ENABLE AES_CR_DMAOUTEN /*!< Enable DMA Output phase management */
762 /** @defgroup CRYP_GCM_CMAC_Phase GCM/GMAC and CMAC processing phase selection
765 #define CRYP_GCM_INIT_PHASE ((uint32_t)0x00000000) /*!< GCM/GMAC (or CCM) init phase */
766 #define CRYP_GCMCMAC_HEADER_PHASE AES_CR_GCMPH_0 /*!< GCM/GMAC or (CCM/)CMAC header phase */
767 #define CRYP_GCM_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< GCM(/CCM) payload phase */
768 #define CRYP_GCMCMAC_FINAL_PHASE AES_CR_GCMPH /*!< GCM/GMAC or (CCM/)CMAC final phase */
769 /* Definitions duplication for code readibility's sake:
770 supported or not supported chain modes are not specified for each phase */
771 #define CRYP_INIT_PHASE ((uint32_t)0x00000000) /*!< Init phase */
772 #define CRYP_HEADER_PHASE AES_CR_GCMPH_0 /*!< Header phase */
773 #define CRYP_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< Payload phase */
774 #define CRYP_FINAL_PHASE AES_CR_GCMPH /*!< Final phase */
779 /** @defgroup CRYP_Flags AES status flags
783 #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */
784 #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */
785 #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */
786 #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */
791 /** @defgroup CRYP_Clear_Flags AES clearing flags
795 #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */
796 #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */
801 /** @defgroup AES_Interrupts_Enable AES Interrupts Enable bits
804 #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */
805 #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */
810 /** @defgroup CRYP_Interrupts_Flags AES Interrupts flags
813 #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */
814 #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */
815 #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */
824 /* Exported macros -----------------------------------------------------------*/
825 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
829 /** @brief Reset CRYP handle state.
830 * @param __HANDLE__: specifies the CRYP handle.
833 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
836 * @brief Enable the CRYP AES peripheral.
839 #define __HAL_CRYP_ENABLE() (AES->CR |= AES_CR_EN)
842 * @brief Disable the CRYP AES peripheral.
845 #define __HAL_CRYP_DISABLE() (AES->CR &= ~AES_CR_EN)
848 * @brief Set the algorithm operating mode.
849 * @param __OPERATING_MODE__: specifies the operating mode
850 * This parameter can be one of the following values:
851 * @arg @ref CRYP_ALGOMODE_ENCRYPT encryption
852 * @arg @ref CRYP_ALGOMODE_KEYDERIVATION key derivation
853 * @arg @ref CRYP_ALGOMODE_DECRYPT decryption
854 * @arg @ref CRYP_ALGOMODE_KEYDERIVATION_DECRYPT key derivation and decryption
857 #define __HAL_CRYP_SET_OPERATINGMODE(__OPERATING_MODE__) MODIFY_REG(AES->CR, AES_CR_MODE, (__OPERATING_MODE__))
861 * @brief Set the algorithm chaining mode.
862 * @param __CHAINING_MODE__: specifies the chaining mode
863 * This parameter can be one of the following values:
864 * @arg @ref CRYP_CHAINMODE_AES_ECB Electronic CodeBook
865 * @arg @ref CRYP_CHAINMODE_AES_CBC Cipher Block Chaining
866 * @arg @ref CRYP_CHAINMODE_AES_CTR CounTeR mode
867 * @arg @ref CRYP_CHAINMODE_AES_GCM_GMAC Galois Counter Mode or Galois Message Authentication Code
868 * @arg @ref CRYP_CHAINMODE_AES_CMAC Cipher Message Authentication Code (or Counter with Cipher Mode when applicable)
871 #define __HAL_CRYP_SET_CHAININGMODE(__CHAINING_MODE__) MODIFY_REG(AES->CR, AES_CR_CHMOD, (__CHAINING_MODE__))
875 /** @brief Check whether the specified CRYP status flag is set or not.
876 * @param __FLAG__: specifies the flag to check.
877 * This parameter can be one of the following values:
878 * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden
879 * @arg @ref CRYP_IT_WRERR Write Error
880 * @arg @ref CRYP_IT_RDERR Read Error
881 * @arg @ref CRYP_IT_CCF Computation Complete
882 * @retval The state of __FLAG__ (TRUE or FALSE).
884 #define __HAL_CRYP_GET_FLAG(__FLAG__) ((AES->SR & (__FLAG__)) == (__FLAG__))
887 /** @brief Clear the CRYP pending status flag.
888 * @param __FLAG__: specifies the flag to clear.
889 * This parameter can be one of the following values:
890 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
891 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
894 #define __HAL_CRYP_CLEAR_FLAG(__FLAG__) SET_BIT(AES->CR, (__FLAG__))
898 /** @brief Check whether the specified CRYP interrupt source is enabled or not.
899 * @param __INTERRUPT__: CRYP interrupt source to check
900 * This parameter can be one of the following values:
901 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
902 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
903 * @retval State of interruption (TRUE or FALSE).
905 #define __HAL_CRYP_GET_IT_SOURCE(__INTERRUPT__) ((AES->CR & (__INTERRUPT__)) == (__INTERRUPT__))
908 /** @brief Check whether the specified CRYP interrupt is set or not.
909 * @param __INTERRUPT__: specifies the interrupt to check.
910 * This parameter can be one of the following values:
911 * @arg @ref CRYP_IT_WRERR Write Error
912 * @arg @ref CRYP_IT_RDERR Read Error
913 * @arg @ref CRYP_IT_CCF Computation Complete
914 * @retval The state of __INTERRUPT__ (TRUE or FALSE).
916 #define __HAL_CRYP_GET_IT(__INTERRUPT__) ((AES->SR & (__INTERRUPT__)) == (__INTERRUPT__))
920 /** @brief Clear the CRYP pending interrupt.
921 * @param __INTERRUPT__: specifies the IT to clear.
922 * This parameter can be one of the following values:
923 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
924 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
927 #define __HAL_CRYP_CLEAR_IT(__INTERRUPT__) SET_BIT(AES->CR, (__INTERRUPT__))
931 * @brief Enable the CRYP interrupt.
932 * @param __INTERRUPT__: CRYP Interrupt.
933 * This parameter can be one of the following values:
934 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
935 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
938 #define __HAL_CRYP_ENABLE_IT(__INTERRUPT__) ((AES->CR) |= (__INTERRUPT__))
942 * @brief Disable the CRYP interrupt.
943 * @param __INTERRUPT__: CRYP Interrupt.
944 * This parameter can be one of the following values:
945 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
946 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
949 #define __HAL_CRYP_DISABLE_IT(__INTERRUPT__) ((AES->CR) &= ~(__INTERRUPT__))
955 /* Private macros --------------------------------------------------------*/
956 /** @addtogroup CRYP_Private_Macros CRYP Private Macros
961 * @brief Verify the key size length.
962 * @param __KEYSIZE__: Ciphering/deciphering algorithm key size.
963 * @retval SET (__KEYSIZE__ is a valid value) or RESET (__KEYSIZE__ is invalid)
965 #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \
966 ((__KEYSIZE__) == CRYP_KEYSIZE_256B))
969 * @brief Verify the input data type.
970 * @param __DATATYPE__: Ciphering/deciphering algorithm input data type.
971 * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid)
973 #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \
974 ((__DATATYPE__) == CRYP_DATATYPE_16B) || \
975 ((__DATATYPE__) == CRYP_DATATYPE_8B) || \
976 ((__DATATYPE__) == CRYP_DATATYPE_1B))
979 * @brief Verify the CRYP AES IP running mode.
980 * @param __MODE__: CRYP AES IP running mode.
981 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
983 #define IS_CRYP_AES(__MODE__) (((__MODE__) == CRYP_AES_DISABLE) || \
984 ((__MODE__) == CRYP_AES_ENABLE))
987 * @brief Verify the selected CRYP algorithm.
988 * @param __ALGOMODE__: Selected CRYP algorithm (ciphering, deciphering, key derivation or a combination of the latter).
989 * @retval SET (__ALGOMODE__ is valid) or RESET (__ALGOMODE__ is invalid)
991 #define IS_CRYP_ALGOMODE(__ALGOMODE__) (((__ALGOMODE__) == CRYP_ALGOMODE_ENCRYPT) || \
992 ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION) || \
993 ((__ALGOMODE__) == CRYP_ALGOMODE_DECRYPT) || \
994 ((__ALGOMODE__) == CRYP_ALGOMODE_TAG_GENERATION) || \
995 ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION_DECRYPT))
998 * @brief Verify the selected CRYP chaining algorithm.
999 * @param __CHAINMODE__: Selected CRYP chaining algorithm.
1000 * @retval SET (__CHAINMODE__ is valid) or RESET (__CHAINMODE__ is invalid)
1002 #if defined(AES_CR_NPBLB)
1003 #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \
1004 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \
1005 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \
1006 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \
1007 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CCM_CMAC))
1009 #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \
1010 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \
1011 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \
1012 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \
1013 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CMAC))
1017 * @brief Verify the deciphering key write option.
1018 * @param __WRITE__: deciphering key write option.
1019 * @retval SET (__WRITE__ is valid) or RESET (__WRITE__ is invalid)
1021 #define IS_CRYP_WRITE(__WRITE__) (((__WRITE__) == CRYP_KEY_WRITE_ENABLE) || \
1022 ((__WRITE__) == CRYP_KEY_WRITE_DISABLE))
1025 * @brief Verify the CRYP input data DMA mode.
1026 * @param __MODE__: CRYP input data DMA mode.
1027 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
1029 #define IS_CRYP_DMAIN(__MODE__) (((__MODE__) == CRYP_DMAIN_DISABLE) || \
1030 ((__MODE__) == CRYP_DMAIN_ENABLE))
1033 * @brief Verify the CRYP output data DMA mode.
1034 * @param __MODE__: CRYP output data DMA mode.
1035 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
1037 #define IS_CRYP_DMAOUT(__MODE__) (((__MODE__) == CRYP_DMAOUT_DISABLE) || \
1038 ((__MODE__) == CRYP_DMAOUT_ENABLE))
1041 * @brief Verify the CRYP AES ciphering/deciphering/authentication algorithm phase.
1042 * @param __PHASE__: CRYP AES ciphering/deciphering/authentication algorithm phase.
1043 * @retval SET (__PHASE__ is valid) or RESET (__PHASE__ is invalid)
1045 #define IS_CRYP_GCMCMAC_PHASE(__PHASE__) (((__PHASE__) == CRYP_GCM_INIT_PHASE) || \
1046 ((__PHASE__) == CRYP_GCMCMAC_HEADER_PHASE) || \
1047 ((__PHASE__) == CRYP_GCM_PAYLOAD_PHASE) || \
1048 ((__PHASE__) == CRYP_GCMCMAC_FINAL_PHASE))
1054 /* Include CRYP HAL Extended module */
1055 #include "stm32f7xx_hal_cryp_ex.h"
1057 /* Exported functions --------------------------------------------------------*/
1058 /** @addtogroup CRYP_Exported_Functions CRYP Exported Functions
1062 /** @addtogroup CRYP_Exported_Functions_Group1 Initialization and deinitialization functions
1066 /* Initialization/de-initialization functions ********************************/
1067 HAL_StatusTypeDef
HAL_CRYP_Init(CRYP_HandleTypeDef
*hcryp
);
1068 HAL_StatusTypeDef
HAL_CRYP_DeInit(CRYP_HandleTypeDef
*hcryp
);
1070 /* MSP initialization/de-initialization functions ****************************/
1071 void HAL_CRYP_MspInit(CRYP_HandleTypeDef
*hcryp
);
1072 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef
*hcryp
);
1078 /** @addtogroup CRYP_Exported_Functions_Group2 AES processing functions
1082 /* AES encryption/decryption processing functions ****************************/
1084 /* AES encryption/decryption using polling ***********************************/
1085 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
1086 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
1087 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
1088 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
1089 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
1090 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
1092 /* AES encryption/decryption using interrupt *********************************/
1093 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1094 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1095 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1096 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1097 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1098 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1100 /* AES encryption/decryption using DMA ***************************************/
1101 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1102 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1103 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1104 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1105 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1106 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1112 /** @addtogroup CRYP_Exported_Functions_Group3 Callback functions
1115 /* CallBack functions ********************************************************/
1116 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef
*hcryp
);
1117 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef
*hcryp
);
1118 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef
*hcryp
);
1124 /** @addtogroup CRYP_Exported_Functions_Group4 CRYP IRQ handler
1128 /* AES interrupt handling function *******************************************/
1129 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef
*hcryp
);
1135 /** @addtogroup CRYP_Exported_Functions_Group5 Peripheral State functions
1139 /* Peripheral State functions ************************************************/
1140 HAL_CRYP_STATETypeDef
HAL_CRYP_GetState(CRYP_HandleTypeDef
*hcryp
);
1141 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef
*hcryp
);
1166 #endif /* __STM32F7xx_HAL_CRYP_H */
1168 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/