fix LPC812 PWM
Fork of mbed-dev by
targets/cmsis/TARGET_STM/TARGET_STM32L1/stm32l1xx_hal_cryp.c@129:2e517c56bcfb, 2016-05-16 (annotated)
- Committer:
- nameless129
- Date:
- Mon May 16 16:50:30 2016 +0000
- Revision:
- 129:2e517c56bcfb
- Parent:
- 0:9b334a45a8ff
PWM Fix:Duty 0%??H???????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /** |
bogdanm | 0:9b334a45a8ff | 2 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 3 | * @file stm32l1xx_hal_cryp.c |
bogdanm | 0:9b334a45a8ff | 4 | * @author MCD Application Team |
bogdanm | 0:9b334a45a8ff | 5 | * @version V1.0.0 |
bogdanm | 0:9b334a45a8ff | 6 | * @date 5-September-2014 |
bogdanm | 0:9b334a45a8ff | 7 | * @brief CRYP HAL module driver. |
bogdanm | 0:9b334a45a8ff | 8 | * |
bogdanm | 0:9b334a45a8ff | 9 | * This file provides firmware functions to manage the following |
bogdanm | 0:9b334a45a8ff | 10 | * functionalities of the Cryptography (CRYP) peripheral: |
bogdanm | 0:9b334a45a8ff | 11 | * + Initialization and de-initialization functions |
bogdanm | 0:9b334a45a8ff | 12 | * + Processing functions by algorithm using polling mode |
bogdanm | 0:9b334a45a8ff | 13 | * + Processing functions by algorithm using interrupt mode |
bogdanm | 0:9b334a45a8ff | 14 | * + Processing functions by algorithm using DMA mode |
bogdanm | 0:9b334a45a8ff | 15 | * + Peripheral State functions |
bogdanm | 0:9b334a45a8ff | 16 | * |
bogdanm | 0:9b334a45a8ff | 17 | @verbatim |
bogdanm | 0:9b334a45a8ff | 18 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 19 | ##### How to use this driver ##### |
bogdanm | 0:9b334a45a8ff | 20 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 21 | [..] |
bogdanm | 0:9b334a45a8ff | 22 | The CRYP HAL driver can be used as follows: |
bogdanm | 0:9b334a45a8ff | 23 | |
bogdanm | 0:9b334a45a8ff | 24 | (#)Initialize the CRYP low level resources by implementing the HAL_CRYP_MspInit(): |
bogdanm | 0:9b334a45a8ff | 25 | (##) Enable the CRYP interface clock using __CRYP_CLK_ENABLE() |
bogdanm | 0:9b334a45a8ff | 26 | (##) In case of using interrupts (e.g. HAL_CRYP_AESECB_Encrypt_IT()) |
bogdanm | 0:9b334a45a8ff | 27 | (+) Configure the CRYP interrupt priority using HAL_NVIC_SetPriority() |
bogdanm | 0:9b334a45a8ff | 28 | (+) Enable the CRYP IRQ handler using HAL_NVIC_EnableIRQ() |
bogdanm | 0:9b334a45a8ff | 29 | (+) In CRYP IRQ handler, call HAL_CRYP_IRQHandler() |
bogdanm | 0:9b334a45a8ff | 30 | (##) In case of using DMA to control data transfer (e.g. HAL_CRYP_AESECB_Encrypt_DMA()) |
bogdanm | 0:9b334a45a8ff | 31 | (+) Enable the DMA2 interface clock using |
bogdanm | 0:9b334a45a8ff | 32 | (++) __DMA2_CLK_ENABLE() |
bogdanm | 0:9b334a45a8ff | 33 | (+) Configure and enable two DMA Channels one for managing data transfer from |
bogdanm | 0:9b334a45a8ff | 34 | memory to peripheral (input channel) and another channel for managing data |
bogdanm | 0:9b334a45a8ff | 35 | transfer from peripheral to memory (output channel) |
bogdanm | 0:9b334a45a8ff | 36 | (+) Associate the initialized DMA handle to the CRYP DMA handle |
bogdanm | 0:9b334a45a8ff | 37 | using __HAL_LINKDMA() |
bogdanm | 0:9b334a45a8ff | 38 | (+) Configure the priority and enable the NVIC for the transfer complete |
bogdanm | 0:9b334a45a8ff | 39 | interrupt on the two DMA Streams. The output stream should have higher |
bogdanm | 0:9b334a45a8ff | 40 | priority than the input stream. |
bogdanm | 0:9b334a45a8ff | 41 | (++) HAL_NVIC_SetPriority() |
bogdanm | 0:9b334a45a8ff | 42 | (++) HAL_NVIC_EnableIRQ() |
bogdanm | 0:9b334a45a8ff | 43 | |
bogdanm | 0:9b334a45a8ff | 44 | (#)Initialize the CRYP HAL using HAL_CRYP_Init(). This function configures mainly: |
bogdanm | 0:9b334a45a8ff | 45 | (##) The data type: 1-bit, 8-bit, 16-bit and 32-bit |
bogdanm | 0:9b334a45a8ff | 46 | (##) The encryption/decryption key. |
bogdanm | 0:9b334a45a8ff | 47 | (##) The initialization vector (counter). It is not used ECB mode. |
bogdanm | 0:9b334a45a8ff | 48 | |
bogdanm | 0:9b334a45a8ff | 49 | (#)Three processing (encryption/decryption) functions are available: |
bogdanm | 0:9b334a45a8ff | 50 | (##) Polling mode: encryption and decryption APIs are blocking functions |
bogdanm | 0:9b334a45a8ff | 51 | i.e. they process the data and wait till the processing is finished |
bogdanm | 0:9b334a45a8ff | 52 | e.g. HAL_CRYP_AESCBC_Encrypt() |
bogdanm | 0:9b334a45a8ff | 53 | (##) Interrupt mode: encryption and decryption APIs are not blocking functions |
bogdanm | 0:9b334a45a8ff | 54 | i.e. they process the data under interrupt |
bogdanm | 0:9b334a45a8ff | 55 | e.g. HAL_CRYP_AESCBC_Encrypt_IT() |
bogdanm | 0:9b334a45a8ff | 56 | (##) DMA mode: encryption and decryption APIs are not blocking functions |
bogdanm | 0:9b334a45a8ff | 57 | i.e. the data transfer is ensured by DMA |
bogdanm | 0:9b334a45a8ff | 58 | e.g. HAL_CRYP_AESCBC_Encrypt_DMA() |
bogdanm | 0:9b334a45a8ff | 59 | |
bogdanm | 0:9b334a45a8ff | 60 | (#)When the processing function is called for the first time after HAL_CRYP_Init() |
bogdanm | 0:9b334a45a8ff | 61 | the CRYP peripheral is initialized and processes the buffer in input. |
bogdanm | 0:9b334a45a8ff | 62 | At second call, the processing function performs an append of the already |
bogdanm | 0:9b334a45a8ff | 63 | processed buffer. |
bogdanm | 0:9b334a45a8ff | 64 | When a new data block is to be processed, call HAL_CRYP_Init() then the |
bogdanm | 0:9b334a45a8ff | 65 | processing function. |
bogdanm | 0:9b334a45a8ff | 66 | |
bogdanm | 0:9b334a45a8ff | 67 | (#)Call HAL_CRYP_DeInit() to deinitialize the CRYP peripheral. |
bogdanm | 0:9b334a45a8ff | 68 | |
bogdanm | 0:9b334a45a8ff | 69 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 70 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 71 | * @attention |
bogdanm | 0:9b334a45a8ff | 72 | * |
bogdanm | 0:9b334a45a8ff | 73 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
bogdanm | 0:9b334a45a8ff | 74 | * |
bogdanm | 0:9b334a45a8ff | 75 | * Redistribution and use in source and binary forms, with or without modification, |
bogdanm | 0:9b334a45a8ff | 76 | * are permitted provided that the following conditions are met: |
bogdanm | 0:9b334a45a8ff | 77 | * 1. Redistributions of source code must retain the above copyright notice, |
bogdanm | 0:9b334a45a8ff | 78 | * this list of conditions and the following disclaimer. |
bogdanm | 0:9b334a45a8ff | 79 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
bogdanm | 0:9b334a45a8ff | 80 | * this list of conditions and the following disclaimer in the documentation |
bogdanm | 0:9b334a45a8ff | 81 | * and/or other materials provided with the distribution. |
bogdanm | 0:9b334a45a8ff | 82 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
bogdanm | 0:9b334a45a8ff | 83 | * may be used to endorse or promote products derived from this software |
bogdanm | 0:9b334a45a8ff | 84 | * without specific prior written permission. |
bogdanm | 0:9b334a45a8ff | 85 | * |
bogdanm | 0:9b334a45a8ff | 86 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
bogdanm | 0:9b334a45a8ff | 87 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
bogdanm | 0:9b334a45a8ff | 88 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bogdanm | 0:9b334a45a8ff | 89 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
bogdanm | 0:9b334a45a8ff | 90 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
bogdanm | 0:9b334a45a8ff | 91 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
bogdanm | 0:9b334a45a8ff | 92 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
bogdanm | 0:9b334a45a8ff | 93 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
bogdanm | 0:9b334a45a8ff | 94 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
bogdanm | 0:9b334a45a8ff | 95 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bogdanm | 0:9b334a45a8ff | 96 | * |
bogdanm | 0:9b334a45a8ff | 97 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 98 | */ |
bogdanm | 0:9b334a45a8ff | 99 | |
bogdanm | 0:9b334a45a8ff | 100 | /* Includes ------------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 101 | #include "stm32l1xx_hal.h" |
bogdanm | 0:9b334a45a8ff | 102 | |
bogdanm | 0:9b334a45a8ff | 103 | #ifdef HAL_CRYP_MODULE_ENABLED |
bogdanm | 0:9b334a45a8ff | 104 | |
bogdanm | 0:9b334a45a8ff | 105 | /** @addtogroup STM32L1xx_HAL_Driver |
bogdanm | 0:9b334a45a8ff | 106 | * @{ |
bogdanm | 0:9b334a45a8ff | 107 | */ |
bogdanm | 0:9b334a45a8ff | 108 | |
bogdanm | 0:9b334a45a8ff | 109 | /** @defgroup CRYP CRYP |
bogdanm | 0:9b334a45a8ff | 110 | * @brief CRYP HAL module driver. |
bogdanm | 0:9b334a45a8ff | 111 | * @{ |
bogdanm | 0:9b334a45a8ff | 112 | */ |
bogdanm | 0:9b334a45a8ff | 113 | |
bogdanm | 0:9b334a45a8ff | 114 | #if defined(STM32L162xC) || defined(STM32L162xCA) || defined(STM32L162xD) || defined(STM32L162xE) |
bogdanm | 0:9b334a45a8ff | 115 | |
bogdanm | 0:9b334a45a8ff | 116 | /* Private typedef -----------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 117 | /* Private define ------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 118 | |
bogdanm | 0:9b334a45a8ff | 119 | /** @defgroup CRYP_Private_Defines CRYP Private Defines |
bogdanm | 0:9b334a45a8ff | 120 | * @{ |
bogdanm | 0:9b334a45a8ff | 121 | */ |
bogdanm | 0:9b334a45a8ff | 122 | |
bogdanm | 0:9b334a45a8ff | 123 | #define CRYP_ALGO_CHAIN_MASK (AES_CR_MODE | AES_CR_CHMOD) |
bogdanm | 0:9b334a45a8ff | 124 | |
bogdanm | 0:9b334a45a8ff | 125 | /** |
bogdanm | 0:9b334a45a8ff | 126 | * @} |
bogdanm | 0:9b334a45a8ff | 127 | */ |
bogdanm | 0:9b334a45a8ff | 128 | |
bogdanm | 0:9b334a45a8ff | 129 | /* Private macro -------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 130 | /* Private variables ---------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 131 | /* Private function prototypes -----------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 132 | |
bogdanm | 0:9b334a45a8ff | 133 | /** @defgroup CRYP_Private_Functions CRYP Private Functions |
bogdanm | 0:9b334a45a8ff | 134 | * @{ |
bogdanm | 0:9b334a45a8ff | 135 | */ |
bogdanm | 0:9b334a45a8ff | 136 | |
bogdanm | 0:9b334a45a8ff | 137 | static HAL_StatusTypeDef CRYP_EncryptDecrypt_IT(CRYP_HandleTypeDef *hcryp); |
bogdanm | 0:9b334a45a8ff | 138 | static void CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector); |
bogdanm | 0:9b334a45a8ff | 139 | static void CRYP_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key); |
bogdanm | 0:9b334a45a8ff | 140 | static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout); |
bogdanm | 0:9b334a45a8ff | 141 | static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma); |
bogdanm | 0:9b334a45a8ff | 142 | static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma); |
bogdanm | 0:9b334a45a8ff | 143 | static void CRYP_DMAError(DMA_HandleTypeDef *hdma); |
bogdanm | 0:9b334a45a8ff | 144 | static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr); |
bogdanm | 0:9b334a45a8ff | 145 | |
bogdanm | 0:9b334a45a8ff | 146 | /** |
bogdanm | 0:9b334a45a8ff | 147 | * @} |
bogdanm | 0:9b334a45a8ff | 148 | */ |
bogdanm | 0:9b334a45a8ff | 149 | |
bogdanm | 0:9b334a45a8ff | 150 | /* Private functions ---------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 151 | |
bogdanm | 0:9b334a45a8ff | 152 | /** @defgroup CRYP_Exported_Functions CRYP Exported Functions |
bogdanm | 0:9b334a45a8ff | 153 | * @{ |
bogdanm | 0:9b334a45a8ff | 154 | */ |
bogdanm | 0:9b334a45a8ff | 155 | |
bogdanm | 0:9b334a45a8ff | 156 | /** @defgroup CRYP_Exported_Functions_Group1 Initialization and de-initialization functions |
bogdanm | 0:9b334a45a8ff | 157 | * @brief Initialization and Configuration functions. |
bogdanm | 0:9b334a45a8ff | 158 | * |
bogdanm | 0:9b334a45a8ff | 159 | @verbatim |
bogdanm | 0:9b334a45a8ff | 160 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 161 | ##### Initialization and de-initialization functions ##### |
bogdanm | 0:9b334a45a8ff | 162 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 163 | [..] This section provides functions allowing to: |
bogdanm | 0:9b334a45a8ff | 164 | (+) Initialize the CRYP according to the specified parameters |
bogdanm | 0:9b334a45a8ff | 165 | in the CRYP_InitTypeDef and creates the associated handle |
bogdanm | 0:9b334a45a8ff | 166 | (+) DeInitialize the CRYP peripheral |
bogdanm | 0:9b334a45a8ff | 167 | (+) Initialize the CRYP MSP |
bogdanm | 0:9b334a45a8ff | 168 | (+) DeInitialize CRYP MSP |
bogdanm | 0:9b334a45a8ff | 169 | |
bogdanm | 0:9b334a45a8ff | 170 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 171 | * @{ |
bogdanm | 0:9b334a45a8ff | 172 | */ |
bogdanm | 0:9b334a45a8ff | 173 | |
bogdanm | 0:9b334a45a8ff | 174 | /** |
bogdanm | 0:9b334a45a8ff | 175 | * @brief Initializes the CRYP according to the specified |
bogdanm | 0:9b334a45a8ff | 176 | * parameters in the CRYP_InitTypeDef and creates the associated handle. |
bogdanm | 0:9b334a45a8ff | 177 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 178 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 179 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 180 | */ |
bogdanm | 0:9b334a45a8ff | 181 | HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 182 | { |
bogdanm | 0:9b334a45a8ff | 183 | /* Check the CRYP handle allocation */ |
bogdanm | 0:9b334a45a8ff | 184 | if(hcryp == HAL_NULL) |
bogdanm | 0:9b334a45a8ff | 185 | { |
bogdanm | 0:9b334a45a8ff | 186 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 187 | } |
bogdanm | 0:9b334a45a8ff | 188 | |
bogdanm | 0:9b334a45a8ff | 189 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 190 | assert_param(IS_CRYP_DATATYPE(hcryp->Init.DataType)); |
bogdanm | 0:9b334a45a8ff | 191 | |
bogdanm | 0:9b334a45a8ff | 192 | if(hcryp->State == HAL_CRYP_STATE_RESET) |
bogdanm | 0:9b334a45a8ff | 193 | { |
bogdanm | 0:9b334a45a8ff | 194 | /* Init the low level hardware */ |
bogdanm | 0:9b334a45a8ff | 195 | HAL_CRYP_MspInit(hcryp); |
bogdanm | 0:9b334a45a8ff | 196 | } |
bogdanm | 0:9b334a45a8ff | 197 | |
bogdanm | 0:9b334a45a8ff | 198 | /* Check if AES already enabled */ |
bogdanm | 0:9b334a45a8ff | 199 | if (HAL_IS_BIT_CLR(AES->CR, AES_CR_EN)) |
bogdanm | 0:9b334a45a8ff | 200 | { |
bogdanm | 0:9b334a45a8ff | 201 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 202 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 203 | |
bogdanm | 0:9b334a45a8ff | 204 | /* Set the data type*/ |
bogdanm | 0:9b334a45a8ff | 205 | MODIFY_REG(AES->CR, AES_CR_DATATYPE, hcryp->Init.DataType); |
bogdanm | 0:9b334a45a8ff | 206 | |
bogdanm | 0:9b334a45a8ff | 207 | /* Reset CrypInCount and CrypOutCount */ |
bogdanm | 0:9b334a45a8ff | 208 | hcryp->CrypInCount = 0; |
bogdanm | 0:9b334a45a8ff | 209 | hcryp->CrypOutCount = 0; |
bogdanm | 0:9b334a45a8ff | 210 | |
bogdanm | 0:9b334a45a8ff | 211 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 212 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 213 | |
bogdanm | 0:9b334a45a8ff | 214 | /* Set the default CRYP phase */ |
bogdanm | 0:9b334a45a8ff | 215 | hcryp->Phase = HAL_CRYP_PHASE_READY; |
bogdanm | 0:9b334a45a8ff | 216 | |
bogdanm | 0:9b334a45a8ff | 217 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 218 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 219 | } |
bogdanm | 0:9b334a45a8ff | 220 | else |
bogdanm | 0:9b334a45a8ff | 221 | { |
bogdanm | 0:9b334a45a8ff | 222 | /* The Datatype selection must be changed if the AES is disabled. Writing these bits while the AES is */ |
bogdanm | 0:9b334a45a8ff | 223 | /* enabled is forbidden to avoid unpredictable AES behavior.*/ |
bogdanm | 0:9b334a45a8ff | 224 | |
bogdanm | 0:9b334a45a8ff | 225 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 226 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 227 | } |
bogdanm | 0:9b334a45a8ff | 228 | |
bogdanm | 0:9b334a45a8ff | 229 | } |
bogdanm | 0:9b334a45a8ff | 230 | |
bogdanm | 0:9b334a45a8ff | 231 | /** |
bogdanm | 0:9b334a45a8ff | 232 | * @brief DeInitializes the CRYP peripheral. |
bogdanm | 0:9b334a45a8ff | 233 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 234 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 235 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 236 | */ |
bogdanm | 0:9b334a45a8ff | 237 | HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 238 | { |
bogdanm | 0:9b334a45a8ff | 239 | /* Check the CRYP handle allocation */ |
bogdanm | 0:9b334a45a8ff | 240 | if(hcryp == HAL_NULL) |
bogdanm | 0:9b334a45a8ff | 241 | { |
bogdanm | 0:9b334a45a8ff | 242 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 243 | } |
bogdanm | 0:9b334a45a8ff | 244 | |
bogdanm | 0:9b334a45a8ff | 245 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 246 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 247 | |
bogdanm | 0:9b334a45a8ff | 248 | /* Set the default CRYP phase */ |
bogdanm | 0:9b334a45a8ff | 249 | hcryp->Phase = HAL_CRYP_PHASE_READY; |
bogdanm | 0:9b334a45a8ff | 250 | |
bogdanm | 0:9b334a45a8ff | 251 | /* Reset CrypInCount and CrypOutCount */ |
bogdanm | 0:9b334a45a8ff | 252 | hcryp->CrypInCount = 0; |
bogdanm | 0:9b334a45a8ff | 253 | hcryp->CrypOutCount = 0; |
bogdanm | 0:9b334a45a8ff | 254 | |
bogdanm | 0:9b334a45a8ff | 255 | /* Disable the CRYP Peripheral Clock */ |
bogdanm | 0:9b334a45a8ff | 256 | __HAL_CRYP_DISABLE(); |
bogdanm | 0:9b334a45a8ff | 257 | |
bogdanm | 0:9b334a45a8ff | 258 | /* DeInit the low level hardware: CLOCK, NVIC.*/ |
bogdanm | 0:9b334a45a8ff | 259 | HAL_CRYP_MspDeInit(hcryp); |
bogdanm | 0:9b334a45a8ff | 260 | |
bogdanm | 0:9b334a45a8ff | 261 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 262 | hcryp->State = HAL_CRYP_STATE_RESET; |
bogdanm | 0:9b334a45a8ff | 263 | |
bogdanm | 0:9b334a45a8ff | 264 | /* Release Lock */ |
bogdanm | 0:9b334a45a8ff | 265 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 266 | |
bogdanm | 0:9b334a45a8ff | 267 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 268 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 269 | } |
bogdanm | 0:9b334a45a8ff | 270 | |
bogdanm | 0:9b334a45a8ff | 271 | /** |
bogdanm | 0:9b334a45a8ff | 272 | * @brief Initializes the CRYP MSP. |
bogdanm | 0:9b334a45a8ff | 273 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 274 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 275 | * @retval None |
bogdanm | 0:9b334a45a8ff | 276 | */ |
bogdanm | 0:9b334a45a8ff | 277 | __weak void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 278 | { |
bogdanm | 0:9b334a45a8ff | 279 | /* NOTE : This function should not be modified; when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 280 | the HAL_CRYP_MspInit can be implemented in the user file */ |
bogdanm | 0:9b334a45a8ff | 281 | } |
bogdanm | 0:9b334a45a8ff | 282 | |
bogdanm | 0:9b334a45a8ff | 283 | /** |
bogdanm | 0:9b334a45a8ff | 284 | * @brief DeInitializes CRYP MSP. |
bogdanm | 0:9b334a45a8ff | 285 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 286 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 287 | * @retval None |
bogdanm | 0:9b334a45a8ff | 288 | */ |
bogdanm | 0:9b334a45a8ff | 289 | __weak void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 290 | { |
bogdanm | 0:9b334a45a8ff | 291 | /* NOTE : This function should not be modified; when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 292 | the HAL_CRYP_MspDeInit can be implemented in the user file */ |
bogdanm | 0:9b334a45a8ff | 293 | } |
bogdanm | 0:9b334a45a8ff | 294 | |
bogdanm | 0:9b334a45a8ff | 295 | /** |
bogdanm | 0:9b334a45a8ff | 296 | * @} |
bogdanm | 0:9b334a45a8ff | 297 | */ |
bogdanm | 0:9b334a45a8ff | 298 | |
bogdanm | 0:9b334a45a8ff | 299 | /** @defgroup CRYP_Exported_Functions_Group2 AES processing functions |
bogdanm | 0:9b334a45a8ff | 300 | * @brief processing functions. |
bogdanm | 0:9b334a45a8ff | 301 | * |
bogdanm | 0:9b334a45a8ff | 302 | @verbatim |
bogdanm | 0:9b334a45a8ff | 303 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 304 | ##### AES processing functions ##### |
bogdanm | 0:9b334a45a8ff | 305 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 306 | [..] This section provides functions allowing to: |
bogdanm | 0:9b334a45a8ff | 307 | (+) Encrypt plaintext using AES algorithm in different chaining modes |
bogdanm | 0:9b334a45a8ff | 308 | (+) Decrypt cyphertext using AES algorithm in different chaining modes |
bogdanm | 0:9b334a45a8ff | 309 | [..] Three processing functions are available: |
bogdanm | 0:9b334a45a8ff | 310 | (+) Polling mode |
bogdanm | 0:9b334a45a8ff | 311 | (+) Interrupt mode |
bogdanm | 0:9b334a45a8ff | 312 | (+) DMA mode |
bogdanm | 0:9b334a45a8ff | 313 | |
bogdanm | 0:9b334a45a8ff | 314 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 315 | * @{ |
bogdanm | 0:9b334a45a8ff | 316 | */ |
bogdanm | 0:9b334a45a8ff | 317 | |
bogdanm | 0:9b334a45a8ff | 318 | /** |
bogdanm | 0:9b334a45a8ff | 319 | * @brief Initializes the CRYP peripheral in AES ECB encryption mode |
bogdanm | 0:9b334a45a8ff | 320 | * then encrypt pPlainData. The cypher data are available in pCypherData |
bogdanm | 0:9b334a45a8ff | 321 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 322 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 323 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 324 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 325 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 326 | * @param Timeout: Specify Timeout value |
bogdanm | 0:9b334a45a8ff | 327 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 328 | */ |
bogdanm | 0:9b334a45a8ff | 329 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 330 | { |
bogdanm | 0:9b334a45a8ff | 331 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 332 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 333 | |
bogdanm | 0:9b334a45a8ff | 334 | /* Check that data aligned on u32 and Size multiple of 16*/ |
bogdanm | 0:9b334a45a8ff | 335 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 336 | { |
bogdanm | 0:9b334a45a8ff | 337 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 338 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 339 | |
bogdanm | 0:9b334a45a8ff | 340 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 341 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 342 | } |
bogdanm | 0:9b334a45a8ff | 343 | |
bogdanm | 0:9b334a45a8ff | 344 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 345 | if(hcryp->State != HAL_CRYP_STATE_RESET) |
bogdanm | 0:9b334a45a8ff | 346 | { |
bogdanm | 0:9b334a45a8ff | 347 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 348 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 349 | |
bogdanm | 0:9b334a45a8ff | 350 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 351 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 352 | { |
bogdanm | 0:9b334a45a8ff | 353 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 354 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 355 | |
bogdanm | 0:9b334a45a8ff | 356 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 357 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 358 | |
bogdanm | 0:9b334a45a8ff | 359 | /* Set the CRYP peripheral in AES ECB mode */ |
bogdanm | 0:9b334a45a8ff | 360 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 361 | |
bogdanm | 0:9b334a45a8ff | 362 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 363 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 364 | |
bogdanm | 0:9b334a45a8ff | 365 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 366 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 367 | } |
bogdanm | 0:9b334a45a8ff | 368 | |
bogdanm | 0:9b334a45a8ff | 369 | /* Write Plain Data and Get Cypher Data */ |
bogdanm | 0:9b334a45a8ff | 370 | if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 371 | { |
bogdanm | 0:9b334a45a8ff | 372 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 373 | } |
bogdanm | 0:9b334a45a8ff | 374 | |
bogdanm | 0:9b334a45a8ff | 375 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 376 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 377 | |
bogdanm | 0:9b334a45a8ff | 378 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 379 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 380 | |
bogdanm | 0:9b334a45a8ff | 381 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 382 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 383 | } |
bogdanm | 0:9b334a45a8ff | 384 | else |
bogdanm | 0:9b334a45a8ff | 385 | { |
bogdanm | 0:9b334a45a8ff | 386 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 387 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 388 | } |
bogdanm | 0:9b334a45a8ff | 389 | } |
bogdanm | 0:9b334a45a8ff | 390 | |
bogdanm | 0:9b334a45a8ff | 391 | /** |
bogdanm | 0:9b334a45a8ff | 392 | * @brief Initializes the CRYP peripheral in AES CBC encryption mode |
bogdanm | 0:9b334a45a8ff | 393 | * then encrypt pPlainData. The cypher data are available in pCypherData |
bogdanm | 0:9b334a45a8ff | 394 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 395 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 396 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 397 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 398 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 399 | * @param Timeout: Specify Timeout value |
bogdanm | 0:9b334a45a8ff | 400 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 401 | */ |
bogdanm | 0:9b334a45a8ff | 402 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 403 | { |
bogdanm | 0:9b334a45a8ff | 404 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 405 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 406 | |
bogdanm | 0:9b334a45a8ff | 407 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 408 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 409 | { |
bogdanm | 0:9b334a45a8ff | 410 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 411 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 412 | |
bogdanm | 0:9b334a45a8ff | 413 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 414 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 415 | } |
bogdanm | 0:9b334a45a8ff | 416 | |
bogdanm | 0:9b334a45a8ff | 417 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 418 | if(hcryp->State != HAL_CRYP_STATE_RESET) |
bogdanm | 0:9b334a45a8ff | 419 | { |
bogdanm | 0:9b334a45a8ff | 420 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 421 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 422 | |
bogdanm | 0:9b334a45a8ff | 423 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 424 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 425 | { |
bogdanm | 0:9b334a45a8ff | 426 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 427 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 428 | |
bogdanm | 0:9b334a45a8ff | 429 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 430 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 431 | |
bogdanm | 0:9b334a45a8ff | 432 | /* Set the CRYP peripheral in AES CBC mode */ |
bogdanm | 0:9b334a45a8ff | 433 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 434 | |
bogdanm | 0:9b334a45a8ff | 435 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 436 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 437 | |
bogdanm | 0:9b334a45a8ff | 438 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 439 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 440 | |
bogdanm | 0:9b334a45a8ff | 441 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 442 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 443 | } |
bogdanm | 0:9b334a45a8ff | 444 | |
bogdanm | 0:9b334a45a8ff | 445 | /* Write Plain Data and Get Cypher Data */ |
bogdanm | 0:9b334a45a8ff | 446 | if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 447 | { |
bogdanm | 0:9b334a45a8ff | 448 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 449 | } |
bogdanm | 0:9b334a45a8ff | 450 | |
bogdanm | 0:9b334a45a8ff | 451 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 452 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 453 | |
bogdanm | 0:9b334a45a8ff | 454 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 455 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 456 | |
bogdanm | 0:9b334a45a8ff | 457 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 458 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 459 | } |
bogdanm | 0:9b334a45a8ff | 460 | else |
bogdanm | 0:9b334a45a8ff | 461 | { |
bogdanm | 0:9b334a45a8ff | 462 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 463 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 464 | } |
bogdanm | 0:9b334a45a8ff | 465 | } |
bogdanm | 0:9b334a45a8ff | 466 | |
bogdanm | 0:9b334a45a8ff | 467 | /** |
bogdanm | 0:9b334a45a8ff | 468 | * @brief Initializes the CRYP peripheral in AES CTR encryption mode |
bogdanm | 0:9b334a45a8ff | 469 | * then encrypt pPlainData. The cypher data are available in pCypherData |
bogdanm | 0:9b334a45a8ff | 470 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 471 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 472 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 473 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 474 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 475 | * @param Timeout: Specify Timeout value |
bogdanm | 0:9b334a45a8ff | 476 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 477 | */ |
bogdanm | 0:9b334a45a8ff | 478 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 479 | { |
bogdanm | 0:9b334a45a8ff | 480 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 481 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 482 | |
bogdanm | 0:9b334a45a8ff | 483 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 484 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 485 | { |
bogdanm | 0:9b334a45a8ff | 486 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 487 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 488 | |
bogdanm | 0:9b334a45a8ff | 489 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 490 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 491 | } |
bogdanm | 0:9b334a45a8ff | 492 | |
bogdanm | 0:9b334a45a8ff | 493 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 494 | if(hcryp->State != HAL_CRYP_STATE_RESET) |
bogdanm | 0:9b334a45a8ff | 495 | { |
bogdanm | 0:9b334a45a8ff | 496 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 497 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 498 | |
bogdanm | 0:9b334a45a8ff | 499 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 500 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 501 | { |
bogdanm | 0:9b334a45a8ff | 502 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 503 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 504 | |
bogdanm | 0:9b334a45a8ff | 505 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 506 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 507 | |
bogdanm | 0:9b334a45a8ff | 508 | /* Set the CRYP peripheral in AES CTR mode */ |
bogdanm | 0:9b334a45a8ff | 509 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 510 | |
bogdanm | 0:9b334a45a8ff | 511 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 512 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 513 | |
bogdanm | 0:9b334a45a8ff | 514 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 515 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 516 | |
bogdanm | 0:9b334a45a8ff | 517 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 518 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 519 | } |
bogdanm | 0:9b334a45a8ff | 520 | |
bogdanm | 0:9b334a45a8ff | 521 | /* Write Plain Data and Get Cypher Data */ |
bogdanm | 0:9b334a45a8ff | 522 | if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 523 | { |
bogdanm | 0:9b334a45a8ff | 524 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 525 | } |
bogdanm | 0:9b334a45a8ff | 526 | |
bogdanm | 0:9b334a45a8ff | 527 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 528 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 529 | |
bogdanm | 0:9b334a45a8ff | 530 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 531 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 532 | |
bogdanm | 0:9b334a45a8ff | 533 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 534 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 535 | } |
bogdanm | 0:9b334a45a8ff | 536 | else |
bogdanm | 0:9b334a45a8ff | 537 | { |
bogdanm | 0:9b334a45a8ff | 538 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 539 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 540 | } |
bogdanm | 0:9b334a45a8ff | 541 | } |
bogdanm | 0:9b334a45a8ff | 542 | |
bogdanm | 0:9b334a45a8ff | 543 | /** |
bogdanm | 0:9b334a45a8ff | 544 | * @brief Initializes the CRYP peripheral in AES ECB decryption mode |
bogdanm | 0:9b334a45a8ff | 545 | * then decrypted pCypherData. The cypher data are available in pPlainData |
bogdanm | 0:9b334a45a8ff | 546 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 547 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 548 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 549 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 550 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 551 | * @param Timeout: Specify Timeout value |
bogdanm | 0:9b334a45a8ff | 552 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 553 | */ |
bogdanm | 0:9b334a45a8ff | 554 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 555 | { |
bogdanm | 0:9b334a45a8ff | 556 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 557 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 558 | |
bogdanm | 0:9b334a45a8ff | 559 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 560 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 561 | { |
bogdanm | 0:9b334a45a8ff | 562 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 563 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 564 | |
bogdanm | 0:9b334a45a8ff | 565 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 566 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 567 | } |
bogdanm | 0:9b334a45a8ff | 568 | |
bogdanm | 0:9b334a45a8ff | 569 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 570 | if(hcryp->State != HAL_CRYP_STATE_RESET) |
bogdanm | 0:9b334a45a8ff | 571 | { |
bogdanm | 0:9b334a45a8ff | 572 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 573 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 574 | |
bogdanm | 0:9b334a45a8ff | 575 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 576 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 577 | { |
bogdanm | 0:9b334a45a8ff | 578 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 579 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 580 | |
bogdanm | 0:9b334a45a8ff | 581 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 582 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 583 | |
bogdanm | 0:9b334a45a8ff | 584 | /* Set the CRYP peripheral in AES ECB decryption mode (with key derivation) */ |
bogdanm | 0:9b334a45a8ff | 585 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB_KEYDERDECRYPT); |
bogdanm | 0:9b334a45a8ff | 586 | |
bogdanm | 0:9b334a45a8ff | 587 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 588 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 589 | |
bogdanm | 0:9b334a45a8ff | 590 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 591 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 592 | } |
bogdanm | 0:9b334a45a8ff | 593 | |
bogdanm | 0:9b334a45a8ff | 594 | /* Write Cypher Data and Get Plain Data */ |
bogdanm | 0:9b334a45a8ff | 595 | if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 596 | { |
bogdanm | 0:9b334a45a8ff | 597 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 598 | } |
bogdanm | 0:9b334a45a8ff | 599 | |
bogdanm | 0:9b334a45a8ff | 600 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 601 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 602 | |
bogdanm | 0:9b334a45a8ff | 603 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 604 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 605 | |
bogdanm | 0:9b334a45a8ff | 606 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 607 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 608 | } |
bogdanm | 0:9b334a45a8ff | 609 | else |
bogdanm | 0:9b334a45a8ff | 610 | { |
bogdanm | 0:9b334a45a8ff | 611 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 612 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 613 | } |
bogdanm | 0:9b334a45a8ff | 614 | } |
bogdanm | 0:9b334a45a8ff | 615 | |
bogdanm | 0:9b334a45a8ff | 616 | /** |
bogdanm | 0:9b334a45a8ff | 617 | * @brief Initializes the CRYP peripheral in AES ECB decryption mode |
bogdanm | 0:9b334a45a8ff | 618 | * then decrypted pCypherData. The cypher data are available in pPlainData |
bogdanm | 0:9b334a45a8ff | 619 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 620 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 621 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 622 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 623 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 624 | * @param Timeout: Specify Timeout value |
bogdanm | 0:9b334a45a8ff | 625 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 626 | */ |
bogdanm | 0:9b334a45a8ff | 627 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 628 | { |
bogdanm | 0:9b334a45a8ff | 629 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 630 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 631 | |
bogdanm | 0:9b334a45a8ff | 632 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 633 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 634 | { |
bogdanm | 0:9b334a45a8ff | 635 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 636 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 637 | |
bogdanm | 0:9b334a45a8ff | 638 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 639 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 640 | } |
bogdanm | 0:9b334a45a8ff | 641 | |
bogdanm | 0:9b334a45a8ff | 642 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 643 | if(hcryp->State != HAL_CRYP_STATE_RESET) |
bogdanm | 0:9b334a45a8ff | 644 | { |
bogdanm | 0:9b334a45a8ff | 645 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 646 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 647 | |
bogdanm | 0:9b334a45a8ff | 648 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 649 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 650 | { |
bogdanm | 0:9b334a45a8ff | 651 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 652 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 653 | |
bogdanm | 0:9b334a45a8ff | 654 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 655 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 656 | |
bogdanm | 0:9b334a45a8ff | 657 | /* Set the CRYP peripheral in AES CBC decryption mode (with key derivation) */ |
bogdanm | 0:9b334a45a8ff | 658 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC_KEYDERDECRYPT); |
bogdanm | 0:9b334a45a8ff | 659 | |
bogdanm | 0:9b334a45a8ff | 660 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 661 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 662 | |
bogdanm | 0:9b334a45a8ff | 663 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 664 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 665 | |
bogdanm | 0:9b334a45a8ff | 666 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 667 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 668 | } |
bogdanm | 0:9b334a45a8ff | 669 | |
bogdanm | 0:9b334a45a8ff | 670 | /* Write Cypher Data and Get Plain Data */ |
bogdanm | 0:9b334a45a8ff | 671 | if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 672 | { |
bogdanm | 0:9b334a45a8ff | 673 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 674 | } |
bogdanm | 0:9b334a45a8ff | 675 | |
bogdanm | 0:9b334a45a8ff | 676 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 677 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 678 | |
bogdanm | 0:9b334a45a8ff | 679 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 680 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 681 | |
bogdanm | 0:9b334a45a8ff | 682 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 683 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 684 | } |
bogdanm | 0:9b334a45a8ff | 685 | else |
bogdanm | 0:9b334a45a8ff | 686 | { |
bogdanm | 0:9b334a45a8ff | 687 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 688 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 689 | } |
bogdanm | 0:9b334a45a8ff | 690 | } |
bogdanm | 0:9b334a45a8ff | 691 | |
bogdanm | 0:9b334a45a8ff | 692 | /** |
bogdanm | 0:9b334a45a8ff | 693 | * @brief Initializes the CRYP peripheral in AES CTR decryption mode |
bogdanm | 0:9b334a45a8ff | 694 | * then decrypted pCypherData. The cypher data are available in pPlainData |
bogdanm | 0:9b334a45a8ff | 695 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 696 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 697 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 698 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 699 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 700 | * @param Timeout: Specify Timeout value |
bogdanm | 0:9b334a45a8ff | 701 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 702 | */ |
bogdanm | 0:9b334a45a8ff | 703 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 704 | { |
bogdanm | 0:9b334a45a8ff | 705 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 706 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 707 | |
bogdanm | 0:9b334a45a8ff | 708 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 709 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 710 | { |
bogdanm | 0:9b334a45a8ff | 711 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 712 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 713 | |
bogdanm | 0:9b334a45a8ff | 714 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 715 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 716 | } |
bogdanm | 0:9b334a45a8ff | 717 | |
bogdanm | 0:9b334a45a8ff | 718 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 719 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->Phase == HAL_CRYP_PHASE_READY)) |
bogdanm | 0:9b334a45a8ff | 720 | { |
bogdanm | 0:9b334a45a8ff | 721 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 722 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 723 | |
bogdanm | 0:9b334a45a8ff | 724 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 725 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 726 | |
bogdanm | 0:9b334a45a8ff | 727 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 728 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 729 | |
bogdanm | 0:9b334a45a8ff | 730 | /* Set the CRYP peripheral in AES CTR decryption mode */ |
bogdanm | 0:9b334a45a8ff | 731 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR_DECRYPT); |
bogdanm | 0:9b334a45a8ff | 732 | |
bogdanm | 0:9b334a45a8ff | 733 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 734 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 735 | |
bogdanm | 0:9b334a45a8ff | 736 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 737 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 738 | |
bogdanm | 0:9b334a45a8ff | 739 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 740 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 741 | } |
bogdanm | 0:9b334a45a8ff | 742 | |
bogdanm | 0:9b334a45a8ff | 743 | /* Write Cypher Data and Get Plain Data */ |
bogdanm | 0:9b334a45a8ff | 744 | if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 745 | { |
bogdanm | 0:9b334a45a8ff | 746 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 747 | } |
bogdanm | 0:9b334a45a8ff | 748 | |
bogdanm | 0:9b334a45a8ff | 749 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 750 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 751 | |
bogdanm | 0:9b334a45a8ff | 752 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 753 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 754 | |
bogdanm | 0:9b334a45a8ff | 755 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 756 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 757 | } |
bogdanm | 0:9b334a45a8ff | 758 | |
bogdanm | 0:9b334a45a8ff | 759 | /** |
bogdanm | 0:9b334a45a8ff | 760 | * @brief Initializes the CRYP peripheral in AES ECB encryption mode using Interrupt. |
bogdanm | 0:9b334a45a8ff | 761 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 762 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 763 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 764 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
bogdanm | 0:9b334a45a8ff | 765 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 766 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 767 | */ |
bogdanm | 0:9b334a45a8ff | 768 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
bogdanm | 0:9b334a45a8ff | 769 | { |
bogdanm | 0:9b334a45a8ff | 770 | uint32_t inputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 771 | |
bogdanm | 0:9b334a45a8ff | 772 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 773 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 774 | { |
bogdanm | 0:9b334a45a8ff | 775 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 776 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 777 | |
bogdanm | 0:9b334a45a8ff | 778 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 779 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 780 | } |
bogdanm | 0:9b334a45a8ff | 781 | |
bogdanm | 0:9b334a45a8ff | 782 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 783 | { |
bogdanm | 0:9b334a45a8ff | 784 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 785 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 786 | |
bogdanm | 0:9b334a45a8ff | 787 | /* Get the buffer addresses and sizes */ |
bogdanm | 0:9b334a45a8ff | 788 | hcryp->CrypInCount = Size; |
bogdanm | 0:9b334a45a8ff | 789 | hcryp->pCrypInBuffPtr = pPlainData; |
bogdanm | 0:9b334a45a8ff | 790 | hcryp->pCrypOutBuffPtr = pCypherData; |
bogdanm | 0:9b334a45a8ff | 791 | hcryp->CrypOutCount = Size; |
bogdanm | 0:9b334a45a8ff | 792 | |
bogdanm | 0:9b334a45a8ff | 793 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 794 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 795 | |
bogdanm | 0:9b334a45a8ff | 796 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 797 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 798 | { |
bogdanm | 0:9b334a45a8ff | 799 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 800 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 801 | |
bogdanm | 0:9b334a45a8ff | 802 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 803 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 804 | |
bogdanm | 0:9b334a45a8ff | 805 | /* Set the CRYP peripheral in AES ECB mode */ |
bogdanm | 0:9b334a45a8ff | 806 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 807 | |
bogdanm | 0:9b334a45a8ff | 808 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 809 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 810 | } |
bogdanm | 0:9b334a45a8ff | 811 | |
bogdanm | 0:9b334a45a8ff | 812 | /* Enable Interrupts */ |
bogdanm | 0:9b334a45a8ff | 813 | __HAL_CRYP_ENABLE_IT(AES_IT_CC); |
bogdanm | 0:9b334a45a8ff | 814 | |
bogdanm | 0:9b334a45a8ff | 815 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 816 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 817 | |
bogdanm | 0:9b334a45a8ff | 818 | /* Get the last input data adress */ |
bogdanm | 0:9b334a45a8ff | 819 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
bogdanm | 0:9b334a45a8ff | 820 | |
bogdanm | 0:9b334a45a8ff | 821 | /* Write the Input block in the Data Input register */ |
bogdanm | 0:9b334a45a8ff | 822 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 823 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 824 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 825 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 826 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 827 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 828 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 829 | hcryp->pCrypInBuffPtr += 16; |
bogdanm | 0:9b334a45a8ff | 830 | hcryp->CrypInCount -= 16; |
bogdanm | 0:9b334a45a8ff | 831 | |
bogdanm | 0:9b334a45a8ff | 832 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 833 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 834 | } |
bogdanm | 0:9b334a45a8ff | 835 | else |
bogdanm | 0:9b334a45a8ff | 836 | { |
bogdanm | 0:9b334a45a8ff | 837 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 838 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 839 | } |
bogdanm | 0:9b334a45a8ff | 840 | } |
bogdanm | 0:9b334a45a8ff | 841 | |
bogdanm | 0:9b334a45a8ff | 842 | /** |
bogdanm | 0:9b334a45a8ff | 843 | * @brief Initializes the CRYP peripheral in AES CBC encryption mode using Interrupt. |
bogdanm | 0:9b334a45a8ff | 844 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 845 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 846 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 847 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
bogdanm | 0:9b334a45a8ff | 848 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 849 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 850 | */ |
bogdanm | 0:9b334a45a8ff | 851 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
bogdanm | 0:9b334a45a8ff | 852 | { |
bogdanm | 0:9b334a45a8ff | 853 | uint32_t inputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 854 | |
bogdanm | 0:9b334a45a8ff | 855 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 856 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 857 | { |
bogdanm | 0:9b334a45a8ff | 858 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 859 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 860 | |
bogdanm | 0:9b334a45a8ff | 861 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 862 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 863 | } |
bogdanm | 0:9b334a45a8ff | 864 | |
bogdanm | 0:9b334a45a8ff | 865 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 866 | { |
bogdanm | 0:9b334a45a8ff | 867 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 868 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 869 | |
bogdanm | 0:9b334a45a8ff | 870 | /* Get the buffer addresses and sizes */ |
bogdanm | 0:9b334a45a8ff | 871 | hcryp->CrypInCount = Size; |
bogdanm | 0:9b334a45a8ff | 872 | hcryp->pCrypInBuffPtr = pPlainData; |
bogdanm | 0:9b334a45a8ff | 873 | hcryp->pCrypOutBuffPtr = pCypherData; |
bogdanm | 0:9b334a45a8ff | 874 | hcryp->CrypOutCount = Size; |
bogdanm | 0:9b334a45a8ff | 875 | |
bogdanm | 0:9b334a45a8ff | 876 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 877 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 878 | |
bogdanm | 0:9b334a45a8ff | 879 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 880 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 881 | { |
bogdanm | 0:9b334a45a8ff | 882 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 883 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 884 | |
bogdanm | 0:9b334a45a8ff | 885 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 886 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 887 | |
bogdanm | 0:9b334a45a8ff | 888 | /* Set the CRYP peripheral in AES CBC mode */ |
bogdanm | 0:9b334a45a8ff | 889 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 890 | |
bogdanm | 0:9b334a45a8ff | 891 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 892 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 893 | |
bogdanm | 0:9b334a45a8ff | 894 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 895 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 896 | } |
bogdanm | 0:9b334a45a8ff | 897 | |
bogdanm | 0:9b334a45a8ff | 898 | /* Enable Interrupts */ |
bogdanm | 0:9b334a45a8ff | 899 | __HAL_CRYP_ENABLE_IT(AES_IT_CC); |
bogdanm | 0:9b334a45a8ff | 900 | |
bogdanm | 0:9b334a45a8ff | 901 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 902 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 903 | |
bogdanm | 0:9b334a45a8ff | 904 | /* Get the last input data adress */ |
bogdanm | 0:9b334a45a8ff | 905 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
bogdanm | 0:9b334a45a8ff | 906 | |
bogdanm | 0:9b334a45a8ff | 907 | /* Write the Input block in the Data Input register */ |
bogdanm | 0:9b334a45a8ff | 908 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 909 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 910 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 911 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 912 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 913 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 914 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 915 | hcryp->pCrypInBuffPtr += 16; |
bogdanm | 0:9b334a45a8ff | 916 | hcryp->CrypInCount -= 16; |
bogdanm | 0:9b334a45a8ff | 917 | |
bogdanm | 0:9b334a45a8ff | 918 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 919 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 920 | } |
bogdanm | 0:9b334a45a8ff | 921 | else |
bogdanm | 0:9b334a45a8ff | 922 | { |
bogdanm | 0:9b334a45a8ff | 923 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 924 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 925 | } |
bogdanm | 0:9b334a45a8ff | 926 | } |
bogdanm | 0:9b334a45a8ff | 927 | |
bogdanm | 0:9b334a45a8ff | 928 | /** |
bogdanm | 0:9b334a45a8ff | 929 | * @brief Initializes the CRYP peripheral in AES CTR encryption mode using Interrupt. |
bogdanm | 0:9b334a45a8ff | 930 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 931 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 932 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 933 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
bogdanm | 0:9b334a45a8ff | 934 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 935 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 936 | */ |
bogdanm | 0:9b334a45a8ff | 937 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
bogdanm | 0:9b334a45a8ff | 938 | { |
bogdanm | 0:9b334a45a8ff | 939 | uint32_t inputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 940 | |
bogdanm | 0:9b334a45a8ff | 941 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 942 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 943 | { |
bogdanm | 0:9b334a45a8ff | 944 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 945 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 946 | |
bogdanm | 0:9b334a45a8ff | 947 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 948 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 949 | } |
bogdanm | 0:9b334a45a8ff | 950 | |
bogdanm | 0:9b334a45a8ff | 951 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 952 | { |
bogdanm | 0:9b334a45a8ff | 953 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 954 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 955 | |
bogdanm | 0:9b334a45a8ff | 956 | /* Get the buffer addresses and sizes */ |
bogdanm | 0:9b334a45a8ff | 957 | hcryp->CrypInCount = Size; |
bogdanm | 0:9b334a45a8ff | 958 | hcryp->pCrypInBuffPtr = pPlainData; |
bogdanm | 0:9b334a45a8ff | 959 | hcryp->pCrypOutBuffPtr = pCypherData; |
bogdanm | 0:9b334a45a8ff | 960 | hcryp->CrypOutCount = Size; |
bogdanm | 0:9b334a45a8ff | 961 | |
bogdanm | 0:9b334a45a8ff | 962 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 963 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 964 | |
bogdanm | 0:9b334a45a8ff | 965 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 966 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 967 | { |
bogdanm | 0:9b334a45a8ff | 968 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 969 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 970 | |
bogdanm | 0:9b334a45a8ff | 971 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 972 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 973 | |
bogdanm | 0:9b334a45a8ff | 974 | /* Set the CRYP peripheral in AES CTR mode */ |
bogdanm | 0:9b334a45a8ff | 975 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 976 | |
bogdanm | 0:9b334a45a8ff | 977 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 978 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 979 | |
bogdanm | 0:9b334a45a8ff | 980 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 981 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 982 | } |
bogdanm | 0:9b334a45a8ff | 983 | |
bogdanm | 0:9b334a45a8ff | 984 | /* Enable Interrupts */ |
bogdanm | 0:9b334a45a8ff | 985 | __HAL_CRYP_ENABLE_IT(AES_IT_CC); |
bogdanm | 0:9b334a45a8ff | 986 | |
bogdanm | 0:9b334a45a8ff | 987 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 988 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 989 | |
bogdanm | 0:9b334a45a8ff | 990 | /* Get the last input data adress */ |
bogdanm | 0:9b334a45a8ff | 991 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
bogdanm | 0:9b334a45a8ff | 992 | |
bogdanm | 0:9b334a45a8ff | 993 | /* Write the Input block in the Data Input register */ |
bogdanm | 0:9b334a45a8ff | 994 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 995 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 996 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 997 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 998 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 999 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1000 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1001 | hcryp->pCrypInBuffPtr += 16; |
bogdanm | 0:9b334a45a8ff | 1002 | hcryp->CrypInCount -= 16; |
bogdanm | 0:9b334a45a8ff | 1003 | |
bogdanm | 0:9b334a45a8ff | 1004 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1005 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1006 | } |
bogdanm | 0:9b334a45a8ff | 1007 | else |
bogdanm | 0:9b334a45a8ff | 1008 | { |
bogdanm | 0:9b334a45a8ff | 1009 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1010 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1011 | } |
bogdanm | 0:9b334a45a8ff | 1012 | } |
bogdanm | 0:9b334a45a8ff | 1013 | |
bogdanm | 0:9b334a45a8ff | 1014 | /** |
bogdanm | 0:9b334a45a8ff | 1015 | * @brief Initializes the CRYP peripheral in AES ECB decryption mode using Interrupt. |
bogdanm | 0:9b334a45a8ff | 1016 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1017 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1018 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1019 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 1020 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1021 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1022 | */ |
bogdanm | 0:9b334a45a8ff | 1023 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
bogdanm | 0:9b334a45a8ff | 1024 | { |
bogdanm | 0:9b334a45a8ff | 1025 | uint32_t inputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1026 | |
bogdanm | 0:9b334a45a8ff | 1027 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1028 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1029 | { |
bogdanm | 0:9b334a45a8ff | 1030 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1031 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1032 | |
bogdanm | 0:9b334a45a8ff | 1033 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1034 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1035 | } |
bogdanm | 0:9b334a45a8ff | 1036 | |
bogdanm | 0:9b334a45a8ff | 1037 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1038 | { |
bogdanm | 0:9b334a45a8ff | 1039 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1040 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1041 | |
bogdanm | 0:9b334a45a8ff | 1042 | /* Get the buffer addresses and sizes */ |
bogdanm | 0:9b334a45a8ff | 1043 | hcryp->CrypInCount = Size; |
bogdanm | 0:9b334a45a8ff | 1044 | hcryp->pCrypInBuffPtr = pCypherData; |
bogdanm | 0:9b334a45a8ff | 1045 | hcryp->pCrypOutBuffPtr = pPlainData; |
bogdanm | 0:9b334a45a8ff | 1046 | hcryp->CrypOutCount = Size; |
bogdanm | 0:9b334a45a8ff | 1047 | |
bogdanm | 0:9b334a45a8ff | 1048 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1049 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1050 | |
bogdanm | 0:9b334a45a8ff | 1051 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1052 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1053 | { |
bogdanm | 0:9b334a45a8ff | 1054 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1055 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1056 | |
bogdanm | 0:9b334a45a8ff | 1057 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 1058 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 1059 | |
bogdanm | 0:9b334a45a8ff | 1060 | /* Set the CRYP peripheral in AES ECB decryption mode (with key derivation) */ |
bogdanm | 0:9b334a45a8ff | 1061 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB_KEYDERDECRYPT); |
bogdanm | 0:9b334a45a8ff | 1062 | |
bogdanm | 0:9b334a45a8ff | 1063 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1064 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1065 | } |
bogdanm | 0:9b334a45a8ff | 1066 | |
bogdanm | 0:9b334a45a8ff | 1067 | /* Enable Interrupts */ |
bogdanm | 0:9b334a45a8ff | 1068 | __HAL_CRYP_ENABLE_IT(AES_IT_CC); |
bogdanm | 0:9b334a45a8ff | 1069 | |
bogdanm | 0:9b334a45a8ff | 1070 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 1071 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 1072 | |
bogdanm | 0:9b334a45a8ff | 1073 | /* Get the last input data adress */ |
bogdanm | 0:9b334a45a8ff | 1074 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
bogdanm | 0:9b334a45a8ff | 1075 | |
bogdanm | 0:9b334a45a8ff | 1076 | /* Write the Input block in the Data Input register */ |
bogdanm | 0:9b334a45a8ff | 1077 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1078 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1079 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1080 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1081 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1082 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1083 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1084 | hcryp->pCrypInBuffPtr += 16; |
bogdanm | 0:9b334a45a8ff | 1085 | hcryp->CrypInCount -= 16; |
bogdanm | 0:9b334a45a8ff | 1086 | |
bogdanm | 0:9b334a45a8ff | 1087 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1088 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1089 | } |
bogdanm | 0:9b334a45a8ff | 1090 | else |
bogdanm | 0:9b334a45a8ff | 1091 | { |
bogdanm | 0:9b334a45a8ff | 1092 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1093 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1094 | } |
bogdanm | 0:9b334a45a8ff | 1095 | } |
bogdanm | 0:9b334a45a8ff | 1096 | |
bogdanm | 0:9b334a45a8ff | 1097 | /** |
bogdanm | 0:9b334a45a8ff | 1098 | * @brief Initializes the CRYP peripheral in AES CBC decryption mode using IT. |
bogdanm | 0:9b334a45a8ff | 1099 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1100 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1101 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1102 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 |
bogdanm | 0:9b334a45a8ff | 1103 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1104 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1105 | */ |
bogdanm | 0:9b334a45a8ff | 1106 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
bogdanm | 0:9b334a45a8ff | 1107 | { |
bogdanm | 0:9b334a45a8ff | 1108 | uint32_t inputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1109 | |
bogdanm | 0:9b334a45a8ff | 1110 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1111 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1112 | { |
bogdanm | 0:9b334a45a8ff | 1113 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1114 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1115 | |
bogdanm | 0:9b334a45a8ff | 1116 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1117 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1118 | } |
bogdanm | 0:9b334a45a8ff | 1119 | |
bogdanm | 0:9b334a45a8ff | 1120 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1121 | { |
bogdanm | 0:9b334a45a8ff | 1122 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1123 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1124 | |
bogdanm | 0:9b334a45a8ff | 1125 | /* Get the buffer addresses and sizes */ |
bogdanm | 0:9b334a45a8ff | 1126 | hcryp->CrypInCount = Size; |
bogdanm | 0:9b334a45a8ff | 1127 | hcryp->pCrypInBuffPtr = pCypherData; |
bogdanm | 0:9b334a45a8ff | 1128 | hcryp->pCrypOutBuffPtr = pPlainData; |
bogdanm | 0:9b334a45a8ff | 1129 | hcryp->CrypOutCount = Size; |
bogdanm | 0:9b334a45a8ff | 1130 | |
bogdanm | 0:9b334a45a8ff | 1131 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1132 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1133 | |
bogdanm | 0:9b334a45a8ff | 1134 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1135 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1136 | { |
bogdanm | 0:9b334a45a8ff | 1137 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1138 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1139 | |
bogdanm | 0:9b334a45a8ff | 1140 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 1141 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 1142 | |
bogdanm | 0:9b334a45a8ff | 1143 | /* Set the CRYP peripheral in AES CBC decryption mode (with key derivation) */ |
bogdanm | 0:9b334a45a8ff | 1144 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC_KEYDERDECRYPT); |
bogdanm | 0:9b334a45a8ff | 1145 | |
bogdanm | 0:9b334a45a8ff | 1146 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 1147 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 1148 | |
bogdanm | 0:9b334a45a8ff | 1149 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1150 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1151 | } |
bogdanm | 0:9b334a45a8ff | 1152 | |
bogdanm | 0:9b334a45a8ff | 1153 | /* Enable Interrupts */ |
bogdanm | 0:9b334a45a8ff | 1154 | __HAL_CRYP_ENABLE_IT(AES_IT_CC); |
bogdanm | 0:9b334a45a8ff | 1155 | |
bogdanm | 0:9b334a45a8ff | 1156 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 1157 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 1158 | |
bogdanm | 0:9b334a45a8ff | 1159 | /* Get the last input data adress */ |
bogdanm | 0:9b334a45a8ff | 1160 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
bogdanm | 0:9b334a45a8ff | 1161 | |
bogdanm | 0:9b334a45a8ff | 1162 | /* Write the Input block in the Data Input register */ |
bogdanm | 0:9b334a45a8ff | 1163 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1164 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1165 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1166 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1167 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1168 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1169 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1170 | hcryp->pCrypInBuffPtr += 16; |
bogdanm | 0:9b334a45a8ff | 1171 | hcryp->CrypInCount -= 16; |
bogdanm | 0:9b334a45a8ff | 1172 | |
bogdanm | 0:9b334a45a8ff | 1173 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1174 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1175 | } |
bogdanm | 0:9b334a45a8ff | 1176 | else |
bogdanm | 0:9b334a45a8ff | 1177 | { |
bogdanm | 0:9b334a45a8ff | 1178 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1179 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1180 | } |
bogdanm | 0:9b334a45a8ff | 1181 | } |
bogdanm | 0:9b334a45a8ff | 1182 | |
bogdanm | 0:9b334a45a8ff | 1183 | /** |
bogdanm | 0:9b334a45a8ff | 1184 | * @brief Initializes the CRYP peripheral in AES CTR decryption mode using Interrupt. |
bogdanm | 0:9b334a45a8ff | 1185 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1186 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1187 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1188 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 |
bogdanm | 0:9b334a45a8ff | 1189 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1190 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1191 | */ |
bogdanm | 0:9b334a45a8ff | 1192 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
bogdanm | 0:9b334a45a8ff | 1193 | { |
bogdanm | 0:9b334a45a8ff | 1194 | uint32_t inputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1195 | |
bogdanm | 0:9b334a45a8ff | 1196 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1197 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1198 | { |
bogdanm | 0:9b334a45a8ff | 1199 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1200 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1201 | |
bogdanm | 0:9b334a45a8ff | 1202 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1203 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1204 | } |
bogdanm | 0:9b334a45a8ff | 1205 | |
bogdanm | 0:9b334a45a8ff | 1206 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1207 | { |
bogdanm | 0:9b334a45a8ff | 1208 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1209 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1210 | |
bogdanm | 0:9b334a45a8ff | 1211 | /* Get the buffer addresses and sizes */ |
bogdanm | 0:9b334a45a8ff | 1212 | hcryp->CrypInCount = Size; |
bogdanm | 0:9b334a45a8ff | 1213 | hcryp->pCrypInBuffPtr = pCypherData; |
bogdanm | 0:9b334a45a8ff | 1214 | hcryp->pCrypOutBuffPtr = pPlainData; |
bogdanm | 0:9b334a45a8ff | 1215 | hcryp->CrypOutCount = Size; |
bogdanm | 0:9b334a45a8ff | 1216 | |
bogdanm | 0:9b334a45a8ff | 1217 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1218 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1219 | |
bogdanm | 0:9b334a45a8ff | 1220 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1221 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1222 | { |
bogdanm | 0:9b334a45a8ff | 1223 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1224 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1225 | |
bogdanm | 0:9b334a45a8ff | 1226 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 1227 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 1228 | |
bogdanm | 0:9b334a45a8ff | 1229 | /* Set the CRYP peripheral in AES CTR decryption mode */ |
bogdanm | 0:9b334a45a8ff | 1230 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR_DECRYPT); |
bogdanm | 0:9b334a45a8ff | 1231 | |
bogdanm | 0:9b334a45a8ff | 1232 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 1233 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 1234 | |
bogdanm | 0:9b334a45a8ff | 1235 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1236 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1237 | } |
bogdanm | 0:9b334a45a8ff | 1238 | |
bogdanm | 0:9b334a45a8ff | 1239 | /* Enable Interrupts */ |
bogdanm | 0:9b334a45a8ff | 1240 | __HAL_CRYP_ENABLE_IT(AES_IT_CC); |
bogdanm | 0:9b334a45a8ff | 1241 | |
bogdanm | 0:9b334a45a8ff | 1242 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 1243 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 1244 | |
bogdanm | 0:9b334a45a8ff | 1245 | /* Get the last input data adress */ |
bogdanm | 0:9b334a45a8ff | 1246 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
bogdanm | 0:9b334a45a8ff | 1247 | |
bogdanm | 0:9b334a45a8ff | 1248 | /* Write the Input block in the Data Input register */ |
bogdanm | 0:9b334a45a8ff | 1249 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1250 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1251 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1252 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1253 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1254 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1255 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1256 | hcryp->pCrypInBuffPtr += 16; |
bogdanm | 0:9b334a45a8ff | 1257 | hcryp->CrypInCount -= 16; |
bogdanm | 0:9b334a45a8ff | 1258 | |
bogdanm | 0:9b334a45a8ff | 1259 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1260 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1261 | } |
bogdanm | 0:9b334a45a8ff | 1262 | else |
bogdanm | 0:9b334a45a8ff | 1263 | { |
bogdanm | 0:9b334a45a8ff | 1264 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1265 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1266 | } |
bogdanm | 0:9b334a45a8ff | 1267 | } |
bogdanm | 0:9b334a45a8ff | 1268 | |
bogdanm | 0:9b334a45a8ff | 1269 | /** |
bogdanm | 0:9b334a45a8ff | 1270 | * @brief Initializes the CRYP peripheral in AES ECB encryption mode using DMA. |
bogdanm | 0:9b334a45a8ff | 1271 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1272 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1273 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1274 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
bogdanm | 0:9b334a45a8ff | 1275 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1276 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1277 | */ |
bogdanm | 0:9b334a45a8ff | 1278 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
bogdanm | 0:9b334a45a8ff | 1279 | { |
bogdanm | 0:9b334a45a8ff | 1280 | uint32_t inputaddr = 0, outputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1281 | |
bogdanm | 0:9b334a45a8ff | 1282 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1283 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1284 | { |
bogdanm | 0:9b334a45a8ff | 1285 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1286 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1287 | |
bogdanm | 0:9b334a45a8ff | 1288 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1289 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1290 | } |
bogdanm | 0:9b334a45a8ff | 1291 | |
bogdanm | 0:9b334a45a8ff | 1292 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 1293 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1294 | { |
bogdanm | 0:9b334a45a8ff | 1295 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1296 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1297 | |
bogdanm | 0:9b334a45a8ff | 1298 | inputaddr = (uint32_t)pPlainData; |
bogdanm | 0:9b334a45a8ff | 1299 | outputaddr = (uint32_t)pCypherData; |
bogdanm | 0:9b334a45a8ff | 1300 | |
bogdanm | 0:9b334a45a8ff | 1301 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1302 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1303 | |
bogdanm | 0:9b334a45a8ff | 1304 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1305 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1306 | { |
bogdanm | 0:9b334a45a8ff | 1307 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1308 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1309 | |
bogdanm | 0:9b334a45a8ff | 1310 | /* Set the CRYP peripheral in AES ECB mode */ |
bogdanm | 0:9b334a45a8ff | 1311 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 1312 | |
bogdanm | 0:9b334a45a8ff | 1313 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1314 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1315 | } |
bogdanm | 0:9b334a45a8ff | 1316 | /* Set the input and output addresses and start DMA transfer */ |
bogdanm | 0:9b334a45a8ff | 1317 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
bogdanm | 0:9b334a45a8ff | 1318 | |
bogdanm | 0:9b334a45a8ff | 1319 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1320 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1321 | |
bogdanm | 0:9b334a45a8ff | 1322 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1323 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1324 | } |
bogdanm | 0:9b334a45a8ff | 1325 | else |
bogdanm | 0:9b334a45a8ff | 1326 | { |
bogdanm | 0:9b334a45a8ff | 1327 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1328 | } |
bogdanm | 0:9b334a45a8ff | 1329 | } |
bogdanm | 0:9b334a45a8ff | 1330 | |
bogdanm | 0:9b334a45a8ff | 1331 | /** |
bogdanm | 0:9b334a45a8ff | 1332 | * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA. |
bogdanm | 0:9b334a45a8ff | 1333 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1334 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1335 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1336 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 1337 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1338 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1339 | */ |
bogdanm | 0:9b334a45a8ff | 1340 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
bogdanm | 0:9b334a45a8ff | 1341 | { |
bogdanm | 0:9b334a45a8ff | 1342 | uint32_t inputaddr = 0, outputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1343 | |
bogdanm | 0:9b334a45a8ff | 1344 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1345 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1346 | { |
bogdanm | 0:9b334a45a8ff | 1347 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1348 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1349 | |
bogdanm | 0:9b334a45a8ff | 1350 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1351 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1352 | } |
bogdanm | 0:9b334a45a8ff | 1353 | |
bogdanm | 0:9b334a45a8ff | 1354 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 1355 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1356 | { |
bogdanm | 0:9b334a45a8ff | 1357 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1358 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1359 | |
bogdanm | 0:9b334a45a8ff | 1360 | inputaddr = (uint32_t)pPlainData; |
bogdanm | 0:9b334a45a8ff | 1361 | outputaddr = (uint32_t)pCypherData; |
bogdanm | 0:9b334a45a8ff | 1362 | |
bogdanm | 0:9b334a45a8ff | 1363 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1364 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1365 | |
bogdanm | 0:9b334a45a8ff | 1366 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1367 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1368 | { |
bogdanm | 0:9b334a45a8ff | 1369 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1370 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1371 | |
bogdanm | 0:9b334a45a8ff | 1372 | /* Set the CRYP peripheral in AES CBC mode */ |
bogdanm | 0:9b334a45a8ff | 1373 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 1374 | |
bogdanm | 0:9b334a45a8ff | 1375 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 1376 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 1377 | |
bogdanm | 0:9b334a45a8ff | 1378 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1379 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1380 | } |
bogdanm | 0:9b334a45a8ff | 1381 | /* Set the input and output addresses and start DMA transfer */ |
bogdanm | 0:9b334a45a8ff | 1382 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
bogdanm | 0:9b334a45a8ff | 1383 | |
bogdanm | 0:9b334a45a8ff | 1384 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1385 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1386 | |
bogdanm | 0:9b334a45a8ff | 1387 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1388 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1389 | } |
bogdanm | 0:9b334a45a8ff | 1390 | else |
bogdanm | 0:9b334a45a8ff | 1391 | { |
bogdanm | 0:9b334a45a8ff | 1392 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1393 | } |
bogdanm | 0:9b334a45a8ff | 1394 | } |
bogdanm | 0:9b334a45a8ff | 1395 | |
bogdanm | 0:9b334a45a8ff | 1396 | /** |
bogdanm | 0:9b334a45a8ff | 1397 | * @brief Initializes the CRYP peripheral in AES CTR encryption mode using DMA. |
bogdanm | 0:9b334a45a8ff | 1398 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1399 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1400 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1401 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 1402 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1403 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1404 | */ |
bogdanm | 0:9b334a45a8ff | 1405 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
bogdanm | 0:9b334a45a8ff | 1406 | { |
bogdanm | 0:9b334a45a8ff | 1407 | uint32_t inputaddr = 0, outputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1408 | |
bogdanm | 0:9b334a45a8ff | 1409 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1410 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1411 | { |
bogdanm | 0:9b334a45a8ff | 1412 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1413 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1414 | |
bogdanm | 0:9b334a45a8ff | 1415 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1416 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1417 | } |
bogdanm | 0:9b334a45a8ff | 1418 | |
bogdanm | 0:9b334a45a8ff | 1419 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 1420 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1421 | { |
bogdanm | 0:9b334a45a8ff | 1422 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1423 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1424 | |
bogdanm | 0:9b334a45a8ff | 1425 | inputaddr = (uint32_t)pPlainData; |
bogdanm | 0:9b334a45a8ff | 1426 | outputaddr = (uint32_t)pCypherData; |
bogdanm | 0:9b334a45a8ff | 1427 | |
bogdanm | 0:9b334a45a8ff | 1428 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1429 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1430 | |
bogdanm | 0:9b334a45a8ff | 1431 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1432 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1433 | { |
bogdanm | 0:9b334a45a8ff | 1434 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1435 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1436 | |
bogdanm | 0:9b334a45a8ff | 1437 | /* Set the CRYP peripheral in AES CTR mode */ |
bogdanm | 0:9b334a45a8ff | 1438 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT); |
bogdanm | 0:9b334a45a8ff | 1439 | |
bogdanm | 0:9b334a45a8ff | 1440 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 1441 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 1442 | |
bogdanm | 0:9b334a45a8ff | 1443 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1444 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1445 | } |
bogdanm | 0:9b334a45a8ff | 1446 | |
bogdanm | 0:9b334a45a8ff | 1447 | /* Set the input and output addresses and start DMA transfer */ |
bogdanm | 0:9b334a45a8ff | 1448 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
bogdanm | 0:9b334a45a8ff | 1449 | |
bogdanm | 0:9b334a45a8ff | 1450 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1451 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1452 | |
bogdanm | 0:9b334a45a8ff | 1453 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1454 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1455 | } |
bogdanm | 0:9b334a45a8ff | 1456 | else |
bogdanm | 0:9b334a45a8ff | 1457 | { |
bogdanm | 0:9b334a45a8ff | 1458 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1459 | } |
bogdanm | 0:9b334a45a8ff | 1460 | } |
bogdanm | 0:9b334a45a8ff | 1461 | |
bogdanm | 0:9b334a45a8ff | 1462 | /** |
bogdanm | 0:9b334a45a8ff | 1463 | * @brief Initializes the CRYP peripheral in AES ECB decryption mode using DMA. |
bogdanm | 0:9b334a45a8ff | 1464 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1465 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1466 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1467 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
bogdanm | 0:9b334a45a8ff | 1468 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1469 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1470 | */ |
bogdanm | 0:9b334a45a8ff | 1471 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
bogdanm | 0:9b334a45a8ff | 1472 | { |
bogdanm | 0:9b334a45a8ff | 1473 | uint32_t inputaddr = 0, outputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1474 | |
bogdanm | 0:9b334a45a8ff | 1475 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1476 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1477 | { |
bogdanm | 0:9b334a45a8ff | 1478 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1479 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1480 | |
bogdanm | 0:9b334a45a8ff | 1481 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1482 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1483 | } |
bogdanm | 0:9b334a45a8ff | 1484 | |
bogdanm | 0:9b334a45a8ff | 1485 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 1486 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1487 | { |
bogdanm | 0:9b334a45a8ff | 1488 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1489 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1490 | |
bogdanm | 0:9b334a45a8ff | 1491 | inputaddr = (uint32_t)pCypherData; |
bogdanm | 0:9b334a45a8ff | 1492 | outputaddr = (uint32_t)pPlainData; |
bogdanm | 0:9b334a45a8ff | 1493 | |
bogdanm | 0:9b334a45a8ff | 1494 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1495 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1496 | |
bogdanm | 0:9b334a45a8ff | 1497 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1498 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1499 | { |
bogdanm | 0:9b334a45a8ff | 1500 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1501 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1502 | |
bogdanm | 0:9b334a45a8ff | 1503 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 1504 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 1505 | |
bogdanm | 0:9b334a45a8ff | 1506 | /* Set the CRYP peripheral in AES ECB decryption mode (with key derivation) */ |
bogdanm | 0:9b334a45a8ff | 1507 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB_KEYDERDECRYPT); |
bogdanm | 0:9b334a45a8ff | 1508 | |
bogdanm | 0:9b334a45a8ff | 1509 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1510 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1511 | } |
bogdanm | 0:9b334a45a8ff | 1512 | |
bogdanm | 0:9b334a45a8ff | 1513 | /* Set the input and output addresses and start DMA transfer */ |
bogdanm | 0:9b334a45a8ff | 1514 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
bogdanm | 0:9b334a45a8ff | 1515 | |
bogdanm | 0:9b334a45a8ff | 1516 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1517 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1518 | |
bogdanm | 0:9b334a45a8ff | 1519 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1520 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1521 | } |
bogdanm | 0:9b334a45a8ff | 1522 | else |
bogdanm | 0:9b334a45a8ff | 1523 | { |
bogdanm | 0:9b334a45a8ff | 1524 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1525 | } |
bogdanm | 0:9b334a45a8ff | 1526 | } |
bogdanm | 0:9b334a45a8ff | 1527 | |
bogdanm | 0:9b334a45a8ff | 1528 | /** |
bogdanm | 0:9b334a45a8ff | 1529 | * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA. |
bogdanm | 0:9b334a45a8ff | 1530 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1531 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1532 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1533 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
bogdanm | 0:9b334a45a8ff | 1534 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1535 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1536 | */ |
bogdanm | 0:9b334a45a8ff | 1537 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
bogdanm | 0:9b334a45a8ff | 1538 | { |
bogdanm | 0:9b334a45a8ff | 1539 | uint32_t inputaddr = 0, outputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1540 | |
bogdanm | 0:9b334a45a8ff | 1541 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1542 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1543 | { |
bogdanm | 0:9b334a45a8ff | 1544 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1545 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1546 | |
bogdanm | 0:9b334a45a8ff | 1547 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1548 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1549 | } |
bogdanm | 0:9b334a45a8ff | 1550 | |
bogdanm | 0:9b334a45a8ff | 1551 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 1552 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1553 | { |
bogdanm | 0:9b334a45a8ff | 1554 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1555 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1556 | |
bogdanm | 0:9b334a45a8ff | 1557 | inputaddr = (uint32_t)pCypherData; |
bogdanm | 0:9b334a45a8ff | 1558 | outputaddr = (uint32_t)pPlainData; |
bogdanm | 0:9b334a45a8ff | 1559 | |
bogdanm | 0:9b334a45a8ff | 1560 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1561 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1562 | |
bogdanm | 0:9b334a45a8ff | 1563 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1564 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1565 | { |
bogdanm | 0:9b334a45a8ff | 1566 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1567 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1568 | |
bogdanm | 0:9b334a45a8ff | 1569 | /* Reset the CHMOD & MODE bits */ |
bogdanm | 0:9b334a45a8ff | 1570 | CLEAR_BIT(AES->CR, CRYP_ALGO_CHAIN_MASK); |
bogdanm | 0:9b334a45a8ff | 1571 | |
bogdanm | 0:9b334a45a8ff | 1572 | /* Set the CRYP peripheral in AES CBC decryption mode (with key derivation) */ |
bogdanm | 0:9b334a45a8ff | 1573 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC_KEYDERDECRYPT); |
bogdanm | 0:9b334a45a8ff | 1574 | |
bogdanm | 0:9b334a45a8ff | 1575 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 1576 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 1577 | |
bogdanm | 0:9b334a45a8ff | 1578 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1579 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1580 | } |
bogdanm | 0:9b334a45a8ff | 1581 | |
bogdanm | 0:9b334a45a8ff | 1582 | /* Set the input and output addresses and start DMA transfer */ |
bogdanm | 0:9b334a45a8ff | 1583 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
bogdanm | 0:9b334a45a8ff | 1584 | |
bogdanm | 0:9b334a45a8ff | 1585 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1586 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1587 | |
bogdanm | 0:9b334a45a8ff | 1588 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1589 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1590 | } |
bogdanm | 0:9b334a45a8ff | 1591 | else |
bogdanm | 0:9b334a45a8ff | 1592 | { |
bogdanm | 0:9b334a45a8ff | 1593 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1594 | } |
bogdanm | 0:9b334a45a8ff | 1595 | } |
bogdanm | 0:9b334a45a8ff | 1596 | |
bogdanm | 0:9b334a45a8ff | 1597 | /** |
bogdanm | 0:9b334a45a8ff | 1598 | * @brief Initializes the CRYP peripheral in AES CTR decryption mode using DMA. |
bogdanm | 0:9b334a45a8ff | 1599 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1600 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1601 | * @param pCypherData: Pointer to the cyphertext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1602 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 |
bogdanm | 0:9b334a45a8ff | 1603 | * @param pPlainData: Pointer to the plaintext buffer (aligned on u32) |
bogdanm | 0:9b334a45a8ff | 1604 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1605 | */ |
bogdanm | 0:9b334a45a8ff | 1606 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
bogdanm | 0:9b334a45a8ff | 1607 | { |
bogdanm | 0:9b334a45a8ff | 1608 | uint32_t inputaddr = 0, outputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1609 | |
bogdanm | 0:9b334a45a8ff | 1610 | /* Check that data aligned on u32 */ |
bogdanm | 0:9b334a45a8ff | 1611 | if((((uint32_t)pPlainData & (uint32_t)0x00000003) != 0) || (((uint32_t)pCypherData & (uint32_t)0x00000003) != 0) || ((Size & (uint16_t)0x000F) != 0)) |
bogdanm | 0:9b334a45a8ff | 1612 | { |
bogdanm | 0:9b334a45a8ff | 1613 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1614 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1615 | |
bogdanm | 0:9b334a45a8ff | 1616 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1617 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1618 | } |
bogdanm | 0:9b334a45a8ff | 1619 | |
bogdanm | 0:9b334a45a8ff | 1620 | /* Check if HAL_CRYP_Init has been called */ |
bogdanm | 0:9b334a45a8ff | 1621 | if ((hcryp->State != HAL_CRYP_STATE_RESET) && (hcryp->State == HAL_CRYP_STATE_READY)) |
bogdanm | 0:9b334a45a8ff | 1622 | { |
bogdanm | 0:9b334a45a8ff | 1623 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1624 | __HAL_LOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1625 | |
bogdanm | 0:9b334a45a8ff | 1626 | inputaddr = (uint32_t)pCypherData; |
bogdanm | 0:9b334a45a8ff | 1627 | outputaddr = (uint32_t)pPlainData; |
bogdanm | 0:9b334a45a8ff | 1628 | |
bogdanm | 0:9b334a45a8ff | 1629 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1630 | hcryp->State = HAL_CRYP_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1631 | |
bogdanm | 0:9b334a45a8ff | 1632 | /* Check if initialization phase has already been performed */ |
bogdanm | 0:9b334a45a8ff | 1633 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
bogdanm | 0:9b334a45a8ff | 1634 | { |
bogdanm | 0:9b334a45a8ff | 1635 | /* Set the key */ |
bogdanm | 0:9b334a45a8ff | 1636 | CRYP_SetKey(hcryp, hcryp->Init.pKey); |
bogdanm | 0:9b334a45a8ff | 1637 | |
bogdanm | 0:9b334a45a8ff | 1638 | /* Set the CRYP peripheral in AES CTR mode */ |
bogdanm | 0:9b334a45a8ff | 1639 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR_DECRYPT); |
bogdanm | 0:9b334a45a8ff | 1640 | |
bogdanm | 0:9b334a45a8ff | 1641 | /* Set the Initialization Vector */ |
bogdanm | 0:9b334a45a8ff | 1642 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect); |
bogdanm | 0:9b334a45a8ff | 1643 | |
bogdanm | 0:9b334a45a8ff | 1644 | /* Set the phase */ |
bogdanm | 0:9b334a45a8ff | 1645 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
bogdanm | 0:9b334a45a8ff | 1646 | } |
bogdanm | 0:9b334a45a8ff | 1647 | |
bogdanm | 0:9b334a45a8ff | 1648 | /* Set the input and output addresses and start DMA transfer */ |
bogdanm | 0:9b334a45a8ff | 1649 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
bogdanm | 0:9b334a45a8ff | 1650 | |
bogdanm | 0:9b334a45a8ff | 1651 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1652 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1653 | |
bogdanm | 0:9b334a45a8ff | 1654 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 1655 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1656 | } |
bogdanm | 0:9b334a45a8ff | 1657 | else |
bogdanm | 0:9b334a45a8ff | 1658 | { |
bogdanm | 0:9b334a45a8ff | 1659 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1660 | } |
bogdanm | 0:9b334a45a8ff | 1661 | } |
bogdanm | 0:9b334a45a8ff | 1662 | |
bogdanm | 0:9b334a45a8ff | 1663 | /** |
bogdanm | 0:9b334a45a8ff | 1664 | * @} |
bogdanm | 0:9b334a45a8ff | 1665 | */ |
bogdanm | 0:9b334a45a8ff | 1666 | |
bogdanm | 0:9b334a45a8ff | 1667 | /** @defgroup CRYP_Exported_Functions_Group3 DMA callback functions |
bogdanm | 0:9b334a45a8ff | 1668 | * @brief DMA callback functions. |
bogdanm | 0:9b334a45a8ff | 1669 | * |
bogdanm | 0:9b334a45a8ff | 1670 | @verbatim |
bogdanm | 0:9b334a45a8ff | 1671 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 1672 | ##### DMA callback functions ##### |
bogdanm | 0:9b334a45a8ff | 1673 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 1674 | [..] This section provides DMA callback functions: |
bogdanm | 0:9b334a45a8ff | 1675 | (+) DMA Input data transfer complete |
bogdanm | 0:9b334a45a8ff | 1676 | (+) DMA Output data transfer complete |
bogdanm | 0:9b334a45a8ff | 1677 | (+) DMA error |
bogdanm | 0:9b334a45a8ff | 1678 | |
bogdanm | 0:9b334a45a8ff | 1679 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 1680 | * @{ |
bogdanm | 0:9b334a45a8ff | 1681 | */ |
bogdanm | 0:9b334a45a8ff | 1682 | |
bogdanm | 0:9b334a45a8ff | 1683 | /** |
bogdanm | 0:9b334a45a8ff | 1684 | * @brief CRYP error callback. |
bogdanm | 0:9b334a45a8ff | 1685 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1686 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1687 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1688 | */ |
bogdanm | 0:9b334a45a8ff | 1689 | __weak void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 1690 | { |
bogdanm | 0:9b334a45a8ff | 1691 | /* NOTE : This function should not be modified; when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 1692 | the HAL_CRYP_ErrorCallback can be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 1693 | */ |
bogdanm | 0:9b334a45a8ff | 1694 | } |
bogdanm | 0:9b334a45a8ff | 1695 | |
bogdanm | 0:9b334a45a8ff | 1696 | /** |
bogdanm | 0:9b334a45a8ff | 1697 | * @brief Input transfer completed callback. |
bogdanm | 0:9b334a45a8ff | 1698 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1699 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1700 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1701 | */ |
bogdanm | 0:9b334a45a8ff | 1702 | __weak void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 1703 | { |
bogdanm | 0:9b334a45a8ff | 1704 | /* NOTE : This function should not be modified; when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 1705 | the HAL_CRYP_InCpltCallback can be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 1706 | */ |
bogdanm | 0:9b334a45a8ff | 1707 | } |
bogdanm | 0:9b334a45a8ff | 1708 | |
bogdanm | 0:9b334a45a8ff | 1709 | /** |
bogdanm | 0:9b334a45a8ff | 1710 | * @brief Output transfer completed callback. |
bogdanm | 0:9b334a45a8ff | 1711 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1712 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1713 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1714 | */ |
bogdanm | 0:9b334a45a8ff | 1715 | __weak void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 1716 | { |
bogdanm | 0:9b334a45a8ff | 1717 | /* NOTE : This function should not be modified; when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 1718 | the HAL_CRYP_OutCpltCallback can be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 1719 | */ |
bogdanm | 0:9b334a45a8ff | 1720 | } |
bogdanm | 0:9b334a45a8ff | 1721 | |
bogdanm | 0:9b334a45a8ff | 1722 | /** |
bogdanm | 0:9b334a45a8ff | 1723 | * @} |
bogdanm | 0:9b334a45a8ff | 1724 | */ |
bogdanm | 0:9b334a45a8ff | 1725 | |
bogdanm | 0:9b334a45a8ff | 1726 | /** @defgroup CRYP_Exported_Functions_Group4 CRYP IRQ handler |
bogdanm | 0:9b334a45a8ff | 1727 | * @brief CRYP IRQ handler. |
bogdanm | 0:9b334a45a8ff | 1728 | * |
bogdanm | 0:9b334a45a8ff | 1729 | @verbatim |
bogdanm | 0:9b334a45a8ff | 1730 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 1731 | ##### CRYP IRQ handler management ##### |
bogdanm | 0:9b334a45a8ff | 1732 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 1733 | [..] This section provides CRYP IRQ handler function. |
bogdanm | 0:9b334a45a8ff | 1734 | |
bogdanm | 0:9b334a45a8ff | 1735 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 1736 | * @{ |
bogdanm | 0:9b334a45a8ff | 1737 | */ |
bogdanm | 0:9b334a45a8ff | 1738 | |
bogdanm | 0:9b334a45a8ff | 1739 | /** |
bogdanm | 0:9b334a45a8ff | 1740 | * @brief This function handles CRYP interrupt request. |
bogdanm | 0:9b334a45a8ff | 1741 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1742 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1743 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1744 | */ |
bogdanm | 0:9b334a45a8ff | 1745 | void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 1746 | { |
bogdanm | 0:9b334a45a8ff | 1747 | /* Check if error occurred*/ |
bogdanm | 0:9b334a45a8ff | 1748 | if (__HAL_CRYP_GET_IT_SOURCE(hcryp, AES_IT_ERR) != RESET) |
bogdanm | 0:9b334a45a8ff | 1749 | { |
bogdanm | 0:9b334a45a8ff | 1750 | if (__HAL_CRYP_GET_FLAG(AES_FLAG_RDERR) != RESET) |
bogdanm | 0:9b334a45a8ff | 1751 | { |
bogdanm | 0:9b334a45a8ff | 1752 | __HAL_CRYP_CLEAR_FLAG(hcryp, AES_CLEARFLAG_RDERR); |
bogdanm | 0:9b334a45a8ff | 1753 | } |
bogdanm | 0:9b334a45a8ff | 1754 | |
bogdanm | 0:9b334a45a8ff | 1755 | if (__HAL_CRYP_GET_FLAG(AES_FLAG_WRERR) != RESET) |
bogdanm | 0:9b334a45a8ff | 1756 | { |
bogdanm | 0:9b334a45a8ff | 1757 | __HAL_CRYP_CLEAR_FLAG(hcryp, AES_CLEARFLAG_WRERR); |
bogdanm | 0:9b334a45a8ff | 1758 | } |
bogdanm | 0:9b334a45a8ff | 1759 | |
bogdanm | 0:9b334a45a8ff | 1760 | if (__HAL_CRYP_GET_FLAG(AES_FLAG_CCF) != RESET) |
bogdanm | 0:9b334a45a8ff | 1761 | { |
bogdanm | 0:9b334a45a8ff | 1762 | __HAL_CRYP_CLEAR_FLAG(hcryp, AES_CLEARFLAG_CCF); |
bogdanm | 0:9b334a45a8ff | 1763 | } |
bogdanm | 0:9b334a45a8ff | 1764 | |
bogdanm | 0:9b334a45a8ff | 1765 | hcryp->State= HAL_CRYP_STATE_ERROR; |
bogdanm | 0:9b334a45a8ff | 1766 | /* Disable Computation Complete Interrupt */ |
bogdanm | 0:9b334a45a8ff | 1767 | __HAL_CRYP_DISABLE_IT(AES_IT_CC); |
bogdanm | 0:9b334a45a8ff | 1768 | __HAL_CRYP_DISABLE_IT(AES_IT_ERR); |
bogdanm | 0:9b334a45a8ff | 1769 | |
bogdanm | 0:9b334a45a8ff | 1770 | HAL_CRYP_ErrorCallback(hcryp); |
bogdanm | 0:9b334a45a8ff | 1771 | |
bogdanm | 0:9b334a45a8ff | 1772 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1773 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1774 | |
bogdanm | 0:9b334a45a8ff | 1775 | return; |
bogdanm | 0:9b334a45a8ff | 1776 | } |
bogdanm | 0:9b334a45a8ff | 1777 | |
bogdanm | 0:9b334a45a8ff | 1778 | /* Check if computation complete interrupt was enabled*/ |
bogdanm | 0:9b334a45a8ff | 1779 | if (__HAL_CRYP_GET_IT_SOURCE(hcryp, AES_IT_CC) != RESET) |
bogdanm | 0:9b334a45a8ff | 1780 | { |
bogdanm | 0:9b334a45a8ff | 1781 | /* Clear CCF Flag */ |
bogdanm | 0:9b334a45a8ff | 1782 | __HAL_CRYP_CLEAR_FLAG(hcryp, AES_CLEARFLAG_CCF); |
bogdanm | 0:9b334a45a8ff | 1783 | |
bogdanm | 0:9b334a45a8ff | 1784 | CRYP_EncryptDecrypt_IT(hcryp); |
bogdanm | 0:9b334a45a8ff | 1785 | } |
bogdanm | 0:9b334a45a8ff | 1786 | } |
bogdanm | 0:9b334a45a8ff | 1787 | |
bogdanm | 0:9b334a45a8ff | 1788 | /** |
bogdanm | 0:9b334a45a8ff | 1789 | * @} |
bogdanm | 0:9b334a45a8ff | 1790 | */ |
bogdanm | 0:9b334a45a8ff | 1791 | |
bogdanm | 0:9b334a45a8ff | 1792 | /** @defgroup CRYP_Exported_Functions_Group5 Peripheral State functions |
bogdanm | 0:9b334a45a8ff | 1793 | * @brief Peripheral State functions. |
bogdanm | 0:9b334a45a8ff | 1794 | * |
bogdanm | 0:9b334a45a8ff | 1795 | @verbatim |
bogdanm | 0:9b334a45a8ff | 1796 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 1797 | ##### Peripheral State functions ##### |
bogdanm | 0:9b334a45a8ff | 1798 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 1799 | [..] |
bogdanm | 0:9b334a45a8ff | 1800 | This subsection permits to get in run-time the status of the peripheral. |
bogdanm | 0:9b334a45a8ff | 1801 | |
bogdanm | 0:9b334a45a8ff | 1802 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 1803 | * @{ |
bogdanm | 0:9b334a45a8ff | 1804 | */ |
bogdanm | 0:9b334a45a8ff | 1805 | |
bogdanm | 0:9b334a45a8ff | 1806 | /** |
bogdanm | 0:9b334a45a8ff | 1807 | * @brief Returns the CRYP state. |
bogdanm | 0:9b334a45a8ff | 1808 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1809 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1810 | * @retval HAL state |
bogdanm | 0:9b334a45a8ff | 1811 | */ |
bogdanm | 0:9b334a45a8ff | 1812 | HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 1813 | { |
bogdanm | 0:9b334a45a8ff | 1814 | return hcryp->State; |
bogdanm | 0:9b334a45a8ff | 1815 | } |
bogdanm | 0:9b334a45a8ff | 1816 | |
bogdanm | 0:9b334a45a8ff | 1817 | /** |
bogdanm | 0:9b334a45a8ff | 1818 | * @} |
bogdanm | 0:9b334a45a8ff | 1819 | */ |
bogdanm | 0:9b334a45a8ff | 1820 | |
bogdanm | 0:9b334a45a8ff | 1821 | /** |
bogdanm | 0:9b334a45a8ff | 1822 | * @} |
bogdanm | 0:9b334a45a8ff | 1823 | */ |
bogdanm | 0:9b334a45a8ff | 1824 | |
bogdanm | 0:9b334a45a8ff | 1825 | /** @addtogroup CRYP_Private_Functions |
bogdanm | 0:9b334a45a8ff | 1826 | * @{ |
bogdanm | 0:9b334a45a8ff | 1827 | */ |
bogdanm | 0:9b334a45a8ff | 1828 | |
bogdanm | 0:9b334a45a8ff | 1829 | /** |
bogdanm | 0:9b334a45a8ff | 1830 | * @brief IT function called under interruption context to continue encryption or decryption |
bogdanm | 0:9b334a45a8ff | 1831 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1832 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1833 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1834 | */ |
bogdanm | 0:9b334a45a8ff | 1835 | static HAL_StatusTypeDef CRYP_EncryptDecrypt_IT(CRYP_HandleTypeDef *hcryp) |
bogdanm | 0:9b334a45a8ff | 1836 | { |
bogdanm | 0:9b334a45a8ff | 1837 | uint32_t inputaddr = 0, outputaddr = 0; |
bogdanm | 0:9b334a45a8ff | 1838 | |
bogdanm | 0:9b334a45a8ff | 1839 | /* Get the last Output data adress */ |
bogdanm | 0:9b334a45a8ff | 1840 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
bogdanm | 0:9b334a45a8ff | 1841 | |
bogdanm | 0:9b334a45a8ff | 1842 | /* Read the Output block from the Output Register */ |
bogdanm | 0:9b334a45a8ff | 1843 | *(uint32_t*)(outputaddr) = AES->DOUTR; |
bogdanm | 0:9b334a45a8ff | 1844 | outputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1845 | *(uint32_t*)(outputaddr) = AES->DOUTR; |
bogdanm | 0:9b334a45a8ff | 1846 | outputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1847 | *(uint32_t*)(outputaddr) = AES->DOUTR; |
bogdanm | 0:9b334a45a8ff | 1848 | outputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1849 | *(uint32_t*)(outputaddr) = AES->DOUTR; |
bogdanm | 0:9b334a45a8ff | 1850 | |
bogdanm | 0:9b334a45a8ff | 1851 | hcryp->pCrypOutBuffPtr += 16; |
bogdanm | 0:9b334a45a8ff | 1852 | hcryp->CrypOutCount -= 16; |
bogdanm | 0:9b334a45a8ff | 1853 | |
bogdanm | 0:9b334a45a8ff | 1854 | /* Check if all input text is encrypted or decrypted */ |
bogdanm | 0:9b334a45a8ff | 1855 | if(hcryp->CrypOutCount == 0) |
bogdanm | 0:9b334a45a8ff | 1856 | { |
bogdanm | 0:9b334a45a8ff | 1857 | /* Disable Computation Complete Interrupt */ |
bogdanm | 0:9b334a45a8ff | 1858 | __HAL_CRYP_DISABLE_IT(AES_IT_CC); |
bogdanm | 0:9b334a45a8ff | 1859 | __HAL_CRYP_DISABLE_IT(AES_IT_ERR); |
bogdanm | 0:9b334a45a8ff | 1860 | |
bogdanm | 0:9b334a45a8ff | 1861 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1862 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 1863 | |
bogdanm | 0:9b334a45a8ff | 1864 | /* Change the CRYP state */ |
bogdanm | 0:9b334a45a8ff | 1865 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1866 | |
bogdanm | 0:9b334a45a8ff | 1867 | /* Call computation complete callback */ |
bogdanm | 0:9b334a45a8ff | 1868 | HAL_CRYPEx_ComputationCpltCallback(hcryp); |
bogdanm | 0:9b334a45a8ff | 1869 | } |
bogdanm | 0:9b334a45a8ff | 1870 | else /* Process the rest of input text */ |
bogdanm | 0:9b334a45a8ff | 1871 | { |
bogdanm | 0:9b334a45a8ff | 1872 | /* Get the last Intput data adress */ |
bogdanm | 0:9b334a45a8ff | 1873 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
bogdanm | 0:9b334a45a8ff | 1874 | |
bogdanm | 0:9b334a45a8ff | 1875 | /* Write the Input block in the Data Input register */ |
bogdanm | 0:9b334a45a8ff | 1876 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1877 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1878 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1879 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1880 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1881 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1882 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 1883 | hcryp->pCrypInBuffPtr += 16; |
bogdanm | 0:9b334a45a8ff | 1884 | hcryp->CrypInCount -= 16; |
bogdanm | 0:9b334a45a8ff | 1885 | } |
bogdanm | 0:9b334a45a8ff | 1886 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1887 | } |
bogdanm | 0:9b334a45a8ff | 1888 | /** |
bogdanm | 0:9b334a45a8ff | 1889 | * @brief DMA CRYP Input Data process complete callback. |
bogdanm | 0:9b334a45a8ff | 1890 | * @param hdma: DMA handle |
bogdanm | 0:9b334a45a8ff | 1891 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1892 | */ |
bogdanm | 0:9b334a45a8ff | 1893 | static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma) |
bogdanm | 0:9b334a45a8ff | 1894 | { |
bogdanm | 0:9b334a45a8ff | 1895 | CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
bogdanm | 0:9b334a45a8ff | 1896 | |
bogdanm | 0:9b334a45a8ff | 1897 | /* Disable the DMA transfer for input request */ |
bogdanm | 0:9b334a45a8ff | 1898 | CLEAR_BIT(AES->CR, AES_CR_DMAINEN); |
bogdanm | 0:9b334a45a8ff | 1899 | |
bogdanm | 0:9b334a45a8ff | 1900 | /* Call input data transfer complete callback */ |
bogdanm | 0:9b334a45a8ff | 1901 | HAL_CRYP_InCpltCallback(hcryp); |
bogdanm | 0:9b334a45a8ff | 1902 | } |
bogdanm | 0:9b334a45a8ff | 1903 | |
bogdanm | 0:9b334a45a8ff | 1904 | /** |
bogdanm | 0:9b334a45a8ff | 1905 | * @brief DMA CRYP Output Data process complete callback. |
bogdanm | 0:9b334a45a8ff | 1906 | * @param hdma: DMA handle |
bogdanm | 0:9b334a45a8ff | 1907 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1908 | */ |
bogdanm | 0:9b334a45a8ff | 1909 | static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma) |
bogdanm | 0:9b334a45a8ff | 1910 | { |
bogdanm | 0:9b334a45a8ff | 1911 | CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
bogdanm | 0:9b334a45a8ff | 1912 | |
bogdanm | 0:9b334a45a8ff | 1913 | /* Disable the DMA transfer for output request by resetting the DMAOUTEN bit |
bogdanm | 0:9b334a45a8ff | 1914 | in the DMACR register */ |
bogdanm | 0:9b334a45a8ff | 1915 | CLEAR_BIT(AES->CR, AES_CR_DMAOUTEN); |
bogdanm | 0:9b334a45a8ff | 1916 | |
bogdanm | 0:9b334a45a8ff | 1917 | /* Clear CCF Flag */ |
bogdanm | 0:9b334a45a8ff | 1918 | __HAL_CRYP_CLEAR_FLAG(hcryp, AES_CLEARFLAG_CCF); |
bogdanm | 0:9b334a45a8ff | 1919 | |
bogdanm | 0:9b334a45a8ff | 1920 | /* Disable CRYP */ |
bogdanm | 0:9b334a45a8ff | 1921 | __HAL_CRYP_DISABLE(); |
bogdanm | 0:9b334a45a8ff | 1922 | |
bogdanm | 0:9b334a45a8ff | 1923 | /* Change the CRYP state to ready */ |
bogdanm | 0:9b334a45a8ff | 1924 | hcryp->State = HAL_CRYP_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1925 | |
bogdanm | 0:9b334a45a8ff | 1926 | /* Call output data transfer complete callback */ |
bogdanm | 0:9b334a45a8ff | 1927 | HAL_CRYP_OutCpltCallback(hcryp); |
bogdanm | 0:9b334a45a8ff | 1928 | } |
bogdanm | 0:9b334a45a8ff | 1929 | |
bogdanm | 0:9b334a45a8ff | 1930 | /** |
bogdanm | 0:9b334a45a8ff | 1931 | * @brief DMA CRYP communication error callback. |
bogdanm | 0:9b334a45a8ff | 1932 | * @param hdma: DMA handle |
bogdanm | 0:9b334a45a8ff | 1933 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1934 | */ |
bogdanm | 0:9b334a45a8ff | 1935 | static void CRYP_DMAError(DMA_HandleTypeDef *hdma) |
bogdanm | 0:9b334a45a8ff | 1936 | { |
bogdanm | 0:9b334a45a8ff | 1937 | CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
bogdanm | 0:9b334a45a8ff | 1938 | hcryp->State= HAL_CRYP_STATE_ERROR; |
bogdanm | 0:9b334a45a8ff | 1939 | HAL_CRYP_ErrorCallback(hcryp); |
bogdanm | 0:9b334a45a8ff | 1940 | } |
bogdanm | 0:9b334a45a8ff | 1941 | |
bogdanm | 0:9b334a45a8ff | 1942 | /** |
bogdanm | 0:9b334a45a8ff | 1943 | * @brief Writes the Key in Key registers. |
bogdanm | 0:9b334a45a8ff | 1944 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1945 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1946 | * @param Key: Pointer to Key buffer |
bogdanm | 0:9b334a45a8ff | 1947 | * @note Key must be written as little endian. |
bogdanm | 0:9b334a45a8ff | 1948 | * If Key pointer points at address n, |
bogdanm | 0:9b334a45a8ff | 1949 | * n[15:0] contains key[96:127], |
bogdanm | 0:9b334a45a8ff | 1950 | * (n+4)[15:0] contains key[64:95], |
bogdanm | 0:9b334a45a8ff | 1951 | * (n+8)[15:0] contains key[32:63] and |
bogdanm | 0:9b334a45a8ff | 1952 | * (n+12)[15:0] contains key[0:31] |
bogdanm | 0:9b334a45a8ff | 1953 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1954 | */ |
bogdanm | 0:9b334a45a8ff | 1955 | static void CRYP_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key) |
bogdanm | 0:9b334a45a8ff | 1956 | { |
bogdanm | 0:9b334a45a8ff | 1957 | uint32_t keyaddr = (uint32_t)Key; |
bogdanm | 0:9b334a45a8ff | 1958 | |
bogdanm | 0:9b334a45a8ff | 1959 | AES->KEYR3 = __REV(*(uint32_t*)(keyaddr)); |
bogdanm | 0:9b334a45a8ff | 1960 | keyaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1961 | AES->KEYR2 = __REV(*(uint32_t*)(keyaddr)); |
bogdanm | 0:9b334a45a8ff | 1962 | keyaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1963 | AES->KEYR1 = __REV(*(uint32_t*)(keyaddr)); |
bogdanm | 0:9b334a45a8ff | 1964 | keyaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1965 | AES->KEYR0 = __REV(*(uint32_t*)(keyaddr)); |
bogdanm | 0:9b334a45a8ff | 1966 | } |
bogdanm | 0:9b334a45a8ff | 1967 | |
bogdanm | 0:9b334a45a8ff | 1968 | /** |
bogdanm | 0:9b334a45a8ff | 1969 | * @brief Writes the InitVector/InitCounter in IV registers. |
bogdanm | 0:9b334a45a8ff | 1970 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1971 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1972 | * @param InitVector: Pointer to InitVector/InitCounter buffer |
bogdanm | 0:9b334a45a8ff | 1973 | * @note Init Vector must be written as little endian. |
bogdanm | 0:9b334a45a8ff | 1974 | * If Init Vector pointer points at address n, |
bogdanm | 0:9b334a45a8ff | 1975 | * n[15:0] contains Vector[96:127], |
bogdanm | 0:9b334a45a8ff | 1976 | * (n+4)[15:0] contains Vector[64:95], |
bogdanm | 0:9b334a45a8ff | 1977 | * (n+8)[15:0] contains Vector[32:63] and |
bogdanm | 0:9b334a45a8ff | 1978 | * (n+12)[15:0] contains Vector[0:31] |
bogdanm | 0:9b334a45a8ff | 1979 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1980 | */ |
bogdanm | 0:9b334a45a8ff | 1981 | static void CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector) |
bogdanm | 0:9b334a45a8ff | 1982 | { |
bogdanm | 0:9b334a45a8ff | 1983 | uint32_t ivaddr = (uint32_t)InitVector; |
bogdanm | 0:9b334a45a8ff | 1984 | |
bogdanm | 0:9b334a45a8ff | 1985 | AES->IVR3 = __REV(*(uint32_t*)(ivaddr)); |
bogdanm | 0:9b334a45a8ff | 1986 | ivaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1987 | AES->IVR2 = __REV(*(uint32_t*)(ivaddr)); |
bogdanm | 0:9b334a45a8ff | 1988 | ivaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1989 | AES->IVR1 = __REV(*(uint32_t*)(ivaddr)); |
bogdanm | 0:9b334a45a8ff | 1990 | ivaddr+=4; |
bogdanm | 0:9b334a45a8ff | 1991 | AES->IVR0 = __REV(*(uint32_t*)(ivaddr)); |
bogdanm | 0:9b334a45a8ff | 1992 | } |
bogdanm | 0:9b334a45a8ff | 1993 | |
bogdanm | 0:9b334a45a8ff | 1994 | /** |
bogdanm | 0:9b334a45a8ff | 1995 | * @brief Process Data: Writes Input data in polling mode and reads the output data |
bogdanm | 0:9b334a45a8ff | 1996 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 1997 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 1998 | * @param Input: Pointer to the Input buffer |
bogdanm | 0:9b334a45a8ff | 1999 | * @param Ilength: Length of the Input buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 2000 | * @param Output: Pointer to the returned buffer |
bogdanm | 0:9b334a45a8ff | 2001 | * @param Timeout: Specify Timeout value |
bogdanm | 0:9b334a45a8ff | 2002 | * @retval None |
bogdanm | 0:9b334a45a8ff | 2003 | */ |
bogdanm | 0:9b334a45a8ff | 2004 | static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 2005 | { |
bogdanm | 0:9b334a45a8ff | 2006 | uint32_t tickstart = 0; |
bogdanm | 0:9b334a45a8ff | 2007 | |
bogdanm | 0:9b334a45a8ff | 2008 | uint32_t index = 0; |
bogdanm | 0:9b334a45a8ff | 2009 | uint32_t inputaddr = (uint32_t)Input; |
bogdanm | 0:9b334a45a8ff | 2010 | uint32_t outputaddr = (uint32_t)Output; |
bogdanm | 0:9b334a45a8ff | 2011 | |
bogdanm | 0:9b334a45a8ff | 2012 | for(index=0; (index < Ilength); index += 16) |
bogdanm | 0:9b334a45a8ff | 2013 | { |
bogdanm | 0:9b334a45a8ff | 2014 | /* Write the Input block in the Data Input register */ |
bogdanm | 0:9b334a45a8ff | 2015 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 2016 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 2017 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 2018 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 2019 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 2020 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 2021 | AES->DINR = *(uint32_t*)(inputaddr); |
bogdanm | 0:9b334a45a8ff | 2022 | inputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 2023 | |
bogdanm | 0:9b334a45a8ff | 2024 | /* Get timeout */ |
bogdanm | 0:9b334a45a8ff | 2025 | tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 2026 | |
bogdanm | 0:9b334a45a8ff | 2027 | while(HAL_IS_BIT_CLR(AES->SR, AES_SR_CCF)) |
bogdanm | 0:9b334a45a8ff | 2028 | { |
bogdanm | 0:9b334a45a8ff | 2029 | /* Check for the Timeout */ |
bogdanm | 0:9b334a45a8ff | 2030 | if(Timeout != HAL_MAX_DELAY) |
bogdanm | 0:9b334a45a8ff | 2031 | { |
bogdanm | 0:9b334a45a8ff | 2032 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
bogdanm | 0:9b334a45a8ff | 2033 | { |
bogdanm | 0:9b334a45a8ff | 2034 | /* Change state */ |
bogdanm | 0:9b334a45a8ff | 2035 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 2036 | |
bogdanm | 0:9b334a45a8ff | 2037 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 2038 | __HAL_UNLOCK(hcryp); |
bogdanm | 0:9b334a45a8ff | 2039 | |
bogdanm | 0:9b334a45a8ff | 2040 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 2041 | } |
bogdanm | 0:9b334a45a8ff | 2042 | } |
bogdanm | 0:9b334a45a8ff | 2043 | } |
bogdanm | 0:9b334a45a8ff | 2044 | /* Clear CCF Flag */ |
bogdanm | 0:9b334a45a8ff | 2045 | __HAL_CRYP_CLEAR_FLAG(hcryp, AES_CLEARFLAG_CCF); |
bogdanm | 0:9b334a45a8ff | 2046 | |
bogdanm | 0:9b334a45a8ff | 2047 | /* Read the Output block from the Data Output Register */ |
bogdanm | 0:9b334a45a8ff | 2048 | *(uint32_t*)(outputaddr) = AES->DOUTR; |
bogdanm | 0:9b334a45a8ff | 2049 | outputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 2050 | *(uint32_t*)(outputaddr) = AES->DOUTR; |
bogdanm | 0:9b334a45a8ff | 2051 | outputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 2052 | *(uint32_t*)(outputaddr) = AES->DOUTR; |
bogdanm | 0:9b334a45a8ff | 2053 | outputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 2054 | *(uint32_t*)(outputaddr) = AES->DOUTR; |
bogdanm | 0:9b334a45a8ff | 2055 | outputaddr+=4; |
bogdanm | 0:9b334a45a8ff | 2056 | } |
bogdanm | 0:9b334a45a8ff | 2057 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 2058 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 2059 | } |
bogdanm | 0:9b334a45a8ff | 2060 | |
bogdanm | 0:9b334a45a8ff | 2061 | /** |
bogdanm | 0:9b334a45a8ff | 2062 | * @brief Set the DMA configuration and start the DMA transfer |
bogdanm | 0:9b334a45a8ff | 2063 | * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains |
bogdanm | 0:9b334a45a8ff | 2064 | * the configuration information for CRYP module |
bogdanm | 0:9b334a45a8ff | 2065 | * @param inputaddr: address of the Input buffer |
bogdanm | 0:9b334a45a8ff | 2066 | * @param Size: Size of the Input buffer, must be a multiple of 16. |
bogdanm | 0:9b334a45a8ff | 2067 | * @param outputaddr: address of the Output buffer |
bogdanm | 0:9b334a45a8ff | 2068 | * @retval None |
bogdanm | 0:9b334a45a8ff | 2069 | */ |
bogdanm | 0:9b334a45a8ff | 2070 | static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr) |
bogdanm | 0:9b334a45a8ff | 2071 | { |
bogdanm | 0:9b334a45a8ff | 2072 | /* Set the CRYP DMA transfer complete callback */ |
bogdanm | 0:9b334a45a8ff | 2073 | hcryp->hdmain->XferCpltCallback = CRYP_DMAInCplt; |
bogdanm | 0:9b334a45a8ff | 2074 | /* Set the DMA error callback */ |
bogdanm | 0:9b334a45a8ff | 2075 | hcryp->hdmain->XferErrorCallback = CRYP_DMAError; |
bogdanm | 0:9b334a45a8ff | 2076 | |
bogdanm | 0:9b334a45a8ff | 2077 | /* Set the CRYP DMA transfer complete callback */ |
bogdanm | 0:9b334a45a8ff | 2078 | hcryp->hdmaout->XferCpltCallback = CRYP_DMAOutCplt; |
bogdanm | 0:9b334a45a8ff | 2079 | /* Set the DMA error callback */ |
bogdanm | 0:9b334a45a8ff | 2080 | hcryp->hdmaout->XferErrorCallback = CRYP_DMAError; |
bogdanm | 0:9b334a45a8ff | 2081 | |
bogdanm | 0:9b334a45a8ff | 2082 | /* Enable the DMA In DMA Stream */ |
bogdanm | 0:9b334a45a8ff | 2083 | HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&AES->DINR, Size/4); |
bogdanm | 0:9b334a45a8ff | 2084 | |
bogdanm | 0:9b334a45a8ff | 2085 | /* Enable the DMA Out DMA Stream */ |
bogdanm | 0:9b334a45a8ff | 2086 | HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&AES->DOUTR, outputaddr, Size/4); |
bogdanm | 0:9b334a45a8ff | 2087 | |
bogdanm | 0:9b334a45a8ff | 2088 | /* Enable In and Out DMA requests */ |
bogdanm | 0:9b334a45a8ff | 2089 | SET_BIT(AES->CR, (AES_CR_DMAINEN | AES_CR_DMAOUTEN)); |
bogdanm | 0:9b334a45a8ff | 2090 | |
bogdanm | 0:9b334a45a8ff | 2091 | /* Enable CRYP */ |
bogdanm | 0:9b334a45a8ff | 2092 | __HAL_CRYP_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 2093 | } |
bogdanm | 0:9b334a45a8ff | 2094 | |
bogdanm | 0:9b334a45a8ff | 2095 | /** |
bogdanm | 0:9b334a45a8ff | 2096 | * @} |
bogdanm | 0:9b334a45a8ff | 2097 | */ |
bogdanm | 0:9b334a45a8ff | 2098 | |
bogdanm | 0:9b334a45a8ff | 2099 | #endif /* STM32L162xC || STM32L162xCA || STM32L162xD || STM32L162xE*/ |
bogdanm | 0:9b334a45a8ff | 2100 | |
bogdanm | 0:9b334a45a8ff | 2101 | /** |
bogdanm | 0:9b334a45a8ff | 2102 | * @} |
bogdanm | 0:9b334a45a8ff | 2103 | */ |
bogdanm | 0:9b334a45a8ff | 2104 | |
bogdanm | 0:9b334a45a8ff | 2105 | /** |
bogdanm | 0:9b334a45a8ff | 2106 | * @} |
bogdanm | 0:9b334a45a8ff | 2107 | */ |
bogdanm | 0:9b334a45a8ff | 2108 | |
bogdanm | 0:9b334a45a8ff | 2109 | #endif /* HAL_CRYP_MODULE_ENABLED */ |
bogdanm | 0:9b334a45a8ff | 2110 | |
bogdanm | 0:9b334a45a8ff | 2111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |