mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_cryp.c@87:085cde657901, 2014-02-08 (annotated)
- Committer:
- mbed_official
- Date:
- Sat Feb 08 19:45:06 2014 +0000
- Revision:
- 87:085cde657901
- Child:
- 106:ced8cbb51063
Synchronized with git revision 9272cdeb45ec7e6077641536509413da8fd2ebc2
Full URL: https://github.com/mbedmicro/mbed/commit/9272cdeb45ec7e6077641536509413da8fd2ebc2/
Add NUCLEO_F401RE, improvements
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 87:085cde657901 | 1 | /** |
mbed_official | 87:085cde657901 | 2 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 3 | * @file stm32f4xx_hal_cryp.c |
mbed_official | 87:085cde657901 | 4 | * @author MCD Application Team |
mbed_official | 87:085cde657901 | 5 | * @version V1.0.0RC2 |
mbed_official | 87:085cde657901 | 6 | * @date 04-February-2014 |
mbed_official | 87:085cde657901 | 7 | * @brief CRYP HAL module driver. |
mbed_official | 87:085cde657901 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 87:085cde657901 | 9 | * functionalities of the Cryptography (CRYP) peripheral: |
mbed_official | 87:085cde657901 | 10 | * + Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 11 | * + AES processing functions |
mbed_official | 87:085cde657901 | 12 | * + DES processing functions |
mbed_official | 87:085cde657901 | 13 | * + TDES processing functions |
mbed_official | 87:085cde657901 | 14 | * + DMA callback functions |
mbed_official | 87:085cde657901 | 15 | * + CRYP IRQ handler management |
mbed_official | 87:085cde657901 | 16 | * + Peripheral State functions |
mbed_official | 87:085cde657901 | 17 | * |
mbed_official | 87:085cde657901 | 18 | @verbatim |
mbed_official | 87:085cde657901 | 19 | ============================================================================== |
mbed_official | 87:085cde657901 | 20 | ##### How to use this driver ##### |
mbed_official | 87:085cde657901 | 21 | ============================================================================== |
mbed_official | 87:085cde657901 | 22 | [..] |
mbed_official | 87:085cde657901 | 23 | The CRYP HAL driver can be used as follows: |
mbed_official | 87:085cde657901 | 24 | |
mbed_official | 87:085cde657901 | 25 | (#)Initialize the CRYP low level resources by implementing the HAL_CRYP_MspInit(): |
mbed_official | 87:085cde657901 | 26 | (##) Enable the CRYP interface clock using __CRYP_CLK_ENABLE() |
mbed_official | 87:085cde657901 | 27 | (##) In case of using interrupts (e.g. HAL_CRYP_AESECB_Encrypt_IT()) |
mbed_official | 87:085cde657901 | 28 | (+++) Configure the CRYP interrupt priority using HAL_NVIC_SetPriority() |
mbed_official | 87:085cde657901 | 29 | (+++) Enable the CRYP IRQ handler using HAL_NVIC_EnableIRQ() |
mbed_official | 87:085cde657901 | 30 | (+++) In CRYP IRQ handler, call HAL_CRYP_IRQHandler() |
mbed_official | 87:085cde657901 | 31 | (##) In case of using DMA to control data transfer (e.g. HAL_CRYP_AESECB_Encrypt_DMA()) |
mbed_official | 87:085cde657901 | 32 | (++) Enable the DMAx interface clock using |
mbed_official | 87:085cde657901 | 33 | (+++) __DMAx_CLK_ENABLE() |
mbed_official | 87:085cde657901 | 34 | (++) Configure and enable two DMA streams one for managing data transfer from |
mbed_official | 87:085cde657901 | 35 | memory to peripheral (input stream) and another stream for managing data |
mbed_official | 87:085cde657901 | 36 | transfer from peripheral to memory (output stream) |
mbed_official | 87:085cde657901 | 37 | (++) Associate the initilalized DMA handle to the CRYP DMA handle |
mbed_official | 87:085cde657901 | 38 | using __HAL_LINKDMA() |
mbed_official | 87:085cde657901 | 39 | (++) Configure the priority and enable the NVIC for the transfer complete |
mbed_official | 87:085cde657901 | 40 | interrupt on the two DMA Streams. The output stream should have higher |
mbed_official | 87:085cde657901 | 41 | priority than the input stream. |
mbed_official | 87:085cde657901 | 42 | (+++) HAL_NVIC_SetPriority() |
mbed_official | 87:085cde657901 | 43 | (+++) HAL_NVIC_EnableIRQ() |
mbed_official | 87:085cde657901 | 44 | |
mbed_official | 87:085cde657901 | 45 | (#)Initialize the CRYP HAL using HAL_CRYP_Init(). This function configures mainly: |
mbed_official | 87:085cde657901 | 46 | (##) The data type: 1-bit, 8-bit, 16-bit and 32-bit |
mbed_official | 87:085cde657901 | 47 | (##) The key size: 128, 192 and 256. This parameter is relevant only for AES |
mbed_official | 87:085cde657901 | 48 | (##) The encryption/decryption key. It's size depends on the algorithm |
mbed_official | 87:085cde657901 | 49 | used for encryption/decryption |
mbed_official | 87:085cde657901 | 50 | (##) The initialization vector (counter). It is not used ECB mode. |
mbed_official | 87:085cde657901 | 51 | |
mbed_official | 87:085cde657901 | 52 | (#)Three processing (encryption/decryption) functions are available: |
mbed_official | 87:085cde657901 | 53 | (##) Polling mode: encryption and decryption APIs are blocking functions |
mbed_official | 87:085cde657901 | 54 | i.e. they process the data and wait till the processing is finished |
mbed_official | 87:085cde657901 | 55 | e.g. HAL_CRYP_AESCBC_Encrypt() |
mbed_official | 87:085cde657901 | 56 | (##) Interrupt mode: encryption and decryption APIs are not blocking functions |
mbed_official | 87:085cde657901 | 57 | i.e. they process the data under interrupt |
mbed_official | 87:085cde657901 | 58 | e.g. HAL_CRYP_AESCBC_Encrypt_IT() |
mbed_official | 87:085cde657901 | 59 | (##) DMA mode: encryption and decryption APIs are not blocking functions |
mbed_official | 87:085cde657901 | 60 | i.e. the data transfer is ensured by DMA |
mbed_official | 87:085cde657901 | 61 | e.g. HAL_CRYP_AESCBC_Encrypt_DMA() |
mbed_official | 87:085cde657901 | 62 | |
mbed_official | 87:085cde657901 | 63 | (#)When the processing function is called at first time after HAL_CRYP_Init() |
mbed_official | 87:085cde657901 | 64 | the CRYP peripheral is initialized and processes the buffer in input. |
mbed_official | 87:085cde657901 | 65 | At second call, the processing function performs an append of the already |
mbed_official | 87:085cde657901 | 66 | processed buffer. |
mbed_official | 87:085cde657901 | 67 | When a new data block is to be processed, call HAL_CRYP_Init() then the |
mbed_official | 87:085cde657901 | 68 | processing function. |
mbed_official | 87:085cde657901 | 69 | |
mbed_official | 87:085cde657901 | 70 | (#)Call HAL_CRYP_DeInit() to deinitialize the CRYP peripheral. |
mbed_official | 87:085cde657901 | 71 | |
mbed_official | 87:085cde657901 | 72 | @endverbatim |
mbed_official | 87:085cde657901 | 73 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 74 | * @attention |
mbed_official | 87:085cde657901 | 75 | * |
mbed_official | 87:085cde657901 | 76 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 87:085cde657901 | 77 | * |
mbed_official | 87:085cde657901 | 78 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 87:085cde657901 | 79 | * are permitted provided that the following conditions are met: |
mbed_official | 87:085cde657901 | 80 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 87:085cde657901 | 81 | * this list of conditions and the following disclaimer. |
mbed_official | 87:085cde657901 | 82 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 87:085cde657901 | 83 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 87:085cde657901 | 84 | * and/or other materials provided with the distribution. |
mbed_official | 87:085cde657901 | 85 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 87:085cde657901 | 86 | * may be used to endorse or promote products derived from this software |
mbed_official | 87:085cde657901 | 87 | * without specific prior written permission. |
mbed_official | 87:085cde657901 | 88 | * |
mbed_official | 87:085cde657901 | 89 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 87:085cde657901 | 90 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 87:085cde657901 | 91 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 87:085cde657901 | 92 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 87:085cde657901 | 93 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 87:085cde657901 | 94 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 87:085cde657901 | 95 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 87:085cde657901 | 96 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 87:085cde657901 | 97 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 87:085cde657901 | 98 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 87:085cde657901 | 99 | * |
mbed_official | 87:085cde657901 | 100 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 101 | */ |
mbed_official | 87:085cde657901 | 102 | |
mbed_official | 87:085cde657901 | 103 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 104 | #include "stm32f4xx_hal.h" |
mbed_official | 87:085cde657901 | 105 | |
mbed_official | 87:085cde657901 | 106 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 87:085cde657901 | 107 | * @{ |
mbed_official | 87:085cde657901 | 108 | */ |
mbed_official | 87:085cde657901 | 109 | |
mbed_official | 87:085cde657901 | 110 | /** @defgroup CRYP |
mbed_official | 87:085cde657901 | 111 | * @brief CRYP HAL module driver. |
mbed_official | 87:085cde657901 | 112 | * @{ |
mbed_official | 87:085cde657901 | 113 | */ |
mbed_official | 87:085cde657901 | 114 | |
mbed_official | 87:085cde657901 | 115 | #ifdef HAL_CRYP_MODULE_ENABLED |
mbed_official | 87:085cde657901 | 116 | |
mbed_official | 87:085cde657901 | 117 | #if defined(STM32F415xx) || defined(STM32F417xx) || defined(STM32F437xx) || defined(STM32F439xx) |
mbed_official | 87:085cde657901 | 118 | |
mbed_official | 87:085cde657901 | 119 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 120 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 121 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 122 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 123 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 87:085cde657901 | 124 | static void CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector, uint32_t IVSize); |
mbed_official | 87:085cde657901 | 125 | static void CRYP_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key, uint32_t KeySize); |
mbed_official | 87:085cde657901 | 126 | static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout); |
mbed_official | 87:085cde657901 | 127 | static HAL_StatusTypeDef CRYP_ProcessData2Words(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout); |
mbed_official | 87:085cde657901 | 128 | static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 129 | static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 130 | static void CRYP_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 131 | static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr); |
mbed_official | 87:085cde657901 | 132 | static void CRYP_SetTDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction); |
mbed_official | 87:085cde657901 | 133 | static void CRYP_SetTDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction); |
mbed_official | 87:085cde657901 | 134 | static void CRYP_SetDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction); |
mbed_official | 87:085cde657901 | 135 | static void CRYP_SetDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction); |
mbed_official | 87:085cde657901 | 136 | |
mbed_official | 87:085cde657901 | 137 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 138 | |
mbed_official | 87:085cde657901 | 139 | /** @defgroup CRYP_Private_Functions |
mbed_official | 87:085cde657901 | 140 | * @{ |
mbed_official | 87:085cde657901 | 141 | */ |
mbed_official | 87:085cde657901 | 142 | |
mbed_official | 87:085cde657901 | 143 | /** @defgroup CRYP_Group1 Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 144 | * @brief Initialization and Configuration functions. |
mbed_official | 87:085cde657901 | 145 | * |
mbed_official | 87:085cde657901 | 146 | @verbatim |
mbed_official | 87:085cde657901 | 147 | ============================================================================== |
mbed_official | 87:085cde657901 | 148 | ##### Initialization and de-initialization functions ##### |
mbed_official | 87:085cde657901 | 149 | ============================================================================== |
mbed_official | 87:085cde657901 | 150 | [..] This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 151 | (+) Initialize the CRYP according to the specified parameters |
mbed_official | 87:085cde657901 | 152 | in the CRYP_InitTypeDef and creates the associated handle |
mbed_official | 87:085cde657901 | 153 | (+) DeInitialize the CRYP peripheral |
mbed_official | 87:085cde657901 | 154 | (+) Initialize the CRYP MSP |
mbed_official | 87:085cde657901 | 155 | (+) DeInitialize CRYP MSP |
mbed_official | 87:085cde657901 | 156 | |
mbed_official | 87:085cde657901 | 157 | @endverbatim |
mbed_official | 87:085cde657901 | 158 | * @{ |
mbed_official | 87:085cde657901 | 159 | */ |
mbed_official | 87:085cde657901 | 160 | |
mbed_official | 87:085cde657901 | 161 | /** |
mbed_official | 87:085cde657901 | 162 | * @brief Initializes the CRYP according to the specified |
mbed_official | 87:085cde657901 | 163 | * parameters in the CRYP_InitTypeDef and creates the associated handle. |
mbed_official | 87:085cde657901 | 164 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 165 | * @retval HAL status |
mbed_official | 87:085cde657901 | 166 | */ |
mbed_official | 87:085cde657901 | 167 | HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 168 | { |
mbed_official | 87:085cde657901 | 169 | /* Check the CRYP handle allocation */ |
mbed_official | 87:085cde657901 | 170 | if(hcryp == NULL) |
mbed_official | 87:085cde657901 | 171 | { |
mbed_official | 87:085cde657901 | 172 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 173 | } |
mbed_official | 87:085cde657901 | 174 | |
mbed_official | 87:085cde657901 | 175 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 176 | assert_param(IS_CRYP_KEYSIZE(hcryp->Init.KeySize)); |
mbed_official | 87:085cde657901 | 177 | assert_param(IS_CRYP_DATATYPE(hcryp->Init.DataType)); |
mbed_official | 87:085cde657901 | 178 | |
mbed_official | 87:085cde657901 | 179 | if(hcryp->State == HAL_CRYP_STATE_RESET) |
mbed_official | 87:085cde657901 | 180 | { |
mbed_official | 87:085cde657901 | 181 | /* Init the low level hardware */ |
mbed_official | 87:085cde657901 | 182 | HAL_CRYP_MspInit(hcryp); |
mbed_official | 87:085cde657901 | 183 | } |
mbed_official | 87:085cde657901 | 184 | |
mbed_official | 87:085cde657901 | 185 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 186 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 187 | |
mbed_official | 87:085cde657901 | 188 | /* Set the key size and data type*/ |
mbed_official | 87:085cde657901 | 189 | CRYP->CR = (uint32_t) (hcryp->Init.KeySize | hcryp->Init.DataType); |
mbed_official | 87:085cde657901 | 190 | |
mbed_official | 87:085cde657901 | 191 | /* Reset CrypInCount and CrypOutCount */ |
mbed_official | 87:085cde657901 | 192 | hcryp->CrypInCount = 0; |
mbed_official | 87:085cde657901 | 193 | hcryp->CrypOutCount = 0; |
mbed_official | 87:085cde657901 | 194 | |
mbed_official | 87:085cde657901 | 195 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 196 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 197 | |
mbed_official | 87:085cde657901 | 198 | /* Set the default CRYP phase */ |
mbed_official | 87:085cde657901 | 199 | hcryp->Phase = HAL_CRYP_PHASE_READY; |
mbed_official | 87:085cde657901 | 200 | |
mbed_official | 87:085cde657901 | 201 | /* Return function status */ |
mbed_official | 87:085cde657901 | 202 | return HAL_OK; |
mbed_official | 87:085cde657901 | 203 | } |
mbed_official | 87:085cde657901 | 204 | |
mbed_official | 87:085cde657901 | 205 | /** |
mbed_official | 87:085cde657901 | 206 | * @brief DeInitializes the CRYP peripheral. |
mbed_official | 87:085cde657901 | 207 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 208 | * @retval HAL status |
mbed_official | 87:085cde657901 | 209 | */ |
mbed_official | 87:085cde657901 | 210 | HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 211 | { |
mbed_official | 87:085cde657901 | 212 | /* Check the CRYP handle allocation */ |
mbed_official | 87:085cde657901 | 213 | if(hcryp == NULL) |
mbed_official | 87:085cde657901 | 214 | { |
mbed_official | 87:085cde657901 | 215 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 216 | } |
mbed_official | 87:085cde657901 | 217 | |
mbed_official | 87:085cde657901 | 218 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 219 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 220 | |
mbed_official | 87:085cde657901 | 221 | /* Set the default CRYP phase */ |
mbed_official | 87:085cde657901 | 222 | hcryp->Phase = HAL_CRYP_PHASE_READY; |
mbed_official | 87:085cde657901 | 223 | |
mbed_official | 87:085cde657901 | 224 | /* Reset CrypInCount and CrypOutCount */ |
mbed_official | 87:085cde657901 | 225 | hcryp->CrypInCount = 0; |
mbed_official | 87:085cde657901 | 226 | hcryp->CrypOutCount = 0; |
mbed_official | 87:085cde657901 | 227 | |
mbed_official | 87:085cde657901 | 228 | /* Disable the CRYP Peripheral Clock */ |
mbed_official | 87:085cde657901 | 229 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 230 | |
mbed_official | 87:085cde657901 | 231 | /* DeInit the low level hardware: CLOCK, NVIC.*/ |
mbed_official | 87:085cde657901 | 232 | HAL_CRYP_MspDeInit(hcryp); |
mbed_official | 87:085cde657901 | 233 | |
mbed_official | 87:085cde657901 | 234 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 235 | hcryp->State = HAL_CRYP_STATE_RESET; |
mbed_official | 87:085cde657901 | 236 | |
mbed_official | 87:085cde657901 | 237 | /* Return function status */ |
mbed_official | 87:085cde657901 | 238 | return HAL_OK; |
mbed_official | 87:085cde657901 | 239 | } |
mbed_official | 87:085cde657901 | 240 | |
mbed_official | 87:085cde657901 | 241 | /** |
mbed_official | 87:085cde657901 | 242 | * @brief Initializes the CRYP MSP. |
mbed_official | 87:085cde657901 | 243 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 244 | * @retval None |
mbed_official | 87:085cde657901 | 245 | */ |
mbed_official | 87:085cde657901 | 246 | __weak void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 247 | { |
mbed_official | 87:085cde657901 | 248 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 249 | the HAL_CRYP_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 250 | */ |
mbed_official | 87:085cde657901 | 251 | } |
mbed_official | 87:085cde657901 | 252 | |
mbed_official | 87:085cde657901 | 253 | /** |
mbed_official | 87:085cde657901 | 254 | * @brief DeInitializes CRYP MSP. |
mbed_official | 87:085cde657901 | 255 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 256 | * @retval None |
mbed_official | 87:085cde657901 | 257 | */ |
mbed_official | 87:085cde657901 | 258 | __weak void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 259 | { |
mbed_official | 87:085cde657901 | 260 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 261 | the HAL_CRYP_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 262 | */ |
mbed_official | 87:085cde657901 | 263 | } |
mbed_official | 87:085cde657901 | 264 | |
mbed_official | 87:085cde657901 | 265 | /** |
mbed_official | 87:085cde657901 | 266 | * @} |
mbed_official | 87:085cde657901 | 267 | */ |
mbed_official | 87:085cde657901 | 268 | |
mbed_official | 87:085cde657901 | 269 | /** @defgroup CRYP_Group2 AES processing functions |
mbed_official | 87:085cde657901 | 270 | * @brief processing functions. |
mbed_official | 87:085cde657901 | 271 | * |
mbed_official | 87:085cde657901 | 272 | @verbatim |
mbed_official | 87:085cde657901 | 273 | ============================================================================== |
mbed_official | 87:085cde657901 | 274 | ##### AES processing functions ##### |
mbed_official | 87:085cde657901 | 275 | ============================================================================== |
mbed_official | 87:085cde657901 | 276 | [..] This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 277 | (+) Encrypt plaintext using AES-128/192/256 using chaining modes |
mbed_official | 87:085cde657901 | 278 | (+) Decrypt cyphertext using AES-128/192/256 using chaining modes |
mbed_official | 87:085cde657901 | 279 | [..] Three processing functions are available: |
mbed_official | 87:085cde657901 | 280 | (+) Polling mode |
mbed_official | 87:085cde657901 | 281 | (+) Interrupt mode |
mbed_official | 87:085cde657901 | 282 | (+) DMA mode |
mbed_official | 87:085cde657901 | 283 | |
mbed_official | 87:085cde657901 | 284 | @endverbatim |
mbed_official | 87:085cde657901 | 285 | * @{ |
mbed_official | 87:085cde657901 | 286 | */ |
mbed_official | 87:085cde657901 | 287 | |
mbed_official | 87:085cde657901 | 288 | /** |
mbed_official | 87:085cde657901 | 289 | * @brief Initializes the CRYP peripheral in AES ECB encryption mode |
mbed_official | 87:085cde657901 | 290 | * then encrypt pPlainData. The cypher data are available in pCypherData |
mbed_official | 87:085cde657901 | 291 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 292 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 293 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 294 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 295 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 296 | * @retval HAL status |
mbed_official | 87:085cde657901 | 297 | */ |
mbed_official | 87:085cde657901 | 298 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 299 | { |
mbed_official | 87:085cde657901 | 300 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 301 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 302 | |
mbed_official | 87:085cde657901 | 303 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 304 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 305 | |
mbed_official | 87:085cde657901 | 306 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 307 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 308 | { |
mbed_official | 87:085cde657901 | 309 | /* Set the key */ |
mbed_official | 87:085cde657901 | 310 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 311 | |
mbed_official | 87:085cde657901 | 312 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 313 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB); |
mbed_official | 87:085cde657901 | 314 | |
mbed_official | 87:085cde657901 | 315 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 316 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 317 | |
mbed_official | 87:085cde657901 | 318 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 319 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 320 | |
mbed_official | 87:085cde657901 | 321 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 322 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 323 | } |
mbed_official | 87:085cde657901 | 324 | |
mbed_official | 87:085cde657901 | 325 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 326 | if(CRYP_ProcessData(hcryp,pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 327 | { |
mbed_official | 87:085cde657901 | 328 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 329 | } |
mbed_official | 87:085cde657901 | 330 | |
mbed_official | 87:085cde657901 | 331 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 332 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 333 | |
mbed_official | 87:085cde657901 | 334 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 335 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 336 | |
mbed_official | 87:085cde657901 | 337 | /* Return function status */ |
mbed_official | 87:085cde657901 | 338 | return HAL_OK; |
mbed_official | 87:085cde657901 | 339 | } |
mbed_official | 87:085cde657901 | 340 | |
mbed_official | 87:085cde657901 | 341 | /** |
mbed_official | 87:085cde657901 | 342 | * @brief Initializes the CRYP peripheral in AES CBC encryption mode |
mbed_official | 87:085cde657901 | 343 | * then encrypt pPlainData. The cypher data are available in pCypherData |
mbed_official | 87:085cde657901 | 344 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 345 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 346 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 347 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 348 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 349 | * @retval HAL status |
mbed_official | 87:085cde657901 | 350 | */ |
mbed_official | 87:085cde657901 | 351 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 352 | { |
mbed_official | 87:085cde657901 | 353 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 354 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 355 | |
mbed_official | 87:085cde657901 | 356 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 357 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 358 | |
mbed_official | 87:085cde657901 | 359 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 360 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 361 | { |
mbed_official | 87:085cde657901 | 362 | /* Set the key */ |
mbed_official | 87:085cde657901 | 363 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 364 | |
mbed_official | 87:085cde657901 | 365 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 366 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC); |
mbed_official | 87:085cde657901 | 367 | |
mbed_official | 87:085cde657901 | 368 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 369 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 370 | |
mbed_official | 87:085cde657901 | 371 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 372 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 373 | |
mbed_official | 87:085cde657901 | 374 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 375 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 376 | |
mbed_official | 87:085cde657901 | 377 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 378 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 379 | } |
mbed_official | 87:085cde657901 | 380 | |
mbed_official | 87:085cde657901 | 381 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 382 | if(CRYP_ProcessData(hcryp,pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 383 | { |
mbed_official | 87:085cde657901 | 384 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 385 | } |
mbed_official | 87:085cde657901 | 386 | |
mbed_official | 87:085cde657901 | 387 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 388 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 389 | |
mbed_official | 87:085cde657901 | 390 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 391 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 392 | |
mbed_official | 87:085cde657901 | 393 | /* Return function status */ |
mbed_official | 87:085cde657901 | 394 | return HAL_OK; |
mbed_official | 87:085cde657901 | 395 | } |
mbed_official | 87:085cde657901 | 396 | |
mbed_official | 87:085cde657901 | 397 | /** |
mbed_official | 87:085cde657901 | 398 | * @brief Initializes the CRYP peripheral in AES CTR encryption mode |
mbed_official | 87:085cde657901 | 399 | * then encrypt pPlainData. The cypher data are available in pCypherData |
mbed_official | 87:085cde657901 | 400 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 401 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 402 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 403 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 404 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 405 | * @retval HAL status |
mbed_official | 87:085cde657901 | 406 | */ |
mbed_official | 87:085cde657901 | 407 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 408 | { |
mbed_official | 87:085cde657901 | 409 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 410 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 411 | |
mbed_official | 87:085cde657901 | 412 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 413 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 414 | |
mbed_official | 87:085cde657901 | 415 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 416 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 417 | { |
mbed_official | 87:085cde657901 | 418 | /* Set the key */ |
mbed_official | 87:085cde657901 | 419 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 420 | |
mbed_official | 87:085cde657901 | 421 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 422 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR); |
mbed_official | 87:085cde657901 | 423 | |
mbed_official | 87:085cde657901 | 424 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 425 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 426 | |
mbed_official | 87:085cde657901 | 427 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 428 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 429 | |
mbed_official | 87:085cde657901 | 430 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 431 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 432 | |
mbed_official | 87:085cde657901 | 433 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 434 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 435 | } |
mbed_official | 87:085cde657901 | 436 | |
mbed_official | 87:085cde657901 | 437 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 438 | if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 439 | { |
mbed_official | 87:085cde657901 | 440 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 441 | } |
mbed_official | 87:085cde657901 | 442 | |
mbed_official | 87:085cde657901 | 443 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 444 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 445 | |
mbed_official | 87:085cde657901 | 446 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 447 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 448 | |
mbed_official | 87:085cde657901 | 449 | /* Return function status */ |
mbed_official | 87:085cde657901 | 450 | return HAL_OK; |
mbed_official | 87:085cde657901 | 451 | } |
mbed_official | 87:085cde657901 | 452 | |
mbed_official | 87:085cde657901 | 453 | |
mbed_official | 87:085cde657901 | 454 | |
mbed_official | 87:085cde657901 | 455 | /** |
mbed_official | 87:085cde657901 | 456 | * @brief Initializes the CRYP peripheral in AES ECB decryption mode |
mbed_official | 87:085cde657901 | 457 | * then decrypted pCypherData. The cypher data are available in pPlainData |
mbed_official | 87:085cde657901 | 458 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 459 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 460 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 461 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 462 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 463 | * @retval HAL status |
mbed_official | 87:085cde657901 | 464 | */ |
mbed_official | 87:085cde657901 | 465 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 466 | { |
mbed_official | 87:085cde657901 | 467 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 468 | |
mbed_official | 87:085cde657901 | 469 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 470 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 471 | |
mbed_official | 87:085cde657901 | 472 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 473 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 474 | |
mbed_official | 87:085cde657901 | 475 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 476 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 477 | { |
mbed_official | 87:085cde657901 | 478 | /* Set the key */ |
mbed_official | 87:085cde657901 | 479 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 480 | |
mbed_official | 87:085cde657901 | 481 | /* Set the CRYP peripheral in AES Key mode */ |
mbed_official | 87:085cde657901 | 482 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 483 | |
mbed_official | 87:085cde657901 | 484 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 485 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 486 | |
mbed_official | 87:085cde657901 | 487 | /* Get timeout */ |
mbed_official | 87:085cde657901 | 488 | timeout = HAL_GetTick() + Timeout; |
mbed_official | 87:085cde657901 | 489 | |
mbed_official | 87:085cde657901 | 490 | while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY)) |
mbed_official | 87:085cde657901 | 491 | { |
mbed_official | 87:085cde657901 | 492 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 493 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 87:085cde657901 | 494 | { |
mbed_official | 87:085cde657901 | 495 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 496 | { |
mbed_official | 87:085cde657901 | 497 | /* Change state */ |
mbed_official | 87:085cde657901 | 498 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 499 | |
mbed_official | 87:085cde657901 | 500 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 501 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 502 | |
mbed_official | 87:085cde657901 | 503 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 504 | } |
mbed_official | 87:085cde657901 | 505 | } |
mbed_official | 87:085cde657901 | 506 | } |
mbed_official | 87:085cde657901 | 507 | |
mbed_official | 87:085cde657901 | 508 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 509 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 510 | |
mbed_official | 87:085cde657901 | 511 | /* Reset the ALGOMODE bits*/ |
mbed_official | 87:085cde657901 | 512 | CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE); |
mbed_official | 87:085cde657901 | 513 | |
mbed_official | 87:085cde657901 | 514 | /* Set the CRYP peripheral in AES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 515 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 516 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 517 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 518 | |
mbed_official | 87:085cde657901 | 519 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 520 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 521 | |
mbed_official | 87:085cde657901 | 522 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 523 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 524 | } |
mbed_official | 87:085cde657901 | 525 | |
mbed_official | 87:085cde657901 | 526 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 527 | if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 528 | { |
mbed_official | 87:085cde657901 | 529 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 530 | } |
mbed_official | 87:085cde657901 | 531 | |
mbed_official | 87:085cde657901 | 532 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 533 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 534 | |
mbed_official | 87:085cde657901 | 535 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 536 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 537 | |
mbed_official | 87:085cde657901 | 538 | /* Return function status */ |
mbed_official | 87:085cde657901 | 539 | return HAL_OK; |
mbed_official | 87:085cde657901 | 540 | } |
mbed_official | 87:085cde657901 | 541 | |
mbed_official | 87:085cde657901 | 542 | /** |
mbed_official | 87:085cde657901 | 543 | * @brief Initializes the CRYP peripheral in AES ECB decryption mode |
mbed_official | 87:085cde657901 | 544 | * then decrypted pCypherData. The cypher data are available in pPlainData |
mbed_official | 87:085cde657901 | 545 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 546 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 547 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 548 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 549 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 550 | * @retval HAL status |
mbed_official | 87:085cde657901 | 551 | */ |
mbed_official | 87:085cde657901 | 552 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 553 | { |
mbed_official | 87:085cde657901 | 554 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 555 | |
mbed_official | 87:085cde657901 | 556 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 557 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 558 | |
mbed_official | 87:085cde657901 | 559 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 560 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 561 | |
mbed_official | 87:085cde657901 | 562 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 563 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 564 | { |
mbed_official | 87:085cde657901 | 565 | /* Set the key */ |
mbed_official | 87:085cde657901 | 566 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 567 | |
mbed_official | 87:085cde657901 | 568 | /* Set the CRYP peripheral in AES Key mode */ |
mbed_official | 87:085cde657901 | 569 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 570 | |
mbed_official | 87:085cde657901 | 571 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 572 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 573 | |
mbed_official | 87:085cde657901 | 574 | /* Get Timeout */ |
mbed_official | 87:085cde657901 | 575 | timeout = HAL_GetTick() + Timeout; |
mbed_official | 87:085cde657901 | 576 | |
mbed_official | 87:085cde657901 | 577 | while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY)) |
mbed_official | 87:085cde657901 | 578 | { |
mbed_official | 87:085cde657901 | 579 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 580 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 87:085cde657901 | 581 | { |
mbed_official | 87:085cde657901 | 582 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 583 | { |
mbed_official | 87:085cde657901 | 584 | /* Change state */ |
mbed_official | 87:085cde657901 | 585 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 586 | |
mbed_official | 87:085cde657901 | 587 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 588 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 589 | |
mbed_official | 87:085cde657901 | 590 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 591 | } |
mbed_official | 87:085cde657901 | 592 | } |
mbed_official | 87:085cde657901 | 593 | } |
mbed_official | 87:085cde657901 | 594 | |
mbed_official | 87:085cde657901 | 595 | /* Reset the ALGOMODE bits*/ |
mbed_official | 87:085cde657901 | 596 | CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE); |
mbed_official | 87:085cde657901 | 597 | |
mbed_official | 87:085cde657901 | 598 | /* Set the CRYP peripheral in AES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 599 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 600 | |
mbed_official | 87:085cde657901 | 601 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 602 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 603 | |
mbed_official | 87:085cde657901 | 604 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 605 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 606 | |
mbed_official | 87:085cde657901 | 607 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 608 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 609 | |
mbed_official | 87:085cde657901 | 610 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 611 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 612 | } |
mbed_official | 87:085cde657901 | 613 | |
mbed_official | 87:085cde657901 | 614 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 615 | if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 616 | { |
mbed_official | 87:085cde657901 | 617 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 618 | } |
mbed_official | 87:085cde657901 | 619 | |
mbed_official | 87:085cde657901 | 620 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 621 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 622 | |
mbed_official | 87:085cde657901 | 623 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 624 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 625 | |
mbed_official | 87:085cde657901 | 626 | /* Return function status */ |
mbed_official | 87:085cde657901 | 627 | return HAL_OK; |
mbed_official | 87:085cde657901 | 628 | } |
mbed_official | 87:085cde657901 | 629 | |
mbed_official | 87:085cde657901 | 630 | /** |
mbed_official | 87:085cde657901 | 631 | * @brief Initializes the CRYP peripheral in AES CTR decryption mode |
mbed_official | 87:085cde657901 | 632 | * then decrypted pCypherData. The cypher data are available in pPlainData |
mbed_official | 87:085cde657901 | 633 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 634 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 635 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 636 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 637 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 638 | * @retval HAL status |
mbed_official | 87:085cde657901 | 639 | */ |
mbed_official | 87:085cde657901 | 640 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 641 | { |
mbed_official | 87:085cde657901 | 642 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 643 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 644 | |
mbed_official | 87:085cde657901 | 645 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 646 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 647 | { |
mbed_official | 87:085cde657901 | 648 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 649 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 650 | |
mbed_official | 87:085cde657901 | 651 | /* Set the key */ |
mbed_official | 87:085cde657901 | 652 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 653 | |
mbed_official | 87:085cde657901 | 654 | /* Set the CRYP peripheral in AES CTR mode */ |
mbed_official | 87:085cde657901 | 655 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 656 | |
mbed_official | 87:085cde657901 | 657 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 658 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 659 | |
mbed_official | 87:085cde657901 | 660 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 661 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 662 | |
mbed_official | 87:085cde657901 | 663 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 664 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 665 | |
mbed_official | 87:085cde657901 | 666 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 667 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 668 | } |
mbed_official | 87:085cde657901 | 669 | |
mbed_official | 87:085cde657901 | 670 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 671 | if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 672 | { |
mbed_official | 87:085cde657901 | 673 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 674 | } |
mbed_official | 87:085cde657901 | 675 | |
mbed_official | 87:085cde657901 | 676 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 677 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 678 | |
mbed_official | 87:085cde657901 | 679 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 680 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 681 | |
mbed_official | 87:085cde657901 | 682 | /* Return function status */ |
mbed_official | 87:085cde657901 | 683 | return HAL_OK; |
mbed_official | 87:085cde657901 | 684 | } |
mbed_official | 87:085cde657901 | 685 | |
mbed_official | 87:085cde657901 | 686 | /** |
mbed_official | 87:085cde657901 | 687 | * @brief Initializes the CRYP peripheral in AES ECB encryption mode using Interrupt. |
mbed_official | 87:085cde657901 | 688 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 689 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 690 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
mbed_official | 87:085cde657901 | 691 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 692 | * @retval HAL status |
mbed_official | 87:085cde657901 | 693 | */ |
mbed_official | 87:085cde657901 | 694 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 695 | { |
mbed_official | 87:085cde657901 | 696 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 697 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 698 | |
mbed_official | 87:085cde657901 | 699 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 700 | { |
mbed_official | 87:085cde657901 | 701 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 702 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 703 | |
mbed_official | 87:085cde657901 | 704 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 705 | hcryp->pCrypInBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 706 | hcryp->pCrypOutBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 707 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 708 | |
mbed_official | 87:085cde657901 | 709 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 710 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 711 | |
mbed_official | 87:085cde657901 | 712 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 713 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 714 | { |
mbed_official | 87:085cde657901 | 715 | /* Set the key */ |
mbed_official | 87:085cde657901 | 716 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 717 | |
mbed_official | 87:085cde657901 | 718 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 719 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB); |
mbed_official | 87:085cde657901 | 720 | |
mbed_official | 87:085cde657901 | 721 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 722 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 723 | |
mbed_official | 87:085cde657901 | 724 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 725 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 726 | } |
mbed_official | 87:085cde657901 | 727 | |
mbed_official | 87:085cde657901 | 728 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 729 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 730 | |
mbed_official | 87:085cde657901 | 731 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 732 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 733 | |
mbed_official | 87:085cde657901 | 734 | /* Return function status */ |
mbed_official | 87:085cde657901 | 735 | return HAL_OK; |
mbed_official | 87:085cde657901 | 736 | } |
mbed_official | 87:085cde657901 | 737 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 738 | { |
mbed_official | 87:085cde657901 | 739 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 740 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 741 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 742 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 743 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 744 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 745 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 746 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 747 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 748 | hcryp->pCrypInBuffPtr += 16; |
mbed_official | 87:085cde657901 | 749 | hcryp->CrypInCount -= 16; |
mbed_official | 87:085cde657901 | 750 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 751 | { |
mbed_official | 87:085cde657901 | 752 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 753 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 754 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 755 | } |
mbed_official | 87:085cde657901 | 756 | } |
mbed_official | 87:085cde657901 | 757 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 758 | { |
mbed_official | 87:085cde657901 | 759 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 760 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 761 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 762 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 763 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 764 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 765 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 766 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 767 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 768 | hcryp->pCrypOutBuffPtr += 16; |
mbed_official | 87:085cde657901 | 769 | hcryp->CrypOutCount -= 16; |
mbed_official | 87:085cde657901 | 770 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 771 | { |
mbed_official | 87:085cde657901 | 772 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 773 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 774 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 775 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 776 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 777 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 778 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 779 | } |
mbed_official | 87:085cde657901 | 780 | } |
mbed_official | 87:085cde657901 | 781 | |
mbed_official | 87:085cde657901 | 782 | /* Return function status */ |
mbed_official | 87:085cde657901 | 783 | return HAL_OK; |
mbed_official | 87:085cde657901 | 784 | } |
mbed_official | 87:085cde657901 | 785 | |
mbed_official | 87:085cde657901 | 786 | /** |
mbed_official | 87:085cde657901 | 787 | * @brief Initializes the CRYP peripheral in AES CBC encryption mode using Interrupt. |
mbed_official | 87:085cde657901 | 788 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 789 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 790 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
mbed_official | 87:085cde657901 | 791 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 792 | * @retval HAL status |
mbed_official | 87:085cde657901 | 793 | */ |
mbed_official | 87:085cde657901 | 794 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 795 | { |
mbed_official | 87:085cde657901 | 796 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 797 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 798 | |
mbed_official | 87:085cde657901 | 799 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 800 | { |
mbed_official | 87:085cde657901 | 801 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 802 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 803 | |
mbed_official | 87:085cde657901 | 804 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 805 | hcryp->pCrypInBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 806 | hcryp->pCrypOutBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 807 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 808 | |
mbed_official | 87:085cde657901 | 809 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 810 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 811 | |
mbed_official | 87:085cde657901 | 812 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 813 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 814 | { |
mbed_official | 87:085cde657901 | 815 | /* Set the key */ |
mbed_official | 87:085cde657901 | 816 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 817 | |
mbed_official | 87:085cde657901 | 818 | /* Set the CRYP peripheral in AES CBC mode */ |
mbed_official | 87:085cde657901 | 819 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC); |
mbed_official | 87:085cde657901 | 820 | |
mbed_official | 87:085cde657901 | 821 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 822 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 823 | |
mbed_official | 87:085cde657901 | 824 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 825 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 826 | |
mbed_official | 87:085cde657901 | 827 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 828 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 829 | } |
mbed_official | 87:085cde657901 | 830 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 831 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 832 | |
mbed_official | 87:085cde657901 | 833 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 834 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 835 | |
mbed_official | 87:085cde657901 | 836 | /* Return function status */ |
mbed_official | 87:085cde657901 | 837 | return HAL_OK; |
mbed_official | 87:085cde657901 | 838 | } |
mbed_official | 87:085cde657901 | 839 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 840 | { |
mbed_official | 87:085cde657901 | 841 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 842 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 843 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 844 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 845 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 846 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 847 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 848 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 849 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 850 | hcryp->pCrypInBuffPtr += 16; |
mbed_official | 87:085cde657901 | 851 | hcryp->CrypInCount -= 16; |
mbed_official | 87:085cde657901 | 852 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 853 | { |
mbed_official | 87:085cde657901 | 854 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 855 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 856 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 857 | } |
mbed_official | 87:085cde657901 | 858 | } |
mbed_official | 87:085cde657901 | 859 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 860 | { |
mbed_official | 87:085cde657901 | 861 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 862 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 863 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 864 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 865 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 866 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 867 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 868 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 869 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 870 | hcryp->pCrypOutBuffPtr += 16; |
mbed_official | 87:085cde657901 | 871 | hcryp->CrypOutCount -= 16; |
mbed_official | 87:085cde657901 | 872 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 873 | { |
mbed_official | 87:085cde657901 | 874 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 875 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 876 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 877 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 878 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 879 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 880 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 881 | } |
mbed_official | 87:085cde657901 | 882 | } |
mbed_official | 87:085cde657901 | 883 | |
mbed_official | 87:085cde657901 | 884 | /* Return function status */ |
mbed_official | 87:085cde657901 | 885 | return HAL_OK; |
mbed_official | 87:085cde657901 | 886 | } |
mbed_official | 87:085cde657901 | 887 | |
mbed_official | 87:085cde657901 | 888 | /** |
mbed_official | 87:085cde657901 | 889 | * @brief Initializes the CRYP peripheral in AES CTR encryption mode using Interrupt. |
mbed_official | 87:085cde657901 | 890 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 891 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 892 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
mbed_official | 87:085cde657901 | 893 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 894 | * @retval HAL status |
mbed_official | 87:085cde657901 | 895 | */ |
mbed_official | 87:085cde657901 | 896 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 897 | { |
mbed_official | 87:085cde657901 | 898 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 899 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 900 | |
mbed_official | 87:085cde657901 | 901 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 902 | { |
mbed_official | 87:085cde657901 | 903 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 904 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 905 | |
mbed_official | 87:085cde657901 | 906 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 907 | hcryp->pCrypInBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 908 | hcryp->pCrypOutBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 909 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 910 | |
mbed_official | 87:085cde657901 | 911 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 912 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 913 | |
mbed_official | 87:085cde657901 | 914 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 915 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 916 | { |
mbed_official | 87:085cde657901 | 917 | /* Set the key */ |
mbed_official | 87:085cde657901 | 918 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 919 | |
mbed_official | 87:085cde657901 | 920 | /* Set the CRYP peripheral in AES CTR mode */ |
mbed_official | 87:085cde657901 | 921 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR); |
mbed_official | 87:085cde657901 | 922 | |
mbed_official | 87:085cde657901 | 923 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 924 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 925 | |
mbed_official | 87:085cde657901 | 926 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 927 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 928 | |
mbed_official | 87:085cde657901 | 929 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 930 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 931 | } |
mbed_official | 87:085cde657901 | 932 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 933 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 934 | |
mbed_official | 87:085cde657901 | 935 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 936 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 937 | |
mbed_official | 87:085cde657901 | 938 | /* Return function status */ |
mbed_official | 87:085cde657901 | 939 | return HAL_OK; |
mbed_official | 87:085cde657901 | 940 | } |
mbed_official | 87:085cde657901 | 941 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 942 | { |
mbed_official | 87:085cde657901 | 943 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 944 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 945 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 946 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 947 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 948 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 949 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 950 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 951 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 952 | hcryp->pCrypInBuffPtr += 16; |
mbed_official | 87:085cde657901 | 953 | hcryp->CrypInCount -= 16; |
mbed_official | 87:085cde657901 | 954 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 955 | { |
mbed_official | 87:085cde657901 | 956 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 957 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 958 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 959 | } |
mbed_official | 87:085cde657901 | 960 | } |
mbed_official | 87:085cde657901 | 961 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 962 | { |
mbed_official | 87:085cde657901 | 963 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 964 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 965 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 966 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 967 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 968 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 969 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 970 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 971 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 972 | hcryp->pCrypOutBuffPtr += 16; |
mbed_official | 87:085cde657901 | 973 | hcryp->CrypOutCount -= 16; |
mbed_official | 87:085cde657901 | 974 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 975 | { |
mbed_official | 87:085cde657901 | 976 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 977 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 978 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 979 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 980 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 981 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 982 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 983 | } |
mbed_official | 87:085cde657901 | 984 | } |
mbed_official | 87:085cde657901 | 985 | |
mbed_official | 87:085cde657901 | 986 | /* Return function status */ |
mbed_official | 87:085cde657901 | 987 | return HAL_OK; |
mbed_official | 87:085cde657901 | 988 | } |
mbed_official | 87:085cde657901 | 989 | |
mbed_official | 87:085cde657901 | 990 | |
mbed_official | 87:085cde657901 | 991 | /** |
mbed_official | 87:085cde657901 | 992 | * @brief Initializes the CRYP peripheral in AES ECB decryption mode using Interrupt. |
mbed_official | 87:085cde657901 | 993 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 994 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 995 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 996 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 997 | * @retval HAL status |
mbed_official | 87:085cde657901 | 998 | */ |
mbed_official | 87:085cde657901 | 999 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 1000 | { |
mbed_official | 87:085cde657901 | 1001 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 1002 | |
mbed_official | 87:085cde657901 | 1003 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1004 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1005 | |
mbed_official | 87:085cde657901 | 1006 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 1007 | { |
mbed_official | 87:085cde657901 | 1008 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1009 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1010 | |
mbed_official | 87:085cde657901 | 1011 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 1012 | hcryp->pCrypInBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 1013 | hcryp->pCrypOutBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 1014 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 1015 | |
mbed_official | 87:085cde657901 | 1016 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1017 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1018 | |
mbed_official | 87:085cde657901 | 1019 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1020 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1021 | { |
mbed_official | 87:085cde657901 | 1022 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1023 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1024 | |
mbed_official | 87:085cde657901 | 1025 | /* Set the CRYP peripheral in AES Key mode */ |
mbed_official | 87:085cde657901 | 1026 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1027 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1028 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1029 | |
mbed_official | 87:085cde657901 | 1030 | /* Get timeout */ |
mbed_official | 87:085cde657901 | 1031 | timeout = HAL_GetTick() + 1; |
mbed_official | 87:085cde657901 | 1032 | |
mbed_official | 87:085cde657901 | 1033 | while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY)) |
mbed_official | 87:085cde657901 | 1034 | { |
mbed_official | 87:085cde657901 | 1035 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 1036 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1037 | { |
mbed_official | 87:085cde657901 | 1038 | /* Change state */ |
mbed_official | 87:085cde657901 | 1039 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1040 | |
mbed_official | 87:085cde657901 | 1041 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1042 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1043 | |
mbed_official | 87:085cde657901 | 1044 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1045 | } |
mbed_official | 87:085cde657901 | 1046 | } |
mbed_official | 87:085cde657901 | 1047 | |
mbed_official | 87:085cde657901 | 1048 | /* Reset the ALGOMODE bits*/ |
mbed_official | 87:085cde657901 | 1049 | CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE); |
mbed_official | 87:085cde657901 | 1050 | |
mbed_official | 87:085cde657901 | 1051 | /* Set the CRYP peripheral in AES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 1052 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1053 | |
mbed_official | 87:085cde657901 | 1054 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1055 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1056 | |
mbed_official | 87:085cde657901 | 1057 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1058 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1059 | } |
mbed_official | 87:085cde657901 | 1060 | |
mbed_official | 87:085cde657901 | 1061 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 1062 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 1063 | |
mbed_official | 87:085cde657901 | 1064 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1065 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1066 | |
mbed_official | 87:085cde657901 | 1067 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1068 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1069 | } |
mbed_official | 87:085cde657901 | 1070 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 1071 | { |
mbed_official | 87:085cde657901 | 1072 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 1073 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 1074 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1075 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1076 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1077 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1078 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1079 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1080 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1081 | hcryp->pCrypInBuffPtr += 16; |
mbed_official | 87:085cde657901 | 1082 | hcryp->CrypInCount -= 16; |
mbed_official | 87:085cde657901 | 1083 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 1084 | { |
mbed_official | 87:085cde657901 | 1085 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 1086 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 1087 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 1088 | } |
mbed_official | 87:085cde657901 | 1089 | } |
mbed_official | 87:085cde657901 | 1090 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 1091 | { |
mbed_official | 87:085cde657901 | 1092 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 1093 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 1094 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1095 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1096 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1097 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1098 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1099 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1100 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1101 | hcryp->pCrypOutBuffPtr += 16; |
mbed_official | 87:085cde657901 | 1102 | hcryp->CrypOutCount -= 16; |
mbed_official | 87:085cde657901 | 1103 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 1104 | { |
mbed_official | 87:085cde657901 | 1105 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 1106 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1107 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1108 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1109 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 1110 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 1111 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 1112 | } |
mbed_official | 87:085cde657901 | 1113 | } |
mbed_official | 87:085cde657901 | 1114 | |
mbed_official | 87:085cde657901 | 1115 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1116 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1117 | } |
mbed_official | 87:085cde657901 | 1118 | |
mbed_official | 87:085cde657901 | 1119 | /** |
mbed_official | 87:085cde657901 | 1120 | * @brief Initializes the CRYP peripheral in AES CBC decryption mode using IT. |
mbed_official | 87:085cde657901 | 1121 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1122 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1123 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 |
mbed_official | 87:085cde657901 | 1124 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1125 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1126 | */ |
mbed_official | 87:085cde657901 | 1127 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 1128 | { |
mbed_official | 87:085cde657901 | 1129 | |
mbed_official | 87:085cde657901 | 1130 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 1131 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1132 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1133 | |
mbed_official | 87:085cde657901 | 1134 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 1135 | { |
mbed_official | 87:085cde657901 | 1136 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1137 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1138 | |
mbed_official | 87:085cde657901 | 1139 | /* Get the buffer addresses and sizes */ |
mbed_official | 87:085cde657901 | 1140 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 1141 | hcryp->pCrypInBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 1142 | hcryp->pCrypOutBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 1143 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 1144 | |
mbed_official | 87:085cde657901 | 1145 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1146 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1147 | |
mbed_official | 87:085cde657901 | 1148 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1149 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1150 | { |
mbed_official | 87:085cde657901 | 1151 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1152 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1153 | |
mbed_official | 87:085cde657901 | 1154 | /* Set the CRYP peripheral in AES Key mode */ |
mbed_official | 87:085cde657901 | 1155 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1156 | |
mbed_official | 87:085cde657901 | 1157 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1158 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1159 | |
mbed_official | 87:085cde657901 | 1160 | /* Get timeout */ |
mbed_official | 87:085cde657901 | 1161 | timeout = HAL_GetTick() + 1; |
mbed_official | 87:085cde657901 | 1162 | |
mbed_official | 87:085cde657901 | 1163 | while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY)) |
mbed_official | 87:085cde657901 | 1164 | { |
mbed_official | 87:085cde657901 | 1165 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 1166 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1167 | { |
mbed_official | 87:085cde657901 | 1168 | /* Change state */ |
mbed_official | 87:085cde657901 | 1169 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1170 | |
mbed_official | 87:085cde657901 | 1171 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1172 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1173 | |
mbed_official | 87:085cde657901 | 1174 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1175 | } |
mbed_official | 87:085cde657901 | 1176 | } |
mbed_official | 87:085cde657901 | 1177 | |
mbed_official | 87:085cde657901 | 1178 | /* Reset the ALGOMODE bits*/ |
mbed_official | 87:085cde657901 | 1179 | CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE); |
mbed_official | 87:085cde657901 | 1180 | |
mbed_official | 87:085cde657901 | 1181 | /* Set the CRYP peripheral in AES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 1182 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1183 | |
mbed_official | 87:085cde657901 | 1184 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 1185 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 1186 | |
mbed_official | 87:085cde657901 | 1187 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1188 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1189 | |
mbed_official | 87:085cde657901 | 1190 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1191 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1192 | |
mbed_official | 87:085cde657901 | 1193 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1194 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1195 | } |
mbed_official | 87:085cde657901 | 1196 | |
mbed_official | 87:085cde657901 | 1197 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 1198 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 1199 | |
mbed_official | 87:085cde657901 | 1200 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1201 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1202 | |
mbed_official | 87:085cde657901 | 1203 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1204 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1205 | } |
mbed_official | 87:085cde657901 | 1206 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 1207 | { |
mbed_official | 87:085cde657901 | 1208 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 1209 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 1210 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1211 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1212 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1213 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1214 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1215 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1216 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1217 | hcryp->pCrypInBuffPtr += 16; |
mbed_official | 87:085cde657901 | 1218 | hcryp->CrypInCount -= 16; |
mbed_official | 87:085cde657901 | 1219 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 1220 | { |
mbed_official | 87:085cde657901 | 1221 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 1222 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 1223 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 1224 | } |
mbed_official | 87:085cde657901 | 1225 | } |
mbed_official | 87:085cde657901 | 1226 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 1227 | { |
mbed_official | 87:085cde657901 | 1228 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 1229 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 1230 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1231 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1232 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1233 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1234 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1235 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1236 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1237 | hcryp->pCrypOutBuffPtr += 16; |
mbed_official | 87:085cde657901 | 1238 | hcryp->CrypOutCount -= 16; |
mbed_official | 87:085cde657901 | 1239 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 1240 | { |
mbed_official | 87:085cde657901 | 1241 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 1242 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1243 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1244 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1245 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 1246 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 1247 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 1248 | } |
mbed_official | 87:085cde657901 | 1249 | } |
mbed_official | 87:085cde657901 | 1250 | |
mbed_official | 87:085cde657901 | 1251 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1252 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1253 | } |
mbed_official | 87:085cde657901 | 1254 | |
mbed_official | 87:085cde657901 | 1255 | /** |
mbed_official | 87:085cde657901 | 1256 | * @brief Initializes the CRYP peripheral in AES CTR decryption mode using Interrupt. |
mbed_official | 87:085cde657901 | 1257 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1258 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1259 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 |
mbed_official | 87:085cde657901 | 1260 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1261 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1262 | */ |
mbed_official | 87:085cde657901 | 1263 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 1264 | { |
mbed_official | 87:085cde657901 | 1265 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1266 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1267 | |
mbed_official | 87:085cde657901 | 1268 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 1269 | { |
mbed_official | 87:085cde657901 | 1270 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1271 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1272 | |
mbed_official | 87:085cde657901 | 1273 | /* Get the buffer addresses and sizes */ |
mbed_official | 87:085cde657901 | 1274 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 1275 | hcryp->pCrypInBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 1276 | hcryp->pCrypOutBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 1277 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 1278 | |
mbed_official | 87:085cde657901 | 1279 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1280 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1281 | |
mbed_official | 87:085cde657901 | 1282 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1283 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1284 | { |
mbed_official | 87:085cde657901 | 1285 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1286 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1287 | |
mbed_official | 87:085cde657901 | 1288 | /* Set the CRYP peripheral in AES CTR mode */ |
mbed_official | 87:085cde657901 | 1289 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1290 | |
mbed_official | 87:085cde657901 | 1291 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 1292 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 1293 | |
mbed_official | 87:085cde657901 | 1294 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1295 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1296 | |
mbed_official | 87:085cde657901 | 1297 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1298 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1299 | } |
mbed_official | 87:085cde657901 | 1300 | |
mbed_official | 87:085cde657901 | 1301 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 1302 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 1303 | |
mbed_official | 87:085cde657901 | 1304 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1305 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1306 | |
mbed_official | 87:085cde657901 | 1307 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1308 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1309 | } |
mbed_official | 87:085cde657901 | 1310 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 1311 | { |
mbed_official | 87:085cde657901 | 1312 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 1313 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 1314 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1315 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1316 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1317 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1318 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1319 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1320 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1321 | hcryp->pCrypInBuffPtr += 16; |
mbed_official | 87:085cde657901 | 1322 | hcryp->CrypInCount -= 16; |
mbed_official | 87:085cde657901 | 1323 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 1324 | { |
mbed_official | 87:085cde657901 | 1325 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 1326 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 1327 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 1328 | } |
mbed_official | 87:085cde657901 | 1329 | } |
mbed_official | 87:085cde657901 | 1330 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 1331 | { |
mbed_official | 87:085cde657901 | 1332 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 1333 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 1334 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1335 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1336 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1337 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1338 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1339 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1340 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1341 | hcryp->pCrypOutBuffPtr += 16; |
mbed_official | 87:085cde657901 | 1342 | hcryp->CrypOutCount -= 16; |
mbed_official | 87:085cde657901 | 1343 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 1344 | { |
mbed_official | 87:085cde657901 | 1345 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 1346 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1347 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1348 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1349 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 1350 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 1351 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 1352 | } |
mbed_official | 87:085cde657901 | 1353 | } |
mbed_official | 87:085cde657901 | 1354 | |
mbed_official | 87:085cde657901 | 1355 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1356 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1357 | } |
mbed_official | 87:085cde657901 | 1358 | |
mbed_official | 87:085cde657901 | 1359 | /** |
mbed_official | 87:085cde657901 | 1360 | * @brief Initializes the CRYP peripheral in AES ECB encryption mode using DMA. |
mbed_official | 87:085cde657901 | 1361 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1362 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1363 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
mbed_official | 87:085cde657901 | 1364 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1365 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1366 | */ |
mbed_official | 87:085cde657901 | 1367 | HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 1368 | { |
mbed_official | 87:085cde657901 | 1369 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1370 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1371 | |
mbed_official | 87:085cde657901 | 1372 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 1373 | { |
mbed_official | 87:085cde657901 | 1374 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1375 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1376 | |
mbed_official | 87:085cde657901 | 1377 | inputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 1378 | outputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 1379 | |
mbed_official | 87:085cde657901 | 1380 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1381 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1382 | |
mbed_official | 87:085cde657901 | 1383 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1384 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1385 | { |
mbed_official | 87:085cde657901 | 1386 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1387 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1388 | |
mbed_official | 87:085cde657901 | 1389 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 1390 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB); |
mbed_official | 87:085cde657901 | 1391 | |
mbed_official | 87:085cde657901 | 1392 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1393 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1394 | |
mbed_official | 87:085cde657901 | 1395 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1396 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1397 | } |
mbed_official | 87:085cde657901 | 1398 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 1399 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 1400 | |
mbed_official | 87:085cde657901 | 1401 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1402 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1403 | |
mbed_official | 87:085cde657901 | 1404 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1405 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1406 | } |
mbed_official | 87:085cde657901 | 1407 | else |
mbed_official | 87:085cde657901 | 1408 | { |
mbed_official | 87:085cde657901 | 1409 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1410 | } |
mbed_official | 87:085cde657901 | 1411 | } |
mbed_official | 87:085cde657901 | 1412 | |
mbed_official | 87:085cde657901 | 1413 | /** |
mbed_official | 87:085cde657901 | 1414 | * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA. |
mbed_official | 87:085cde657901 | 1415 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1416 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1417 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 1418 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1419 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1420 | */ |
mbed_official | 87:085cde657901 | 1421 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 1422 | { |
mbed_official | 87:085cde657901 | 1423 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1424 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1425 | |
mbed_official | 87:085cde657901 | 1426 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 1427 | { |
mbed_official | 87:085cde657901 | 1428 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1429 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1430 | |
mbed_official | 87:085cde657901 | 1431 | inputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 1432 | outputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 1433 | |
mbed_official | 87:085cde657901 | 1434 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1435 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1436 | |
mbed_official | 87:085cde657901 | 1437 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1438 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1439 | { |
mbed_official | 87:085cde657901 | 1440 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1441 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1442 | |
mbed_official | 87:085cde657901 | 1443 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 1444 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC); |
mbed_official | 87:085cde657901 | 1445 | |
mbed_official | 87:085cde657901 | 1446 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 1447 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 1448 | |
mbed_official | 87:085cde657901 | 1449 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1450 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1451 | |
mbed_official | 87:085cde657901 | 1452 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1453 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1454 | } |
mbed_official | 87:085cde657901 | 1455 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 1456 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 1457 | |
mbed_official | 87:085cde657901 | 1458 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1459 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1460 | |
mbed_official | 87:085cde657901 | 1461 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1462 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1463 | } |
mbed_official | 87:085cde657901 | 1464 | else |
mbed_official | 87:085cde657901 | 1465 | { |
mbed_official | 87:085cde657901 | 1466 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1467 | } |
mbed_official | 87:085cde657901 | 1468 | } |
mbed_official | 87:085cde657901 | 1469 | |
mbed_official | 87:085cde657901 | 1470 | /** |
mbed_official | 87:085cde657901 | 1471 | * @brief Initializes the CRYP peripheral in AES CTR encryption mode using DMA. |
mbed_official | 87:085cde657901 | 1472 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1473 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1474 | * @param Size: Length of the plaintext buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 1475 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1476 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1477 | */ |
mbed_official | 87:085cde657901 | 1478 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 1479 | { |
mbed_official | 87:085cde657901 | 1480 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1481 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1482 | |
mbed_official | 87:085cde657901 | 1483 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 1484 | { |
mbed_official | 87:085cde657901 | 1485 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1486 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1487 | |
mbed_official | 87:085cde657901 | 1488 | inputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 1489 | outputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 1490 | |
mbed_official | 87:085cde657901 | 1491 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1492 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1493 | |
mbed_official | 87:085cde657901 | 1494 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1495 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1496 | { |
mbed_official | 87:085cde657901 | 1497 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1498 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1499 | |
mbed_official | 87:085cde657901 | 1500 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 1501 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR); |
mbed_official | 87:085cde657901 | 1502 | |
mbed_official | 87:085cde657901 | 1503 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 1504 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 1505 | |
mbed_official | 87:085cde657901 | 1506 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1507 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1508 | |
mbed_official | 87:085cde657901 | 1509 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1510 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1511 | } |
mbed_official | 87:085cde657901 | 1512 | |
mbed_official | 87:085cde657901 | 1513 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 1514 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 1515 | |
mbed_official | 87:085cde657901 | 1516 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1517 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1518 | |
mbed_official | 87:085cde657901 | 1519 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1520 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1521 | } |
mbed_official | 87:085cde657901 | 1522 | else |
mbed_official | 87:085cde657901 | 1523 | { |
mbed_official | 87:085cde657901 | 1524 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1525 | } |
mbed_official | 87:085cde657901 | 1526 | } |
mbed_official | 87:085cde657901 | 1527 | |
mbed_official | 87:085cde657901 | 1528 | /** |
mbed_official | 87:085cde657901 | 1529 | * @brief Initializes the CRYP peripheral in AES ECB decryption mode using DMA. |
mbed_official | 87:085cde657901 | 1530 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1531 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1532 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
mbed_official | 87:085cde657901 | 1533 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1534 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1535 | */ |
mbed_official | 87:085cde657901 | 1536 | HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 1537 | { |
mbed_official | 87:085cde657901 | 1538 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 1539 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1540 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1541 | |
mbed_official | 87:085cde657901 | 1542 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 1543 | { |
mbed_official | 87:085cde657901 | 1544 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1545 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1546 | |
mbed_official | 87:085cde657901 | 1547 | inputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 1548 | outputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 1549 | |
mbed_official | 87:085cde657901 | 1550 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1551 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1552 | |
mbed_official | 87:085cde657901 | 1553 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1554 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1555 | { |
mbed_official | 87:085cde657901 | 1556 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1557 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1558 | |
mbed_official | 87:085cde657901 | 1559 | /* Set the CRYP peripheral in AES Key mode */ |
mbed_official | 87:085cde657901 | 1560 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1561 | |
mbed_official | 87:085cde657901 | 1562 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1563 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1564 | |
mbed_official | 87:085cde657901 | 1565 | /* Get timeout */ |
mbed_official | 87:085cde657901 | 1566 | timeout = HAL_GetTick() + 1; |
mbed_official | 87:085cde657901 | 1567 | |
mbed_official | 87:085cde657901 | 1568 | while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY)) |
mbed_official | 87:085cde657901 | 1569 | { |
mbed_official | 87:085cde657901 | 1570 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 1571 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1572 | { |
mbed_official | 87:085cde657901 | 1573 | /* Change state */ |
mbed_official | 87:085cde657901 | 1574 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1575 | |
mbed_official | 87:085cde657901 | 1576 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1577 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1578 | |
mbed_official | 87:085cde657901 | 1579 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1580 | } |
mbed_official | 87:085cde657901 | 1581 | } |
mbed_official | 87:085cde657901 | 1582 | |
mbed_official | 87:085cde657901 | 1583 | /* Reset the ALGOMODE bits*/ |
mbed_official | 87:085cde657901 | 1584 | CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE); |
mbed_official | 87:085cde657901 | 1585 | |
mbed_official | 87:085cde657901 | 1586 | /* Set the CRYP peripheral in AES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 1587 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1588 | |
mbed_official | 87:085cde657901 | 1589 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1590 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1591 | |
mbed_official | 87:085cde657901 | 1592 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1593 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1594 | } |
mbed_official | 87:085cde657901 | 1595 | |
mbed_official | 87:085cde657901 | 1596 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 1597 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 1598 | |
mbed_official | 87:085cde657901 | 1599 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1600 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1601 | |
mbed_official | 87:085cde657901 | 1602 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1603 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1604 | } |
mbed_official | 87:085cde657901 | 1605 | else |
mbed_official | 87:085cde657901 | 1606 | { |
mbed_official | 87:085cde657901 | 1607 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1608 | } |
mbed_official | 87:085cde657901 | 1609 | } |
mbed_official | 87:085cde657901 | 1610 | |
mbed_official | 87:085cde657901 | 1611 | /** |
mbed_official | 87:085cde657901 | 1612 | * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA. |
mbed_official | 87:085cde657901 | 1613 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1614 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1615 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes |
mbed_official | 87:085cde657901 | 1616 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1617 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1618 | */ |
mbed_official | 87:085cde657901 | 1619 | HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 1620 | { |
mbed_official | 87:085cde657901 | 1621 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 1622 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1623 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1624 | |
mbed_official | 87:085cde657901 | 1625 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 1626 | { |
mbed_official | 87:085cde657901 | 1627 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1628 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1629 | |
mbed_official | 87:085cde657901 | 1630 | inputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 1631 | outputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 1632 | |
mbed_official | 87:085cde657901 | 1633 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1634 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1635 | |
mbed_official | 87:085cde657901 | 1636 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1637 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1638 | { |
mbed_official | 87:085cde657901 | 1639 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1640 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1641 | |
mbed_official | 87:085cde657901 | 1642 | /* Set the CRYP peripheral in AES Key mode */ |
mbed_official | 87:085cde657901 | 1643 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1644 | |
mbed_official | 87:085cde657901 | 1645 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1646 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1647 | |
mbed_official | 87:085cde657901 | 1648 | /* Get timeout */ |
mbed_official | 87:085cde657901 | 1649 | timeout = HAL_GetTick() + 1; |
mbed_official | 87:085cde657901 | 1650 | |
mbed_official | 87:085cde657901 | 1651 | while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY)) |
mbed_official | 87:085cde657901 | 1652 | { |
mbed_official | 87:085cde657901 | 1653 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 1654 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1655 | { |
mbed_official | 87:085cde657901 | 1656 | /* Change state */ |
mbed_official | 87:085cde657901 | 1657 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1658 | |
mbed_official | 87:085cde657901 | 1659 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1660 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1661 | |
mbed_official | 87:085cde657901 | 1662 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1663 | } |
mbed_official | 87:085cde657901 | 1664 | } |
mbed_official | 87:085cde657901 | 1665 | |
mbed_official | 87:085cde657901 | 1666 | /* Reset the ALGOMODE bits*/ |
mbed_official | 87:085cde657901 | 1667 | CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE); |
mbed_official | 87:085cde657901 | 1668 | |
mbed_official | 87:085cde657901 | 1669 | /* Set the CRYP peripheral in AES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 1670 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1671 | |
mbed_official | 87:085cde657901 | 1672 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 1673 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 1674 | |
mbed_official | 87:085cde657901 | 1675 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1676 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1677 | |
mbed_official | 87:085cde657901 | 1678 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1679 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1680 | } |
mbed_official | 87:085cde657901 | 1681 | |
mbed_official | 87:085cde657901 | 1682 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 1683 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 1684 | |
mbed_official | 87:085cde657901 | 1685 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1686 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1687 | |
mbed_official | 87:085cde657901 | 1688 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1689 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1690 | } |
mbed_official | 87:085cde657901 | 1691 | else |
mbed_official | 87:085cde657901 | 1692 | { |
mbed_official | 87:085cde657901 | 1693 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1694 | } |
mbed_official | 87:085cde657901 | 1695 | } |
mbed_official | 87:085cde657901 | 1696 | |
mbed_official | 87:085cde657901 | 1697 | /** |
mbed_official | 87:085cde657901 | 1698 | * @brief Initializes the CRYP peripheral in AES CTR decryption mode using DMA. |
mbed_official | 87:085cde657901 | 1699 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1700 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1701 | * @param Size: Length of the plaintext buffer, must be a multiple of 16 |
mbed_official | 87:085cde657901 | 1702 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1703 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1704 | */ |
mbed_official | 87:085cde657901 | 1705 | HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 1706 | { |
mbed_official | 87:085cde657901 | 1707 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1708 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1709 | |
mbed_official | 87:085cde657901 | 1710 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 1711 | { |
mbed_official | 87:085cde657901 | 1712 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1713 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1714 | |
mbed_official | 87:085cde657901 | 1715 | inputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 1716 | outputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 1717 | |
mbed_official | 87:085cde657901 | 1718 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1719 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1720 | |
mbed_official | 87:085cde657901 | 1721 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 1722 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 1723 | { |
mbed_official | 87:085cde657901 | 1724 | /* Set the key */ |
mbed_official | 87:085cde657901 | 1725 | CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); |
mbed_official | 87:085cde657901 | 1726 | |
mbed_official | 87:085cde657901 | 1727 | /* Set the CRYP peripheral in AES CTR mode */ |
mbed_official | 87:085cde657901 | 1728 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1729 | |
mbed_official | 87:085cde657901 | 1730 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 1731 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); |
mbed_official | 87:085cde657901 | 1732 | |
mbed_official | 87:085cde657901 | 1733 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 1734 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 1735 | |
mbed_official | 87:085cde657901 | 1736 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 1737 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 1738 | } |
mbed_official | 87:085cde657901 | 1739 | |
mbed_official | 87:085cde657901 | 1740 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 1741 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 1742 | |
mbed_official | 87:085cde657901 | 1743 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1744 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1745 | |
mbed_official | 87:085cde657901 | 1746 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1747 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1748 | } |
mbed_official | 87:085cde657901 | 1749 | else |
mbed_official | 87:085cde657901 | 1750 | { |
mbed_official | 87:085cde657901 | 1751 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1752 | } |
mbed_official | 87:085cde657901 | 1753 | } |
mbed_official | 87:085cde657901 | 1754 | |
mbed_official | 87:085cde657901 | 1755 | |
mbed_official | 87:085cde657901 | 1756 | /** |
mbed_official | 87:085cde657901 | 1757 | * @} |
mbed_official | 87:085cde657901 | 1758 | */ |
mbed_official | 87:085cde657901 | 1759 | /** @defgroup CRYP_Group3 DES processing functions |
mbed_official | 87:085cde657901 | 1760 | * @brief processing functions. |
mbed_official | 87:085cde657901 | 1761 | * |
mbed_official | 87:085cde657901 | 1762 | @verbatim |
mbed_official | 87:085cde657901 | 1763 | ============================================================================== |
mbed_official | 87:085cde657901 | 1764 | ##### DES processing functions ##### |
mbed_official | 87:085cde657901 | 1765 | ============================================================================== |
mbed_official | 87:085cde657901 | 1766 | [..] This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 1767 | (+) Encrypt plaintext using DES using ECB or CBC chaining modes |
mbed_official | 87:085cde657901 | 1768 | (+) Decrypt cyphertext using using ECB or CBC chaining modes |
mbed_official | 87:085cde657901 | 1769 | [..] Three processing functions are available: |
mbed_official | 87:085cde657901 | 1770 | (+) polling mode |
mbed_official | 87:085cde657901 | 1771 | (+) interrupt mode |
mbed_official | 87:085cde657901 | 1772 | (+) DMA mode |
mbed_official | 87:085cde657901 | 1773 | |
mbed_official | 87:085cde657901 | 1774 | @endverbatim |
mbed_official | 87:085cde657901 | 1775 | * @{ |
mbed_official | 87:085cde657901 | 1776 | */ |
mbed_official | 87:085cde657901 | 1777 | |
mbed_official | 87:085cde657901 | 1778 | /** |
mbed_official | 87:085cde657901 | 1779 | * @brief Initializes the CRYP peripheral in DES ECB encryption mode. |
mbed_official | 87:085cde657901 | 1780 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1781 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1782 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 1783 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1784 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 1785 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1786 | */ |
mbed_official | 87:085cde657901 | 1787 | HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 1788 | { |
mbed_official | 87:085cde657901 | 1789 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1790 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1791 | |
mbed_official | 87:085cde657901 | 1792 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1793 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1794 | |
mbed_official | 87:085cde657901 | 1795 | /* Set CRYP peripheral in DES ECB encryption mode */ |
mbed_official | 87:085cde657901 | 1796 | CRYP_SetDESECBMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 1797 | |
mbed_official | 87:085cde657901 | 1798 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1799 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1800 | |
mbed_official | 87:085cde657901 | 1801 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 1802 | if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 1803 | { |
mbed_official | 87:085cde657901 | 1804 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1805 | } |
mbed_official | 87:085cde657901 | 1806 | |
mbed_official | 87:085cde657901 | 1807 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1808 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 1809 | |
mbed_official | 87:085cde657901 | 1810 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1811 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1812 | |
mbed_official | 87:085cde657901 | 1813 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1814 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1815 | } |
mbed_official | 87:085cde657901 | 1816 | |
mbed_official | 87:085cde657901 | 1817 | /** |
mbed_official | 87:085cde657901 | 1818 | * @brief Initializes the CRYP peripheral in DES ECB decryption mode. |
mbed_official | 87:085cde657901 | 1819 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1820 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1821 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 1822 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1823 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 1824 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1825 | */ |
mbed_official | 87:085cde657901 | 1826 | HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 1827 | { |
mbed_official | 87:085cde657901 | 1828 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1829 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1830 | |
mbed_official | 87:085cde657901 | 1831 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1832 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1833 | |
mbed_official | 87:085cde657901 | 1834 | /* Set CRYP peripheral in DES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 1835 | CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1836 | |
mbed_official | 87:085cde657901 | 1837 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1838 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1839 | |
mbed_official | 87:085cde657901 | 1840 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 1841 | if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 1842 | { |
mbed_official | 87:085cde657901 | 1843 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1844 | } |
mbed_official | 87:085cde657901 | 1845 | |
mbed_official | 87:085cde657901 | 1846 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1847 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 1848 | |
mbed_official | 87:085cde657901 | 1849 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1850 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1851 | |
mbed_official | 87:085cde657901 | 1852 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1853 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1854 | } |
mbed_official | 87:085cde657901 | 1855 | |
mbed_official | 87:085cde657901 | 1856 | /** |
mbed_official | 87:085cde657901 | 1857 | * @brief Initializes the CRYP peripheral in DES CBC encryption mode. |
mbed_official | 87:085cde657901 | 1858 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1859 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1860 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 1861 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1862 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 1863 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1864 | */ |
mbed_official | 87:085cde657901 | 1865 | HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 1866 | { |
mbed_official | 87:085cde657901 | 1867 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1868 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1869 | |
mbed_official | 87:085cde657901 | 1870 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1871 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1872 | |
mbed_official | 87:085cde657901 | 1873 | /* Set CRYP peripheral in DES CBC encryption mode */ |
mbed_official | 87:085cde657901 | 1874 | CRYP_SetDESCBCMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 1875 | |
mbed_official | 87:085cde657901 | 1876 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1877 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1878 | |
mbed_official | 87:085cde657901 | 1879 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 1880 | if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 1881 | { |
mbed_official | 87:085cde657901 | 1882 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1883 | } |
mbed_official | 87:085cde657901 | 1884 | |
mbed_official | 87:085cde657901 | 1885 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1886 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 1887 | |
mbed_official | 87:085cde657901 | 1888 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1889 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1890 | |
mbed_official | 87:085cde657901 | 1891 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1892 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1893 | } |
mbed_official | 87:085cde657901 | 1894 | |
mbed_official | 87:085cde657901 | 1895 | /** |
mbed_official | 87:085cde657901 | 1896 | * @brief Initializes the CRYP peripheral in DES ECB decryption mode. |
mbed_official | 87:085cde657901 | 1897 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1898 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1899 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 1900 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1901 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 1902 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1903 | */ |
mbed_official | 87:085cde657901 | 1904 | HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 1905 | { |
mbed_official | 87:085cde657901 | 1906 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1907 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1908 | |
mbed_official | 87:085cde657901 | 1909 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1910 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1911 | |
mbed_official | 87:085cde657901 | 1912 | /* Set CRYP peripheral in DES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 1913 | CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 1914 | |
mbed_official | 87:085cde657901 | 1915 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1916 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1917 | |
mbed_official | 87:085cde657901 | 1918 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 1919 | if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 1920 | { |
mbed_official | 87:085cde657901 | 1921 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1922 | } |
mbed_official | 87:085cde657901 | 1923 | |
mbed_official | 87:085cde657901 | 1924 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1925 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 1926 | |
mbed_official | 87:085cde657901 | 1927 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1928 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 1929 | |
mbed_official | 87:085cde657901 | 1930 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1931 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1932 | } |
mbed_official | 87:085cde657901 | 1933 | |
mbed_official | 87:085cde657901 | 1934 | /** |
mbed_official | 87:085cde657901 | 1935 | * @brief Initializes the CRYP peripheral in DES ECB encryption mode using IT. |
mbed_official | 87:085cde657901 | 1936 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 1937 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 1938 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 1939 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 1940 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1941 | */ |
mbed_official | 87:085cde657901 | 1942 | HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 1943 | { |
mbed_official | 87:085cde657901 | 1944 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 1945 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 1946 | |
mbed_official | 87:085cde657901 | 1947 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 1948 | { |
mbed_official | 87:085cde657901 | 1949 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1950 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 1951 | |
mbed_official | 87:085cde657901 | 1952 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 1953 | hcryp->pCrypInBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 1954 | hcryp->pCrypOutBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 1955 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 1956 | |
mbed_official | 87:085cde657901 | 1957 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 1958 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1959 | |
mbed_official | 87:085cde657901 | 1960 | /* Set CRYP peripheral in DES ECB encryption mode */ |
mbed_official | 87:085cde657901 | 1961 | CRYP_SetDESECBMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 1962 | |
mbed_official | 87:085cde657901 | 1963 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 1964 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 1965 | |
mbed_official | 87:085cde657901 | 1966 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 1967 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 1968 | |
mbed_official | 87:085cde657901 | 1969 | /* Return function status */ |
mbed_official | 87:085cde657901 | 1970 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1971 | } |
mbed_official | 87:085cde657901 | 1972 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 1973 | { |
mbed_official | 87:085cde657901 | 1974 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 1975 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 1976 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1977 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 1978 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 1979 | |
mbed_official | 87:085cde657901 | 1980 | hcryp->pCrypInBuffPtr += 8; |
mbed_official | 87:085cde657901 | 1981 | hcryp->CrypInCount -= 8; |
mbed_official | 87:085cde657901 | 1982 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 1983 | { |
mbed_official | 87:085cde657901 | 1984 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 1985 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 1986 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 1987 | } |
mbed_official | 87:085cde657901 | 1988 | } |
mbed_official | 87:085cde657901 | 1989 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 1990 | { |
mbed_official | 87:085cde657901 | 1991 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 1992 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 1993 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1994 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 1995 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 1996 | |
mbed_official | 87:085cde657901 | 1997 | hcryp->pCrypOutBuffPtr += 8; |
mbed_official | 87:085cde657901 | 1998 | hcryp->CrypOutCount -= 8; |
mbed_official | 87:085cde657901 | 1999 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 2000 | { |
mbed_official | 87:085cde657901 | 2001 | /* Disable IT */ |
mbed_official | 87:085cde657901 | 2002 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2003 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 2004 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 2005 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2006 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2007 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2008 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2009 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 2010 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2011 | } |
mbed_official | 87:085cde657901 | 2012 | } |
mbed_official | 87:085cde657901 | 2013 | |
mbed_official | 87:085cde657901 | 2014 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2015 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2016 | } |
mbed_official | 87:085cde657901 | 2017 | |
mbed_official | 87:085cde657901 | 2018 | /** |
mbed_official | 87:085cde657901 | 2019 | * @brief Initializes the CRYP peripheral in DES CBC encryption mode using interrupt. |
mbed_official | 87:085cde657901 | 2020 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2021 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2022 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2023 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2024 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2025 | */ |
mbed_official | 87:085cde657901 | 2026 | HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 2027 | { |
mbed_official | 87:085cde657901 | 2028 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2029 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2030 | |
mbed_official | 87:085cde657901 | 2031 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 2032 | { |
mbed_official | 87:085cde657901 | 2033 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2034 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2035 | |
mbed_official | 87:085cde657901 | 2036 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 2037 | hcryp->pCrypInBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 2038 | hcryp->pCrypOutBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 2039 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 2040 | |
mbed_official | 87:085cde657901 | 2041 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2042 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2043 | |
mbed_official | 87:085cde657901 | 2044 | /* Set CRYP peripheral in DES CBC encryption mode */ |
mbed_official | 87:085cde657901 | 2045 | CRYP_SetDESCBCMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 2046 | |
mbed_official | 87:085cde657901 | 2047 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 2048 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2049 | |
mbed_official | 87:085cde657901 | 2050 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2051 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2052 | |
mbed_official | 87:085cde657901 | 2053 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2054 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2055 | } |
mbed_official | 87:085cde657901 | 2056 | |
mbed_official | 87:085cde657901 | 2057 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 2058 | { |
mbed_official | 87:085cde657901 | 2059 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 2060 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 2061 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2062 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 2063 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2064 | |
mbed_official | 87:085cde657901 | 2065 | hcryp->pCrypInBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2066 | hcryp->CrypInCount -= 8; |
mbed_official | 87:085cde657901 | 2067 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 2068 | { |
mbed_official | 87:085cde657901 | 2069 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 2070 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 2071 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2072 | } |
mbed_official | 87:085cde657901 | 2073 | } |
mbed_official | 87:085cde657901 | 2074 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 2075 | { |
mbed_official | 87:085cde657901 | 2076 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 2077 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 2078 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2079 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 2080 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2081 | |
mbed_official | 87:085cde657901 | 2082 | hcryp->pCrypOutBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2083 | hcryp->CrypOutCount -= 8; |
mbed_official | 87:085cde657901 | 2084 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 2085 | { |
mbed_official | 87:085cde657901 | 2086 | /* Disable IT */ |
mbed_official | 87:085cde657901 | 2087 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2088 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 2089 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 2090 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2091 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2092 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2093 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2094 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 2095 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2096 | } |
mbed_official | 87:085cde657901 | 2097 | } |
mbed_official | 87:085cde657901 | 2098 | |
mbed_official | 87:085cde657901 | 2099 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2100 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2101 | } |
mbed_official | 87:085cde657901 | 2102 | |
mbed_official | 87:085cde657901 | 2103 | /** |
mbed_official | 87:085cde657901 | 2104 | * @brief Initializes the CRYP peripheral in DES ECB decryption mode using IT. |
mbed_official | 87:085cde657901 | 2105 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2106 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2107 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2108 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2109 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2110 | */ |
mbed_official | 87:085cde657901 | 2111 | HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 2112 | { |
mbed_official | 87:085cde657901 | 2113 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2114 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2115 | |
mbed_official | 87:085cde657901 | 2116 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 2117 | { |
mbed_official | 87:085cde657901 | 2118 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2119 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2120 | |
mbed_official | 87:085cde657901 | 2121 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 2122 | hcryp->pCrypInBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 2123 | hcryp->pCrypOutBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 2124 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 2125 | |
mbed_official | 87:085cde657901 | 2126 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2127 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2128 | |
mbed_official | 87:085cde657901 | 2129 | /* Set CRYP peripheral in DES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 2130 | CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 2131 | |
mbed_official | 87:085cde657901 | 2132 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 2133 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2134 | |
mbed_official | 87:085cde657901 | 2135 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2136 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2137 | |
mbed_official | 87:085cde657901 | 2138 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2139 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2140 | } |
mbed_official | 87:085cde657901 | 2141 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 2142 | { |
mbed_official | 87:085cde657901 | 2143 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 2144 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 2145 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2146 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 2147 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2148 | |
mbed_official | 87:085cde657901 | 2149 | hcryp->pCrypInBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2150 | hcryp->CrypInCount -= 8; |
mbed_official | 87:085cde657901 | 2151 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 2152 | { |
mbed_official | 87:085cde657901 | 2153 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 2154 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 2155 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2156 | } |
mbed_official | 87:085cde657901 | 2157 | } |
mbed_official | 87:085cde657901 | 2158 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 2159 | { |
mbed_official | 87:085cde657901 | 2160 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 2161 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 2162 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2163 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 2164 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2165 | |
mbed_official | 87:085cde657901 | 2166 | hcryp->pCrypOutBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2167 | hcryp->CrypOutCount -= 8; |
mbed_official | 87:085cde657901 | 2168 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 2169 | { |
mbed_official | 87:085cde657901 | 2170 | /* Disable IT */ |
mbed_official | 87:085cde657901 | 2171 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2172 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 2173 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 2174 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2175 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2176 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2177 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2178 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 2179 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2180 | } |
mbed_official | 87:085cde657901 | 2181 | } |
mbed_official | 87:085cde657901 | 2182 | |
mbed_official | 87:085cde657901 | 2183 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2184 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2185 | } |
mbed_official | 87:085cde657901 | 2186 | |
mbed_official | 87:085cde657901 | 2187 | /** |
mbed_official | 87:085cde657901 | 2188 | * @brief Initializes the CRYP peripheral in DES ECB decryption mode using interrupt. |
mbed_official | 87:085cde657901 | 2189 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2190 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2191 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2192 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2193 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2194 | */ |
mbed_official | 87:085cde657901 | 2195 | HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 2196 | { |
mbed_official | 87:085cde657901 | 2197 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2198 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2199 | |
mbed_official | 87:085cde657901 | 2200 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 2201 | { |
mbed_official | 87:085cde657901 | 2202 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2203 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2204 | |
mbed_official | 87:085cde657901 | 2205 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 2206 | hcryp->pCrypInBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 2207 | hcryp->pCrypOutBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 2208 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 2209 | |
mbed_official | 87:085cde657901 | 2210 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2211 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2212 | |
mbed_official | 87:085cde657901 | 2213 | /* Set CRYP peripheral in DES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 2214 | CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 2215 | |
mbed_official | 87:085cde657901 | 2216 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 2217 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2218 | |
mbed_official | 87:085cde657901 | 2219 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2220 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2221 | |
mbed_official | 87:085cde657901 | 2222 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2223 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2224 | } |
mbed_official | 87:085cde657901 | 2225 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 2226 | { |
mbed_official | 87:085cde657901 | 2227 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 2228 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 2229 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2230 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 2231 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2232 | |
mbed_official | 87:085cde657901 | 2233 | hcryp->pCrypInBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2234 | hcryp->CrypInCount -= 8; |
mbed_official | 87:085cde657901 | 2235 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 2236 | { |
mbed_official | 87:085cde657901 | 2237 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 2238 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 2239 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2240 | } |
mbed_official | 87:085cde657901 | 2241 | } |
mbed_official | 87:085cde657901 | 2242 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 2243 | { |
mbed_official | 87:085cde657901 | 2244 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 2245 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 2246 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2247 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 2248 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2249 | |
mbed_official | 87:085cde657901 | 2250 | hcryp->pCrypOutBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2251 | hcryp->CrypOutCount -= 8; |
mbed_official | 87:085cde657901 | 2252 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 2253 | { |
mbed_official | 87:085cde657901 | 2254 | /* Disable IT */ |
mbed_official | 87:085cde657901 | 2255 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2256 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 2257 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 2258 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2259 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2260 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2261 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2262 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 2263 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2264 | } |
mbed_official | 87:085cde657901 | 2265 | } |
mbed_official | 87:085cde657901 | 2266 | |
mbed_official | 87:085cde657901 | 2267 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2268 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2269 | } |
mbed_official | 87:085cde657901 | 2270 | |
mbed_official | 87:085cde657901 | 2271 | /** |
mbed_official | 87:085cde657901 | 2272 | * @brief Initializes the CRYP peripheral in DES ECB encryption mode using DMA. |
mbed_official | 87:085cde657901 | 2273 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2274 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2275 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2276 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2277 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2278 | */ |
mbed_official | 87:085cde657901 | 2279 | HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 2280 | { |
mbed_official | 87:085cde657901 | 2281 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2282 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2283 | |
mbed_official | 87:085cde657901 | 2284 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 2285 | { |
mbed_official | 87:085cde657901 | 2286 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2287 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2288 | |
mbed_official | 87:085cde657901 | 2289 | inputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 2290 | outputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 2291 | |
mbed_official | 87:085cde657901 | 2292 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2293 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2294 | |
mbed_official | 87:085cde657901 | 2295 | /* Set CRYP peripheral in DES ECB encryption mode */ |
mbed_official | 87:085cde657901 | 2296 | CRYP_SetDESECBMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 2297 | |
mbed_official | 87:085cde657901 | 2298 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 2299 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 2300 | |
mbed_official | 87:085cde657901 | 2301 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2302 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2303 | |
mbed_official | 87:085cde657901 | 2304 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2305 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2306 | } |
mbed_official | 87:085cde657901 | 2307 | else |
mbed_official | 87:085cde657901 | 2308 | { |
mbed_official | 87:085cde657901 | 2309 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 2310 | } |
mbed_official | 87:085cde657901 | 2311 | } |
mbed_official | 87:085cde657901 | 2312 | |
mbed_official | 87:085cde657901 | 2313 | /** |
mbed_official | 87:085cde657901 | 2314 | * @brief Initializes the CRYP peripheral in DES CBC encryption mode using DMA. |
mbed_official | 87:085cde657901 | 2315 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2316 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2317 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2318 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2319 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2320 | */ |
mbed_official | 87:085cde657901 | 2321 | HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 2322 | { |
mbed_official | 87:085cde657901 | 2323 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2324 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2325 | |
mbed_official | 87:085cde657901 | 2326 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 2327 | { |
mbed_official | 87:085cde657901 | 2328 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2329 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2330 | |
mbed_official | 87:085cde657901 | 2331 | inputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 2332 | outputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 2333 | |
mbed_official | 87:085cde657901 | 2334 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2335 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2336 | |
mbed_official | 87:085cde657901 | 2337 | /* Set CRYP peripheral in DES CBC encryption mode */ |
mbed_official | 87:085cde657901 | 2338 | CRYP_SetDESCBCMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 2339 | |
mbed_official | 87:085cde657901 | 2340 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 2341 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 2342 | |
mbed_official | 87:085cde657901 | 2343 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2344 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2345 | |
mbed_official | 87:085cde657901 | 2346 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2347 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2348 | } |
mbed_official | 87:085cde657901 | 2349 | else |
mbed_official | 87:085cde657901 | 2350 | { |
mbed_official | 87:085cde657901 | 2351 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 2352 | } |
mbed_official | 87:085cde657901 | 2353 | } |
mbed_official | 87:085cde657901 | 2354 | |
mbed_official | 87:085cde657901 | 2355 | /** |
mbed_official | 87:085cde657901 | 2356 | * @brief Initializes the CRYP peripheral in DES ECB decryption mode using DMA. |
mbed_official | 87:085cde657901 | 2357 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2358 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2359 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2360 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2361 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2362 | */ |
mbed_official | 87:085cde657901 | 2363 | HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 2364 | { |
mbed_official | 87:085cde657901 | 2365 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2366 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2367 | |
mbed_official | 87:085cde657901 | 2368 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 2369 | { |
mbed_official | 87:085cde657901 | 2370 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2371 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2372 | |
mbed_official | 87:085cde657901 | 2373 | inputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 2374 | outputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 2375 | |
mbed_official | 87:085cde657901 | 2376 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2377 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2378 | |
mbed_official | 87:085cde657901 | 2379 | /* Set CRYP peripheral in DES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 2380 | CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 2381 | |
mbed_official | 87:085cde657901 | 2382 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 2383 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 2384 | |
mbed_official | 87:085cde657901 | 2385 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2386 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2387 | |
mbed_official | 87:085cde657901 | 2388 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2389 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2390 | } |
mbed_official | 87:085cde657901 | 2391 | else |
mbed_official | 87:085cde657901 | 2392 | { |
mbed_official | 87:085cde657901 | 2393 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 2394 | } |
mbed_official | 87:085cde657901 | 2395 | } |
mbed_official | 87:085cde657901 | 2396 | |
mbed_official | 87:085cde657901 | 2397 | /** |
mbed_official | 87:085cde657901 | 2398 | * @brief Initializes the CRYP peripheral in DES ECB decryption mode using DMA. |
mbed_official | 87:085cde657901 | 2399 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2400 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2401 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2402 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2403 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2404 | */ |
mbed_official | 87:085cde657901 | 2405 | HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 2406 | { |
mbed_official | 87:085cde657901 | 2407 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2408 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2409 | |
mbed_official | 87:085cde657901 | 2410 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 2411 | { |
mbed_official | 87:085cde657901 | 2412 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2413 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2414 | |
mbed_official | 87:085cde657901 | 2415 | inputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 2416 | outputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 2417 | |
mbed_official | 87:085cde657901 | 2418 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2419 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2420 | |
mbed_official | 87:085cde657901 | 2421 | /* Set CRYP peripheral in DES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 2422 | CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 2423 | |
mbed_official | 87:085cde657901 | 2424 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 2425 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 2426 | |
mbed_official | 87:085cde657901 | 2427 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2428 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2429 | |
mbed_official | 87:085cde657901 | 2430 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2431 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2432 | } |
mbed_official | 87:085cde657901 | 2433 | else |
mbed_official | 87:085cde657901 | 2434 | { |
mbed_official | 87:085cde657901 | 2435 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 2436 | } |
mbed_official | 87:085cde657901 | 2437 | } |
mbed_official | 87:085cde657901 | 2438 | |
mbed_official | 87:085cde657901 | 2439 | /** |
mbed_official | 87:085cde657901 | 2440 | * @} |
mbed_official | 87:085cde657901 | 2441 | */ |
mbed_official | 87:085cde657901 | 2442 | |
mbed_official | 87:085cde657901 | 2443 | /** @defgroup CRYP_Group4 TDES processing functions |
mbed_official | 87:085cde657901 | 2444 | * @brief processing functions. |
mbed_official | 87:085cde657901 | 2445 | * |
mbed_official | 87:085cde657901 | 2446 | @verbatim |
mbed_official | 87:085cde657901 | 2447 | ============================================================================== |
mbed_official | 87:085cde657901 | 2448 | ##### TDES processing functions ##### |
mbed_official | 87:085cde657901 | 2449 | ============================================================================== |
mbed_official | 87:085cde657901 | 2450 | [..] This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 2451 | (+) Encrypt plaintext using TDES using ECB or CBC chaining modes |
mbed_official | 87:085cde657901 | 2452 | (+) Decrypt cyphertext using TDES using ECB or CBC chaining modes |
mbed_official | 87:085cde657901 | 2453 | [..] Three processing functions are available: |
mbed_official | 87:085cde657901 | 2454 | (+) polling mode |
mbed_official | 87:085cde657901 | 2455 | (+) interrupt mode |
mbed_official | 87:085cde657901 | 2456 | (+) DMA mode |
mbed_official | 87:085cde657901 | 2457 | |
mbed_official | 87:085cde657901 | 2458 | @endverbatim |
mbed_official | 87:085cde657901 | 2459 | * @{ |
mbed_official | 87:085cde657901 | 2460 | */ |
mbed_official | 87:085cde657901 | 2461 | |
mbed_official | 87:085cde657901 | 2462 | /** |
mbed_official | 87:085cde657901 | 2463 | * @brief Initializes the CRYP peripheral in TDES ECB encryption mode |
mbed_official | 87:085cde657901 | 2464 | * then encrypt pPlainData. The cypher data are available in pCypherData |
mbed_official | 87:085cde657901 | 2465 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2466 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2467 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2468 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2469 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 2470 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2471 | */ |
mbed_official | 87:085cde657901 | 2472 | HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 2473 | { |
mbed_official | 87:085cde657901 | 2474 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2475 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2476 | |
mbed_official | 87:085cde657901 | 2477 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2478 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2479 | |
mbed_official | 87:085cde657901 | 2480 | /* Set CRYP peripheral in TDES ECB encryption mode */ |
mbed_official | 87:085cde657901 | 2481 | CRYP_SetTDESECBMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 2482 | |
mbed_official | 87:085cde657901 | 2483 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2484 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2485 | |
mbed_official | 87:085cde657901 | 2486 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 2487 | if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 2488 | { |
mbed_official | 87:085cde657901 | 2489 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 2490 | } |
mbed_official | 87:085cde657901 | 2491 | |
mbed_official | 87:085cde657901 | 2492 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2493 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2494 | |
mbed_official | 87:085cde657901 | 2495 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2496 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2497 | |
mbed_official | 87:085cde657901 | 2498 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2499 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2500 | } |
mbed_official | 87:085cde657901 | 2501 | |
mbed_official | 87:085cde657901 | 2502 | /** |
mbed_official | 87:085cde657901 | 2503 | * @brief Initializes the CRYP peripheral in TDES ECB decryption mode |
mbed_official | 87:085cde657901 | 2504 | * then decrypted pCypherData. The cypher data are available in pPlainData |
mbed_official | 87:085cde657901 | 2505 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2506 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2507 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2508 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2509 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 2510 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2511 | */ |
mbed_official | 87:085cde657901 | 2512 | HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 2513 | { |
mbed_official | 87:085cde657901 | 2514 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2515 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2516 | |
mbed_official | 87:085cde657901 | 2517 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2518 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2519 | |
mbed_official | 87:085cde657901 | 2520 | /* Set CRYP peripheral in TDES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 2521 | CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 2522 | |
mbed_official | 87:085cde657901 | 2523 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2524 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2525 | |
mbed_official | 87:085cde657901 | 2526 | /* Write Cypher Data and Get Plain Data */ |
mbed_official | 87:085cde657901 | 2527 | if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 2528 | { |
mbed_official | 87:085cde657901 | 2529 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 2530 | } |
mbed_official | 87:085cde657901 | 2531 | |
mbed_official | 87:085cde657901 | 2532 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2533 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2534 | |
mbed_official | 87:085cde657901 | 2535 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2536 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2537 | |
mbed_official | 87:085cde657901 | 2538 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2539 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2540 | } |
mbed_official | 87:085cde657901 | 2541 | |
mbed_official | 87:085cde657901 | 2542 | /** |
mbed_official | 87:085cde657901 | 2543 | * @brief Initializes the CRYP peripheral in TDES CBC encryption mode |
mbed_official | 87:085cde657901 | 2544 | * then encrypt pPlainData. The cypher data are available in pCypherData |
mbed_official | 87:085cde657901 | 2545 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2546 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2547 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2548 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2549 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 2550 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2551 | */ |
mbed_official | 87:085cde657901 | 2552 | HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 2553 | { |
mbed_official | 87:085cde657901 | 2554 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2555 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2556 | |
mbed_official | 87:085cde657901 | 2557 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2558 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2559 | |
mbed_official | 87:085cde657901 | 2560 | /* Set CRYP peripheral in TDES CBC encryption mode */ |
mbed_official | 87:085cde657901 | 2561 | CRYP_SetTDESCBCMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 2562 | |
mbed_official | 87:085cde657901 | 2563 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2564 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2565 | |
mbed_official | 87:085cde657901 | 2566 | /* Write Plain Data and Get Cypher Data */ |
mbed_official | 87:085cde657901 | 2567 | if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 2568 | { |
mbed_official | 87:085cde657901 | 2569 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 2570 | } |
mbed_official | 87:085cde657901 | 2571 | |
mbed_official | 87:085cde657901 | 2572 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2573 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2574 | |
mbed_official | 87:085cde657901 | 2575 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2576 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2577 | |
mbed_official | 87:085cde657901 | 2578 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2579 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2580 | } |
mbed_official | 87:085cde657901 | 2581 | |
mbed_official | 87:085cde657901 | 2582 | /** |
mbed_official | 87:085cde657901 | 2583 | * @brief Initializes the CRYP peripheral in TDES CBC decryption mode |
mbed_official | 87:085cde657901 | 2584 | * then decrypted pCypherData. The cypher data are available in pPlainData |
mbed_official | 87:085cde657901 | 2585 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2586 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2587 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2588 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2589 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 2590 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2591 | */ |
mbed_official | 87:085cde657901 | 2592 | HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 2593 | { |
mbed_official | 87:085cde657901 | 2594 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2595 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2596 | |
mbed_official | 87:085cde657901 | 2597 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2598 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2599 | |
mbed_official | 87:085cde657901 | 2600 | /* Set CRYP peripheral in TDES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 2601 | CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 2602 | |
mbed_official | 87:085cde657901 | 2603 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2604 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2605 | |
mbed_official | 87:085cde657901 | 2606 | /* Write Cypher Data and Get Plain Data */ |
mbed_official | 87:085cde657901 | 2607 | if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) |
mbed_official | 87:085cde657901 | 2608 | { |
mbed_official | 87:085cde657901 | 2609 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 2610 | } |
mbed_official | 87:085cde657901 | 2611 | |
mbed_official | 87:085cde657901 | 2612 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2613 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2614 | |
mbed_official | 87:085cde657901 | 2615 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2616 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2617 | |
mbed_official | 87:085cde657901 | 2618 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2619 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2620 | } |
mbed_official | 87:085cde657901 | 2621 | |
mbed_official | 87:085cde657901 | 2622 | /** |
mbed_official | 87:085cde657901 | 2623 | * @brief Initializes the CRYP peripheral in TDES ECB encryption mode using interrupt. |
mbed_official | 87:085cde657901 | 2624 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2625 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2626 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2627 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2628 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2629 | */ |
mbed_official | 87:085cde657901 | 2630 | HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 2631 | { |
mbed_official | 87:085cde657901 | 2632 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2633 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2634 | |
mbed_official | 87:085cde657901 | 2635 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 2636 | { |
mbed_official | 87:085cde657901 | 2637 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2638 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2639 | |
mbed_official | 87:085cde657901 | 2640 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 2641 | hcryp->pCrypInBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 2642 | hcryp->pCrypOutBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 2643 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 2644 | |
mbed_official | 87:085cde657901 | 2645 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2646 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2647 | |
mbed_official | 87:085cde657901 | 2648 | /* Set CRYP peripheral in TDES ECB encryption mode */ |
mbed_official | 87:085cde657901 | 2649 | CRYP_SetTDESECBMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 2650 | |
mbed_official | 87:085cde657901 | 2651 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 2652 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2653 | |
mbed_official | 87:085cde657901 | 2654 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2655 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2656 | |
mbed_official | 87:085cde657901 | 2657 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2658 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2659 | } |
mbed_official | 87:085cde657901 | 2660 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 2661 | { |
mbed_official | 87:085cde657901 | 2662 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 2663 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 2664 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2665 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 2666 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2667 | |
mbed_official | 87:085cde657901 | 2668 | hcryp->pCrypInBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2669 | hcryp->CrypInCount -= 8; |
mbed_official | 87:085cde657901 | 2670 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 2671 | { |
mbed_official | 87:085cde657901 | 2672 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 2673 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 2674 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2675 | } |
mbed_official | 87:085cde657901 | 2676 | } |
mbed_official | 87:085cde657901 | 2677 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 2678 | { |
mbed_official | 87:085cde657901 | 2679 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 2680 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 2681 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2682 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 2683 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2684 | |
mbed_official | 87:085cde657901 | 2685 | hcryp->pCrypOutBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2686 | hcryp->CrypOutCount -= 8; |
mbed_official | 87:085cde657901 | 2687 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 2688 | { |
mbed_official | 87:085cde657901 | 2689 | /* Disable IT */ |
mbed_official | 87:085cde657901 | 2690 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2691 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 2692 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 2693 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2694 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2695 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2696 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2697 | /* Call the Output data transfer complete callback */ |
mbed_official | 87:085cde657901 | 2698 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2699 | } |
mbed_official | 87:085cde657901 | 2700 | } |
mbed_official | 87:085cde657901 | 2701 | |
mbed_official | 87:085cde657901 | 2702 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2703 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2704 | } |
mbed_official | 87:085cde657901 | 2705 | |
mbed_official | 87:085cde657901 | 2706 | /** |
mbed_official | 87:085cde657901 | 2707 | * @brief Initializes the CRYP peripheral in TDES CBC encryption mode. |
mbed_official | 87:085cde657901 | 2708 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2709 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2710 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2711 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2712 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2713 | */ |
mbed_official | 87:085cde657901 | 2714 | HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 2715 | { |
mbed_official | 87:085cde657901 | 2716 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2717 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2718 | |
mbed_official | 87:085cde657901 | 2719 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 2720 | { |
mbed_official | 87:085cde657901 | 2721 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2722 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2723 | |
mbed_official | 87:085cde657901 | 2724 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 2725 | hcryp->pCrypInBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 2726 | hcryp->pCrypOutBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 2727 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 2728 | |
mbed_official | 87:085cde657901 | 2729 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2730 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2731 | |
mbed_official | 87:085cde657901 | 2732 | /* Set CRYP peripheral in TDES CBC encryption mode */ |
mbed_official | 87:085cde657901 | 2733 | CRYP_SetTDESCBCMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 2734 | |
mbed_official | 87:085cde657901 | 2735 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 2736 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2737 | |
mbed_official | 87:085cde657901 | 2738 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2739 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2740 | |
mbed_official | 87:085cde657901 | 2741 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2742 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2743 | } |
mbed_official | 87:085cde657901 | 2744 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 2745 | { |
mbed_official | 87:085cde657901 | 2746 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 2747 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 2748 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2749 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 2750 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2751 | |
mbed_official | 87:085cde657901 | 2752 | hcryp->pCrypInBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2753 | hcryp->CrypInCount -= 8; |
mbed_official | 87:085cde657901 | 2754 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 2755 | { |
mbed_official | 87:085cde657901 | 2756 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 2757 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 2758 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2759 | } |
mbed_official | 87:085cde657901 | 2760 | } |
mbed_official | 87:085cde657901 | 2761 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 2762 | { |
mbed_official | 87:085cde657901 | 2763 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 2764 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 2765 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2766 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 2767 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2768 | |
mbed_official | 87:085cde657901 | 2769 | hcryp->pCrypOutBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2770 | hcryp->CrypOutCount -= 8; |
mbed_official | 87:085cde657901 | 2771 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 2772 | { |
mbed_official | 87:085cde657901 | 2773 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2774 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 2775 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 2776 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2777 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2778 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2779 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2780 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 2781 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2782 | } |
mbed_official | 87:085cde657901 | 2783 | } |
mbed_official | 87:085cde657901 | 2784 | |
mbed_official | 87:085cde657901 | 2785 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2786 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2787 | } |
mbed_official | 87:085cde657901 | 2788 | |
mbed_official | 87:085cde657901 | 2789 | /** |
mbed_official | 87:085cde657901 | 2790 | * @brief Initializes the CRYP peripheral in TDES ECB decryption mode. |
mbed_official | 87:085cde657901 | 2791 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2792 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2793 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2794 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2795 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2796 | */ |
mbed_official | 87:085cde657901 | 2797 | HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 2798 | { |
mbed_official | 87:085cde657901 | 2799 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2800 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2801 | |
mbed_official | 87:085cde657901 | 2802 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 2803 | { |
mbed_official | 87:085cde657901 | 2804 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2805 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2806 | |
mbed_official | 87:085cde657901 | 2807 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 2808 | hcryp->pCrypInBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 2809 | hcryp->pCrypOutBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 2810 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 2811 | |
mbed_official | 87:085cde657901 | 2812 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2813 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2814 | |
mbed_official | 87:085cde657901 | 2815 | /* Set CRYP peripheral in TDES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 2816 | CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 2817 | |
mbed_official | 87:085cde657901 | 2818 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 2819 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2820 | |
mbed_official | 87:085cde657901 | 2821 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2822 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2823 | |
mbed_official | 87:085cde657901 | 2824 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2825 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2826 | } |
mbed_official | 87:085cde657901 | 2827 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 2828 | { |
mbed_official | 87:085cde657901 | 2829 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 2830 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 2831 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2832 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 2833 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2834 | |
mbed_official | 87:085cde657901 | 2835 | hcryp->pCrypInBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2836 | hcryp->CrypInCount -= 8; |
mbed_official | 87:085cde657901 | 2837 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 2838 | { |
mbed_official | 87:085cde657901 | 2839 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 2840 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 2841 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2842 | } |
mbed_official | 87:085cde657901 | 2843 | } |
mbed_official | 87:085cde657901 | 2844 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 2845 | { |
mbed_official | 87:085cde657901 | 2846 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 2847 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 2848 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2849 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 2850 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2851 | |
mbed_official | 87:085cde657901 | 2852 | hcryp->pCrypOutBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2853 | hcryp->CrypOutCount -= 8; |
mbed_official | 87:085cde657901 | 2854 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 2855 | { |
mbed_official | 87:085cde657901 | 2856 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2857 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 2858 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 2859 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2860 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2861 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2862 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2863 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 2864 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2865 | } |
mbed_official | 87:085cde657901 | 2866 | } |
mbed_official | 87:085cde657901 | 2867 | |
mbed_official | 87:085cde657901 | 2868 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2869 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2870 | } |
mbed_official | 87:085cde657901 | 2871 | |
mbed_official | 87:085cde657901 | 2872 | /** |
mbed_official | 87:085cde657901 | 2873 | * @brief Initializes the CRYP peripheral in TDES CBC decryption mode. |
mbed_official | 87:085cde657901 | 2874 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2875 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2876 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2877 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2878 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2879 | */ |
mbed_official | 87:085cde657901 | 2880 | HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 2881 | { |
mbed_official | 87:085cde657901 | 2882 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2883 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2884 | |
mbed_official | 87:085cde657901 | 2885 | if(hcryp->State == HAL_CRYP_STATE_READY) |
mbed_official | 87:085cde657901 | 2886 | { |
mbed_official | 87:085cde657901 | 2887 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2888 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2889 | |
mbed_official | 87:085cde657901 | 2890 | hcryp->CrypInCount = Size; |
mbed_official | 87:085cde657901 | 2891 | hcryp->pCrypInBuffPtr = pCypherData; |
mbed_official | 87:085cde657901 | 2892 | hcryp->pCrypOutBuffPtr = pPlainData; |
mbed_official | 87:085cde657901 | 2893 | hcryp->CrypOutCount = Size; |
mbed_official | 87:085cde657901 | 2894 | |
mbed_official | 87:085cde657901 | 2895 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2896 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2897 | |
mbed_official | 87:085cde657901 | 2898 | /* Set CRYP peripheral in TDES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 2899 | CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 2900 | |
mbed_official | 87:085cde657901 | 2901 | /* Enable Interrupts */ |
mbed_official | 87:085cde657901 | 2902 | __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2903 | |
mbed_official | 87:085cde657901 | 2904 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 2905 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 2906 | |
mbed_official | 87:085cde657901 | 2907 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2908 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2909 | } |
mbed_official | 87:085cde657901 | 2910 | else if(__HAL_CRYP_GET_IT(CRYP_IT_INI)) |
mbed_official | 87:085cde657901 | 2911 | { |
mbed_official | 87:085cde657901 | 2912 | inputaddr = (uint32_t)hcryp->pCrypInBuffPtr; |
mbed_official | 87:085cde657901 | 2913 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 2914 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2915 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 2916 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 2917 | |
mbed_official | 87:085cde657901 | 2918 | hcryp->pCrypInBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2919 | hcryp->CrypInCount -= 8; |
mbed_official | 87:085cde657901 | 2920 | if(hcryp->CrypInCount == 0) |
mbed_official | 87:085cde657901 | 2921 | { |
mbed_official | 87:085cde657901 | 2922 | __HAL_CRYP_DISABLE_IT(CRYP_IT_INI); |
mbed_official | 87:085cde657901 | 2923 | /* Call the Input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 2924 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2925 | } |
mbed_official | 87:085cde657901 | 2926 | } |
mbed_official | 87:085cde657901 | 2927 | else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI)) |
mbed_official | 87:085cde657901 | 2928 | { |
mbed_official | 87:085cde657901 | 2929 | outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr; |
mbed_official | 87:085cde657901 | 2930 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 2931 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2932 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 2933 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 2934 | |
mbed_official | 87:085cde657901 | 2935 | hcryp->pCrypOutBuffPtr += 8; |
mbed_official | 87:085cde657901 | 2936 | hcryp->CrypOutCount -= 8; |
mbed_official | 87:085cde657901 | 2937 | if(hcryp->CrypOutCount == 0) |
mbed_official | 87:085cde657901 | 2938 | { |
mbed_official | 87:085cde657901 | 2939 | __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI); |
mbed_official | 87:085cde657901 | 2940 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 2941 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 2942 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2943 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2944 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2945 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 2946 | /* Call Input transfer complete callback */ |
mbed_official | 87:085cde657901 | 2947 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 2948 | } |
mbed_official | 87:085cde657901 | 2949 | } |
mbed_official | 87:085cde657901 | 2950 | |
mbed_official | 87:085cde657901 | 2951 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2952 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2953 | } |
mbed_official | 87:085cde657901 | 2954 | |
mbed_official | 87:085cde657901 | 2955 | /** |
mbed_official | 87:085cde657901 | 2956 | * @brief Initializes the CRYP peripheral in TDES ECB encryption mode using DMA. |
mbed_official | 87:085cde657901 | 2957 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 2958 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 2959 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 2960 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 2961 | * @retval HAL status |
mbed_official | 87:085cde657901 | 2962 | */ |
mbed_official | 87:085cde657901 | 2963 | HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 2964 | { |
mbed_official | 87:085cde657901 | 2965 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 2966 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 2967 | |
mbed_official | 87:085cde657901 | 2968 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 2969 | { |
mbed_official | 87:085cde657901 | 2970 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 2971 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 2972 | |
mbed_official | 87:085cde657901 | 2973 | inputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 2974 | outputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 2975 | |
mbed_official | 87:085cde657901 | 2976 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 2977 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 2978 | |
mbed_official | 87:085cde657901 | 2979 | /* Set CRYP peripheral in TDES ECB encryption mode */ |
mbed_official | 87:085cde657901 | 2980 | CRYP_SetTDESECBMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 2981 | |
mbed_official | 87:085cde657901 | 2982 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 2983 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 2984 | |
mbed_official | 87:085cde657901 | 2985 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 2986 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 2987 | |
mbed_official | 87:085cde657901 | 2988 | /* Return function status */ |
mbed_official | 87:085cde657901 | 2989 | return HAL_OK; |
mbed_official | 87:085cde657901 | 2990 | } |
mbed_official | 87:085cde657901 | 2991 | else |
mbed_official | 87:085cde657901 | 2992 | { |
mbed_official | 87:085cde657901 | 2993 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 2994 | } |
mbed_official | 87:085cde657901 | 2995 | } |
mbed_official | 87:085cde657901 | 2996 | |
mbed_official | 87:085cde657901 | 2997 | /** |
mbed_official | 87:085cde657901 | 2998 | * @brief Initializes the CRYP peripheral in TDES CBC encryption mode using DMA. |
mbed_official | 87:085cde657901 | 2999 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3000 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 3001 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 3002 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 3003 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3004 | */ |
mbed_official | 87:085cde657901 | 3005 | HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData) |
mbed_official | 87:085cde657901 | 3006 | { |
mbed_official | 87:085cde657901 | 3007 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 3008 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 3009 | |
mbed_official | 87:085cde657901 | 3010 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 3011 | { |
mbed_official | 87:085cde657901 | 3012 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 3013 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 3014 | |
mbed_official | 87:085cde657901 | 3015 | inputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 3016 | outputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 3017 | |
mbed_official | 87:085cde657901 | 3018 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 3019 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3020 | |
mbed_official | 87:085cde657901 | 3021 | /* Set CRYP peripheral in TDES CBC encryption mode */ |
mbed_official | 87:085cde657901 | 3022 | CRYP_SetTDESCBCMode(hcryp, 0); |
mbed_official | 87:085cde657901 | 3023 | |
mbed_official | 87:085cde657901 | 3024 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 3025 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 3026 | |
mbed_official | 87:085cde657901 | 3027 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 3028 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 3029 | |
mbed_official | 87:085cde657901 | 3030 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3031 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3032 | } |
mbed_official | 87:085cde657901 | 3033 | else |
mbed_official | 87:085cde657901 | 3034 | { |
mbed_official | 87:085cde657901 | 3035 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 3036 | } |
mbed_official | 87:085cde657901 | 3037 | } |
mbed_official | 87:085cde657901 | 3038 | |
mbed_official | 87:085cde657901 | 3039 | /** |
mbed_official | 87:085cde657901 | 3040 | * @brief Initializes the CRYP peripheral in TDES ECB decryption mode using DMA. |
mbed_official | 87:085cde657901 | 3041 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3042 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 3043 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 3044 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 3045 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3046 | */ |
mbed_official | 87:085cde657901 | 3047 | HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 3048 | { |
mbed_official | 87:085cde657901 | 3049 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 3050 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 3051 | |
mbed_official | 87:085cde657901 | 3052 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 3053 | { |
mbed_official | 87:085cde657901 | 3054 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 3055 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 3056 | |
mbed_official | 87:085cde657901 | 3057 | inputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 3058 | outputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 3059 | |
mbed_official | 87:085cde657901 | 3060 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 3061 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3062 | |
mbed_official | 87:085cde657901 | 3063 | /* Set CRYP peripheral in TDES ECB decryption mode */ |
mbed_official | 87:085cde657901 | 3064 | CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 3065 | |
mbed_official | 87:085cde657901 | 3066 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 3067 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 3068 | |
mbed_official | 87:085cde657901 | 3069 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 3070 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 3071 | |
mbed_official | 87:085cde657901 | 3072 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3073 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3074 | } |
mbed_official | 87:085cde657901 | 3075 | else |
mbed_official | 87:085cde657901 | 3076 | { |
mbed_official | 87:085cde657901 | 3077 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 3078 | } |
mbed_official | 87:085cde657901 | 3079 | } |
mbed_official | 87:085cde657901 | 3080 | |
mbed_official | 87:085cde657901 | 3081 | /** |
mbed_official | 87:085cde657901 | 3082 | * @brief Initializes the CRYP peripheral in TDES CBC decryption mode using DMA. |
mbed_official | 87:085cde657901 | 3083 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3084 | * @param pCypherData: Pointer to the cyphertext buffer |
mbed_official | 87:085cde657901 | 3085 | * @param Size: Length of the plaintext buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 3086 | * @param pPlainData: Pointer to the plaintext buffer |
mbed_official | 87:085cde657901 | 3087 | * @retval HAL status |
mbed_official | 87:085cde657901 | 3088 | */ |
mbed_official | 87:085cde657901 | 3089 | HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData) |
mbed_official | 87:085cde657901 | 3090 | { |
mbed_official | 87:085cde657901 | 3091 | uint32_t inputaddr; |
mbed_official | 87:085cde657901 | 3092 | uint32_t outputaddr; |
mbed_official | 87:085cde657901 | 3093 | |
mbed_official | 87:085cde657901 | 3094 | if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS)) |
mbed_official | 87:085cde657901 | 3095 | { |
mbed_official | 87:085cde657901 | 3096 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 3097 | __HAL_LOCK(hcryp); |
mbed_official | 87:085cde657901 | 3098 | |
mbed_official | 87:085cde657901 | 3099 | inputaddr = (uint32_t)pCypherData; |
mbed_official | 87:085cde657901 | 3100 | outputaddr = (uint32_t)pPlainData; |
mbed_official | 87:085cde657901 | 3101 | |
mbed_official | 87:085cde657901 | 3102 | /* Change the CRYP state */ |
mbed_official | 87:085cde657901 | 3103 | hcryp->State = HAL_CRYP_STATE_BUSY; |
mbed_official | 87:085cde657901 | 3104 | |
mbed_official | 87:085cde657901 | 3105 | /* Set CRYP peripheral in TDES CBC decryption mode */ |
mbed_official | 87:085cde657901 | 3106 | CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR); |
mbed_official | 87:085cde657901 | 3107 | |
mbed_official | 87:085cde657901 | 3108 | /* Set the input and output addresses and start DMA transfer */ |
mbed_official | 87:085cde657901 | 3109 | CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr); |
mbed_official | 87:085cde657901 | 3110 | |
mbed_official | 87:085cde657901 | 3111 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 3112 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 3113 | |
mbed_official | 87:085cde657901 | 3114 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3115 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3116 | } |
mbed_official | 87:085cde657901 | 3117 | else |
mbed_official | 87:085cde657901 | 3118 | { |
mbed_official | 87:085cde657901 | 3119 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 3120 | } |
mbed_official | 87:085cde657901 | 3121 | } |
mbed_official | 87:085cde657901 | 3122 | |
mbed_official | 87:085cde657901 | 3123 | /** |
mbed_official | 87:085cde657901 | 3124 | * @} |
mbed_official | 87:085cde657901 | 3125 | */ |
mbed_official | 87:085cde657901 | 3126 | |
mbed_official | 87:085cde657901 | 3127 | /** @defgroup CRYP_Group5 DMA callback functions |
mbed_official | 87:085cde657901 | 3128 | * @brief DMA callback functions. |
mbed_official | 87:085cde657901 | 3129 | * |
mbed_official | 87:085cde657901 | 3130 | @verbatim |
mbed_official | 87:085cde657901 | 3131 | ============================================================================== |
mbed_official | 87:085cde657901 | 3132 | ##### DMA callback functions ##### |
mbed_official | 87:085cde657901 | 3133 | ============================================================================== |
mbed_official | 87:085cde657901 | 3134 | [..] This section provides DMA callback functions: |
mbed_official | 87:085cde657901 | 3135 | (+) DMA Input data transfer complete |
mbed_official | 87:085cde657901 | 3136 | (+) DMA Output data transfer complete |
mbed_official | 87:085cde657901 | 3137 | (+) DMA error |
mbed_official | 87:085cde657901 | 3138 | |
mbed_official | 87:085cde657901 | 3139 | @endverbatim |
mbed_official | 87:085cde657901 | 3140 | * @{ |
mbed_official | 87:085cde657901 | 3141 | */ |
mbed_official | 87:085cde657901 | 3142 | |
mbed_official | 87:085cde657901 | 3143 | /** |
mbed_official | 87:085cde657901 | 3144 | * @brief Input FIFO transfer completed callbacks. |
mbed_official | 87:085cde657901 | 3145 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3146 | * @retval None |
mbed_official | 87:085cde657901 | 3147 | */ |
mbed_official | 87:085cde657901 | 3148 | __weak void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 3149 | { |
mbed_official | 87:085cde657901 | 3150 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 3151 | the HAL_CRYP_InCpltCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 3152 | */ |
mbed_official | 87:085cde657901 | 3153 | } |
mbed_official | 87:085cde657901 | 3154 | |
mbed_official | 87:085cde657901 | 3155 | /** |
mbed_official | 87:085cde657901 | 3156 | * @brief Output FIFO transfer completed callbacks. |
mbed_official | 87:085cde657901 | 3157 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3158 | * @retval None |
mbed_official | 87:085cde657901 | 3159 | */ |
mbed_official | 87:085cde657901 | 3160 | __weak void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 3161 | { |
mbed_official | 87:085cde657901 | 3162 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 3163 | the HAL_CRYP_OutCpltCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 3164 | */ |
mbed_official | 87:085cde657901 | 3165 | } |
mbed_official | 87:085cde657901 | 3166 | |
mbed_official | 87:085cde657901 | 3167 | /** |
mbed_official | 87:085cde657901 | 3168 | * @brief CRYP error callbacks. |
mbed_official | 87:085cde657901 | 3169 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3170 | * @retval None |
mbed_official | 87:085cde657901 | 3171 | */ |
mbed_official | 87:085cde657901 | 3172 | __weak void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 3173 | { |
mbed_official | 87:085cde657901 | 3174 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 3175 | the HAL_CRYP_ErrorCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 3176 | */ |
mbed_official | 87:085cde657901 | 3177 | } |
mbed_official | 87:085cde657901 | 3178 | |
mbed_official | 87:085cde657901 | 3179 | /** |
mbed_official | 87:085cde657901 | 3180 | * @} |
mbed_official | 87:085cde657901 | 3181 | */ |
mbed_official | 87:085cde657901 | 3182 | |
mbed_official | 87:085cde657901 | 3183 | /** @defgroup CRYP_Group6 CRYP IRQ handler management |
mbed_official | 87:085cde657901 | 3184 | * @brief CRYP IRQ handler. |
mbed_official | 87:085cde657901 | 3185 | * |
mbed_official | 87:085cde657901 | 3186 | @verbatim |
mbed_official | 87:085cde657901 | 3187 | ============================================================================== |
mbed_official | 87:085cde657901 | 3188 | ##### CRYP IRQ handler management ##### |
mbed_official | 87:085cde657901 | 3189 | ============================================================================== |
mbed_official | 87:085cde657901 | 3190 | [..] This section provides CRYP IRQ handler function. |
mbed_official | 87:085cde657901 | 3191 | |
mbed_official | 87:085cde657901 | 3192 | @endverbatim |
mbed_official | 87:085cde657901 | 3193 | * @{ |
mbed_official | 87:085cde657901 | 3194 | */ |
mbed_official | 87:085cde657901 | 3195 | |
mbed_official | 87:085cde657901 | 3196 | /** |
mbed_official | 87:085cde657901 | 3197 | * @brief This function handles CRYP interrupt request. |
mbed_official | 87:085cde657901 | 3198 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3199 | * @retval None |
mbed_official | 87:085cde657901 | 3200 | */ |
mbed_official | 87:085cde657901 | 3201 | void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 3202 | { |
mbed_official | 87:085cde657901 | 3203 | switch(CRYP->CR & CRYP_CR_ALGOMODE_DIRECTION) |
mbed_official | 87:085cde657901 | 3204 | { |
mbed_official | 87:085cde657901 | 3205 | case CRYP_CR_ALGOMODE_TDES_ECB_ENCRYPT: |
mbed_official | 87:085cde657901 | 3206 | HAL_CRYP_TDESECB_Encrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3207 | break; |
mbed_official | 87:085cde657901 | 3208 | |
mbed_official | 87:085cde657901 | 3209 | case CRYP_CR_ALGOMODE_TDES_ECB_DECRYPT: |
mbed_official | 87:085cde657901 | 3210 | HAL_CRYP_TDESECB_Decrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3211 | break; |
mbed_official | 87:085cde657901 | 3212 | |
mbed_official | 87:085cde657901 | 3213 | case CRYP_CR_ALGOMODE_TDES_CBC_ENCRYPT: |
mbed_official | 87:085cde657901 | 3214 | HAL_CRYP_TDESCBC_Encrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3215 | break; |
mbed_official | 87:085cde657901 | 3216 | |
mbed_official | 87:085cde657901 | 3217 | case CRYP_CR_ALGOMODE_TDES_CBC_DECRYPT: |
mbed_official | 87:085cde657901 | 3218 | HAL_CRYP_TDESCBC_Decrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3219 | break; |
mbed_official | 87:085cde657901 | 3220 | |
mbed_official | 87:085cde657901 | 3221 | case CRYP_CR_ALGOMODE_DES_ECB_ENCRYPT: |
mbed_official | 87:085cde657901 | 3222 | HAL_CRYP_DESECB_Encrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3223 | break; |
mbed_official | 87:085cde657901 | 3224 | |
mbed_official | 87:085cde657901 | 3225 | case CRYP_CR_ALGOMODE_DES_ECB_DECRYPT: |
mbed_official | 87:085cde657901 | 3226 | HAL_CRYP_DESECB_Decrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3227 | break; |
mbed_official | 87:085cde657901 | 3228 | |
mbed_official | 87:085cde657901 | 3229 | case CRYP_CR_ALGOMODE_DES_CBC_ENCRYPT: |
mbed_official | 87:085cde657901 | 3230 | HAL_CRYP_DESCBC_Encrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3231 | break; |
mbed_official | 87:085cde657901 | 3232 | |
mbed_official | 87:085cde657901 | 3233 | case CRYP_CR_ALGOMODE_DES_CBC_DECRYPT: |
mbed_official | 87:085cde657901 | 3234 | HAL_CRYP_DESCBC_Decrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3235 | break; |
mbed_official | 87:085cde657901 | 3236 | |
mbed_official | 87:085cde657901 | 3237 | case CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT: |
mbed_official | 87:085cde657901 | 3238 | HAL_CRYP_AESECB_Encrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3239 | break; |
mbed_official | 87:085cde657901 | 3240 | |
mbed_official | 87:085cde657901 | 3241 | case CRYP_CR_ALGOMODE_AES_ECB_DECRYPT: |
mbed_official | 87:085cde657901 | 3242 | HAL_CRYP_AESECB_Decrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3243 | break; |
mbed_official | 87:085cde657901 | 3244 | |
mbed_official | 87:085cde657901 | 3245 | case CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT: |
mbed_official | 87:085cde657901 | 3246 | HAL_CRYP_AESCBC_Encrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3247 | break; |
mbed_official | 87:085cde657901 | 3248 | |
mbed_official | 87:085cde657901 | 3249 | case CRYP_CR_ALGOMODE_AES_CBC_DECRYPT: |
mbed_official | 87:085cde657901 | 3250 | HAL_CRYP_AESCBC_Decrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3251 | break; |
mbed_official | 87:085cde657901 | 3252 | |
mbed_official | 87:085cde657901 | 3253 | case CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT: |
mbed_official | 87:085cde657901 | 3254 | HAL_CRYP_AESCTR_Encrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3255 | break; |
mbed_official | 87:085cde657901 | 3256 | |
mbed_official | 87:085cde657901 | 3257 | case CRYP_CR_ALGOMODE_AES_CTR_DECRYPT: |
mbed_official | 87:085cde657901 | 3258 | HAL_CRYP_AESCTR_Decrypt_IT(hcryp, NULL, 0, NULL); |
mbed_official | 87:085cde657901 | 3259 | break; |
mbed_official | 87:085cde657901 | 3260 | |
mbed_official | 87:085cde657901 | 3261 | default: |
mbed_official | 87:085cde657901 | 3262 | break; |
mbed_official | 87:085cde657901 | 3263 | } |
mbed_official | 87:085cde657901 | 3264 | } |
mbed_official | 87:085cde657901 | 3265 | |
mbed_official | 87:085cde657901 | 3266 | /** |
mbed_official | 87:085cde657901 | 3267 | * @} |
mbed_official | 87:085cde657901 | 3268 | */ |
mbed_official | 87:085cde657901 | 3269 | |
mbed_official | 87:085cde657901 | 3270 | /** @defgroup CRYP_Group7 Peripheral State functions |
mbed_official | 87:085cde657901 | 3271 | * @brief Peripheral State functions. |
mbed_official | 87:085cde657901 | 3272 | * |
mbed_official | 87:085cde657901 | 3273 | @verbatim |
mbed_official | 87:085cde657901 | 3274 | ============================================================================== |
mbed_official | 87:085cde657901 | 3275 | ##### Peripheral State functions ##### |
mbed_official | 87:085cde657901 | 3276 | ============================================================================== |
mbed_official | 87:085cde657901 | 3277 | [..] |
mbed_official | 87:085cde657901 | 3278 | This subsection permits to get in run-time the status of the peripheral. |
mbed_official | 87:085cde657901 | 3279 | |
mbed_official | 87:085cde657901 | 3280 | @endverbatim |
mbed_official | 87:085cde657901 | 3281 | * @{ |
mbed_official | 87:085cde657901 | 3282 | */ |
mbed_official | 87:085cde657901 | 3283 | |
mbed_official | 87:085cde657901 | 3284 | /** |
mbed_official | 87:085cde657901 | 3285 | * @brief Returns the CRYP state. |
mbed_official | 87:085cde657901 | 3286 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3287 | * @retval HAL state |
mbed_official | 87:085cde657901 | 3288 | */ |
mbed_official | 87:085cde657901 | 3289 | HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp) |
mbed_official | 87:085cde657901 | 3290 | { |
mbed_official | 87:085cde657901 | 3291 | return hcryp->State; |
mbed_official | 87:085cde657901 | 3292 | } |
mbed_official | 87:085cde657901 | 3293 | |
mbed_official | 87:085cde657901 | 3294 | /** |
mbed_official | 87:085cde657901 | 3295 | * @} |
mbed_official | 87:085cde657901 | 3296 | */ |
mbed_official | 87:085cde657901 | 3297 | |
mbed_official | 87:085cde657901 | 3298 | /** |
mbed_official | 87:085cde657901 | 3299 | * @brief DMA CRYP Input Data process complete callback. |
mbed_official | 87:085cde657901 | 3300 | * @param hdma: DMA handle |
mbed_official | 87:085cde657901 | 3301 | * @retval None |
mbed_official | 87:085cde657901 | 3302 | */ |
mbed_official | 87:085cde657901 | 3303 | static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 3304 | { |
mbed_official | 87:085cde657901 | 3305 | CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 87:085cde657901 | 3306 | |
mbed_official | 87:085cde657901 | 3307 | /* Disable the DMA transfer for input FIFO request by resetting the DIEN bit |
mbed_official | 87:085cde657901 | 3308 | in the DMACR register */ |
mbed_official | 87:085cde657901 | 3309 | CRYP->DMACR &= (uint32_t)(~CRYP_DMACR_DIEN); |
mbed_official | 87:085cde657901 | 3310 | |
mbed_official | 87:085cde657901 | 3311 | /* Call input data transfer complete callback */ |
mbed_official | 87:085cde657901 | 3312 | HAL_CRYP_InCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 3313 | } |
mbed_official | 87:085cde657901 | 3314 | |
mbed_official | 87:085cde657901 | 3315 | /** |
mbed_official | 87:085cde657901 | 3316 | * @brief DMA CRYP Output Data process complete callback. |
mbed_official | 87:085cde657901 | 3317 | * @param hdma: DMA handle |
mbed_official | 87:085cde657901 | 3318 | * @retval None |
mbed_official | 87:085cde657901 | 3319 | */ |
mbed_official | 87:085cde657901 | 3320 | static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 3321 | { |
mbed_official | 87:085cde657901 | 3322 | CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 87:085cde657901 | 3323 | |
mbed_official | 87:085cde657901 | 3324 | /* Disable the DMA transfer for output FIFO request by resetting the DOEN bit |
mbed_official | 87:085cde657901 | 3325 | in the DMACR register */ |
mbed_official | 87:085cde657901 | 3326 | CRYP->DMACR &= (uint32_t)(~CRYP_DMACR_DOEN); |
mbed_official | 87:085cde657901 | 3327 | |
mbed_official | 87:085cde657901 | 3328 | /* Disable CRYP */ |
mbed_official | 87:085cde657901 | 3329 | __HAL_CRYP_DISABLE(); |
mbed_official | 87:085cde657901 | 3330 | |
mbed_official | 87:085cde657901 | 3331 | /* Change the CRYP state to ready */ |
mbed_official | 87:085cde657901 | 3332 | hcryp->State = HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 3333 | |
mbed_official | 87:085cde657901 | 3334 | /* Call output data transfer complete callback */ |
mbed_official | 87:085cde657901 | 3335 | HAL_CRYP_OutCpltCallback(hcryp); |
mbed_official | 87:085cde657901 | 3336 | } |
mbed_official | 87:085cde657901 | 3337 | |
mbed_official | 87:085cde657901 | 3338 | /** |
mbed_official | 87:085cde657901 | 3339 | * @brief DMA CRYP communication error callback. |
mbed_official | 87:085cde657901 | 3340 | * @param hdma: DMA handle |
mbed_official | 87:085cde657901 | 3341 | * @retval None |
mbed_official | 87:085cde657901 | 3342 | */ |
mbed_official | 87:085cde657901 | 3343 | static void CRYP_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 3344 | { |
mbed_official | 87:085cde657901 | 3345 | CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 87:085cde657901 | 3346 | hcryp->State= HAL_CRYP_STATE_READY; |
mbed_official | 87:085cde657901 | 3347 | HAL_CRYP_ErrorCallback(hcryp); |
mbed_official | 87:085cde657901 | 3348 | } |
mbed_official | 87:085cde657901 | 3349 | |
mbed_official | 87:085cde657901 | 3350 | /** |
mbed_official | 87:085cde657901 | 3351 | * @brief Writes the Key in Key registers. |
mbed_official | 87:085cde657901 | 3352 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3353 | * @param Key: Pointer to Key buffer |
mbed_official | 87:085cde657901 | 3354 | * @param KeySize: Size of Key |
mbed_official | 87:085cde657901 | 3355 | * @retval None |
mbed_official | 87:085cde657901 | 3356 | */ |
mbed_official | 87:085cde657901 | 3357 | static void CRYP_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key, uint32_t KeySize) |
mbed_official | 87:085cde657901 | 3358 | { |
mbed_official | 87:085cde657901 | 3359 | uint32_t keyaddr = (uint32_t)Key; |
mbed_official | 87:085cde657901 | 3360 | |
mbed_official | 87:085cde657901 | 3361 | switch(KeySize) |
mbed_official | 87:085cde657901 | 3362 | { |
mbed_official | 87:085cde657901 | 3363 | case CRYP_KEYSIZE_256B: |
mbed_official | 87:085cde657901 | 3364 | /* Key Initialisation */ |
mbed_official | 87:085cde657901 | 3365 | CRYP->K0LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3366 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3367 | CRYP->K0RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3368 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3369 | CRYP->K1LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3370 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3371 | CRYP->K1RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3372 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3373 | CRYP->K2LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3374 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3375 | CRYP->K2RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3376 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3377 | CRYP->K3LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3378 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3379 | CRYP->K3RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3380 | break; |
mbed_official | 87:085cde657901 | 3381 | case CRYP_KEYSIZE_192B: |
mbed_official | 87:085cde657901 | 3382 | CRYP->K1LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3383 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3384 | CRYP->K1RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3385 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3386 | CRYP->K2LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3387 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3388 | CRYP->K2RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3389 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3390 | CRYP->K3LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3391 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3392 | CRYP->K3RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3393 | break; |
mbed_official | 87:085cde657901 | 3394 | case CRYP_KEYSIZE_128B: |
mbed_official | 87:085cde657901 | 3395 | CRYP->K2LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3396 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3397 | CRYP->K2RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3398 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3399 | CRYP->K3LR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3400 | keyaddr+=4; |
mbed_official | 87:085cde657901 | 3401 | CRYP->K3RR = __REV(*(uint32_t*)(keyaddr)); |
mbed_official | 87:085cde657901 | 3402 | break; |
mbed_official | 87:085cde657901 | 3403 | default: |
mbed_official | 87:085cde657901 | 3404 | break; |
mbed_official | 87:085cde657901 | 3405 | } |
mbed_official | 87:085cde657901 | 3406 | } |
mbed_official | 87:085cde657901 | 3407 | |
mbed_official | 87:085cde657901 | 3408 | /** |
mbed_official | 87:085cde657901 | 3409 | * @brief Writes the InitVector/InitCounter in IV registers. |
mbed_official | 87:085cde657901 | 3410 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3411 | * @param InitVector: Pointer to InitVector/InitCounter buffer |
mbed_official | 87:085cde657901 | 3412 | * @param IVSize: Size of the InitVector/InitCounter |
mbed_official | 87:085cde657901 | 3413 | * @retval None |
mbed_official | 87:085cde657901 | 3414 | */ |
mbed_official | 87:085cde657901 | 3415 | static void CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector, uint32_t IVSize) |
mbed_official | 87:085cde657901 | 3416 | { |
mbed_official | 87:085cde657901 | 3417 | uint32_t ivaddr = (uint32_t)InitVector; |
mbed_official | 87:085cde657901 | 3418 | |
mbed_official | 87:085cde657901 | 3419 | switch(IVSize) |
mbed_official | 87:085cde657901 | 3420 | { |
mbed_official | 87:085cde657901 | 3421 | case CRYP_KEYSIZE_128B: |
mbed_official | 87:085cde657901 | 3422 | CRYP->IV0LR = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 87:085cde657901 | 3423 | ivaddr+=4; |
mbed_official | 87:085cde657901 | 3424 | CRYP->IV0RR = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 87:085cde657901 | 3425 | ivaddr+=4; |
mbed_official | 87:085cde657901 | 3426 | CRYP->IV1LR = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 87:085cde657901 | 3427 | ivaddr+=4; |
mbed_official | 87:085cde657901 | 3428 | CRYP->IV1RR = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 87:085cde657901 | 3429 | break; |
mbed_official | 87:085cde657901 | 3430 | /* Whatever key size 192 or 256, Init vector is written in IV0LR and IV0RR */ |
mbed_official | 87:085cde657901 | 3431 | case CRYP_KEYSIZE_192B: |
mbed_official | 87:085cde657901 | 3432 | CRYP->IV0LR = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 87:085cde657901 | 3433 | ivaddr+=4; |
mbed_official | 87:085cde657901 | 3434 | CRYP->IV0RR = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 87:085cde657901 | 3435 | break; |
mbed_official | 87:085cde657901 | 3436 | case CRYP_KEYSIZE_256B: |
mbed_official | 87:085cde657901 | 3437 | CRYP->IV0LR = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 87:085cde657901 | 3438 | ivaddr+=4; |
mbed_official | 87:085cde657901 | 3439 | CRYP->IV0RR = __REV(*(uint32_t*)(ivaddr)); |
mbed_official | 87:085cde657901 | 3440 | break; |
mbed_official | 87:085cde657901 | 3441 | default: |
mbed_official | 87:085cde657901 | 3442 | break; |
mbed_official | 87:085cde657901 | 3443 | } |
mbed_official | 87:085cde657901 | 3444 | } |
mbed_official | 87:085cde657901 | 3445 | |
mbed_official | 87:085cde657901 | 3446 | /** |
mbed_official | 87:085cde657901 | 3447 | * @brief Process Data: Writes Input data in polling mode and read the output data |
mbed_official | 87:085cde657901 | 3448 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3449 | * @param Input: Pointer to the Input buffer |
mbed_official | 87:085cde657901 | 3450 | * @param Ilength: Length of the Input buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 3451 | * @param Output: Pointer to the returned buffer |
mbed_official | 87:085cde657901 | 3452 | * @retval None |
mbed_official | 87:085cde657901 | 3453 | */ |
mbed_official | 87:085cde657901 | 3454 | static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 3455 | { |
mbed_official | 87:085cde657901 | 3456 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 3457 | |
mbed_official | 87:085cde657901 | 3458 | uint32_t i = 0; |
mbed_official | 87:085cde657901 | 3459 | uint32_t inputaddr = (uint32_t)Input; |
mbed_official | 87:085cde657901 | 3460 | uint32_t outputaddr = (uint32_t)Output; |
mbed_official | 87:085cde657901 | 3461 | |
mbed_official | 87:085cde657901 | 3462 | for(i=0; (i < Ilength); i+=16) |
mbed_official | 87:085cde657901 | 3463 | { |
mbed_official | 87:085cde657901 | 3464 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 3465 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 3466 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 3467 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 3468 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 3469 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 3470 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 3471 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 3472 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 3473 | |
mbed_official | 87:085cde657901 | 3474 | /* Get timeout */ |
mbed_official | 87:085cde657901 | 3475 | timeout = HAL_GetTick() + Timeout; |
mbed_official | 87:085cde657901 | 3476 | |
mbed_official | 87:085cde657901 | 3477 | while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_OFNE)) |
mbed_official | 87:085cde657901 | 3478 | { |
mbed_official | 87:085cde657901 | 3479 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 3480 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 87:085cde657901 | 3481 | { |
mbed_official | 87:085cde657901 | 3482 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 3483 | { |
mbed_official | 87:085cde657901 | 3484 | /* Change state */ |
mbed_official | 87:085cde657901 | 3485 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 3486 | |
mbed_official | 87:085cde657901 | 3487 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 3488 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 3489 | |
mbed_official | 87:085cde657901 | 3490 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 3491 | } |
mbed_official | 87:085cde657901 | 3492 | } |
mbed_official | 87:085cde657901 | 3493 | } |
mbed_official | 87:085cde657901 | 3494 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 3495 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 3496 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 3497 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 3498 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 3499 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 3500 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 3501 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 3502 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 3503 | } |
mbed_official | 87:085cde657901 | 3504 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3505 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3506 | } |
mbed_official | 87:085cde657901 | 3507 | |
mbed_official | 87:085cde657901 | 3508 | /** |
mbed_official | 87:085cde657901 | 3509 | * @brief Process Data: Write Input data in polling mode. |
mbed_official | 87:085cde657901 | 3510 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3511 | * @param Input: Pointer to the Input buffer |
mbed_official | 87:085cde657901 | 3512 | * @param Ilength: Length of the Input buffer, must be a multiple of 8 |
mbed_official | 87:085cde657901 | 3513 | * @param Output: Pointer to the returned buffer |
mbed_official | 87:085cde657901 | 3514 | * @param Timeout: Specify Timeout value |
mbed_official | 87:085cde657901 | 3515 | * @retval None |
mbed_official | 87:085cde657901 | 3516 | */ |
mbed_official | 87:085cde657901 | 3517 | static HAL_StatusTypeDef CRYP_ProcessData2Words(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 3518 | { |
mbed_official | 87:085cde657901 | 3519 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 3520 | |
mbed_official | 87:085cde657901 | 3521 | uint32_t i = 0; |
mbed_official | 87:085cde657901 | 3522 | uint32_t inputaddr = (uint32_t)Input; |
mbed_official | 87:085cde657901 | 3523 | uint32_t outputaddr = (uint32_t)Output; |
mbed_official | 87:085cde657901 | 3524 | |
mbed_official | 87:085cde657901 | 3525 | for(i=0; (i < Ilength); i+=8) |
mbed_official | 87:085cde657901 | 3526 | { |
mbed_official | 87:085cde657901 | 3527 | /* Write the Input block in the IN FIFO */ |
mbed_official | 87:085cde657901 | 3528 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 3529 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 3530 | CRYP->DR = *(uint32_t*)(inputaddr); |
mbed_official | 87:085cde657901 | 3531 | inputaddr+=4; |
mbed_official | 87:085cde657901 | 3532 | |
mbed_official | 87:085cde657901 | 3533 | /* Get timeout */ |
mbed_official | 87:085cde657901 | 3534 | timeout = HAL_GetTick() + Timeout; |
mbed_official | 87:085cde657901 | 3535 | |
mbed_official | 87:085cde657901 | 3536 | while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_OFNE)) |
mbed_official | 87:085cde657901 | 3537 | { |
mbed_official | 87:085cde657901 | 3538 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 3539 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 87:085cde657901 | 3540 | { |
mbed_official | 87:085cde657901 | 3541 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 3542 | { |
mbed_official | 87:085cde657901 | 3543 | /* Change state */ |
mbed_official | 87:085cde657901 | 3544 | hcryp->State = HAL_CRYP_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 3545 | |
mbed_official | 87:085cde657901 | 3546 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 3547 | __HAL_UNLOCK(hcryp); |
mbed_official | 87:085cde657901 | 3548 | |
mbed_official | 87:085cde657901 | 3549 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 3550 | } |
mbed_official | 87:085cde657901 | 3551 | } |
mbed_official | 87:085cde657901 | 3552 | } |
mbed_official | 87:085cde657901 | 3553 | /* Read the Output block from the Output FIFO */ |
mbed_official | 87:085cde657901 | 3554 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 3555 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 3556 | *(uint32_t*)(outputaddr) = CRYP->DOUT; |
mbed_official | 87:085cde657901 | 3557 | outputaddr+=4; |
mbed_official | 87:085cde657901 | 3558 | } |
mbed_official | 87:085cde657901 | 3559 | /* Return function status */ |
mbed_official | 87:085cde657901 | 3560 | return HAL_OK; |
mbed_official | 87:085cde657901 | 3561 | } |
mbed_official | 87:085cde657901 | 3562 | |
mbed_official | 87:085cde657901 | 3563 | /** |
mbed_official | 87:085cde657901 | 3564 | * @brief Set the DMA configuration and start the DMA transfer |
mbed_official | 87:085cde657901 | 3565 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3566 | * @param inputaddr: address of the Input buffer |
mbed_official | 87:085cde657901 | 3567 | * @param Size: Size of the Input buffer, must be a multiple of 16. |
mbed_official | 87:085cde657901 | 3568 | * @param outputaddr: address of the Output buffer |
mbed_official | 87:085cde657901 | 3569 | * @retval None |
mbed_official | 87:085cde657901 | 3570 | */ |
mbed_official | 87:085cde657901 | 3571 | static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr) |
mbed_official | 87:085cde657901 | 3572 | { |
mbed_official | 87:085cde657901 | 3573 | /* Set the CRYP DMA transfer complete callback */ |
mbed_official | 87:085cde657901 | 3574 | hcryp->hdmain->XferCpltCallback = CRYP_DMAInCplt; |
mbed_official | 87:085cde657901 | 3575 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3576 | hcryp->hdmain->XferErrorCallback = CRYP_DMAError; |
mbed_official | 87:085cde657901 | 3577 | |
mbed_official | 87:085cde657901 | 3578 | /* Set the CRYP DMA transfer complete callback */ |
mbed_official | 87:085cde657901 | 3579 | hcryp->hdmaout->XferCpltCallback = CRYP_DMAOutCplt; |
mbed_official | 87:085cde657901 | 3580 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 3581 | hcryp->hdmaout->XferErrorCallback = CRYP_DMAError; |
mbed_official | 87:085cde657901 | 3582 | |
mbed_official | 87:085cde657901 | 3583 | /* Enable CRYP */ |
mbed_official | 87:085cde657901 | 3584 | __HAL_CRYP_ENABLE(); |
mbed_official | 87:085cde657901 | 3585 | |
mbed_official | 87:085cde657901 | 3586 | /* Enable the DMA In DMA Stream */ |
mbed_official | 87:085cde657901 | 3587 | HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&CRYP->DR, Size/4); |
mbed_official | 87:085cde657901 | 3588 | |
mbed_official | 87:085cde657901 | 3589 | /* Enable In DMA request */ |
mbed_official | 87:085cde657901 | 3590 | CRYP->DMACR = (CRYP_DMACR_DIEN); |
mbed_official | 87:085cde657901 | 3591 | |
mbed_official | 87:085cde657901 | 3592 | /* Enable the DMA Out DMA Stream */ |
mbed_official | 87:085cde657901 | 3593 | HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&CRYP->DOUT, outputaddr, Size/4); |
mbed_official | 87:085cde657901 | 3594 | |
mbed_official | 87:085cde657901 | 3595 | /* Enable Out DMA request */ |
mbed_official | 87:085cde657901 | 3596 | CRYP->DMACR |= CRYP_DMACR_DOEN; |
mbed_official | 87:085cde657901 | 3597 | |
mbed_official | 87:085cde657901 | 3598 | } |
mbed_official | 87:085cde657901 | 3599 | |
mbed_official | 87:085cde657901 | 3600 | /** |
mbed_official | 87:085cde657901 | 3601 | * @brief Sets the CRYP peripheral in DES ECB mode. |
mbed_official | 87:085cde657901 | 3602 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3603 | * @param Direction: Encryption or decryption |
mbed_official | 87:085cde657901 | 3604 | * @retval None |
mbed_official | 87:085cde657901 | 3605 | */ |
mbed_official | 87:085cde657901 | 3606 | static void CRYP_SetDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction) |
mbed_official | 87:085cde657901 | 3607 | { |
mbed_official | 87:085cde657901 | 3608 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 3609 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 3610 | { |
mbed_official | 87:085cde657901 | 3611 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 3612 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_DES_ECB | Direction); |
mbed_official | 87:085cde657901 | 3613 | |
mbed_official | 87:085cde657901 | 3614 | /* Set the key */ |
mbed_official | 87:085cde657901 | 3615 | CRYP->K1LR = __REV(*(uint32_t*)(hcryp->Init.pKey)); |
mbed_official | 87:085cde657901 | 3616 | CRYP->K1RR = __REV(*(uint32_t*)(hcryp->Init.pKey+4)); |
mbed_official | 87:085cde657901 | 3617 | |
mbed_official | 87:085cde657901 | 3618 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 3619 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 3620 | |
mbed_official | 87:085cde657901 | 3621 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 3622 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 3623 | } |
mbed_official | 87:085cde657901 | 3624 | } |
mbed_official | 87:085cde657901 | 3625 | |
mbed_official | 87:085cde657901 | 3626 | /** |
mbed_official | 87:085cde657901 | 3627 | * @brief Sets the CRYP peripheral in DES CBC mode. |
mbed_official | 87:085cde657901 | 3628 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3629 | * @param Direction: Encryption or decryption |
mbed_official | 87:085cde657901 | 3630 | * @retval None |
mbed_official | 87:085cde657901 | 3631 | */ |
mbed_official | 87:085cde657901 | 3632 | static void CRYP_SetDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction) |
mbed_official | 87:085cde657901 | 3633 | { |
mbed_official | 87:085cde657901 | 3634 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 3635 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 3636 | { |
mbed_official | 87:085cde657901 | 3637 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 3638 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_DES_CBC | Direction); |
mbed_official | 87:085cde657901 | 3639 | |
mbed_official | 87:085cde657901 | 3640 | /* Set the key */ |
mbed_official | 87:085cde657901 | 3641 | CRYP->K1LR = __REV(*(uint32_t*)(hcryp->Init.pKey)); |
mbed_official | 87:085cde657901 | 3642 | CRYP->K1RR = __REV(*(uint32_t*)(hcryp->Init.pKey+4)); |
mbed_official | 87:085cde657901 | 3643 | |
mbed_official | 87:085cde657901 | 3644 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 3645 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_256B); |
mbed_official | 87:085cde657901 | 3646 | |
mbed_official | 87:085cde657901 | 3647 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 3648 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 3649 | |
mbed_official | 87:085cde657901 | 3650 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 3651 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 3652 | } |
mbed_official | 87:085cde657901 | 3653 | } |
mbed_official | 87:085cde657901 | 3654 | |
mbed_official | 87:085cde657901 | 3655 | /** |
mbed_official | 87:085cde657901 | 3656 | * @brief Sets the CRYP peripheral in TDES ECB mode. |
mbed_official | 87:085cde657901 | 3657 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3658 | * @param Direction: Encryption or decryption |
mbed_official | 87:085cde657901 | 3659 | * @retval None |
mbed_official | 87:085cde657901 | 3660 | */ |
mbed_official | 87:085cde657901 | 3661 | static void CRYP_SetTDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction) |
mbed_official | 87:085cde657901 | 3662 | { |
mbed_official | 87:085cde657901 | 3663 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 3664 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 3665 | { |
mbed_official | 87:085cde657901 | 3666 | /* Set the CRYP peripheral in AES ECB mode */ |
mbed_official | 87:085cde657901 | 3667 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_TDES_ECB | Direction); |
mbed_official | 87:085cde657901 | 3668 | |
mbed_official | 87:085cde657901 | 3669 | /* Set the key */ |
mbed_official | 87:085cde657901 | 3670 | CRYP_SetKey(hcryp, hcryp->Init.pKey, CRYP_KEYSIZE_192B); |
mbed_official | 87:085cde657901 | 3671 | |
mbed_official | 87:085cde657901 | 3672 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 3673 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 3674 | |
mbed_official | 87:085cde657901 | 3675 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 3676 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 3677 | } |
mbed_official | 87:085cde657901 | 3678 | } |
mbed_official | 87:085cde657901 | 3679 | |
mbed_official | 87:085cde657901 | 3680 | /** |
mbed_official | 87:085cde657901 | 3681 | * @brief Sets the CRYP peripheral in TDES CBC mode |
mbed_official | 87:085cde657901 | 3682 | * @param hcryp: CRYP handle |
mbed_official | 87:085cde657901 | 3683 | * @param Direction: Encryption or decryption |
mbed_official | 87:085cde657901 | 3684 | * @retval None |
mbed_official | 87:085cde657901 | 3685 | */ |
mbed_official | 87:085cde657901 | 3686 | static void CRYP_SetTDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction) |
mbed_official | 87:085cde657901 | 3687 | { |
mbed_official | 87:085cde657901 | 3688 | /* Check if initialization phase has already been performed */ |
mbed_official | 87:085cde657901 | 3689 | if(hcryp->Phase == HAL_CRYP_PHASE_READY) |
mbed_official | 87:085cde657901 | 3690 | { |
mbed_official | 87:085cde657901 | 3691 | /* Set the CRYP peripheral in AES CBC mode */ |
mbed_official | 87:085cde657901 | 3692 | __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_TDES_CBC | Direction); |
mbed_official | 87:085cde657901 | 3693 | |
mbed_official | 87:085cde657901 | 3694 | /* Set the key */ |
mbed_official | 87:085cde657901 | 3695 | CRYP_SetKey(hcryp, hcryp->Init.pKey, CRYP_KEYSIZE_192B); |
mbed_official | 87:085cde657901 | 3696 | |
mbed_official | 87:085cde657901 | 3697 | /* Set the Initialization Vector */ |
mbed_official | 87:085cde657901 | 3698 | CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_256B); |
mbed_official | 87:085cde657901 | 3699 | |
mbed_official | 87:085cde657901 | 3700 | /* Flush FIFO */ |
mbed_official | 87:085cde657901 | 3701 | __HAL_CRYP_FIFO_FLUSH(); |
mbed_official | 87:085cde657901 | 3702 | |
mbed_official | 87:085cde657901 | 3703 | /* Set the phase */ |
mbed_official | 87:085cde657901 | 3704 | hcryp->Phase = HAL_CRYP_PHASE_PROCESS; |
mbed_official | 87:085cde657901 | 3705 | } |
mbed_official | 87:085cde657901 | 3706 | } |
mbed_official | 87:085cde657901 | 3707 | |
mbed_official | 87:085cde657901 | 3708 | /** |
mbed_official | 87:085cde657901 | 3709 | * @} |
mbed_official | 87:085cde657901 | 3710 | */ |
mbed_official | 87:085cde657901 | 3711 | |
mbed_official | 87:085cde657901 | 3712 | #endif /* STM32F415xx || STM32F417xx || STM32F437xx || STM32F439xx */ |
mbed_official | 87:085cde657901 | 3713 | |
mbed_official | 87:085cde657901 | 3714 | #endif /* HAL_CRYP_MODULE_ENABLED */ |
mbed_official | 87:085cde657901 | 3715 | /** |
mbed_official | 87:085cde657901 | 3716 | * @} |
mbed_official | 87:085cde657901 | 3717 | */ |
mbed_official | 87:085cde657901 | 3718 | |
mbed_official | 87:085cde657901 | 3719 | /** |
mbed_official | 87:085cde657901 | 3720 | * @} |
mbed_official | 87:085cde657901 | 3721 | */ |
mbed_official | 87:085cde657901 | 3722 | |
mbed_official | 87:085cde657901 | 3723 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |