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