STM32F439xx 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) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 /* Define to prevent recursive inclusion -------------------------------------*/ 00037 #ifndef __STM32F4xx_HAL_CRYP_H 00038 #define __STM32F4xx_HAL_CRYP_H 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 /* Includes ------------------------------------------------------------------*/ 00045 #include "stm32f4xx_hal_def.h" 00046 00047 00048 #if defined(CRYP) 00049 00050 /** @addtogroup STM32F4xx_HAL_Driver 00051 * @{ 00052 */ 00053 00054 /** @addtogroup CRYP 00055 * @{ 00056 */ 00057 00058 /* Exported types ------------------------------------------------------------*/ 00059 00060 /** @defgroup CRYP_Exported_Types CRYP Exported Types 00061 * @{ 00062 */ 00063 00064 /** @defgroup CRYP_Exported_Types_Group1 CRYP Configuration Structure definition 00065 * @{ 00066 */ 00067 00068 typedef struct 00069 { 00070 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string. 00071 This parameter can be a value of @ref CRYP_Data_Type */ 00072 00073 uint32_t KeySize; /*!< Used only in AES mode only : 128, 192 or 256 bit key length. 00074 This parameter can be a value of @ref CRYP_Key_Size */ 00075 00076 uint8_t* pKey; /*!< The key used for encryption/decryption */ 00077 00078 uint8_t* pInitVect; /*!< The initialization vector used also as initialization 00079 counter in CTR mode */ 00080 00081 uint8_t IVSize; /*!< The size of initialization vector. 00082 This parameter (called nonce size in CCM) is used only 00083 in AES-128/192/256 encryption/decryption CCM mode */ 00084 00085 uint8_t TagSize; /*!< The size of returned authentication TAG. 00086 This parameter is used only in AES-128/192/256 00087 encryption/decryption CCM mode */ 00088 00089 uint8_t* Header; /*!< The header used in GCM and CCM modes */ 00090 00091 uint32_t HeaderSize; /*!< The size of header buffer in bytes */ 00092 00093 uint8_t* pScratch; /*!< Scratch buffer used to append the header. It's size must be equal to header size + 21 bytes. 00094 This parameter is used only in AES-128/192/256 encryption/decryption CCM mode */ 00095 }CRYP_InitTypeDef; 00096 00097 /** 00098 * @} 00099 */ 00100 00101 /** @defgroup CRYP_Exported_Types_Group2 CRYP State structures definition 00102 * @{ 00103 */ 00104 00105 00106 typedef enum 00107 { 00108 HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */ 00109 HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */ 00110 HAL_CRYP_STATE_BUSY = 0x02U, /*!< CRYP internal processing is ongoing */ 00111 HAL_CRYP_STATE_TIMEOUT = 0x03U, /*!< CRYP timeout state */ 00112 HAL_CRYP_STATE_ERROR = 0x04U /*!< CRYP error state */ 00113 }HAL_CRYP_STATETypeDef; 00114 00115 /** 00116 * @} 00117 */ 00118 00119 /** @defgroup CRYP_Exported_Types_Group3 CRYP phase structures definition 00120 * @{ 00121 */ 00122 00123 00124 typedef enum 00125 { 00126 HAL_CRYP_PHASE_READY = 0x01U, /*!< CRYP peripheral is ready for initialization. */ 00127 HAL_CRYP_PHASE_PROCESS = 0x02U, /*!< CRYP peripheral is in processing phase */ 00128 HAL_CRYP_PHASE_FINAL = 0x03U /*!< CRYP peripheral is in final phase 00129 This is relevant only with CCM and GCM modes */ 00130 }HAL_PhaseTypeDef; 00131 00132 /** 00133 * @} 00134 */ 00135 00136 /** @defgroup CRYP_Exported_Types_Group4 CRYP handle Structure definition 00137 * @{ 00138 */ 00139 00140 typedef struct 00141 { 00142 CRYP_TypeDef *Instance; /*!< CRYP registers base address */ 00143 00144 CRYP_InitTypeDef Init; /*!< CRYP required parameters */ 00145 00146 uint8_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */ 00147 00148 uint8_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */ 00149 00150 __IO uint16_t CrypInCount; /*!< Counter of inputed data */ 00151 00152 __IO uint16_t CrypOutCount; /*!< Counter of output data */ 00153 00154 HAL_StatusTypeDef Status; /*!< CRYP peripheral status */ 00155 00156 HAL_PhaseTypeDef Phase; /*!< CRYP peripheral phase */ 00157 00158 DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */ 00159 00160 DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */ 00161 00162 HAL_LockTypeDef Lock; /*!< CRYP locking object */ 00163 00164 __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */ 00165 }CRYP_HandleTypeDef; 00166 00167 /** 00168 * @} 00169 */ 00170 00171 /** 00172 * @} 00173 */ 00174 00175 /* Exported constants --------------------------------------------------------*/ 00176 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants 00177 * @{ 00178 */ 00179 00180 /** @defgroup CRYP_Key_Size CRYP Key Size 00181 * @{ 00182 */ 00183 #define CRYP_KEYSIZE_128B 0x00000000U 00184 #define CRYP_KEYSIZE_192B CRYP_CR_KEYSIZE_0 00185 #define CRYP_KEYSIZE_256B CRYP_CR_KEYSIZE_1 00186 /** 00187 * @} 00188 */ 00189 00190 /** @defgroup CRYP_Data_Type CRYP Data Type 00191 * @{ 00192 */ 00193 #define CRYP_DATATYPE_32B 0x00000000U 00194 #define CRYP_DATATYPE_16B CRYP_CR_DATATYPE_0 00195 #define CRYP_DATATYPE_8B CRYP_CR_DATATYPE_1 00196 #define CRYP_DATATYPE_1B CRYP_CR_DATATYPE 00197 /** 00198 * @} 00199 */ 00200 00201 /** @defgroup CRYP_Exported_Constants_Group3 CRYP CRYP_AlgoModeDirection 00202 * @{ 00203 */ 00204 #define CRYP_CR_ALGOMODE_DIRECTION 0x0008003CU 00205 #define CRYP_CR_ALGOMODE_TDES_ECB_ENCRYPT 0x00000000U 00206 #define CRYP_CR_ALGOMODE_TDES_ECB_DECRYPT 0x00000004U 00207 #define CRYP_CR_ALGOMODE_TDES_CBC_ENCRYPT 0x00000008U 00208 #define CRYP_CR_ALGOMODE_TDES_CBC_DECRYPT 0x0000000CU 00209 #define CRYP_CR_ALGOMODE_DES_ECB_ENCRYPT 0x00000010U 00210 #define CRYP_CR_ALGOMODE_DES_ECB_DECRYPT 0x00000014U 00211 #define CRYP_CR_ALGOMODE_DES_CBC_ENCRYPT 0x00000018U 00212 #define CRYP_CR_ALGOMODE_DES_CBC_DECRYPT 0x0000001CU 00213 #define CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT 0x00000020U 00214 #define CRYP_CR_ALGOMODE_AES_ECB_DECRYPT 0x00000024U 00215 #define CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT 0x00000028U 00216 #define CRYP_CR_ALGOMODE_AES_CBC_DECRYPT 0x0000002CU 00217 #define CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT 0x00000030U 00218 #define CRYP_CR_ALGOMODE_AES_CTR_DECRYPT 0x00000034U 00219 /** 00220 * @} 00221 */ 00222 00223 /** @defgroup CRYP_Exported_Constants_Group4 CRYP CRYP_Interrupt 00224 * @{ 00225 */ 00226 #define CRYP_IT_INI ((uint32_t)CRYP_IMSCR_INIM) /*!< Input FIFO Interrupt */ 00227 #define CRYP_IT_OUTI ((uint32_t)CRYP_IMSCR_OUTIM) /*!< Output FIFO Interrupt */ 00228 /** 00229 * @} 00230 */ 00231 00232 /** @defgroup CRYP_Exported_Constants_Group5 CRYP CRYP_Flags 00233 * @{ 00234 */ 00235 #define CRYP_FLAG_BUSY 0x00000010U /*!< The CRYP core is currently 00236 processing a block of data 00237 or a key preparation (for 00238 AES decryption). */ 00239 #define CRYP_FLAG_IFEM 0x00000001U /*!< Input FIFO is empty */ 00240 #define CRYP_FLAG_IFNF 0x00000002U /*!< Input FIFO is not Full */ 00241 #define CRYP_FLAG_OFNE 0x00000004U /*!< Output FIFO is not empty */ 00242 #define CRYP_FLAG_OFFU 0x00000008U /*!< Output FIFO is Full */ 00243 #define CRYP_FLAG_OUTRIS 0x01000002U /*!< Output FIFO service raw 00244 interrupt status */ 00245 #define CRYP_FLAG_INRIS 0x01000001U /*!< Input FIFO service raw 00246 interrupt status */ 00247 /** 00248 * @} 00249 */ 00250 00251 /** 00252 * @} 00253 */ 00254 00255 /* Exported macro ------------------------------------------------------------*/ 00256 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros 00257 * @{ 00258 */ 00259 00260 /** @brief Reset CRYP handle state 00261 * @param __HANDLE__ specifies the CRYP handle. 00262 * @retval None 00263 */ 00264 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET) 00265 00266 /** 00267 * @brief Enable/Disable the CRYP peripheral. 00268 * @param __HANDLE__ specifies the CRYP handle. 00269 * @retval None 00270 */ 00271 #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_CRYPEN) 00272 #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~CRYP_CR_CRYPEN) 00273 00274 /** 00275 * @brief Flush the data FIFO. 00276 * @param __HANDLE__ specifies the CRYP handle. 00277 * @retval None 00278 */ 00279 #define __HAL_CRYP_FIFO_FLUSH(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_FFLUSH) 00280 00281 /** 00282 * @brief Set the algorithm mode: AES-ECB, AES-CBC, AES-CTR, DES-ECB, DES-CBC. 00283 * @param __HANDLE__ specifies the CRYP handle. 00284 * @param MODE The algorithm mode. 00285 * @retval None 00286 */ 00287 #define __HAL_CRYP_SET_MODE(__HANDLE__, MODE) ((__HANDLE__)->Instance->CR |= (uint32_t)(MODE)) 00288 00289 /** @brief Check whether the specified CRYP flag is set or not. 00290 * @param __HANDLE__ specifies the CRYP handle. 00291 * @param __FLAG__ specifies the flag to check. 00292 * This parameter can be one of the following values: 00293 * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data 00294 * or a key preparation (for AES decryption). 00295 * @arg CRYP_FLAG_IFEM: Input FIFO is empty 00296 * @arg CRYP_FLAG_IFNF: Input FIFO is not full 00297 * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending 00298 * @arg CRYP_FLAG_OFNE: Output FIFO is not empty 00299 * @arg CRYP_FLAG_OFFU: Output FIFO is full 00300 * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending 00301 * @retval The new state of __FLAG__ (TRUE or FALSE). 00302 */ 00303 00304 #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 24U)) == 0x01U)?((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \ 00305 ((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK))) 00306 00307 /** @brief Check whether the specified CRYP interrupt is set or not. 00308 * @param __HANDLE__ specifies the CRYP handle. 00309 * @param __INTERRUPT__ specifies the interrupt to check. 00310 * This parameter can be one of the following values: 00311 * @arg CRYP_IT_INRIS: Input FIFO service raw interrupt is pending 00312 * @arg CRYP_IT_OUTRIS: Output FIFO service raw interrupt is pending 00313 * @retval The new state of __INTERRUPT__ (TRUE or FALSE). 00314 */ 00315 #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->MISR & (__INTERRUPT__)) == (__INTERRUPT__)) 00316 00317 /** 00318 * @brief Enable the CRYP interrupt. 00319 * @param __HANDLE__ specifies the CRYP handle. 00320 * @param __INTERRUPT__ CRYP Interrupt. 00321 * @retval None 00322 */ 00323 #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) |= (__INTERRUPT__)) 00324 00325 /** 00326 * @brief Disable the CRYP interrupt. 00327 * @param __HANDLE__ specifies the CRYP handle. 00328 * @param __INTERRUPT__ CRYP interrupt. 00329 * @retval None 00330 */ 00331 #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) &= ~(__INTERRUPT__)) 00332 00333 /** 00334 * @} 00335 */ 00336 00337 /* Include CRYP HAL Extension module */ 00338 #include "stm32f4xx_hal_cryp_ex.h" 00339 00340 /* Exported functions --------------------------------------------------------*/ 00341 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions 00342 * @{ 00343 */ 00344 00345 /** @addtogroup CRYP_Exported_Functions_Group1 00346 * @{ 00347 */ 00348 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp); 00349 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp); 00350 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp); 00351 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp); 00352 /** 00353 * @} 00354 */ 00355 00356 /** @addtogroup CRYP_Exported_Functions_Group2 00357 * @{ 00358 */ 00359 /* AES encryption/decryption using polling ***********************************/ 00360 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00361 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00362 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00363 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00364 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00365 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00366 00367 /* AES encryption/decryption using interrupt *********************************/ 00368 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00369 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00370 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00371 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00372 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00373 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00374 00375 /* AES encryption/decryption using DMA ***************************************/ 00376 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00377 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00378 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00379 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00380 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00381 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00382 /** 00383 * @} 00384 */ 00385 00386 /** @addtogroup CRYP_Exported_Functions_Group3 00387 * @{ 00388 */ 00389 /* DES encryption/decryption using polling ***********************************/ 00390 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00391 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00392 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00393 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00394 00395 /* DES encryption/decryption using interrupt *********************************/ 00396 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00397 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00398 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00399 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00400 00401 /* DES encryption/decryption using DMA ***************************************/ 00402 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00403 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00404 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00405 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00406 /** 00407 * @} 00408 */ 00409 00410 /** @addtogroup CRYP_Exported_Functions_Group4 00411 * @{ 00412 */ 00413 /* TDES encryption/decryption using polling **********************************/ 00414 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00415 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 00416 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00417 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 00418 00419 /* TDES encryption/decryption using interrupt ********************************/ 00420 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00421 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00422 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00423 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00424 00425 /* TDES encryption/decryption using DMA **************************************/ 00426 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00427 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00428 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 00429 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 00430 /** 00431 * @} 00432 */ 00433 00434 /** @addtogroup CRYP_Exported_Functions_Group5 00435 * @{ 00436 */ 00437 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp); 00438 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp); 00439 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp); 00440 /** 00441 * @} 00442 */ 00443 00444 /** @addtogroup CRYP_Exported_Functions_Group6 00445 * @{ 00446 */ 00447 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp); 00448 /** 00449 * @} 00450 */ 00451 00452 /** @addtogroup CRYP_Exported_Functions_Group7 00453 * @{ 00454 */ 00455 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp); 00456 /** 00457 * @} 00458 */ 00459 00460 /** 00461 * @} 00462 */ 00463 00464 /* Private types -------------------------------------------------------------*/ 00465 /** @defgroup CRYP_Private_Types CRYP Private Types 00466 * @{ 00467 */ 00468 00469 /** 00470 * @} 00471 */ 00472 00473 /* Private variables ---------------------------------------------------------*/ 00474 /** @defgroup CRYP_Private_Variables CRYP Private Variables 00475 * @{ 00476 */ 00477 00478 /** 00479 * @} 00480 */ 00481 00482 /* Private constants ---------------------------------------------------------*/ 00483 /** @defgroup CRYP_Private_Constants CRYP Private Constants 00484 * @{ 00485 */ 00486 #define CRYP_FLAG_MASK 0x0000001FU 00487 /** 00488 * @} 00489 */ 00490 00491 /* Private macros ------------------------------------------------------------*/ 00492 /** @defgroup CRYP_Private_Macros CRYP Private Macros 00493 * @{ 00494 */ 00495 00496 #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \ 00497 ((__KEYSIZE__) == CRYP_KEYSIZE_192B) || \ 00498 ((__KEYSIZE__) == CRYP_KEYSIZE_256B)) 00499 00500 00501 #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \ 00502 ((__DATATYPE__) == CRYP_DATATYPE_16B) || \ 00503 ((__DATATYPE__) == CRYP_DATATYPE_8B) || \ 00504 ((__DATATYPE__) == CRYP_DATATYPE_1B)) 00505 00506 00507 /** 00508 * @} 00509 */ 00510 00511 /* Private functions ---------------------------------------------------------*/ 00512 /** @defgroup CRYP_Private_Functions CRYP Private Functions 00513 * @{ 00514 */ 00515 00516 /** 00517 * @} 00518 */ 00519 00520 #endif /* CRYP */ 00521 00522 #if defined (AES) 00523 00524 /** @addtogroup STM32F4xx_HAL_Driver 00525 * @{ 00526 */ 00527 00528 /** @addtogroup CRYP 00529 * @{ 00530 */ 00531 00532 /* Exported types ------------------------------------------------------------*/ 00533 /** @defgroup CRYP_Exported_Types CRYP Exported Types 00534 * @{ 00535 */ 00536 00537 /** 00538 * @brief CRYP Configuration Structure definition 00539 */ 00540 typedef struct 00541 { 00542 uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string. 00543 This parameter can be a value of @ref CRYP_Data_Type */ 00544 00545 uint32_t KeySize; /*!< 128 or 256-bit key length. 00546 This parameter can be a value of @ref CRYP_Key_Size */ 00547 00548 uint32_t OperatingMode; /*!< AES operating mode. 00549 This parameter can be a value of @ref CRYP_AES_OperatingMode */ 00550 00551 uint32_t ChainingMode; /*!< AES chaining mode. 00552 This parameter can be a value of @ref CRYP_AES_ChainingMode */ 00553 00554 uint32_t KeyWriteFlag; /*!< Allows to bypass or not key write-up before decryption. 00555 This parameter can be a value of @ref CRYP_Key_Write */ 00556 00557 uint32_t GCMCMACPhase; /*!< Indicates the processing phase of the Galois Counter Mode (GCM), 00558 Galois Message Authentication Code (GMAC) or Cipher Message 00559 Authentication Code (CMAC) or Counter with Cipher Mode (CCM) when 00560 the latter is applicable. 00561 This parameter can be a value of @ref CRYP_GCM_CMAC_Phase */ 00562 00563 uint8_t* pKey; /*!< Encryption/Decryption Key */ 00564 00565 uint8_t* pInitVect; /*!< Initialization Vector used for CTR, CBC, GCM/GMAC, CMAC, 00566 (and CCM when applicable) modes */ 00567 00568 uint8_t* Header; /*!< Header used in GCM/GMAC, CMAC (and CCM when applicable) modes */ 00569 00570 uint64_t HeaderSize; /*!< Header size in bytes */ 00571 00572 }CRYP_InitTypeDef; 00573 00574 /** 00575 * @brief HAL CRYP State structures definition 00576 */ 00577 typedef enum 00578 { 00579 HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */ 00580 HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */ 00581 HAL_CRYP_STATE_BUSY = 0x02U, /*!< CRYP internal processing is ongoing */ 00582 HAL_CRYP_STATE_TIMEOUT = 0x03U, /*!< CRYP timeout state */ 00583 HAL_CRYP_STATE_ERROR = 0x04U, /*!< CRYP error state */ 00584 HAL_CRYP_STATE_SUSPENDED = 0x05U /*!< CRYP suspended */ 00585 }HAL_CRYP_STATETypeDef; 00586 00587 /** 00588 * @brief HAL CRYP phase structures definition 00589 */ 00590 typedef enum 00591 { 00592 HAL_CRYP_PHASE_READY = 0x01U, /*!< CRYP peripheral is ready for initialization. */ 00593 HAL_CRYP_PHASE_PROCESS = 0x02U, /*!< CRYP peripheral is in processing phase */ 00594 HAL_CRYP_PHASE_START = 0x03U, /*!< CRYP peripheral has been initialized but 00595 GCM/GMAC/CMAC(/CCM) initialization phase has not started */ 00596 HAL_CRYP_PHASE_INIT_OVER = 0x04U, /*!< GCM/GMAC/CMAC(/CCM) init phase has been carried out */ 00597 HAL_CRYP_PHASE_HEADER_OVER = 0x05U, /*!< GCM/GMAC/CMAC(/CCM) header phase has been carried out */ 00598 HAL_CRYP_PHASE_PAYLOAD_OVER = 0x06U, /*!< GCM(/CCM) payload phase has been carried out */ 00599 HAL_CRYP_PHASE_FINAL_OVER = 0x07U, /*!< GCM/GMAC/CMAC(/CCM) final phase has been carried out */ 00600 HAL_CRYP_PHASE_HEADER_SUSPENDED = 0x08U, /*!< GCM/GMAC/CMAC(/CCM) header phase has been suspended */ 00601 HAL_CRYP_PHASE_PAYLOAD_SUSPENDED = 0x09U, /*!< GCM(/CCM) payload phase has been suspended */ 00602 HAL_CRYP_PHASE_NOT_USED = 0x0AU /*!< Phase is irrelevant to the current chaining mode */ 00603 }HAL_PhaseTypeDef; 00604 00605 /** 00606 * @brief HAL CRYP mode suspend definitions 00607 */ 00608 typedef enum 00609 { 00610 HAL_CRYP_SUSPEND_NONE = 0x00U, /*!< CRYP peripheral suspension not requested */ 00611 HAL_CRYP_SUSPEND = 0x01U /*!< CRYP peripheral suspension requested */ 00612 }HAL_SuspendTypeDef; 00613 00614 00615 /** 00616 * @brief HAL CRYP Error Codes definition 00617 */ 00618 #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */ 00619 #define HAL_CRYP_WRITE_ERROR 0x00000001U /*!< Write error */ 00620 #define HAL_CRYP_READ_ERROR 0x00000002U /*!< Read error */ 00621 #define HAL_CRYP_DMA_ERROR 0x00000004U /*!< DMA error */ 00622 #define HAL_CRYP_BUSY_ERROR 0x00000008U /*!< Busy flag error */ 00623 00624 /** 00625 * @brief CRYP handle Structure definition 00626 */ 00627 typedef struct 00628 { 00629 AES_TypeDef *Instance; /*!< Register base address */ 00630 00631 CRYP_InitTypeDef Init; /*!< CRYP initialization parameters */ 00632 00633 uint8_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) input buffer */ 00634 00635 uint8_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) output buffer */ 00636 00637 uint32_t CrypInCount; /*!< Input data size in bytes or, after suspension, the remaining 00638 number of bytes to process */ 00639 00640 uint32_t CrypOutCount; /*!< Output data size in bytes */ 00641 00642 HAL_PhaseTypeDef Phase; /*!< CRYP peripheral processing phase for GCM, GMAC, CMAC 00643 (or CCM when applicable) modes. 00644 Indicates the last phase carried out to ease 00645 phase transitions */ 00646 00647 DMA_HandleTypeDef *hdmain; /*!< CRYP peripheral Input DMA handle parameters */ 00648 00649 DMA_HandleTypeDef *hdmaout; /*!< CRYP peripheral Output DMA handle parameters */ 00650 00651 HAL_LockTypeDef Lock; /*!< CRYP locking object */ 00652 00653 __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */ 00654 00655 __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */ 00656 00657 HAL_SuspendTypeDef SuspendRequest; /*!< CRYP peripheral suspension request flag */ 00658 }CRYP_HandleTypeDef; 00659 00660 /** 00661 * @} 00662 */ 00663 00664 00665 /* Exported constants --------------------------------------------------------*/ 00666 /** @defgroup CRYP_Exported_Constants CRYP Exported Constants 00667 * @{ 00668 */ 00669 00670 /** @defgroup CRYP_Key_Size Key size selection 00671 * @{ 00672 */ 00673 #define CRYP_KEYSIZE_128B 0x00000000U /*!< 128-bit long key */ 00674 #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */ 00675 /** 00676 * @} 00677 */ 00678 00679 /** @defgroup CRYP_Data_Type AES Data Type selection 00680 * @{ 00681 */ 00682 #define CRYP_DATATYPE_32B 0x00000000U /*!< 32-bit data type (no swapping) */ 00683 #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */ 00684 #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */ 00685 #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */ 00686 /** 00687 * @} 00688 */ 00689 00690 /** @defgroup CRYP_AES_State AES Enable state 00691 * @{ 00692 */ 00693 #define CRYP_AES_DISABLE 0x00000000U /*!< Disable AES */ 00694 #define CRYP_AES_ENABLE AES_CR_EN /*!< Enable AES */ 00695 /** 00696 * @} 00697 */ 00698 00699 /** @defgroup CRYP_AES_OperatingMode AES operating mode 00700 * @{ 00701 */ 00702 #define CRYP_ALGOMODE_ENCRYPT 0x00000000U /*!< Encryption mode */ 00703 #define CRYP_ALGOMODE_KEYDERIVATION AES_CR_MODE_0 /*!< Key derivation mode */ 00704 #define CRYP_ALGOMODE_DECRYPT AES_CR_MODE_1 /*!< Decryption */ 00705 #define CRYP_ALGOMODE_KEYDERIVATION_DECRYPT AES_CR_MODE /*!< Key derivation and decryption */ 00706 #define CRYP_ALGOMODE_TAG_GENERATION 0x00000000U /*!< GMAC or CMAC authentication tag generation */ 00707 /** 00708 * @} 00709 */ 00710 00711 /** @defgroup CRYP_AES_ChainingMode AES chaining mode 00712 * @{ 00713 */ 00714 #define CRYP_CHAINMODE_AES_ECB 0x00000000U /*!< Electronic codebook chaining algorithm */ 00715 #define CRYP_CHAINMODE_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */ 00716 #define CRYP_CHAINMODE_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */ 00717 #define CRYP_CHAINMODE_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */ 00718 #define CRYP_CHAINMODE_AES_CMAC AES_CR_CHMOD_2 /*!< Cipher message authentication code */ 00719 #if defined(AES_CR_NPBLB) 00720 #define CRYP_CHAINMODE_AES_CCM_CMAC AES_CR_CHMOD_2 /*!< Counter with Cipher Mode - Cipher message authentication code */ 00721 #endif 00722 /** 00723 * @} 00724 */ 00725 00726 /** @defgroup CRYP_Key_Write AES decryption key write-up flag 00727 * @{ 00728 */ 00729 #define CRYP_KEY_WRITE_ENABLE 0x00000000U /*!< Enable decryption key writing */ 00730 #define CRYP_KEY_WRITE_DISABLE 0x00000001U /*!< Disable decryption key writing */ 00731 /** 00732 * @} 00733 */ 00734 00735 /** @defgroup CRYP_DMAIN DMA Input phase management enable state 00736 * @{ 00737 */ 00738 #define CRYP_DMAIN_DISABLE 0x00000000U /*!< Disable DMA Input phase management */ 00739 #define CRYP_DMAIN_ENABLE AES_CR_DMAINEN /*!< Enable DMA Input phase management */ 00740 /** 00741 * @} 00742 */ 00743 00744 /** @defgroup CRYP_DMAOUT DMA Output phase management enable state 00745 * @{ 00746 */ 00747 #define CRYP_DMAOUT_DISABLE 0x00000000U /*!< Disable DMA Output phase management */ 00748 #define CRYP_DMAOUT_ENABLE AES_CR_DMAOUTEN /*!< Enable DMA Output phase management */ 00749 /** 00750 * @} 00751 */ 00752 00753 00754 /** @defgroup CRYP_GCM_CMAC_Phase GCM/GMAC and CMAC processing phase selection 00755 * @{ 00756 */ 00757 #define CRYP_GCM_INIT_PHASE 0x00000000U /*!< GCM/GMAC (or CCM) init phase */ 00758 #define CRYP_GCMCMAC_HEADER_PHASE AES_CR_GCMPH_0 /*!< GCM/GMAC or (CCM/)CMAC header phase */ 00759 #define CRYP_GCM_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< GCM(/CCM) payload phase */ 00760 #define CRYP_GCMCMAC_FINAL_PHASE AES_CR_GCMPH /*!< GCM/GMAC or (CCM/)CMAC final phase */ 00761 /* Definitions duplication for code readibility's sake: 00762 supported or not supported chain modes are not specified for each phase */ 00763 #define CRYP_INIT_PHASE 0x00000000U /*!< Init phase */ 00764 #define CRYP_HEADER_PHASE AES_CR_GCMPH_0 /*!< Header phase */ 00765 #define CRYP_PAYLOAD_PHASE AES_CR_GCMPH_1 /*!< Payload phase */ 00766 #define CRYP_FINAL_PHASE AES_CR_GCMPH /*!< Final phase */ 00767 /** 00768 * @} 00769 */ 00770 00771 /** @defgroup CRYP_Flags AES status flags 00772 * @{ 00773 */ 00774 00775 #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */ 00776 #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */ 00777 #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */ 00778 #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */ 00779 /** 00780 * @} 00781 */ 00782 00783 /** @defgroup CRYP_Clear_Flags AES clearing flags 00784 * @{ 00785 */ 00786 00787 #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */ 00788 #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */ 00789 /** 00790 * @} 00791 */ 00792 00793 /** @defgroup AES_Interrupts_Enable AES Interrupts Enable bits 00794 * @{ 00795 */ 00796 #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */ 00797 #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */ 00798 /** 00799 * @} 00800 */ 00801 00802 /** @defgroup CRYP_Interrupts_Flags AES Interrupts flags 00803 * @{ 00804 */ 00805 #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */ 00806 #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */ 00807 #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */ 00808 /** 00809 * @} 00810 */ 00811 00812 /** 00813 * @} 00814 */ 00815 00816 /* Exported macros -----------------------------------------------------------*/ 00817 /** @defgroup CRYP_Exported_Macros CRYP Exported Macros 00818 * @{ 00819 */ 00820 00821 /** @brief Reset CRYP handle state. 00822 * @param __HANDLE__ specifies the CRYP handle. 00823 * @retval None 00824 */ 00825 #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRYP_STATE_RESET) 00826 00827 /** 00828 * @brief Enable the CRYP AES peripheral. 00829 * @retval None 00830 */ 00831 #define __HAL_CRYP_ENABLE() (AES->CR |= AES_CR_EN) 00832 00833 /** 00834 * @brief Disable the CRYP AES peripheral. 00835 * @retval None 00836 */ 00837 #define __HAL_CRYP_DISABLE() (AES->CR &= ~AES_CR_EN) 00838 00839 /** 00840 * @brief Set the algorithm operating mode. 00841 * @param __OPERATING_MODE__ specifies the operating mode 00842 * This parameter can be one of the following values: 00843 * @arg @ref CRYP_ALGOMODE_ENCRYPT encryption 00844 * @arg @ref CRYP_ALGOMODE_KEYDERIVATION key derivation 00845 * @arg @ref CRYP_ALGOMODE_DECRYPT decryption 00846 * @arg @ref CRYP_ALGOMODE_KEYDERIVATION_DECRYPT key derivation and decryption 00847 * @retval None 00848 */ 00849 #define __HAL_CRYP_SET_OPERATINGMODE(__OPERATING_MODE__) MODIFY_REG(AES->CR, AES_CR_MODE, (__OPERATING_MODE__)) 00850 00851 00852 /** 00853 * @brief Set the algorithm chaining mode. 00854 * @param __CHAINING_MODE__ specifies the chaining mode 00855 * This parameter can be one of the following values: 00856 * @arg @ref CRYP_CHAINMODE_AES_ECB Electronic CodeBook 00857 * @arg @ref CRYP_CHAINMODE_AES_CBC Cipher Block Chaining 00858 * @arg @ref CRYP_CHAINMODE_AES_CTR CounTeR mode 00859 * @arg @ref CRYP_CHAINMODE_AES_GCM_GMAC Galois Counter Mode or Galois Message Authentication Code 00860 * @arg @ref CRYP_CHAINMODE_AES_CMAC Cipher Message Authentication Code (or Counter with Cipher Mode when applicable) 00861 * @retval None 00862 */ 00863 #define __HAL_CRYP_SET_CHAININGMODE(__CHAINING_MODE__) MODIFY_REG(AES->CR, AES_CR_CHMOD, (__CHAINING_MODE__)) 00864 00865 00866 00867 /** @brief Check whether the specified CRYP status flag is set or not. 00868 * @param __FLAG__ specifies the flag to check. 00869 * This parameter can be one of the following values: 00870 * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden 00871 * @arg @ref CRYP_IT_WRERR Write Error 00872 * @arg @ref CRYP_IT_RDERR Read Error 00873 * @arg @ref CRYP_IT_CCF Computation Complete 00874 * @retval The state of __FLAG__ (TRUE or FALSE). 00875 */ 00876 #define __HAL_CRYP_GET_FLAG(__FLAG__) ((AES->SR & (__FLAG__)) == (__FLAG__)) 00877 00878 00879 /** @brief Clear the CRYP pending status flag. 00880 * @param __FLAG__ specifies the flag to clear. 00881 * This parameter can be one of the following values: 00882 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear 00883 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear 00884 * @retval None 00885 */ 00886 #define __HAL_CRYP_CLEAR_FLAG(__FLAG__) SET_BIT(AES->CR, (__FLAG__)) 00887 00888 00889 00890 /** @brief Check whether the specified CRYP interrupt source is enabled or not. 00891 * @param __INTERRUPT__ CRYP interrupt source to check 00892 * This parameter can be one of the following values: 00893 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00894 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00895 * @retval State of interruption (TRUE or FALSE). 00896 */ 00897 #define __HAL_CRYP_GET_IT_SOURCE(__INTERRUPT__) ((AES->CR & (__INTERRUPT__)) == (__INTERRUPT__)) 00898 00899 00900 /** @brief Check whether the specified CRYP interrupt is set or not. 00901 * @param __INTERRUPT__ specifies the interrupt to check. 00902 * This parameter can be one of the following values: 00903 * @arg @ref CRYP_IT_WRERR Write Error 00904 * @arg @ref CRYP_IT_RDERR Read Error 00905 * @arg @ref CRYP_IT_CCF Computation Complete 00906 * @retval The state of __INTERRUPT__ (TRUE or FALSE). 00907 */ 00908 #define __HAL_CRYP_GET_IT(__INTERRUPT__) ((AES->SR & (__INTERRUPT__)) == (__INTERRUPT__)) 00909 00910 00911 00912 /** @brief Clear the CRYP pending interrupt. 00913 * @param __INTERRUPT__ specifies the IT to clear. 00914 * This parameter can be one of the following values: 00915 * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear 00916 * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear 00917 * @retval None 00918 */ 00919 #define __HAL_CRYP_CLEAR_IT(__INTERRUPT__) SET_BIT(AES->CR, (__INTERRUPT__)) 00920 00921 00922 /** 00923 * @brief Enable the CRYP interrupt. 00924 * @param __INTERRUPT__ CRYP Interrupt. 00925 * This parameter can be one of the following values: 00926 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00927 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00928 * @retval None 00929 */ 00930 #define __HAL_CRYP_ENABLE_IT(__INTERRUPT__) ((AES->CR) |= (__INTERRUPT__)) 00931 00932 00933 /** 00934 * @brief Disable the CRYP interrupt. 00935 * @param __INTERRUPT__ CRYP Interrupt. 00936 * This parameter can be one of the following values: 00937 * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR) 00938 * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt 00939 * @retval None 00940 */ 00941 #define __HAL_CRYP_DISABLE_IT(__INTERRUPT__) ((AES->CR) &= ~(__INTERRUPT__)) 00942 00943 /** 00944 * @} 00945 */ 00946 00947 /* Private macros --------------------------------------------------------*/ 00948 /** @addtogroup CRYP_Private_Macros CRYP Private Macros 00949 * @{ 00950 */ 00951 00952 /** 00953 * @brief Verify the key size length. 00954 * @param __KEYSIZE__ Ciphering/deciphering algorithm key size. 00955 * @retval SET (__KEYSIZE__ is a valid value) or RESET (__KEYSIZE__ is invalid) 00956 */ 00957 #define IS_CRYP_KEYSIZE(__KEYSIZE__) (((__KEYSIZE__) == CRYP_KEYSIZE_128B) || \ 00958 ((__KEYSIZE__) == CRYP_KEYSIZE_256B)) 00959 00960 /** 00961 * @brief Verify the input data type. 00962 * @param __DATATYPE__ Ciphering/deciphering algorithm input data type. 00963 * @retval SET (__DATATYPE__ is valid) or RESET (__DATATYPE__ is invalid) 00964 */ 00965 #define IS_CRYP_DATATYPE(__DATATYPE__) (((__DATATYPE__) == CRYP_DATATYPE_32B) || \ 00966 ((__DATATYPE__) == CRYP_DATATYPE_16B) || \ 00967 ((__DATATYPE__) == CRYP_DATATYPE_8B) || \ 00968 ((__DATATYPE__) == CRYP_DATATYPE_1B)) 00969 00970 /** 00971 * @brief Verify the CRYP AES IP running mode. 00972 * @param __MODE__ CRYP AES IP running mode. 00973 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 00974 */ 00975 #define IS_CRYP_AES(__MODE__) (((__MODE__) == CRYP_AES_DISABLE) || \ 00976 ((__MODE__) == CRYP_AES_ENABLE)) 00977 00978 /** 00979 * @brief Verify the selected CRYP algorithm. 00980 * @param __ALGOMODE__ Selected CRYP algorithm (ciphering, deciphering, key derivation or a combination of the latter). 00981 * @retval SET (__ALGOMODE__ is valid) or RESET (__ALGOMODE__ is invalid) 00982 */ 00983 #define IS_CRYP_ALGOMODE(__ALGOMODE__) (((__ALGOMODE__) == CRYP_ALGOMODE_ENCRYPT) || \ 00984 ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION) || \ 00985 ((__ALGOMODE__) == CRYP_ALGOMODE_DECRYPT) || \ 00986 ((__ALGOMODE__) == CRYP_ALGOMODE_TAG_GENERATION) || \ 00987 ((__ALGOMODE__) == CRYP_ALGOMODE_KEYDERIVATION_DECRYPT)) 00988 00989 /** 00990 * @brief Verify the selected CRYP chaining algorithm. 00991 * @param __CHAINMODE__ Selected CRYP chaining algorithm. 00992 * @retval SET (__CHAINMODE__ is valid) or RESET (__CHAINMODE__ is invalid) 00993 */ 00994 #if defined(AES_CR_NPBLB) 00995 #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \ 00996 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \ 00997 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \ 00998 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \ 00999 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CCM_CMAC)) 01000 #else 01001 #define IS_CRYP_CHAINMODE(__CHAINMODE__) (((__CHAINMODE__) == CRYP_CHAINMODE_AES_ECB) || \ 01002 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CBC) || \ 01003 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CTR) || \ 01004 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_GCM_GMAC) || \ 01005 ((__CHAINMODE__) == CRYP_CHAINMODE_AES_CMAC)) 01006 #endif 01007 01008 /** 01009 * @brief Verify the deciphering key write option. 01010 * @param __WRITE__ deciphering key write option. 01011 * @retval SET (__WRITE__ is valid) or RESET (__WRITE__ is invalid) 01012 */ 01013 #define IS_CRYP_WRITE(__WRITE__) (((__WRITE__) == CRYP_KEY_WRITE_ENABLE) || \ 01014 ((__WRITE__) == CRYP_KEY_WRITE_DISABLE)) 01015 01016 /** 01017 * @brief Verify the CRYP input data DMA mode. 01018 * @param __MODE__ CRYP input data DMA mode. 01019 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 01020 */ 01021 #define IS_CRYP_DMAIN(__MODE__) (((__MODE__) == CRYP_DMAIN_DISABLE) || \ 01022 ((__MODE__) == CRYP_DMAIN_ENABLE)) 01023 01024 /** 01025 * @brief Verify the CRYP output data DMA mode. 01026 * @param __MODE__ CRYP output data DMA mode. 01027 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 01028 */ 01029 #define IS_CRYP_DMAOUT(__MODE__) (((__MODE__) == CRYP_DMAOUT_DISABLE) || \ 01030 ((__MODE__) == CRYP_DMAOUT_ENABLE)) 01031 01032 /** 01033 * @brief Verify the CRYP AES ciphering/deciphering/authentication algorithm phase. 01034 * @param __PHASE__ CRYP AES ciphering/deciphering/authentication algorithm phase. 01035 * @retval SET (__PHASE__ is valid) or RESET (__PHASE__ is invalid) 01036 */ 01037 #define IS_CRYP_GCMCMAC_PHASE(__PHASE__) (((__PHASE__) == CRYP_GCM_INIT_PHASE) || \ 01038 ((__PHASE__) == CRYP_GCMCMAC_HEADER_PHASE) || \ 01039 ((__PHASE__) == CRYP_GCM_PAYLOAD_PHASE) || \ 01040 ((__PHASE__) == CRYP_GCMCMAC_FINAL_PHASE)) 01041 01042 /** 01043 * @} 01044 */ 01045 01046 /* Include CRYP HAL Extended module */ 01047 #include "stm32f4xx_hal_cryp_ex.h" 01048 01049 /* Exported functions --------------------------------------------------------*/ 01050 /** @addtogroup CRYP_Exported_Functions CRYP Exported Functions 01051 * @{ 01052 */ 01053 01054 /** @addtogroup CRYP_Exported_Functions_Group1 Initialization and deinitialization functions 01055 * @{ 01056 */ 01057 01058 /* Initialization/de-initialization functions ********************************/ 01059 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp); 01060 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp); 01061 01062 /* MSP initialization/de-initialization functions ****************************/ 01063 void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp); 01064 void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp); 01065 01066 /** 01067 * @} 01068 */ 01069 01070 /** @addtogroup CRYP_Exported_Functions_Group2 AES processing functions 01071 * @{ 01072 */ 01073 01074 /* AES encryption/decryption processing functions ****************************/ 01075 01076 /* AES encryption/decryption using polling ***********************************/ 01077 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 01078 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 01079 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 01080 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 01081 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout); 01082 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout); 01083 01084 /* AES encryption/decryption using interrupt *********************************/ 01085 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 01086 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 01087 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 01088 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 01089 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 01090 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 01091 01092 /* AES encryption/decryption using DMA ***************************************/ 01093 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 01094 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 01095 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 01096 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 01097 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData); 01098 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData); 01099 01100 /** 01101 * @} 01102 */ 01103 01104 /** @addtogroup CRYP_Exported_Functions_Group3 Callback functions 01105 * @{ 01106 */ 01107 /* CallBack functions ********************************************************/ 01108 void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp); 01109 void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp); 01110 void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp); 01111 01112 /** 01113 * @} 01114 */ 01115 01116 /** @addtogroup CRYP_Exported_Functions_Group4 CRYP IRQ handler 01117 * @{ 01118 */ 01119 01120 /* AES interrupt handling function *******************************************/ 01121 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp); 01122 01123 /** 01124 * @} 01125 */ 01126 01127 /** @addtogroup CRYP_Exported_Functions_Group5 Peripheral State functions 01128 * @{ 01129 */ 01130 01131 /* Peripheral State functions ************************************************/ 01132 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp); 01133 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp); 01134 01135 /** 01136 * @} 01137 */ 01138 01139 /** 01140 * @} 01141 */ 01142 01143 01144 #endif /* AES */ 01145 01146 /** 01147 * @} 01148 */ 01149 01150 /** 01151 * @} 01152 */ 01153 01154 #ifdef __cplusplus 01155 } 01156 #endif 01157 01158 #endif /* __STM32F4xx_HAL_CRYP_H */ 01159 01160 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/