| 1 | /**
|
|---|
| 2 | ******************************************************************************
|
|---|
| 3 | * @file stm32g0xx_hal_cryp.h
|
|---|
| 4 | * @author MCD Application Team
|
|---|
| 5 | * @brief Header file of CRYP HAL module.
|
|---|
| 6 | ******************************************************************************
|
|---|
| 7 | * @attention
|
|---|
| 8 | *
|
|---|
| 9 | * <h2><center>© Copyright (c) 2018 STMicroelectronics.
|
|---|
| 10 | * All rights reserved.</center></h2>
|
|---|
| 11 | *
|
|---|
| 12 | * This software component is licensed by ST under BSD 3-Clause license,
|
|---|
| 13 | * the "License"; You may not use this file except in compliance with the
|
|---|
| 14 | * License. You may obtain a copy of the License at:
|
|---|
| 15 | * opensource.org/licenses/BSD-3-Clause
|
|---|
| 16 | *
|
|---|
| 17 | ******************************************************************************
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | /* Define to prevent recursive inclusion -------------------------------------*/
|
|---|
| 21 | #ifndef STM32G0xx_HAL_CRYP_H
|
|---|
| 22 | #define STM32G0xx_HAL_CRYP_H
|
|---|
| 23 |
|
|---|
| 24 | #ifdef __cplusplus
|
|---|
| 25 | extern "C" {
|
|---|
| 26 | #endif
|
|---|
| 27 |
|
|---|
| 28 | /* Includes ------------------------------------------------------------------*/
|
|---|
| 29 | #include "stm32g0xx_hal_def.h"
|
|---|
| 30 |
|
|---|
| 31 | /** @addtogroup STM32G0xx_HAL_Driver
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #if defined(AES)
|
|---|
| 36 |
|
|---|
| 37 | /** @defgroup CRYP CRYP
|
|---|
| 38 | * @brief CRYP HAL module driver.
|
|---|
| 39 | * @{
|
|---|
| 40 | */
|
|---|
| 41 |
|
|---|
| 42 | /* Exported types ------------------------------------------------------------*/
|
|---|
| 43 |
|
|---|
| 44 | /** @defgroup CRYP_Exported_Types CRYP Exported Types
|
|---|
| 45 | * @{
|
|---|
| 46 | */
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * @brief CRYP Init Structure definition
|
|---|
| 50 | */
|
|---|
| 51 |
|
|---|
| 52 | typedef struct
|
|---|
| 53 | {
|
|---|
| 54 | uint32_t DataType; /*!< 32-bit data, 16-bit data, 8-bit data or 1-bit string.
|
|---|
| 55 | This parameter can be a value of @ref CRYP_Data_Type */
|
|---|
| 56 | uint32_t KeySize; /*!< Used only in AES mode : 128, 192 or 256 bit key length in CRYP1.
|
|---|
| 57 | 128 or 256 bit key length in TinyAES This parameter can be a value of @ref CRYP_Key_Size */
|
|---|
| 58 | uint32_t *pKey; /*!< The key used for encryption/decryption */
|
|---|
| 59 | uint32_t *pInitVect; /*!< The initialization vector used also as initialization
|
|---|
| 60 | counter in CTR mode */
|
|---|
| 61 | uint32_t Algorithm; /*!< DES/ TDES Algorithm ECB/CBC
|
|---|
| 62 | AES Algorithm ECB/CBC/CTR/GCM or CCM
|
|---|
| 63 | This parameter can be a value of @ref CRYP_Algorithm_Mode */
|
|---|
| 64 | uint32_t *Header; /*!< used only in AES GCM and CCM Algorithm for authentication,
|
|---|
| 65 | GCM : also known as Additional Authentication Data
|
|---|
| 66 | CCM : named B1 composed of the associated data length and Associated Data. */
|
|---|
| 67 | uint32_t HeaderSize; /*!< The size of header buffer in word */
|
|---|
| 68 | uint32_t *B0; /*!< B0 is first authentication block used only in AES CCM mode */
|
|---|
| 69 | uint32_t DataWidthUnit; /*!< Data With Unit, this parameter can be value of @ref CRYP_Data_Width_Unit*/
|
|---|
| 70 | uint32_t KeyIVConfigSkip; /*!< CRYP peripheral Key and IV configuration skip, to config Key and Initialization
|
|---|
| 71 | Vector only once and to skip configuration for consecutive processings.
|
|---|
| 72 | This parameter can be a value of @ref CRYP_Configuration_Skip */
|
|---|
| 73 |
|
|---|
| 74 | } CRYP_ConfigTypeDef;
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | /**
|
|---|
| 78 | * @brief CRYP State Structure definition
|
|---|
| 79 | */
|
|---|
| 80 |
|
|---|
| 81 | typedef enum
|
|---|
| 82 | {
|
|---|
| 83 | HAL_CRYP_STATE_RESET = 0x00U, /*!< CRYP not yet initialized or disabled */
|
|---|
| 84 | HAL_CRYP_STATE_READY = 0x01U, /*!< CRYP initialized and ready for use */
|
|---|
| 85 | HAL_CRYP_STATE_BUSY = 0x02U, /*!< CRYP BUSY, internal processing is ongoing */
|
|---|
| 86 | #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
|
|---|
| 87 | HAL_CRYP_STATE_SUSPENDED = 0x03U, /*!< CRYP suspended */
|
|---|
| 88 | #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
|
|---|
| 89 | } HAL_CRYP_STATETypeDef;
|
|---|
| 90 |
|
|---|
| 91 | #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
|
|---|
| 92 | /**
|
|---|
| 93 | * @brief HAL CRYP mode suspend definitions
|
|---|
| 94 | */
|
|---|
| 95 | typedef enum
|
|---|
| 96 | {
|
|---|
| 97 | HAL_CRYP_SUSPEND_NONE = 0x00U, /*!< CRYP processing suspension not requested */
|
|---|
| 98 | HAL_CRYP_SUSPEND = 0x01U /*!< CRYP processing suspension requested */
|
|---|
| 99 | }HAL_SuspendTypeDef;
|
|---|
| 100 | #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
|
|---|
| 101 |
|
|---|
| 102 | /**
|
|---|
| 103 | * @brief CRYP handle Structure definition
|
|---|
| 104 | */
|
|---|
| 105 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
|
|---|
| 106 | typedef struct __CRYP_HandleTypeDef
|
|---|
| 107 | #else
|
|---|
| 108 | typedef struct
|
|---|
| 109 | #endif
|
|---|
| 110 | {
|
|---|
| 111 | AES_TypeDef *Instance; /*!< AES Register base address */
|
|---|
| 112 |
|
|---|
| 113 | CRYP_ConfigTypeDef Init; /*!< CRYP required parameters */
|
|---|
| 114 |
|
|---|
| 115 | FunctionalState AutoKeyDerivation; /*!< Used only in TinyAES to allow to bypass or not key write-up before decryption.
|
|---|
| 116 | This parameter can be a value of ENABLE/DISABLE */
|
|---|
| 117 |
|
|---|
| 118 | uint32_t *pCrypInBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
|
|---|
| 119 |
|
|---|
| 120 | uint32_t *pCrypOutBuffPtr; /*!< Pointer to CRYP processing (encryption, decryption,...) buffer */
|
|---|
| 121 |
|
|---|
| 122 | __IO uint16_t CrypHeaderCount; /*!< Counter of header data */
|
|---|
| 123 |
|
|---|
| 124 | __IO uint16_t CrypInCount; /*!< Counter of input data */
|
|---|
| 125 |
|
|---|
| 126 | __IO uint16_t CrypOutCount; /*!< Counter of output data */
|
|---|
| 127 |
|
|---|
| 128 | uint16_t Size; /*!< length of input data in words */
|
|---|
| 129 |
|
|---|
| 130 | uint32_t Phase; /*!< CRYP peripheral phase */
|
|---|
| 131 |
|
|---|
| 132 | DMA_HandleTypeDef *hdmain; /*!< CRYP In DMA handle parameters */
|
|---|
| 133 |
|
|---|
| 134 | DMA_HandleTypeDef *hdmaout; /*!< CRYP Out DMA handle parameters */
|
|---|
| 135 |
|
|---|
| 136 | HAL_LockTypeDef Lock; /*!< CRYP locking object */
|
|---|
| 137 |
|
|---|
| 138 | __IO HAL_CRYP_STATETypeDef State; /*!< CRYP peripheral state */
|
|---|
| 139 |
|
|---|
| 140 | __IO uint32_t ErrorCode; /*!< CRYP peripheral error code */
|
|---|
| 141 |
|
|---|
| 142 | uint32_t KeyIVConfig; /*!< CRYP peripheral Key and IV configuration flag, used when
|
|---|
| 143 | configuration can be skipped */
|
|---|
| 144 |
|
|---|
| 145 | uint32_t SizesSum; /*!< Sum of successive payloads lengths (in bytes), stored
|
|---|
| 146 | for a single signature computation after several
|
|---|
| 147 | messages processing */
|
|---|
| 148 |
|
|---|
| 149 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
|
|---|
| 150 | void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Input FIFO transfer completed callback */
|
|---|
| 151 | void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Output FIFO transfer completed callback */
|
|---|
| 152 | void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Error callback */
|
|---|
| 153 |
|
|---|
| 154 | void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp Init callback */
|
|---|
| 155 | void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp); /*!< CRYP Msp DeInit callback */
|
|---|
| 156 |
|
|---|
| 157 | #endif /* (USE_HAL_CRYP_REGISTER_CALLBACKS) */
|
|---|
| 158 |
|
|---|
| 159 | #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
|
|---|
| 160 |
|
|---|
| 161 | __IO HAL_SuspendTypeDef SuspendRequest; /*!< CRYP peripheral suspension request flag */
|
|---|
| 162 |
|
|---|
| 163 | CRYP_ConfigTypeDef Init_saved; /*!< copy of CRYP required parameters when processing is suspended */
|
|---|
| 164 |
|
|---|
| 165 | uint32_t *pCrypInBuffPtr_saved; /*!< copy of CRYP input pointer when processing is suspended */
|
|---|
| 166 |
|
|---|
| 167 | uint32_t *pCrypOutBuffPtr_saved; /*!< copy of CRYP output pointer when processing is suspended */
|
|---|
| 168 |
|
|---|
| 169 | uint32_t CrypInCount_saved; /*!< copy of CRYP input data counter when processing is suspended */
|
|---|
| 170 |
|
|---|
| 171 | uint32_t CrypOutCount_saved; /*!< copy of CRYP output data counter when processing is suspended */
|
|---|
| 172 |
|
|---|
| 173 | uint32_t Phase_saved; /*!< copy of CRYP authentication phase when processing is suspended */
|
|---|
| 174 |
|
|---|
| 175 | __IO HAL_CRYP_STATETypeDef State_saved; /*!< copy of CRYP peripheral state when processing is suspended */
|
|---|
| 176 |
|
|---|
| 177 | uint32_t IV_saved[4]; /*!< copy of Initialisation Vector registers */
|
|---|
| 178 |
|
|---|
| 179 | uint32_t SUSPxR_saved[8]; /*!< copy of suspension registers */
|
|---|
| 180 |
|
|---|
| 181 | uint32_t CR_saved; /*!< copy of CRYP control register when processing is suspended*/
|
|---|
| 182 |
|
|---|
| 183 | uint32_t Key_saved[8]; /*!< copy of key registers */
|
|---|
| 184 |
|
|---|
| 185 | uint32_t Size_saved; /*!< copy of input buffer size */
|
|---|
| 186 |
|
|---|
| 187 | uint16_t CrypHeaderCount_saved; /*!< copy of CRYP header data counter when processing is suspended */
|
|---|
| 188 |
|
|---|
| 189 | uint32_t ResumingFlag; /*!< resumption flag to bypass steps already carried out */
|
|---|
| 190 |
|
|---|
| 191 | FunctionalState AutoKeyDerivation_saved; /*!< copy of CRYP handle auto key derivation parameter */
|
|---|
| 192 |
|
|---|
| 193 | #endif /* USE_HAL_CRYP_SUSPEND_RESUME */
|
|---|
| 194 |
|
|---|
| 195 | } CRYP_HandleTypeDef;
|
|---|
| 196 |
|
|---|
| 197 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
|
|---|
| 198 | /** @defgroup HAL_CRYP_Callback_ID_enumeration_definition HAL CRYP Callback ID enumeration definition
|
|---|
| 199 | * @brief HAL CRYP Callback ID enumeration definition
|
|---|
| 200 | * @{
|
|---|
| 201 | */
|
|---|
| 202 | typedef enum
|
|---|
| 203 | {
|
|---|
| 204 | HAL_CRYP_MSPINIT_CB_ID = 0x00U, /*!< CRYP MspInit callback ID */
|
|---|
| 205 | HAL_CRYP_MSPDEINIT_CB_ID = 0x01U, /*!< CRYP MspDeInit callback ID */
|
|---|
| 206 | HAL_CRYP_INPUT_COMPLETE_CB_ID = 0x02U, /*!< CRYP Input FIFO transfer completed callback ID */
|
|---|
| 207 | HAL_CRYP_OUTPUT_COMPLETE_CB_ID = 0x03U, /*!< CRYP Output FIFO transfer completed callback ID */
|
|---|
| 208 | HAL_CRYP_ERROR_CB_ID = 0x04U, /*!< CRYP Error callback ID */
|
|---|
| 209 | } HAL_CRYP_CallbackIDTypeDef;
|
|---|
| 210 | /**
|
|---|
| 211 | * @}
|
|---|
| 212 | */
|
|---|
| 213 |
|
|---|
| 214 | /** @defgroup HAL_CRYP_Callback_pointer_definition HAL CRYP Callback pointer definition
|
|---|
| 215 | * @brief HAL CRYP Callback pointer definition
|
|---|
| 216 | * @{
|
|---|
| 217 | */
|
|---|
| 218 |
|
|---|
| 219 | typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp); /*!< pointer to a common CRYP callback function */
|
|---|
| 220 |
|
|---|
| 221 | /**
|
|---|
| 222 | * @}
|
|---|
| 223 | */
|
|---|
| 224 |
|
|---|
| 225 | #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
|
|---|
| 226 |
|
|---|
| 227 | /**
|
|---|
| 228 | * @}
|
|---|
| 229 | */
|
|---|
| 230 |
|
|---|
| 231 | /* Exported constants --------------------------------------------------------*/
|
|---|
| 232 | /** @defgroup CRYP_Exported_Constants CRYP Exported Constants
|
|---|
| 233 | * @{
|
|---|
| 234 | */
|
|---|
| 235 |
|
|---|
| 236 | /** @defgroup CRYP_Error_Definition CRYP Error Definition
|
|---|
| 237 | * @{
|
|---|
| 238 | */
|
|---|
| 239 | #define HAL_CRYP_ERROR_NONE 0x00000000U /*!< No error */
|
|---|
| 240 | #define HAL_CRYP_ERROR_WRITE 0x00000001U /*!< Write error */
|
|---|
| 241 | #define HAL_CRYP_ERROR_READ 0x00000002U /*!< Read error */
|
|---|
| 242 | #define HAL_CRYP_ERROR_DMA 0x00000004U /*!< DMA error */
|
|---|
| 243 | #define HAL_CRYP_ERROR_BUSY 0x00000008U /*!< Busy flag error */
|
|---|
| 244 | #define HAL_CRYP_ERROR_TIMEOUT 0x00000010U /*!< Timeout error */
|
|---|
| 245 | #define HAL_CRYP_ERROR_NOT_SUPPORTED 0x00000020U /*!< Not supported mode */
|
|---|
| 246 | #define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U /*!< Sequence are not respected only for GCM or CCM */
|
|---|
| 247 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
|
|---|
| 248 | #define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U) /*!< Invalid Callback error */
|
|---|
| 249 | #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
|
|---|
| 250 |
|
|---|
| 251 | /**
|
|---|
| 252 | * @}
|
|---|
| 253 | */
|
|---|
| 254 |
|
|---|
| 255 | /** @defgroup CRYP_Data_Width_Unit CRYP Data Width Unit
|
|---|
| 256 | * @{
|
|---|
| 257 | */
|
|---|
| 258 |
|
|---|
| 259 | #define CRYP_DATAWIDTHUNIT_WORD 0x00000000U /*!< By default, size unit is word */
|
|---|
| 260 | #define CRYP_DATAWIDTHUNIT_BYTE 0x00000001U /*!< By default, size unit is byte */
|
|---|
| 261 |
|
|---|
| 262 | /**
|
|---|
| 263 | * @}
|
|---|
| 264 | */
|
|---|
| 265 |
|
|---|
| 266 | /** @defgroup CRYP_Algorithm_Mode CRYP Algorithm Mode
|
|---|
| 267 | * @{
|
|---|
| 268 | */
|
|---|
| 269 |
|
|---|
| 270 | #define CRYP_AES_ECB 0x00000000U /*!< Electronic codebook chaining algorithm */
|
|---|
| 271 | #define CRYP_AES_CBC AES_CR_CHMOD_0 /*!< Cipher block chaining algorithm */
|
|---|
| 272 | #define CRYP_AES_CTR AES_CR_CHMOD_1 /*!< Counter mode chaining algorithm */
|
|---|
| 273 | #define CRYP_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1) /*!< Galois counter mode - Galois message authentication code */
|
|---|
| 274 | #define CRYP_AES_CCM AES_CR_CHMOD_2 /*!< Counter with Cipher Mode */
|
|---|
| 275 |
|
|---|
| 276 | /**
|
|---|
| 277 | * @}
|
|---|
| 278 | */
|
|---|
| 279 |
|
|---|
| 280 | /** @defgroup CRYP_Key_Size CRYP Key Size
|
|---|
| 281 | * @{
|
|---|
| 282 | */
|
|---|
| 283 |
|
|---|
| 284 | #define CRYP_KEYSIZE_128B 0x00000000U /*!< 128-bit long key */
|
|---|
| 285 | #define CRYP_KEYSIZE_256B AES_CR_KEYSIZE /*!< 256-bit long key */
|
|---|
| 286 |
|
|---|
| 287 | /**
|
|---|
| 288 | * @}
|
|---|
| 289 | */
|
|---|
| 290 |
|
|---|
| 291 | /** @defgroup CRYP_Data_Type CRYP Data Type
|
|---|
| 292 | * @{
|
|---|
| 293 | */
|
|---|
| 294 |
|
|---|
| 295 | #define CRYP_DATATYPE_32B 0x00000000U /*!< 32-bit data type (no swapping) */
|
|---|
| 296 | #define CRYP_DATATYPE_16B AES_CR_DATATYPE_0 /*!< 16-bit data type (half-word swapping) */
|
|---|
| 297 | #define CRYP_DATATYPE_8B AES_CR_DATATYPE_1 /*!< 8-bit data type (byte swapping) */
|
|---|
| 298 | #define CRYP_DATATYPE_1B AES_CR_DATATYPE /*!< 1-bit data type (bit swapping) */
|
|---|
| 299 |
|
|---|
| 300 | /**
|
|---|
| 301 | * @}
|
|---|
| 302 | */
|
|---|
| 303 |
|
|---|
| 304 | /** @defgroup CRYP_Interrupt CRYP Interrupt
|
|---|
| 305 | * @{
|
|---|
| 306 | */
|
|---|
| 307 |
|
|---|
| 308 | #define CRYP_IT_CCFIE AES_CR_CCFIE /*!< Computation Complete interrupt enable */
|
|---|
| 309 | #define CRYP_IT_ERRIE AES_CR_ERRIE /*!< Error interrupt enable */
|
|---|
| 310 | #define CRYP_IT_WRERR AES_SR_WRERR /*!< Write Error */
|
|---|
| 311 | #define CRYP_IT_RDERR AES_SR_RDERR /*!< Read Error */
|
|---|
| 312 | #define CRYP_IT_CCF AES_SR_CCF /*!< Computation completed */
|
|---|
| 313 |
|
|---|
| 314 | /**
|
|---|
| 315 | * @}
|
|---|
| 316 | */
|
|---|
| 317 |
|
|---|
| 318 | /** @defgroup CRYP_Flags CRYP Flags
|
|---|
| 319 | * @{
|
|---|
| 320 | */
|
|---|
| 321 |
|
|---|
| 322 | /* status flags */
|
|---|
| 323 | #define CRYP_FLAG_BUSY AES_SR_BUSY /*!< GCM process suspension forbidden */
|
|---|
| 324 | #define CRYP_FLAG_WRERR AES_SR_WRERR /*!< Write Error */
|
|---|
| 325 | #define CRYP_FLAG_RDERR AES_SR_RDERR /*!< Read error */
|
|---|
| 326 | #define CRYP_FLAG_CCF AES_SR_CCF /*!< Computation completed */
|
|---|
| 327 | /* clearing flags */
|
|---|
| 328 | #define CRYP_CCF_CLEAR AES_CR_CCFC /*!< Computation Complete Flag Clear */
|
|---|
| 329 | #define CRYP_ERR_CLEAR AES_CR_ERRC /*!< Error Flag Clear */
|
|---|
| 330 |
|
|---|
| 331 | /**
|
|---|
| 332 | * @}
|
|---|
| 333 | */
|
|---|
| 334 |
|
|---|
| 335 | /** @defgroup CRYP_Configuration_Skip CRYP Key and IV Configuration Skip Mode
|
|---|
| 336 | * @{
|
|---|
| 337 | */
|
|---|
| 338 |
|
|---|
| 339 | #define CRYP_KEYIVCONFIG_ALWAYS 0x00000000U /*!< Peripheral Key and IV configuration to do systematically */
|
|---|
| 340 | #define CRYP_KEYIVCONFIG_ONCE 0x00000001U /*!< Peripheral Key and IV configuration to do only once */
|
|---|
| 341 |
|
|---|
| 342 | /**
|
|---|
| 343 | * @}
|
|---|
| 344 | */
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 | /**
|
|---|
| 348 | * @}
|
|---|
| 349 | */
|
|---|
| 350 |
|
|---|
| 351 | /* Exported macros -----------------------------------------------------------*/
|
|---|
| 352 | /** @defgroup CRYP_Exported_Macros CRYP Exported Macros
|
|---|
| 353 | * @{
|
|---|
| 354 | */
|
|---|
| 355 |
|
|---|
| 356 | /** @brief Reset CRYP handle state
|
|---|
| 357 | * @param __HANDLE__ specifies the CRYP handle.
|
|---|
| 358 | * @retval None
|
|---|
| 359 | */
|
|---|
| 360 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
|
|---|
| 361 | #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\
|
|---|
| 362 | (__HANDLE__)->State = HAL_CRYP_STATE_RESET;\
|
|---|
| 363 | (__HANDLE__)->MspInitCallback = NULL;\
|
|---|
| 364 | (__HANDLE__)->MspDeInitCallback = NULL;\
|
|---|
| 365 | }while(0U)
|
|---|
| 366 | #else
|
|---|
| 367 | #define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET)
|
|---|
| 368 | #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
|
|---|
| 369 |
|
|---|
| 370 | /**
|
|---|
| 371 | * @brief Enable/Disable the CRYP peripheral.
|
|---|
| 372 | * @param __HANDLE__ specifies the CRYP handle.
|
|---|
| 373 | * @retval None
|
|---|
| 374 | */
|
|---|
| 375 |
|
|---|
| 376 | #define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= AES_CR_EN)
|
|---|
| 377 | #define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~AES_CR_EN)
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 | /** @brief Check whether the specified CRYP status flag is set or not.
|
|---|
| 381 | * @param __HANDLE__ specifies the CRYP handle.
|
|---|
| 382 | * @param __FLAG__ specifies the flag to check.
|
|---|
| 383 | * This parameter can be one of the following values for TinyAES:
|
|---|
| 384 | * @arg @ref CRYP_FLAG_BUSY GCM process suspension forbidden
|
|---|
| 385 | * @arg @ref CRYP_IT_WRERR Write Error
|
|---|
| 386 | * @arg @ref CRYP_IT_RDERR Read Error
|
|---|
| 387 | * @arg @ref CRYP_IT_CCF Computation Complete
|
|---|
| 388 | * This parameter can be one of the following values for CRYP:
|
|---|
| 389 | * @arg CRYP_FLAG_BUSY: The CRYP core is currently processing a block of data
|
|---|
| 390 | * or a key preparation (for AES decryption).
|
|---|
| 391 | * @arg CRYP_FLAG_IFEM: Input FIFO is empty
|
|---|
| 392 | * @arg CRYP_FLAG_IFNF: Input FIFO is not full
|
|---|
| 393 | * @arg CRYP_FLAG_INRIS: Input FIFO service raw interrupt is pending
|
|---|
| 394 | * @arg CRYP_FLAG_OFNE: Output FIFO is not empty
|
|---|
| 395 | * @arg CRYP_FLAG_OFFU: Output FIFO is full
|
|---|
| 396 | * @arg CRYP_FLAG_OUTRIS: Input FIFO service raw interrupt is pending
|
|---|
| 397 | * @retval The state of __FLAG__ (TRUE or FALSE).
|
|---|
| 398 | */
|
|---|
| 399 |
|
|---|
| 400 | #define CRYP_FLAG_MASK 0x0000001FU
|
|---|
| 401 | #define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
|
|---|
| 402 |
|
|---|
| 403 | /** @brief Clear the CRYP pending status flag.
|
|---|
| 404 | * @param __HANDLE__ specifies the CRYP handle.
|
|---|
| 405 | * @param __FLAG__ specifies the flag to clear.
|
|---|
| 406 | * This parameter can be one of the following values:
|
|---|
| 407 | * @arg @ref CRYP_ERR_CLEAR Read (RDERR) or Write Error (WRERR) Flag Clear
|
|---|
| 408 | * @arg @ref CRYP_CCF_CLEAR Computation Complete Flag (CCF) Clear
|
|---|
| 409 | * @retval None
|
|---|
| 410 | */
|
|---|
| 411 |
|
|---|
| 412 | #define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__))
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 | /** @brief Check whether the specified CRYP interrupt source is enabled or not.
|
|---|
| 416 | * @param __HANDLE__ specifies the CRYP handle.
|
|---|
| 417 | * @param __INTERRUPT__ CRYP interrupt source to check
|
|---|
| 418 | * This parameter can be one of the following values for TinyAES:
|
|---|
| 419 | * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
|
|---|
| 420 | * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
|
|---|
| 421 | * @retval State of interruption (TRUE or FALSE).
|
|---|
| 422 | */
|
|---|
| 423 |
|
|---|
| 424 | #define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__))
|
|---|
| 425 |
|
|---|
| 426 | /** @brief Check whether the specified CRYP interrupt is set or not.
|
|---|
| 427 | * @param __HANDLE__ specifies the CRYP handle.
|
|---|
| 428 | * @param __INTERRUPT__ specifies the interrupt to check.
|
|---|
| 429 | * This parameter can be one of the following values for TinyAES:
|
|---|
| 430 | * @arg @ref CRYP_IT_WRERR Write Error
|
|---|
| 431 | * @arg @ref CRYP_IT_RDERR Read Error
|
|---|
| 432 | * @arg @ref CRYP_IT_CCF Computation Complete
|
|---|
| 433 | * This parameter can be one of the following values for CRYP:
|
|---|
| 434 | * @arg CRYP_IT_INI: Input FIFO service masked interrupt status
|
|---|
| 435 | * @arg CRYP_IT_OUTI: Output FIFO service masked interrupt status
|
|---|
| 436 | * @retval The state of __INTERRUPT__ (TRUE or FALSE).
|
|---|
| 437 | */
|
|---|
| 438 |
|
|---|
| 439 | #define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
|
|---|
| 440 |
|
|---|
| 441 | /**
|
|---|
| 442 | * @brief Enable the CRYP interrupt.
|
|---|
| 443 | * @param __HANDLE__ specifies the CRYP handle.
|
|---|
| 444 | * @param __INTERRUPT__ CRYP Interrupt.
|
|---|
| 445 | * This parameter can be one of the following values for TinyAES:
|
|---|
| 446 | * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
|
|---|
| 447 | * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
|
|---|
| 448 | * This parameter can be one of the following values for CRYP:
|
|---|
| 449 | * @ CRYP_IT_INI : Input FIFO service interrupt mask.
|
|---|
| 450 | * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt.
|
|---|
| 451 | * @retval None
|
|---|
| 452 | */
|
|---|
| 453 |
|
|---|
| 454 | #define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
|
|---|
| 455 |
|
|---|
| 456 | /**
|
|---|
| 457 | * @brief Disable the CRYP interrupt.
|
|---|
| 458 | * @param __HANDLE__ specifies the CRYP handle.
|
|---|
| 459 | * @param __INTERRUPT__ CRYP Interrupt.
|
|---|
| 460 | * This parameter can be one of the following values for TinyAES:
|
|---|
| 461 | * @arg @ref CRYP_IT_ERRIE Error interrupt (used for RDERR and WRERR)
|
|---|
| 462 | * @arg @ref CRYP_IT_CCFIE Computation Complete interrupt
|
|---|
| 463 | * This parameter can be one of the following values for CRYP:
|
|---|
| 464 | * @ CRYP_IT_INI : Input FIFO service interrupt mask.
|
|---|
| 465 | * @ CRYP_IT_OUTI : Output FIFO service interrupt mask.CRYP interrupt.
|
|---|
| 466 | * @retval None
|
|---|
| 467 | */
|
|---|
| 468 |
|
|---|
| 469 | #define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
|
|---|
| 470 |
|
|---|
| 471 | /**
|
|---|
| 472 | * @}
|
|---|
| 473 | */
|
|---|
| 474 |
|
|---|
| 475 | /* Include CRYP HAL Extended module */
|
|---|
| 476 | #include "stm32g0xx_hal_cryp_ex.h"
|
|---|
| 477 |
|
|---|
| 478 | /* Exported functions --------------------------------------------------------*/
|
|---|
| 479 | /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
|
|---|
| 480 | * @{
|
|---|
| 481 | */
|
|---|
| 482 |
|
|---|
| 483 | /** @addtogroup CRYP_Exported_Functions_Group1
|
|---|
| 484 | * @{
|
|---|
| 485 | */
|
|---|
| 486 | HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
|
|---|
| 487 | HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
|
|---|
| 488 | void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
|
|---|
| 489 | void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
|
|---|
| 490 | HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
|
|---|
| 491 | HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
|
|---|
| 492 | #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1U)
|
|---|
| 493 | HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID, pCRYP_CallbackTypeDef pCallback);
|
|---|
| 494 | HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID);
|
|---|
| 495 | #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
|
|---|
| 496 | #if (USE_HAL_CRYP_SUSPEND_RESUME == 1U)
|
|---|
| 497 | void HAL_CRYP_ProcessSuspend(CRYP_HandleTypeDef *hcryp);
|
|---|
| 498 | HAL_StatusTypeDef HAL_CRYP_Suspend(CRYP_HandleTypeDef *hcryp);
|
|---|
| 499 | HAL_StatusTypeDef HAL_CRYP_Resume(CRYP_HandleTypeDef *hcryp);
|
|---|
| 500 | #endif /* defined (USE_HAL_CRYP_SUSPEND_RESUME) */
|
|---|
| 501 | /**
|
|---|
| 502 | * @}
|
|---|
| 503 | */
|
|---|
| 504 |
|
|---|
| 505 | /** @addtogroup CRYP_Exported_Functions_Group2
|
|---|
| 506 | * @{
|
|---|
| 507 | */
|
|---|
| 508 |
|
|---|
| 509 | /* encryption/decryption ***********************************/
|
|---|
| 510 | HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output, uint32_t Timeout);
|
|---|
| 511 | HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output, uint32_t Timeout);
|
|---|
| 512 | HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
|
|---|
| 513 | HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
|
|---|
| 514 | HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
|
|---|
| 515 | HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
|
|---|
| 516 |
|
|---|
| 517 | /**
|
|---|
| 518 | * @}
|
|---|
| 519 | */
|
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 | /** @addtogroup CRYP_Exported_Functions_Group3
|
|---|
| 523 | * @{
|
|---|
| 524 | */
|
|---|
| 525 | /* Interrupt Handler functions **********************************************/
|
|---|
| 526 | void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
|
|---|
| 527 | HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
|
|---|
| 528 | void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
|
|---|
| 529 | void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
|
|---|
| 530 | void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
|
|---|
| 531 | uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp);
|
|---|
| 532 |
|
|---|
| 533 | /**
|
|---|
| 534 | * @}
|
|---|
| 535 | */
|
|---|
| 536 |
|
|---|
| 537 | /**
|
|---|
| 538 | * @}
|
|---|
| 539 | */
|
|---|
| 540 |
|
|---|
| 541 | /* Private macros --------------------------------------------------------*/
|
|---|
| 542 | /** @defgroup CRYP_Private_Macros CRYP Private Macros
|
|---|
| 543 | * @{
|
|---|
| 544 | */
|
|---|
| 545 |
|
|---|
| 546 | /** @defgroup CRYP_IS_CRYP_Definitions CRYP Private macros to check input parameters
|
|---|
| 547 | * @{
|
|---|
| 548 | */
|
|---|
| 549 |
|
|---|
| 550 | #define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \
|
|---|
| 551 | ((ALGORITHM) == CRYP_AES_CBC) || \
|
|---|
| 552 | ((ALGORITHM) == CRYP_AES_CTR) || \
|
|---|
| 553 | ((ALGORITHM) == CRYP_AES_GCM_GMAC)|| \
|
|---|
| 554 | ((ALGORITHM) == CRYP_AES_CCM))
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 | #define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \
|
|---|
| 558 | ((KEYSIZE) == CRYP_KEYSIZE_256B))
|
|---|
| 559 |
|
|---|
| 560 | #define IS_CRYP_DATATYPE(DATATYPE)(((DATATYPE) == CRYP_DATATYPE_32B) || \
|
|---|
| 561 | ((DATATYPE) == CRYP_DATATYPE_16B) || \
|
|---|
| 562 | ((DATATYPE) == CRYP_DATATYPE_8B) || \
|
|---|
| 563 | ((DATATYPE) == CRYP_DATATYPE_1B))
|
|---|
| 564 |
|
|---|
| 565 | #define IS_CRYP_INIT(CONFIG)(((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \
|
|---|
| 566 | ((CONFIG) == CRYP_KEYIVCONFIG_ONCE))
|
|---|
| 567 |
|
|---|
| 568 | /**
|
|---|
| 569 | * @}
|
|---|
| 570 | */
|
|---|
| 571 |
|
|---|
| 572 | /**
|
|---|
| 573 | * @}
|
|---|
| 574 | */
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 | /* Private constants ---------------------------------------------------------*/
|
|---|
| 578 | /** @defgroup CRYP_Private_Constants CRYP Private Constants
|
|---|
| 579 | * @{
|
|---|
| 580 | */
|
|---|
| 581 |
|
|---|
| 582 | /**
|
|---|
| 583 | * @}
|
|---|
| 584 | */
|
|---|
| 585 | /* Private defines -----------------------------------------------------------*/
|
|---|
| 586 | /** @defgroup CRYP_Private_Defines CRYP Private Defines
|
|---|
| 587 | * @{
|
|---|
| 588 | */
|
|---|
| 589 |
|
|---|
| 590 | /**
|
|---|
| 591 | * @}
|
|---|
| 592 | */
|
|---|
| 593 |
|
|---|
| 594 | /* Private variables ---------------------------------------------------------*/
|
|---|
| 595 | /** @defgroup CRYP_Private_Variables CRYP Private Variables
|
|---|
| 596 | * @{
|
|---|
| 597 | */
|
|---|
| 598 |
|
|---|
| 599 | /**
|
|---|
| 600 | * @}
|
|---|
| 601 | */
|
|---|
| 602 |
|
|---|
| 603 | /* Private functions ---------------------------------------------------------*/
|
|---|
| 604 | /** @defgroup CRYP_Private_Functions CRYP Private Functions
|
|---|
| 605 | * @{
|
|---|
| 606 | */
|
|---|
| 607 |
|
|---|
| 608 | /**
|
|---|
| 609 | * @}
|
|---|
| 610 | */
|
|---|
| 611 |
|
|---|
| 612 | /**
|
|---|
| 613 | * @}
|
|---|
| 614 | */
|
|---|
| 615 |
|
|---|
| 616 | #endif /* AES */
|
|---|
| 617 | /**
|
|---|
| 618 | * @}
|
|---|
| 619 | */
|
|---|
| 620 |
|
|---|
| 621 | #ifdef __cplusplus
|
|---|
| 622 | }
|
|---|
| 623 | #endif
|
|---|
| 624 |
|
|---|
| 625 | #endif /* STM32G0xx_HAL_CRYP_H */
|
|---|
| 626 |
|
|---|
| 627 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|---|