2 ******************************************************************************
3 * @file stm32f4xx_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 __STM32F4xx_HAL_CRYP_H
40 #define __STM32F4xx_HAL_CRYP_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
52 /** @addtogroup STM32F4xx_HAL_Driver
60 /* Exported types ------------------------------------------------------------*/
62 /** @defgroup CRYP_Exported_Types CRYP Exported Types
66 /** @defgroup CRYP_Exported_Types_Group1 CRYP Configuration Structure definition
72 uint32_t DataType
; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
73 This parameter can be a value of @ref CRYP_Data_Type */
75 uint32_t KeySize
; /*!< Used only in AES mode only : 128, 192 or 256 bit key length.
76 This parameter can be a value of @ref CRYP_Key_Size */
78 uint8_t* pKey
; /*!< The key used for encryption/decryption */
80 uint8_t* pInitVect
; /*!< The initialization vector used also as initialization
81 counter in CTR mode */
83 uint8_t IVSize
; /*!< The size of initialization vector.
84 This parameter (called nonce size in CCM) is used only
85 in AES-128/192/256 encryption/decryption CCM mode */
87 uint8_t TagSize
; /*!< The size of returned authentication TAG.
88 This parameter is used only in AES-128/192/256
89 encryption/decryption CCM mode */
91 uint8_t* Header
; /*!< The header used in GCM and CCM modes */
93 uint32_t HeaderSize
; /*!< The size of header buffer in bytes */
95 uint8_t* pScratch
; /*!< Scratch buffer used to append the header. It's size must be equal to header size + 21 bytes.
96 This parameter is used only in AES-128/192/256 encryption/decryption CCM mode */
103 /** @defgroup CRYP_Exported_Types_Group2 CRYP State structures definition
110 HAL_CRYP_STATE_RESET
= 0x00U
, /*!< CRYP not yet initialized or disabled */
111 HAL_CRYP_STATE_READY
= 0x01U
, /*!< CRYP initialized and ready for use */
112 HAL_CRYP_STATE_BUSY
= 0x02U
, /*!< CRYP internal processing is ongoing */
113 HAL_CRYP_STATE_TIMEOUT
= 0x03U
, /*!< CRYP timeout state */
114 HAL_CRYP_STATE_ERROR
= 0x04U
/*!< CRYP error state */
115 }HAL_CRYP_STATETypeDef
;
121 /** @defgroup CRYP_Exported_Types_Group3 CRYP phase structures definition
128 HAL_CRYP_PHASE_READY
= 0x01U
, /*!< CRYP peripheral is ready for initialization. */
129 HAL_CRYP_PHASE_PROCESS
= 0x02U
, /*!< CRYP peripheral is in processing phase */
130 HAL_CRYP_PHASE_FINAL
= 0x03U
/*!< CRYP peripheral is in final phase
131 This is relevant only with CCM and GCM modes */
138 /** @defgroup CRYP_Exported_Types_Group4 CRYP handle Structure definition
144 CRYP_TypeDef
*Instance
; /*!< CRYP registers base address */
146 CRYP_InitTypeDef Init
; /*!< CRYP required parameters */
148 uint8_t *pCrypInBuffPtr
; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
150 uint8_t *pCrypOutBuffPtr
; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
152 __IO
uint16_t CrypInCount
; /*!< Counter of inputed data */
154 __IO
uint16_t CrypOutCount
; /*!< Counter of output data */
156 HAL_StatusTypeDef Status
; /*!< CRYP peripheral status */
158 HAL_PhaseTypeDef Phase
; /*!< CRYP peripheral phase */
160 DMA_HandleTypeDef
*hdmain
; /*!< CRYP In DMA handle parameters */
162 DMA_HandleTypeDef
*hdmaout
; /*!< CRYP Out DMA handle parameters */
164 HAL_LockTypeDef Lock
; /*!< CRYP locking object */
166 __IO HAL_CRYP_STATETypeDef State
; /*!< CRYP peripheral state */
177 /* Exported constants --------------------------------------------------------*/
178 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
182 /** @defgroup CRYP_Key_Size CRYP Key Size
185 #define CRYP_KEYSIZE_128B 0x00000000U
186 #define CRYP_KEYSIZE_192B CRYP_CR_KEYSIZE_0
187 #define CRYP_KEYSIZE_256B CRYP_CR_KEYSIZE_1
192 /** @defgroup CRYP_Data_Type CRYP Data Type
195 #define CRYP_DATATYPE_32B 0x00000000U
196 #define CRYP_DATATYPE_16B CRYP_CR_DATATYPE_0
197 #define CRYP_DATATYPE_8B CRYP_CR_DATATYPE_1
198 #define CRYP_DATATYPE_1B CRYP_CR_DATATYPE
203 /** @defgroup CRYP_Exported_Constants_Group3 CRYP CRYP_AlgoModeDirection
206 #define CRYP_CR_ALGOMODE_DIRECTION 0x0008003CU
207 #define CRYP_CR_ALGOMODE_TDES_ECB_ENCRYPT 0x00000000U
208 #define CRYP_CR_ALGOMODE_TDES_ECB_DECRYPT 0x00000004U
209 #define CRYP_CR_ALGOMODE_TDES_CBC_ENCRYPT 0x00000008U
210 #define CRYP_CR_ALGOMODE_TDES_CBC_DECRYPT 0x0000000CU
211 #define CRYP_CR_ALGOMODE_DES_ECB_ENCRYPT 0x00000010U
212 #define CRYP_CR_ALGOMODE_DES_ECB_DECRYPT 0x00000014U
213 #define CRYP_CR_ALGOMODE_DES_CBC_ENCRYPT 0x00000018U
214 #define CRYP_CR_ALGOMODE_DES_CBC_DECRYPT 0x0000001CU
215 #define CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT 0x00000020U
216 #define CRYP_CR_ALGOMODE_AES_ECB_DECRYPT 0x00000024U
217 #define CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT 0x00000028U
218 #define CRYP_CR_ALGOMODE_AES_CBC_DECRYPT 0x0000002CU
219 #define CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT 0x00000030U
220 #define CRYP_CR_ALGOMODE_AES_CTR_DECRYPT 0x00000034U
225 /** @defgroup CRYP_Exported_Constants_Group4 CRYP CRYP_Interrupt
228 #define CRYP_IT_INI ((uint32_t)CRYP_IMSCR_INIM) /*!< Input FIFO Interrupt */
229 #define CRYP_IT_OUTI ((uint32_t)CRYP_IMSCR_OUTIM) /*!< Output FIFO Interrupt */
234 /** @defgroup CRYP_Exported_Constants_Group5 CRYP CRYP_Flags
237 #define CRYP_FLAG_BUSY 0x00000010U /*!< The CRYP core is currently
238 processing a block of data
239 or a key preparation (for
241 #define CRYP_FLAG_IFEM 0x00000001U /*!< Input FIFO is empty */
242 #define CRYP_FLAG_IFNF 0x00000002U /*!< Input FIFO is not Full */
243 #define CRYP_FLAG_OFNE 0x00000004U /*!< Output FIFO is not empty */
244 #define CRYP_FLAG_OFFU 0x00000008U /*!< Output FIFO is Full */
245 #define CRYP_FLAG_OUTRIS 0x01000002U /*!< Output FIFO service raw
247 #define CRYP_FLAG_INRIS 0x01000001U /*!< Input FIFO service raw
257 /* Exported macro ------------------------------------------------------------*/
258 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
262 /** @brief Reset CRYP handle state
263 * @param __HANDLE__: specifies the CRYP handle.
266 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
269 * @brief Enable/Disable the CRYP peripheral.
270 * @param __HANDLE__: specifies the CRYP handle.
273 #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_CRYPEN)
274 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~CRYP_CR_CRYPEN)
277 * @brief Flush the data FIFO.
278 * @param __HANDLE__: specifies the CRYP handle.
281 #define __HAL_CRYP_FIFO_FLUSH(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_FFLUSH)
284 * @brief Set the algorithm mode: AES-ECB, AES-CBC, AES-CTR, DES-ECB, DES-CBC.
285 * @param __HANDLE__: specifies the CRYP handle.
286 * @param MODE: The algorithm mode.
289 #define __HAL_CRYP_SET_MODE(__HANDLE__, MODE) ((__HANDLE__)->Instance->CR |= (uint32_t)(MODE))
291 /** @brief Check whether the specified CRYP flag is set or not.
292 * @param __HANDLE__: specifies the CRYP handle.
293 * @param __FLAG__: specifies the flag to check.
294 * This parameter can be one of the following values:
295 * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data
296 * or a key preparation (for AES decryption).
297 * @arg CRYP_FLAG_IFEM: Input FIFO is empty
298 * @arg CRYP_FLAG_IFNF: Input FIFO is not full
299 * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending
300 * @arg CRYP_FLAG_OFNE: Output FIFO is not empty
301 * @arg CRYP_FLAG_OFFU: Output FIFO is full
302 * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending
303 * @retval The new state of __FLAG__ (TRUE or FALSE).
306 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 24U)) == 0x01U)?((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \
307 ((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)))
309 /** @brief Check whether the specified CRYP interrupt is set or not.
310 * @param __HANDLE__: specifies the CRYP handle.
311 * @param __INTERRUPT__: specifies the interrupt to check.
312 * This parameter can be one of the following values:
313 * @arg CRYP_IT_INRIS: Input FIFO service raw interrupt is pending
314 * @arg CRYP_IT_OUTRIS: Output FIFO service raw interrupt is pending
315 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
317 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->MISR & (__INTERRUPT__)) == (__INTERRUPT__))
320 * @brief Enable the CRYP interrupt.
321 * @param __HANDLE__: specifies the CRYP handle.
322 * @param __INTERRUPT__: CRYP Interrupt.
325 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) |= (__INTERRUPT__))
328 * @brief Disable the CRYP interrupt.
329 * @param __HANDLE__: specifies the CRYP handle.
330 * @param __INTERRUPT__: CRYP interrupt.
333 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) &= ~(__INTERRUPT__))
339 /* Include CRYP HAL Extension module */
340 #include "stm32f4xx_hal_cryp_ex.h"
342 /* Exported functions --------------------------------------------------------*/
343 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
347 /** @addtogroup CRYP_Exported_Functions_Group1
350 HAL_StatusTypeDef
HAL_CRYP_Init(CRYP_HandleTypeDef
*hcryp
);
351 HAL_StatusTypeDef
HAL_CRYP_DeInit(CRYP_HandleTypeDef
*hcryp
);
352 void HAL_CRYP_MspInit(CRYP_HandleTypeDef
*hcryp
);
353 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef
*hcryp
);
358 /** @addtogroup CRYP_Exported_Functions_Group2
361 /* AES encryption/decryption using polling ***********************************/
362 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
363 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
364 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
365 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
366 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
367 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
369 /* AES encryption/decryption using interrupt *********************************/
370 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
371 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
372 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
373 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
374 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
375 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
377 /* AES encryption/decryption using DMA ***************************************/
378 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
379 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
380 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
381 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
382 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
383 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
388 /** @addtogroup CRYP_Exported_Functions_Group3
391 /* DES encryption/decryption using polling ***********************************/
392 HAL_StatusTypeDef
HAL_CRYP_DESECB_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
393 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
394 HAL_StatusTypeDef
HAL_CRYP_DESECB_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
395 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
397 /* DES encryption/decryption using interrupt *********************************/
398 HAL_StatusTypeDef
HAL_CRYP_DESECB_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
399 HAL_StatusTypeDef
HAL_CRYP_DESECB_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
400 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
401 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
403 /* DES encryption/decryption using DMA ***************************************/
404 HAL_StatusTypeDef
HAL_CRYP_DESECB_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
405 HAL_StatusTypeDef
HAL_CRYP_DESECB_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
406 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
407 HAL_StatusTypeDef
HAL_CRYP_DESCBC_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
412 /** @addtogroup CRYP_Exported_Functions_Group4
415 /* TDES encryption/decryption using polling **********************************/
416 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
417 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
418 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
419 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
421 /* TDES encryption/decryption using interrupt ********************************/
422 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
423 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
424 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
425 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
427 /* TDES encryption/decryption using DMA **************************************/
428 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
429 HAL_StatusTypeDef
HAL_CRYP_TDESECB_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
430 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
431 HAL_StatusTypeDef
HAL_CRYP_TDESCBC_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
436 /** @addtogroup CRYP_Exported_Functions_Group5
439 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef
*hcryp
);
440 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef
*hcryp
);
441 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef
*hcryp
);
446 /** @addtogroup CRYP_Exported_Functions_Group6
449 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef
*hcryp
);
454 /** @addtogroup CRYP_Exported_Functions_Group7
457 HAL_CRYP_STATETypeDef
HAL_CRYP_GetState(CRYP_HandleTypeDef
*hcryp
);
466 /* Private types -------------------------------------------------------------*/
467 /** @defgroup CRYP_Private_Types CRYP Private Types
475 /* Private variables ---------------------------------------------------------*/
476 /** @defgroup CRYP_Private_Variables CRYP Private Variables
484 /* Private constants ---------------------------------------------------------*/
485 /** @defgroup CRYP_Private_Constants CRYP Private Constants
488 #define CRYP_FLAG_MASK 0x0000001FU
493 /* Private macros ------------------------------------------------------------*/
494 /** @defgroup CRYP_Private_Macros CRYP Private Macros
498 #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \
499 ((__KEYSIZE__) == CRYP_KEYSIZE_192B) || \
500 ((__KEYSIZE__) == CRYP_KEYSIZE_256B))
503 #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \
504 ((__DATATYPE__) == CRYP_DATATYPE_16B) || \
505 ((__DATATYPE__) == CRYP_DATATYPE_8B) || \
506 ((__DATATYPE__) == CRYP_DATATYPE_1B))
513 /* Private functions ---------------------------------------------------------*/
514 /** @defgroup CRYP_Private_Functions CRYP Private Functions
526 /** @addtogroup STM32F4xx_HAL_Driver
534 /* Exported types ------------------------------------------------------------*/
535 /** @defgroup CRYP_Exported_Types CRYP Exported Types
540 * @brief CRYP Configuration Structure definition
544 uint32_t DataType
; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
545 This parameter can be a value of @ref CRYP_Data_Type */
547 uint32_t KeySize
; /*!< 128 or 256-bit key length.
548 This parameter can be a value of @ref CRYP_Key_Size */
550 uint32_t OperatingMode
; /*!< AES operating mode.
551 This parameter can be a value of @ref CRYP_AES_OperatingMode */
553 uint32_t ChainingMode
; /*!< AES chaining mode.
554 This parameter can be a value of @ref CRYP_AES_ChainingMode */
556 uint32_t KeyWriteFlag
; /*!< Allows to bypass or not key write-up before decryption.
557 This parameter can be a value of @ref CRYP_Key_Write */
559 uint32_t GCMCMACPhase
; /*!< Indicates the processing phase of the Galois Counter Mode (GCM),
560 Galois Message Authentication Code (GMAC) or Cipher Message
561 Authentication Code (CMAC) or Counter with Cipher Mode (CCM) when
562 the latter is applicable.
563 This parameter can be a value of @ref CRYP_GCM_CMAC_Phase */
565 uint8_t* pKey
; /*!< Encryption/Decryption Key */
567 uint8_t* pInitVect
; /*!< Initialization Vector used for CTR, CBC, GCM/GMAC, CMAC,
568 (and CCM when applicable) modes */
570 uint8_t* Header
; /*!< Header used in GCM/GMAC, CMAC (and CCM when applicable) modes */
572 uint64_t HeaderSize
; /*!< Header size in bytes */
577 * @brief HAL CRYP State structures definition
581 HAL_CRYP_STATE_RESET
= 0x00U
, /*!< CRYP not yet initialized or disabled */
582 HAL_CRYP_STATE_READY
= 0x01U
, /*!< CRYP initialized and ready for use */
583 HAL_CRYP_STATE_BUSY
= 0x02U
, /*!< CRYP internal processing is ongoing */
584 HAL_CRYP_STATE_TIMEOUT
= 0x03U
, /*!< CRYP timeout state */
585 HAL_CRYP_STATE_ERROR
= 0x04U
, /*!< CRYP error state */
586 HAL_CRYP_STATE_SUSPENDED
= 0x05U
/*!< CRYP suspended */
587 }HAL_CRYP_STATETypeDef
;
590 * @brief HAL CRYP phase structures definition
594 HAL_CRYP_PHASE_READY
= 0x01U
, /*!< CRYP peripheral is ready for initialization. */
595 HAL_CRYP_PHASE_PROCESS
= 0x02U
, /*!< CRYP peripheral is in processing phase */
596 HAL_CRYP_PHASE_START
= 0x03U
, /*!< CRYP peripheral has been initialized but
597 GCM/GMAC/CMAC(/CCM) initialization phase has not started */
598 HAL_CRYP_PHASE_INIT_OVER
= 0x04U
, /*!< GCM/GMAC/CMAC(/CCM) init phase has been carried out */
599 HAL_CRYP_PHASE_HEADER_OVER
= 0x05U
, /*!< GCM/GMAC/CMAC(/CCM) header phase has been carried out */
600 HAL_CRYP_PHASE_PAYLOAD_OVER
= 0x06U
, /*!< GCM(/CCM) payload phase has been carried out */
601 HAL_CRYP_PHASE_FINAL_OVER
= 0x07U
, /*!< GCM/GMAC/CMAC(/CCM) final phase has been carried out */
602 HAL_CRYP_PHASE_HEADER_SUSPENDED
= 0x08U
, /*!< GCM/GMAC/CMAC(/CCM) header phase has been suspended */
603 HAL_CRYP_PHASE_PAYLOAD_SUSPENDED
= 0x09U
, /*!< GCM(/CCM) payload phase has been suspended */
604 HAL_CRYP_PHASE_NOT_USED
= 0x0AU
/*!< Phase is irrelevant to the current chaining mode */
608 * @brief HAL CRYP mode suspend definitions
612 HAL_CRYP_SUSPEND_NONE
= 0x00U
, /*!< CRYP peripheral suspension not requested */
613 HAL_CRYP_SUSPEND
= 0x01U
/*!< CRYP peripheral suspension requested */
618 * @brief HAL CRYP Error Codes definition
620 #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */
621 #define HAL_CRYP_WRITE_ERROR 0x00000001U /*!< Write error */
622 #define HAL_CRYP_READ_ERROR 0x00000002U /*!< Read error */
623 #define HAL_CRYP_DMA_ERROR 0x00000004U /*!< DMA error */
624 #define HAL_CRYP_BUSY_ERROR 0x00000008U /*!< Busy flag error */
627 * @brief CRYP handle Structure definition
631 AES_TypeDef
*Instance
; /*!< Register base address */
633 CRYP_InitTypeDef Init
; /*!< CRYP initialization parameters */
635 uint8_t *pCrypInBuffPtr
; /*!< Pointer to CRYP processing (encryption, decryption,...) input buffer */
637 uint8_t *pCrypOutBuffPtr
; /*!< Pointer to CRYP processing (encryption, decryption,...) output buffer */
639 uint32_t CrypInCount
; /*!< Input data size in bytes or, after suspension, the remaining
640 number of bytes to process */
642 uint32_t CrypOutCount
; /*!< Output data size in bytes */
644 HAL_PhaseTypeDef Phase
; /*!< CRYP peripheral processing phase for GCM, GMAC, CMAC
645 (or CCM when applicable) modes.
646 Indicates the last phase carried out to ease
649 DMA_HandleTypeDef
*hdmain
; /*!< CRYP peripheral Input DMA handle parameters */
651 DMA_HandleTypeDef
*hdmaout
; /*!< CRYP peripheral Output DMA handle parameters */
653 HAL_LockTypeDef Lock
; /*!< CRYP locking object */
655 __IO HAL_CRYP_STATETypeDef State
; /*!< CRYP peripheral state */
657 __IO
uint32_t ErrorCode
; /*!< CRYP peripheral error code */
659 HAL_SuspendTypeDef SuspendRequest
; /*!< CRYP peripheral suspension request flag */
667 /* Exported constants --------------------------------------------------------*/
668 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
672 /** @defgroup CRYP_Key_Size Key size selection
675 #define CRYP_KEYSIZE_128B 0x00000000U /*!< 128-bit long key */
676 #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */
681 /** @defgroup CRYP_Data_Type AES Data Type selection
684 #define CRYP_DATATYPE_32B 0x00000000U /*!< 32-bit data type (no swapping) */
685 #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */
686 #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */
687 #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */
692 /** @defgroup CRYP_AES_State AES Enable state
695 #define CRYP_AES_DISABLE 0x00000000U /*!< Disable AES */
696 #define CRYP_AES_ENABLE AES_CR_EN /*!< Enable AES */
701 /** @defgroup CRYP_AES_OperatingMode AES operating mode
704 #define CRYP_ALGOMODE_ENCRYPT 0x00000000U /*!< Encryption mode */
705 #define CRYP_ALGOMODE_KEYDERIVATION AES_CR_MODE_0 /*!< Key derivation mode */
706 #define CRYP_ALGOMODE_DECRYPT AES_CR_MODE_1 /*!< Decryption */
707 #define CRYP_ALGOMODE_KEYDERIVATION_DECRYPT AES_CR_MODE /*!< Key derivation and decryption */
708 #define CRYP_ALGOMODE_TAG_GENERATION 0x00000000U /*!< GMAC or CMAC authentication tag generation */
713 /** @defgroup CRYP_AES_ChainingMode AES chaining mode
716 #define CRYP_CHAINMODE_AES_ECB 0x00000000U /*!< Electronic codebook chaining algorithm */
717 #define CRYP_CHAINMODE_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */
718 #define CRYP_CHAINMODE_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */
719 #define CRYP_CHAINMODE_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */
720 #define CRYP_CHAINMODE_AES_CMAC AES_CR_CHMOD_2 /*!< Cipher message authentication code */
721 #if defined(AES_CR_NPBLB)
722 #define CRYP_CHAINMODE_AES_CCM_CMAC AES_CR_CHMOD_2 /*!< Counter with Cipher Mode - Cipher message authentication code */
728 /** @defgroup CRYP_Key_Write AES decryption key write-up flag
731 #define CRYP_KEY_WRITE_ENABLE 0x00000000U /*!< Enable decryption key writing */
732 #define CRYP_KEY_WRITE_DISABLE 0x00000001U /*!< Disable decryption key writing */
737 /** @defgroup CRYP_DMAIN DMA Input phase management enable state
740 #define CRYP_DMAIN_DISABLE 0x00000000U /*!< Disable DMA Input phase management */
741 #define CRYP_DMAIN_ENABLE AES_CR_DMAINEN /*!< Enable DMA Input phase management */
746 /** @defgroup CRYP_DMAOUT DMA Output phase management enable state
749 #define CRYP_DMAOUT_DISABLE 0x00000000U /*!< Disable DMA Output phase management */
750 #define CRYP_DMAOUT_ENABLE AES_CR_DMAOUTEN /*!< Enable DMA Output phase management */
756 /** @defgroup CRYP_GCM_CMAC_Phase GCM/GMAC and CMAC processing phase selection
759 #define CRYP_GCM_INIT_PHASE 0x00000000U /*!< GCM/GMAC (or CCM) init phase */
760 #define CRYP_GCMCMAC_HEADER_PHASE AES_CR_GCMPH_0 /*!< GCM/GMAC or (CCM/)CMAC header phase */
761 #define CRYP_GCM_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< GCM(/CCM) payload phase */
762 #define CRYP_GCMCMAC_FINAL_PHASE AES_CR_GCMPH /*!< GCM/GMAC or (CCM/)CMAC final phase */
763 /* Definitions duplication for code readibility's sake:
764 supported or not supported chain modes are not specified for each phase */
765 #define CRYP_INIT_PHASE 0x00000000U /*!< Init phase */
766 #define CRYP_HEADER_PHASE AES_CR_GCMPH_0 /*!< Header phase */
767 #define CRYP_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< Payload phase */
768 #define CRYP_FINAL_PHASE AES_CR_GCMPH /*!< Final phase */
773 /** @defgroup CRYP_Flags AES status flags
777 #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */
778 #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */
779 #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */
780 #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */
785 /** @defgroup CRYP_Clear_Flags AES clearing flags
789 #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */
790 #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */
795 /** @defgroup AES_Interrupts_Enable AES Interrupts Enable bits
798 #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */
799 #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */
804 /** @defgroup CRYP_Interrupts_Flags AES Interrupts flags
807 #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */
808 #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */
809 #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */
818 /* Exported macros -----------------------------------------------------------*/
819 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
823 /** @brief Reset CRYP handle state.
824 * @param __HANDLE__: specifies the CRYP handle.
827 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET)
830 * @brief Enable the CRYP AES peripheral.
833 #define __HAL_CRYP_ENABLE() (AES->CR |= AES_CR_EN)
836 * @brief Disable the CRYP AES peripheral.
839 #define __HAL_CRYP_DISABLE() (AES->CR &= ~AES_CR_EN)
842 * @brief Set the algorithm operating mode.
843 * @param __OPERATING_MODE__: specifies the operating mode
844 * This parameter can be one of the following values:
845 * @arg @ref CRYP_ALGOMODE_ENCRYPT encryption
846 * @arg @ref CRYP_ALGOMODE_KEYDERIVATION key derivation
847 * @arg @ref CRYP_ALGOMODE_DECRYPT decryption
848 * @arg @ref CRYP_ALGOMODE_KEYDERIVATION_DECRYPT key derivation and decryption
851 #define __HAL_CRYP_SET_OPERATINGMODE(__OPERATING_MODE__) MODIFY_REG(AES->CR, AES_CR_MODE, (__OPERATING_MODE__))
855 * @brief Set the algorithm chaining mode.
856 * @param __CHAINING_MODE__: specifies the chaining mode
857 * This parameter can be one of the following values:
858 * @arg @ref CRYP_CHAINMODE_AES_ECB Electronic CodeBook
859 * @arg @ref CRYP_CHAINMODE_AES_CBC Cipher Block Chaining
860 * @arg @ref CRYP_CHAINMODE_AES_CTR CounTeR mode
861 * @arg @ref CRYP_CHAINMODE_AES_GCM_GMAC Galois Counter Mode or Galois Message Authentication Code
862 * @arg @ref CRYP_CHAINMODE_AES_CMAC Cipher Message Authentication Code (or Counter with Cipher Mode when applicable)
865 #define __HAL_CRYP_SET_CHAININGMODE(__CHAINING_MODE__) MODIFY_REG(AES->CR, AES_CR_CHMOD, (__CHAINING_MODE__))
869 /** @brief Check whether the specified CRYP status flag is set or not.
870 * @param __FLAG__: specifies the flag to check.
871 * This parameter can be one of the following values:
872 * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden
873 * @arg @ref CRYP_IT_WRERR Write Error
874 * @arg @ref CRYP_IT_RDERR Read Error
875 * @arg @ref CRYP_IT_CCF Computation Complete
876 * @retval The state of __FLAG__ (TRUE or FALSE).
878 #define __HAL_CRYP_GET_FLAG(__FLAG__) ((AES->SR & (__FLAG__)) == (__FLAG__))
881 /** @brief Clear the CRYP pending status flag.
882 * @param __FLAG__: specifies the flag to clear.
883 * This parameter can be one of the following values:
884 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
885 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
888 #define __HAL_CRYP_CLEAR_FLAG(__FLAG__) SET_BIT(AES->CR, (__FLAG__))
892 /** @brief Check whether the specified CRYP interrupt source is enabled or not.
893 * @param __INTERRUPT__: CRYP interrupt source to check
894 * This parameter can be one of the following values:
895 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
896 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
897 * @retval State of interruption (TRUE or FALSE).
899 #define __HAL_CRYP_GET_IT_SOURCE(__INTERRUPT__) ((AES->CR & (__INTERRUPT__)) == (__INTERRUPT__))
902 /** @brief Check whether the specified CRYP interrupt is set or not.
903 * @param __INTERRUPT__: specifies the interrupt to check.
904 * This parameter can be one of the following values:
905 * @arg @ref CRYP_IT_WRERR Write Error
906 * @arg @ref CRYP_IT_RDERR Read Error
907 * @arg @ref CRYP_IT_CCF Computation Complete
908 * @retval The state of __INTERRUPT__ (TRUE or FALSE).
910 #define __HAL_CRYP_GET_IT(__INTERRUPT__) ((AES->SR & (__INTERRUPT__)) == (__INTERRUPT__))
914 /** @brief Clear the CRYP pending interrupt.
915 * @param __INTERRUPT__: specifies the IT to clear.
916 * This parameter can be one of the following values:
917 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
918 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
921 #define __HAL_CRYP_CLEAR_IT(__INTERRUPT__) SET_BIT(AES->CR, (__INTERRUPT__))
925 * @brief Enable the CRYP interrupt.
926 * @param __INTERRUPT__: CRYP Interrupt.
927 * This parameter can be one of the following values:
928 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
929 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
932 #define __HAL_CRYP_ENABLE_IT(__INTERRUPT__) ((AES->CR) |= (__INTERRUPT__))
936 * @brief Disable the CRYP interrupt.
937 * @param __INTERRUPT__: CRYP Interrupt.
938 * This parameter can be one of the following values:
939 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
940 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
943 #define __HAL_CRYP_DISABLE_IT(__INTERRUPT__) ((AES->CR) &= ~(__INTERRUPT__))
949 /* Private macros --------------------------------------------------------*/
950 /** @addtogroup CRYP_Private_Macros CRYP Private Macros
955 * @brief Verify the key size length.
956 * @param __KEYSIZE__: Ciphering/deciphering algorithm key size.
957 * @retval SET (__KEYSIZE__ is a valid value) or RESET (__KEYSIZE__ is invalid)
959 #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \
960 ((__KEYSIZE__) == CRYP_KEYSIZE_256B))
963 * @brief Verify the input data type.
964 * @param __DATATYPE__: Ciphering/deciphering algorithm input data type.
965 * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid)
967 #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \
968 ((__DATATYPE__) == CRYP_DATATYPE_16B) || \
969 ((__DATATYPE__) == CRYP_DATATYPE_8B) || \
970 ((__DATATYPE__) == CRYP_DATATYPE_1B))
973 * @brief Verify the CRYP AES IP running mode.
974 * @param __MODE__: CRYP AES IP running mode.
975 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
977 #define IS_CRYP_AES(__MODE__) (((__MODE__) == CRYP_AES_DISABLE) || \
978 ((__MODE__) == CRYP_AES_ENABLE))
981 * @brief Verify the selected CRYP algorithm.
982 * @param __ALGOMODE__: Selected CRYP algorithm (ciphering, deciphering, key derivation or a combination of the latter).
983 * @retval SET (__ALGOMODE__ is valid) or RESET (__ALGOMODE__ is invalid)
985 #define IS_CRYP_ALGOMODE(__ALGOMODE__) (((__ALGOMODE__) == CRYP_ALGOMODE_ENCRYPT) || \
986 ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION) || \
987 ((__ALGOMODE__) == CRYP_ALGOMODE_DECRYPT) || \
988 ((__ALGOMODE__) == CRYP_ALGOMODE_TAG_GENERATION) || \
989 ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION_DECRYPT))
992 * @brief Verify the selected CRYP chaining algorithm.
993 * @param __CHAINMODE__: Selected CRYP chaining algorithm.
994 * @retval SET (__CHAINMODE__ is valid) or RESET (__CHAINMODE__ is invalid)
996 #if defined(AES_CR_NPBLB)
997 #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \
998 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \
999 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \
1000 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \
1001 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CCM_CMAC))
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_CMAC))
1011 * @brief Verify the deciphering key write option.
1012 * @param __WRITE__: deciphering key write option.
1013 * @retval SET (__WRITE__ is valid) or RESET (__WRITE__ is invalid)
1015 #define IS_CRYP_WRITE(__WRITE__) (((__WRITE__) == CRYP_KEY_WRITE_ENABLE) || \
1016 ((__WRITE__) == CRYP_KEY_WRITE_DISABLE))
1019 * @brief Verify the CRYP input data DMA mode.
1020 * @param __MODE__: CRYP input data DMA mode.
1021 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
1023 #define IS_CRYP_DMAIN(__MODE__) (((__MODE__) == CRYP_DMAIN_DISABLE) || \
1024 ((__MODE__) == CRYP_DMAIN_ENABLE))
1027 * @brief Verify the CRYP output data DMA mode.
1028 * @param __MODE__: CRYP output data DMA mode.
1029 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
1031 #define IS_CRYP_DMAOUT(__MODE__) (((__MODE__) == CRYP_DMAOUT_DISABLE) || \
1032 ((__MODE__) == CRYP_DMAOUT_ENABLE))
1035 * @brief Verify the CRYP AES ciphering/deciphering/authentication algorithm phase.
1036 * @param __PHASE__: CRYP AES ciphering/deciphering/authentication algorithm phase.
1037 * @retval SET (__PHASE__ is valid) or RESET (__PHASE__ is invalid)
1039 #define IS_CRYP_GCMCMAC_PHASE(__PHASE__) (((__PHASE__) == CRYP_GCM_INIT_PHASE) || \
1040 ((__PHASE__) == CRYP_GCMCMAC_HEADER_PHASE) || \
1041 ((__PHASE__) == CRYP_GCM_PAYLOAD_PHASE) || \
1042 ((__PHASE__) == CRYP_GCMCMAC_FINAL_PHASE))
1048 /* Include CRYP HAL Extended module */
1049 #include "stm32f4xx_hal_cryp_ex.h"
1051 /* Exported functions --------------------------------------------------------*/
1052 /** @addtogroup CRYP_Exported_Functions CRYP Exported Functions
1056 /** @addtogroup CRYP_Exported_Functions_Group1 Initialization and deinitialization functions
1060 /* Initialization/de-initialization functions ********************************/
1061 HAL_StatusTypeDef
HAL_CRYP_Init(CRYP_HandleTypeDef
*hcryp
);
1062 HAL_StatusTypeDef
HAL_CRYP_DeInit(CRYP_HandleTypeDef
*hcryp
);
1064 /* MSP initialization/de-initialization functions ****************************/
1065 void HAL_CRYP_MspInit(CRYP_HandleTypeDef
*hcryp
);
1066 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef
*hcryp
);
1072 /** @addtogroup CRYP_Exported_Functions_Group2 AES processing functions
1076 /* AES encryption/decryption processing functions ****************************/
1078 /* AES encryption/decryption using polling ***********************************/
1079 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
1080 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
1081 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
1082 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
1083 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
, uint32_t Timeout
);
1084 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
, uint32_t Timeout
);
1086 /* AES encryption/decryption using interrupt *********************************/
1087 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1088 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1089 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1090 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1091 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1092 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1094 /* AES encryption/decryption using DMA ***************************************/
1095 HAL_StatusTypeDef
HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1096 HAL_StatusTypeDef
HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1097 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1098 HAL_StatusTypeDef
HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1099 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pPlainData
, uint16_t Size
, uint8_t *pCypherData
);
1100 HAL_StatusTypeDef
HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef
*hcryp
, uint8_t *pCypherData
, uint16_t Size
, uint8_t *pPlainData
);
1106 /** @addtogroup CRYP_Exported_Functions_Group3 Callback functions
1109 /* CallBack functions ********************************************************/
1110 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef
*hcryp
);
1111 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef
*hcryp
);
1112 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef
*hcryp
);
1118 /** @addtogroup CRYP_Exported_Functions_Group4 CRYP IRQ handler
1122 /* AES interrupt handling function *******************************************/
1123 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef
*hcryp
);
1129 /** @addtogroup CRYP_Exported_Functions_Group5 Peripheral State functions
1133 /* Peripheral State functions ************************************************/
1134 HAL_CRYP_STATETypeDef
HAL_CRYP_GetState(CRYP_HandleTypeDef
*hcryp
);
1135 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef
*hcryp
);
1160 #endif /* __STM32F4xx_HAL_CRYP_H */
1162 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/