STM32F479xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_cryp.h 00004 * @author MCD Application Team 00005 * @brief Header file of CRYP HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 00020 /* Define to prevent recursive inclusion -------------------------------------*/ 00021 #ifndef __STM32F4xx_HAL_CRYP_H 00022 #define __STM32F4xx_HAL_CRYP_H 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 00029 /* Includes ------------------------------------------------------------------*/ 00030 #include "stm32f4xx_hal_def.h" 00031 00032 /** @addtogroup STM32F4xx_HAL_Driver 00033 * @{ 00034 */ 00035 #if defined (AES) || defined (CRYP) 00036 /** @addtogroup CRYP 00037 * @{ 00038 */ 00039 00040 /* Exported types ------------------------------------------------------------*/ 00041 00042 /** @defgroup CRYP_Exported_Types CRYP Exported Types 00043 * @{ 00044 */ 00045 00046 /** 00047 * @brief CRYP Init Structure definition 00048 */ 00049 00050 typedef struct 00051 { 00052 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string. 00053 This parameter can be a value of @ref CRYP_Data_Type */ 00054 uint32_t KeySize; /*!< Used only in AES mode : 128, 192 or 256 bit key length in CRYP1. 00055 128 or 256 bit key length in TinyAES This parameter can be a value of @ref CRYP_Key_Size */ 00056 uint32_t *pKey; /*!< The key used for encryption/decryption */ 00057 uint32_t *pInitVect; /*!< The initialization vector used also as initialization 00058 counter in CTR mode */ 00059 uint32_t Algorithm; /*!< DES/ TDES Algorithm ECB/CBC 00060 AES Algorithm ECB/CBC/CTR/GCM or CCM 00061 This parameter can be a value of @ref CRYP_Algorithm_Mode */ 00062 uint32_t *Header; /*!< used only in AES GCM and CCM Algorithm for authentication, 00063 GCM : also known as Additional Authentication Data 00064 CCM : named B1 composed of the associated data length and Associated Data. */ 00065 uint32_t HeaderSize; /*!< The size of header buffer in word */ 00066 uint32_t *B0; /*!< B0 is first authentication block used only in AES CCM mode */ 00067 uint32_t DataWidthUnit; /*!< Data With Unit, this parameter can be value of @ref CRYP_Data_Width_Unit*/ 00068 uint32_t HeaderWidthUnit; /*!< Header Width Unit, this parameter can be value of @ref CRYP_Header_Width_Unit*/ 00069 uint32_t KeyIVConfigSkip; /*!< CRYP peripheral Key and IV configuration skip, to config Key and Initialization 00070 Vector only once and to skip configuration for consecutive processings. 00071 This parameter can be a value of @ref CRYP_Configuration_Skip */ 00072 00073 } CRYP_ConfigTypeDef; 00074 00075 00076 /** 00077 * @brief CRYP State Structure definition 00078 */ 00079 00080 typedef enum 00081 { 00082 HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */ 00083 HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */ 00084 HAL_CRYP_STATE_BUSY = 0x02U /*!< CRYP BUSY, internal processing is ongoing */ 00085 } HAL_CRYP_STATETypeDef; 00086 00087 00088 /** 00089 * @brief CRYP handle Structure definition 00090 */ 00091 00092 typedef struct __CRYP_HandleTypeDef 00093 { 00094 #if defined (CRYP) 00095 CRYP_TypeDef *Instance; /*!< CRYP registers base address */ 00096 #else /* AES*/ 00097 AES_TypeDef *Instance; /*!< AES Register base address */ 00098 #endif /* End AES or CRYP */ 00099 00100 CRYP_ConfigTypeDef Init; /*!< CRYP required parameters */ 00101 00102 FunctionalState AutoKeyDerivation; /*!< Used only in TinyAES to allows to bypass or not key write-up before decryption. 00103 This parameter can be a value of ENABLE/DISABLE */ 00104 00105 uint32_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */ 00106 00107 uint32_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */ 00108 00109 __IO uint16_t CrypHeaderCount; /*!< Counter of header data */ 00110 00111 __IO uint16_t CrypInCount; /*!< Counter of input data */ 00112 00113 __IO uint16_t CrypOutCount; /*!< Counter of output data */ 00114 00115 uint16_t Size; /*!< length of input data in word */ 00116 00117 uint32_t Phase; /*!< CRYP peripheral phase */ 00118 00119 DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */ 00120 00121 DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */ 00122 00123 HAL_LockTypeDef Lock; /*!< CRYP locking object */ 00124 00125 __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */ 00126 00127 __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */ 00128 00129 uint32_t KeyIVConfig; /*!< CRYP peripheral Key and IV configuration flag, used when 00130 configuration can be skipped */ 00131 00132 uint32_t SizesSum; /*!< Sum of successive payloads lengths (in bytes), stored 00133 for a single signature computation after several 00134 messages processing */ 00135 00136 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00137 void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Input FIFO transfer completed callback */ 00138 void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Output FIFO transfer completed callback */ 00139 void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Error callback */ 00140 00141 void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp Init callback */ 00142 void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp DeInit callback */ 00143 00144 #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */ 00145 } CRYP_HandleTypeDef; 00146 00147 00148 /** 00149 * @} 00150 */ 00151 00152 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00153 /** @defgroup HAL_CRYP_Callback_ID_enumeration_definition HAL CRYP Callback ID enumeration definition 00154 * @brief HAL CRYP Callback ID enumeration definition 00155 * @{ 00156 */ 00157 typedef enum 00158 { 00159 HAL_CRYP_INPUT_COMPLETE_CB_ID = 0x01U, /*!< CRYP Input FIFO transfer completed callback ID */ 00160 HAL_CRYP_OUTPUT_COMPLETE_CB_ID = 0x02U, /*!< CRYP Output FIFO transfer completed callback ID */ 00161 HAL_CRYP_ERROR_CB_ID = 0x03U, /*!< CRYP Error callback ID */ 00162 00163 HAL_CRYP_MSPINIT_CB_ID = 0x04U, /*!< CRYP MspInit callback ID */ 00164 HAL_CRYP_MSPDEINIT_CB_ID = 0x05U /*!< CRYP MspDeInit callback ID */ 00165 00166 } HAL_CRYP_CallbackIDTypeDef; 00167 /** 00168 * @} 00169 */ 00170 00171 /** @defgroup HAL_CRYP_Callback_pointer_definition HAL CRYP Callback pointer definition 00172 * @brief HAL CRYP Callback pointer definition 00173 * @{ 00174 */ 00175 00176 typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp); /*!< pointer to a common CRYP callback function */ 00177 00178 /** 00179 * @} 00180 */ 00181 00182 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00183 00184 /* Exported constants --------------------------------------------------------*/ 00185 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants 00186 * @{ 00187 */ 00188 00189 /** @defgroup CRYP_Error_Definition CRYP Error Definition 00190 * @{ 00191 */ 00192 #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */ 00193 #define HAL_CRYP_ERROR_WRITE 0x00000001U /*!< Write error */ 00194 #define HAL_CRYP_ERROR_READ 0x00000002U /*!< Read error */ 00195 #define HAL_CRYP_ERROR_DMA 0x00000004U /*!< DMA error */ 00196 #define HAL_CRYP_ERROR_BUSY 0x00000008U /*!< Busy flag error */ 00197 #define HAL_CRYP_ERROR_TIMEOUT 0x00000010U /*!< Timeout error */ 00198 #define HAL_CRYP_ERROR_NOT_SUPPORTED 0x00000020U /*!< Not supported mode */ 00199 #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U /*!< Sequence are not respected only for GCM or CCM */ 00200 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00201 #define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U) /*!< Invalid Callback error */ 00202 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00203 /** 00204 * @} 00205 */ 00206 00207 /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit 00208 * @{ 00209 */ 00210 00211 #define CRYP_DATAWIDTHUNIT_WORD 0x00000000U /*!< By default, size unit is word */ 00212 #define CRYP_DATAWIDTHUNIT_BYTE 0x00000001U /*!< By default, size unit is word */ 00213 00214 /** 00215 * @} 00216 */ 00217 00218 /** @defgroup CRYP_Header_Width_Unit CRYP Header Width Unit 00219 * @{ 00220 */ 00221 00222 #define CRYP_HEADERWIDTHUNIT_WORD 0x00000000U /*!< By default, header size unit is word */ 00223 #define CRYP_HEADERWIDTHUNIT_BYTE 0x00000001U /*!< By default, header size unit is byte */ 00224 00225 /** 00226 * @} 00227 */ 00228 00229 /** @defgroup CRYP_Algorithm_Mode CRYP Algorithm Mode 00230 * @{ 00231 */ 00232 #if defined(CRYP) 00233 00234 #define CRYP_DES_ECB CRYP_CR_ALGOMODE_DES_ECB 00235 #define CRYP_DES_CBC CRYP_CR_ALGOMODE_DES_CBC 00236 #define CRYP_TDES_ECB CRYP_CR_ALGOMODE_TDES_ECB 00237 #define CRYP_TDES_CBC CRYP_CR_ALGOMODE_TDES_CBC 00238 #define CRYP_AES_ECB CRYP_CR_ALGOMODE_AES_ECB 00239 #define CRYP_AES_CBC CRYP_CR_ALGOMODE_AES_CBC 00240 #define CRYP_AES_CTR CRYP_CR_ALGOMODE_AES_CTR 00241 #if defined (CRYP_CR_ALGOMODE_AES_GCM) 00242 #define CRYP_AES_GCM CRYP_CR_ALGOMODE_AES_GCM 00243 #define CRYP_AES_CCM CRYP_CR_ALGOMODE_AES_CCM 00244 #endif /* GCM CCM defined*/ 00245 #else /* AES*/ 00246 #define CRYP_AES_ECB 0x00000000U /*!< Electronic codebook chaining algorithm */ 00247 #define CRYP_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */ 00248 #define CRYP_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */ 00249 #define CRYP_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */ 00250 #define CRYP_AES_CCM AES_CR_CHMOD_2 /*!< Counter with Cipher Mode */ 00251 #endif /* End AES or CRYP */ 00252 00253 /** 00254 * @} 00255 */ 00256 00257 /** @defgroup CRYP_Key_Size CRYP Key Size 00258 * @{ 00259 */ 00260 #if defined(CRYP) 00261 #define CRYP_KEYSIZE_128B 0x00000000U 00262 #define CRYP_KEYSIZE_192B CRYP_CR_KEYSIZE_0 00263 #define CRYP_KEYSIZE_256B CRYP_CR_KEYSIZE_1 00264 #else /* AES*/ 00265 #define CRYP_KEYSIZE_128B 0x00000000U /*!< 128-bit long key */ 00266 #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */ 00267 #endif /* End AES or CRYP */ 00268 /** 00269 * @} 00270 */ 00271 00272 /** @defgroup CRYP_Data_Type CRYP Data Type 00273 * @{ 00274 */ 00275 #if defined(CRYP) 00276 #define CRYP_DATATYPE_32B 0x00000000U 00277 #define CRYP_DATATYPE_16B CRYP_CR_DATATYPE_0 00278 #define CRYP_DATATYPE_8B CRYP_CR_DATATYPE_1 00279 #define CRYP_DATATYPE_1B CRYP_CR_DATATYPE 00280 #else /* AES*/ 00281 #define CRYP_DATATYPE_32B 0x00000000U /*!< 32-bit data type (no swapping) */ 00282 #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */ 00283 #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */ 00284 #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */ 00285 #endif /* End AES or CRYP */ 00286 00287 /** 00288 * @} 00289 */ 00290 00291 /** @defgroup CRYP_Interrupt CRYP Interrupt 00292 * @{ 00293 */ 00294 #if defined (CRYP) 00295 #define CRYP_IT_INI CRYP_IMSCR_INIM /*!< Input FIFO Interrupt */ 00296 #define CRYP_IT_OUTI CRYP_IMSCR_OUTIM /*!< Output FIFO Interrupt */ 00297 #else /* AES*/ 00298 #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */ 00299 #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */ 00300 #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */ 00301 #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */ 00302 #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */ 00303 #endif /* End AES or CRYP */ 00304 00305 /** 00306 * @} 00307 */ 00308 00309 /** @defgroup CRYP_Flags CRYP Flags 00310 * @{ 00311 */ 00312 #if defined (CRYP) 00313 /* Flags in the SR register */ 00314 #define CRYP_FLAG_IFEM CRYP_SR_IFEM /*!< Input FIFO is empty */ 00315 #define CRYP_FLAG_IFNF CRYP_SR_IFNF /*!< Input FIFO is not Full */ 00316 #define CRYP_FLAG_OFNE CRYP_SR_OFNE /*!< Output FIFO is not empty */ 00317 #define CRYP_FLAG_OFFU CRYP_SR_OFFU /*!< Output FIFO is Full */ 00318 #define CRYP_FLAG_BUSY CRYP_SR_BUSY /*!< The CRYP core is currently processing a block of data 00319 or a key preparation (for AES decryption). */ 00320 /* Flags in the RISR register */ 00321 #define CRYP_FLAG_OUTRIS 0x01000002U /*!< Output FIFO service raw interrupt status */ 00322 #define CRYP_FLAG_INRIS 0x01000001U /*!< Input FIFO service raw interrupt status*/ 00323 #else /* AES*/ 00324 /* status flags */ 00325 #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */ 00326 #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */ 00327 #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */ 00328 #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */ 00329 /* clearing flags */ 00330 #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */ 00331 #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */ 00332 #endif /* End AES or CRYP */ 00333 00334 /** 00335 * @} 00336 */ 00337 00338 /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode 00339 * @{ 00340 */ 00341 00342 #define CRYP_KEYIVCONFIG_ALWAYS 0x00000000U /*!< Peripheral Key and IV configuration to do systematically */ 00343 #define CRYP_KEYIVCONFIG_ONCE 0x00000001U /*!< Peripheral Key and IV configuration to do only once */ 00344 00345 /** 00346 * @} 00347 */ 00348 00349 00350 /** 00351 * @} 00352 */ 00353 00354 /* Exported macros -----------------------------------------------------------*/ 00355 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros 00356 * @{ 00357 */ 00358 00359 /** @brief Reset CRYP handle state 00360 * @param __HANDLE__ specifies the CRYP handle. 00361 * @retval None 00362 */ 00363 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00364 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\ 00365 (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\ 00366 (__HANDLE__)->MspInitCallback = NULL;\ 00367 (__HANDLE__)->MspDeInitCallback = NULL;\ 00368 }while(0) 00369 #else 00370 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET) 00371 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00372 00373 /** 00374 * @brief Enable/Disable the CRYP peripheral. 00375 * @param __HANDLE__: specifies the CRYP handle. 00376 * @retval None 00377 */ 00378 #if defined(CRYP) 00379 #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_CRYPEN) 00380 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~CRYP_CR_CRYPEN) 00381 #else /* AES*/ 00382 #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= AES_CR_EN) 00383 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~AES_CR_EN) 00384 #endif /* End AES or CRYP */ 00385 00386 /** @brief Check whether the specified CRYP status flag is set or not. 00387 * @param __FLAG__: specifies the flag to check. 00388 * This parameter can be one of the following values for TinyAES: 00389 * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden 00390 * @arg @ref CRYP_IT_WRERR Write Error 00391 * @arg @ref CRYP_IT_RDERR Read Error 00392 * @arg @ref CRYP_IT_CCF Computation Complete 00393 * This parameter can be one of the following values for CRYP: 00394 * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data 00395 * or a key preparation (for AES decryption). 00396 * @arg CRYP_FLAG_IFEM: Input FIFO is empty 00397 * @arg CRYP_FLAG_IFNF: Input FIFO is not full 00398 * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending 00399 * @arg CRYP_FLAG_OFNE: Output FIFO is not empty 00400 * @arg CRYP_FLAG_OFFU: Output FIFO is full 00401 * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending 00402 * @retval The state of __FLAG__ (TRUE or FALSE). 00403 */ 00404 #define CRYP_FLAG_MASK 0x0000001FU 00405 #if defined(CRYP) 00406 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 24)) == 0x01U)?((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \ 00407 ((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK))) 00408 #else /* AES*/ 00409 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 00410 #endif /* End AES or CRYP */ 00411 00412 /** @brief Clear the CRYP pending status flag. 00413 * @param __FLAG__: specifies the flag to clear. 00414 * This parameter can be one of the following values: 00415 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear 00416 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear 00417 * @param __HANDLE__: specifies the CRYP handle. 00418 * @retval None 00419 */ 00420 00421 #if defined(AES) 00422 #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__)) 00423 00424 00425 /** @brief Check whether the specified CRYP interrupt source is enabled or not. 00426 * @param __INTERRUPT__: CRYP interrupt source to check 00427 * This parameter can be one of the following values for TinyAES: 00428 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00429 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00430 * @param __HANDLE__: specifies the CRYP handle. 00431 * @retval State of interruption (TRUE or FALSE). 00432 */ 00433 00434 #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR\ 00435 & (__INTERRUPT__)) == (__INTERRUPT__)) 00436 00437 #endif /* AES */ 00438 00439 /** @brief Check whether the specified CRYP interrupt is set or not. 00440 * @param __INTERRUPT__: specifies the interrupt to check. 00441 * This parameter can be one of the following values for TinyAES: 00442 * @arg @ref CRYP_IT_WRERR Write Error 00443 * @arg @ref CRYP_IT_RDERR Read Error 00444 * @arg @ref CRYP_IT_CCF Computation Complete 00445 * This parameter can be one of the following values for CRYP: 00446 * @arg CRYP_IT_INI: Input FIFO service masked interrupt status 00447 * @arg CRYP_IT_OUTI: Output FIFO service masked interrupt status 00448 * @param __HANDLE__: specifies the CRYP handle. 00449 * @retval The state of __INTERRUPT__ (TRUE or FALSE). 00450 */ 00451 #if defined(CRYP) 00452 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->MISR\ 00453 & (__INTERRUPT__)) == (__INTERRUPT__)) 00454 #else /* AES*/ 00455 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__)) 00456 #endif /* End AES or CRYP */ 00457 00458 /** 00459 * @brief Enable the CRYP interrupt. 00460 * @param __INTERRUPT__: CRYP Interrupt. 00461 * This parameter can be one of the following values for TinyAES: 00462 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00463 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00464 * This parameter can be one of the following values for CRYP: 00465 * @ CRYP_IT_INI : Input FIFO service interrupt mask. 00466 * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt. 00467 * @param __HANDLE__: specifies the CRYP handle. 00468 * @retval None 00469 */ 00470 #if defined(CRYP) 00471 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) |= (__INTERRUPT__)) 00472 #else /* AES*/ 00473 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__)) 00474 #endif /* End AES or CRYP */ 00475 00476 /** 00477 * @brief Disable the CRYP interrupt. 00478 * @param __INTERRUPT__: CRYP Interrupt. 00479 * This parameter can be one of the following values for TinyAES: 00480 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00481 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00482 * This parameter can be one of the following values for CRYP: 00483 * @ CRYP_IT_INI : Input FIFO service interrupt mask. 00484 * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt. 00485 * @param __HANDLE__: specifies the CRYP handle. 00486 * @retval None 00487 */ 00488 #if defined(CRYP) 00489 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) &= ~(__INTERRUPT__)) 00490 #else /* AES*/ 00491 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__)) 00492 #endif /* End AES or CRYP */ 00493 00494 /** 00495 * @} 00496 */ 00497 #if defined (CRYP_CR_ALGOMODE_AES_GCM)|| defined (AES) 00498 /* Include CRYP HAL Extended module */ 00499 #include "stm32f4xx_hal_cryp_ex.h" 00500 #endif /* AES or GCM CCM defined*/ 00501 /* Exported functions --------------------------------------------------------*/ 00502 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions 00503 * @{ 00504 */ 00505 00506 /** @addtogroup CRYP_Exported_Functions_Group1 00507 * @{ 00508 */ 00509 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp); 00510 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp); 00511 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp); 00512 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp); 00513 HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf); 00514 HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf); 00515 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1) 00516 HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID, 00517 pCRYP_CallbackTypeDef pCallback); 00518 HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID); 00519 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */ 00520 /** 00521 * @} 00522 */ 00523 00524 /** @addtogroup CRYP_Exported_Functions_Group2 00525 * @{ 00526 */ 00527 00528 /* encryption/decryption ***********************************/ 00529 HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output, 00530 uint32_t Timeout); 00531 HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output, 00532 uint32_t Timeout); 00533 HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 00534 HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 00535 HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 00536 HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output); 00537 00538 /** 00539 * @} 00540 */ 00541 00542 00543 /** @addtogroup CRYP_Exported_Functions_Group3 00544 * @{ 00545 */ 00546 /* Interrupt Handler functions **********************************************/ 00547 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp); 00548 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp); 00549 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp); 00550 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp); 00551 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp); 00552 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp); 00553 00554 /** 00555 * @} 00556 */ 00557 00558 /** 00559 * @} 00560 */ 00561 00562 /* Private macros --------------------------------------------------------*/ 00563 /** @defgroup CRYP_Private_Macros CRYP Private Macros 00564 * @{ 00565 */ 00566 00567 /** @defgroup CRYP_IS_CRYP_Definitions CRYP Private macros to check input parameters 00568 * @{ 00569 */ 00570 #if defined(CRYP) 00571 #if defined (CRYP_CR_ALGOMODE_AES_GCM) 00572 #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_DES_ECB) || \ 00573 ((ALGORITHM) == CRYP_DES_CBC) || \ 00574 ((ALGORITHM) == CRYP_TDES_ECB) || \ 00575 ((ALGORITHM) == CRYP_TDES_CBC) || \ 00576 ((ALGORITHM) == CRYP_AES_ECB) || \ 00577 ((ALGORITHM) == CRYP_AES_CBC) || \ 00578 ((ALGORITHM) == CRYP_AES_CTR) || \ 00579 ((ALGORITHM) == CRYP_AES_GCM) || \ 00580 ((ALGORITHM) == CRYP_AES_CCM)) 00581 #else /*NO GCM CCM */ 00582 #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_DES_ECB) || \ 00583 ((ALGORITHM) == CRYP_DES_CBC) || \ 00584 ((ALGORITHM) == CRYP_TDES_ECB) || \ 00585 ((ALGORITHM) == CRYP_TDES_CBC) || \ 00586 ((ALGORITHM) == CRYP_AES_ECB) || \ 00587 ((ALGORITHM) == CRYP_AES_CBC) || \ 00588 ((ALGORITHM) == CRYP_AES_CTR)) 00589 #endif /* GCM CCM defined*/ 00590 #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \ 00591 ((KEYSIZE) == CRYP_KEYSIZE_192B) || \ 00592 ((KEYSIZE) == CRYP_KEYSIZE_256B)) 00593 #else /* AES*/ 00594 #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \ 00595 ((ALGORITHM) == CRYP_AES_CBC) || \ 00596 ((ALGORITHM) == CRYP_AES_CTR) || \ 00597 ((ALGORITHM) == CRYP_AES_GCM_GMAC)|| \ 00598 ((ALGORITHM) == CRYP_AES_CCM)) 00599 00600 00601 #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \ 00602 ((KEYSIZE) == CRYP_KEYSIZE_256B)) 00603 #endif /* End AES or CRYP */ 00604 00605 #define IS_CRYP_DATATYPE(DATATYPE)(((DATATYPE) == CRYP_DATATYPE_32B) || \ 00606 ((DATATYPE) == CRYP_DATATYPE_16B) || \ 00607 ((DATATYPE) == CRYP_DATATYPE_8B) || \ 00608 ((DATATYPE) == CRYP_DATATYPE_1B)) 00609 00610 #define IS_CRYP_INIT(CONFIG)(((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \ 00611 ((CONFIG) == CRYP_KEYIVCONFIG_ONCE)) 00612 /** 00613 * @} 00614 */ 00615 00616 /** 00617 * @} 00618 */ 00619 00620 00621 /* Private constants ---------------------------------------------------------*/ 00622 /** @defgroup CRYP_Private_Constants CRYP Private Constants 00623 * @{ 00624 */ 00625 00626 /** 00627 * @} 00628 */ 00629 /* Private defines -----------------------------------------------------------*/ 00630 /** @defgroup CRYP_Private_Defines CRYP Private Defines 00631 * @{ 00632 */ 00633 00634 /** 00635 * @} 00636 */ 00637 00638 /* Private variables ---------------------------------------------------------*/ 00639 /** @defgroup CRYP_Private_Variables CRYP Private Variables 00640 * @{ 00641 */ 00642 00643 /** 00644 * @} 00645 */ 00646 /* Private functions prototypes ----------------------------------------------*/ 00647 /** @defgroup CRYP_Private_Functions_Prototypes CRYP Private Functions Prototypes 00648 * @{ 00649 */ 00650 00651 /** 00652 * @} 00653 */ 00654 00655 /* Private functions ---------------------------------------------------------*/ 00656 /** @defgroup CRYP_Private_Functions CRYP Private Functions 00657 * @{ 00658 */ 00659 00660 /** 00661 * @} 00662 */ 00663 00664 00665 /** 00666 * @} 00667 */ 00668 00669 00670 /** 00671 * @} 00672 */ 00673 #endif /* TinyAES or CRYP*/ 00674 00675 /** 00676 * @} 00677 */ 00678 00679 #ifdef __cplusplus 00680 } 00681 #endif 00682 00683 #endif /* __STM32F4xx_HAL_CRYP_H */ 00684 00685 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/