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