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