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