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