L4 HAL Drivers

Committer:
EricLew
Date:
Mon Nov 02 19:37:23 2015 +0000
Revision:
0:80ee8f3b695e
Errors are with definitions of LCD and QSPI functions. I believe all .h and .c files are  uploaded, but there may need to be certain functions called.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EricLew 0:80ee8f3b695e 1 /**
EricLew 0:80ee8f3b695e 2 ******************************************************************************
EricLew 0:80ee8f3b695e 3 * @file stm32l4xx_hal_cryp_ex.c
EricLew 0:80ee8f3b695e 4 * @author MCD Application Team
EricLew 0:80ee8f3b695e 5 * @version V1.1.0
EricLew 0:80ee8f3b695e 6 * @date 16-September-2015
EricLew 0:80ee8f3b695e 7 * @brief CRYPEx HAL module driver.
EricLew 0:80ee8f3b695e 8 * This file provides firmware functions to manage the extended
EricLew 0:80ee8f3b695e 9 * functionalities of the Cryptography (CRYP) peripheral.
EricLew 0:80ee8f3b695e 10 *
EricLew 0:80ee8f3b695e 11 ******************************************************************************
EricLew 0:80ee8f3b695e 12 * @attention
EricLew 0:80ee8f3b695e 13 *
EricLew 0:80ee8f3b695e 14 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
EricLew 0:80ee8f3b695e 15 *
EricLew 0:80ee8f3b695e 16 * Redistribution and use in source and binary forms, with or without modification,
EricLew 0:80ee8f3b695e 17 * are permitted provided that the following conditions are met:
EricLew 0:80ee8f3b695e 18 * 1. Redistributions of source code must retain the above copyright notice,
EricLew 0:80ee8f3b695e 19 * this list of conditions and the following disclaimer.
EricLew 0:80ee8f3b695e 20 * 2. Redistributions in binary form must reproduce the above copyright notice,
EricLew 0:80ee8f3b695e 21 * this list of conditions and the following disclaimer in the documentation
EricLew 0:80ee8f3b695e 22 * and/or other materials provided with the distribution.
EricLew 0:80ee8f3b695e 23 * 3. Neither the name of STMicroelectronics nor the names of its contributors
EricLew 0:80ee8f3b695e 24 * may be used to endorse or promote products derived from this software
EricLew 0:80ee8f3b695e 25 * without specific prior written permission.
EricLew 0:80ee8f3b695e 26 *
EricLew 0:80ee8f3b695e 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
EricLew 0:80ee8f3b695e 28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
EricLew 0:80ee8f3b695e 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
EricLew 0:80ee8f3b695e 30 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
EricLew 0:80ee8f3b695e 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
EricLew 0:80ee8f3b695e 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
EricLew 0:80ee8f3b695e 33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
EricLew 0:80ee8f3b695e 34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
EricLew 0:80ee8f3b695e 35 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
EricLew 0:80ee8f3b695e 36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
EricLew 0:80ee8f3b695e 37 *
EricLew 0:80ee8f3b695e 38 ******************************************************************************
EricLew 0:80ee8f3b695e 39 */
EricLew 0:80ee8f3b695e 40
EricLew 0:80ee8f3b695e 41 /* Includes ------------------------------------------------------------------*/
EricLew 0:80ee8f3b695e 42 #include "stm32l4xx_hal.h"
EricLew 0:80ee8f3b695e 43
EricLew 0:80ee8f3b695e 44 #ifdef HAL_CRYP_MODULE_ENABLED
EricLew 0:80ee8f3b695e 45
EricLew 0:80ee8f3b695e 46 #if defined(STM32L485xx) || defined(STM32L486xx)
EricLew 0:80ee8f3b695e 47
EricLew 0:80ee8f3b695e 48 /** @addtogroup STM32L4xx_HAL_Driver
EricLew 0:80ee8f3b695e 49 * @{
EricLew 0:80ee8f3b695e 50 */
EricLew 0:80ee8f3b695e 51
EricLew 0:80ee8f3b695e 52 /** @defgroup CRYPEx CRYPEx
EricLew 0:80ee8f3b695e 53 * @brief CRYP Extended HAL module driver
EricLew 0:80ee8f3b695e 54 * @{
EricLew 0:80ee8f3b695e 55 */
EricLew 0:80ee8f3b695e 56
EricLew 0:80ee8f3b695e 57 /* Private typedef -----------------------------------------------------------*/
EricLew 0:80ee8f3b695e 58 /* Private define ------------------------------------------------------------*/
EricLew 0:80ee8f3b695e 59 /** @defgroup CRYPEx_Private_Constants CRYPEx Private Constants
EricLew 0:80ee8f3b695e 60 * @{
EricLew 0:80ee8f3b695e 61 */
EricLew 0:80ee8f3b695e 62 #define CRYP_CCF_TIMEOUTVALUE 22000 /*!< CCF flag raising time-out value */
EricLew 0:80ee8f3b695e 63 #define CRYP_BUSY_TIMEOUTVALUE 22000 /*!< BUSY flag reset time-out value */
EricLew 0:80ee8f3b695e 64 /**
EricLew 0:80ee8f3b695e 65 * @}
EricLew 0:80ee8f3b695e 66 */
EricLew 0:80ee8f3b695e 67
EricLew 0:80ee8f3b695e 68 /* Private macro -------------------------------------------------------------*/
EricLew 0:80ee8f3b695e 69 /* Private variables ---------------------------------------------------------*/
EricLew 0:80ee8f3b695e 70 /* Private function prototypes -----------------------------------------------*/
EricLew 0:80ee8f3b695e 71 /** @defgroup CRYPEx_Private_Functions CRYPEx Private Functions
EricLew 0:80ee8f3b695e 72 * @{
EricLew 0:80ee8f3b695e 73 */
EricLew 0:80ee8f3b695e 74 static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout);
EricLew 0:80ee8f3b695e 75 static HAL_StatusTypeDef CRYP_ReadKey(CRYP_HandleTypeDef *hcryp, uint8_t* Output, uint32_t Timeout);
EricLew 0:80ee8f3b695e 76 static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr);
EricLew 0:80ee8f3b695e 77 static void CRYP_GCMCMAC_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr);
EricLew 0:80ee8f3b695e 78 static void CRYP_GCMCMAC_DMAInCplt(DMA_HandleTypeDef *hdma);
EricLew 0:80ee8f3b695e 79 static void CRYP_GCMCMAC_DMAError(DMA_HandleTypeDef *hdma);
EricLew 0:80ee8f3b695e 80 static void CRYP_GCMCMAC_DMAOutCplt(DMA_HandleTypeDef *hdma);
EricLew 0:80ee8f3b695e 81 static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef *hcryp, uint32_t Timeout);
EricLew 0:80ee8f3b695e 82 static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset(CRYP_HandleTypeDef *hcryp, uint32_t Timeout);
EricLew 0:80ee8f3b695e 83 static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma);
EricLew 0:80ee8f3b695e 84 static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma);
EricLew 0:80ee8f3b695e 85 static void CRYP_DMAError(DMA_HandleTypeDef *hdma);
EricLew 0:80ee8f3b695e 86 /**
EricLew 0:80ee8f3b695e 87 * @}
EricLew 0:80ee8f3b695e 88 */
EricLew 0:80ee8f3b695e 89
EricLew 0:80ee8f3b695e 90 /* Exported functions ---------------------------------------------------------*/
EricLew 0:80ee8f3b695e 91
EricLew 0:80ee8f3b695e 92 /** @defgroup CRYPEx_Exported_Functions CRYPEx Exported Functions
EricLew 0:80ee8f3b695e 93 * @{
EricLew 0:80ee8f3b695e 94 */
EricLew 0:80ee8f3b695e 95
EricLew 0:80ee8f3b695e 96
EricLew 0:80ee8f3b695e 97 /** @defgroup CRYPEx_Exported_Functions_Group1 Extended callback function
EricLew 0:80ee8f3b695e 98 * @brief Extended callback functions.
EricLew 0:80ee8f3b695e 99 *
EricLew 0:80ee8f3b695e 100 @verbatim
EricLew 0:80ee8f3b695e 101 ===============================================================================
EricLew 0:80ee8f3b695e 102 ##### Extended callback functions #####
EricLew 0:80ee8f3b695e 103 ===============================================================================
EricLew 0:80ee8f3b695e 104 [..] This section provides callback function:
EricLew 0:80ee8f3b695e 105 (+) Computation completed.
EricLew 0:80ee8f3b695e 106
EricLew 0:80ee8f3b695e 107 @endverbatim
EricLew 0:80ee8f3b695e 108 * @{
EricLew 0:80ee8f3b695e 109 */
EricLew 0:80ee8f3b695e 110
EricLew 0:80ee8f3b695e 111
EricLew 0:80ee8f3b695e 112 /**
EricLew 0:80ee8f3b695e 113 * @brief Computation completed callbacks.
EricLew 0:80ee8f3b695e 114 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 115 * the configuration information for CRYP module
EricLew 0:80ee8f3b695e 116 * @retval None
EricLew 0:80ee8f3b695e 117 */
EricLew 0:80ee8f3b695e 118 __weak void HAL_CRYPEx_ComputationCpltCallback(CRYP_HandleTypeDef *hcryp)
EricLew 0:80ee8f3b695e 119 {
EricLew 0:80ee8f3b695e 120 /* NOTE : This function should not be modified; when the callback is needed,
EricLew 0:80ee8f3b695e 121 the HAL_CRYP_ErrorCallback can be implemented in the user file
EricLew 0:80ee8f3b695e 122 */
EricLew 0:80ee8f3b695e 123 }
EricLew 0:80ee8f3b695e 124
EricLew 0:80ee8f3b695e 125 /**
EricLew 0:80ee8f3b695e 126 * @}
EricLew 0:80ee8f3b695e 127 */
EricLew 0:80ee8f3b695e 128
EricLew 0:80ee8f3b695e 129 /** @defgroup CRYPEx_Exported_Functions_Group2 AES extended processing functions
EricLew 0:80ee8f3b695e 130 * @brief Extended processing functions.
EricLew 0:80ee8f3b695e 131 *
EricLew 0:80ee8f3b695e 132 @verbatim
EricLew 0:80ee8f3b695e 133 ==============================================================================
EricLew 0:80ee8f3b695e 134 ##### AES extended processing functions #####
EricLew 0:80ee8f3b695e 135 ==============================================================================
EricLew 0:80ee8f3b695e 136 [..] This section provides functions allowing to:
EricLew 0:80ee8f3b695e 137 (+) Encrypt plaintext or decrypt cipher text using AES algorithm in different chaining modes.
EricLew 0:80ee8f3b695e 138 Functions are generic (handles ECB, CBC and CTR and all modes) and are only differentiated
EricLew 0:80ee8f3b695e 139 based on the processing type. Three processing types are available:
EricLew 0:80ee8f3b695e 140 (++) Polling mode
EricLew 0:80ee8f3b695e 141 (++) Interrupt mode
EricLew 0:80ee8f3b695e 142 (++) DMA mode
EricLew 0:80ee8f3b695e 143 (+) Generate and authentication tag in addition to encrypt/decrypt a plain/cipher text using AES
EricLew 0:80ee8f3b695e 144 algorithm in different chaining modes.
EricLew 0:80ee8f3b695e 145 Functions are generic (handles GCM, GMAC and CMAC) and process only one phase so that steps
EricLew 0:80ee8f3b695e 146 can be skipped if so required. Functions are only differentiated based on the processing type.
EricLew 0:80ee8f3b695e 147 Three processing types are available:
EricLew 0:80ee8f3b695e 148 (++) Polling mode
EricLew 0:80ee8f3b695e 149 (++) Interrupt mode
EricLew 0:80ee8f3b695e 150 (++) DMA mode
EricLew 0:80ee8f3b695e 151
EricLew 0:80ee8f3b695e 152 @endverbatim
EricLew 0:80ee8f3b695e 153 * @{
EricLew 0:80ee8f3b695e 154 */
EricLew 0:80ee8f3b695e 155
EricLew 0:80ee8f3b695e 156 /**
EricLew 0:80ee8f3b695e 157 * @brief Carry out in polling mode the ciphering or deciphering operation according to
EricLew 0:80ee8f3b695e 158 * hcryp->Init structure fields, all operating modes (encryption, key derivation and/or decryption) and
EricLew 0:80ee8f3b695e 159 * chaining modes ECB, CBC and CTR are managed by this function in polling mode.
EricLew 0:80ee8f3b695e 160 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 161 * the configuration information for CRYP module
EricLew 0:80ee8f3b695e 162 * @param pInputData: Pointer to the plain text in case of encryption or cipher text in case of decryption
EricLew 0:80ee8f3b695e 163 * or key derivation+decryption.
EricLew 0:80ee8f3b695e 164 * Parameter is meaningless in case of key derivation.
EricLew 0:80ee8f3b695e 165 * @param Size: Length of the input data buffer in bytes, must be a multiple of 16.
EricLew 0:80ee8f3b695e 166 * Parameter is meaningless in case of key derivation.
EricLew 0:80ee8f3b695e 167 * @param pOutputData: Pointer to the cipher text in case of encryption or plain text in case of
EricLew 0:80ee8f3b695e 168 * decryption/key derivation+decryption, or pointer to the derivative keys in
EricLew 0:80ee8f3b695e 169 * case of key derivation only.
EricLew 0:80ee8f3b695e 170 * @param Timeout: Specify Timeout value
EricLew 0:80ee8f3b695e 171 * @retval HAL status
EricLew 0:80ee8f3b695e 172 */
EricLew 0:80ee8f3b695e 173 HAL_StatusTypeDef HAL_CRYPEx_AES(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData, uint32_t Timeout)
EricLew 0:80ee8f3b695e 174 {
EricLew 0:80ee8f3b695e 175
EricLew 0:80ee8f3b695e 176 if (hcryp->State == HAL_CRYP_STATE_READY)
EricLew 0:80ee8f3b695e 177 {
EricLew 0:80ee8f3b695e 178 /* Check parameters setting */
EricLew 0:80ee8f3b695e 179 if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION)
EricLew 0:80ee8f3b695e 180 {
EricLew 0:80ee8f3b695e 181 if (pOutputData == NULL)
EricLew 0:80ee8f3b695e 182 {
EricLew 0:80ee8f3b695e 183 return HAL_ERROR;
EricLew 0:80ee8f3b695e 184 }
EricLew 0:80ee8f3b695e 185 }
EricLew 0:80ee8f3b695e 186 else
EricLew 0:80ee8f3b695e 187 {
EricLew 0:80ee8f3b695e 188 if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
EricLew 0:80ee8f3b695e 189 {
EricLew 0:80ee8f3b695e 190 return HAL_ERROR;
EricLew 0:80ee8f3b695e 191 }
EricLew 0:80ee8f3b695e 192 }
EricLew 0:80ee8f3b695e 193
EricLew 0:80ee8f3b695e 194 /* Process Locked */
EricLew 0:80ee8f3b695e 195 __HAL_LOCK(hcryp);
EricLew 0:80ee8f3b695e 196
EricLew 0:80ee8f3b695e 197 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 198 hcryp->State = HAL_CRYP_STATE_BUSY;
EricLew 0:80ee8f3b695e 199
EricLew 0:80ee8f3b695e 200 /* Call CRYP_ReadKey() API if the operating mode is set to
EricLew 0:80ee8f3b695e 201 key derivation, CRYP_ProcessData() otherwise */
EricLew 0:80ee8f3b695e 202 if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION)
EricLew 0:80ee8f3b695e 203 {
EricLew 0:80ee8f3b695e 204 if(CRYP_ReadKey(hcryp, pOutputData, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 205 {
EricLew 0:80ee8f3b695e 206 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 207 }
EricLew 0:80ee8f3b695e 208 }
EricLew 0:80ee8f3b695e 209 else
EricLew 0:80ee8f3b695e 210 {
EricLew 0:80ee8f3b695e 211 if(CRYP_ProcessData(hcryp, pInputData, Size, pOutputData, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 212 {
EricLew 0:80ee8f3b695e 213 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 214 }
EricLew 0:80ee8f3b695e 215 }
EricLew 0:80ee8f3b695e 216
EricLew 0:80ee8f3b695e 217 /* If the state has not been set to SUSPENDED, set it to
EricLew 0:80ee8f3b695e 218 READY, otherwise keep it as it is */
EricLew 0:80ee8f3b695e 219 if (hcryp->State != HAL_CRYP_STATE_SUSPENDED)
EricLew 0:80ee8f3b695e 220 {
EricLew 0:80ee8f3b695e 221 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 222 }
EricLew 0:80ee8f3b695e 223
EricLew 0:80ee8f3b695e 224 /* Process Unlocked */
EricLew 0:80ee8f3b695e 225 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 226
EricLew 0:80ee8f3b695e 227 return HAL_OK;
EricLew 0:80ee8f3b695e 228 }
EricLew 0:80ee8f3b695e 229 else
EricLew 0:80ee8f3b695e 230 {
EricLew 0:80ee8f3b695e 231 return HAL_BUSY;
EricLew 0:80ee8f3b695e 232 }
EricLew 0:80ee8f3b695e 233 }
EricLew 0:80ee8f3b695e 234
EricLew 0:80ee8f3b695e 235
EricLew 0:80ee8f3b695e 236
EricLew 0:80ee8f3b695e 237 /**
EricLew 0:80ee8f3b695e 238 * @brief Carry out in interrupt mode the ciphering or deciphering operation according to
EricLew 0:80ee8f3b695e 239 * hcryp->Init structure fields, all operating modes (encryption, key derivation and/or decryption) and
EricLew 0:80ee8f3b695e 240 * chaining modes ECB, CBC and CTR are managed by this function in interrupt mode.
EricLew 0:80ee8f3b695e 241 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 242 * the configuration information for CRYP module
EricLew 0:80ee8f3b695e 243 * @param pInputData: Pointer to the plain text in case of encryption or cipher text in case of decryption
EricLew 0:80ee8f3b695e 244 * or key derivation+decryption.
EricLew 0:80ee8f3b695e 245 * Parameter is meaningless in case of key derivation.
EricLew 0:80ee8f3b695e 246 * @param Size: Length of the input data buffer in bytes, must be a multiple of 16.
EricLew 0:80ee8f3b695e 247 * Parameter is meaningless in case of key derivation.
EricLew 0:80ee8f3b695e 248 * @param pOutputData: Pointer to the cipher text in case of encryption or plain text in case of
EricLew 0:80ee8f3b695e 249 * decryption/key derivation+decryption, or pointer to the derivative keys in
EricLew 0:80ee8f3b695e 250 * case of key derivation only.
EricLew 0:80ee8f3b695e 251 * @retval HAL status
EricLew 0:80ee8f3b695e 252 */
EricLew 0:80ee8f3b695e 253 HAL_StatusTypeDef HAL_CRYPEx_AES_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData)
EricLew 0:80ee8f3b695e 254 {
EricLew 0:80ee8f3b695e 255 uint32_t inputaddr = 0;
EricLew 0:80ee8f3b695e 256
EricLew 0:80ee8f3b695e 257 if(hcryp->State == HAL_CRYP_STATE_READY)
EricLew 0:80ee8f3b695e 258 {
EricLew 0:80ee8f3b695e 259 /* Check parameters setting */
EricLew 0:80ee8f3b695e 260 if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION)
EricLew 0:80ee8f3b695e 261 {
EricLew 0:80ee8f3b695e 262 if (pOutputData == NULL)
EricLew 0:80ee8f3b695e 263 {
EricLew 0:80ee8f3b695e 264 return HAL_ERROR;
EricLew 0:80ee8f3b695e 265 }
EricLew 0:80ee8f3b695e 266 }
EricLew 0:80ee8f3b695e 267 else
EricLew 0:80ee8f3b695e 268 {
EricLew 0:80ee8f3b695e 269 if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
EricLew 0:80ee8f3b695e 270 {
EricLew 0:80ee8f3b695e 271 return HAL_ERROR;
EricLew 0:80ee8f3b695e 272 }
EricLew 0:80ee8f3b695e 273 }
EricLew 0:80ee8f3b695e 274 /* Process Locked */
EricLew 0:80ee8f3b695e 275 __HAL_LOCK(hcryp);
EricLew 0:80ee8f3b695e 276
EricLew 0:80ee8f3b695e 277 /* If operating mode is not limited to key derivation only,
EricLew 0:80ee8f3b695e 278 get the buffers addresses and sizes */
EricLew 0:80ee8f3b695e 279 if (hcryp->Init.OperatingMode != CRYP_ALGOMODE_KEYDERIVATION)
EricLew 0:80ee8f3b695e 280 {
EricLew 0:80ee8f3b695e 281
EricLew 0:80ee8f3b695e 282 hcryp->CrypInCount = Size;
EricLew 0:80ee8f3b695e 283 hcryp->pCrypInBuffPtr = pInputData;
EricLew 0:80ee8f3b695e 284 hcryp->pCrypOutBuffPtr = pOutputData;
EricLew 0:80ee8f3b695e 285 hcryp->CrypOutCount = Size;
EricLew 0:80ee8f3b695e 286 }
EricLew 0:80ee8f3b695e 287
EricLew 0:80ee8f3b695e 288 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 289 hcryp->State = HAL_CRYP_STATE_BUSY;
EricLew 0:80ee8f3b695e 290
EricLew 0:80ee8f3b695e 291 /* Process Unlocked */
EricLew 0:80ee8f3b695e 292 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 293
EricLew 0:80ee8f3b695e 294 /* Enable Computation Complete Flag and Error Interrupts */
EricLew 0:80ee8f3b695e 295 __HAL_CRYP_ENABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
EricLew 0:80ee8f3b695e 296
EricLew 0:80ee8f3b695e 297
EricLew 0:80ee8f3b695e 298 /* If operating mode is key derivation only, the input data have
EricLew 0:80ee8f3b695e 299 already been entered during the initialization process. For
EricLew 0:80ee8f3b695e 300 the other operating modes, they are fed to the CRYP hardware
EricLew 0:80ee8f3b695e 301 block at this point. */
EricLew 0:80ee8f3b695e 302 if (hcryp->Init.OperatingMode != CRYP_ALGOMODE_KEYDERIVATION)
EricLew 0:80ee8f3b695e 303 {
EricLew 0:80ee8f3b695e 304 /* Initiate the processing under interrupt in entering
EricLew 0:80ee8f3b695e 305 the first input data */
EricLew 0:80ee8f3b695e 306 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
EricLew 0:80ee8f3b695e 307 /* Increment/decrement instance pointer/counter */
EricLew 0:80ee8f3b695e 308 hcryp->pCrypInBuffPtr += 16;
EricLew 0:80ee8f3b695e 309 hcryp->CrypInCount -= 16;
EricLew 0:80ee8f3b695e 310 /* Write the first input block in the Data Input register */
EricLew 0:80ee8f3b695e 311 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 312 inputaddr+=4;
EricLew 0:80ee8f3b695e 313 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 314 inputaddr+=4;
EricLew 0:80ee8f3b695e 315 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 316 inputaddr+=4;
EricLew 0:80ee8f3b695e 317 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 318 }
EricLew 0:80ee8f3b695e 319
EricLew 0:80ee8f3b695e 320 /* Return function status */
EricLew 0:80ee8f3b695e 321 return HAL_OK;
EricLew 0:80ee8f3b695e 322 }
EricLew 0:80ee8f3b695e 323 else
EricLew 0:80ee8f3b695e 324 {
EricLew 0:80ee8f3b695e 325 return HAL_BUSY;
EricLew 0:80ee8f3b695e 326 }
EricLew 0:80ee8f3b695e 327 }
EricLew 0:80ee8f3b695e 328
EricLew 0:80ee8f3b695e 329
EricLew 0:80ee8f3b695e 330
EricLew 0:80ee8f3b695e 331
EricLew 0:80ee8f3b695e 332
EricLew 0:80ee8f3b695e 333 /**
EricLew 0:80ee8f3b695e 334 * @brief Carry out in DMA mode the ciphering or deciphering operation according to
EricLew 0:80ee8f3b695e 335 * hcryp->Init structure fields.
EricLew 0:80ee8f3b695e 336 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 337 * the configuration information for CRYP module
EricLew 0:80ee8f3b695e 338 * @param pInputData: Pointer to the plain text in case of encryption or cipher text in case of decryption
EricLew 0:80ee8f3b695e 339 * or key derivation+decryption.
EricLew 0:80ee8f3b695e 340 * @param Size: Length of the input data buffer in bytes, must be a multiple of 16.
EricLew 0:80ee8f3b695e 341 * @param pOutputData: Pointer to the cipher text in case of encryption or plain text in case of
EricLew 0:80ee8f3b695e 342 * decryption/key derivation+decryption.
EricLew 0:80ee8f3b695e 343 * @note Chaining modes ECB, CBC and CTR are managed by this function in DMA mode.
EricLew 0:80ee8f3b695e 344 * @note Supported operating modes are encryption, decryption and key derivation with decryption.
EricLew 0:80ee8f3b695e 345 * @note No DMA channel is provided for key derivation only and therefore, access to AES_KEYRx
EricLew 0:80ee8f3b695e 346 * registers must be done by software.
EricLew 0:80ee8f3b695e 347 * @note This API is not applicable to key derivation only; for such a mode, access to AES_KEYRx
EricLew 0:80ee8f3b695e 348 * registers must be done by software thru HAL_CRYPEx_AES() or HAL_CRYPEx_AES_IT() APIs.
EricLew 0:80ee8f3b695e 349 * @note pInputData and pOutputData buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the IP.
EricLew 0:80ee8f3b695e 350 * @retval HAL status
EricLew 0:80ee8f3b695e 351 */
EricLew 0:80ee8f3b695e 352 HAL_StatusTypeDef HAL_CRYPEx_AES_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint16_t Size, uint8_t *pOutputData)
EricLew 0:80ee8f3b695e 353 {
EricLew 0:80ee8f3b695e 354 uint32_t inputaddr = 0;
EricLew 0:80ee8f3b695e 355 uint32_t outputaddr = 0;
EricLew 0:80ee8f3b695e 356
EricLew 0:80ee8f3b695e 357 if (hcryp->State == HAL_CRYP_STATE_READY)
EricLew 0:80ee8f3b695e 358 {
EricLew 0:80ee8f3b695e 359 /* Check parameters setting */
EricLew 0:80ee8f3b695e 360 if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION)
EricLew 0:80ee8f3b695e 361 {
EricLew 0:80ee8f3b695e 362 /* no DMA channel is provided for key derivation operating mode,
EricLew 0:80ee8f3b695e 363 access to AES_KEYRx registers must be done by software */
EricLew 0:80ee8f3b695e 364 return HAL_ERROR;
EricLew 0:80ee8f3b695e 365 }
EricLew 0:80ee8f3b695e 366 else
EricLew 0:80ee8f3b695e 367 {
EricLew 0:80ee8f3b695e 368 if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
EricLew 0:80ee8f3b695e 369 {
EricLew 0:80ee8f3b695e 370 return HAL_ERROR;
EricLew 0:80ee8f3b695e 371 }
EricLew 0:80ee8f3b695e 372 }
EricLew 0:80ee8f3b695e 373
EricLew 0:80ee8f3b695e 374
EricLew 0:80ee8f3b695e 375 /* Process Locked */
EricLew 0:80ee8f3b695e 376 __HAL_LOCK(hcryp);
EricLew 0:80ee8f3b695e 377
EricLew 0:80ee8f3b695e 378 inputaddr = (uint32_t)pInputData;
EricLew 0:80ee8f3b695e 379 outputaddr = (uint32_t)pOutputData;
EricLew 0:80ee8f3b695e 380
EricLew 0:80ee8f3b695e 381 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 382 hcryp->State = HAL_CRYP_STATE_BUSY;
EricLew 0:80ee8f3b695e 383
EricLew 0:80ee8f3b695e 384 /* Set the input and output addresses and start DMA transfer */
EricLew 0:80ee8f3b695e 385 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
EricLew 0:80ee8f3b695e 386
EricLew 0:80ee8f3b695e 387 /* Process Unlocked */
EricLew 0:80ee8f3b695e 388 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 389
EricLew 0:80ee8f3b695e 390 /* Return function status */
EricLew 0:80ee8f3b695e 391 return HAL_OK;
EricLew 0:80ee8f3b695e 392 }
EricLew 0:80ee8f3b695e 393 else
EricLew 0:80ee8f3b695e 394 {
EricLew 0:80ee8f3b695e 395 return HAL_BUSY;
EricLew 0:80ee8f3b695e 396 }
EricLew 0:80ee8f3b695e 397 }
EricLew 0:80ee8f3b695e 398
EricLew 0:80ee8f3b695e 399
EricLew 0:80ee8f3b695e 400
EricLew 0:80ee8f3b695e 401
EricLew 0:80ee8f3b695e 402
EricLew 0:80ee8f3b695e 403
EricLew 0:80ee8f3b695e 404 /**
EricLew 0:80ee8f3b695e 405 * @brief Carry out in polling mode the authentication tag generation as well as the ciphering or deciphering
EricLew 0:80ee8f3b695e 406 * operation according to hcryp->Init structure fields.
EricLew 0:80ee8f3b695e 407 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 408 * the configuration information for CRYP module
EricLew 0:80ee8f3b695e 409 * @param pInputData: Pointer to payload data in GCM payload phase,
EricLew 0:80ee8f3b695e 410 * Parameter is meaningless in case of GCM/GMAC init, header and final phases,
EricLew 0:80ee8f3b695e 411 * Pointer to B0 blocks in CMAC header phase,
EricLew 0:80ee8f3b695e 412 * Pointer to C block in CMAC final phase.
EricLew 0:80ee8f3b695e 413 * @param Size: Length of the input payload data buffer in bytes, must be a multiple of 16,
EricLew 0:80ee8f3b695e 414 * Parameter is meaningless in case of GCM/GMAC init and header phases,
EricLew 0:80ee8f3b695e 415 * Length of B blocks (in bytes, must be a multiple of 16) in CMAC header phase,
EricLew 0:80ee8f3b695e 416 * Length of C block (in bytes) in CMAC final phase.
EricLew 0:80ee8f3b695e 417 * @param pOutputData: Pointer to plain or cipher text in GCM payload phase,
EricLew 0:80ee8f3b695e 418 * pointer to authentication tag in GCM/GMAC and CMAC final phases.
EricLew 0:80ee8f3b695e 419 * Parameter is meaningless in case of GCM/GMAC init and header phases
EricLew 0:80ee8f3b695e 420 * and in case of CMAC header phase.
EricLew 0:80ee8f3b695e 421 * @param Timeout: Specify Timeout value
EricLew 0:80ee8f3b695e 422 * @note Supported operating modes are encryption and decryption, supported chaining modes are GCM, GMAC and CMAC.
EricLew 0:80ee8f3b695e 423 * @note Phases are singly processed according to hcryp->Init.GCMCMACPhase so that steps in these specific chaining modes
EricLew 0:80ee8f3b695e 424 * can be skipped by the user if so required.
EricLew 0:80ee8f3b695e 425 * @retval HAL status
EricLew 0:80ee8f3b695e 426 */
EricLew 0:80ee8f3b695e 427 HAL_StatusTypeDef HAL_CRYPEx_AES_Auth(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData, uint32_t Timeout)
EricLew 0:80ee8f3b695e 428 {
EricLew 0:80ee8f3b695e 429 uint32_t index = 0;
EricLew 0:80ee8f3b695e 430 uint32_t inputaddr = 0;
EricLew 0:80ee8f3b695e 431 uint32_t outputaddr = 0;
EricLew 0:80ee8f3b695e 432 uint32_t tagaddr = 0;
EricLew 0:80ee8f3b695e 433 uint64_t headerlength = 0;
EricLew 0:80ee8f3b695e 434 uint64_t inputlength = 0;
EricLew 0:80ee8f3b695e 435
EricLew 0:80ee8f3b695e 436 if (hcryp->State == HAL_CRYP_STATE_READY)
EricLew 0:80ee8f3b695e 437 {
EricLew 0:80ee8f3b695e 438 /* input/output parameters check */
EricLew 0:80ee8f3b695e 439 if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_HEADER_PHASE)
EricLew 0:80ee8f3b695e 440 {
EricLew 0:80ee8f3b695e 441 if ((hcryp->Init.Header == NULL) || (hcryp->Init.HeaderSize == 0))
EricLew 0:80ee8f3b695e 442 {
EricLew 0:80ee8f3b695e 443 return HAL_ERROR;
EricLew 0:80ee8f3b695e 444 }
EricLew 0:80ee8f3b695e 445 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 446 {
EricLew 0:80ee8f3b695e 447 /* In case of CMAC header phase resumption, we can have pInputData = NULL and Size = 0 */
EricLew 0:80ee8f3b695e 448 if (((pInputData != NULL) && (Size == 0)) || ((pInputData == NULL) && (Size != 0)))
EricLew 0:80ee8f3b695e 449 {
EricLew 0:80ee8f3b695e 450 return HAL_ERROR;
EricLew 0:80ee8f3b695e 451 }
EricLew 0:80ee8f3b695e 452 }
EricLew 0:80ee8f3b695e 453 }
EricLew 0:80ee8f3b695e 454 else if (hcryp->Init.GCMCMACPhase == CRYP_GCM_PAYLOAD_PHASE)
EricLew 0:80ee8f3b695e 455 {
EricLew 0:80ee8f3b695e 456 if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
EricLew 0:80ee8f3b695e 457 {
EricLew 0:80ee8f3b695e 458 return HAL_ERROR;
EricLew 0:80ee8f3b695e 459 }
EricLew 0:80ee8f3b695e 460 }
EricLew 0:80ee8f3b695e 461 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_FINAL_PHASE)
EricLew 0:80ee8f3b695e 462 {
EricLew 0:80ee8f3b695e 463 if (pOutputData == NULL)
EricLew 0:80ee8f3b695e 464 {
EricLew 0:80ee8f3b695e 465 return HAL_ERROR;
EricLew 0:80ee8f3b695e 466 }
EricLew 0:80ee8f3b695e 467 if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC) && (pInputData == NULL))
EricLew 0:80ee8f3b695e 468 {
EricLew 0:80ee8f3b695e 469 return HAL_ERROR;
EricLew 0:80ee8f3b695e 470 }
EricLew 0:80ee8f3b695e 471 }
EricLew 0:80ee8f3b695e 472
EricLew 0:80ee8f3b695e 473
EricLew 0:80ee8f3b695e 474 /* Process Locked */
EricLew 0:80ee8f3b695e 475 __HAL_LOCK(hcryp);
EricLew 0:80ee8f3b695e 476
EricLew 0:80ee8f3b695e 477 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 478 hcryp->State = HAL_CRYP_STATE_BUSY;
EricLew 0:80ee8f3b695e 479
EricLew 0:80ee8f3b695e 480 /*=====================*/
EricLew 0:80ee8f3b695e 481 /* GCM/GMAC init phase */
EricLew 0:80ee8f3b695e 482 /*=====================*/
EricLew 0:80ee8f3b695e 483 /* In case of init phase, the input data (Key and Initialization Vector) have
EricLew 0:80ee8f3b695e 484 already been entered during the initialization process. Therefore, the
EricLew 0:80ee8f3b695e 485 API just waits for the CCF flag to be set. */
EricLew 0:80ee8f3b695e 486 if (hcryp->Init.GCMCMACPhase == CRYP_GCM_INIT_PHASE)
EricLew 0:80ee8f3b695e 487 {
EricLew 0:80ee8f3b695e 488 /* just wait for hash computation */
EricLew 0:80ee8f3b695e 489 if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 490 {
EricLew 0:80ee8f3b695e 491 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 492 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 493 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 494 }
EricLew 0:80ee8f3b695e 495
EricLew 0:80ee8f3b695e 496 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 497 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 498 /* Mark that the initialization phase is over */
EricLew 0:80ee8f3b695e 499 hcryp->Phase = HAL_CRYP_PHASE_INIT_OVER;
EricLew 0:80ee8f3b695e 500 }
EricLew 0:80ee8f3b695e 501 /*===============================*/
EricLew 0:80ee8f3b695e 502 /* GCM/GMAC or CMAC header phase */
EricLew 0:80ee8f3b695e 503 /*===============================*/
EricLew 0:80ee8f3b695e 504 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_HEADER_PHASE)
EricLew 0:80ee8f3b695e 505 {
EricLew 0:80ee8f3b695e 506 /* Set header phase; for GCM or GMAC, set data-byte at this point */
EricLew 0:80ee8f3b695e 507 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
EricLew 0:80ee8f3b695e 508 {
EricLew 0:80ee8f3b695e 509 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH|AES_CR_DATATYPE, CRYP_GCMCMAC_HEADER_PHASE|hcryp->Init.DataType);
EricLew 0:80ee8f3b695e 510 }
EricLew 0:80ee8f3b695e 511 else
EricLew 0:80ee8f3b695e 512 {
EricLew 0:80ee8f3b695e 513 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCMCMAC_HEADER_PHASE);
EricLew 0:80ee8f3b695e 514 }
EricLew 0:80ee8f3b695e 515
EricLew 0:80ee8f3b695e 516 /* Enable the Peripheral */
EricLew 0:80ee8f3b695e 517 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 518
EricLew 0:80ee8f3b695e 519 /* in case of CMAC, enter B0 block in header phase, before the header itself. */
EricLew 0:80ee8f3b695e 520 /* If Size = 0 (possible case of resumption after CMAC header phase suspension),
EricLew 0:80ee8f3b695e 521 skip these steps and go directly to header buffer feeding to the HW */
EricLew 0:80ee8f3b695e 522 if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC) && (Size != 0))
EricLew 0:80ee8f3b695e 523 {
EricLew 0:80ee8f3b695e 524 inputaddr = (uint32_t)pInputData;
EricLew 0:80ee8f3b695e 525
EricLew 0:80ee8f3b695e 526 for(index=0; (index < Size); index += 16)
EricLew 0:80ee8f3b695e 527 {
EricLew 0:80ee8f3b695e 528 /* Write the Input block in the Data Input register */
EricLew 0:80ee8f3b695e 529 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 530 inputaddr+=4;
EricLew 0:80ee8f3b695e 531 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 532 inputaddr+=4;
EricLew 0:80ee8f3b695e 533 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 534 inputaddr+=4;
EricLew 0:80ee8f3b695e 535 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 536 inputaddr+=4;
EricLew 0:80ee8f3b695e 537
EricLew 0:80ee8f3b695e 538 if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 539 {
EricLew 0:80ee8f3b695e 540 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 541 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 542 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 543 }
EricLew 0:80ee8f3b695e 544 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 545 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 546
EricLew 0:80ee8f3b695e 547 /* If the suspension flag has been raised and if the processing is not about
EricLew 0:80ee8f3b695e 548 to end, suspend processing */
EricLew 0:80ee8f3b695e 549 if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16) < Size))
EricLew 0:80ee8f3b695e 550 {
EricLew 0:80ee8f3b695e 551 /* reset SuspendRequest */
EricLew 0:80ee8f3b695e 552 hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
EricLew 0:80ee8f3b695e 553 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 554 hcryp->State = HAL_CRYP_STATE_SUSPENDED;
EricLew 0:80ee8f3b695e 555 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 556 hcryp->Phase = HAL_CRYP_PHASE_HEADER_SUSPENDED;
EricLew 0:80ee8f3b695e 557
EricLew 0:80ee8f3b695e 558 /* Save current reading and writing locations of Input and Output buffers */
EricLew 0:80ee8f3b695e 559 hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
EricLew 0:80ee8f3b695e 560 /* Save the total number of bytes (B blocks + header) that remain to be
EricLew 0:80ee8f3b695e 561 processed at this point */
EricLew 0:80ee8f3b695e 562 hcryp->CrypInCount = hcryp->Init.HeaderSize + Size - (index+16);
EricLew 0:80ee8f3b695e 563
EricLew 0:80ee8f3b695e 564 /* Process Unlocked */
EricLew 0:80ee8f3b695e 565 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 566
EricLew 0:80ee8f3b695e 567 return HAL_OK;
EricLew 0:80ee8f3b695e 568 }
EricLew 0:80ee8f3b695e 569 } /* for(index=0; (index < Size); index += 16) */
EricLew 0:80ee8f3b695e 570 }
EricLew 0:80ee8f3b695e 571
EricLew 0:80ee8f3b695e 572 /* Enter header */
EricLew 0:80ee8f3b695e 573 inputaddr = (uint32_t)hcryp->Init.Header;
EricLew 0:80ee8f3b695e 574 for(index=0; (index < hcryp->Init.HeaderSize); index += 16)
EricLew 0:80ee8f3b695e 575 {
EricLew 0:80ee8f3b695e 576 /* Write the Input block in the Data Input register */
EricLew 0:80ee8f3b695e 577 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 578 inputaddr+=4;
EricLew 0:80ee8f3b695e 579 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 580 inputaddr+=4;
EricLew 0:80ee8f3b695e 581 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 582 inputaddr+=4;
EricLew 0:80ee8f3b695e 583 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 584 inputaddr+=4;
EricLew 0:80ee8f3b695e 585
EricLew 0:80ee8f3b695e 586 if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 587 {
EricLew 0:80ee8f3b695e 588 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 589 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 590 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 591 }
EricLew 0:80ee8f3b695e 592 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 593 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 594
EricLew 0:80ee8f3b695e 595 /* If the suspension flag has been raised and if the processing is not about
EricLew 0:80ee8f3b695e 596 to end, suspend processing */
EricLew 0:80ee8f3b695e 597 if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16) < hcryp->Init.HeaderSize))
EricLew 0:80ee8f3b695e 598 {
EricLew 0:80ee8f3b695e 599 /* reset SuspendRequest */
EricLew 0:80ee8f3b695e 600 hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
EricLew 0:80ee8f3b695e 601 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 602 hcryp->State = HAL_CRYP_STATE_SUSPENDED;
EricLew 0:80ee8f3b695e 603 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 604 hcryp->Phase = HAL_CRYP_PHASE_HEADER_SUSPENDED;
EricLew 0:80ee8f3b695e 605
EricLew 0:80ee8f3b695e 606 /* Save current reading and writing locations of Input and Output buffers */
EricLew 0:80ee8f3b695e 607 hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
EricLew 0:80ee8f3b695e 608 /* Save the total number of bytes that remain to be processed at this point */
EricLew 0:80ee8f3b695e 609 hcryp->CrypInCount = hcryp->Init.HeaderSize - (index+16);
EricLew 0:80ee8f3b695e 610
EricLew 0:80ee8f3b695e 611 /* Process Unlocked */
EricLew 0:80ee8f3b695e 612 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 613
EricLew 0:80ee8f3b695e 614 return HAL_OK;
EricLew 0:80ee8f3b695e 615 }
EricLew 0:80ee8f3b695e 616 }
EricLew 0:80ee8f3b695e 617 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 618 hcryp->Phase = HAL_CRYP_PHASE_HEADER_OVER;
EricLew 0:80ee8f3b695e 619 }
EricLew 0:80ee8f3b695e 620 /*========================*/
EricLew 0:80ee8f3b695e 621 /* GCM/GMAC payload phase */
EricLew 0:80ee8f3b695e 622 /*========================*/
EricLew 0:80ee8f3b695e 623 else if (hcryp->Init.GCMCMACPhase == CRYP_GCM_PAYLOAD_PHASE)
EricLew 0:80ee8f3b695e 624 {
EricLew 0:80ee8f3b695e 625
EricLew 0:80ee8f3b695e 626 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCM_PAYLOAD_PHASE);
EricLew 0:80ee8f3b695e 627
EricLew 0:80ee8f3b695e 628 /* if the header phase has been bypassed, AES must be enabled again */
EricLew 0:80ee8f3b695e 629 if (hcryp->Phase == HAL_CRYP_PHASE_INIT_OVER)
EricLew 0:80ee8f3b695e 630 {
EricLew 0:80ee8f3b695e 631 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 632 }
EricLew 0:80ee8f3b695e 633
EricLew 0:80ee8f3b695e 634 inputaddr = (uint32_t)pInputData;
EricLew 0:80ee8f3b695e 635 outputaddr = (uint32_t)pOutputData;
EricLew 0:80ee8f3b695e 636
EricLew 0:80ee8f3b695e 637 /* Enter payload */
EricLew 0:80ee8f3b695e 638 for(index=0; (index < Size); index += 16)
EricLew 0:80ee8f3b695e 639 {
EricLew 0:80ee8f3b695e 640 /* Write the Input block in the Data Input register */
EricLew 0:80ee8f3b695e 641 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 642 inputaddr+=4;
EricLew 0:80ee8f3b695e 643 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 644 inputaddr+=4;
EricLew 0:80ee8f3b695e 645 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 646 inputaddr+=4;
EricLew 0:80ee8f3b695e 647 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 648 inputaddr+=4;
EricLew 0:80ee8f3b695e 649
EricLew 0:80ee8f3b695e 650 if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 651 {
EricLew 0:80ee8f3b695e 652 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 653 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 654 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 655 }
EricLew 0:80ee8f3b695e 656
EricLew 0:80ee8f3b695e 657 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 658 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 659
EricLew 0:80ee8f3b695e 660 /* Retrieve output data: read the output block
EricLew 0:80ee8f3b695e 661 from the Data Output Register */
EricLew 0:80ee8f3b695e 662 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 663 outputaddr+=4;
EricLew 0:80ee8f3b695e 664 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 665 outputaddr+=4;
EricLew 0:80ee8f3b695e 666 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 667 outputaddr+=4;
EricLew 0:80ee8f3b695e 668 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 669 outputaddr+=4;
EricLew 0:80ee8f3b695e 670
EricLew 0:80ee8f3b695e 671 /* If the suspension flag has been raised and if the processing is not about
EricLew 0:80ee8f3b695e 672 to end, suspend processing */
EricLew 0:80ee8f3b695e 673 if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16) < Size))
EricLew 0:80ee8f3b695e 674 {
EricLew 0:80ee8f3b695e 675 if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT)
EricLew 0:80ee8f3b695e 676 {
EricLew 0:80ee8f3b695e 677 /* Ensure that Busy flag is reset */
EricLew 0:80ee8f3b695e 678 if(CRYP_WaitOnBusyFlagReset(hcryp, CRYP_BUSY_TIMEOUTVALUE) != HAL_OK)
EricLew 0:80ee8f3b695e 679 {
EricLew 0:80ee8f3b695e 680 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 681 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 682 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 683 }
EricLew 0:80ee8f3b695e 684 }
EricLew 0:80ee8f3b695e 685 /* reset SuspendRequest */
EricLew 0:80ee8f3b695e 686 hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
EricLew 0:80ee8f3b695e 687 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 688 hcryp->State = HAL_CRYP_STATE_SUSPENDED;
EricLew 0:80ee8f3b695e 689 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 690 hcryp->Phase = HAL_CRYP_PHASE_HEADER_SUSPENDED;
EricLew 0:80ee8f3b695e 691
EricLew 0:80ee8f3b695e 692 /* Save current reading and writing locations of Input and Output buffers */
EricLew 0:80ee8f3b695e 693 hcryp->pCrypOutBuffPtr = (uint8_t *)outputaddr;
EricLew 0:80ee8f3b695e 694 hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
EricLew 0:80ee8f3b695e 695 /* Save the number of bytes that remain to be processed at this point */
EricLew 0:80ee8f3b695e 696 hcryp->CrypInCount = Size - (index+16);
EricLew 0:80ee8f3b695e 697
EricLew 0:80ee8f3b695e 698 /* Process Unlocked */
EricLew 0:80ee8f3b695e 699 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 700
EricLew 0:80ee8f3b695e 701 return HAL_OK;
EricLew 0:80ee8f3b695e 702 }
EricLew 0:80ee8f3b695e 703
EricLew 0:80ee8f3b695e 704 }
EricLew 0:80ee8f3b695e 705 /* Mark that the payload phase is over */
EricLew 0:80ee8f3b695e 706 hcryp->Phase = HAL_CRYP_PHASE_PAYLOAD_OVER;
EricLew 0:80ee8f3b695e 707 }
EricLew 0:80ee8f3b695e 708 /*==============================*/
EricLew 0:80ee8f3b695e 709 /* GCM/GMAC or CMAC final phase */
EricLew 0:80ee8f3b695e 710 /*==============================*/
EricLew 0:80ee8f3b695e 711 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_FINAL_PHASE)
EricLew 0:80ee8f3b695e 712 {
EricLew 0:80ee8f3b695e 713 tagaddr = (uint32_t)pOutputData;
EricLew 0:80ee8f3b695e 714
EricLew 0:80ee8f3b695e 715 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCMCMAC_FINAL_PHASE);
EricLew 0:80ee8f3b695e 716
EricLew 0:80ee8f3b695e 717 /* if the header and payload phases have been bypassed, AES must be enabled again */
EricLew 0:80ee8f3b695e 718 if (hcryp->Phase == HAL_CRYP_PHASE_INIT_OVER)
EricLew 0:80ee8f3b695e 719 {
EricLew 0:80ee8f3b695e 720 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 721 }
EricLew 0:80ee8f3b695e 722
EricLew 0:80ee8f3b695e 723 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
EricLew 0:80ee8f3b695e 724 {
EricLew 0:80ee8f3b695e 725 headerlength = hcryp->Init.HeaderSize * 8; /* Header length in bits */
EricLew 0:80ee8f3b695e 726 inputlength = Size * 8; /* input length in bits */
EricLew 0:80ee8f3b695e 727
EricLew 0:80ee8f3b695e 728
EricLew 0:80ee8f3b695e 729 if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
EricLew 0:80ee8f3b695e 730 {
EricLew 0:80ee8f3b695e 731 hcryp->Instance->DINR = __RBIT((headerlength)>>32);
EricLew 0:80ee8f3b695e 732 hcryp->Instance->DINR = __RBIT(headerlength);
EricLew 0:80ee8f3b695e 733 hcryp->Instance->DINR = __RBIT((inputlength)>>32);
EricLew 0:80ee8f3b695e 734 hcryp->Instance->DINR = __RBIT(inputlength);
EricLew 0:80ee8f3b695e 735 }
EricLew 0:80ee8f3b695e 736 else if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
EricLew 0:80ee8f3b695e 737 {
EricLew 0:80ee8f3b695e 738 hcryp->Instance->DINR = __REV((headerlength)>>32);
EricLew 0:80ee8f3b695e 739 hcryp->Instance->DINR = __REV(headerlength);
EricLew 0:80ee8f3b695e 740 hcryp->Instance->DINR = __REV((inputlength)>>32);
EricLew 0:80ee8f3b695e 741 hcryp->Instance->DINR = __REV(inputlength);
EricLew 0:80ee8f3b695e 742 }
EricLew 0:80ee8f3b695e 743 else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
EricLew 0:80ee8f3b695e 744 {
EricLew 0:80ee8f3b695e 745 hcryp->Instance->DINR = __ROR((headerlength)>>32, 16);
EricLew 0:80ee8f3b695e 746 hcryp->Instance->DINR = __ROR(headerlength, 16);
EricLew 0:80ee8f3b695e 747 hcryp->Instance->DINR = __ROR((inputlength)>>32, 16);
EricLew 0:80ee8f3b695e 748 hcryp->Instance->DINR = __ROR(inputlength, 16);
EricLew 0:80ee8f3b695e 749 }
EricLew 0:80ee8f3b695e 750 else if(hcryp->Init.DataType == CRYP_DATATYPE_32B)
EricLew 0:80ee8f3b695e 751 {
EricLew 0:80ee8f3b695e 752 hcryp->Instance->DINR = (uint32_t)(headerlength>>32);
EricLew 0:80ee8f3b695e 753 hcryp->Instance->DINR = (uint32_t)(headerlength);
EricLew 0:80ee8f3b695e 754 hcryp->Instance->DINR = (uint32_t)(inputlength>>32);
EricLew 0:80ee8f3b695e 755 hcryp->Instance->DINR = (uint32_t)(inputlength);
EricLew 0:80ee8f3b695e 756 }
EricLew 0:80ee8f3b695e 757 }
EricLew 0:80ee8f3b695e 758 else if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 759 {
EricLew 0:80ee8f3b695e 760 inputaddr = (uint32_t)pInputData;
EricLew 0:80ee8f3b695e 761 /* Enter the last block made of a 128-bit value formatted
EricLew 0:80ee8f3b695e 762 from the original B0 packet. */
EricLew 0:80ee8f3b695e 763 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 764 inputaddr+=4;
EricLew 0:80ee8f3b695e 765 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 766 inputaddr+=4;
EricLew 0:80ee8f3b695e 767 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 768 inputaddr+=4;
EricLew 0:80ee8f3b695e 769 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 770 }
EricLew 0:80ee8f3b695e 771
EricLew 0:80ee8f3b695e 772
EricLew 0:80ee8f3b695e 773 if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 774 {
EricLew 0:80ee8f3b695e 775 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 776 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 777 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 778 }
EricLew 0:80ee8f3b695e 779
EricLew 0:80ee8f3b695e 780 /* Read the Auth TAG in the Data Out register */
EricLew 0:80ee8f3b695e 781 *(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 782 tagaddr+=4;
EricLew 0:80ee8f3b695e 783 *(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 784 tagaddr+=4;
EricLew 0:80ee8f3b695e 785 *(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 786 tagaddr+=4;
EricLew 0:80ee8f3b695e 787 *(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 788
EricLew 0:80ee8f3b695e 789
EricLew 0:80ee8f3b695e 790 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 791 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 792 /* Mark that the final phase is over */
EricLew 0:80ee8f3b695e 793 hcryp->Phase = HAL_CRYP_PHASE_FINAL_OVER;
EricLew 0:80ee8f3b695e 794 /* Disable the Peripheral */
EricLew 0:80ee8f3b695e 795 __HAL_CRYP_DISABLE();
EricLew 0:80ee8f3b695e 796 }
EricLew 0:80ee8f3b695e 797 /*=================================================*/
EricLew 0:80ee8f3b695e 798 /* case incorrect hcryp->Init.GCMCMACPhase setting */
EricLew 0:80ee8f3b695e 799 /*=================================================*/
EricLew 0:80ee8f3b695e 800 else
EricLew 0:80ee8f3b695e 801 {
EricLew 0:80ee8f3b695e 802 hcryp->State = HAL_CRYP_STATE_ERROR;
EricLew 0:80ee8f3b695e 803 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 804 return HAL_ERROR;
EricLew 0:80ee8f3b695e 805 }
EricLew 0:80ee8f3b695e 806
EricLew 0:80ee8f3b695e 807 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 808 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 809
EricLew 0:80ee8f3b695e 810 /* Process Unlocked */
EricLew 0:80ee8f3b695e 811 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 812
EricLew 0:80ee8f3b695e 813 return HAL_OK;
EricLew 0:80ee8f3b695e 814 }
EricLew 0:80ee8f3b695e 815 else
EricLew 0:80ee8f3b695e 816 {
EricLew 0:80ee8f3b695e 817 return HAL_BUSY;
EricLew 0:80ee8f3b695e 818 }
EricLew 0:80ee8f3b695e 819 }
EricLew 0:80ee8f3b695e 820
EricLew 0:80ee8f3b695e 821
EricLew 0:80ee8f3b695e 822
EricLew 0:80ee8f3b695e 823
EricLew 0:80ee8f3b695e 824 /**
EricLew 0:80ee8f3b695e 825 * @brief Carry out in interrupt mode the authentication tag generation as well as the ciphering or deciphering
EricLew 0:80ee8f3b695e 826 * operation according to hcryp->Init structure fields.
EricLew 0:80ee8f3b695e 827 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 828 * the configuration information for CRYP module
EricLew 0:80ee8f3b695e 829 * @param pInputData: Pointer to payload data in GCM payload phase,
EricLew 0:80ee8f3b695e 830 * Parameter is meaningless in case of GCM/GMAC init, header and final phases,
EricLew 0:80ee8f3b695e 831 * Pointer to B0 blocks in CMAC header phase,
EricLew 0:80ee8f3b695e 832 * Pointer to C block in CMAC final phase.
EricLew 0:80ee8f3b695e 833 * @param Size: Length of the input payload data buffer in bytes, must be a multiple of 16,
EricLew 0:80ee8f3b695e 834 * Parameter is meaningless in case of GCM/GMAC init and header phases,
EricLew 0:80ee8f3b695e 835 * Length of B blocks (in bytes, must be a multiple of 16) in CMAC header phase,
EricLew 0:80ee8f3b695e 836 * Length of C block (in bytes) in CMAC final phase.
EricLew 0:80ee8f3b695e 837 * @param pOutputData: Pointer to plain or cipher text in GCM payload phase,
EricLew 0:80ee8f3b695e 838 * pointer to authentication tag in GCM/GMAC and CMAC final phases.
EricLew 0:80ee8f3b695e 839 * Parameter is meaningless in case of GCM/GMAC init and header phases
EricLew 0:80ee8f3b695e 840 * and in case of CMAC header phase.
EricLew 0:80ee8f3b695e 841 * @note Supported operating modes are encryption and decryption, supported chaining modes are GCM, GMAC and CMAC.
EricLew 0:80ee8f3b695e 842 * @note Phases are singly processed according to hcryp->Init.GCMCMACPhase so that steps in these specific chaining modes
EricLew 0:80ee8f3b695e 843 * can be skipped by the user if so required.
EricLew 0:80ee8f3b695e 844 * @retval HAL status
EricLew 0:80ee8f3b695e 845 */
EricLew 0:80ee8f3b695e 846 HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData)
EricLew 0:80ee8f3b695e 847 {
EricLew 0:80ee8f3b695e 848
EricLew 0:80ee8f3b695e 849 uint32_t inputaddr = 0;
EricLew 0:80ee8f3b695e 850 uint64_t headerlength = 0;
EricLew 0:80ee8f3b695e 851 uint64_t inputlength = 0;
EricLew 0:80ee8f3b695e 852
EricLew 0:80ee8f3b695e 853
EricLew 0:80ee8f3b695e 854 if (hcryp->State == HAL_CRYP_STATE_READY)
EricLew 0:80ee8f3b695e 855 {
EricLew 0:80ee8f3b695e 856 /* input/output parameters check */
EricLew 0:80ee8f3b695e 857 if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_HEADER_PHASE)
EricLew 0:80ee8f3b695e 858 {
EricLew 0:80ee8f3b695e 859 if ((hcryp->Init.Header == NULL) || (hcryp->Init.HeaderSize == 0))
EricLew 0:80ee8f3b695e 860 {
EricLew 0:80ee8f3b695e 861 return HAL_ERROR;
EricLew 0:80ee8f3b695e 862 }
EricLew 0:80ee8f3b695e 863 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 864 {
EricLew 0:80ee8f3b695e 865 /* In case of CMAC header phase resumption, we can have pInputData = NULL and Size = 0 */
EricLew 0:80ee8f3b695e 866 if (((pInputData != NULL) && (Size == 0)) || ((pInputData == NULL) && (Size != 0)))
EricLew 0:80ee8f3b695e 867 {
EricLew 0:80ee8f3b695e 868 return HAL_ERROR;
EricLew 0:80ee8f3b695e 869 }
EricLew 0:80ee8f3b695e 870 }
EricLew 0:80ee8f3b695e 871 }
EricLew 0:80ee8f3b695e 872 else if (hcryp->Init.GCMCMACPhase == CRYP_GCM_PAYLOAD_PHASE)
EricLew 0:80ee8f3b695e 873 {
EricLew 0:80ee8f3b695e 874 if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
EricLew 0:80ee8f3b695e 875 {
EricLew 0:80ee8f3b695e 876 return HAL_ERROR;
EricLew 0:80ee8f3b695e 877 }
EricLew 0:80ee8f3b695e 878 }
EricLew 0:80ee8f3b695e 879 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_FINAL_PHASE)
EricLew 0:80ee8f3b695e 880 {
EricLew 0:80ee8f3b695e 881 if (pOutputData == NULL)
EricLew 0:80ee8f3b695e 882 {
EricLew 0:80ee8f3b695e 883 return HAL_ERROR;
EricLew 0:80ee8f3b695e 884 }
EricLew 0:80ee8f3b695e 885 if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC) && (pInputData == NULL))
EricLew 0:80ee8f3b695e 886 {
EricLew 0:80ee8f3b695e 887 return HAL_ERROR;
EricLew 0:80ee8f3b695e 888 }
EricLew 0:80ee8f3b695e 889 }
EricLew 0:80ee8f3b695e 890
EricLew 0:80ee8f3b695e 891
EricLew 0:80ee8f3b695e 892 /* Process Locked */
EricLew 0:80ee8f3b695e 893 __HAL_LOCK(hcryp);
EricLew 0:80ee8f3b695e 894
EricLew 0:80ee8f3b695e 895 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 896 hcryp->State = HAL_CRYP_STATE_BUSY;
EricLew 0:80ee8f3b695e 897
EricLew 0:80ee8f3b695e 898 /* Process Unlocked */
EricLew 0:80ee8f3b695e 899 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 900
EricLew 0:80ee8f3b695e 901 /* Enable Computation Complete Flag and Error Interrupts */
EricLew 0:80ee8f3b695e 902 __HAL_CRYP_ENABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
EricLew 0:80ee8f3b695e 903
EricLew 0:80ee8f3b695e 904
EricLew 0:80ee8f3b695e 905
EricLew 0:80ee8f3b695e 906 /*=====================*/
EricLew 0:80ee8f3b695e 907 /* GCM/GMAC init phase */
EricLew 0:80ee8f3b695e 908 /*=====================*/
EricLew 0:80ee8f3b695e 909 if (hcryp->Init.GCMCMACPhase == CRYP_GCM_INIT_PHASE)
EricLew 0:80ee8f3b695e 910 {
EricLew 0:80ee8f3b695e 911 /* In case of init phase, the input data (Key and Initialization Vector) have
EricLew 0:80ee8f3b695e 912 already been entered during the initialization process. Therefore, the
EricLew 0:80ee8f3b695e 913 software just waits for the CCF interrupt to be raised and which will
EricLew 0:80ee8f3b695e 914 be handled by CRYP_AES_Auth_IT() API. */
EricLew 0:80ee8f3b695e 915 }
EricLew 0:80ee8f3b695e 916 /*===============================*/
EricLew 0:80ee8f3b695e 917 /* GCM/GMAC or CMAC header phase */
EricLew 0:80ee8f3b695e 918 /*===============================*/
EricLew 0:80ee8f3b695e 919 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_HEADER_PHASE)
EricLew 0:80ee8f3b695e 920 {
EricLew 0:80ee8f3b695e 921 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 922 {
EricLew 0:80ee8f3b695e 923 /* In case of CMAC, B blocks are first entered, before the header.
EricLew 0:80ee8f3b695e 924 Therefore, B blocks and the header are entered back-to-back
EricLew 0:80ee8f3b695e 925 as if it was only one single block.
EricLew 0:80ee8f3b695e 926 However, in case of resumption after suspension, if all the
EricLew 0:80ee8f3b695e 927 B blocks have been entered (in that case, Size = 0), only the
EricLew 0:80ee8f3b695e 928 remainder of the non-processed header bytes are entered. */
EricLew 0:80ee8f3b695e 929 if (Size != 0)
EricLew 0:80ee8f3b695e 930 {
EricLew 0:80ee8f3b695e 931 hcryp->CrypInCount = Size + hcryp->Init.HeaderSize;
EricLew 0:80ee8f3b695e 932 hcryp->pCrypInBuffPtr = pInputData;
EricLew 0:80ee8f3b695e 933 }
EricLew 0:80ee8f3b695e 934 else
EricLew 0:80ee8f3b695e 935 {
EricLew 0:80ee8f3b695e 936 hcryp->CrypInCount = hcryp->Init.HeaderSize;
EricLew 0:80ee8f3b695e 937 hcryp->pCrypInBuffPtr = hcryp->Init.Header;
EricLew 0:80ee8f3b695e 938 }
EricLew 0:80ee8f3b695e 939 }
EricLew 0:80ee8f3b695e 940 else
EricLew 0:80ee8f3b695e 941 {
EricLew 0:80ee8f3b695e 942 /* Get the header addresses and sizes */
EricLew 0:80ee8f3b695e 943 hcryp->CrypInCount = hcryp->Init.HeaderSize;
EricLew 0:80ee8f3b695e 944 hcryp->pCrypInBuffPtr = hcryp->Init.Header;
EricLew 0:80ee8f3b695e 945 }
EricLew 0:80ee8f3b695e 946
EricLew 0:80ee8f3b695e 947 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
EricLew 0:80ee8f3b695e 948
EricLew 0:80ee8f3b695e 949 /* Set header phase; for GCM or GMAC, set data-byte at this point */
EricLew 0:80ee8f3b695e 950 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
EricLew 0:80ee8f3b695e 951 {
EricLew 0:80ee8f3b695e 952 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH|AES_CR_DATATYPE, CRYP_GCMCMAC_HEADER_PHASE|hcryp->Init.DataType);
EricLew 0:80ee8f3b695e 953 }
EricLew 0:80ee8f3b695e 954 else
EricLew 0:80ee8f3b695e 955 {
EricLew 0:80ee8f3b695e 956 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCMCMAC_HEADER_PHASE);
EricLew 0:80ee8f3b695e 957 }
EricLew 0:80ee8f3b695e 958
EricLew 0:80ee8f3b695e 959 /* Enable the Peripheral */
EricLew 0:80ee8f3b695e 960 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 961
EricLew 0:80ee8f3b695e 962 /* Increment/decrement instance pointer/counter */
EricLew 0:80ee8f3b695e 963 hcryp->pCrypInBuffPtr += 16;
EricLew 0:80ee8f3b695e 964 hcryp->CrypInCount -= 16;
EricLew 0:80ee8f3b695e 965
EricLew 0:80ee8f3b695e 966
EricLew 0:80ee8f3b695e 967 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 968 {
EricLew 0:80ee8f3b695e 969 if (hcryp->CrypInCount == hcryp->Init.HeaderSize)
EricLew 0:80ee8f3b695e 970 {
EricLew 0:80ee8f3b695e 971 /* All B blocks will have been entered after the next
EricLew 0:80ee8f3b695e 972 four DINR writing, so point at header buffer for
EricLew 0:80ee8f3b695e 973 the next iteration */
EricLew 0:80ee8f3b695e 974 hcryp->pCrypInBuffPtr = hcryp->Init.Header;
EricLew 0:80ee8f3b695e 975 }
EricLew 0:80ee8f3b695e 976 }
EricLew 0:80ee8f3b695e 977
EricLew 0:80ee8f3b695e 978 /* Enter header first block to initiate the process
EricLew 0:80ee8f3b695e 979 in the Data Input register */
EricLew 0:80ee8f3b695e 980 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 981 inputaddr+=4;
EricLew 0:80ee8f3b695e 982 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 983 inputaddr+=4;
EricLew 0:80ee8f3b695e 984 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 985 inputaddr+=4;
EricLew 0:80ee8f3b695e 986 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 987 }
EricLew 0:80ee8f3b695e 988 /*========================*/
EricLew 0:80ee8f3b695e 989 /* GCM/GMAC payload phase */
EricLew 0:80ee8f3b695e 990 /*========================*/
EricLew 0:80ee8f3b695e 991 else if (hcryp->Init.GCMCMACPhase == CRYP_GCM_PAYLOAD_PHASE)
EricLew 0:80ee8f3b695e 992 {
EricLew 0:80ee8f3b695e 993 /* Get the buffer addresses and sizes */
EricLew 0:80ee8f3b695e 994 hcryp->CrypInCount = Size;
EricLew 0:80ee8f3b695e 995 hcryp->pCrypInBuffPtr = pInputData;
EricLew 0:80ee8f3b695e 996 hcryp->pCrypOutBuffPtr = pOutputData;
EricLew 0:80ee8f3b695e 997 hcryp->CrypOutCount = Size;
EricLew 0:80ee8f3b695e 998
EricLew 0:80ee8f3b695e 999 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
EricLew 0:80ee8f3b695e 1000
EricLew 0:80ee8f3b695e 1001 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCM_PAYLOAD_PHASE);
EricLew 0:80ee8f3b695e 1002
EricLew 0:80ee8f3b695e 1003 /* if the header phase has been bypassed, AES must be enabled again */
EricLew 0:80ee8f3b695e 1004 if (hcryp->Phase == HAL_CRYP_PHASE_INIT_OVER)
EricLew 0:80ee8f3b695e 1005 {
EricLew 0:80ee8f3b695e 1006 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 1007 }
EricLew 0:80ee8f3b695e 1008
EricLew 0:80ee8f3b695e 1009 /* Increment/decrement instance pointer/counter */
EricLew 0:80ee8f3b695e 1010 hcryp->pCrypInBuffPtr += 16;
EricLew 0:80ee8f3b695e 1011 hcryp->CrypInCount -= 16;
EricLew 0:80ee8f3b695e 1012
EricLew 0:80ee8f3b695e 1013 /* Enter payload first block to initiate the process
EricLew 0:80ee8f3b695e 1014 in the Data Input register */
EricLew 0:80ee8f3b695e 1015 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1016 inputaddr+=4;
EricLew 0:80ee8f3b695e 1017 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1018 inputaddr+=4;
EricLew 0:80ee8f3b695e 1019 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1020 inputaddr+=4;
EricLew 0:80ee8f3b695e 1021 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1022 }
EricLew 0:80ee8f3b695e 1023 /*==============================*/
EricLew 0:80ee8f3b695e 1024 /* GCM/GMAC or CMAC final phase */
EricLew 0:80ee8f3b695e 1025 /*==============================*/
EricLew 0:80ee8f3b695e 1026 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_FINAL_PHASE)
EricLew 0:80ee8f3b695e 1027 {
EricLew 0:80ee8f3b695e 1028 hcryp->pCrypOutBuffPtr = pOutputData;
EricLew 0:80ee8f3b695e 1029
EricLew 0:80ee8f3b695e 1030 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCMCMAC_FINAL_PHASE);
EricLew 0:80ee8f3b695e 1031
EricLew 0:80ee8f3b695e 1032 /* if the header and payload phases have been bypassed, AES must be enabled again */
EricLew 0:80ee8f3b695e 1033 if (hcryp->Phase == HAL_CRYP_PHASE_INIT_OVER)
EricLew 0:80ee8f3b695e 1034 {
EricLew 0:80ee8f3b695e 1035 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 1036 }
EricLew 0:80ee8f3b695e 1037
EricLew 0:80ee8f3b695e 1038 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
EricLew 0:80ee8f3b695e 1039 {
EricLew 0:80ee8f3b695e 1040 headerlength = hcryp->Init.HeaderSize * 8; /* Header length in bits */
EricLew 0:80ee8f3b695e 1041 inputlength = Size * 8; /* input length in bits */
EricLew 0:80ee8f3b695e 1042 /* Write the number of bits in the header on 64 bits followed by the number
EricLew 0:80ee8f3b695e 1043 of bits in the payload on 64 bits as well */
EricLew 0:80ee8f3b695e 1044 if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
EricLew 0:80ee8f3b695e 1045 {
EricLew 0:80ee8f3b695e 1046 hcryp->Instance->DINR = __RBIT((headerlength)>>32);
EricLew 0:80ee8f3b695e 1047 hcryp->Instance->DINR = __RBIT(headerlength);
EricLew 0:80ee8f3b695e 1048 hcryp->Instance->DINR = __RBIT((inputlength)>>32);
EricLew 0:80ee8f3b695e 1049 hcryp->Instance->DINR = __RBIT(inputlength);
EricLew 0:80ee8f3b695e 1050 }
EricLew 0:80ee8f3b695e 1051 else if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
EricLew 0:80ee8f3b695e 1052 {
EricLew 0:80ee8f3b695e 1053 hcryp->Instance->DINR = __REV((headerlength)>>32);
EricLew 0:80ee8f3b695e 1054 hcryp->Instance->DINR = __REV(headerlength);
EricLew 0:80ee8f3b695e 1055 hcryp->Instance->DINR = __REV((inputlength)>>32);
EricLew 0:80ee8f3b695e 1056 hcryp->Instance->DINR = __REV(inputlength);
EricLew 0:80ee8f3b695e 1057 }
EricLew 0:80ee8f3b695e 1058 else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
EricLew 0:80ee8f3b695e 1059 {
EricLew 0:80ee8f3b695e 1060 hcryp->Instance->DINR = __ROR((headerlength)>>32, 16);
EricLew 0:80ee8f3b695e 1061 hcryp->Instance->DINR = __ROR(headerlength, 16);
EricLew 0:80ee8f3b695e 1062 hcryp->Instance->DINR = __ROR((inputlength)>>32, 16);
EricLew 0:80ee8f3b695e 1063 hcryp->Instance->DINR = __ROR(inputlength, 16);
EricLew 0:80ee8f3b695e 1064 }
EricLew 0:80ee8f3b695e 1065 else if(hcryp->Init.DataType == CRYP_DATATYPE_32B)
EricLew 0:80ee8f3b695e 1066 {
EricLew 0:80ee8f3b695e 1067 hcryp->Instance->DINR = (uint32_t)(headerlength>>32);
EricLew 0:80ee8f3b695e 1068 hcryp->Instance->DINR = (uint32_t)(headerlength);
EricLew 0:80ee8f3b695e 1069 hcryp->Instance->DINR = (uint32_t)(inputlength>>32);
EricLew 0:80ee8f3b695e 1070 hcryp->Instance->DINR = (uint32_t)(inputlength);
EricLew 0:80ee8f3b695e 1071 }
EricLew 0:80ee8f3b695e 1072 }
EricLew 0:80ee8f3b695e 1073 else if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 1074 {
EricLew 0:80ee8f3b695e 1075 inputaddr = (uint32_t)pInputData;
EricLew 0:80ee8f3b695e 1076 /* Enter the last block made of a 128-bit value formatted
EricLew 0:80ee8f3b695e 1077 from the original B0 packet. */
EricLew 0:80ee8f3b695e 1078 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1079 inputaddr+=4;
EricLew 0:80ee8f3b695e 1080 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1081 inputaddr+=4;
EricLew 0:80ee8f3b695e 1082 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1083 inputaddr+=4;
EricLew 0:80ee8f3b695e 1084 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1085 inputaddr+=4;
EricLew 0:80ee8f3b695e 1086 }
EricLew 0:80ee8f3b695e 1087 }
EricLew 0:80ee8f3b695e 1088 /*=================================================*/
EricLew 0:80ee8f3b695e 1089 /* case incorrect hcryp->Init.GCMCMACPhase setting */
EricLew 0:80ee8f3b695e 1090 /*=================================================*/
EricLew 0:80ee8f3b695e 1091 else
EricLew 0:80ee8f3b695e 1092 {
EricLew 0:80ee8f3b695e 1093 hcryp->State = HAL_CRYP_STATE_ERROR;
EricLew 0:80ee8f3b695e 1094 return HAL_ERROR;
EricLew 0:80ee8f3b695e 1095 }
EricLew 0:80ee8f3b695e 1096
EricLew 0:80ee8f3b695e 1097 return HAL_OK;
EricLew 0:80ee8f3b695e 1098 }
EricLew 0:80ee8f3b695e 1099 else
EricLew 0:80ee8f3b695e 1100 {
EricLew 0:80ee8f3b695e 1101 return HAL_BUSY;
EricLew 0:80ee8f3b695e 1102 }
EricLew 0:80ee8f3b695e 1103 }
EricLew 0:80ee8f3b695e 1104
EricLew 0:80ee8f3b695e 1105
EricLew 0:80ee8f3b695e 1106
EricLew 0:80ee8f3b695e 1107
EricLew 0:80ee8f3b695e 1108 /**
EricLew 0:80ee8f3b695e 1109 * @brief Carry out in DMA mode the authentication tag generation as well as the ciphering or deciphering
EricLew 0:80ee8f3b695e 1110 * operation according to hcryp->Init structure fields.
EricLew 0:80ee8f3b695e 1111 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1112 * the configuration information for CRYP module
EricLew 0:80ee8f3b695e 1113 * @param pInputData: Pointer to payload data in GCM payload phase,
EricLew 0:80ee8f3b695e 1114 * Parameter is meaningless in case of GCM/GMAC init, header and final phases,
EricLew 0:80ee8f3b695e 1115 * Pointer to B0 blocks in CMAC header phase,
EricLew 0:80ee8f3b695e 1116 * Pointer to C block in CMAC final phase.
EricLew 0:80ee8f3b695e 1117 * @param Size: Length of the input payload data buffer in bytes, must be a multiple of 16,
EricLew 0:80ee8f3b695e 1118 * Parameter is meaningless in case of GCM/GMAC init and header phases,
EricLew 0:80ee8f3b695e 1119 * Length of B blocks (in bytes, must be a multiple of 16) in CMAC header phase,
EricLew 0:80ee8f3b695e 1120 * Length of C block (in bytes) in CMAC final phase.
EricLew 0:80ee8f3b695e 1121 * @param pOutputData: Pointer to plain or cipher text in GCM payload phase,
EricLew 0:80ee8f3b695e 1122 * pointer to authentication tag in GCM/GMAC and CMAC final phases.
EricLew 0:80ee8f3b695e 1123 * Parameter is meaningless in case of GCM/GMAC init and header phases
EricLew 0:80ee8f3b695e 1124 * and in case of CMAC header phase.
EricLew 0:80ee8f3b695e 1125 * @note Supported operating modes are encryption and decryption, supported chaining modes are GCM, GMAC and CMAC.
EricLew 0:80ee8f3b695e 1126 * @note Phases are singly processed according to hcryp->Init.GCMCMACPhase so that steps in these specific chaining modes
EricLew 0:80ee8f3b695e 1127 * can be skipped by the user if so required.
EricLew 0:80ee8f3b695e 1128 * @note pInputData and pOutputData buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the IP.
EricLew 0:80ee8f3b695e 1129 * @retval HAL status
EricLew 0:80ee8f3b695e 1130 */
EricLew 0:80ee8f3b695e 1131 HAL_StatusTypeDef HAL_CRYPEx_AES_Auth_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pInputData, uint64_t Size, uint8_t *pOutputData)
EricLew 0:80ee8f3b695e 1132 {
EricLew 0:80ee8f3b695e 1133 uint32_t inputaddr = 0;
EricLew 0:80ee8f3b695e 1134 uint32_t outputaddr = 0;
EricLew 0:80ee8f3b695e 1135 uint32_t tagaddr = 0;
EricLew 0:80ee8f3b695e 1136 uint64_t headerlength = 0;
EricLew 0:80ee8f3b695e 1137 uint64_t inputlength = 0;
EricLew 0:80ee8f3b695e 1138
EricLew 0:80ee8f3b695e 1139
EricLew 0:80ee8f3b695e 1140 if (hcryp->State == HAL_CRYP_STATE_READY)
EricLew 0:80ee8f3b695e 1141 {
EricLew 0:80ee8f3b695e 1142 /* input/output parameters check */
EricLew 0:80ee8f3b695e 1143 if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_HEADER_PHASE)
EricLew 0:80ee8f3b695e 1144 {
EricLew 0:80ee8f3b695e 1145 if ((hcryp->Init.Header == NULL) || (hcryp->Init.HeaderSize == 0))
EricLew 0:80ee8f3b695e 1146 {
EricLew 0:80ee8f3b695e 1147 return HAL_ERROR;
EricLew 0:80ee8f3b695e 1148 }
EricLew 0:80ee8f3b695e 1149 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 1150 {
EricLew 0:80ee8f3b695e 1151 if ((pInputData == NULL) || (Size == 0))
EricLew 0:80ee8f3b695e 1152 {
EricLew 0:80ee8f3b695e 1153 return HAL_ERROR;
EricLew 0:80ee8f3b695e 1154 }
EricLew 0:80ee8f3b695e 1155 }
EricLew 0:80ee8f3b695e 1156 }
EricLew 0:80ee8f3b695e 1157 else if (hcryp->Init.GCMCMACPhase == CRYP_GCM_PAYLOAD_PHASE)
EricLew 0:80ee8f3b695e 1158 {
EricLew 0:80ee8f3b695e 1159 if ((pInputData == NULL) || (pOutputData == NULL) || (Size == 0))
EricLew 0:80ee8f3b695e 1160 {
EricLew 0:80ee8f3b695e 1161 return HAL_ERROR;
EricLew 0:80ee8f3b695e 1162 }
EricLew 0:80ee8f3b695e 1163 }
EricLew 0:80ee8f3b695e 1164 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_FINAL_PHASE)
EricLew 0:80ee8f3b695e 1165 {
EricLew 0:80ee8f3b695e 1166 if (pOutputData == NULL)
EricLew 0:80ee8f3b695e 1167 {
EricLew 0:80ee8f3b695e 1168 return HAL_ERROR;
EricLew 0:80ee8f3b695e 1169 }
EricLew 0:80ee8f3b695e 1170 if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC) && (pInputData == NULL))
EricLew 0:80ee8f3b695e 1171 {
EricLew 0:80ee8f3b695e 1172 return HAL_ERROR;
EricLew 0:80ee8f3b695e 1173 }
EricLew 0:80ee8f3b695e 1174 }
EricLew 0:80ee8f3b695e 1175
EricLew 0:80ee8f3b695e 1176
EricLew 0:80ee8f3b695e 1177 /* Process Locked */
EricLew 0:80ee8f3b695e 1178 __HAL_LOCK(hcryp);
EricLew 0:80ee8f3b695e 1179
EricLew 0:80ee8f3b695e 1180 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 1181 hcryp->State = HAL_CRYP_STATE_BUSY;
EricLew 0:80ee8f3b695e 1182
EricLew 0:80ee8f3b695e 1183 /*=====================*/
EricLew 0:80ee8f3b695e 1184 /* GCM/GMAC init phase */
EricLew 0:80ee8f3b695e 1185 /*=====================*/
EricLew 0:80ee8f3b695e 1186 /* In case of init phase, the input data (Key and Initialization Vector) have
EricLew 0:80ee8f3b695e 1187 already been entered during the initialization process. No DMA transfer is
EricLew 0:80ee8f3b695e 1188 required at that point therefore, the software just waits for the CCF flag
EricLew 0:80ee8f3b695e 1189 to be raised. */
EricLew 0:80ee8f3b695e 1190 if (hcryp->Init.GCMCMACPhase == CRYP_GCM_INIT_PHASE)
EricLew 0:80ee8f3b695e 1191 {
EricLew 0:80ee8f3b695e 1192 /* just wait for hash computation */
EricLew 0:80ee8f3b695e 1193 if(CRYP_WaitOnCCFlag(hcryp, CRYP_CCF_TIMEOUTVALUE) != HAL_OK)
EricLew 0:80ee8f3b695e 1194 {
EricLew 0:80ee8f3b695e 1195 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1196 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1197 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 1198 }
EricLew 0:80ee8f3b695e 1199
EricLew 0:80ee8f3b695e 1200 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 1201 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1202 /* Mark that the initialization phase is over */
EricLew 0:80ee8f3b695e 1203 hcryp->Phase = HAL_CRYP_PHASE_INIT_OVER;
EricLew 0:80ee8f3b695e 1204 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1205 }
EricLew 0:80ee8f3b695e 1206 /*===============================*/
EricLew 0:80ee8f3b695e 1207 /* GCM/GMAC or CMAC header phase */
EricLew 0:80ee8f3b695e 1208 /*===============================*/
EricLew 0:80ee8f3b695e 1209 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_HEADER_PHASE)
EricLew 0:80ee8f3b695e 1210 {
EricLew 0:80ee8f3b695e 1211 /* Set header phase; for GCM or GMAC, set data-byte at this point */
EricLew 0:80ee8f3b695e 1212 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
EricLew 0:80ee8f3b695e 1213 {
EricLew 0:80ee8f3b695e 1214 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH|AES_CR_DATATYPE, CRYP_GCMCMAC_HEADER_PHASE|hcryp->Init.DataType);
EricLew 0:80ee8f3b695e 1215 }
EricLew 0:80ee8f3b695e 1216 else
EricLew 0:80ee8f3b695e 1217 {
EricLew 0:80ee8f3b695e 1218 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCMCMAC_HEADER_PHASE);
EricLew 0:80ee8f3b695e 1219 }
EricLew 0:80ee8f3b695e 1220
EricLew 0:80ee8f3b695e 1221 /* enter first B0 block in polling mode (no DMA transfer for B0) */
EricLew 0:80ee8f3b695e 1222 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 1223 {
EricLew 0:80ee8f3b695e 1224 /* Enable the CRYP peripheral */
EricLew 0:80ee8f3b695e 1225 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 1226
EricLew 0:80ee8f3b695e 1227 inputaddr = (uint32_t)pInputData;
EricLew 0:80ee8f3b695e 1228 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1229 inputaddr+=4;
EricLew 0:80ee8f3b695e 1230 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1231 inputaddr+=4;
EricLew 0:80ee8f3b695e 1232 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1233 inputaddr+=4;
EricLew 0:80ee8f3b695e 1234 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1235
EricLew 0:80ee8f3b695e 1236 if(CRYP_WaitOnCCFlag(hcryp, CRYP_CCF_TIMEOUTVALUE) != HAL_OK)
EricLew 0:80ee8f3b695e 1237 {
EricLew 0:80ee8f3b695e 1238 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1239 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1240 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 1241 }
EricLew 0:80ee8f3b695e 1242 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 1243 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1244 }
EricLew 0:80ee8f3b695e 1245
EricLew 0:80ee8f3b695e 1246
EricLew 0:80ee8f3b695e 1247 inputaddr = (uint32_t)hcryp->Init.Header;
EricLew 0:80ee8f3b695e 1248 /* Set the input address and start DMA transfer */
EricLew 0:80ee8f3b695e 1249 CRYP_GCMCMAC_SetDMAConfig(hcryp, inputaddr, hcryp->Init.HeaderSize, 0);
EricLew 0:80ee8f3b695e 1250 }
EricLew 0:80ee8f3b695e 1251 /*========================*/
EricLew 0:80ee8f3b695e 1252 /* GCM/GMAC payload phase */
EricLew 0:80ee8f3b695e 1253 /*========================*/
EricLew 0:80ee8f3b695e 1254 else if (hcryp->Init.GCMCMACPhase == CRYP_GCM_PAYLOAD_PHASE)
EricLew 0:80ee8f3b695e 1255 {
EricLew 0:80ee8f3b695e 1256 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCM_PAYLOAD_PHASE);
EricLew 0:80ee8f3b695e 1257
EricLew 0:80ee8f3b695e 1258 inputaddr = (uint32_t)pInputData;
EricLew 0:80ee8f3b695e 1259 outputaddr = (uint32_t)pOutputData;
EricLew 0:80ee8f3b695e 1260 /* Set the input and output addresses and start DMA transfer */
EricLew 0:80ee8f3b695e 1261 CRYP_GCMCMAC_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
EricLew 0:80ee8f3b695e 1262 }
EricLew 0:80ee8f3b695e 1263 /*==============================*/
EricLew 0:80ee8f3b695e 1264 /* GCM/GMAC or CMAC final phase */
EricLew 0:80ee8f3b695e 1265 /*==============================*/
EricLew 0:80ee8f3b695e 1266 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_FINAL_PHASE)
EricLew 0:80ee8f3b695e 1267 {
EricLew 0:80ee8f3b695e 1268 tagaddr = (uint32_t)pOutputData;
EricLew 0:80ee8f3b695e 1269
EricLew 0:80ee8f3b695e 1270 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_GCMCMAC_FINAL_PHASE);
EricLew 0:80ee8f3b695e 1271
EricLew 0:80ee8f3b695e 1272 /* if the header and payload phases have been bypassed, AES must be enabled again */
EricLew 0:80ee8f3b695e 1273 if (hcryp->Phase == HAL_CRYP_PHASE_INIT_OVER)
EricLew 0:80ee8f3b695e 1274 {
EricLew 0:80ee8f3b695e 1275 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 1276 }
EricLew 0:80ee8f3b695e 1277
EricLew 0:80ee8f3b695e 1278 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
EricLew 0:80ee8f3b695e 1279 {
EricLew 0:80ee8f3b695e 1280 headerlength = hcryp->Init.HeaderSize * 8; /* Header length in bits */
EricLew 0:80ee8f3b695e 1281 inputlength = Size * 8; /* input length in bits */
EricLew 0:80ee8f3b695e 1282 /* Write the number of bits in the header on 64 bits followed by the number
EricLew 0:80ee8f3b695e 1283 of bits in the payload on 64 bits as well */
EricLew 0:80ee8f3b695e 1284 if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
EricLew 0:80ee8f3b695e 1285 {
EricLew 0:80ee8f3b695e 1286 hcryp->Instance->DINR = __RBIT((headerlength)>>32);
EricLew 0:80ee8f3b695e 1287 hcryp->Instance->DINR = __RBIT(headerlength);
EricLew 0:80ee8f3b695e 1288 hcryp->Instance->DINR = __RBIT((inputlength)>>32);
EricLew 0:80ee8f3b695e 1289 hcryp->Instance->DINR = __RBIT(inputlength);
EricLew 0:80ee8f3b695e 1290 }
EricLew 0:80ee8f3b695e 1291 else if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
EricLew 0:80ee8f3b695e 1292 {
EricLew 0:80ee8f3b695e 1293 hcryp->Instance->DINR = __REV((headerlength)>>32);
EricLew 0:80ee8f3b695e 1294 hcryp->Instance->DINR = __REV(headerlength);
EricLew 0:80ee8f3b695e 1295 hcryp->Instance->DINR = __REV((inputlength)>>32);
EricLew 0:80ee8f3b695e 1296 hcryp->Instance->DINR = __REV(inputlength);
EricLew 0:80ee8f3b695e 1297 }
EricLew 0:80ee8f3b695e 1298 else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
EricLew 0:80ee8f3b695e 1299 {
EricLew 0:80ee8f3b695e 1300 hcryp->Instance->DINR = __ROR((headerlength)>>32, 16);
EricLew 0:80ee8f3b695e 1301 hcryp->Instance->DINR = __ROR(headerlength, 16);
EricLew 0:80ee8f3b695e 1302 hcryp->Instance->DINR = __ROR((inputlength)>>32, 16);
EricLew 0:80ee8f3b695e 1303 hcryp->Instance->DINR = __ROR(inputlength, 16);
EricLew 0:80ee8f3b695e 1304 }
EricLew 0:80ee8f3b695e 1305 else if(hcryp->Init.DataType == CRYP_DATATYPE_32B)
EricLew 0:80ee8f3b695e 1306 {
EricLew 0:80ee8f3b695e 1307 hcryp->Instance->DINR = (uint32_t)(headerlength>>32);
EricLew 0:80ee8f3b695e 1308 hcryp->Instance->DINR = (uint32_t)(headerlength);
EricLew 0:80ee8f3b695e 1309 hcryp->Instance->DINR = (uint32_t)(inputlength>>32);
EricLew 0:80ee8f3b695e 1310 hcryp->Instance->DINR = (uint32_t)(inputlength);
EricLew 0:80ee8f3b695e 1311 }
EricLew 0:80ee8f3b695e 1312 }
EricLew 0:80ee8f3b695e 1313 else if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 1314 {
EricLew 0:80ee8f3b695e 1315 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1316
EricLew 0:80ee8f3b695e 1317 inputaddr = (uint32_t)pInputData;
EricLew 0:80ee8f3b695e 1318 /* Enter the last block made of a 128-bit value formatted
EricLew 0:80ee8f3b695e 1319 from the original B0 packet. */
EricLew 0:80ee8f3b695e 1320 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1321 inputaddr+=4;
EricLew 0:80ee8f3b695e 1322 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1323 inputaddr+=4;
EricLew 0:80ee8f3b695e 1324 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1325 inputaddr+=4;
EricLew 0:80ee8f3b695e 1326 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1327 inputaddr+=4;
EricLew 0:80ee8f3b695e 1328 }
EricLew 0:80ee8f3b695e 1329
EricLew 0:80ee8f3b695e 1330 /* No DMA transfer is required at that point therefore, the software
EricLew 0:80ee8f3b695e 1331 just waits for the CCF flag to be raised. */
EricLew 0:80ee8f3b695e 1332 if(CRYP_WaitOnCCFlag(hcryp, CRYP_CCF_TIMEOUTVALUE) != HAL_OK)
EricLew 0:80ee8f3b695e 1333 {
EricLew 0:80ee8f3b695e 1334 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1335 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1336 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 1337 }
EricLew 0:80ee8f3b695e 1338 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 1339 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1340 /* Read the Auth TAG in the IN FIFO */
EricLew 0:80ee8f3b695e 1341 *(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1342 tagaddr+=4;
EricLew 0:80ee8f3b695e 1343 *(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1344 tagaddr+=4;
EricLew 0:80ee8f3b695e 1345 *(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1346 tagaddr+=4;
EricLew 0:80ee8f3b695e 1347 *(uint32_t*)(tagaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1348
EricLew 0:80ee8f3b695e 1349 /* Mark that the final phase is over */
EricLew 0:80ee8f3b695e 1350 hcryp->Phase = HAL_CRYP_PHASE_FINAL_OVER;
EricLew 0:80ee8f3b695e 1351 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1352 /* Disable the Peripheral */
EricLew 0:80ee8f3b695e 1353 __HAL_CRYP_DISABLE();
EricLew 0:80ee8f3b695e 1354 }
EricLew 0:80ee8f3b695e 1355 /*=================================================*/
EricLew 0:80ee8f3b695e 1356 /* case incorrect hcryp->Init.GCMCMACPhase setting */
EricLew 0:80ee8f3b695e 1357 /*=================================================*/
EricLew 0:80ee8f3b695e 1358 else
EricLew 0:80ee8f3b695e 1359 {
EricLew 0:80ee8f3b695e 1360 hcryp->State = HAL_CRYP_STATE_ERROR;
EricLew 0:80ee8f3b695e 1361 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1362 return HAL_ERROR;
EricLew 0:80ee8f3b695e 1363 }
EricLew 0:80ee8f3b695e 1364
EricLew 0:80ee8f3b695e 1365 /* Process Unlocked */
EricLew 0:80ee8f3b695e 1366 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1367
EricLew 0:80ee8f3b695e 1368 return HAL_OK;
EricLew 0:80ee8f3b695e 1369 }
EricLew 0:80ee8f3b695e 1370 else
EricLew 0:80ee8f3b695e 1371 {
EricLew 0:80ee8f3b695e 1372 return HAL_BUSY;
EricLew 0:80ee8f3b695e 1373 }
EricLew 0:80ee8f3b695e 1374 }
EricLew 0:80ee8f3b695e 1375
EricLew 0:80ee8f3b695e 1376 /**
EricLew 0:80ee8f3b695e 1377 * @}
EricLew 0:80ee8f3b695e 1378 */
EricLew 0:80ee8f3b695e 1379
EricLew 0:80ee8f3b695e 1380 /** @defgroup CRYPEx_Exported_Functions_Group3 AES suspension/resumption functions
EricLew 0:80ee8f3b695e 1381 * @brief Extended processing functions.
EricLew 0:80ee8f3b695e 1382 *
EricLew 0:80ee8f3b695e 1383 @verbatim
EricLew 0:80ee8f3b695e 1384 ==============================================================================
EricLew 0:80ee8f3b695e 1385 ##### AES extended suspension and resumption functions #####
EricLew 0:80ee8f3b695e 1386 ==============================================================================
EricLew 0:80ee8f3b695e 1387 [..] This section provides functions allowing to:
EricLew 0:80ee8f3b695e 1388 (+) save in memory the Initialization Vector, the Key registers, the Control register or
EricLew 0:80ee8f3b695e 1389 the Suspend registers when a process is suspended by a higher priority message
EricLew 0:80ee8f3b695e 1390 (+) write back in CRYP hardware block the saved values listed above when the suspended
EricLew 0:80ee8f3b695e 1391 lower priority message processing is resumed.
EricLew 0:80ee8f3b695e 1392
EricLew 0:80ee8f3b695e 1393 @endverbatim
EricLew 0:80ee8f3b695e 1394 * @{
EricLew 0:80ee8f3b695e 1395 */
EricLew 0:80ee8f3b695e 1396
EricLew 0:80ee8f3b695e 1397
EricLew 0:80ee8f3b695e 1398 /**
EricLew 0:80ee8f3b695e 1399 * @brief In case of message processing suspension, read the Initialization Vector.
EricLew 0:80ee8f3b695e 1400 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1401 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1402 * @param Output: Pointer to the buffer containing the saved Initialization Vector.
EricLew 0:80ee8f3b695e 1403 * @note This value has to be stored for reuse by writing the AES_IVRx registers
EricLew 0:80ee8f3b695e 1404 * as soon as the interrupted processing has to be resumed.
EricLew 0:80ee8f3b695e 1405 * Applicable to all chaining modes.
EricLew 0:80ee8f3b695e 1406 * @note AES must be disabled when reading or resetting the IV values.
EricLew 0:80ee8f3b695e 1407 * @retval None
EricLew 0:80ee8f3b695e 1408 */
EricLew 0:80ee8f3b695e 1409 void HAL_CRYPEx_Read_IVRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output)
EricLew 0:80ee8f3b695e 1410 {
EricLew 0:80ee8f3b695e 1411 uint32_t outputaddr = (uint32_t)Output;
EricLew 0:80ee8f3b695e 1412
EricLew 0:80ee8f3b695e 1413 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->IVR3);
EricLew 0:80ee8f3b695e 1414 outputaddr+=4;
EricLew 0:80ee8f3b695e 1415 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->IVR2);
EricLew 0:80ee8f3b695e 1416 outputaddr+=4;
EricLew 0:80ee8f3b695e 1417 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->IVR1);
EricLew 0:80ee8f3b695e 1418 outputaddr+=4;
EricLew 0:80ee8f3b695e 1419 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->IVR0);
EricLew 0:80ee8f3b695e 1420 }
EricLew 0:80ee8f3b695e 1421
EricLew 0:80ee8f3b695e 1422 /**
EricLew 0:80ee8f3b695e 1423 * @brief In case of message processing resumption, rewrite the Initialization
EricLew 0:80ee8f3b695e 1424 * Vector in the AES_IVRx registers.
EricLew 0:80ee8f3b695e 1425 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1426 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1427 * @param Input: Pointer to the buffer containing the saved Initialization Vector to
EricLew 0:80ee8f3b695e 1428 * write back in the CRYP hardware block.
EricLew 0:80ee8f3b695e 1429 * @note Applicable to all chaining modes.
EricLew 0:80ee8f3b695e 1430 * @note AES must be disabled when reading or resetting the IV values.
EricLew 0:80ee8f3b695e 1431 * @retval None
EricLew 0:80ee8f3b695e 1432 */
EricLew 0:80ee8f3b695e 1433 void HAL_CRYPEx_Write_IVRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input)
EricLew 0:80ee8f3b695e 1434 {
EricLew 0:80ee8f3b695e 1435 uint32_t ivaddr = (uint32_t)Input;
EricLew 0:80ee8f3b695e 1436
EricLew 0:80ee8f3b695e 1437 hcryp->Instance->IVR3 = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1438 ivaddr+=4;
EricLew 0:80ee8f3b695e 1439 hcryp->Instance->IVR2 = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1440 ivaddr+=4;
EricLew 0:80ee8f3b695e 1441 hcryp->Instance->IVR1 = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1442 ivaddr+=4;
EricLew 0:80ee8f3b695e 1443 hcryp->Instance->IVR0 = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1444 }
EricLew 0:80ee8f3b695e 1445
EricLew 0:80ee8f3b695e 1446
EricLew 0:80ee8f3b695e 1447 /**
EricLew 0:80ee8f3b695e 1448 * @brief In case of message GCM/GMAC or CMAC processing suspension, read the Suspend Registers.
EricLew 0:80ee8f3b695e 1449 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1450 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1451 * @param Output: Pointer to the buffer containing the saved Suspend Registers.
EricLew 0:80ee8f3b695e 1452 * @note These values have to be stored for reuse by writing back the AES_SUSPxR registers
EricLew 0:80ee8f3b695e 1453 * as soon as the interrupted processing has to be resumed.
EricLew 0:80ee8f3b695e 1454 * @retval None
EricLew 0:80ee8f3b695e 1455 */
EricLew 0:80ee8f3b695e 1456 void HAL_CRYPEx_Read_SuspendRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output)
EricLew 0:80ee8f3b695e 1457 {
EricLew 0:80ee8f3b695e 1458 uint32_t outputaddr = (uint32_t)Output;
EricLew 0:80ee8f3b695e 1459
EricLew 0:80ee8f3b695e 1460 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP7R);
EricLew 0:80ee8f3b695e 1461 outputaddr+=4;
EricLew 0:80ee8f3b695e 1462 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP6R);
EricLew 0:80ee8f3b695e 1463 outputaddr+=4;
EricLew 0:80ee8f3b695e 1464 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP5R);
EricLew 0:80ee8f3b695e 1465 outputaddr+=4;
EricLew 0:80ee8f3b695e 1466 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP4R);
EricLew 0:80ee8f3b695e 1467 outputaddr+=4;
EricLew 0:80ee8f3b695e 1468 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP3R);
EricLew 0:80ee8f3b695e 1469 outputaddr+=4;
EricLew 0:80ee8f3b695e 1470 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP2R);
EricLew 0:80ee8f3b695e 1471 outputaddr+=4;
EricLew 0:80ee8f3b695e 1472 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP1R);
EricLew 0:80ee8f3b695e 1473 outputaddr+=4;
EricLew 0:80ee8f3b695e 1474 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->SUSP0R);
EricLew 0:80ee8f3b695e 1475 }
EricLew 0:80ee8f3b695e 1476
EricLew 0:80ee8f3b695e 1477 /**
EricLew 0:80ee8f3b695e 1478 * @brief In case of message GCM/GMAC or CMAC processing resumption, rewrite the Suspend
EricLew 0:80ee8f3b695e 1479 * Registers in the AES_SUSPxR registers.
EricLew 0:80ee8f3b695e 1480 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1481 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1482 * @param Input: Pointer to the buffer containing the saved suspend registers to
EricLew 0:80ee8f3b695e 1483 * write back in the CRYP hardware block.
EricLew 0:80ee8f3b695e 1484 * @retval None
EricLew 0:80ee8f3b695e 1485 */
EricLew 0:80ee8f3b695e 1486 void HAL_CRYPEx_Write_SuspendRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input)
EricLew 0:80ee8f3b695e 1487 {
EricLew 0:80ee8f3b695e 1488 uint32_t ivaddr = (uint32_t)Input;
EricLew 0:80ee8f3b695e 1489
EricLew 0:80ee8f3b695e 1490 hcryp->Instance->SUSP7R = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1491 ivaddr+=4;
EricLew 0:80ee8f3b695e 1492 hcryp->Instance->SUSP6R = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1493 ivaddr+=4;
EricLew 0:80ee8f3b695e 1494 hcryp->Instance->SUSP5R = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1495 ivaddr+=4;
EricLew 0:80ee8f3b695e 1496 hcryp->Instance->SUSP4R = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1497 ivaddr+=4;
EricLew 0:80ee8f3b695e 1498 hcryp->Instance->SUSP3R = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1499 ivaddr+=4;
EricLew 0:80ee8f3b695e 1500 hcryp->Instance->SUSP2R = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1501 ivaddr+=4;
EricLew 0:80ee8f3b695e 1502 hcryp->Instance->SUSP1R = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1503 ivaddr+=4;
EricLew 0:80ee8f3b695e 1504 hcryp->Instance->SUSP0R = __REV(*(uint32_t*)(ivaddr));
EricLew 0:80ee8f3b695e 1505 }
EricLew 0:80ee8f3b695e 1506
EricLew 0:80ee8f3b695e 1507
EricLew 0:80ee8f3b695e 1508 /**
EricLew 0:80ee8f3b695e 1509 * @brief In case of message GCM/GMAC or CMAC processing suspension, read the Key Registers.
EricLew 0:80ee8f3b695e 1510 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1511 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1512 * @param Output: Pointer to the buffer containing the saved Key Registers.
EricLew 0:80ee8f3b695e 1513 * @param KeySize: Indicates the key size (128 or 256 bits).
EricLew 0:80ee8f3b695e 1514 * @note These values have to be stored for reuse by writing back the AES_KEYRx registers
EricLew 0:80ee8f3b695e 1515 * as soon as the interrupted processing has to be resumed.
EricLew 0:80ee8f3b695e 1516 * @retval None
EricLew 0:80ee8f3b695e 1517 */
EricLew 0:80ee8f3b695e 1518 void HAL_CRYPEx_Read_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Output, uint32_t KeySize)
EricLew 0:80ee8f3b695e 1519 {
EricLew 0:80ee8f3b695e 1520 uint32_t keyaddr = (uint32_t)Output;
EricLew 0:80ee8f3b695e 1521
EricLew 0:80ee8f3b695e 1522 if (KeySize == CRYP_KEYSIZE_256B)
EricLew 0:80ee8f3b695e 1523 {
EricLew 0:80ee8f3b695e 1524 *(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR7);
EricLew 0:80ee8f3b695e 1525 keyaddr+=4;
EricLew 0:80ee8f3b695e 1526 *(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR6);
EricLew 0:80ee8f3b695e 1527 keyaddr+=4;
EricLew 0:80ee8f3b695e 1528 *(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR5);
EricLew 0:80ee8f3b695e 1529 keyaddr+=4;
EricLew 0:80ee8f3b695e 1530 *(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR4);
EricLew 0:80ee8f3b695e 1531 keyaddr+=4;
EricLew 0:80ee8f3b695e 1532 }
EricLew 0:80ee8f3b695e 1533
EricLew 0:80ee8f3b695e 1534 *(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR3);
EricLew 0:80ee8f3b695e 1535 keyaddr+=4;
EricLew 0:80ee8f3b695e 1536 *(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR2);
EricLew 0:80ee8f3b695e 1537 keyaddr+=4;
EricLew 0:80ee8f3b695e 1538 *(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR1);
EricLew 0:80ee8f3b695e 1539 keyaddr+=4;
EricLew 0:80ee8f3b695e 1540 *(uint32_t*)(keyaddr) = __REV(hcryp->Instance->KEYR0);
EricLew 0:80ee8f3b695e 1541 }
EricLew 0:80ee8f3b695e 1542
EricLew 0:80ee8f3b695e 1543 /**
EricLew 0:80ee8f3b695e 1544 * @brief In case of message GCM/GMAC or CMAC processing resumption, rewrite the Key
EricLew 0:80ee8f3b695e 1545 * Registers in the AES_KEYRx registers.
EricLew 0:80ee8f3b695e 1546 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1547 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1548 * @param Input: Pointer to the buffer containing the saved key registers to
EricLew 0:80ee8f3b695e 1549 * write back in the CRYP hardware block.
EricLew 0:80ee8f3b695e 1550 * @param KeySize: Indicates the key size (128 or 256 bits)
EricLew 0:80ee8f3b695e 1551 * @retval None
EricLew 0:80ee8f3b695e 1552 */
EricLew 0:80ee8f3b695e 1553 void HAL_CRYPEx_Write_KeyRegisters(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint32_t KeySize)
EricLew 0:80ee8f3b695e 1554 {
EricLew 0:80ee8f3b695e 1555 uint32_t keyaddr = (uint32_t)Input;
EricLew 0:80ee8f3b695e 1556
EricLew 0:80ee8f3b695e 1557 if (KeySize == CRYP_KEYSIZE_256B)
EricLew 0:80ee8f3b695e 1558 {
EricLew 0:80ee8f3b695e 1559 hcryp->Instance->KEYR7 = __REV(*(uint32_t*)(keyaddr));
EricLew 0:80ee8f3b695e 1560 keyaddr+=4;
EricLew 0:80ee8f3b695e 1561 hcryp->Instance->KEYR6 = __REV(*(uint32_t*)(keyaddr));
EricLew 0:80ee8f3b695e 1562 keyaddr+=4;
EricLew 0:80ee8f3b695e 1563 hcryp->Instance->KEYR5 = __REV(*(uint32_t*)(keyaddr));
EricLew 0:80ee8f3b695e 1564 keyaddr+=4;
EricLew 0:80ee8f3b695e 1565 hcryp->Instance->KEYR4 = __REV(*(uint32_t*)(keyaddr));
EricLew 0:80ee8f3b695e 1566 keyaddr+=4;
EricLew 0:80ee8f3b695e 1567 }
EricLew 0:80ee8f3b695e 1568
EricLew 0:80ee8f3b695e 1569 hcryp->Instance->KEYR3 = __REV(*(uint32_t*)(keyaddr));
EricLew 0:80ee8f3b695e 1570 keyaddr+=4;
EricLew 0:80ee8f3b695e 1571 hcryp->Instance->KEYR2 = __REV(*(uint32_t*)(keyaddr));
EricLew 0:80ee8f3b695e 1572 keyaddr+=4;
EricLew 0:80ee8f3b695e 1573 hcryp->Instance->KEYR1 = __REV(*(uint32_t*)(keyaddr));
EricLew 0:80ee8f3b695e 1574 keyaddr+=4;
EricLew 0:80ee8f3b695e 1575 hcryp->Instance->KEYR0 = __REV(*(uint32_t*)(keyaddr));
EricLew 0:80ee8f3b695e 1576 }
EricLew 0:80ee8f3b695e 1577
EricLew 0:80ee8f3b695e 1578
EricLew 0:80ee8f3b695e 1579 /**
EricLew 0:80ee8f3b695e 1580 * @brief In case of message GCM/GMAC or CMAC processing suspension, read the Control Register.
EricLew 0:80ee8f3b695e 1581 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1582 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1583 * @param Output: Pointer to the buffer containing the saved Control Register.
EricLew 0:80ee8f3b695e 1584 * @note This values has to be stored for reuse by writing back the AES_CR register
EricLew 0:80ee8f3b695e 1585 * as soon as the interrupted processing has to be resumed.
EricLew 0:80ee8f3b695e 1586 * @retval None
EricLew 0:80ee8f3b695e 1587 */
EricLew 0:80ee8f3b695e 1588 void HAL_CRYPEx_Read_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Output)
EricLew 0:80ee8f3b695e 1589 {
EricLew 0:80ee8f3b695e 1590 *(uint32_t*)(Output) = hcryp->Instance->CR;
EricLew 0:80ee8f3b695e 1591 }
EricLew 0:80ee8f3b695e 1592
EricLew 0:80ee8f3b695e 1593 /**
EricLew 0:80ee8f3b695e 1594 * @brief In case of message GCM/GMAC or CMAC processing resumption, rewrite the Control
EricLew 0:80ee8f3b695e 1595 * Registers in the AES_CR register.
EricLew 0:80ee8f3b695e 1596 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1597 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1598 * @param Input: Pointer to the buffer containing the saved Control Register to
EricLew 0:80ee8f3b695e 1599 * write back in the CRYP hardware block.
EricLew 0:80ee8f3b695e 1600 * @retval None
EricLew 0:80ee8f3b695e 1601 */
EricLew 0:80ee8f3b695e 1602 void HAL_CRYPEx_Write_ControlRegister(CRYP_HandleTypeDef *hcryp, uint8_t* Input)
EricLew 0:80ee8f3b695e 1603 {
EricLew 0:80ee8f3b695e 1604 hcryp->Instance->CR = *(uint32_t*)(Input);
EricLew 0:80ee8f3b695e 1605 }
EricLew 0:80ee8f3b695e 1606
EricLew 0:80ee8f3b695e 1607 /**
EricLew 0:80ee8f3b695e 1608 * @brief Request CRYP processing suspension when in polling or interruption mode.
EricLew 0:80ee8f3b695e 1609 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1610 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1611 * @note Set the handle field SuspendRequest to the appropriate value so that
EricLew 0:80ee8f3b695e 1612 * the on-going CRYP processing is suspended as soon as the required
EricLew 0:80ee8f3b695e 1613 * conditions are met.
EricLew 0:80ee8f3b695e 1614 * @note It is advised not to suspend the CRYP processing when the DMA controller
EricLew 0:80ee8f3b695e 1615 * is managing the data transfer
EricLew 0:80ee8f3b695e 1616 * @retval None
EricLew 0:80ee8f3b695e 1617 */
EricLew 0:80ee8f3b695e 1618 void HAL_CRYPEx_ProcessSuspend(CRYP_HandleTypeDef *hcryp)
EricLew 0:80ee8f3b695e 1619 {
EricLew 0:80ee8f3b695e 1620 /* Set Handle Suspend Request field */
EricLew 0:80ee8f3b695e 1621 hcryp->SuspendRequest = HAL_CRYP_SUSPEND;
EricLew 0:80ee8f3b695e 1622 }
EricLew 0:80ee8f3b695e 1623
EricLew 0:80ee8f3b695e 1624 /**
EricLew 0:80ee8f3b695e 1625 * @}
EricLew 0:80ee8f3b695e 1626 */
EricLew 0:80ee8f3b695e 1627
EricLew 0:80ee8f3b695e 1628 /**
EricLew 0:80ee8f3b695e 1629 * @}
EricLew 0:80ee8f3b695e 1630 */
EricLew 0:80ee8f3b695e 1631
EricLew 0:80ee8f3b695e 1632 /** @addtogroup CRYPEx_Private_Functions
EricLew 0:80ee8f3b695e 1633 * @{
EricLew 0:80ee8f3b695e 1634 */
EricLew 0:80ee8f3b695e 1635
EricLew 0:80ee8f3b695e 1636 /**
EricLew 0:80ee8f3b695e 1637 * @brief DMA CRYP Input Data process complete callback
EricLew 0:80ee8f3b695e 1638 * for GCM, GMAC or CMAC chainging modes.
EricLew 0:80ee8f3b695e 1639 * @note Specific setting of hcryp fields are required only
EricLew 0:80ee8f3b695e 1640 * in the case of header phase where no output data DMA
EricLew 0:80ee8f3b695e 1641 * transfer is on-going (only input data transfer is enabled
EricLew 0:80ee8f3b695e 1642 * in such a case).
EricLew 0:80ee8f3b695e 1643 * @param hdma: DMA handle.
EricLew 0:80ee8f3b695e 1644 * @retval None
EricLew 0:80ee8f3b695e 1645 */
EricLew 0:80ee8f3b695e 1646 static void CRYP_GCMCMAC_DMAInCplt(DMA_HandleTypeDef *hdma)
EricLew 0:80ee8f3b695e 1647 {
EricLew 0:80ee8f3b695e 1648 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
EricLew 0:80ee8f3b695e 1649
EricLew 0:80ee8f3b695e 1650 /* Disable the DMA transfer for input request */
EricLew 0:80ee8f3b695e 1651 CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
EricLew 0:80ee8f3b695e 1652
EricLew 0:80ee8f3b695e 1653 if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_HEADER_PHASE)
EricLew 0:80ee8f3b695e 1654 {
EricLew 0:80ee8f3b695e 1655 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 1656 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1657 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 1658 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1659
EricLew 0:80ee8f3b695e 1660 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 1661 hcryp->Phase = HAL_CRYP_PHASE_HEADER_OVER;
EricLew 0:80ee8f3b695e 1662 }
EricLew 0:80ee8f3b695e 1663
EricLew 0:80ee8f3b695e 1664 /* Call input data transfer complete callback */
EricLew 0:80ee8f3b695e 1665 HAL_CRYP_InCpltCallback(hcryp);
EricLew 0:80ee8f3b695e 1666 }
EricLew 0:80ee8f3b695e 1667
EricLew 0:80ee8f3b695e 1668 /**
EricLew 0:80ee8f3b695e 1669 * @brief DMA CRYP Output Data process complete callback
EricLew 0:80ee8f3b695e 1670 * for GCM, GMAC or CMAC chainging modes.
EricLew 0:80ee8f3b695e 1671 * @note This callback is called only in the payload phase.
EricLew 0:80ee8f3b695e 1672 * @param hdma: DMA handle.
EricLew 0:80ee8f3b695e 1673 * @retval None
EricLew 0:80ee8f3b695e 1674 */
EricLew 0:80ee8f3b695e 1675 static void CRYP_GCMCMAC_DMAOutCplt(DMA_HandleTypeDef *hdma)
EricLew 0:80ee8f3b695e 1676 {
EricLew 0:80ee8f3b695e 1677 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
EricLew 0:80ee8f3b695e 1678
EricLew 0:80ee8f3b695e 1679 /* Disable the DMA transfer for output request */
EricLew 0:80ee8f3b695e 1680 CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
EricLew 0:80ee8f3b695e 1681
EricLew 0:80ee8f3b695e 1682 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 1683 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1684
EricLew 0:80ee8f3b695e 1685 /* Change the CRYP state to ready */
EricLew 0:80ee8f3b695e 1686 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1687 /* Mark that the payload phase is over */
EricLew 0:80ee8f3b695e 1688 hcryp->Phase = HAL_CRYP_PHASE_PAYLOAD_OVER;
EricLew 0:80ee8f3b695e 1689
EricLew 0:80ee8f3b695e 1690 /* Call output data transfer complete callback */
EricLew 0:80ee8f3b695e 1691 HAL_CRYP_OutCpltCallback(hcryp);
EricLew 0:80ee8f3b695e 1692 }
EricLew 0:80ee8f3b695e 1693
EricLew 0:80ee8f3b695e 1694 /**
EricLew 0:80ee8f3b695e 1695 * @brief DMA CRYP communication error callback
EricLew 0:80ee8f3b695e 1696 * for GCM, GMAC or CMAC chainging modes.
EricLew 0:80ee8f3b695e 1697 * @param hdma: DMA handle
EricLew 0:80ee8f3b695e 1698 * @retval None
EricLew 0:80ee8f3b695e 1699 */
EricLew 0:80ee8f3b695e 1700 static void CRYP_GCMCMAC_DMAError(DMA_HandleTypeDef *hdma)
EricLew 0:80ee8f3b695e 1701 {
EricLew 0:80ee8f3b695e 1702 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
EricLew 0:80ee8f3b695e 1703
EricLew 0:80ee8f3b695e 1704 hcryp->State= HAL_CRYP_STATE_ERROR;
EricLew 0:80ee8f3b695e 1705 hcryp->ErrorCode |= HAL_CRYP_DMA_ERROR;
EricLew 0:80ee8f3b695e 1706 HAL_CRYP_ErrorCallback(hcryp);
EricLew 0:80ee8f3b695e 1707 /* Clear Error Flag */
EricLew 0:80ee8f3b695e 1708 __HAL_CRYP_CLEAR_FLAG(CRYP_ERR_CLEAR);
EricLew 0:80ee8f3b695e 1709 }
EricLew 0:80ee8f3b695e 1710
EricLew 0:80ee8f3b695e 1711
EricLew 0:80ee8f3b695e 1712
EricLew 0:80ee8f3b695e 1713 /**
EricLew 0:80ee8f3b695e 1714 * @brief Handle CRYP block input/output data handling under interruption
EricLew 0:80ee8f3b695e 1715 * for GCM, GMAC or CMAC chainging modes.
EricLew 0:80ee8f3b695e 1716 * @note The function is called under interruption only, once
EricLew 0:80ee8f3b695e 1717 * interruptions have been enabled by HAL_CRYPEx_AES_Auth_IT().
EricLew 0:80ee8f3b695e 1718 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1719 * the configuration information for CRYP module
EricLew 0:80ee8f3b695e 1720 * @retval HAL status
EricLew 0:80ee8f3b695e 1721 */
EricLew 0:80ee8f3b695e 1722 HAL_StatusTypeDef CRYP_AES_Auth_IT(CRYP_HandleTypeDef *hcryp)
EricLew 0:80ee8f3b695e 1723 {
EricLew 0:80ee8f3b695e 1724 uint32_t inputaddr = 0x0;
EricLew 0:80ee8f3b695e 1725 uint32_t outputaddr = 0x0;
EricLew 0:80ee8f3b695e 1726
EricLew 0:80ee8f3b695e 1727 if(hcryp->State == HAL_CRYP_STATE_BUSY)
EricLew 0:80ee8f3b695e 1728 {
EricLew 0:80ee8f3b695e 1729 /*=====================*/
EricLew 0:80ee8f3b695e 1730 /* GCM/GMAC init phase */
EricLew 0:80ee8f3b695e 1731 /*=====================*/
EricLew 0:80ee8f3b695e 1732 if (hcryp->Init.GCMCMACPhase == CRYP_GCM_INIT_PHASE)
EricLew 0:80ee8f3b695e 1733 {
EricLew 0:80ee8f3b695e 1734 /* Clear Computation Complete Flag */
EricLew 0:80ee8f3b695e 1735 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1736 /* Disable Computation Complete Flag and Errors Interrupts */
EricLew 0:80ee8f3b695e 1737 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
EricLew 0:80ee8f3b695e 1738 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 1739 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1740
EricLew 0:80ee8f3b695e 1741 /* Mark that the initialization phase is over */
EricLew 0:80ee8f3b695e 1742 hcryp->Phase = HAL_CRYP_PHASE_INIT_OVER;
EricLew 0:80ee8f3b695e 1743
EricLew 0:80ee8f3b695e 1744 /* Process Unlocked */
EricLew 0:80ee8f3b695e 1745 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1746 /* Call computation complete callback */
EricLew 0:80ee8f3b695e 1747 HAL_CRYPEx_ComputationCpltCallback(hcryp);
EricLew 0:80ee8f3b695e 1748 return HAL_OK;
EricLew 0:80ee8f3b695e 1749 }
EricLew 0:80ee8f3b695e 1750 /*===============================*/
EricLew 0:80ee8f3b695e 1751 /* GCM/GMAC or CMAC header phase */
EricLew 0:80ee8f3b695e 1752 /*===============================*/
EricLew 0:80ee8f3b695e 1753 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_HEADER_PHASE)
EricLew 0:80ee8f3b695e 1754 {
EricLew 0:80ee8f3b695e 1755 /* Check if all input header data have been entered */
EricLew 0:80ee8f3b695e 1756 if (hcryp->CrypInCount == 0)
EricLew 0:80ee8f3b695e 1757 {
EricLew 0:80ee8f3b695e 1758 /* Clear Computation Complete Flag */
EricLew 0:80ee8f3b695e 1759 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1760 /* Disable Computation Complete Flag and Errors Interrupts */
EricLew 0:80ee8f3b695e 1761 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
EricLew 0:80ee8f3b695e 1762 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 1763 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1764 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 1765 hcryp->Phase = HAL_CRYP_PHASE_HEADER_OVER;
EricLew 0:80ee8f3b695e 1766
EricLew 0:80ee8f3b695e 1767 /* Process Unlocked */
EricLew 0:80ee8f3b695e 1768 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1769
EricLew 0:80ee8f3b695e 1770 /* Call computation complete callback */
EricLew 0:80ee8f3b695e 1771 HAL_CRYPEx_ComputationCpltCallback(hcryp);
EricLew 0:80ee8f3b695e 1772
EricLew 0:80ee8f3b695e 1773 return HAL_OK;
EricLew 0:80ee8f3b695e 1774 }
EricLew 0:80ee8f3b695e 1775 /* If suspension flag has been raised, suspend processing */
EricLew 0:80ee8f3b695e 1776 else if (hcryp->SuspendRequest == HAL_CRYP_SUSPEND)
EricLew 0:80ee8f3b695e 1777 {
EricLew 0:80ee8f3b695e 1778 /* Ensure that CCF flag is set */
EricLew 0:80ee8f3b695e 1779 if(CRYP_WaitOnCCFlag(hcryp, CRYP_CCF_TIMEOUTVALUE) != HAL_OK)
EricLew 0:80ee8f3b695e 1780 {
EricLew 0:80ee8f3b695e 1781 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1782 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1783 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 1784 }
EricLew 0:80ee8f3b695e 1785 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 1786 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1787
EricLew 0:80ee8f3b695e 1788 /* reset SuspendRequest */
EricLew 0:80ee8f3b695e 1789 hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
EricLew 0:80ee8f3b695e 1790 /* Disable Computation Complete Flag and Errors Interrupts */
EricLew 0:80ee8f3b695e 1791 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
EricLew 0:80ee8f3b695e 1792 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 1793 hcryp->State = HAL_CRYP_STATE_SUSPENDED;
EricLew 0:80ee8f3b695e 1794 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 1795 hcryp->Phase = HAL_CRYP_PHASE_HEADER_SUSPENDED;
EricLew 0:80ee8f3b695e 1796
EricLew 0:80ee8f3b695e 1797 /* Process Unlocked */
EricLew 0:80ee8f3b695e 1798 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1799
EricLew 0:80ee8f3b695e 1800 return HAL_OK;
EricLew 0:80ee8f3b695e 1801 }
EricLew 0:80ee8f3b695e 1802 else /* Carry on feeding input data to the CRYP hardware block */
EricLew 0:80ee8f3b695e 1803 {
EricLew 0:80ee8f3b695e 1804 /* Clear Computation Complete Flag */
EricLew 0:80ee8f3b695e 1805 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1806 /* Get the last Input data address */
EricLew 0:80ee8f3b695e 1807 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
EricLew 0:80ee8f3b695e 1808
EricLew 0:80ee8f3b695e 1809 /* Increment/decrement instance pointer/counter */
EricLew 0:80ee8f3b695e 1810 hcryp->pCrypInBuffPtr += 16;
EricLew 0:80ee8f3b695e 1811 hcryp->CrypInCount -= 16;
EricLew 0:80ee8f3b695e 1812
EricLew 0:80ee8f3b695e 1813 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
EricLew 0:80ee8f3b695e 1814 {
EricLew 0:80ee8f3b695e 1815 if (hcryp->CrypInCount == hcryp->Init.HeaderSize)
EricLew 0:80ee8f3b695e 1816 {
EricLew 0:80ee8f3b695e 1817 /* All B blocks will have been entered after the next
EricLew 0:80ee8f3b695e 1818 four DINR writing, so point at header buffer for
EricLew 0:80ee8f3b695e 1819 the next iteration */
EricLew 0:80ee8f3b695e 1820 hcryp->pCrypInBuffPtr = hcryp->Init.Header;
EricLew 0:80ee8f3b695e 1821 }
EricLew 0:80ee8f3b695e 1822 }
EricLew 0:80ee8f3b695e 1823
EricLew 0:80ee8f3b695e 1824 /* Write the Input block in the Data Input register */
EricLew 0:80ee8f3b695e 1825 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1826 inputaddr+=4;
EricLew 0:80ee8f3b695e 1827 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1828 inputaddr+=4;
EricLew 0:80ee8f3b695e 1829 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1830 inputaddr+=4;
EricLew 0:80ee8f3b695e 1831 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1832
EricLew 0:80ee8f3b695e 1833 return HAL_OK;
EricLew 0:80ee8f3b695e 1834 }
EricLew 0:80ee8f3b695e 1835 }
EricLew 0:80ee8f3b695e 1836 /*========================*/
EricLew 0:80ee8f3b695e 1837 /* GCM/GMAC payload phase */
EricLew 0:80ee8f3b695e 1838 /*========================*/
EricLew 0:80ee8f3b695e 1839 else if (hcryp->Init.GCMCMACPhase == CRYP_GCM_PAYLOAD_PHASE)
EricLew 0:80ee8f3b695e 1840 {
EricLew 0:80ee8f3b695e 1841 /* Get the last output data address */
EricLew 0:80ee8f3b695e 1842 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
EricLew 0:80ee8f3b695e 1843
EricLew 0:80ee8f3b695e 1844 /* Retrieve the last block available from the CRYP hardware block:
EricLew 0:80ee8f3b695e 1845 read the output block from the Data Output Register */
EricLew 0:80ee8f3b695e 1846 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1847 outputaddr+=4;
EricLew 0:80ee8f3b695e 1848 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1849 outputaddr+=4;
EricLew 0:80ee8f3b695e 1850 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1851 outputaddr+=4;
EricLew 0:80ee8f3b695e 1852 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1853
EricLew 0:80ee8f3b695e 1854 /* Increment/decrement instance pointer/counter */
EricLew 0:80ee8f3b695e 1855 hcryp->pCrypOutBuffPtr += 16;
EricLew 0:80ee8f3b695e 1856 hcryp->CrypOutCount -= 16;
EricLew 0:80ee8f3b695e 1857
EricLew 0:80ee8f3b695e 1858 /* Check if all output text has been retrieved */
EricLew 0:80ee8f3b695e 1859 if (hcryp->CrypOutCount == 0)
EricLew 0:80ee8f3b695e 1860 {
EricLew 0:80ee8f3b695e 1861 /* Clear Computation Complete Flag */
EricLew 0:80ee8f3b695e 1862 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1863 /* Disable Computation Complete Flag and Errors Interrupts */
EricLew 0:80ee8f3b695e 1864 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
EricLew 0:80ee8f3b695e 1865 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 1866 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1867 /* Mark that the payload phase is over */
EricLew 0:80ee8f3b695e 1868 hcryp->Phase = HAL_CRYP_PHASE_PAYLOAD_OVER;
EricLew 0:80ee8f3b695e 1869
EricLew 0:80ee8f3b695e 1870 /* Process Unlocked */
EricLew 0:80ee8f3b695e 1871 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1872
EricLew 0:80ee8f3b695e 1873 /* Call computation complete callback */
EricLew 0:80ee8f3b695e 1874 HAL_CRYPEx_ComputationCpltCallback(hcryp);
EricLew 0:80ee8f3b695e 1875
EricLew 0:80ee8f3b695e 1876 return HAL_OK;
EricLew 0:80ee8f3b695e 1877 }
EricLew 0:80ee8f3b695e 1878 /* If suspension flag has been raised, suspend processing */
EricLew 0:80ee8f3b695e 1879 else if (hcryp->SuspendRequest == HAL_CRYP_SUSPEND)
EricLew 0:80ee8f3b695e 1880 {
EricLew 0:80ee8f3b695e 1881 if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT)
EricLew 0:80ee8f3b695e 1882 {
EricLew 0:80ee8f3b695e 1883 /* Ensure that Busy flag is reset */
EricLew 0:80ee8f3b695e 1884 if(CRYP_WaitOnBusyFlagReset(hcryp, CRYP_BUSY_TIMEOUTVALUE) != HAL_OK)
EricLew 0:80ee8f3b695e 1885 {
EricLew 0:80ee8f3b695e 1886 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1887 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1888 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 1889 }
EricLew 0:80ee8f3b695e 1890 }
EricLew 0:80ee8f3b695e 1891 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 1892 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1893
EricLew 0:80ee8f3b695e 1894 /* reset SuspendRequest */
EricLew 0:80ee8f3b695e 1895 hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
EricLew 0:80ee8f3b695e 1896 /* Disable Computation Complete Flag and Errors Interrupts */
EricLew 0:80ee8f3b695e 1897 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
EricLew 0:80ee8f3b695e 1898 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 1899 hcryp->State = HAL_CRYP_STATE_SUSPENDED;
EricLew 0:80ee8f3b695e 1900 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 1901 hcryp->Phase = HAL_CRYP_PHASE_HEADER_SUSPENDED;
EricLew 0:80ee8f3b695e 1902
EricLew 0:80ee8f3b695e 1903 /* Process Unlocked */
EricLew 0:80ee8f3b695e 1904 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1905
EricLew 0:80ee8f3b695e 1906 return HAL_OK;
EricLew 0:80ee8f3b695e 1907 }
EricLew 0:80ee8f3b695e 1908 else /* Output data are still expected, carry on feeding the CRYP
EricLew 0:80ee8f3b695e 1909 hardware block with input data */
EricLew 0:80ee8f3b695e 1910 {
EricLew 0:80ee8f3b695e 1911 /* Clear Computation Complete Flag */
EricLew 0:80ee8f3b695e 1912 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1913 /* Get the last Input data address */
EricLew 0:80ee8f3b695e 1914 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
EricLew 0:80ee8f3b695e 1915
EricLew 0:80ee8f3b695e 1916 /* Increment/decrement instance pointer/counter */
EricLew 0:80ee8f3b695e 1917 hcryp->pCrypInBuffPtr += 16;
EricLew 0:80ee8f3b695e 1918 hcryp->CrypInCount -= 16;
EricLew 0:80ee8f3b695e 1919
EricLew 0:80ee8f3b695e 1920 /* Write the Input block in the Data Input register */
EricLew 0:80ee8f3b695e 1921 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1922 inputaddr+=4;
EricLew 0:80ee8f3b695e 1923 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1924 inputaddr+=4;
EricLew 0:80ee8f3b695e 1925 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1926 inputaddr+=4;
EricLew 0:80ee8f3b695e 1927 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 1928
EricLew 0:80ee8f3b695e 1929 return HAL_OK;
EricLew 0:80ee8f3b695e 1930 }
EricLew 0:80ee8f3b695e 1931 }
EricLew 0:80ee8f3b695e 1932 /*==============================*/
EricLew 0:80ee8f3b695e 1933 /* GCM/GMAC or CMAC final phase */
EricLew 0:80ee8f3b695e 1934 /*==============================*/
EricLew 0:80ee8f3b695e 1935 else if (hcryp->Init.GCMCMACPhase == CRYP_GCMCMAC_FINAL_PHASE)
EricLew 0:80ee8f3b695e 1936 {
EricLew 0:80ee8f3b695e 1937 /* Clear Computation Complete Flag */
EricLew 0:80ee8f3b695e 1938 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1939
EricLew 0:80ee8f3b695e 1940 /* Get the last output data address */
EricLew 0:80ee8f3b695e 1941 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
EricLew 0:80ee8f3b695e 1942
EricLew 0:80ee8f3b695e 1943 /* Retrieve the last expected data from the CRYP hardware block:
EricLew 0:80ee8f3b695e 1944 read the output block from the Data Output Register */
EricLew 0:80ee8f3b695e 1945 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1946 outputaddr+=4;
EricLew 0:80ee8f3b695e 1947 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1948 outputaddr+=4;
EricLew 0:80ee8f3b695e 1949 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1950 outputaddr+=4;
EricLew 0:80ee8f3b695e 1951 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 1952
EricLew 0:80ee8f3b695e 1953 /* Disable Computation Complete Flag and Errors Interrupts */
EricLew 0:80ee8f3b695e 1954 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
EricLew 0:80ee8f3b695e 1955 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 1956 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 1957 /* Mark that the header phase is over */
EricLew 0:80ee8f3b695e 1958 hcryp->Phase = HAL_CRYP_PHASE_FINAL_OVER;
EricLew 0:80ee8f3b695e 1959
EricLew 0:80ee8f3b695e 1960 /* Disable the Peripheral */
EricLew 0:80ee8f3b695e 1961 __HAL_CRYP_DISABLE();
EricLew 0:80ee8f3b695e 1962 /* Process Unlocked */
EricLew 0:80ee8f3b695e 1963 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1964
EricLew 0:80ee8f3b695e 1965 /* Call computation complete callback */
EricLew 0:80ee8f3b695e 1966 HAL_CRYPEx_ComputationCpltCallback(hcryp);
EricLew 0:80ee8f3b695e 1967
EricLew 0:80ee8f3b695e 1968 return HAL_OK;
EricLew 0:80ee8f3b695e 1969 }
EricLew 0:80ee8f3b695e 1970 else
EricLew 0:80ee8f3b695e 1971 {
EricLew 0:80ee8f3b695e 1972 /* Clear Computation Complete Flag */
EricLew 0:80ee8f3b695e 1973 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 1974 hcryp->State = HAL_CRYP_STATE_ERROR;
EricLew 0:80ee8f3b695e 1975 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 1976 return HAL_ERROR;
EricLew 0:80ee8f3b695e 1977 }
EricLew 0:80ee8f3b695e 1978 }
EricLew 0:80ee8f3b695e 1979 else
EricLew 0:80ee8f3b695e 1980 {
EricLew 0:80ee8f3b695e 1981 return HAL_BUSY;
EricLew 0:80ee8f3b695e 1982 }
EricLew 0:80ee8f3b695e 1983 }
EricLew 0:80ee8f3b695e 1984
EricLew 0:80ee8f3b695e 1985
EricLew 0:80ee8f3b695e 1986
EricLew 0:80ee8f3b695e 1987 /**
EricLew 0:80ee8f3b695e 1988 * @brief Set the DMA configuration and start the DMA transfer
EricLew 0:80ee8f3b695e 1989 * for GCM, GMAC or CMAC chainging modes.
EricLew 0:80ee8f3b695e 1990 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 1991 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 1992 * @param inputaddr: Address of the Input buffer.
EricLew 0:80ee8f3b695e 1993 * @param Size: Size of the Input buffer un bytes, must be a multiple of 16.
EricLew 0:80ee8f3b695e 1994 * @param outputaddr: Address of the Output buffer, null pointer when no output DMA stream
EricLew 0:80ee8f3b695e 1995 * has to be configured.
EricLew 0:80ee8f3b695e 1996 * @retval None
EricLew 0:80ee8f3b695e 1997 */
EricLew 0:80ee8f3b695e 1998 static void CRYP_GCMCMAC_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr)
EricLew 0:80ee8f3b695e 1999 {
EricLew 0:80ee8f3b695e 2000
EricLew 0:80ee8f3b695e 2001 /* Set the input CRYP DMA transfer complete callback */
EricLew 0:80ee8f3b695e 2002 hcryp->hdmain->XferCpltCallback = CRYP_GCMCMAC_DMAInCplt;
EricLew 0:80ee8f3b695e 2003 /* Set the DMA error callback */
EricLew 0:80ee8f3b695e 2004 hcryp->hdmain->XferErrorCallback = CRYP_GCMCMAC_DMAError;
EricLew 0:80ee8f3b695e 2005
EricLew 0:80ee8f3b695e 2006 if (outputaddr != 0)
EricLew 0:80ee8f3b695e 2007 {
EricLew 0:80ee8f3b695e 2008 /* Set the output CRYP DMA transfer complete callback */
EricLew 0:80ee8f3b695e 2009 hcryp->hdmaout->XferCpltCallback = CRYP_GCMCMAC_DMAOutCplt;
EricLew 0:80ee8f3b695e 2010 /* Set the DMA error callback */
EricLew 0:80ee8f3b695e 2011 hcryp->hdmaout->XferErrorCallback = CRYP_GCMCMAC_DMAError;
EricLew 0:80ee8f3b695e 2012 }
EricLew 0:80ee8f3b695e 2013
EricLew 0:80ee8f3b695e 2014 /* Enable the CRYP peripheral */
EricLew 0:80ee8f3b695e 2015 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 2016
EricLew 0:80ee8f3b695e 2017 /* Enable the DMA input stream */
EricLew 0:80ee8f3b695e 2018 HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DINR, Size/4);
EricLew 0:80ee8f3b695e 2019
EricLew 0:80ee8f3b695e 2020 /* Enable the DMA input request */
EricLew 0:80ee8f3b695e 2021 SET_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
EricLew 0:80ee8f3b695e 2022
EricLew 0:80ee8f3b695e 2023
EricLew 0:80ee8f3b695e 2024 if (outputaddr != 0)
EricLew 0:80ee8f3b695e 2025 {
EricLew 0:80ee8f3b695e 2026 /* Enable the DMA output stream */
EricLew 0:80ee8f3b695e 2027 HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUTR, outputaddr, Size/4);
EricLew 0:80ee8f3b695e 2028
EricLew 0:80ee8f3b695e 2029 /* Enable the DMA output request */
EricLew 0:80ee8f3b695e 2030 SET_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
EricLew 0:80ee8f3b695e 2031 }
EricLew 0:80ee8f3b695e 2032 }
EricLew 0:80ee8f3b695e 2033
EricLew 0:80ee8f3b695e 2034
EricLew 0:80ee8f3b695e 2035
EricLew 0:80ee8f3b695e 2036 /**
EricLew 0:80ee8f3b695e 2037 * @brief Write/read input/output data in polling mode.
EricLew 0:80ee8f3b695e 2038 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 2039 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 2040 * @param Input: Pointer to the Input buffer.
EricLew 0:80ee8f3b695e 2041 * @param Ilength: Length of the Input buffer in bytes, must be a multiple of 16.
EricLew 0:80ee8f3b695e 2042 * @param Output: Pointer to the returned buffer.
EricLew 0:80ee8f3b695e 2043 * @param Timeout: Specify Timeout value.
EricLew 0:80ee8f3b695e 2044 * @retval HAL status
EricLew 0:80ee8f3b695e 2045 */
EricLew 0:80ee8f3b695e 2046 static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout)
EricLew 0:80ee8f3b695e 2047 {
EricLew 0:80ee8f3b695e 2048 uint32_t index = 0;
EricLew 0:80ee8f3b695e 2049 uint32_t inputaddr = (uint32_t)Input;
EricLew 0:80ee8f3b695e 2050 uint32_t outputaddr = (uint32_t)Output;
EricLew 0:80ee8f3b695e 2051
EricLew 0:80ee8f3b695e 2052
EricLew 0:80ee8f3b695e 2053 for(index=0; (index < Ilength); index += 16)
EricLew 0:80ee8f3b695e 2054 {
EricLew 0:80ee8f3b695e 2055 /* Write the Input block in the Data Input register */
EricLew 0:80ee8f3b695e 2056 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 2057 inputaddr+=4;
EricLew 0:80ee8f3b695e 2058 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 2059 inputaddr+=4;
EricLew 0:80ee8f3b695e 2060 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 2061 inputaddr+=4;
EricLew 0:80ee8f3b695e 2062 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
EricLew 0:80ee8f3b695e 2063 inputaddr+=4;
EricLew 0:80ee8f3b695e 2064
EricLew 0:80ee8f3b695e 2065 /* Wait for CCF flag to be raised */
EricLew 0:80ee8f3b695e 2066 if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 2067 {
EricLew 0:80ee8f3b695e 2068 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 2069 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 2070 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 2071 }
EricLew 0:80ee8f3b695e 2072
EricLew 0:80ee8f3b695e 2073 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 2074 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 2075
EricLew 0:80ee8f3b695e 2076 /* Read the Output block from the Data Output Register */
EricLew 0:80ee8f3b695e 2077 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 2078 outputaddr+=4;
EricLew 0:80ee8f3b695e 2079 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 2080 outputaddr+=4;
EricLew 0:80ee8f3b695e 2081 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 2082 outputaddr+=4;
EricLew 0:80ee8f3b695e 2083 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
EricLew 0:80ee8f3b695e 2084 outputaddr+=4;
EricLew 0:80ee8f3b695e 2085
EricLew 0:80ee8f3b695e 2086 /* If the suspension flag has been raised and if the processing is not about
EricLew 0:80ee8f3b695e 2087 to end, suspend processing */
EricLew 0:80ee8f3b695e 2088 if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16) < Ilength))
EricLew 0:80ee8f3b695e 2089 {
EricLew 0:80ee8f3b695e 2090 /* Reset SuspendRequest */
EricLew 0:80ee8f3b695e 2091 hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
EricLew 0:80ee8f3b695e 2092
EricLew 0:80ee8f3b695e 2093 /* Save current reading and writing locations of Input and Output buffers */
EricLew 0:80ee8f3b695e 2094 hcryp->pCrypOutBuffPtr = (uint8_t *)outputaddr;
EricLew 0:80ee8f3b695e 2095 hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
EricLew 0:80ee8f3b695e 2096 /* Save the number of bytes that remain to be processed at this point */
EricLew 0:80ee8f3b695e 2097 hcryp->CrypInCount = Ilength - (index+16);
EricLew 0:80ee8f3b695e 2098
EricLew 0:80ee8f3b695e 2099 /* Change the CRYP state */
EricLew 0:80ee8f3b695e 2100 hcryp->State = HAL_CRYP_STATE_SUSPENDED;
EricLew 0:80ee8f3b695e 2101
EricLew 0:80ee8f3b695e 2102 return HAL_OK;
EricLew 0:80ee8f3b695e 2103 }
EricLew 0:80ee8f3b695e 2104
EricLew 0:80ee8f3b695e 2105
EricLew 0:80ee8f3b695e 2106 }
EricLew 0:80ee8f3b695e 2107 /* Return function status */
EricLew 0:80ee8f3b695e 2108 return HAL_OK;
EricLew 0:80ee8f3b695e 2109
EricLew 0:80ee8f3b695e 2110 }
EricLew 0:80ee8f3b695e 2111
EricLew 0:80ee8f3b695e 2112
EricLew 0:80ee8f3b695e 2113
EricLew 0:80ee8f3b695e 2114
EricLew 0:80ee8f3b695e 2115
EricLew 0:80ee8f3b695e 2116 /**
EricLew 0:80ee8f3b695e 2117 * @brief Read derivative key in polling mode when CRYP hardware block is set
EricLew 0:80ee8f3b695e 2118 * in key derivation operating mode (mode 2).
EricLew 0:80ee8f3b695e 2119 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 2120 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 2121 * @param Output: Pointer to the returned buffer.
EricLew 0:80ee8f3b695e 2122 * @param Timeout: Specify Timeout value.
EricLew 0:80ee8f3b695e 2123 * @retval HAL status
EricLew 0:80ee8f3b695e 2124 */
EricLew 0:80ee8f3b695e 2125 static HAL_StatusTypeDef CRYP_ReadKey(CRYP_HandleTypeDef *hcryp, uint8_t* Output, uint32_t Timeout)
EricLew 0:80ee8f3b695e 2126 {
EricLew 0:80ee8f3b695e 2127 uint32_t outputaddr = (uint32_t)Output;
EricLew 0:80ee8f3b695e 2128
EricLew 0:80ee8f3b695e 2129 /* Wait for CCF flag to be raised */
EricLew 0:80ee8f3b695e 2130 if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
EricLew 0:80ee8f3b695e 2131 {
EricLew 0:80ee8f3b695e 2132 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 2133 __HAL_UNLOCK(hcryp);
EricLew 0:80ee8f3b695e 2134 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 2135 }
EricLew 0:80ee8f3b695e 2136 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 2137 __HAL_CRYP_CLEAR_FLAG( CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 2138
EricLew 0:80ee8f3b695e 2139 /* Read the derivative key from the AES_KEYRx registers */
EricLew 0:80ee8f3b695e 2140 if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B)
EricLew 0:80ee8f3b695e 2141 {
EricLew 0:80ee8f3b695e 2142 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR7);
EricLew 0:80ee8f3b695e 2143 outputaddr+=4;
EricLew 0:80ee8f3b695e 2144 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR6);
EricLew 0:80ee8f3b695e 2145 outputaddr+=4;
EricLew 0:80ee8f3b695e 2146 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR5);
EricLew 0:80ee8f3b695e 2147 outputaddr+=4;
EricLew 0:80ee8f3b695e 2148 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR4);
EricLew 0:80ee8f3b695e 2149 outputaddr+=4;
EricLew 0:80ee8f3b695e 2150 }
EricLew 0:80ee8f3b695e 2151
EricLew 0:80ee8f3b695e 2152 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR3);
EricLew 0:80ee8f3b695e 2153 outputaddr+=4;
EricLew 0:80ee8f3b695e 2154 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR2);
EricLew 0:80ee8f3b695e 2155 outputaddr+=4;
EricLew 0:80ee8f3b695e 2156 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR1);
EricLew 0:80ee8f3b695e 2157 outputaddr+=4;
EricLew 0:80ee8f3b695e 2158 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR0);
EricLew 0:80ee8f3b695e 2159
EricLew 0:80ee8f3b695e 2160
EricLew 0:80ee8f3b695e 2161 /* Return function status */
EricLew 0:80ee8f3b695e 2162 return HAL_OK;
EricLew 0:80ee8f3b695e 2163 }
EricLew 0:80ee8f3b695e 2164
EricLew 0:80ee8f3b695e 2165 /**
EricLew 0:80ee8f3b695e 2166 * @brief Set the DMA configuration and start the DMA transfer.
EricLew 0:80ee8f3b695e 2167 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 2168 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 2169 * @param inputaddr: Address of the Input buffer.
EricLew 0:80ee8f3b695e 2170 * @param Size: Size of the Input buffer in bytes, must be a multiple of 16.
EricLew 0:80ee8f3b695e 2171 * @param outputaddr: Address of the Output buffer.
EricLew 0:80ee8f3b695e 2172 * @retval None
EricLew 0:80ee8f3b695e 2173 */
EricLew 0:80ee8f3b695e 2174 static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr)
EricLew 0:80ee8f3b695e 2175 {
EricLew 0:80ee8f3b695e 2176 /* Set the CRYP DMA transfer complete callback */
EricLew 0:80ee8f3b695e 2177 hcryp->hdmain->XferCpltCallback = CRYP_DMAInCplt;
EricLew 0:80ee8f3b695e 2178 /* Set the DMA error callback */
EricLew 0:80ee8f3b695e 2179 hcryp->hdmain->XferErrorCallback = CRYP_DMAError;
EricLew 0:80ee8f3b695e 2180
EricLew 0:80ee8f3b695e 2181 /* Set the CRYP DMA transfer complete callback */
EricLew 0:80ee8f3b695e 2182 hcryp->hdmaout->XferCpltCallback = CRYP_DMAOutCplt;
EricLew 0:80ee8f3b695e 2183 /* Set the DMA error callback */
EricLew 0:80ee8f3b695e 2184 hcryp->hdmaout->XferErrorCallback = CRYP_DMAError;
EricLew 0:80ee8f3b695e 2185
EricLew 0:80ee8f3b695e 2186 /* Enable the DMA input stream */
EricLew 0:80ee8f3b695e 2187 HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DINR, Size/4);
EricLew 0:80ee8f3b695e 2188
EricLew 0:80ee8f3b695e 2189 /* Enable the DMA output stream */
EricLew 0:80ee8f3b695e 2190 HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUTR, outputaddr, Size/4);
EricLew 0:80ee8f3b695e 2191
EricLew 0:80ee8f3b695e 2192 /* Enable In and Out DMA requests */
EricLew 0:80ee8f3b695e 2193 SET_BIT(hcryp->Instance->CR, (AES_CR_DMAINEN | AES_CR_DMAOUTEN));
EricLew 0:80ee8f3b695e 2194
EricLew 0:80ee8f3b695e 2195 /* Enable the CRYP peripheral */
EricLew 0:80ee8f3b695e 2196 __HAL_CRYP_ENABLE();
EricLew 0:80ee8f3b695e 2197 }
EricLew 0:80ee8f3b695e 2198
EricLew 0:80ee8f3b695e 2199
EricLew 0:80ee8f3b695e 2200 /**
EricLew 0:80ee8f3b695e 2201 * @brief Handle CRYP hardware block Timeout when waiting for CCF flag to be raised.
EricLew 0:80ee8f3b695e 2202 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 2203 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 2204 * @param Timeout: Timeout duration.
EricLew 0:80ee8f3b695e 2205 * @retval HAL status
EricLew 0:80ee8f3b695e 2206 */
EricLew 0:80ee8f3b695e 2207 static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef *hcryp, uint32_t Timeout)
EricLew 0:80ee8f3b695e 2208 {
EricLew 0:80ee8f3b695e 2209 uint32_t tickstart = 0;
EricLew 0:80ee8f3b695e 2210
EricLew 0:80ee8f3b695e 2211 /* Get timeout */
EricLew 0:80ee8f3b695e 2212 tickstart = HAL_GetTick();
EricLew 0:80ee8f3b695e 2213
EricLew 0:80ee8f3b695e 2214 while(HAL_IS_BIT_CLR(hcryp->Instance->SR, AES_SR_CCF))
EricLew 0:80ee8f3b695e 2215 {
EricLew 0:80ee8f3b695e 2216 /* Check for the Timeout */
EricLew 0:80ee8f3b695e 2217 if(Timeout != HAL_MAX_DELAY)
EricLew 0:80ee8f3b695e 2218 {
EricLew 0:80ee8f3b695e 2219 if((HAL_GetTick() - tickstart ) > Timeout)
EricLew 0:80ee8f3b695e 2220 {
EricLew 0:80ee8f3b695e 2221 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 2222 }
EricLew 0:80ee8f3b695e 2223 }
EricLew 0:80ee8f3b695e 2224 }
EricLew 0:80ee8f3b695e 2225 return HAL_OK;
EricLew 0:80ee8f3b695e 2226 }
EricLew 0:80ee8f3b695e 2227
EricLew 0:80ee8f3b695e 2228 /**
EricLew 0:80ee8f3b695e 2229 * @brief Wait for Busy Flag to be reset during a GCM payload encryption process suspension.
EricLew 0:80ee8f3b695e 2230 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
EricLew 0:80ee8f3b695e 2231 * the configuration information for CRYP module.
EricLew 0:80ee8f3b695e 2232 * @param Timeout: Timeout duration.
EricLew 0:80ee8f3b695e 2233 * @retval HAL status
EricLew 0:80ee8f3b695e 2234 */
EricLew 0:80ee8f3b695e 2235 static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset(CRYP_HandleTypeDef *hcryp, uint32_t Timeout)
EricLew 0:80ee8f3b695e 2236 {
EricLew 0:80ee8f3b695e 2237 uint32_t tickstart = 0;
EricLew 0:80ee8f3b695e 2238
EricLew 0:80ee8f3b695e 2239 /* Get timeout */
EricLew 0:80ee8f3b695e 2240 tickstart = HAL_GetTick();
EricLew 0:80ee8f3b695e 2241
EricLew 0:80ee8f3b695e 2242 while(HAL_IS_BIT_SET(hcryp->Instance->SR, AES_SR_BUSY))
EricLew 0:80ee8f3b695e 2243 {
EricLew 0:80ee8f3b695e 2244 /* Check for the Timeout */
EricLew 0:80ee8f3b695e 2245 if(Timeout != HAL_MAX_DELAY)
EricLew 0:80ee8f3b695e 2246 {
EricLew 0:80ee8f3b695e 2247 if((HAL_GetTick() - tickstart ) > Timeout)
EricLew 0:80ee8f3b695e 2248 {
EricLew 0:80ee8f3b695e 2249 return HAL_TIMEOUT;
EricLew 0:80ee8f3b695e 2250 }
EricLew 0:80ee8f3b695e 2251 }
EricLew 0:80ee8f3b695e 2252 }
EricLew 0:80ee8f3b695e 2253 return HAL_OK;
EricLew 0:80ee8f3b695e 2254 }
EricLew 0:80ee8f3b695e 2255
EricLew 0:80ee8f3b695e 2256
EricLew 0:80ee8f3b695e 2257 /**
EricLew 0:80ee8f3b695e 2258 * @brief DMA CRYP Input Data process complete callback.
EricLew 0:80ee8f3b695e 2259 * @param hdma: DMA handle.
EricLew 0:80ee8f3b695e 2260 * @retval None
EricLew 0:80ee8f3b695e 2261 */
EricLew 0:80ee8f3b695e 2262 static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma)
EricLew 0:80ee8f3b695e 2263 {
EricLew 0:80ee8f3b695e 2264 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
EricLew 0:80ee8f3b695e 2265
EricLew 0:80ee8f3b695e 2266 /* Disable the DMA transfer for input request */
EricLew 0:80ee8f3b695e 2267 CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
EricLew 0:80ee8f3b695e 2268
EricLew 0:80ee8f3b695e 2269 /* Call input data transfer complete callback */
EricLew 0:80ee8f3b695e 2270 HAL_CRYP_InCpltCallback(hcryp);
EricLew 0:80ee8f3b695e 2271 }
EricLew 0:80ee8f3b695e 2272
EricLew 0:80ee8f3b695e 2273 /**
EricLew 0:80ee8f3b695e 2274 * @brief DMA CRYP Output Data process complete callback.
EricLew 0:80ee8f3b695e 2275 * @param hdma: DMA handle.
EricLew 0:80ee8f3b695e 2276 * @retval None
EricLew 0:80ee8f3b695e 2277 */
EricLew 0:80ee8f3b695e 2278 static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma)
EricLew 0:80ee8f3b695e 2279 {
EricLew 0:80ee8f3b695e 2280 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
EricLew 0:80ee8f3b695e 2281
EricLew 0:80ee8f3b695e 2282 /* Disable the DMA transfer for output request */
EricLew 0:80ee8f3b695e 2283 CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
EricLew 0:80ee8f3b695e 2284
EricLew 0:80ee8f3b695e 2285 /* Clear CCF Flag */
EricLew 0:80ee8f3b695e 2286 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
EricLew 0:80ee8f3b695e 2287
EricLew 0:80ee8f3b695e 2288 /* Disable CRYP */
EricLew 0:80ee8f3b695e 2289 __HAL_CRYP_DISABLE();
EricLew 0:80ee8f3b695e 2290
EricLew 0:80ee8f3b695e 2291 /* Change the CRYP state to ready */
EricLew 0:80ee8f3b695e 2292 hcryp->State = HAL_CRYP_STATE_READY;
EricLew 0:80ee8f3b695e 2293
EricLew 0:80ee8f3b695e 2294 /* Call output data transfer complete callback */
EricLew 0:80ee8f3b695e 2295 HAL_CRYP_OutCpltCallback(hcryp);
EricLew 0:80ee8f3b695e 2296 }
EricLew 0:80ee8f3b695e 2297
EricLew 0:80ee8f3b695e 2298 /**
EricLew 0:80ee8f3b695e 2299 * @brief DMA CRYP communication error callback.
EricLew 0:80ee8f3b695e 2300 * @param hdma: DMA handle.
EricLew 0:80ee8f3b695e 2301 * @retval None
EricLew 0:80ee8f3b695e 2302 */
EricLew 0:80ee8f3b695e 2303 static void CRYP_DMAError(DMA_HandleTypeDef *hdma)
EricLew 0:80ee8f3b695e 2304 {
EricLew 0:80ee8f3b695e 2305 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
EricLew 0:80ee8f3b695e 2306
EricLew 0:80ee8f3b695e 2307 hcryp->State= HAL_CRYP_STATE_ERROR;
EricLew 0:80ee8f3b695e 2308 hcryp->ErrorCode |= HAL_CRYP_DMA_ERROR;
EricLew 0:80ee8f3b695e 2309 HAL_CRYP_ErrorCallback(hcryp);
EricLew 0:80ee8f3b695e 2310 /* Clear Error Flag */
EricLew 0:80ee8f3b695e 2311 __HAL_CRYP_CLEAR_FLAG(CRYP_ERR_CLEAR);
EricLew 0:80ee8f3b695e 2312 }
EricLew 0:80ee8f3b695e 2313
EricLew 0:80ee8f3b695e 2314
EricLew 0:80ee8f3b695e 2315 /**
EricLew 0:80ee8f3b695e 2316 * @}
EricLew 0:80ee8f3b695e 2317 */
EricLew 0:80ee8f3b695e 2318
EricLew 0:80ee8f3b695e 2319 /**
EricLew 0:80ee8f3b695e 2320 * @}
EricLew 0:80ee8f3b695e 2321 */
EricLew 0:80ee8f3b695e 2322
EricLew 0:80ee8f3b695e 2323 /**
EricLew 0:80ee8f3b695e 2324 * @}
EricLew 0:80ee8f3b695e 2325 */
EricLew 0:80ee8f3b695e 2326
EricLew 0:80ee8f3b695e 2327 #endif /* defined(STM32L485xx) || defined(STM32L486xx) */
EricLew 0:80ee8f3b695e 2328
EricLew 0:80ee8f3b695e 2329 #endif /* HAL_CRYP_MODULE_ENABLED */
EricLew 0:80ee8f3b695e 2330 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
EricLew 0:80ee8f3b695e 2331