STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_cryp.h 00004 * @author MCD Application Team 00005 * @brief Header file of CRYP HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file in 00013 * the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 ****************************************************************************** 00016 */ 00017 00018 /* Define to prevent recursive inclusion -------------------------------------*/ 00019 #ifndef STM32L4xx_HAL_CRYP_H 00020 #define STM32L4xx_HAL_CRYP_H 00021 00022 #ifdef __cplusplus 00023 extern "C" { 00024 #endif 00025 00026 /* Includes ------------------------------------------------------------------*/ 00027 #include "stm32l4xx_hal_def.h" 00028 00029 /** @addtogroup STM32L4xx_HAL_Driver 00030 * @{ 00031 */ 00032 00033 #if defined(AES) 00034 00035 /** @addtogroup CRYP 00036 * @{ 00037 */ 00038 00039 /* Exported types ------------------------------------------------------------*/ 00040 /** @defgroup CRYP_Exported_Types CRYP Exported Types 00041 * @{ 00042 */ 00043 00044 /** 00045 * @brief CRYP Configuration Structure definition 00046 */ 00047 typedef struct 00048 { 00049 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string. 00050 This parameter can be a value of @ref CRYP_Data_Type */ 00051 00052 uint32_t KeySize; /*!< 128 or 256-bit key length. 00053 This parameter can be a value of @ref CRYP_Key_Size */ 00054 00055 uint32_t OperatingMode; /*!< AES operating mode. 00056 This parameter can be a value of @ref CRYP_AES_OperatingMode */ 00057 00058 uint32_t ChainingMode; /*!< AES chaining mode. 00059 This parameter can be a value of @ref CRYP_AES_ChainingMode */ 00060 00061 uint32_t KeyWriteFlag; /*!< Allows to bypass or not key write-up before decryption. 00062 This parameter can be a value of @ref CRYP_Key_Write */ 00063 00064 uint32_t GCMCMACPhase; /*!< Indicates the processing phase of the Galois Counter Mode (GCM), 00065 Galois Message Authentication Code (GMAC), Cipher Message 00066 Authentication Code (CMAC) (when applicable) or Counter with Cipher 00067 Mode (CCM) (when applicable). 00068 This parameter can be a value of @ref CRYP_GCM_CMAC_Phase */ 00069 00070 uint8_t* pKey; /*!< Encryption/Decryption Key */ 00071 00072 uint8_t* pInitVect; /*!< Initialization Vector used for CTR, CBC, GCM/GMAC, CMAC (when applicable) 00073 and CCM (when applicable) modes */ 00074 00075 uint8_t* Header; /*!< Header used in GCM/GMAC, CMAC (when applicable) and CCM (when applicable) modes */ 00076 00077 uint64_t HeaderSize; /*!< Header size in bytes */ 00078 00079 }CRYP_InitTypeDef; 00080 00081 /** 00082 * @brief HAL CRYP State structures definition 00083 */ 00084 typedef enum 00085 { 00086 HAL_CRYP_STATE_RESET = 0x00, /*!< CRYP not yet initialized or disabled */ 00087 HAL_CRYP_STATE_READY = 0x01, /*!< CRYP initialized and ready for use */ 00088 HAL_CRYP_STATE_BUSY = 0x02, /*!< CRYP internal processing is ongoing */ 00089 HAL_CRYP_STATE_TIMEOUT = 0x03, /*!< CRYP timeout state */ 00090 HAL_CRYP_STATE_ERROR = 0x04, /*!< CRYP error state */ 00091 HAL_CRYP_STATE_SUSPENDED = 0x05 /*!< CRYP suspended */ 00092 }HAL_CRYP_STATETypeDef; 00093 00094 /** 00095 * @brief HAL CRYP phase structures definition 00096 */ 00097 typedef enum 00098 { 00099 HAL_CRYP_PHASE_READY = 0x01, /*!< CRYP peripheral is ready for initialization. */ 00100 HAL_CRYP_PHASE_PROCESS = 0x02, /*!< CRYP peripheral is in processing phase */ 00101 HAL_CRYP_PHASE_START = 0x03, /*!< CRYP peripheral has been initialized but 00102 GCM/GMAC(/CMAC)(/CCM) initialization phase has not started */ 00103 HAL_CRYP_PHASE_INIT_OVER = 0x04, /*!< GCM/GMAC(/CMAC)(/CCM) init phase has been carried out */ 00104 HAL_CRYP_PHASE_HEADER_OVER = 0x05, /*!< GCM/GMAC(/CMAC)(/CCM) header phase has been carried out */ 00105 HAL_CRYP_PHASE_PAYLOAD_OVER = 0x06, /*!< GCM(/CCM) payload phase has been carried out */ 00106 HAL_CRYP_PHASE_FINAL_OVER = 0x07, /*!< GCM/GMAC(/CMAC)(/CCM) final phase has been carried out */ 00107 HAL_CRYP_PHASE_HEADER_SUSPENDED = 0x08, /*!< GCM/GMAC(/CMAC)(/CCM) header phase has been suspended */ 00108 HAL_CRYP_PHASE_PAYLOAD_SUSPENDED = 0x09, /*!< GCM(/CCM) payload phase has been suspended */ 00109 HAL_CRYP_PHASE_NOT_USED = 0x0a /*!< Phase is irrelevant to the current chaining mode */ 00110 }HAL_PhaseTypeDef; 00111 00112 /** 00113 * @brief HAL CRYP mode suspend definitions 00114 */ 00115 typedef enum 00116 { 00117 HAL_CRYP_SUSPEND_NONE = 0x00, /*!< CRYP peripheral suspension not requested */ 00118 HAL_CRYP_SUSPEND = 0x01 /*!< CRYP peripheral suspension requested */ 00119 }HAL_SuspendTypeDef; 00120 00121 00122 /** 00123 * @brief HAL CRYP Error Codes definition 00124 */ 00125 #define HAL_CRYP_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */ 00126 #define HAL_CRYP_WRITE_ERROR ((uint32_t)0x00000001) /*!< Write error */ 00127 #define HAL_CRYP_READ_ERROR ((uint32_t)0x00000002) /*!< Read error */ 00128 #define HAL_CRYP_DMA_ERROR ((uint32_t)0x00000004) /*!< DMA error */ 00129 #define HAL_CRYP_BUSY_ERROR ((uint32_t)0x00000008) /*!< Busy flag error */ 00130 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00131 #define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000010U) /*!< Invalid Callback error */ 00132 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00133 00134 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00135 /** 00136 * @brief HAL CRYP common Callback ID enumeration definition 00137 */ 00138 typedef enum 00139 { 00140 HAL_CRYP_INPUTCPLT_CB_ID = 0x01U, /*!< CRYP input DMA transfer completion callback ID */ 00141 HAL_CRYP_OUTPUTCPLT_CB_ID = 0x02U, /*!< CRYP output DMA transfer completion callback ID */ 00142 HAL_CRYP_COMPCPLT_CB_ID = 0x03U, /*!< CRYP computation completion callback ID */ 00143 HAL_CRYP_ERROR_CB_ID = 0x04U, /*!< CRYP error callback ID */ 00144 HAL_CRYP_MSPINIT_CB_ID = 0x05U, /*!< CRYP MspInit callback ID */ 00145 HAL_CRYP_MSPDEINIT_CB_ID = 0x06U, /*!< CRYP MspDeInit callback ID */ 00146 }HAL_CRYP_CallbackIDTypeDef; 00147 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00148 00149 /** 00150 * @brief CRYP handle Structure definition 00151 */ 00152 typedef struct __CRYP_HandleTypeDef 00153 { 00154 AES_TypeDef *Instance; /*!< Register base address */ 00155 00156 CRYP_InitTypeDef Init; /*!< CRYP initialization parameters */ 00157 00158 uint8_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) input buffer */ 00159 00160 uint8_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) output buffer */ 00161 00162 uint32_t CrypInCount; /*!< Input data size in bytes or, after suspension, the remaining 00163 number of bytes to process */ 00164 00165 uint32_t CrypOutCount; /*!< Output data size in bytes */ 00166 00167 HAL_PhaseTypeDef Phase; /*!< CRYP peripheral processing phase for GCM, GMAC, CMAC (when applicable) 00168 or CCM (when applicable) modes. 00169 Indicates the last phase carried out to ease 00170 phase transitions */ 00171 00172 DMA_HandleTypeDef *hdmain; /*!< CRYP peripheral Input DMA handle parameters */ 00173 00174 DMA_HandleTypeDef *hdmaout; /*!< CRYP peripheral Output DMA handle parameters */ 00175 00176 HAL_LockTypeDef Lock; /*!< CRYP locking object */ 00177 00178 __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */ 00179 00180 __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */ 00181 00182 HAL_SuspendTypeDef SuspendRequest; /*!< CRYP peripheral suspension request flag */ 00183 00184 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00185 void (* InCpltCallback)( struct __CRYP_HandleTypeDef * hcryp); /*!< CRYP input DMA transfer completion callback */ 00186 00187 void (* OutCpltCallback)( struct __CRYP_HandleTypeDef * hcryp); /*!< CRYP output DMA transfer completion callback */ 00188 00189 void (* CompCpltCallback)( struct __CRYP_HandleTypeDef * hcryp); /*!< CRYP computation completion callback */ 00190 00191 void (* ErrorCallback)( struct __CRYP_HandleTypeDef * hcryp); /*!< CRYP error callback */ 00192 00193 void (* MspInitCallback)( struct __CRYP_HandleTypeDef * hcryp); /*!< CRYP Msp Init callback */ 00194 00195 void (* MspDeInitCallback)( struct __CRYP_HandleTypeDef * hcryp); /*!< CRYP Msp DeInit callback */ 00196 00197 #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */ 00198 }CRYP_HandleTypeDef; 00199 00200 00201 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00202 /** 00203 * @brief HAL CRYP Callback pointer definition 00204 */ 00205 typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef * hcryp); /*!< pointer to a CRYP common callback functions */ 00206 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00207 /** 00208 * @} 00209 */ 00210 00211 00212 /* Exported constants --------------------------------------------------------*/ 00213 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants 00214 * @{ 00215 */ 00216 00217 /** @defgroup CRYP_Key_Size Key size selection 00218 * @{ 00219 */ 00220 #define CRYP_KEYSIZE_128B ((uint32_t)0x00000000) /*!< 128-bit long key */ 00221 #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */ 00222 /** 00223 * @} 00224 */ 00225 00226 /** @defgroup CRYP_Data_Type AES Data Type selection 00227 * @{ 00228 */ 00229 #define CRYP_DATATYPE_32B ((uint32_t)0x00000000) /*!< 32-bit data type (no swapping) */ 00230 #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */ 00231 #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */ 00232 #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */ 00233 /** 00234 * @} 00235 */ 00236 00237 /** @defgroup CRYP_AES_State AES Enable state 00238 * @{ 00239 */ 00240 #define CRYP_AES_DISABLE ((uint32_t)0x00000000) /*!< Disable AES */ 00241 #define CRYP_AES_ENABLE AES_CR_EN /*!< Enable AES */ 00242 /** 00243 * @} 00244 */ 00245 00246 /** @defgroup CRYP_AES_OperatingMode AES operating mode 00247 * @{ 00248 */ 00249 #define CRYP_ALGOMODE_ENCRYPT ((uint32_t)0x00000000) /*!< Encryption mode */ 00250 #define CRYP_ALGOMODE_KEYDERIVATION AES_CR_MODE_0 /*!< Key derivation mode */ 00251 #define CRYP_ALGOMODE_DECRYPT AES_CR_MODE_1 /*!< Decryption */ 00252 #define CRYP_ALGOMODE_KEYDERIVATION_DECRYPT AES_CR_MODE /*!< Key derivation and decryption */ 00253 #define CRYP_ALGOMODE_TAG_GENERATION ((uint32_t)0x00000000) /*!< GMAC or CMAC (when applicable) authentication tag generation */ 00254 /** 00255 * @} 00256 */ 00257 00258 /** @defgroup CRYP_AES_ChainingMode AES chaining mode 00259 * @{ 00260 */ 00261 #define CRYP_CHAINMODE_AES_ECB ((uint32_t)0x00000000) /*!< Electronic codebook chaining algorithm */ 00262 #define CRYP_CHAINMODE_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */ 00263 #define CRYP_CHAINMODE_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */ 00264 #define CRYP_CHAINMODE_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */ 00265 #if defined(AES_CR_NPBLB) 00266 #define CRYP_CHAINMODE_AES_CCM AES_CR_CHMOD_2 /*!< Counter with Cipher Mode */ 00267 #else 00268 #define CRYP_CHAINMODE_AES_CMAC AES_CR_CHMOD_2 /*!< Cipher message authentication code */ 00269 #endif 00270 /** 00271 * @} 00272 */ 00273 00274 /** @defgroup CRYP_Key_Write AES decryption key write-up flag 00275 * @{ 00276 */ 00277 #define CRYP_KEY_WRITE_ENABLE ((uint32_t)0x00000000) /*!< Enable decryption key writing */ 00278 #define CRYP_KEY_WRITE_DISABLE ((uint32_t)0x00000001) /*!< Disable decryption key writing */ 00279 /** 00280 * @} 00281 */ 00282 00283 /** @defgroup CRYP_DMAIN DMA Input phase management enable state 00284 * @{ 00285 */ 00286 #define CRYP_DMAIN_DISABLE ((uint32_t)0x00000000) /*!< Disable DMA Input phase management */ 00287 #define CRYP_DMAIN_ENABLE AES_CR_DMAINEN /*!< Enable DMA Input phase management */ 00288 /** 00289 * @} 00290 */ 00291 00292 /** @defgroup CRYP_DMAOUT DMA Output phase management enable state 00293 * @{ 00294 */ 00295 #define CRYP_DMAOUT_DISABLE ((uint32_t)0x00000000) /*!< Disable DMA Output phase management */ 00296 #define CRYP_DMAOUT_ENABLE AES_CR_DMAOUTEN /*!< Enable DMA Output phase management */ 00297 /** 00298 * @} 00299 */ 00300 00301 00302 /** @defgroup CRYP_GCM_CMAC_Phase GCM/GMAC and CCM/CMAC (when applicable) processing phase selection 00303 * @{ 00304 */ 00305 #define CRYP_GCM_INIT_PHASE ((uint32_t)0x00000000) /*!< GCM/GMAC (or CCM) init phase */ 00306 #define CRYP_GCMCMAC_HEADER_PHASE AES_CR_GCMPH_0 /*!< GCM/GMAC/CCM/CMAC header phase */ 00307 #define CRYP_GCM_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< GCM/CCM payload phase */ 00308 #define CRYP_GCMCMAC_FINAL_PHASE AES_CR_GCMPH /*!< GCM/GMAC/CCM/CMAC final phase */ 00309 /* Definitions duplication for code readibility's sake: 00310 supported or not supported chain modes are not specified for each phase */ 00311 #define CRYP_INIT_PHASE ((uint32_t)0x00000000) /*!< Init phase */ 00312 #define CRYP_HEADER_PHASE AES_CR_GCMPH_0 /*!< Header phase */ 00313 #define CRYP_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< Payload phase */ 00314 #define CRYP_FINAL_PHASE AES_CR_GCMPH /*!< Final phase */ 00315 /** 00316 * @} 00317 */ 00318 00319 /** @defgroup CRYP_Flags AES status flags 00320 * @{ 00321 */ 00322 00323 #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */ 00324 #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */ 00325 #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */ 00326 #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */ 00327 /** 00328 * @} 00329 */ 00330 00331 /** @defgroup CRYP_Clear_Flags AES clearing flags 00332 * @{ 00333 */ 00334 00335 #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */ 00336 #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */ 00337 /** 00338 * @} 00339 */ 00340 00341 /** @defgroup AES_Interrupts_Enable AES Interrupts Enable bits 00342 * @{ 00343 */ 00344 #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */ 00345 #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */ 00346 /** 00347 * @} 00348 */ 00349 00350 /** @defgroup CRYP_Interrupts_Flags AES Interrupts flags 00351 * @{ 00352 */ 00353 #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */ 00354 #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */ 00355 #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */ 00356 /** 00357 * @} 00358 */ 00359 00360 /** 00361 * @} 00362 */ 00363 00364 /* Exported macros -----------------------------------------------------------*/ 00365 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros 00366 * @{ 00367 */ 00368 00369 /** @brief Reset CRYP handle state. 00370 * @param __HANDLE__ specifies the CRYP handle. 00371 * @retval None 00372 */ 00373 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00374 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\ 00375 (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\ 00376 (__HANDLE__)->MspInitCallback = NULL; \ 00377 (__HANDLE__)->MspDeInitCallback = NULL; \ 00378 }while(0) 00379 #else 00380 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET) 00381 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00382 00383 /** 00384 * @brief Enable the CRYP AES peripheral. 00385 * @param __HANDLE__ specifies the CRYP handle. 00386 * @retval None 00387 */ 00388 #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= AES_CR_EN) 00389 00390 /** 00391 * @brief Disable the CRYP AES peripheral. 00392 * @param __HANDLE__ specifies the CRYP handle. 00393 * @retval None 00394 */ 00395 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~AES_CR_EN) 00396 00397 /** 00398 * @brief Set the algorithm operating mode. 00399 * @param __HANDLE__ specifies the CRYP handle. 00400 * @param __OPERATING_MODE__ specifies the operating mode 00401 * This parameter can be one of the following values: 00402 * @arg @ref CRYP_ALGOMODE_ENCRYPT encryption 00403 * @arg @ref CRYP_ALGOMODE_KEYDERIVATION key derivation 00404 * @arg @ref CRYP_ALGOMODE_DECRYPT decryption 00405 * @arg @ref CRYP_ALGOMODE_KEYDERIVATION_DECRYPT key derivation and decryption 00406 * @retval None 00407 */ 00408 #define __HAL_CRYP_SET_OPERATINGMODE(__HANDLE__, __OPERATING_MODE__) MODIFY_REG((__HANDLE__)->Instance->CR, AES_CR_MODE, (__OPERATING_MODE__)) 00409 00410 00411 /** 00412 * @brief Set the algorithm chaining mode. 00413 * @param __HANDLE__ specifies the CRYP handle. 00414 * @param __CHAINING_MODE__ specifies the chaining mode 00415 * This parameter can be one of the following values: 00416 * @arg @ref CRYP_CHAINMODE_AES_ECB Electronic CodeBook 00417 * @arg @ref CRYP_CHAINMODE_AES_CBC Cipher Block Chaining 00418 * @arg @ref CRYP_CHAINMODE_AES_CTR CounTeR mode 00419 * @arg @ref CRYP_CHAINMODE_AES_GCM_GMAC Galois Counter Mode or Galois Message Authentication Code 00420 * @arg @ref CRYP_CHAINMODE_AES_CMAC Cipher Message Authentication Code (or Counter with Cipher Mode when applicable) 00421 * @retval None 00422 */ 00423 #define __HAL_CRYP_SET_CHAININGMODE(__HANDLE__, __CHAINING_MODE__) MODIFY_REG((__HANDLE__)->Instance->CR, AES_CR_CHMOD, (__CHAINING_MODE__)) 00424 00425 00426 00427 /** @brief Check whether the specified CRYP status flag is set or not. 00428 * @param __HANDLE__ specifies the CRYP handle. 00429 * @param __FLAG__ specifies the flag to check. 00430 * This parameter can be one of the following values: 00431 * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden 00432 * @arg @ref CRYP_IT_WRERR Write Error 00433 * @arg @ref CRYP_IT_RDERR Read Error 00434 * @arg @ref CRYP_IT_CCF Computation Complete 00435 * @retval The state of __FLAG__ (TRUE or FALSE). 00436 */ 00437 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 00438 00439 00440 /** @brief Clear the CRYP pending status flag. 00441 * @param __HANDLE__ specifies the CRYP handle. 00442 * @param __FLAG__ specifies the flag to clear. 00443 * This parameter can be one of the following values: 00444 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear 00445 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear 00446 * @retval None 00447 */ 00448 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__)) 00449 00450 00451 00452 /** @brief Check whether the specified CRYP interrupt source is enabled or not. 00453 * @param __HANDLE__ specifies the CRYP handle. 00454 * @param __INTERRUPT__ CRYP interrupt source to check 00455 * This parameter can be one of the following values: 00456 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00457 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00458 * @retval State of interruption (TRUE or FALSE). 00459 */ 00460 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__)) 00461 00462 00463 /** @brief Check whether the specified CRYP interrupt is set or not. 00464 * @param __HANDLE__ specifies the CRYP handle. 00465 * @param __INTERRUPT__ specifies the interrupt to check. 00466 * This parameter can be one of the following values: 00467 * @arg @ref CRYP_IT_WRERR Write Error 00468 * @arg @ref CRYP_IT_RDERR Read Error 00469 * @arg @ref CRYP_IT_CCF Computation Complete 00470 * @retval The state of __INTERRUPT__ (TRUE or FALSE). 00471 */ 00472 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__)) 00473 00474 00475 00476 /** @brief Clear the CRYP pending interrupt. 00477 * @param __HANDLE__ specifies the CRYP handle. 00478 * @param __INTERRUPT__ specifies the IT to clear. 00479 * This parameter can be one of the following values: 00480 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear 00481 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear 00482 * @retval None 00483 */ 00484 #define __HAL_CRYP_CLEAR_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR, (__INTERRUPT__)) 00485 00486 00487 /** 00488 * @brief Enable the CRYP interrupt. 00489 * @param __HANDLE__ specifies the CRYP handle. 00490 * @param __INTERRUPT__ CRYP Interrupt. 00491 * This parameter can be one of the following values: 00492 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00493 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00494 * @retval None 00495 */ 00496 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__)) 00497 00498 00499 /** 00500 * @brief Disable the CRYP interrupt. 00501 * @param __HANDLE__ specifies the CRYP handle. 00502 * @param __INTERRUPT__ CRYP Interrupt. 00503 * This parameter can be one of the following values: 00504 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00505 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00506 * @retval None 00507 */ 00508 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__)) 00509 00510 /** 00511 * @} 00512 */ 00513 00514 /* Private macros --------------------------------------------------------*/ 00515 /** @addtogroup CRYP_Private_Macros CRYP Private Macros 00516 * @{ 00517 */ 00518 00519 /** 00520 * @brief Verify the key size length. 00521 * @param __KEYSIZE__ Ciphering/deciphering algorithm key size. 00522 * @retval SET (__KEYSIZE__ is a valid value) or RESET (__KEYSIZE__ is invalid) 00523 */ 00524 #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \ 00525 ((__KEYSIZE__) == CRYP_KEYSIZE_256B)) 00526 00527 /** 00528 * @brief Verify the input data type. 00529 * @param __DATATYPE__ Ciphering/deciphering algorithm input data type. 00530 * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid) 00531 */ 00532 #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \ 00533 ((__DATATYPE__) == CRYP_DATATYPE_16B) || \ 00534 ((__DATATYPE__) == CRYP_DATATYPE_8B) || \ 00535 ((__DATATYPE__) == CRYP_DATATYPE_1B)) 00536 00537 /** 00538 * @brief Verify the CRYP AES IP running mode. 00539 * @param __MODE__ CRYP AES IP running mode. 00540 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 00541 */ 00542 #define IS_CRYP_AES(__MODE__) (((__MODE__) == CRYP_AES_DISABLE) || \ 00543 ((__MODE__) == CRYP_AES_ENABLE)) 00544 00545 /** 00546 * @brief Verify the selected CRYP algorithm. 00547 * @param __ALGOMODE__ Selected CRYP algorithm (ciphering, deciphering, key derivation or a combination of the latter). 00548 * @retval SET (__ALGOMODE__ is valid) or RESET (__ALGOMODE__ is invalid) 00549 */ 00550 #define IS_CRYP_ALGOMODE(__ALGOMODE__) (((__ALGOMODE__) == CRYP_ALGOMODE_ENCRYPT) || \ 00551 ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION) || \ 00552 ((__ALGOMODE__) == CRYP_ALGOMODE_DECRYPT) || \ 00553 ((__ALGOMODE__) == CRYP_ALGOMODE_TAG_GENERATION) || \ 00554 ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION_DECRYPT)) 00555 00556 /** 00557 * @brief Verify the selected CRYP chaining algorithm. 00558 * @param __CHAINMODE__ Selected CRYP chaining algorithm. 00559 * @retval SET (__CHAINMODE__ is valid) or RESET (__CHAINMODE__ is invalid) 00560 */ 00561 #if defined(AES_CR_NPBLB) 00562 #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \ 00563 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \ 00564 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \ 00565 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \ 00566 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CCM)) 00567 #else 00568 #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \ 00569 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \ 00570 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \ 00571 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \ 00572 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CMAC)) 00573 #endif 00574 00575 /** 00576 * @brief Verify the deciphering key write option. 00577 * @param __WRITE__ deciphering key write option. 00578 * @retval SET (__WRITE__ is valid) or RESET (__WRITE__ is invalid) 00579 */ 00580 #define IS_CRYP_WRITE(__WRITE__) (((__WRITE__) == CRYP_KEY_WRITE_ENABLE) || \ 00581 ((__WRITE__) == CRYP_KEY_WRITE_DISABLE)) 00582 00583 /** 00584 * @brief Verify the CRYP input data DMA mode. 00585 * @param __MODE__ CRYP input data DMA mode. 00586 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 00587 */ 00588 #define IS_CRYP_DMAIN(__MODE__) (((__MODE__) == CRYP_DMAIN_DISABLE) || \ 00589 ((__MODE__) == CRYP_DMAIN_ENABLE)) 00590 00591 /** 00592 * @brief Verify the CRYP output data DMA mode. 00593 * @param __MODE__ CRYP output data DMA mode. 00594 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 00595 */ 00596 #define IS_CRYP_DMAOUT(__MODE__) (((__MODE__) == CRYP_DMAOUT_DISABLE) || \ 00597 ((__MODE__) == CRYP_DMAOUT_ENABLE)) 00598 00599 /** 00600 * @brief Verify the CRYP AES ciphering/deciphering/authentication algorithm phase. 00601 * @param __PHASE__ CRYP AES ciphering/deciphering/authentication algorithm phase. 00602 * @retval SET (__PHASE__ is valid) or RESET (__PHASE__ is invalid) 00603 */ 00604 #define IS_CRYP_GCMCMAC_PHASE(__PHASE__) (((__PHASE__) == CRYP_INIT_PHASE) || \ 00605 ((__PHASE__) == CRYP_HEADER_PHASE) || \ 00606 ((__PHASE__) == CRYP_PAYLOAD_PHASE) || \ 00607 ((__PHASE__) == CRYP_FINAL_PHASE)) 00608 00609 /** 00610 * @} 00611 */ 00612 00613 /* Include CRYP HAL Extended module */ 00614 #include "stm32l4xx_hal_cryp_ex.h" 00615 00616 /* Exported functions --------------------------------------------------------*/ 00617 /** @addtogroup CRYP_Exported_Functions CRYP Exported Functions 00618 * @{ 00619 */ 00620 00621 /** @addtogroup CRYP_Exported_Functions_Group1 Initialization and deinitialization functions 00622 * @{ 00623 */ 00624 00625 /* Initialization/de-initialization functions ********************************/ 00626 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp); 00627 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp); 00628 00629 /* MSP initialization/de-initialization functions ****************************/ 00630 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp); 00631 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp); 00632 00633 /** 00634 * @} 00635 */ 00636 00637 /** @addtogroup CRYP_Exported_Functions_Group2 AES processing functions 00638 * @{ 00639 */ 00640 00641 /* AES encryption/decryption processing functions ****************************/ 00642 00643 /* AES encryption/decryption using polling ***********************************/ 00644 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00645 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00646 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00647 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00648 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00649 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00650 00651 /* AES encryption/decryption using interrupt *********************************/ 00652 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00653 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00654 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00655 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00656 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00657 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00658 00659 /* AES encryption/decryption using DMA ***************************************/ 00660 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00661 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00662 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00663 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00664 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00665 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00666 00667 /** 00668 * @} 00669 */ 00670 00671 /** @addtogroup CRYP_Exported_Functions_Group3 Callback functions 00672 * @{ 00673 */ 00674 /* CallBack functions ********************************************************/ 00675 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp); 00676 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp); 00677 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp); 00678 /* Callbacks Register/UnRegister functions ***********************************/ 00679 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00680 HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID, pCRYP_CallbackTypeDef pCallback); 00681 HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID); 00682 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00683 00684 /** 00685 * @} 00686 */ 00687 00688 /** @addtogroup CRYP_Exported_Functions_Group4 CRYP IRQ handler 00689 * @{ 00690 */ 00691 00692 /* AES interrupt handling function *******************************************/ 00693 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp); 00694 00695 /** 00696 * @} 00697 */ 00698 00699 /** @addtogroup CRYP_Exported_Functions_Group5 Peripheral State functions 00700 * @{ 00701 */ 00702 00703 /* Peripheral State functions ************************************************/ 00704 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp); 00705 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp); 00706 00707 /** 00708 * @} 00709 */ 00710 00711 /** 00712 * @} 00713 */ 00714 00715 /** 00716 * @} 00717 */ 00718 00719 #endif /* AES */ 00720 00721 /** 00722 * @} 00723 */ 00724 00725 #ifdef __cplusplus 00726 } 00727 #endif 00728 00729 #endif /* STM32L4xx_HAL_CRYP_H */