mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32L4/stm32l4xx_hal_cryp.c@637:ed69428d4850, 2015-12-22 (annotated)
- Committer:
- jaerts
- Date:
- Tue Dec 22 13:22:16 2015 +0000
- Revision:
- 637:ed69428d4850
- Parent:
- 610:813dcc80987e
Add very shady LPC1768 CAN Filter implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 610:813dcc80987e | 1 | /** |
mbed_official | 610:813dcc80987e | 2 | ****************************************************************************** |
mbed_official | 610:813dcc80987e | 3 | * @file stm32l4xx_hal_cryp.c |
mbed_official | 610:813dcc80987e | 4 | * @author MCD Application Team |
mbed_official | 610:813dcc80987e | 5 | * @version V1.0.0 |
mbed_official | 610:813dcc80987e | 6 | * @date 26-June-2015 |
mbed_official | 610:813dcc80987e | 7 | * @brief CRYP HAL module driver. |
mbed_official | 610:813dcc80987e | 8 | * This file provides firmware functions to manage the following |
mbed_official | 610:813dcc80987e | 9 | * functionalities of the Cryptography (CRYP) peripheral: |
mbed_official | 610:813dcc80987e | 10 | * + Initialization and de-initialization functions |
mbed_official | 610:813dcc80987e | 11 | * + Processing functions using polling mode |
mbed_official | 610:813dcc80987e | 12 | * + Processing functions using interrupt mode |
mbed_official | 610:813dcc80987e | 13 | * + Processing functions using DMA mode |
mbed_official | 610:813dcc80987e | 14 | * + Peripheral State functions |
mbed_official | 610:813dcc80987e | 15 | * |
mbed_official | 610:813dcc80987e | 16 | @verbatim |
mbed_official | 610:813dcc80987e | 17 | ============================================================================== |
mbed_official | 610:813dcc80987e | 18 | ##### How to use this driver ##### |
mbed_official | 610:813dcc80987e | 19 | ============================================================================== |
mbed_official | 610:813dcc80987e | 20 | [..] |
mbed_official | 610:813dcc80987e | 21 | The CRYP HAL driver can be used as follows: |
mbed_official | 610:813dcc80987e | 22 | |
mbed_official | 610:813dcc80987e | 23 | (#)Initialize the CRYP low level resources by implementing the HAL_CRYP_MspInit(): |
mbed_official | 610:813dcc80987e | 24 | (++) Enable the CRYP interface clock using __HAL_RCC_AES_CLK_ENABLE() |
mbed_official | 610:813dcc80987e | 25 | (++) In case of using interrupts (e.g. HAL_CRYP_AES_IT()) |
mbed_official | 610:813dcc80987e | 26 | (+++) Configure the CRYP interrupt priority using HAL_NVIC_SetPriority() |
mbed_official | 610:813dcc80987e | 27 | (+++) Enable the AES IRQ handler using HAL_NVIC_EnableIRQ() |
mbed_official | 610:813dcc80987e | 28 | (+++) In AES IRQ handler, call HAL_CRYP_IRQHandler() |
mbed_official | 610:813dcc80987e | 29 | (++) In case of using DMA to control data transfer (e.g. HAL_CRYPEx_AES_DMA()) |
mbed_official | 610:813dcc80987e | 30 | (+++) Enable the DMA2 interface clock using |
mbed_official | 610:813dcc80987e | 31 | __HAL_RCC_DMA2_CLK_ENABLE() |
mbed_official | 610:813dcc80987e | 32 | (+++) Configure and enable two DMA channels one for managing data transfer from |
mbed_official | 610:813dcc80987e | 33 | memory to peripheral (input channel) and another channel for managing data |
mbed_official | 610:813dcc80987e | 34 | transfer from peripheral to memory (output channel) |
mbed_official | 610:813dcc80987e | 35 | (+++) Associate the initialized DMA handle to the CRYP DMA handle |
mbed_official | 610:813dcc80987e | 36 | using __HAL_LINKDMA() |
mbed_official | 610:813dcc80987e | 37 | (+++) Configure the priority and enable the NVIC for the transfer complete |
mbed_official | 610:813dcc80987e | 38 | interrupt on the two DMA channels. The output channel should have higher |
mbed_official | 610:813dcc80987e | 39 | priority than the input channel. |
mbed_official | 610:813dcc80987e | 40 | Resort to HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ() |
mbed_official | 610:813dcc80987e | 41 | |
mbed_official | 610:813dcc80987e | 42 | (#)Initialize the CRYP HAL using HAL_CRYP_Init(). This function configures: |
mbed_official | 610:813dcc80987e | 43 | (++) The data type: 1-bit, 8-bit, 16-bit and 32-bit |
mbed_official | 610:813dcc80987e | 44 | (++) The AES operating mode (encryption, key derivation and/or decryption) |
mbed_official | 610:813dcc80987e | 45 | (++) The AES chaining mode (ECB, CBC, CTR, GCM, GMAC, CMAC) |
mbed_official | 610:813dcc80987e | 46 | (++) The encryption/decryption key if so required |
mbed_official | 610:813dcc80987e | 47 | (++) The initialization vector or nonce if applicable (not used in ECB mode). |
mbed_official | 610:813dcc80987e | 48 | |
mbed_official | 610:813dcc80987e | 49 | (#)Three processing (encryption/decryption) functions are available: |
mbed_official | 610:813dcc80987e | 50 | (++) Polling mode: encryption and decryption APIs are blocking functions |
mbed_official | 610:813dcc80987e | 51 | i.e. they process the data and wait till the processing is finished |
mbed_official | 610:813dcc80987e | 52 | (++) Interrupt mode: encryption and decryption APIs are not blocking functions |
mbed_official | 610:813dcc80987e | 53 | i.e. they process the data under interrupt |
mbed_official | 610:813dcc80987e | 54 | (++) DMA mode: encryption and decryption APIs are not blocking functions |
mbed_official | 610:813dcc80987e | 55 | i.e. the data transfer is ensured by DMA |
mbed_official | 610:813dcc80987e | 56 | |
mbed_official | 610:813dcc80987e | 57 | (#)Call HAL_CRYP_DeInit() to deinitialize the CRYP peripheral. |
mbed_official | 610:813dcc80987e | 58 | |
mbed_official | 610:813dcc80987e | 59 | @endverbatim |
mbed_official | 610:813dcc80987e | 60 | ****************************************************************************** |
mbed_official | 610:813dcc80987e | 61 | * @attention |
mbed_official | 610:813dcc80987e | 62 | * |
mbed_official | 610:813dcc80987e | 63 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
mbed_official | 610:813dcc80987e | 64 | * |
mbed_official | 610:813dcc80987e | 65 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 610:813dcc80987e | 66 | * are permitted provided that the following conditions are met: |
mbed_official | 610:813dcc80987e | 67 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 610:813dcc80987e | 68 | * this list of conditions and the following disclaimer. |
mbed_official | 610:813dcc80987e | 69 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 610:813dcc80987e | 70 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 610:813dcc80987e | 71 | * and/or other materials provided with the distribution. |
mbed_official | 610:813dcc80987e | 72 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 610:813dcc80987e | 73 | * may be used to endorse or promote products derived from this software |
mbed_official | 610:813dcc80987e | 74 | * without specific prior written permission. |
mbed_official | 610:813dcc80987e | 75 | * |
mbed_official | 610:813dcc80987e | 76 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 610:813dcc80987e | 77 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 610:813dcc80987e | 78 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 610:813dcc80987e | 79 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 610:813dcc80987e | 80 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 610:813dcc80987e | 81 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 610:813dcc80987e | 82 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 610:813dcc80987e | 83 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 610:813dcc80987e | 84 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 610:813dcc80987e | 85 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 610:813dcc80987e | 86 | * |
mbed_official | 610:813dcc80987e | 87 | ****************************************************************************** |
mbed_official | 610:813dcc80987e | 88 | */ |
mbed_official | 610:813dcc80987e | 89 | |
mbed_official | 610:813dcc80987e | 90 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 91 | #include "stm32l4xx_hal.h" |
mbed_official | 610:813dcc80987e | 92 | |
mbed_official | 610:813dcc80987e | 93 | #ifdef HAL_CRYP_MODULE_ENABLED |
mbed_official | 610:813dcc80987e | 94 | |
mbed_official | 610:813dcc80987e | 95 | #if defined(STM32L485xx) || defined(STM32L486xx) |
mbed_official | 610:813dcc80987e | 96 | |
mbed_official | 610:813dcc80987e | 97 | /** @addtogroup STM32L4xx_HAL_Driver |
mbed_official | 610:813dcc80987e | 98 | * @{ |
mbed_official | 610:813dcc80987e | 99 | */ |
mbed_official | 610:813dcc80987e | 100 | |
mbed_official | 610:813dcc80987e | 101 | /** @defgroup CRYP CRYP |
mbed_official | 610:813dcc80987e | 102 | * @brief CRYP HAL module driver. |
mbed_official | 610:813dcc80987e | 103 | * @{ |
mbed_official | 610:813dcc80987e | 104 | */ |
mbed_official | 610:813dcc80987e | 105 | |
mbed_official | 610:813dcc80987e | 106 | |
mbed_official | 610:813dcc80987e | 107 | |
mbed_official | 610:813dcc80987e | 108 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 109 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 110 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 111 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 112 | /* Private functions --------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 113 | |
mbed_official | 610:813dcc80987e | 114 | /** @defgroup CRYP_Private_Functions CRYP Private Functions |
mbed_official | 610:813dcc80987e | 115 | * @{ |
mbed_official | 610:813dcc80987e | 116 | */ |
mbed_official | 610:813dcc80987e | 117 | |
mbed_official | 610:813dcc80987e | 118 | static HAL_StatusTypeDef CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp); |
mbed_official | 610:813dcc80987e | 119 | static HAL_StatusTypeDef CRYP_SetKey(CRYP_HandleTypeDef *hcryp); |
mbed_official | 610:813dcc80987e | 120 | static HAL_StatusTypeDef CRYP_AES_IT(CRYP_HandleTypeDef *hcryp); |
mbed_official | 610:813dcc80987e | 121 | |
mbed_official | 610:813dcc80987e | 122 | /** |
mbed_official | 610:813dcc80987e | 123 | * @} |
mbed_official | 610:813dcc80987e | 124 | */ |
mbed_official | 610:813dcc80987e | 125 | |
mbed_official | 610:813dcc80987e | 126 | /* Exported functions ---------------------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 127 | |
mbed_official | 610:813dcc80987e | 128 | /** @defgroup CRYP_Exported_Functions CRYP Exported Functions |
mbed_official | 610:813dcc80987e | 129 | * @{ |
mbed_official | 610:813dcc80987e | 130 | */ |
mbed_official | 610:813dcc80987e | 131 | |
mbed_official | 610:813dcc80987e | 132 | /** @defgroup CRYP_Group1 Initialization and deinitialization functions |
mbed_official | 610:813dcc80987e | 133 | * @brief Initialization and Configuration functions. |
mbed_official | 610:813dcc80987e | 134 | * |
mbed_official | 610:813dcc80987e | 135 | @verbatim |
mbed_official | 610:813dcc80987e | 136 | ============================================================================== |
mbed_official | 610:813dcc80987e | 137 | ##### Initialization and deinitialization functions ##### |
mbed_official | 610:813dcc80987e | 138 | ============================================================================== |
mbed_official | 610:813dcc80987e | 139 | [..] This section provides functions allowing to: |
mbed_official | 610:813dcc80987e | 140 | (+) Initialize the CRYP according to the specified parameters |
mbed_official | 610:813dcc80987e | 141 | in the CRYP_InitTypeDef and creates the associated handle |
mbed_official | 610:813dcc80987e | 142 | (+) DeInitialize the CRYP peripheral |
mbed_official | 610:813dcc80987e | 143 | (+) Initialize the CRYP MSP (MCU Specific Package) |
mbed_official | 610:813dcc80987e | 144 | (+) DeInitialize the CRC MSP |
mbed_official | 610:813dcc80987e | 145 | |
mbed_official | 610:813dcc80987e | 146 | @endverbatim |
mbed_official | 610:813dcc80987e | 147 | * @{ |
mbed_official | 610:813dcc80987e | 148 | */ |
mbed_official | 610:813dcc80987e | 149 | |
mbed_official | 610:813dcc80987e | 150 | /** |
mbed_official | 610:813dcc80987e | 151 | * @brief Initialize the CRYP according to the specified |
mbed_official | 610:813dcc80987e | 152 | * parameters in the CRYP_InitTypeDef and initialize the associated handle. |
mbed_official | 610:813dcc80987e | 153 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 154 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 155 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 156 | */ |
mbed_official | 610:813dcc80987e | 157 | HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 158 | { |
mbed_official | 610:813dcc80987e | 159 | /* Check the CRYP handle allocation */ |
mbed_official | 610:813dcc80987e | 160 | if(hcryp == NULL) |
mbed_official | 610:813dcc80987e | 161 | { |
mbed_official | 610:813dcc80987e | 162 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 163 | } |
mbed_official | 610:813dcc80987e | 164 | |
mbed_official | 610:813dcc80987e | 165 | /* Check the instance */ |
mbed_official | 610:813dcc80987e | 166 | assert_param(IS_AES_ALL_INSTANCE(hcryp->Instance)); |
mbed_official | 610:813dcc80987e | 167 | |
mbed_official | 610:813dcc80987e | 168 | /* Check the parameters */ |
mbed_official | 610:813dcc80987e | 169 | assert_param(IS_CRYP_KEYSIZE(hcryp->Init.KeySize)); |
mbed_official | 610:813dcc80987e | 170 | assert_param(IS_CRYP_DATATYPE(hcryp->Init.DataType)); |
mbed_official | 610:813dcc80987e | 171 | assert_param(IS_CRYP_ALGOMODE(hcryp->Init.OperatingMode)); |
mbed_official | 610:813dcc80987e | 172 | /* ChainingMode parameter is irrelevant when mode is set to Key derivation */ |
mbed_official | 610:813dcc80987e | 173 | if (hcryp->Init.OperatingMode != CRYP_ALGOMODE_KEYDERIVATION) |
mbed_official | 610:813dcc80987e | 174 | { |
mbed_official | 610:813dcc80987e | 175 | assert_param(IS_CRYP_CHAINMODE(hcryp->Init.ChainingMode)); |
mbed_official | 610:813dcc80987e | 176 | } |
mbed_official | 610:813dcc80987e | 177 | assert_param(IS_CRYP_WRITE(hcryp->Init.KeyWriteFlag)); |
mbed_official | 610:813dcc80987e | 178 | |
mbed_official | 610:813dcc80987e | 179 | /*========================================================*/ |
mbed_official | 610:813dcc80987e | 180 | /* Check the proper operating/chaining modes combinations */ |
mbed_official | 610:813dcc80987e | 181 | /*========================================================*/ |
mbed_official | 610:813dcc80987e | 182 | /* Check the proper chaining when the operating mode is key derivation and decryption */ |
mbed_official | 610:813dcc80987e | 183 | if ((hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION_DECRYPT) &&\ |
mbed_official | 610:813dcc80987e | 184 | ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CTR) \ |
mbed_official | 610:813dcc80987e | 185 | || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC) \ |
mbed_official | 610:813dcc80987e | 186 | || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC))) |
mbed_official | 610:813dcc80987e | 187 | { |
mbed_official | 610:813dcc80987e | 188 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 189 | } |
mbed_official | 610:813dcc80987e | 190 | /* Check that key derivation is not set in CMAC mode */ |
mbed_official | 610:813dcc80987e | 191 | if ((hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION) |
mbed_official | 610:813dcc80987e | 192 | && (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)) |
mbed_official | 610:813dcc80987e | 193 | { |
mbed_official | 610:813dcc80987e | 194 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 195 | } |
mbed_official | 610:813dcc80987e | 196 | |
mbed_official | 610:813dcc80987e | 197 | |
mbed_official | 610:813dcc80987e | 198 | /*================*/ |
mbed_official | 610:813dcc80987e | 199 | /* Initialization */ |
mbed_official | 610:813dcc80987e | 200 | /*================*/ |
mbed_official | 610:813dcc80987e | 201 | /* Initialization start */ |
mbed_official | 610:813dcc80987e | 202 | if(hcryp->State == HAL_CRYP_STATE_RESET) |
mbed_official | 610:813dcc80987e | 203 | { |
mbed_official | 610:813dcc80987e | 204 | /* Allocate lock resource and initialize it */ |
mbed_official | 610:813dcc80987e | 205 | hcryp->Lock = HAL_UNLOCKED; |
mbed_official | 610:813dcc80987e | 206 | |
mbed_official | 610:813dcc80987e | 207 | /* Init the low level hardware */ |
mbed_official | 610:813dcc80987e | 208 | HAL_CRYP_MspInit(hcryp); |
mbed_official | 610:813dcc80987e | 209 | } |
mbed_official | 610:813dcc80987e | 210 | |
mbed_official | 610:813dcc80987e | 211 | /* Change the CRYP state */ |
mbed_official | 610:813dcc80987e | 212 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 610:813dcc80987e | 213 | |
mbed_official | 610:813dcc80987e | 214 | /* Disable the Peripheral */ |
mbed_official | 610:813dcc80987e | 215 | __HAL_CRYP_DISABLE(); |
mbed_official | 610:813dcc80987e | 216 | |
mbed_official | 610:813dcc80987e | 217 | /*=============================================================*/ |
mbed_official | 610:813dcc80987e | 218 | /* AES initialization common to all operating modes */ |
mbed_official | 610:813dcc80987e | 219 | /*=============================================================*/ |
mbed_official | 610:813dcc80987e | 220 | /* Set the Key size selection */ |
mbed_official | 610:813dcc80987e | 221 | MODIFY_REG(hcryp->Instance->CR, AES_CR_KEYSIZE, hcryp->Init.KeySize); |
mbed_official | 610:813dcc80987e | 222 | |
mbed_official | 610:813dcc80987e | 223 | /* Set the default CRYP phase when this parameter is not used. |
mbed_official | 610:813dcc80987e | 224 | Phase is updated below in case of GCM/GMAC/CMAC setting. */ |
mbed_official | 610:813dcc80987e | 225 | hcryp->Phase = HAL_CRYP_PHASE_NOT_USED; |
mbed_official | 610:813dcc80987e | 226 | |
mbed_official | 610:813dcc80987e | 227 | |
mbed_official | 610:813dcc80987e | 228 | |
mbed_official | 610:813dcc80987e | 229 | /*=============================================================*/ |
mbed_official | 610:813dcc80987e | 230 | /* Carry on the initialization based on the AES operating mode */ |
mbed_official | 610:813dcc80987e | 231 | /*=============================================================*/ |
mbed_official | 610:813dcc80987e | 232 | /* Key derivation */ |
mbed_official | 610:813dcc80987e | 233 | if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION) |
mbed_official | 610:813dcc80987e | 234 | { |
mbed_official | 610:813dcc80987e | 235 | MODIFY_REG(hcryp->Instance->CR, AES_CR_MODE, CRYP_ALGOMODE_KEYDERIVATION); |
mbed_official | 610:813dcc80987e | 236 | |
mbed_official | 610:813dcc80987e | 237 | /* Configure the Key registers */ |
mbed_official | 610:813dcc80987e | 238 | if (CRYP_SetKey(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 239 | { |
mbed_official | 610:813dcc80987e | 240 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 241 | } |
mbed_official | 610:813dcc80987e | 242 | } |
mbed_official | 610:813dcc80987e | 243 | else |
mbed_official | 610:813dcc80987e | 244 | /* Encryption / Decryption (with or without key derivation) / authentication */ |
mbed_official | 610:813dcc80987e | 245 | { |
mbed_official | 610:813dcc80987e | 246 | /* Set data type, operating and chaining modes. |
mbed_official | 610:813dcc80987e | 247 | In case of GCM or GMAC, data type is forced to 0b00 */ |
mbed_official | 610:813dcc80987e | 248 | if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC) |
mbed_official | 610:813dcc80987e | 249 | { |
mbed_official | 610:813dcc80987e | 250 | MODIFY_REG(hcryp->Instance->CR, AES_CR_DATATYPE|AES_CR_MODE|AES_CR_CHMOD, hcryp->Init.OperatingMode|hcryp->Init.ChainingMode); |
mbed_official | 610:813dcc80987e | 251 | } |
mbed_official | 610:813dcc80987e | 252 | else |
mbed_official | 610:813dcc80987e | 253 | { |
mbed_official | 610:813dcc80987e | 254 | MODIFY_REG(hcryp->Instance->CR, AES_CR_DATATYPE|AES_CR_MODE|AES_CR_CHMOD, hcryp->Init.DataType|hcryp->Init.OperatingMode|hcryp->Init.ChainingMode); |
mbed_official | 610:813dcc80987e | 255 | } |
mbed_official | 610:813dcc80987e | 256 | |
mbed_official | 610:813dcc80987e | 257 | |
mbed_official | 610:813dcc80987e | 258 | /* Specify the encryption/decryption phase in case of Galois counter mode (GCM), |
mbed_official | 610:813dcc80987e | 259 | Galois message authentication code (GMAC) or cipher message authentication code (CMAC) */ |
mbed_official | 610:813dcc80987e | 260 | if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC) |
mbed_official | 610:813dcc80987e | 261 | || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)) |
mbed_official | 610:813dcc80987e | 262 | { |
mbed_official | 610:813dcc80987e | 263 | MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, hcryp->Init.GCMCMACPhase); |
mbed_official | 610:813dcc80987e | 264 | hcryp->Phase = HAL_CRYP_PHASE_START; |
mbed_official | 610:813dcc80987e | 265 | } |
mbed_official | 610:813dcc80987e | 266 | |
mbed_official | 610:813dcc80987e | 267 | |
mbed_official | 610:813dcc80987e | 268 | /* Configure the Key registers if no need to bypass this step */ |
mbed_official | 610:813dcc80987e | 269 | if (hcryp->Init.KeyWriteFlag == CRYP_KEY_WRITE_ENABLE) |
mbed_official | 610:813dcc80987e | 270 | { |
mbed_official | 610:813dcc80987e | 271 | if (CRYP_SetKey(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 272 | { |
mbed_official | 610:813dcc80987e | 273 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 274 | } |
mbed_official | 610:813dcc80987e | 275 | } |
mbed_official | 610:813dcc80987e | 276 | |
mbed_official | 610:813dcc80987e | 277 | /* If applicable, configure the Initialization Vector */ |
mbed_official | 610:813dcc80987e | 278 | if (hcryp->Init.ChainingMode != CRYP_CHAINMODE_AES_ECB) |
mbed_official | 610:813dcc80987e | 279 | { |
mbed_official | 610:813dcc80987e | 280 | if (CRYP_SetInitVector(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 281 | { |
mbed_official | 610:813dcc80987e | 282 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 283 | } |
mbed_official | 610:813dcc80987e | 284 | } |
mbed_official | 610:813dcc80987e | 285 | } |
mbed_official | 610:813dcc80987e | 286 | |
mbed_official | 610:813dcc80987e | 287 | /* Reset CrypInCount and CrypOutCount */ |
mbed_official | 610:813dcc80987e | 288 | hcryp->CrypInCount = 0; |
mbed_official | 610:813dcc80987e | 289 | hcryp->CrypOutCount = 0; |
mbed_official | 610:813dcc80987e | 290 | |
mbed_official | 610:813dcc80987e | 291 | /* Reset ErrorCode field */ |
mbed_official | 610:813dcc80987e | 292 | hcryp->ErrorCode = HAL_CRYP_ERROR_NONE; |
mbed_official | 610:813dcc80987e | 293 | |
mbed_official | 610:813dcc80987e | 294 | /* Reset Mode suspension request */ |
mbed_official | 610:813dcc80987e | 295 | hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE; |
mbed_official | 610:813dcc80987e | 296 | |
mbed_official | 610:813dcc80987e | 297 | /* Change the CRYP state */ |
mbed_official | 610:813dcc80987e | 298 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 610:813dcc80987e | 299 | |
mbed_official | 610:813dcc80987e | 300 | /* Enable the Peripheral */ |
mbed_official | 610:813dcc80987e | 301 | __HAL_CRYP_ENABLE(); |
mbed_official | 610:813dcc80987e | 302 | |
mbed_official | 610:813dcc80987e | 303 | /* Return function status */ |
mbed_official | 610:813dcc80987e | 304 | return HAL_OK; |
mbed_official | 610:813dcc80987e | 305 | } |
mbed_official | 610:813dcc80987e | 306 | |
mbed_official | 610:813dcc80987e | 307 | /** |
mbed_official | 610:813dcc80987e | 308 | * @brief DeInitialize the CRYP peripheral. |
mbed_official | 610:813dcc80987e | 309 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 310 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 311 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 312 | */ |
mbed_official | 610:813dcc80987e | 313 | HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 314 | { |
mbed_official | 610:813dcc80987e | 315 | /* Check the CRYP handle allocation */ |
mbed_official | 610:813dcc80987e | 316 | if(hcryp == NULL) |
mbed_official | 610:813dcc80987e | 317 | { |
mbed_official | 610:813dcc80987e | 318 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 319 | } |
mbed_official | 610:813dcc80987e | 320 | |
mbed_official | 610:813dcc80987e | 321 | /* Change the CRYP state */ |
mbed_official | 610:813dcc80987e | 322 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 610:813dcc80987e | 323 | |
mbed_official | 610:813dcc80987e | 324 | /* Set the default CRYP phase */ |
mbed_official | 610:813dcc80987e | 325 | hcryp->Phase = HAL_CRYP_PHASE_READY; |
mbed_official | 610:813dcc80987e | 326 | |
mbed_official | 610:813dcc80987e | 327 | /* Reset CrypInCount and CrypOutCount */ |
mbed_official | 610:813dcc80987e | 328 | hcryp->CrypInCount = 0; |
mbed_official | 610:813dcc80987e | 329 | hcryp->CrypOutCount = 0; |
mbed_official | 610:813dcc80987e | 330 | |
mbed_official | 610:813dcc80987e | 331 | /* Disable the CRYP Peripheral Clock */ |
mbed_official | 610:813dcc80987e | 332 | __HAL_CRYP_DISABLE(); |
mbed_official | 610:813dcc80987e | 333 | |
mbed_official | 610:813dcc80987e | 334 | /* DeInit the low level hardware: CLOCK, NVIC.*/ |
mbed_official | 610:813dcc80987e | 335 | HAL_CRYP_MspDeInit(hcryp); |
mbed_official | 610:813dcc80987e | 336 | |
mbed_official | 610:813dcc80987e | 337 | /* Change the CRYP state */ |
mbed_official | 610:813dcc80987e | 338 | hcryp->State = HAL_CRYP_STATE_RESET; |
mbed_official | 610:813dcc80987e | 339 | |
mbed_official | 610:813dcc80987e | 340 | /* Release Lock */ |
mbed_official | 610:813dcc80987e | 341 | __HAL_UNLOCK(hcryp); |
mbed_official | 610:813dcc80987e | 342 | |
mbed_official | 610:813dcc80987e | 343 | /* Return function status */ |
mbed_official | 610:813dcc80987e | 344 | return HAL_OK; |
mbed_official | 610:813dcc80987e | 345 | } |
mbed_official | 610:813dcc80987e | 346 | |
mbed_official | 610:813dcc80987e | 347 | /** |
mbed_official | 610:813dcc80987e | 348 | * @brief Initialize the CRYP MSP. |
mbed_official | 610:813dcc80987e | 349 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 350 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 351 | * @retval None |
mbed_official | 610:813dcc80987e | 352 | */ |
mbed_official | 610:813dcc80987e | 353 | __weak void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 354 | { |
mbed_official | 610:813dcc80987e | 355 | /* NOTE : This function should not be modified; when the callback is needed, |
mbed_official | 610:813dcc80987e | 356 | the HAL_CRYP_MspInit can be implemented in the user file |
mbed_official | 610:813dcc80987e | 357 | */ |
mbed_official | 610:813dcc80987e | 358 | } |
mbed_official | 610:813dcc80987e | 359 | |
mbed_official | 610:813dcc80987e | 360 | /** |
mbed_official | 610:813dcc80987e | 361 | * @brief DeInitialize CRYP MSP. |
mbed_official | 610:813dcc80987e | 362 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 363 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 364 | * @retval None |
mbed_official | 610:813dcc80987e | 365 | */ |
mbed_official | 610:813dcc80987e | 366 | __weak void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 367 | { |
mbed_official | 610:813dcc80987e | 368 | /* NOTE : This function should not be modified; when the callback is needed, |
mbed_official | 610:813dcc80987e | 369 | the HAL_CRYP_MspDeInit can be implemented in the user file |
mbed_official | 610:813dcc80987e | 370 | */ |
mbed_official | 610:813dcc80987e | 371 | } |
mbed_official | 610:813dcc80987e | 372 | |
mbed_official | 610:813dcc80987e | 373 | /** |
mbed_official | 610:813dcc80987e | 374 | * @} |
mbed_official | 610:813dcc80987e | 375 | */ |
mbed_official | 610:813dcc80987e | 376 | |
mbed_official | 610:813dcc80987e | 377 | /** @defgroup CRYP_Group2 AES processing functions |
mbed_official | 610:813dcc80987e | 378 | * @brief Processing functions. |
mbed_official | 610:813dcc80987e | 379 | * |
mbed_official | 610:813dcc80987e | 380 | @verbatim |
mbed_official | 610:813dcc80987e | 381 | ============================================================================== |
mbed_official | 610:813dcc80987e | 382 | ##### AES processing functions ##### |
mbed_official | 610:813dcc80987e | 383 | ============================================================================== |
mbed_official | 610:813dcc80987e | 384 | [..] This section provides functions allowing to: |
mbed_official | 610:813dcc80987e | 385 | (+) Encrypt plaintext using AES algorithm in different chaining modes |
mbed_official | 610:813dcc80987e | 386 | (+) Decrypt cyphertext using AES algorithm in different chaining modes |
mbed_official | 610:813dcc80987e | 387 | [..] Three processing functions are available: |
mbed_official | 610:813dcc80987e | 388 | (+) Polling mode |
mbed_official | 610:813dcc80987e | 389 | (+) Interrupt mode |
mbed_official | 610:813dcc80987e | 390 | (+) DMA mode |
mbed_official | 610:813dcc80987e | 391 | |
mbed_official | 610:813dcc80987e | 392 | @endverbatim |
mbed_official | 610:813dcc80987e | 393 | * @{ |
mbed_official | 610:813dcc80987e | 394 | */ |
mbed_official | 610:813dcc80987e | 395 | |
mbed_official | 610:813dcc80987e | 396 | |
mbed_official | 610:813dcc80987e | 397 | /** |
mbed_official | 610:813dcc80987e | 398 | * @brief Encrypt pPlainData in AES ECB encryption mode. The cypher data are available in pCypherData. |
mbed_official | 610:813dcc80987e | 399 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 400 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 401 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 402 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 403 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 404 | * @param Timeout: Specify Timeout value |
mbed_official | 610:813dcc80987e | 405 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 406 | * resort to generic HAL_CRYPEx_AES() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 407 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 408 | */ |
mbed_official | 610:813dcc80987e | 409 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 610:813dcc80987e | 410 | { |
mbed_official | 610:813dcc80987e | 411 | /* Re-initialize AES IP with proper parameters */ |
mbed_official | 610:813dcc80987e | 412 | if (HAL_CRYP_DeInit(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 413 | { |
mbed_official | 610:813dcc80987e | 414 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 415 | } |
mbed_official | 610:813dcc80987e | 416 | hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT; |
mbed_official | 610:813dcc80987e | 417 | hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_ECB; |
mbed_official | 610:813dcc80987e | 418 | hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; |
mbed_official | 610:813dcc80987e | 419 | if (HAL_CRYP_Init(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 420 | { |
mbed_official | 610:813dcc80987e | 421 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 422 | } |
mbed_official | 610:813dcc80987e | 423 | |
mbed_official | 610:813dcc80987e | 424 | return HAL_CRYPEx_AES(hcryp, pPlainData, Size, pCypherData, Timeout); |
mbed_official | 610:813dcc80987e | 425 | } |
mbed_official | 610:813dcc80987e | 426 | |
mbed_official | 610:813dcc80987e | 427 | |
mbed_official | 610:813dcc80987e | 428 | /** |
mbed_official | 610:813dcc80987e | 429 | * @brief Encrypt pPlainData in AES CBC encryption mode with key derivation. The cypher data are available in pCypherData. |
mbed_official | 610:813dcc80987e | 430 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 431 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 432 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 433 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 434 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 435 | * @param Timeout: Specify Timeout value |
mbed_official | 610:813dcc80987e | 436 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 437 | * resort to generic HAL_CRYPEx_AES() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 438 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 439 | */ |
mbed_official | 610:813dcc80987e | 440 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 610:813dcc80987e | 441 | { |
mbed_official | 610:813dcc80987e | 442 | /* Re-initialize AES IP with proper parameters */ |
mbed_official | 610:813dcc80987e | 443 | if (HAL_CRYP_DeInit(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 444 | { |
mbed_official | 610:813dcc80987e | 445 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 446 | } |
mbed_official | 610:813dcc80987e | 447 | hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT; |
mbed_official | 610:813dcc80987e | 448 | hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CBC; |
mbed_official | 610:813dcc80987e | 449 | hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; |
mbed_official | 610:813dcc80987e | 450 | if (HAL_CRYP_Init(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 451 | { |
mbed_official | 610:813dcc80987e | 452 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 453 | } |
mbed_official | 610:813dcc80987e | 454 | |
mbed_official | 610:813dcc80987e | 455 | return HAL_CRYPEx_AES(hcryp, pPlainData, Size, pCypherData, Timeout); |
mbed_official | 610:813dcc80987e | 456 | } |
mbed_official | 610:813dcc80987e | 457 | |
mbed_official | 610:813dcc80987e | 458 | |
mbed_official | 610:813dcc80987e | 459 | /** |
mbed_official | 610:813dcc80987e | 460 | * @brief Encrypt pPlainData in AES CTR encryption mode. The cypher data are available in pCypherData |
mbed_official | 610:813dcc80987e | 461 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 462 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 463 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 464 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 465 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 466 | * @param Timeout: Specify Timeout value |
mbed_official | 610:813dcc80987e | 467 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 468 | * resort to generic HAL_CRYPEx_AES() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 469 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 470 | */ |
mbed_official | 610:813dcc80987e | 471 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 610:813dcc80987e | 472 | { |
mbed_official | 610:813dcc80987e | 473 | /* Re-initialize AES IP with proper parameters */ |
mbed_official | 610:813dcc80987e | 474 | if (HAL_CRYP_DeInit(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 475 | { |
mbed_official | 610:813dcc80987e | 476 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 477 | } |
mbed_official | 610:813dcc80987e | 478 | hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT; |
mbed_official | 610:813dcc80987e | 479 | hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR; |
mbed_official | 610:813dcc80987e | 480 | hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; |
mbed_official | 610:813dcc80987e | 481 | if (HAL_CRYP_Init(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 482 | { |
mbed_official | 610:813dcc80987e | 483 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 484 | } |
mbed_official | 610:813dcc80987e | 485 | |
mbed_official | 610:813dcc80987e | 486 | return HAL_CRYPEx_AES(hcryp, pPlainData, Size, pCypherData, Timeout); |
mbed_official | 610:813dcc80987e | 487 | } |
mbed_official | 610:813dcc80987e | 488 | |
mbed_official | 610:813dcc80987e | 489 | /** |
mbed_official | 610:813dcc80987e | 490 | * @brief Decrypt pCypherData in AES ECB decryption mode with key derivation, |
mbed_official | 610:813dcc80987e | 491 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 492 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 493 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 494 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 495 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 496 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 497 | * @param Timeout: Specify Timeout value |
mbed_official | 610:813dcc80987e | 498 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 499 | * resort to generic HAL_CRYPEx_AES() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 500 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 501 | */ |
mbed_official | 610:813dcc80987e | 502 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
mbed_official | 610:813dcc80987e | 503 | { |
mbed_official | 610:813dcc80987e | 504 | /* Re-initialize AES IP with proper parameters */ |
mbed_official | 610:813dcc80987e | 505 | if (HAL_CRYP_DeInit(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 506 | { |
mbed_official | 610:813dcc80987e | 507 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 508 | } |
mbed_official | 610:813dcc80987e | 509 | hcryp->Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT; |
mbed_official | 610:813dcc80987e | 510 | hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_ECB; |
mbed_official | 610:813dcc80987e | 511 | hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; |
mbed_official | 610:813dcc80987e | 512 | if (HAL_CRYP_Init(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 513 | { |
mbed_official | 610:813dcc80987e | 514 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 515 | } |
mbed_official | 610:813dcc80987e | 516 | |
mbed_official | 610:813dcc80987e | 517 | return HAL_CRYPEx_AES(hcryp, pCypherData, Size, pPlainData, Timeout); |
mbed_official | 610:813dcc80987e | 518 | } |
mbed_official | 610:813dcc80987e | 519 | |
mbed_official | 610:813dcc80987e | 520 | /** |
mbed_official | 610:813dcc80987e | 521 | * @brief Decrypt pCypherData in AES ECB decryption mode with key derivation, |
mbed_official | 610:813dcc80987e | 522 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 523 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 524 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 525 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 526 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 527 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 528 | * @param Timeout: Specify Timeout value |
mbed_official | 610:813dcc80987e | 529 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 530 | * resort to generic HAL_CRYPEx_AES() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 531 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 532 | */ |
mbed_official | 610:813dcc80987e | 533 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
mbed_official | 610:813dcc80987e | 534 | { |
mbed_official | 610:813dcc80987e | 535 | /* Re-initialize AES IP with proper parameters */ |
mbed_official | 610:813dcc80987e | 536 | if (HAL_CRYP_DeInit(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 537 | { |
mbed_official | 610:813dcc80987e | 538 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 539 | } |
mbed_official | 610:813dcc80987e | 540 | hcryp->Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT; |
mbed_official | 610:813dcc80987e | 541 | hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CBC; |
mbed_official | 610:813dcc80987e | 542 | hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; |
mbed_official | 610:813dcc80987e | 543 | if (HAL_CRYP_Init(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 544 | { |
mbed_official | 610:813dcc80987e | 545 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 546 | } |
mbed_official | 610:813dcc80987e | 547 | |
mbed_official | 610:813dcc80987e | 548 | return HAL_CRYPEx_AES(hcryp, pCypherData, Size, pPlainData, Timeout); |
mbed_official | 610:813dcc80987e | 549 | } |
mbed_official | 610:813dcc80987e | 550 | |
mbed_official | 610:813dcc80987e | 551 | /** |
mbed_official | 610:813dcc80987e | 552 | * @brief Decrypt pCypherData in AES CTR decryption mode, |
mbed_official | 610:813dcc80987e | 553 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 554 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 555 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 556 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 557 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 558 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 559 | * @param Timeout: Specify Timeout value |
mbed_official | 610:813dcc80987e | 560 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 561 | * resort to generic HAL_CRYPEx_AES() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 562 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 563 | */ |
mbed_official | 610:813dcc80987e | 564 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
mbed_official | 610:813dcc80987e | 565 | { |
mbed_official | 610:813dcc80987e | 566 | /* Re-initialize AES IP with proper parameters */ |
mbed_official | 610:813dcc80987e | 567 | if (HAL_CRYP_DeInit(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 568 | { |
mbed_official | 610:813dcc80987e | 569 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 570 | } |
mbed_official | 610:813dcc80987e | 571 | hcryp->Init.OperatingMode = CRYP_ALGOMODE_DECRYPT; |
mbed_official | 610:813dcc80987e | 572 | hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR; |
mbed_official | 610:813dcc80987e | 573 | hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; |
mbed_official | 610:813dcc80987e | 574 | if (HAL_CRYP_Init(hcryp) != HAL_OK) |
mbed_official | 610:813dcc80987e | 575 | { |
mbed_official | 610:813dcc80987e | 576 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 577 | } |
mbed_official | 610:813dcc80987e | 578 | |
mbed_official | 610:813dcc80987e | 579 | return HAL_CRYPEx_AES(hcryp, pCypherData, Size, pPlainData, Timeout); |
mbed_official | 610:813dcc80987e | 580 | } |
mbed_official | 610:813dcc80987e | 581 | |
mbed_official | 610:813dcc80987e | 582 | /** |
mbed_official | 610:813dcc80987e | 583 | * @brief Encrypt pPlainData in AES ECB encryption mode using Interrupt, |
mbed_official | 610:813dcc80987e | 584 | * the cypher data are available in pCypherData. |
mbed_official | 610:813dcc80987e | 585 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 586 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 587 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 588 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 589 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 590 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 591 | * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 592 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 593 | */ |
mbed_official | 610:813dcc80987e | 594 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 610:813dcc80987e | 595 | { |
mbed_official | 610:813dcc80987e | 596 | return HAL_CRYPEx_AES_IT(hcryp, pPlainData, Size, pCypherData); |
mbed_official | 610:813dcc80987e | 597 | } |
mbed_official | 610:813dcc80987e | 598 | |
mbed_official | 610:813dcc80987e | 599 | /** |
mbed_official | 610:813dcc80987e | 600 | * @brief Encrypt pPlainData in AES CBC encryption mode using Interrupt, |
mbed_official | 610:813dcc80987e | 601 | * the cypher data are available in pCypherData. |
mbed_official | 610:813dcc80987e | 602 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 603 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 604 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 605 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 606 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 607 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 608 | * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 609 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 610 | */ |
mbed_official | 610:813dcc80987e | 611 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 610:813dcc80987e | 612 | { |
mbed_official | 610:813dcc80987e | 613 | return HAL_CRYPEx_AES_IT(hcryp, pPlainData, Size, pCypherData); |
mbed_official | 610:813dcc80987e | 614 | } |
mbed_official | 610:813dcc80987e | 615 | |
mbed_official | 610:813dcc80987e | 616 | |
mbed_official | 610:813dcc80987e | 617 | /** |
mbed_official | 610:813dcc80987e | 618 | * @brief Encrypt pPlainData in AES CTR encryption mode using Interrupt, |
mbed_official | 610:813dcc80987e | 619 | * the cypher data are available in pCypherData. |
mbed_official | 610:813dcc80987e | 620 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 621 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 622 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 623 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 624 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 625 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 626 | * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 627 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 628 | */ |
mbed_official | 610:813dcc80987e | 629 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 610:813dcc80987e | 630 | { |
mbed_official | 610:813dcc80987e | 631 | return HAL_CRYPEx_AES_IT(hcryp, pPlainData, Size, pCypherData); |
mbed_official | 610:813dcc80987e | 632 | } |
mbed_official | 610:813dcc80987e | 633 | |
mbed_official | 610:813dcc80987e | 634 | /** |
mbed_official | 610:813dcc80987e | 635 | * @brief Decrypt pCypherData in AES ECB decryption mode using Interrupt, |
mbed_official | 610:813dcc80987e | 636 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 637 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 638 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 639 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 640 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 641 | * @param pPlainData: Pointer to the plaintext buffer. |
mbed_official | 610:813dcc80987e | 642 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 643 | * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 644 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 645 | */ |
mbed_official | 610:813dcc80987e | 646 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 610:813dcc80987e | 647 | { |
mbed_official | 610:813dcc80987e | 648 | return HAL_CRYPEx_AES_IT(hcryp, pCypherData, Size, pPlainData); |
mbed_official | 610:813dcc80987e | 649 | } |
mbed_official | 610:813dcc80987e | 650 | |
mbed_official | 610:813dcc80987e | 651 | /** |
mbed_official | 610:813dcc80987e | 652 | * @brief Decrypt pCypherData in AES CBC decryption mode using Interrupt, |
mbed_official | 610:813dcc80987e | 653 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 654 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 655 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 656 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 657 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 658 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 659 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 660 | * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 661 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 662 | */ |
mbed_official | 610:813dcc80987e | 663 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 610:813dcc80987e | 664 | { |
mbed_official | 610:813dcc80987e | 665 | return HAL_CRYPEx_AES_IT(hcryp, pCypherData, Size, pPlainData); |
mbed_official | 610:813dcc80987e | 666 | } |
mbed_official | 610:813dcc80987e | 667 | |
mbed_official | 610:813dcc80987e | 668 | /** |
mbed_official | 610:813dcc80987e | 669 | * @brief Decrypt pCypherData in AES CTR decryption mode using Interrupt, |
mbed_official | 610:813dcc80987e | 670 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 671 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 672 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 673 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 674 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 675 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 676 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 677 | * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 678 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 679 | */ |
mbed_official | 610:813dcc80987e | 680 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 610:813dcc80987e | 681 | { |
mbed_official | 610:813dcc80987e | 682 | return HAL_CRYPEx_AES_IT(hcryp, pCypherData, Size, pPlainData); |
mbed_official | 610:813dcc80987e | 683 | } |
mbed_official | 610:813dcc80987e | 684 | |
mbed_official | 610:813dcc80987e | 685 | /** |
mbed_official | 610:813dcc80987e | 686 | * @brief Encrypt pPlainData in AES ECB encryption mode using DMA, |
mbed_official | 610:813dcc80987e | 687 | * the cypher data are available in pCypherData. |
mbed_official | 610:813dcc80987e | 688 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 689 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 690 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 691 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 692 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 693 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 694 | * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 695 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 696 | */ |
mbed_official | 610:813dcc80987e | 697 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 610:813dcc80987e | 698 | { |
mbed_official | 610:813dcc80987e | 699 | return HAL_CRYPEx_AES_DMA(hcryp, pPlainData, Size, pCypherData); |
mbed_official | 610:813dcc80987e | 700 | } |
mbed_official | 610:813dcc80987e | 701 | |
mbed_official | 610:813dcc80987e | 702 | |
mbed_official | 610:813dcc80987e | 703 | |
mbed_official | 610:813dcc80987e | 704 | /** |
mbed_official | 610:813dcc80987e | 705 | * @brief Encrypt pPlainData in AES CBC encryption mode using DMA, |
mbed_official | 610:813dcc80987e | 706 | * the cypher data are available in pCypherData. |
mbed_official | 610:813dcc80987e | 707 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 708 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 709 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 710 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 711 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 712 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 713 | * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 714 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 715 | */ |
mbed_official | 610:813dcc80987e | 716 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 610:813dcc80987e | 717 | { |
mbed_official | 610:813dcc80987e | 718 | return HAL_CRYPEx_AES_DMA(hcryp, pPlainData, Size, pCypherData); |
mbed_official | 610:813dcc80987e | 719 | } |
mbed_official | 610:813dcc80987e | 720 | |
mbed_official | 610:813dcc80987e | 721 | /** |
mbed_official | 610:813dcc80987e | 722 | * @brief Encrypt pPlainData in AES CTR encryption mode using DMA, |
mbed_official | 610:813dcc80987e | 723 | * the cypher data are available in pCypherData. |
mbed_official | 610:813dcc80987e | 724 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 725 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 726 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 727 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 728 | * @param pCypherData: Pointer to the cyphertext buffer. |
mbed_official | 610:813dcc80987e | 729 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 730 | * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 731 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 732 | */ |
mbed_official | 610:813dcc80987e | 733 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 610:813dcc80987e | 734 | { |
mbed_official | 610:813dcc80987e | 735 | return HAL_CRYPEx_AES_DMA(hcryp, pPlainData, Size, pCypherData); |
mbed_official | 610:813dcc80987e | 736 | } |
mbed_official | 610:813dcc80987e | 737 | |
mbed_official | 610:813dcc80987e | 738 | /** |
mbed_official | 610:813dcc80987e | 739 | * @brief Decrypt pCypherData in AES ECB decryption mode using DMA, |
mbed_official | 610:813dcc80987e | 740 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 741 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 742 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 743 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 744 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 745 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 746 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 747 | * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 748 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 749 | */ |
mbed_official | 610:813dcc80987e | 750 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 610:813dcc80987e | 751 | { |
mbed_official | 610:813dcc80987e | 752 | return HAL_CRYPEx_AES_DMA(hcryp, pCypherData, Size, pPlainData); |
mbed_official | 610:813dcc80987e | 753 | } |
mbed_official | 610:813dcc80987e | 754 | |
mbed_official | 610:813dcc80987e | 755 | /** |
mbed_official | 610:813dcc80987e | 756 | * @brief Decrypt pCypherData in AES CBC decryption mode using DMA, |
mbed_official | 610:813dcc80987e | 757 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 758 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 759 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 760 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 761 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 762 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 763 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 764 | * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 765 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 766 | */ |
mbed_official | 610:813dcc80987e | 767 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 610:813dcc80987e | 768 | { |
mbed_official | 610:813dcc80987e | 769 | return HAL_CRYPEx_AES_DMA(hcryp, pCypherData, Size, pPlainData); |
mbed_official | 610:813dcc80987e | 770 | } |
mbed_official | 610:813dcc80987e | 771 | |
mbed_official | 610:813dcc80987e | 772 | /** |
mbed_official | 610:813dcc80987e | 773 | * @brief Decrypt pCypherData in AES CTR decryption mode using DMA, |
mbed_official | 610:813dcc80987e | 774 | * the decyphered data are available in pPlainData. |
mbed_official | 610:813dcc80987e | 775 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 776 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 777 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 610:813dcc80987e | 778 | * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16. |
mbed_official | 610:813dcc80987e | 779 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 610:813dcc80987e | 780 | * @note This API is provided only to maintain compatibility with legacy software. Users should directly |
mbed_official | 610:813dcc80987e | 781 | * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended). |
mbed_official | 610:813dcc80987e | 782 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 783 | */ |
mbed_official | 610:813dcc80987e | 784 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 610:813dcc80987e | 785 | { |
mbed_official | 610:813dcc80987e | 786 | return HAL_CRYPEx_AES_DMA(hcryp, pCypherData, Size, pPlainData); |
mbed_official | 610:813dcc80987e | 787 | } |
mbed_official | 610:813dcc80987e | 788 | |
mbed_official | 610:813dcc80987e | 789 | |
mbed_official | 610:813dcc80987e | 790 | /** |
mbed_official | 610:813dcc80987e | 791 | * @} |
mbed_official | 610:813dcc80987e | 792 | */ |
mbed_official | 610:813dcc80987e | 793 | |
mbed_official | 610:813dcc80987e | 794 | /** @defgroup CRYP_Group3 Callback functions |
mbed_official | 610:813dcc80987e | 795 | * @brief Callback functions. |
mbed_official | 610:813dcc80987e | 796 | * |
mbed_official | 610:813dcc80987e | 797 | @verbatim |
mbed_official | 610:813dcc80987e | 798 | ============================================================================== |
mbed_official | 610:813dcc80987e | 799 | ##### Callback functions ##### |
mbed_official | 610:813dcc80987e | 800 | ============================================================================== |
mbed_official | 610:813dcc80987e | 801 | [..] This section provides Interruption and DMA callback functions: |
mbed_official | 610:813dcc80987e | 802 | (+) DMA Input data transfer complete |
mbed_official | 610:813dcc80987e | 803 | (+) DMA Output data transfer complete |
mbed_official | 610:813dcc80987e | 804 | (+) DMA or Interrupt error |
mbed_official | 610:813dcc80987e | 805 | |
mbed_official | 610:813dcc80987e | 806 | @endverbatim |
mbed_official | 610:813dcc80987e | 807 | * @{ |
mbed_official | 610:813dcc80987e | 808 | */ |
mbed_official | 610:813dcc80987e | 809 | |
mbed_official | 610:813dcc80987e | 810 | /** |
mbed_official | 610:813dcc80987e | 811 | * @brief CRYP error callback. |
mbed_official | 610:813dcc80987e | 812 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 813 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 814 | * @retval None |
mbed_official | 610:813dcc80987e | 815 | */ |
mbed_official | 610:813dcc80987e | 816 | __weak void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 817 | { |
mbed_official | 610:813dcc80987e | 818 | /* NOTE : This function should not be modified; when the callback is needed, |
mbed_official | 610:813dcc80987e | 819 | the HAL_CRYP_ErrorCallback can be implemented in the user file |
mbed_official | 610:813dcc80987e | 820 | */ |
mbed_official | 610:813dcc80987e | 821 | } |
mbed_official | 610:813dcc80987e | 822 | |
mbed_official | 610:813dcc80987e | 823 | /** |
mbed_official | 610:813dcc80987e | 824 | * @brief Input DMA transfer complete callback. |
mbed_official | 610:813dcc80987e | 825 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 826 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 827 | * @retval None |
mbed_official | 610:813dcc80987e | 828 | */ |
mbed_official | 610:813dcc80987e | 829 | __weak void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 830 | { |
mbed_official | 610:813dcc80987e | 831 | /* NOTE : This function should not be modified; when the callback is needed, |
mbed_official | 610:813dcc80987e | 832 | the HAL_CRYP_InCpltCallback can be implemented in the user file |
mbed_official | 610:813dcc80987e | 833 | */ |
mbed_official | 610:813dcc80987e | 834 | } |
mbed_official | 610:813dcc80987e | 835 | |
mbed_official | 610:813dcc80987e | 836 | /** |
mbed_official | 610:813dcc80987e | 837 | * @brief Output DMA transfer complete callback. |
mbed_official | 610:813dcc80987e | 838 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 839 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 840 | * @retval None |
mbed_official | 610:813dcc80987e | 841 | */ |
mbed_official | 610:813dcc80987e | 842 | __weak void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 843 | { |
mbed_official | 610:813dcc80987e | 844 | /* NOTE : This function should not be modified; when the callback is needed, |
mbed_official | 610:813dcc80987e | 845 | the HAL_CRYP_OutCpltCallback can be implemented in the user file |
mbed_official | 610:813dcc80987e | 846 | */ |
mbed_official | 610:813dcc80987e | 847 | } |
mbed_official | 610:813dcc80987e | 848 | |
mbed_official | 610:813dcc80987e | 849 | /** |
mbed_official | 610:813dcc80987e | 850 | * @} |
mbed_official | 610:813dcc80987e | 851 | */ |
mbed_official | 610:813dcc80987e | 852 | |
mbed_official | 610:813dcc80987e | 853 | /** @defgroup CRYP_Group4 CRYP IRQ handler |
mbed_official | 610:813dcc80987e | 854 | * @brief AES IRQ handler. |
mbed_official | 610:813dcc80987e | 855 | * |
mbed_official | 610:813dcc80987e | 856 | @verbatim |
mbed_official | 610:813dcc80987e | 857 | ============================================================================== |
mbed_official | 610:813dcc80987e | 858 | ##### AES IRQ handler management ##### |
mbed_official | 610:813dcc80987e | 859 | ============================================================================== |
mbed_official | 610:813dcc80987e | 860 | [..] This section provides AES IRQ handler function. |
mbed_official | 610:813dcc80987e | 861 | |
mbed_official | 610:813dcc80987e | 862 | @endverbatim |
mbed_official | 610:813dcc80987e | 863 | * @{ |
mbed_official | 610:813dcc80987e | 864 | */ |
mbed_official | 610:813dcc80987e | 865 | |
mbed_official | 610:813dcc80987e | 866 | /** |
mbed_official | 610:813dcc80987e | 867 | * @brief Handle AES interrupt request. |
mbed_official | 610:813dcc80987e | 868 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 869 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 870 | * @retval None |
mbed_official | 610:813dcc80987e | 871 | */ |
mbed_official | 610:813dcc80987e | 872 | void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 873 | { |
mbed_official | 610:813dcc80987e | 874 | /* Check if error occurred */ |
mbed_official | 610:813dcc80987e | 875 | if (__HAL_CRYP_GET_IT_SOURCE(CRYP_IT_ERRIE) != RESET) |
mbed_official | 610:813dcc80987e | 876 | { |
mbed_official | 610:813dcc80987e | 877 | /* If Write Error occurred */ |
mbed_official | 610:813dcc80987e | 878 | if (__HAL_CRYP_GET_FLAG(CRYP_IT_WRERR) != RESET) |
mbed_official | 610:813dcc80987e | 879 | { |
mbed_official | 610:813dcc80987e | 880 | hcryp->ErrorCode |= HAL_CRYP_WRITE_ERROR; |
mbed_official | 610:813dcc80987e | 881 | hcryp->State = HAL_CRYP_STATE_ERROR; |
mbed_official | 610:813dcc80987e | 882 | } |
mbed_official | 610:813dcc80987e | 883 | /* If Read Error occurred */ |
mbed_official | 610:813dcc80987e | 884 | if (__HAL_CRYP_GET_FLAG(CRYP_IT_RDERR) != RESET) |
mbed_official | 610:813dcc80987e | 885 | { |
mbed_official | 610:813dcc80987e | 886 | hcryp->ErrorCode |= HAL_CRYP_READ_ERROR; |
mbed_official | 610:813dcc80987e | 887 | hcryp->State = HAL_CRYP_STATE_ERROR; |
mbed_official | 610:813dcc80987e | 888 | } |
mbed_official | 610:813dcc80987e | 889 | |
mbed_official | 610:813dcc80987e | 890 | /* If an error has been reported */ |
mbed_official | 610:813dcc80987e | 891 | if (hcryp->State == HAL_CRYP_STATE_ERROR) |
mbed_official | 610:813dcc80987e | 892 | { |
mbed_official | 610:813dcc80987e | 893 | /* Disable Error and Computation Complete Interrupts */ |
mbed_official | 610:813dcc80987e | 894 | __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE); |
mbed_official | 610:813dcc80987e | 895 | /* Clear all Interrupt flags */ |
mbed_official | 610:813dcc80987e | 896 | __HAL_CRYP_CLEAR_FLAG(CRYP_ERR_CLEAR|CRYP_CCF_CLEAR); |
mbed_official | 610:813dcc80987e | 897 | |
mbed_official | 610:813dcc80987e | 898 | /* Process Unlocked */ |
mbed_official | 610:813dcc80987e | 899 | __HAL_UNLOCK(hcryp); |
mbed_official | 610:813dcc80987e | 900 | |
mbed_official | 610:813dcc80987e | 901 | HAL_CRYP_ErrorCallback(hcryp); |
mbed_official | 610:813dcc80987e | 902 | |
mbed_official | 610:813dcc80987e | 903 | return; |
mbed_official | 610:813dcc80987e | 904 | } |
mbed_official | 610:813dcc80987e | 905 | } |
mbed_official | 610:813dcc80987e | 906 | |
mbed_official | 610:813dcc80987e | 907 | /* Check if computation complete interrupt is enabled |
mbed_official | 610:813dcc80987e | 908 | and if the computation complete flag is raised */ |
mbed_official | 610:813dcc80987e | 909 | if((__HAL_CRYP_GET_FLAG(CRYP_IT_CCF) != RESET) && (__HAL_CRYP_GET_IT_SOURCE(CRYP_IT_CCFIE) != RESET)) |
mbed_official | 610:813dcc80987e | 910 | { |
mbed_official | 610:813dcc80987e | 911 | if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC) |
mbed_official | 610:813dcc80987e | 912 | || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)) |
mbed_official | 610:813dcc80987e | 913 | { |
mbed_official | 610:813dcc80987e | 914 | /* To ensure proper suspension requests management, CCF flag |
mbed_official | 610:813dcc80987e | 915 | is reset in CRYP_AES_Auth_IT() according to the current |
mbed_official | 610:813dcc80987e | 916 | phase under handling */ |
mbed_official | 610:813dcc80987e | 917 | CRYP_AES_Auth_IT(hcryp); |
mbed_official | 610:813dcc80987e | 918 | } |
mbed_official | 610:813dcc80987e | 919 | else |
mbed_official | 610:813dcc80987e | 920 | { |
mbed_official | 610:813dcc80987e | 921 | /* Clear Computation Complete Flag */ |
mbed_official | 610:813dcc80987e | 922 | __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR); |
mbed_official | 610:813dcc80987e | 923 | CRYP_AES_IT(hcryp); |
mbed_official | 610:813dcc80987e | 924 | } |
mbed_official | 610:813dcc80987e | 925 | } |
mbed_official | 610:813dcc80987e | 926 | } |
mbed_official | 610:813dcc80987e | 927 | |
mbed_official | 610:813dcc80987e | 928 | /** |
mbed_official | 610:813dcc80987e | 929 | * @} |
mbed_official | 610:813dcc80987e | 930 | */ |
mbed_official | 610:813dcc80987e | 931 | |
mbed_official | 610:813dcc80987e | 932 | /** @defgroup CRYP_Group5 Peripheral State functions |
mbed_official | 610:813dcc80987e | 933 | * @brief Peripheral State functions. |
mbed_official | 610:813dcc80987e | 934 | * |
mbed_official | 610:813dcc80987e | 935 | @verbatim |
mbed_official | 610:813dcc80987e | 936 | ============================================================================== |
mbed_official | 610:813dcc80987e | 937 | ##### Peripheral State functions ##### |
mbed_official | 610:813dcc80987e | 938 | ============================================================================== |
mbed_official | 610:813dcc80987e | 939 | [..] |
mbed_official | 610:813dcc80987e | 940 | This subsection permits to get in run-time the status of the peripheral. |
mbed_official | 610:813dcc80987e | 941 | |
mbed_official | 610:813dcc80987e | 942 | @endverbatim |
mbed_official | 610:813dcc80987e | 943 | * @{ |
mbed_official | 610:813dcc80987e | 944 | */ |
mbed_official | 610:813dcc80987e | 945 | |
mbed_official | 610:813dcc80987e | 946 | /** |
mbed_official | 610:813dcc80987e | 947 | * @brief Return the CRYP handle state. |
mbed_official | 610:813dcc80987e | 948 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 949 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 950 | * @retval HAL state |
mbed_official | 610:813dcc80987e | 951 | */ |
mbed_official | 610:813dcc80987e | 952 | HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 953 | { |
mbed_official | 610:813dcc80987e | 954 | /* Return CRYP handle state */ |
mbed_official | 610:813dcc80987e | 955 | return hcryp->State; |
mbed_official | 610:813dcc80987e | 956 | } |
mbed_official | 610:813dcc80987e | 957 | |
mbed_official | 610:813dcc80987e | 958 | /** |
mbed_official | 610:813dcc80987e | 959 | * @brief Return the CRYP peripheral error. |
mbed_official | 610:813dcc80987e | 960 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 961 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 962 | * @note The returned error is a bit-map combination of possible errors |
mbed_official | 610:813dcc80987e | 963 | * @retval Error bit-map |
mbed_official | 610:813dcc80987e | 964 | */ |
mbed_official | 610:813dcc80987e | 965 | uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 966 | { |
mbed_official | 610:813dcc80987e | 967 | return hcryp->ErrorCode; |
mbed_official | 610:813dcc80987e | 968 | } |
mbed_official | 610:813dcc80987e | 969 | |
mbed_official | 610:813dcc80987e | 970 | /** |
mbed_official | 610:813dcc80987e | 971 | * @} |
mbed_official | 610:813dcc80987e | 972 | */ |
mbed_official | 610:813dcc80987e | 973 | |
mbed_official | 610:813dcc80987e | 974 | /** |
mbed_official | 610:813dcc80987e | 975 | * @} |
mbed_official | 610:813dcc80987e | 976 | */ |
mbed_official | 610:813dcc80987e | 977 | |
mbed_official | 610:813dcc80987e | 978 | /** @addtogroup CRYP_Private_Functions |
mbed_official | 610:813dcc80987e | 979 | * @{ |
mbed_official | 610:813dcc80987e | 980 | */ |
mbed_official | 610:813dcc80987e | 981 | |
mbed_official | 610:813dcc80987e | 982 | |
mbed_official | 610:813dcc80987e | 983 | /** |
mbed_official | 610:813dcc80987e | 984 | * @brief Write the Key in KeyRx registers. |
mbed_official | 610:813dcc80987e | 985 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 986 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 987 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 988 | */ |
mbed_official | 610:813dcc80987e | 989 | static HAL_StatusTypeDef CRYP_SetKey(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 990 | { |
mbed_official | 610:813dcc80987e | 991 | uint32_t keyaddr = 0x0; |
mbed_official | 610:813dcc80987e | 992 | |
mbed_official | 610:813dcc80987e | 993 | if (hcryp->Init.pKey == NULL) |
mbed_official | 610:813dcc80987e | 994 | { |
mbed_official | 610:813dcc80987e | 995 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 996 | } |
mbed_official | 610:813dcc80987e | 997 | |
mbed_official | 610:813dcc80987e | 998 | keyaddr = (uint32_t)(hcryp->Init.pKey); |
mbed_official | 610:813dcc80987e | 999 | |
mbed_official | 610:813dcc80987e | 1000 | if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B) |
mbed_official | 610:813dcc80987e | 1001 | { |
mbed_official | 610:813dcc80987e | 1002 | hcryp->Instance->KEYR7 = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 610:813dcc80987e | 1003 | keyaddr+=4; |
mbed_official | 610:813dcc80987e | 1004 | hcryp->Instance->KEYR6 = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 610:813dcc80987e | 1005 | keyaddr+=4; |
mbed_official | 610:813dcc80987e | 1006 | hcryp->Instance->KEYR5 = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 610:813dcc80987e | 1007 | keyaddr+=4; |
mbed_official | 610:813dcc80987e | 1008 | hcryp->Instance->KEYR4 = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 610:813dcc80987e | 1009 | keyaddr+=4; |
mbed_official | 610:813dcc80987e | 1010 | } |
mbed_official | 610:813dcc80987e | 1011 | |
mbed_official | 610:813dcc80987e | 1012 | hcryp->Instance->KEYR3 = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 610:813dcc80987e | 1013 | keyaddr+=4; |
mbed_official | 610:813dcc80987e | 1014 | hcryp->Instance->KEYR2 = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 610:813dcc80987e | 1015 | keyaddr+=4; |
mbed_official | 610:813dcc80987e | 1016 | hcryp->Instance->KEYR1 = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 610:813dcc80987e | 1017 | keyaddr+=4; |
mbed_official | 610:813dcc80987e | 1018 | hcryp->Instance->KEYR0 = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 610:813dcc80987e | 1019 | |
mbed_official | 610:813dcc80987e | 1020 | return HAL_OK; |
mbed_official | 610:813dcc80987e | 1021 | } |
mbed_official | 610:813dcc80987e | 1022 | |
mbed_official | 610:813dcc80987e | 1023 | /** |
mbed_official | 610:813dcc80987e | 1024 | * @brief Write the InitVector/InitCounter in IVRx registers. |
mbed_official | 610:813dcc80987e | 1025 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 1026 | * the configuration information for CRYP module |
mbed_official | 610:813dcc80987e | 1027 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 1028 | */ |
mbed_official | 610:813dcc80987e | 1029 | static HAL_StatusTypeDef CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 1030 | { |
mbed_official | 610:813dcc80987e | 1031 | uint32_t ivaddr = 0x0; |
mbed_official | 610:813dcc80987e | 1032 | |
mbed_official | 610:813dcc80987e | 1033 | if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC) |
mbed_official | 610:813dcc80987e | 1034 | { |
mbed_official | 610:813dcc80987e | 1035 | hcryp->Instance->IVR3 = 0; |
mbed_official | 610:813dcc80987e | 1036 | hcryp->Instance->IVR2 = 0; |
mbed_official | 610:813dcc80987e | 1037 | hcryp->Instance->IVR1 = 0; |
mbed_official | 610:813dcc80987e | 1038 | hcryp->Instance->IVR0 = 0; |
mbed_official | 610:813dcc80987e | 1039 | } |
mbed_official | 610:813dcc80987e | 1040 | else |
mbed_official | 610:813dcc80987e | 1041 | { |
mbed_official | 610:813dcc80987e | 1042 | if (hcryp->Init.pInitVect == NULL) |
mbed_official | 610:813dcc80987e | 1043 | { |
mbed_official | 610:813dcc80987e | 1044 | return HAL_ERROR; |
mbed_official | 610:813dcc80987e | 1045 | } |
mbed_official | 610:813dcc80987e | 1046 | |
mbed_official | 610:813dcc80987e | 1047 | ivaddr = (uint32_t)(hcryp->Init.pInitVect); |
mbed_official | 610:813dcc80987e | 1048 | |
mbed_official | 610:813dcc80987e | 1049 | hcryp->Instance->IVR3 = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 610:813dcc80987e | 1050 | ivaddr+=4; |
mbed_official | 610:813dcc80987e | 1051 | hcryp->Instance->IVR2 = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 610:813dcc80987e | 1052 | ivaddr+=4; |
mbed_official | 610:813dcc80987e | 1053 | hcryp->Instance->IVR1 = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 610:813dcc80987e | 1054 | ivaddr+=4; |
mbed_official | 610:813dcc80987e | 1055 | hcryp->Instance->IVR0 = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 610:813dcc80987e | 1056 | } |
mbed_official | 610:813dcc80987e | 1057 | return HAL_OK; |
mbed_official | 610:813dcc80987e | 1058 | } |
mbed_official | 610:813dcc80987e | 1059 | |
mbed_official | 610:813dcc80987e | 1060 | |
mbed_official | 610:813dcc80987e | 1061 | |
mbed_official | 610:813dcc80987e | 1062 | /** |
mbed_official | 610:813dcc80987e | 1063 | * @brief Handle CRYP block input/output data handling under interruption. |
mbed_official | 610:813dcc80987e | 1064 | * @note The function is called under interruption only, once |
mbed_official | 610:813dcc80987e | 1065 | * interruptions have been enabled by HAL_CRYPEx_AES_IT(). |
mbed_official | 610:813dcc80987e | 1066 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
mbed_official | 610:813dcc80987e | 1067 | * the configuration information for CRYP module. |
mbed_official | 610:813dcc80987e | 1068 | * @retval HAL status |
mbed_official | 610:813dcc80987e | 1069 | */ |
mbed_official | 610:813dcc80987e | 1070 | static HAL_StatusTypeDef CRYP_AES_IT(CRYP_HandleTypeDef *hcryp) |
mbed_official | 610:813dcc80987e | 1071 | { |
mbed_official | 610:813dcc80987e | 1072 | uint32_t inputaddr = 0; |
mbed_official | 610:813dcc80987e | 1073 | uint32_t outputaddr = 0; |
mbed_official | 610:813dcc80987e | 1074 | |
mbed_official | 610:813dcc80987e | 1075 | if(hcryp->State == HAL_CRYP_STATE_BUSY) |
mbed_official | 610:813dcc80987e | 1076 | { |
mbed_official | 610:813dcc80987e | 1077 | if (hcryp->Init.OperatingMode != CRYP_ALGOMODE_KEYDERIVATION) |
mbed_official | 610:813dcc80987e | 1078 | { |
mbed_official | 610:813dcc80987e | 1079 | /* Get the output data address */ |
mbed_official | 610:813dcc80987e | 1080 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 610:813dcc80987e | 1081 | |
mbed_official | 610:813dcc80987e | 1082 | /* Read the last available output block from the Data Output Register */ |
mbed_official | 610:813dcc80987e | 1083 | *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR; |
mbed_official | 610:813dcc80987e | 1084 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1085 | *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR; |
mbed_official | 610:813dcc80987e | 1086 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1087 | *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR; |
mbed_official | 610:813dcc80987e | 1088 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1089 | *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR; |
mbed_official | 610:813dcc80987e | 1090 | hcryp->pCrypOutBuffPtr += 16; |
mbed_official | 610:813dcc80987e | 1091 | hcryp->CrypOutCount -= 16; |
mbed_official | 610:813dcc80987e | 1092 | |
mbed_official | 610:813dcc80987e | 1093 | } |
mbed_official | 610:813dcc80987e | 1094 | else |
mbed_official | 610:813dcc80987e | 1095 | { |
mbed_official | 610:813dcc80987e | 1096 | /* Read the derived key from the Key registers */ |
mbed_official | 610:813dcc80987e | 1097 | if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B) |
mbed_official | 610:813dcc80987e | 1098 | { |
mbed_official | 610:813dcc80987e | 1099 | *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR7); |
mbed_official | 610:813dcc80987e | 1100 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1101 | *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR6); |
mbed_official | 610:813dcc80987e | 1102 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1103 | *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR5); |
mbed_official | 610:813dcc80987e | 1104 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1105 | *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR4); |
mbed_official | 610:813dcc80987e | 1106 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1107 | } |
mbed_official | 610:813dcc80987e | 1108 | |
mbed_official | 610:813dcc80987e | 1109 | *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR3); |
mbed_official | 610:813dcc80987e | 1110 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1111 | *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR2); |
mbed_official | 610:813dcc80987e | 1112 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1113 | *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR1); |
mbed_official | 610:813dcc80987e | 1114 | outputaddr+=4; |
mbed_official | 610:813dcc80987e | 1115 | *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR0); |
mbed_official | 610:813dcc80987e | 1116 | } |
mbed_official | 610:813dcc80987e | 1117 | |
mbed_official | 610:813dcc80987e | 1118 | /* In case of ciphering or deciphering, check if all output text has been retrieved; |
mbed_official | 610:813dcc80987e | 1119 | In case of key derivation, stop right there */ |
mbed_official | 610:813dcc80987e | 1120 | if ((hcryp->CrypOutCount == 0) || (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION)) |
mbed_official | 610:813dcc80987e | 1121 | { |
mbed_official | 610:813dcc80987e | 1122 | /* Disable Computation Complete Flag and Errors Interrupts */ |
mbed_official | 610:813dcc80987e | 1123 | __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE); |
mbed_official | 610:813dcc80987e | 1124 | /* Change the CRYP state */ |
mbed_official | 610:813dcc80987e | 1125 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 610:813dcc80987e | 1126 | |
mbed_official | 610:813dcc80987e | 1127 | /* Process Unlocked */ |
mbed_official | 610:813dcc80987e | 1128 | __HAL_UNLOCK(hcryp); |
mbed_official | 610:813dcc80987e | 1129 | |
mbed_official | 610:813dcc80987e | 1130 | /* Call computation complete callback */ |
mbed_official | 610:813dcc80987e | 1131 | HAL_CRYPEx_ComputationCpltCallback(hcryp); |
mbed_official | 610:813dcc80987e | 1132 | |
mbed_official | 610:813dcc80987e | 1133 | return HAL_OK; |
mbed_official | 610:813dcc80987e | 1134 | } |
mbed_official | 610:813dcc80987e | 1135 | /* If suspension flag has been raised, suspend processing */ |
mbed_official | 610:813dcc80987e | 1136 | else if (hcryp->SuspendRequest == HAL_CRYP_SUSPEND) |
mbed_official | 610:813dcc80987e | 1137 | { |
mbed_official | 610:813dcc80987e | 1138 | /* reset ModeSuspend */ |
mbed_official | 610:813dcc80987e | 1139 | hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE; |
mbed_official | 610:813dcc80987e | 1140 | |
mbed_official | 610:813dcc80987e | 1141 | /* Disable Computation Complete Flag and Errors Interrupts */ |
mbed_official | 610:813dcc80987e | 1142 | __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE); |
mbed_official | 610:813dcc80987e | 1143 | /* Change the CRYP state */ |
mbed_official | 610:813dcc80987e | 1144 | hcryp->State = HAL_CRYP_STATE_SUSPENDED; |
mbed_official | 610:813dcc80987e | 1145 | |
mbed_official | 610:813dcc80987e | 1146 | /* Process Unlocked */ |
mbed_official | 610:813dcc80987e | 1147 | __HAL_UNLOCK(hcryp); |
mbed_official | 610:813dcc80987e | 1148 | |
mbed_official | 610:813dcc80987e | 1149 | return HAL_OK; |
mbed_official | 610:813dcc80987e | 1150 | } |
mbed_official | 610:813dcc80987e | 1151 | else /* Process the rest of input data */ |
mbed_official | 610:813dcc80987e | 1152 | { |
mbed_official | 610:813dcc80987e | 1153 | /* Get the Intput data address */ |
mbed_official | 610:813dcc80987e | 1154 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 610:813dcc80987e | 1155 | |
mbed_official | 610:813dcc80987e | 1156 | /* Increment/decrement instance pointer/counter */ |
mbed_official | 610:813dcc80987e | 1157 | hcryp->pCrypInBuffPtr += 16; |
mbed_official | 610:813dcc80987e | 1158 | hcryp->CrypInCount -= 16; |
mbed_official | 610:813dcc80987e | 1159 | |
mbed_official | 610:813dcc80987e | 1160 | /* Write the next input block in the Data Input register */ |
mbed_official | 610:813dcc80987e | 1161 | hcryp->Instance->DINR = *(uint32_t*)(inputaddr); |
mbed_official | 610:813dcc80987e | 1162 | inputaddr+=4; |
mbed_official | 610:813dcc80987e | 1163 | hcryp->Instance->DINR = *(uint32_t*)(inputaddr); |
mbed_official | 610:813dcc80987e | 1164 | inputaddr+=4; |
mbed_official | 610:813dcc80987e | 1165 | hcryp->Instance->DINR = *(uint32_t*)(inputaddr); |
mbed_official | 610:813dcc80987e | 1166 | inputaddr+=4; |
mbed_official | 610:813dcc80987e | 1167 | hcryp->Instance->DINR = *(uint32_t*)(inputaddr); |
mbed_official | 610:813dcc80987e | 1168 | |
mbed_official | 610:813dcc80987e | 1169 | return HAL_OK; |
mbed_official | 610:813dcc80987e | 1170 | } |
mbed_official | 610:813dcc80987e | 1171 | } |
mbed_official | 610:813dcc80987e | 1172 | else |
mbed_official | 610:813dcc80987e | 1173 | { |
mbed_official | 610:813dcc80987e | 1174 | return HAL_BUSY; |
mbed_official | 610:813dcc80987e | 1175 | } |
mbed_official | 610:813dcc80987e | 1176 | } |
mbed_official | 610:813dcc80987e | 1177 | |
mbed_official | 610:813dcc80987e | 1178 | |
mbed_official | 610:813dcc80987e | 1179 | |
mbed_official | 610:813dcc80987e | 1180 | |
mbed_official | 610:813dcc80987e | 1181 | /** |
mbed_official | 610:813dcc80987e | 1182 | * @} |
mbed_official | 610:813dcc80987e | 1183 | */ |
mbed_official | 610:813dcc80987e | 1184 | |
mbed_official | 610:813dcc80987e | 1185 | |
mbed_official | 610:813dcc80987e | 1186 | |
mbed_official | 610:813dcc80987e | 1187 | /** |
mbed_official | 610:813dcc80987e | 1188 | * @} |
mbed_official | 610:813dcc80987e | 1189 | */ |
mbed_official | 610:813dcc80987e | 1190 | |
mbed_official | 610:813dcc80987e | 1191 | /** |
mbed_official | 610:813dcc80987e | 1192 | * @} |
mbed_official | 610:813dcc80987e | 1193 | */ |
mbed_official | 610:813dcc80987e | 1194 | |
mbed_official | 610:813dcc80987e | 1195 | #endif /* defined(STM32L485xx) || defined(STM32L486xx) */ |
mbed_official | 610:813dcc80987e | 1196 | |
mbed_official | 610:813dcc80987e | 1197 | #endif /* HAL_CRYP_MODULE_ENABLED */ |
mbed_official | 610:813dcc80987e | 1198 | |
mbed_official | 610:813dcc80987e | 1199 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |