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