inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NYX 0:85b3fd62ea1a 1 /**
NYX 0:85b3fd62ea1a 2 ******************************************************************************
NYX 0:85b3fd62ea1a 3 * @file stm32f4xx_hal_cryp.c
NYX 0:85b3fd62ea1a 4 * @author MCD Application Team
NYX 0:85b3fd62ea1a 5 * @version V1.7.1
NYX 0:85b3fd62ea1a 6 * @date 14-April-2017
NYX 0:85b3fd62ea1a 7 * @brief CRYP HAL module driver.
NYX 0:85b3fd62ea1a 8 * This file provides firmware functions to manage the following
NYX 0:85b3fd62ea1a 9 * functionalities of the Cryptography (CRYP) peripheral:
NYX 0:85b3fd62ea1a 10 * + Initialization and de-initialization functions
NYX 0:85b3fd62ea1a 11 * + AES processing functions
NYX 0:85b3fd62ea1a 12 * + DES processing functions
NYX 0:85b3fd62ea1a 13 * + TDES processing functions
NYX 0:85b3fd62ea1a 14 * + DMA callback functions
NYX 0:85b3fd62ea1a 15 * + CRYP IRQ handler management
NYX 0:85b3fd62ea1a 16 * + Peripheral State functions
NYX 0:85b3fd62ea1a 17 *
NYX 0:85b3fd62ea1a 18 @verbatim
NYX 0:85b3fd62ea1a 19 ==============================================================================
NYX 0:85b3fd62ea1a 20 ##### How to use this driver #####
NYX 0:85b3fd62ea1a 21 ==============================================================================
NYX 0:85b3fd62ea1a 22 [..]
NYX 0:85b3fd62ea1a 23 The CRYP HAL driver can be used as follows:
NYX 0:85b3fd62ea1a 24
NYX 0:85b3fd62ea1a 25 (#)Initialize the CRYP low level resources by implementing the HAL_CRYP_MspInit():
NYX 0:85b3fd62ea1a 26 (##) Enable the CRYP interface clock using __HAL_RCC_CRYP_CLK_ENABLE()
NYX 0:85b3fd62ea1a 27 (##) In case of using interrupts (e.g. HAL_CRYP_AESECB_Encrypt_IT())
NYX 0:85b3fd62ea1a 28 (+++) Configure the CRYP interrupt priority using HAL_NVIC_SetPriority()
NYX 0:85b3fd62ea1a 29 (+++) Enable the CRYP IRQ handler using HAL_NVIC_EnableIRQ()
NYX 0:85b3fd62ea1a 30 (+++) In CRYP IRQ handler, call HAL_CRYP_IRQHandler()
NYX 0:85b3fd62ea1a 31 (##) In case of using DMA to control data transfer (e.g. HAL_CRYP_AESECB_Encrypt_DMA())
NYX 0:85b3fd62ea1a 32 (+++) Enable the DMAx interface clock using __DMAx_CLK_ENABLE()
NYX 0:85b3fd62ea1a 33 (+++) Configure and enable two DMA streams one for managing data transfer from
NYX 0:85b3fd62ea1a 34 memory to peripheral (input stream) and another stream for managing data
NYX 0:85b3fd62ea1a 35 transfer from peripheral to memory (output stream)
NYX 0:85b3fd62ea1a 36 (+++) Associate the initialized DMA handle to the CRYP DMA handle
NYX 0:85b3fd62ea1a 37 using __HAL_LINKDMA()
NYX 0:85b3fd62ea1a 38 (+++) Configure the priority and enable the NVIC for the transfer complete
NYX 0:85b3fd62ea1a 39 interrupt on the two DMA Streams. The output stream should have higher
NYX 0:85b3fd62ea1a 40 priority than the input stream HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
NYX 0:85b3fd62ea1a 41
NYX 0:85b3fd62ea1a 42 (#)Initialize the CRYP HAL using HAL_CRYP_Init(). This function configures mainly:
NYX 0:85b3fd62ea1a 43 (##) The data type: 1-bit, 8-bit, 16-bit and 32-bit
NYX 0:85b3fd62ea1a 44 (##) The key size: 128, 192 and 256. This parameter is relevant only for AES
NYX 0:85b3fd62ea1a 45 (##) The encryption/decryption key. It's size depends on the algorithm
NYX 0:85b3fd62ea1a 46 used for encryption/decryption
NYX 0:85b3fd62ea1a 47 (##) The initialization vector (counter). It is not used ECB mode.
NYX 0:85b3fd62ea1a 48
NYX 0:85b3fd62ea1a 49 (#)Three processing (encryption/decryption) functions are available:
NYX 0:85b3fd62ea1a 50 (##) Polling mode: encryption and decryption APIs are blocking functions
NYX 0:85b3fd62ea1a 51 i.e. they process the data and wait till the processing is finished,
NYX 0:85b3fd62ea1a 52 e.g. HAL_CRYP_AESCBC_Encrypt()
NYX 0:85b3fd62ea1a 53 (##) Interrupt mode: encryption and decryption APIs are not blocking functions
NYX 0:85b3fd62ea1a 54 i.e. they process the data under interrupt,
NYX 0:85b3fd62ea1a 55 e.g. HAL_CRYP_AESCBC_Encrypt_IT()
NYX 0:85b3fd62ea1a 56 (##) DMA mode: encryption and decryption APIs are not blocking functions
NYX 0:85b3fd62ea1a 57 i.e. the data transfer is ensured by DMA,
NYX 0:85b3fd62ea1a 58 e.g. HAL_CRYP_AESCBC_Encrypt_DMA()
NYX 0:85b3fd62ea1a 59
NYX 0:85b3fd62ea1a 60 (#)When the processing function is called at first time after HAL_CRYP_Init()
NYX 0:85b3fd62ea1a 61 the CRYP peripheral is initialized and processes the buffer in input.
NYX 0:85b3fd62ea1a 62 At second call, the processing function performs an append of the already
NYX 0:85b3fd62ea1a 63 processed buffer.
NYX 0:85b3fd62ea1a 64 When a new data block is to be processed, call HAL_CRYP_Init() then the
NYX 0:85b3fd62ea1a 65 processing function.
NYX 0:85b3fd62ea1a 66
NYX 0:85b3fd62ea1a 67 (#)Call HAL_CRYP_DeInit() to deinitialize the CRYP peripheral.
NYX 0:85b3fd62ea1a 68
NYX 0:85b3fd62ea1a 69 @endverbatim
NYX 0:85b3fd62ea1a 70 ******************************************************************************
NYX 0:85b3fd62ea1a 71 * @attention
NYX 0:85b3fd62ea1a 72 *
NYX 0:85b3fd62ea1a 73 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
NYX 0:85b3fd62ea1a 74 *
NYX 0:85b3fd62ea1a 75 * Redistribution and use in source and binary forms, with or without modification,
NYX 0:85b3fd62ea1a 76 * are permitted provided that the following conditions are met:
NYX 0:85b3fd62ea1a 77 * 1. Redistributions of source code must retain the above copyright notice,
NYX 0:85b3fd62ea1a 78 * this list of conditions and the following disclaimer.
NYX 0:85b3fd62ea1a 79 * 2. Redistributions in binary form must reproduce the above copyright notice,
NYX 0:85b3fd62ea1a 80 * this list of conditions and the following disclaimer in the documentation
NYX 0:85b3fd62ea1a 81 * and/or other materials provided with the distribution.
NYX 0:85b3fd62ea1a 82 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NYX 0:85b3fd62ea1a 83 * may be used to endorse or promote products derived from this software
NYX 0:85b3fd62ea1a 84 * without specific prior written permission.
NYX 0:85b3fd62ea1a 85 *
NYX 0:85b3fd62ea1a 86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NYX 0:85b3fd62ea1a 87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NYX 0:85b3fd62ea1a 88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NYX 0:85b3fd62ea1a 89 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NYX 0:85b3fd62ea1a 90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NYX 0:85b3fd62ea1a 91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NYX 0:85b3fd62ea1a 92 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NYX 0:85b3fd62ea1a 93 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NYX 0:85b3fd62ea1a 94 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NYX 0:85b3fd62ea1a 95 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NYX 0:85b3fd62ea1a 96 *
NYX 0:85b3fd62ea1a 97 ******************************************************************************
NYX 0:85b3fd62ea1a 98 */
NYX 0:85b3fd62ea1a 99
NYX 0:85b3fd62ea1a 100 /* Includes ------------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 101 #include "stm32f4xx_hal.h"
NYX 0:85b3fd62ea1a 102
NYX 0:85b3fd62ea1a 103 /** @addtogroup STM32F4xx_HAL_Driver
NYX 0:85b3fd62ea1a 104 * @{
NYX 0:85b3fd62ea1a 105 */
NYX 0:85b3fd62ea1a 106
NYX 0:85b3fd62ea1a 107 #ifdef HAL_CRYP_MODULE_ENABLED
NYX 0:85b3fd62ea1a 108
NYX 0:85b3fd62ea1a 109 #if defined(CRYP)
NYX 0:85b3fd62ea1a 110
NYX 0:85b3fd62ea1a 111 /** @defgroup CRYP CRYP
NYX 0:85b3fd62ea1a 112 * @brief CRYP HAL module driver.
NYX 0:85b3fd62ea1a 113 * @{
NYX 0:85b3fd62ea1a 114 */
NYX 0:85b3fd62ea1a 115
NYX 0:85b3fd62ea1a 116 /* Private typedef -----------------------------------------------------------*/
NYX 0:85b3fd62ea1a 117 /* Private define ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 118 /** @addtogroup CRYP_Private_define
NYX 0:85b3fd62ea1a 119 * @{
NYX 0:85b3fd62ea1a 120 */
NYX 0:85b3fd62ea1a 121 #define CRYP_TIMEOUT_VALUE 1U
NYX 0:85b3fd62ea1a 122 /**
NYX 0:85b3fd62ea1a 123 * @}
NYX 0:85b3fd62ea1a 124 */
NYX 0:85b3fd62ea1a 125
NYX 0:85b3fd62ea1a 126 /* Private macro -------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 127 /* Private variables ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 128 /* Private function prototypes -----------------------------------------------*/
NYX 0:85b3fd62ea1a 129 /** @addtogroup CRYP_Private_Functions_prototypes
NYX 0:85b3fd62ea1a 130 * @{
NYX 0:85b3fd62ea1a 131 */
NYX 0:85b3fd62ea1a 132 static void CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector, uint32_t IVSize);
NYX 0:85b3fd62ea1a 133 static void CRYP_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key, uint32_t KeySize);
NYX 0:85b3fd62ea1a 134 static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout);
NYX 0:85b3fd62ea1a 135 static HAL_StatusTypeDef CRYP_ProcessData2Words(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout);
NYX 0:85b3fd62ea1a 136 static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 137 static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 138 static void CRYP_DMAError(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 139 static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr);
NYX 0:85b3fd62ea1a 140 static void CRYP_SetTDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction);
NYX 0:85b3fd62ea1a 141 static void CRYP_SetTDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction);
NYX 0:85b3fd62ea1a 142 static void CRYP_SetDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction);
NYX 0:85b3fd62ea1a 143 static void CRYP_SetDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction);
NYX 0:85b3fd62ea1a 144 /**
NYX 0:85b3fd62ea1a 145 * @}
NYX 0:85b3fd62ea1a 146 */
NYX 0:85b3fd62ea1a 147
NYX 0:85b3fd62ea1a 148
NYX 0:85b3fd62ea1a 149 /* Private functions ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 150
NYX 0:85b3fd62ea1a 151 /** @addtogroup CRYP_Private_Functions
NYX 0:85b3fd62ea1a 152 * @{
NYX 0:85b3fd62ea1a 153 */
NYX 0:85b3fd62ea1a 154
NYX 0:85b3fd62ea1a 155
NYX 0:85b3fd62ea1a 156 /**
NYX 0:85b3fd62ea1a 157 * @brief DMA CRYP Input Data process complete callback.
NYX 0:85b3fd62ea1a 158 * @param hdma: DMA handle
NYX 0:85b3fd62ea1a 159 * @retval None
NYX 0:85b3fd62ea1a 160 */
NYX 0:85b3fd62ea1a 161 static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 162 {
NYX 0:85b3fd62ea1a 163 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
NYX 0:85b3fd62ea1a 164
NYX 0:85b3fd62ea1a 165 /* Disable the DMA transfer for input FIFO request by resetting the DIEN bit
NYX 0:85b3fd62ea1a 166 in the DMACR register */
NYX 0:85b3fd62ea1a 167 hcryp->Instance->DMACR &= (uint32_t)(~CRYP_DMACR_DIEN);
NYX 0:85b3fd62ea1a 168
NYX 0:85b3fd62ea1a 169 /* Call input data transfer complete callback */
NYX 0:85b3fd62ea1a 170 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 171 }
NYX 0:85b3fd62ea1a 172
NYX 0:85b3fd62ea1a 173 /**
NYX 0:85b3fd62ea1a 174 * @brief DMA CRYP Output Data process complete callback.
NYX 0:85b3fd62ea1a 175 * @param hdma: DMA handle
NYX 0:85b3fd62ea1a 176 * @retval None
NYX 0:85b3fd62ea1a 177 */
NYX 0:85b3fd62ea1a 178 static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 179 {
NYX 0:85b3fd62ea1a 180 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
NYX 0:85b3fd62ea1a 181
NYX 0:85b3fd62ea1a 182 /* Disable the DMA transfer for output FIFO request by resetting the DOEN bit
NYX 0:85b3fd62ea1a 183 in the DMACR register */
NYX 0:85b3fd62ea1a 184 hcryp->Instance->DMACR &= (uint32_t)(~CRYP_DMACR_DOEN);
NYX 0:85b3fd62ea1a 185
NYX 0:85b3fd62ea1a 186 /* Disable CRYP */
NYX 0:85b3fd62ea1a 187 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 188
NYX 0:85b3fd62ea1a 189 /* Change the CRYP state to ready */
NYX 0:85b3fd62ea1a 190 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 191
NYX 0:85b3fd62ea1a 192 /* Call output data transfer complete callback */
NYX 0:85b3fd62ea1a 193 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 194 }
NYX 0:85b3fd62ea1a 195
NYX 0:85b3fd62ea1a 196 /**
NYX 0:85b3fd62ea1a 197 * @brief DMA CRYP communication error callback.
NYX 0:85b3fd62ea1a 198 * @param hdma: DMA handle
NYX 0:85b3fd62ea1a 199 * @retval None
NYX 0:85b3fd62ea1a 200 */
NYX 0:85b3fd62ea1a 201 static void CRYP_DMAError(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 202 {
NYX 0:85b3fd62ea1a 203 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
NYX 0:85b3fd62ea1a 204 hcryp->State= HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 205 HAL_CRYP_ErrorCallback(hcryp);
NYX 0:85b3fd62ea1a 206 }
NYX 0:85b3fd62ea1a 207
NYX 0:85b3fd62ea1a 208 /**
NYX 0:85b3fd62ea1a 209 * @brief Writes the Key in Key registers.
NYX 0:85b3fd62ea1a 210 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 211 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 212 * @param Key: Pointer to Key buffer
NYX 0:85b3fd62ea1a 213 * @param KeySize: Size of Key
NYX 0:85b3fd62ea1a 214 * @retval None
NYX 0:85b3fd62ea1a 215 */
NYX 0:85b3fd62ea1a 216 static void CRYP_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key, uint32_t KeySize)
NYX 0:85b3fd62ea1a 217 {
NYX 0:85b3fd62ea1a 218 uint32_t keyaddr = (uint32_t)Key;
NYX 0:85b3fd62ea1a 219
NYX 0:85b3fd62ea1a 220 switch(KeySize)
NYX 0:85b3fd62ea1a 221 {
NYX 0:85b3fd62ea1a 222 case CRYP_KEYSIZE_256B:
NYX 0:85b3fd62ea1a 223 /* Key Initialisation */
NYX 0:85b3fd62ea1a 224 hcryp->Instance->K0LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 225 keyaddr+=4U;
NYX 0:85b3fd62ea1a 226 hcryp->Instance->K0RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 227 keyaddr+=4U;
NYX 0:85b3fd62ea1a 228 hcryp->Instance->K1LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 229 keyaddr+=4U;
NYX 0:85b3fd62ea1a 230 hcryp->Instance->K1RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 231 keyaddr+=4U;
NYX 0:85b3fd62ea1a 232 hcryp->Instance->K2LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 233 keyaddr+=4U;
NYX 0:85b3fd62ea1a 234 hcryp->Instance->K2RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 235 keyaddr+=4U;
NYX 0:85b3fd62ea1a 236 hcryp->Instance->K3LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 237 keyaddr+=4U;
NYX 0:85b3fd62ea1a 238 hcryp->Instance->K3RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 239 break;
NYX 0:85b3fd62ea1a 240 case CRYP_KEYSIZE_192B:
NYX 0:85b3fd62ea1a 241 hcryp->Instance->K1LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 242 keyaddr+=4U;
NYX 0:85b3fd62ea1a 243 hcryp->Instance->K1RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 244 keyaddr+=4U;
NYX 0:85b3fd62ea1a 245 hcryp->Instance->K2LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 246 keyaddr+=4U;
NYX 0:85b3fd62ea1a 247 hcryp->Instance->K2RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 248 keyaddr+=4U;
NYX 0:85b3fd62ea1a 249 hcryp->Instance->K3LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 250 keyaddr+=4U;
NYX 0:85b3fd62ea1a 251 hcryp->Instance->K3RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 252 break;
NYX 0:85b3fd62ea1a 253 case CRYP_KEYSIZE_128B:
NYX 0:85b3fd62ea1a 254 hcryp->Instance->K2LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 255 keyaddr+=4U;
NYX 0:85b3fd62ea1a 256 hcryp->Instance->K2RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 257 keyaddr+=4U;
NYX 0:85b3fd62ea1a 258 hcryp->Instance->K3LR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 259 keyaddr+=4U;
NYX 0:85b3fd62ea1a 260 hcryp->Instance->K3RR = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 261 break;
NYX 0:85b3fd62ea1a 262 default:
NYX 0:85b3fd62ea1a 263 break;
NYX 0:85b3fd62ea1a 264 }
NYX 0:85b3fd62ea1a 265 }
NYX 0:85b3fd62ea1a 266
NYX 0:85b3fd62ea1a 267 /**
NYX 0:85b3fd62ea1a 268 * @brief Writes the InitVector/InitCounter in IV registers.
NYX 0:85b3fd62ea1a 269 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 270 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 271 * @param InitVector: Pointer to InitVector/InitCounter buffer
NYX 0:85b3fd62ea1a 272 * @param IVSize: Size of the InitVector/InitCounter
NYX 0:85b3fd62ea1a 273 * @retval None
NYX 0:85b3fd62ea1a 274 */
NYX 0:85b3fd62ea1a 275 static void CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector, uint32_t IVSize)
NYX 0:85b3fd62ea1a 276 {
NYX 0:85b3fd62ea1a 277 uint32_t ivaddr = (uint32_t)InitVector;
NYX 0:85b3fd62ea1a 278
NYX 0:85b3fd62ea1a 279 switch(IVSize)
NYX 0:85b3fd62ea1a 280 {
NYX 0:85b3fd62ea1a 281 case CRYP_KEYSIZE_128B:
NYX 0:85b3fd62ea1a 282 hcryp->Instance->IV0LR = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 283 ivaddr+=4U;
NYX 0:85b3fd62ea1a 284 hcryp->Instance->IV0RR = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 285 ivaddr+=4U;
NYX 0:85b3fd62ea1a 286 hcryp->Instance->IV1LR = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 287 ivaddr+=4U;
NYX 0:85b3fd62ea1a 288 hcryp->Instance->IV1RR = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 289 break;
NYX 0:85b3fd62ea1a 290 /* Whatever key size 192 or 256, Init vector is written in IV0LR and IV0RR */
NYX 0:85b3fd62ea1a 291 case CRYP_KEYSIZE_192B:
NYX 0:85b3fd62ea1a 292 hcryp->Instance->IV0LR = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 293 ivaddr+=4U;
NYX 0:85b3fd62ea1a 294 hcryp->Instance->IV0RR = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 295 break;
NYX 0:85b3fd62ea1a 296 case CRYP_KEYSIZE_256B:
NYX 0:85b3fd62ea1a 297 hcryp->Instance->IV0LR = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 298 ivaddr+=4U;
NYX 0:85b3fd62ea1a 299 hcryp->Instance->IV0RR = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 300 break;
NYX 0:85b3fd62ea1a 301 default:
NYX 0:85b3fd62ea1a 302 break;
NYX 0:85b3fd62ea1a 303 }
NYX 0:85b3fd62ea1a 304 }
NYX 0:85b3fd62ea1a 305
NYX 0:85b3fd62ea1a 306 /**
NYX 0:85b3fd62ea1a 307 * @brief Process Data: Writes Input data in polling mode and read the output data
NYX 0:85b3fd62ea1a 308 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 309 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 310 * @param Input: Pointer to the Input buffer
NYX 0:85b3fd62ea1a 311 * @param Ilength: Length of the Input buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 312 * @param Output: Pointer to the returned buffer
NYX 0:85b3fd62ea1a 313 * @param Timeout: Timeout value
NYX 0:85b3fd62ea1a 314 * @retval None
NYX 0:85b3fd62ea1a 315 */
NYX 0:85b3fd62ea1a 316 static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout)
NYX 0:85b3fd62ea1a 317 {
NYX 0:85b3fd62ea1a 318 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 319
NYX 0:85b3fd62ea1a 320 uint32_t i = 0U;
NYX 0:85b3fd62ea1a 321 uint32_t inputaddr = (uint32_t)Input;
NYX 0:85b3fd62ea1a 322 uint32_t outputaddr = (uint32_t)Output;
NYX 0:85b3fd62ea1a 323
NYX 0:85b3fd62ea1a 324 for(i=0U; (i < Ilength); i+=16U)
NYX 0:85b3fd62ea1a 325 {
NYX 0:85b3fd62ea1a 326 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 327 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 328 inputaddr+=4U;
NYX 0:85b3fd62ea1a 329 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 330 inputaddr+=4U;
NYX 0:85b3fd62ea1a 331 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 332 inputaddr+=4U;
NYX 0:85b3fd62ea1a 333 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 334 inputaddr+=4U;
NYX 0:85b3fd62ea1a 335
NYX 0:85b3fd62ea1a 336 /* Get tick */
NYX 0:85b3fd62ea1a 337 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 338
NYX 0:85b3fd62ea1a 339 while(HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE))
NYX 0:85b3fd62ea1a 340 {
NYX 0:85b3fd62ea1a 341 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 342 if(Timeout != HAL_MAX_DELAY)
NYX 0:85b3fd62ea1a 343 {
NYX 0:85b3fd62ea1a 344 if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
NYX 0:85b3fd62ea1a 345 {
NYX 0:85b3fd62ea1a 346 /* Change state */
NYX 0:85b3fd62ea1a 347 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
NYX 0:85b3fd62ea1a 348
NYX 0:85b3fd62ea1a 349 /* Process Unlocked */
NYX 0:85b3fd62ea1a 350 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 351
NYX 0:85b3fd62ea1a 352 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 353 }
NYX 0:85b3fd62ea1a 354 }
NYX 0:85b3fd62ea1a 355 }
NYX 0:85b3fd62ea1a 356 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 357 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 358 outputaddr+=4U;
NYX 0:85b3fd62ea1a 359 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 360 outputaddr+=4U;
NYX 0:85b3fd62ea1a 361 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 362 outputaddr+=4U;
NYX 0:85b3fd62ea1a 363 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 364 outputaddr+=4U;
NYX 0:85b3fd62ea1a 365 }
NYX 0:85b3fd62ea1a 366 /* Return function status */
NYX 0:85b3fd62ea1a 367 return HAL_OK;
NYX 0:85b3fd62ea1a 368 }
NYX 0:85b3fd62ea1a 369
NYX 0:85b3fd62ea1a 370 /**
NYX 0:85b3fd62ea1a 371 * @brief Process Data: Write Input data in polling mode.
NYX 0:85b3fd62ea1a 372 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 373 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 374 * @param Input: Pointer to the Input buffer
NYX 0:85b3fd62ea1a 375 * @param Ilength: Length of the Input buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 376 * @param Output: Pointer to the returned buffer
NYX 0:85b3fd62ea1a 377 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 378 * @retval None
NYX 0:85b3fd62ea1a 379 */
NYX 0:85b3fd62ea1a 380 static HAL_StatusTypeDef CRYP_ProcessData2Words(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout)
NYX 0:85b3fd62ea1a 381 {
NYX 0:85b3fd62ea1a 382 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 383
NYX 0:85b3fd62ea1a 384 uint32_t i = 0U;
NYX 0:85b3fd62ea1a 385 uint32_t inputaddr = (uint32_t)Input;
NYX 0:85b3fd62ea1a 386 uint32_t outputaddr = (uint32_t)Output;
NYX 0:85b3fd62ea1a 387
NYX 0:85b3fd62ea1a 388 for(i=0U; (i < Ilength); i+=8U)
NYX 0:85b3fd62ea1a 389 {
NYX 0:85b3fd62ea1a 390 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 391 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 392 inputaddr+=4U;
NYX 0:85b3fd62ea1a 393 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 394 inputaddr+=4U;
NYX 0:85b3fd62ea1a 395
NYX 0:85b3fd62ea1a 396 /* Get tick */
NYX 0:85b3fd62ea1a 397 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 398
NYX 0:85b3fd62ea1a 399 while(HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE))
NYX 0:85b3fd62ea1a 400 {
NYX 0:85b3fd62ea1a 401 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 402 if(Timeout != HAL_MAX_DELAY)
NYX 0:85b3fd62ea1a 403 {
NYX 0:85b3fd62ea1a 404 if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
NYX 0:85b3fd62ea1a 405 {
NYX 0:85b3fd62ea1a 406 /* Change state */
NYX 0:85b3fd62ea1a 407 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
NYX 0:85b3fd62ea1a 408
NYX 0:85b3fd62ea1a 409 /* Process Unlocked */
NYX 0:85b3fd62ea1a 410 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 411
NYX 0:85b3fd62ea1a 412 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 413 }
NYX 0:85b3fd62ea1a 414 }
NYX 0:85b3fd62ea1a 415 }
NYX 0:85b3fd62ea1a 416 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 417 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 418 outputaddr+=4U;
NYX 0:85b3fd62ea1a 419 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 420 outputaddr+=4U;
NYX 0:85b3fd62ea1a 421 }
NYX 0:85b3fd62ea1a 422 /* Return function status */
NYX 0:85b3fd62ea1a 423 return HAL_OK;
NYX 0:85b3fd62ea1a 424 }
NYX 0:85b3fd62ea1a 425
NYX 0:85b3fd62ea1a 426 /**
NYX 0:85b3fd62ea1a 427 * @brief Set the DMA configuration and start the DMA transfer
NYX 0:85b3fd62ea1a 428 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 429 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 430 * @param inputaddr: address of the Input buffer
NYX 0:85b3fd62ea1a 431 * @param Size: Size of the Input buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 432 * @param outputaddr: address of the Output buffer
NYX 0:85b3fd62ea1a 433 * @retval None
NYX 0:85b3fd62ea1a 434 */
NYX 0:85b3fd62ea1a 435 static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr)
NYX 0:85b3fd62ea1a 436 {
NYX 0:85b3fd62ea1a 437 /* Set the CRYP DMA transfer complete callback */
NYX 0:85b3fd62ea1a 438 hcryp->hdmain->XferCpltCallback = CRYP_DMAInCplt;
NYX 0:85b3fd62ea1a 439 /* Set the DMA error callback */
NYX 0:85b3fd62ea1a 440 hcryp->hdmain->XferErrorCallback = CRYP_DMAError;
NYX 0:85b3fd62ea1a 441
NYX 0:85b3fd62ea1a 442 /* Set the CRYP DMA transfer complete callback */
NYX 0:85b3fd62ea1a 443 hcryp->hdmaout->XferCpltCallback = CRYP_DMAOutCplt;
NYX 0:85b3fd62ea1a 444 /* Set the DMA error callback */
NYX 0:85b3fd62ea1a 445 hcryp->hdmaout->XferErrorCallback = CRYP_DMAError;
NYX 0:85b3fd62ea1a 446
NYX 0:85b3fd62ea1a 447 /* Enable CRYP */
NYX 0:85b3fd62ea1a 448 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 449
NYX 0:85b3fd62ea1a 450 /* Enable the DMA In DMA Stream */
NYX 0:85b3fd62ea1a 451 HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DR, Size/4U);
NYX 0:85b3fd62ea1a 452
NYX 0:85b3fd62ea1a 453 /* Enable In DMA request */
NYX 0:85b3fd62ea1a 454 hcryp->Instance->DMACR = (CRYP_DMACR_DIEN);
NYX 0:85b3fd62ea1a 455
NYX 0:85b3fd62ea1a 456 /* Enable the DMA Out DMA Stream */
NYX 0:85b3fd62ea1a 457 HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUT, outputaddr, Size/4U);
NYX 0:85b3fd62ea1a 458
NYX 0:85b3fd62ea1a 459 /* Enable Out DMA request */
NYX 0:85b3fd62ea1a 460 hcryp->Instance->DMACR |= CRYP_DMACR_DOEN;
NYX 0:85b3fd62ea1a 461
NYX 0:85b3fd62ea1a 462 }
NYX 0:85b3fd62ea1a 463
NYX 0:85b3fd62ea1a 464 /**
NYX 0:85b3fd62ea1a 465 * @brief Sets the CRYP peripheral in DES ECB mode.
NYX 0:85b3fd62ea1a 466 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 467 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 468 * @param Direction: Encryption or decryption
NYX 0:85b3fd62ea1a 469 * @retval None
NYX 0:85b3fd62ea1a 470 */
NYX 0:85b3fd62ea1a 471 static void CRYP_SetDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
NYX 0:85b3fd62ea1a 472 {
NYX 0:85b3fd62ea1a 473 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 474 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 475 {
NYX 0:85b3fd62ea1a 476 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 477 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_DES_ECB | Direction);
NYX 0:85b3fd62ea1a 478
NYX 0:85b3fd62ea1a 479 /* Set the key */
NYX 0:85b3fd62ea1a 480 hcryp->Instance->K1LR = __REV(*(uint32_t*)(hcryp->Init.pKey));
NYX 0:85b3fd62ea1a 481 hcryp->Instance->K1RR = __REV(*(uint32_t*)(hcryp->Init.pKey+4U));
NYX 0:85b3fd62ea1a 482
NYX 0:85b3fd62ea1a 483 /* Flush FIFO */
NYX 0:85b3fd62ea1a 484 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 485
NYX 0:85b3fd62ea1a 486 /* Set the phase */
NYX 0:85b3fd62ea1a 487 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 488 }
NYX 0:85b3fd62ea1a 489 }
NYX 0:85b3fd62ea1a 490
NYX 0:85b3fd62ea1a 491 /**
NYX 0:85b3fd62ea1a 492 * @brief Sets the CRYP peripheral in DES CBC mode.
NYX 0:85b3fd62ea1a 493 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 494 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 495 * @param Direction: Encryption or decryption
NYX 0:85b3fd62ea1a 496 * @retval None
NYX 0:85b3fd62ea1a 497 */
NYX 0:85b3fd62ea1a 498 static void CRYP_SetDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
NYX 0:85b3fd62ea1a 499 {
NYX 0:85b3fd62ea1a 500 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 501 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 502 {
NYX 0:85b3fd62ea1a 503 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 504 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_DES_CBC | Direction);
NYX 0:85b3fd62ea1a 505
NYX 0:85b3fd62ea1a 506 /* Set the key */
NYX 0:85b3fd62ea1a 507 hcryp->Instance->K1LR = __REV(*(uint32_t*)(hcryp->Init.pKey));
NYX 0:85b3fd62ea1a 508 hcryp->Instance->K1RR = __REV(*(uint32_t*)(hcryp->Init.pKey+4U));
NYX 0:85b3fd62ea1a 509
NYX 0:85b3fd62ea1a 510 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 511 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_256B);
NYX 0:85b3fd62ea1a 512
NYX 0:85b3fd62ea1a 513 /* Flush FIFO */
NYX 0:85b3fd62ea1a 514 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 515
NYX 0:85b3fd62ea1a 516 /* Set the phase */
NYX 0:85b3fd62ea1a 517 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 518 }
NYX 0:85b3fd62ea1a 519 }
NYX 0:85b3fd62ea1a 520
NYX 0:85b3fd62ea1a 521 /**
NYX 0:85b3fd62ea1a 522 * @brief Sets the CRYP peripheral in TDES ECB mode.
NYX 0:85b3fd62ea1a 523 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 524 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 525 * @param Direction: Encryption or decryption
NYX 0:85b3fd62ea1a 526 * @retval None
NYX 0:85b3fd62ea1a 527 */
NYX 0:85b3fd62ea1a 528 static void CRYP_SetTDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
NYX 0:85b3fd62ea1a 529 {
NYX 0:85b3fd62ea1a 530 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 531 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 532 {
NYX 0:85b3fd62ea1a 533 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 534 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_TDES_ECB | Direction);
NYX 0:85b3fd62ea1a 535
NYX 0:85b3fd62ea1a 536 /* Set the key */
NYX 0:85b3fd62ea1a 537 CRYP_SetKey(hcryp, hcryp->Init.pKey, CRYP_KEYSIZE_192B);
NYX 0:85b3fd62ea1a 538
NYX 0:85b3fd62ea1a 539 /* Flush FIFO */
NYX 0:85b3fd62ea1a 540 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 541
NYX 0:85b3fd62ea1a 542 /* Set the phase */
NYX 0:85b3fd62ea1a 543 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 544 }
NYX 0:85b3fd62ea1a 545 }
NYX 0:85b3fd62ea1a 546
NYX 0:85b3fd62ea1a 547 /**
NYX 0:85b3fd62ea1a 548 * @brief Sets the CRYP peripheral in TDES CBC mode
NYX 0:85b3fd62ea1a 549 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 550 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 551 * @param Direction: Encryption or decryption
NYX 0:85b3fd62ea1a 552 * @retval None
NYX 0:85b3fd62ea1a 553 */
NYX 0:85b3fd62ea1a 554 static void CRYP_SetTDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
NYX 0:85b3fd62ea1a 555 {
NYX 0:85b3fd62ea1a 556 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 557 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 558 {
NYX 0:85b3fd62ea1a 559 /* Set the CRYP peripheral in AES CBC mode */
NYX 0:85b3fd62ea1a 560 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_TDES_CBC | Direction);
NYX 0:85b3fd62ea1a 561
NYX 0:85b3fd62ea1a 562 /* Set the key */
NYX 0:85b3fd62ea1a 563 CRYP_SetKey(hcryp, hcryp->Init.pKey, CRYP_KEYSIZE_192B);
NYX 0:85b3fd62ea1a 564
NYX 0:85b3fd62ea1a 565 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 566 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_256B);
NYX 0:85b3fd62ea1a 567
NYX 0:85b3fd62ea1a 568 /* Flush FIFO */
NYX 0:85b3fd62ea1a 569 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 570
NYX 0:85b3fd62ea1a 571 /* Set the phase */
NYX 0:85b3fd62ea1a 572 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 573 }
NYX 0:85b3fd62ea1a 574 }
NYX 0:85b3fd62ea1a 575
NYX 0:85b3fd62ea1a 576 /**
NYX 0:85b3fd62ea1a 577 * @}
NYX 0:85b3fd62ea1a 578 */
NYX 0:85b3fd62ea1a 579
NYX 0:85b3fd62ea1a 580 /* Exported functions --------------------------------------------------------*/
NYX 0:85b3fd62ea1a 581 /** @addtogroup CRYP_Exported_Functions
NYX 0:85b3fd62ea1a 582 * @{
NYX 0:85b3fd62ea1a 583 */
NYX 0:85b3fd62ea1a 584
NYX 0:85b3fd62ea1a 585 /** @defgroup CRYP_Exported_Functions_Group1 Initialization and de-initialization functions
NYX 0:85b3fd62ea1a 586 * @brief Initialization and Configuration functions.
NYX 0:85b3fd62ea1a 587 *
NYX 0:85b3fd62ea1a 588 @verbatim
NYX 0:85b3fd62ea1a 589 ==============================================================================
NYX 0:85b3fd62ea1a 590 ##### Initialization and de-initialization functions #####
NYX 0:85b3fd62ea1a 591 ==============================================================================
NYX 0:85b3fd62ea1a 592 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 593 (+) Initialize the CRYP according to the specified parameters
NYX 0:85b3fd62ea1a 594 in the CRYP_InitTypeDef and creates the associated handle
NYX 0:85b3fd62ea1a 595 (+) DeInitialize the CRYP peripheral
NYX 0:85b3fd62ea1a 596 (+) Initialize the CRYP MSP
NYX 0:85b3fd62ea1a 597 (+) DeInitialize CRYP MSP
NYX 0:85b3fd62ea1a 598
NYX 0:85b3fd62ea1a 599 @endverbatim
NYX 0:85b3fd62ea1a 600 * @{
NYX 0:85b3fd62ea1a 601 */
NYX 0:85b3fd62ea1a 602
NYX 0:85b3fd62ea1a 603 /**
NYX 0:85b3fd62ea1a 604 * @brief Initializes the CRYP according to the specified
NYX 0:85b3fd62ea1a 605 * parameters in the CRYP_InitTypeDef and creates the associated handle.
NYX 0:85b3fd62ea1a 606 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 607 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 608 * @retval HAL status
NYX 0:85b3fd62ea1a 609 */
NYX 0:85b3fd62ea1a 610 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 611 {
NYX 0:85b3fd62ea1a 612 /* Check the CRYP handle allocation */
NYX 0:85b3fd62ea1a 613 if(hcryp == NULL)
NYX 0:85b3fd62ea1a 614 {
NYX 0:85b3fd62ea1a 615 return HAL_ERROR;
NYX 0:85b3fd62ea1a 616 }
NYX 0:85b3fd62ea1a 617
NYX 0:85b3fd62ea1a 618 /* Check the parameters */
NYX 0:85b3fd62ea1a 619 assert_param(IS_CRYP_KEYSIZE(hcryp->Init.KeySize));
NYX 0:85b3fd62ea1a 620 assert_param(IS_CRYP_DATATYPE(hcryp->Init.DataType));
NYX 0:85b3fd62ea1a 621
NYX 0:85b3fd62ea1a 622 if(hcryp->State == HAL_CRYP_STATE_RESET)
NYX 0:85b3fd62ea1a 623 {
NYX 0:85b3fd62ea1a 624 /* Allocate lock resource and initialize it */
NYX 0:85b3fd62ea1a 625 hcryp->Lock = HAL_UNLOCKED;
NYX 0:85b3fd62ea1a 626 /* Init the low level hardware */
NYX 0:85b3fd62ea1a 627 HAL_CRYP_MspInit(hcryp);
NYX 0:85b3fd62ea1a 628 }
NYX 0:85b3fd62ea1a 629
NYX 0:85b3fd62ea1a 630 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 631 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 632
NYX 0:85b3fd62ea1a 633 /* Set the key size and data type*/
NYX 0:85b3fd62ea1a 634 CRYP->CR = (uint32_t) (hcryp->Init.KeySize | hcryp->Init.DataType);
NYX 0:85b3fd62ea1a 635
NYX 0:85b3fd62ea1a 636 /* Reset CrypInCount and CrypOutCount */
NYX 0:85b3fd62ea1a 637 hcryp->CrypInCount = 0U;
NYX 0:85b3fd62ea1a 638 hcryp->CrypOutCount = 0U;
NYX 0:85b3fd62ea1a 639
NYX 0:85b3fd62ea1a 640 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 641 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 642
NYX 0:85b3fd62ea1a 643 /* Set the default CRYP phase */
NYX 0:85b3fd62ea1a 644 hcryp->Phase = HAL_CRYP_PHASE_READY;
NYX 0:85b3fd62ea1a 645
NYX 0:85b3fd62ea1a 646 /* Return function status */
NYX 0:85b3fd62ea1a 647 return HAL_OK;
NYX 0:85b3fd62ea1a 648 }
NYX 0:85b3fd62ea1a 649
NYX 0:85b3fd62ea1a 650 /**
NYX 0:85b3fd62ea1a 651 * @brief DeInitializes the CRYP peripheral.
NYX 0:85b3fd62ea1a 652 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 653 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 654 * @retval HAL status
NYX 0:85b3fd62ea1a 655 */
NYX 0:85b3fd62ea1a 656 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 657 {
NYX 0:85b3fd62ea1a 658 /* Check the CRYP handle allocation */
NYX 0:85b3fd62ea1a 659 if(hcryp == NULL)
NYX 0:85b3fd62ea1a 660 {
NYX 0:85b3fd62ea1a 661 return HAL_ERROR;
NYX 0:85b3fd62ea1a 662 }
NYX 0:85b3fd62ea1a 663
NYX 0:85b3fd62ea1a 664 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 665 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 666
NYX 0:85b3fd62ea1a 667 /* Set the default CRYP phase */
NYX 0:85b3fd62ea1a 668 hcryp->Phase = HAL_CRYP_PHASE_READY;
NYX 0:85b3fd62ea1a 669
NYX 0:85b3fd62ea1a 670 /* Reset CrypInCount and CrypOutCount */
NYX 0:85b3fd62ea1a 671 hcryp->CrypInCount = 0U;
NYX 0:85b3fd62ea1a 672 hcryp->CrypOutCount = 0U;
NYX 0:85b3fd62ea1a 673
NYX 0:85b3fd62ea1a 674 /* Disable the CRYP Peripheral Clock */
NYX 0:85b3fd62ea1a 675 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 676
NYX 0:85b3fd62ea1a 677 /* DeInit the low level hardware: CLOCK, NVIC.*/
NYX 0:85b3fd62ea1a 678 HAL_CRYP_MspDeInit(hcryp);
NYX 0:85b3fd62ea1a 679
NYX 0:85b3fd62ea1a 680 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 681 hcryp->State = HAL_CRYP_STATE_RESET;
NYX 0:85b3fd62ea1a 682
NYX 0:85b3fd62ea1a 683 /* Release Lock */
NYX 0:85b3fd62ea1a 684 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 685
NYX 0:85b3fd62ea1a 686 /* Return function status */
NYX 0:85b3fd62ea1a 687 return HAL_OK;
NYX 0:85b3fd62ea1a 688 }
NYX 0:85b3fd62ea1a 689
NYX 0:85b3fd62ea1a 690 /**
NYX 0:85b3fd62ea1a 691 * @brief Initializes the CRYP MSP.
NYX 0:85b3fd62ea1a 692 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 693 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 694 * @retval None
NYX 0:85b3fd62ea1a 695 */
NYX 0:85b3fd62ea1a 696 __weak void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 697 {
NYX 0:85b3fd62ea1a 698 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 699 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 700 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 701 the HAL_CRYP_MspInit could be implemented in the user file
NYX 0:85b3fd62ea1a 702 */
NYX 0:85b3fd62ea1a 703 }
NYX 0:85b3fd62ea1a 704
NYX 0:85b3fd62ea1a 705 /**
NYX 0:85b3fd62ea1a 706 * @brief DeInitializes CRYP MSP.
NYX 0:85b3fd62ea1a 707 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 708 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 709 * @retval None
NYX 0:85b3fd62ea1a 710 */
NYX 0:85b3fd62ea1a 711 __weak void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 712 {
NYX 0:85b3fd62ea1a 713 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 714 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 715 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 716 the HAL_CRYP_MspDeInit could be implemented in the user file
NYX 0:85b3fd62ea1a 717 */
NYX 0:85b3fd62ea1a 718 }
NYX 0:85b3fd62ea1a 719
NYX 0:85b3fd62ea1a 720 /**
NYX 0:85b3fd62ea1a 721 * @}
NYX 0:85b3fd62ea1a 722 */
NYX 0:85b3fd62ea1a 723
NYX 0:85b3fd62ea1a 724 /** @defgroup CRYP_Exported_Functions_Group2 AES processing functions
NYX 0:85b3fd62ea1a 725 * @brief processing functions.
NYX 0:85b3fd62ea1a 726 *
NYX 0:85b3fd62ea1a 727 @verbatim
NYX 0:85b3fd62ea1a 728 ==============================================================================
NYX 0:85b3fd62ea1a 729 ##### AES processing functions #####
NYX 0:85b3fd62ea1a 730 ==============================================================================
NYX 0:85b3fd62ea1a 731 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 732 (+) Encrypt plaintext using AES-128/192/256 using chaining modes
NYX 0:85b3fd62ea1a 733 (+) Decrypt cyphertext using AES-128/192/256 using chaining modes
NYX 0:85b3fd62ea1a 734 [..] Three processing functions are available:
NYX 0:85b3fd62ea1a 735 (+) Polling mode
NYX 0:85b3fd62ea1a 736 (+) Interrupt mode
NYX 0:85b3fd62ea1a 737 (+) DMA mode
NYX 0:85b3fd62ea1a 738
NYX 0:85b3fd62ea1a 739 @endverbatim
NYX 0:85b3fd62ea1a 740 * @{
NYX 0:85b3fd62ea1a 741 */
NYX 0:85b3fd62ea1a 742
NYX 0:85b3fd62ea1a 743 /**
NYX 0:85b3fd62ea1a 744 * @brief Initializes the CRYP peripheral in AES ECB encryption mode
NYX 0:85b3fd62ea1a 745 * then encrypt pPlainData. The cypher data are available in pCypherData
NYX 0:85b3fd62ea1a 746 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 747 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 748 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 749 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 750 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 751 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 752 * @retval HAL status
NYX 0:85b3fd62ea1a 753 */
NYX 0:85b3fd62ea1a 754 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 755 {
NYX 0:85b3fd62ea1a 756 /* Process Locked */
NYX 0:85b3fd62ea1a 757 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 758
NYX 0:85b3fd62ea1a 759 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 760 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 761
NYX 0:85b3fd62ea1a 762 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 763 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 764 {
NYX 0:85b3fd62ea1a 765 /* Set the key */
NYX 0:85b3fd62ea1a 766 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 767
NYX 0:85b3fd62ea1a 768 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 769 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB);
NYX 0:85b3fd62ea1a 770
NYX 0:85b3fd62ea1a 771 /* Flush FIFO */
NYX 0:85b3fd62ea1a 772 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 773
NYX 0:85b3fd62ea1a 774 /* Enable CRYP */
NYX 0:85b3fd62ea1a 775 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 776
NYX 0:85b3fd62ea1a 777 /* Set the phase */
NYX 0:85b3fd62ea1a 778 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 779 }
NYX 0:85b3fd62ea1a 780
NYX 0:85b3fd62ea1a 781 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 782 if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 783 {
NYX 0:85b3fd62ea1a 784 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 785 }
NYX 0:85b3fd62ea1a 786
NYX 0:85b3fd62ea1a 787 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 788 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 789
NYX 0:85b3fd62ea1a 790 /* Process Unlocked */
NYX 0:85b3fd62ea1a 791 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 792
NYX 0:85b3fd62ea1a 793 /* Return function status */
NYX 0:85b3fd62ea1a 794 return HAL_OK;
NYX 0:85b3fd62ea1a 795 }
NYX 0:85b3fd62ea1a 796
NYX 0:85b3fd62ea1a 797 /**
NYX 0:85b3fd62ea1a 798 * @brief Initializes the CRYP peripheral in AES CBC encryption mode
NYX 0:85b3fd62ea1a 799 * then encrypt pPlainData. The cypher data are available in pCypherData
NYX 0:85b3fd62ea1a 800 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 801 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 802 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 803 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 804 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 805 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 806 * @retval HAL status
NYX 0:85b3fd62ea1a 807 */
NYX 0:85b3fd62ea1a 808 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 809 {
NYX 0:85b3fd62ea1a 810 /* Process Locked */
NYX 0:85b3fd62ea1a 811 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 812
NYX 0:85b3fd62ea1a 813 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 814 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 815
NYX 0:85b3fd62ea1a 816 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 817 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 818 {
NYX 0:85b3fd62ea1a 819 /* Set the key */
NYX 0:85b3fd62ea1a 820 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 821
NYX 0:85b3fd62ea1a 822 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 823 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC);
NYX 0:85b3fd62ea1a 824
NYX 0:85b3fd62ea1a 825 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 826 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 827
NYX 0:85b3fd62ea1a 828 /* Flush FIFO */
NYX 0:85b3fd62ea1a 829 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 830
NYX 0:85b3fd62ea1a 831 /* Enable CRYP */
NYX 0:85b3fd62ea1a 832 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 833
NYX 0:85b3fd62ea1a 834 /* Set the phase */
NYX 0:85b3fd62ea1a 835 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 836 }
NYX 0:85b3fd62ea1a 837
NYX 0:85b3fd62ea1a 838 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 839 if(CRYP_ProcessData(hcryp,pPlainData, Size, pCypherData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 840 {
NYX 0:85b3fd62ea1a 841 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 842 }
NYX 0:85b3fd62ea1a 843
NYX 0:85b3fd62ea1a 844 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 845 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 846
NYX 0:85b3fd62ea1a 847 /* Process Unlocked */
NYX 0:85b3fd62ea1a 848 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 849
NYX 0:85b3fd62ea1a 850 /* Return function status */
NYX 0:85b3fd62ea1a 851 return HAL_OK;
NYX 0:85b3fd62ea1a 852 }
NYX 0:85b3fd62ea1a 853
NYX 0:85b3fd62ea1a 854 /**
NYX 0:85b3fd62ea1a 855 * @brief Initializes the CRYP peripheral in AES CTR encryption mode
NYX 0:85b3fd62ea1a 856 * then encrypt pPlainData. The cypher data are available in pCypherData
NYX 0:85b3fd62ea1a 857 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 858 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 859 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 860 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 861 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 862 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 863 * @retval HAL status
NYX 0:85b3fd62ea1a 864 */
NYX 0:85b3fd62ea1a 865 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 866 {
NYX 0:85b3fd62ea1a 867 /* Process Locked */
NYX 0:85b3fd62ea1a 868 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 869
NYX 0:85b3fd62ea1a 870 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 871 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 872
NYX 0:85b3fd62ea1a 873 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 874 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 875 {
NYX 0:85b3fd62ea1a 876 /* Set the key */
NYX 0:85b3fd62ea1a 877 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 878
NYX 0:85b3fd62ea1a 879 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 880 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR);
NYX 0:85b3fd62ea1a 881
NYX 0:85b3fd62ea1a 882 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 883 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 884
NYX 0:85b3fd62ea1a 885 /* Flush FIFO */
NYX 0:85b3fd62ea1a 886 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 887
NYX 0:85b3fd62ea1a 888 /* Enable CRYP */
NYX 0:85b3fd62ea1a 889 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 890
NYX 0:85b3fd62ea1a 891 /* Set the phase */
NYX 0:85b3fd62ea1a 892 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 893 }
NYX 0:85b3fd62ea1a 894
NYX 0:85b3fd62ea1a 895 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 896 if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 897 {
NYX 0:85b3fd62ea1a 898 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 899 }
NYX 0:85b3fd62ea1a 900
NYX 0:85b3fd62ea1a 901 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 902 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 903
NYX 0:85b3fd62ea1a 904 /* Process Unlocked */
NYX 0:85b3fd62ea1a 905 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 906
NYX 0:85b3fd62ea1a 907 /* Return function status */
NYX 0:85b3fd62ea1a 908 return HAL_OK;
NYX 0:85b3fd62ea1a 909 }
NYX 0:85b3fd62ea1a 910
NYX 0:85b3fd62ea1a 911
NYX 0:85b3fd62ea1a 912
NYX 0:85b3fd62ea1a 913 /**
NYX 0:85b3fd62ea1a 914 * @brief Initializes the CRYP peripheral in AES ECB decryption mode
NYX 0:85b3fd62ea1a 915 * then decrypted pCypherData. The cypher data are available in pPlainData
NYX 0:85b3fd62ea1a 916 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 917 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 918 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 919 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 920 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 921 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 922 * @retval HAL status
NYX 0:85b3fd62ea1a 923 */
NYX 0:85b3fd62ea1a 924 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 925 {
NYX 0:85b3fd62ea1a 926 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 927
NYX 0:85b3fd62ea1a 928 /* Process Locked */
NYX 0:85b3fd62ea1a 929 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 930
NYX 0:85b3fd62ea1a 931 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 932 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 933
NYX 0:85b3fd62ea1a 934 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 935 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 936 {
NYX 0:85b3fd62ea1a 937 /* Set the key */
NYX 0:85b3fd62ea1a 938 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 939
NYX 0:85b3fd62ea1a 940 /* Set the CRYP peripheral in AES Key mode */
NYX 0:85b3fd62ea1a 941 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 942
NYX 0:85b3fd62ea1a 943 /* Enable CRYP */
NYX 0:85b3fd62ea1a 944 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 945
NYX 0:85b3fd62ea1a 946 /* Get tick */
NYX 0:85b3fd62ea1a 947 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 948
NYX 0:85b3fd62ea1a 949 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
NYX 0:85b3fd62ea1a 950 {
NYX 0:85b3fd62ea1a 951 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 952 if(Timeout != HAL_MAX_DELAY)
NYX 0:85b3fd62ea1a 953 {
NYX 0:85b3fd62ea1a 954 if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
NYX 0:85b3fd62ea1a 955 {
NYX 0:85b3fd62ea1a 956 /* Change state */
NYX 0:85b3fd62ea1a 957 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
NYX 0:85b3fd62ea1a 958
NYX 0:85b3fd62ea1a 959 /* Process Unlocked */
NYX 0:85b3fd62ea1a 960 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 961
NYX 0:85b3fd62ea1a 962 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 963 }
NYX 0:85b3fd62ea1a 964 }
NYX 0:85b3fd62ea1a 965 }
NYX 0:85b3fd62ea1a 966
NYX 0:85b3fd62ea1a 967 /* Disable CRYP */
NYX 0:85b3fd62ea1a 968 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 969
NYX 0:85b3fd62ea1a 970 /* Reset the ALGOMODE bits*/
NYX 0:85b3fd62ea1a 971 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
NYX 0:85b3fd62ea1a 972
NYX 0:85b3fd62ea1a 973 /* Set the CRYP peripheral in AES ECB decryption mode */
NYX 0:85b3fd62ea1a 974 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 975 /* Flush FIFO */
NYX 0:85b3fd62ea1a 976 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 977
NYX 0:85b3fd62ea1a 978 /* Enable CRYP */
NYX 0:85b3fd62ea1a 979 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 980
NYX 0:85b3fd62ea1a 981 /* Set the phase */
NYX 0:85b3fd62ea1a 982 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 983 }
NYX 0:85b3fd62ea1a 984
NYX 0:85b3fd62ea1a 985 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 986 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 987 {
NYX 0:85b3fd62ea1a 988 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 989 }
NYX 0:85b3fd62ea1a 990
NYX 0:85b3fd62ea1a 991 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 992 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 993
NYX 0:85b3fd62ea1a 994 /* Process Unlocked */
NYX 0:85b3fd62ea1a 995 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 996
NYX 0:85b3fd62ea1a 997 /* Return function status */
NYX 0:85b3fd62ea1a 998 return HAL_OK;
NYX 0:85b3fd62ea1a 999 }
NYX 0:85b3fd62ea1a 1000
NYX 0:85b3fd62ea1a 1001 /**
NYX 0:85b3fd62ea1a 1002 * @brief Initializes the CRYP peripheral in AES ECB decryption mode
NYX 0:85b3fd62ea1a 1003 * then decrypted pCypherData. The cypher data are available in pPlainData
NYX 0:85b3fd62ea1a 1004 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1005 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1006 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1007 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 1008 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1009 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 1010 * @retval HAL status
NYX 0:85b3fd62ea1a 1011 */
NYX 0:85b3fd62ea1a 1012 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 1013 {
NYX 0:85b3fd62ea1a 1014 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 1015
NYX 0:85b3fd62ea1a 1016 /* Process Locked */
NYX 0:85b3fd62ea1a 1017 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1018
NYX 0:85b3fd62ea1a 1019 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1020 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1021
NYX 0:85b3fd62ea1a 1022 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1023 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1024 {
NYX 0:85b3fd62ea1a 1025 /* Set the key */
NYX 0:85b3fd62ea1a 1026 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1027
NYX 0:85b3fd62ea1a 1028 /* Set the CRYP peripheral in AES Key mode */
NYX 0:85b3fd62ea1a 1029 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 1030
NYX 0:85b3fd62ea1a 1031 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1032 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1033
NYX 0:85b3fd62ea1a 1034 /* Get tick */
NYX 0:85b3fd62ea1a 1035 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 1036
NYX 0:85b3fd62ea1a 1037 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
NYX 0:85b3fd62ea1a 1038 {
NYX 0:85b3fd62ea1a 1039 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 1040 if(Timeout != HAL_MAX_DELAY)
NYX 0:85b3fd62ea1a 1041 {
NYX 0:85b3fd62ea1a 1042 if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
NYX 0:85b3fd62ea1a 1043 {
NYX 0:85b3fd62ea1a 1044 /* Change state */
NYX 0:85b3fd62ea1a 1045 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
NYX 0:85b3fd62ea1a 1046
NYX 0:85b3fd62ea1a 1047 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1048 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1049
NYX 0:85b3fd62ea1a 1050 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 1051 }
NYX 0:85b3fd62ea1a 1052 }
NYX 0:85b3fd62ea1a 1053 }
NYX 0:85b3fd62ea1a 1054
NYX 0:85b3fd62ea1a 1055 /* Reset the ALGOMODE bits*/
NYX 0:85b3fd62ea1a 1056 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
NYX 0:85b3fd62ea1a 1057
NYX 0:85b3fd62ea1a 1058 /* Set the CRYP peripheral in AES CBC decryption mode */
NYX 0:85b3fd62ea1a 1059 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 1060
NYX 0:85b3fd62ea1a 1061 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 1062 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 1063
NYX 0:85b3fd62ea1a 1064 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1065 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1066
NYX 0:85b3fd62ea1a 1067 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1068 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1069
NYX 0:85b3fd62ea1a 1070 /* Set the phase */
NYX 0:85b3fd62ea1a 1071 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1072 }
NYX 0:85b3fd62ea1a 1073
NYX 0:85b3fd62ea1a 1074 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 1075 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 1076 {
NYX 0:85b3fd62ea1a 1077 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 1078 }
NYX 0:85b3fd62ea1a 1079
NYX 0:85b3fd62ea1a 1080 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1081 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 1082
NYX 0:85b3fd62ea1a 1083 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1084 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1085
NYX 0:85b3fd62ea1a 1086 /* Return function status */
NYX 0:85b3fd62ea1a 1087 return HAL_OK;
NYX 0:85b3fd62ea1a 1088 }
NYX 0:85b3fd62ea1a 1089
NYX 0:85b3fd62ea1a 1090 /**
NYX 0:85b3fd62ea1a 1091 * @brief Initializes the CRYP peripheral in AES CTR decryption mode
NYX 0:85b3fd62ea1a 1092 * then decrypted pCypherData. The cypher data are available in pPlainData
NYX 0:85b3fd62ea1a 1093 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1094 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1095 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1096 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 1097 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1098 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 1099 * @retval HAL status
NYX 0:85b3fd62ea1a 1100 */
NYX 0:85b3fd62ea1a 1101 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 1102 {
NYX 0:85b3fd62ea1a 1103 /* Process Locked */
NYX 0:85b3fd62ea1a 1104 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1105
NYX 0:85b3fd62ea1a 1106 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1107 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1108 {
NYX 0:85b3fd62ea1a 1109 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1110 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1111
NYX 0:85b3fd62ea1a 1112 /* Set the key */
NYX 0:85b3fd62ea1a 1113 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1114
NYX 0:85b3fd62ea1a 1115 /* Set the CRYP peripheral in AES CTR mode */
NYX 0:85b3fd62ea1a 1116 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 1117
NYX 0:85b3fd62ea1a 1118 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 1119 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 1120
NYX 0:85b3fd62ea1a 1121 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1122 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1123
NYX 0:85b3fd62ea1a 1124 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1125 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1126
NYX 0:85b3fd62ea1a 1127 /* Set the phase */
NYX 0:85b3fd62ea1a 1128 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1129 }
NYX 0:85b3fd62ea1a 1130
NYX 0:85b3fd62ea1a 1131 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 1132 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 1133 {
NYX 0:85b3fd62ea1a 1134 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 1135 }
NYX 0:85b3fd62ea1a 1136
NYX 0:85b3fd62ea1a 1137 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1138 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 1139
NYX 0:85b3fd62ea1a 1140 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1141 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1142
NYX 0:85b3fd62ea1a 1143 /* Return function status */
NYX 0:85b3fd62ea1a 1144 return HAL_OK;
NYX 0:85b3fd62ea1a 1145 }
NYX 0:85b3fd62ea1a 1146
NYX 0:85b3fd62ea1a 1147 /**
NYX 0:85b3fd62ea1a 1148 * @brief Initializes the CRYP peripheral in AES ECB encryption mode using Interrupt.
NYX 0:85b3fd62ea1a 1149 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1150 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1151 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1152 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
NYX 0:85b3fd62ea1a 1153 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1154 * @retval HAL status
NYX 0:85b3fd62ea1a 1155 */
NYX 0:85b3fd62ea1a 1156 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 1157 {
NYX 0:85b3fd62ea1a 1158 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1159 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1160
NYX 0:85b3fd62ea1a 1161 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 1162 {
NYX 0:85b3fd62ea1a 1163 /* Process Locked */
NYX 0:85b3fd62ea1a 1164 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1165
NYX 0:85b3fd62ea1a 1166 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 1167 hcryp->pCrypInBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 1168 hcryp->pCrypOutBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 1169 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 1170
NYX 0:85b3fd62ea1a 1171 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1172 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1173
NYX 0:85b3fd62ea1a 1174 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1175 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1176 {
NYX 0:85b3fd62ea1a 1177 /* Set the key */
NYX 0:85b3fd62ea1a 1178 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1179
NYX 0:85b3fd62ea1a 1180 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 1181 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB);
NYX 0:85b3fd62ea1a 1182
NYX 0:85b3fd62ea1a 1183 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1184 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1185
NYX 0:85b3fd62ea1a 1186 /* Set the phase */
NYX 0:85b3fd62ea1a 1187 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1188 }
NYX 0:85b3fd62ea1a 1189
NYX 0:85b3fd62ea1a 1190 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 1191 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1192
NYX 0:85b3fd62ea1a 1193 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1194 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1195
NYX 0:85b3fd62ea1a 1196 /* Return function status */
NYX 0:85b3fd62ea1a 1197 return HAL_OK;
NYX 0:85b3fd62ea1a 1198 }
NYX 0:85b3fd62ea1a 1199 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 1200 {
NYX 0:85b3fd62ea1a 1201 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 1202 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 1203 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1204 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1205 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1206 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1207 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1208 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1209 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1210 hcryp->pCrypInBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1211 hcryp->CrypInCount -= 16U;
NYX 0:85b3fd62ea1a 1212 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 1213 {
NYX 0:85b3fd62ea1a 1214 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 1215 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 1216 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1217 }
NYX 0:85b3fd62ea1a 1218 }
NYX 0:85b3fd62ea1a 1219 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 1220 {
NYX 0:85b3fd62ea1a 1221 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 1222 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 1223 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1224 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1225 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1226 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1227 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1228 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1229 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1230 hcryp->pCrypOutBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1231 hcryp->CrypOutCount -= 16U;
NYX 0:85b3fd62ea1a 1232 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 1233 {
NYX 0:85b3fd62ea1a 1234 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1235 /* Process Locked */
NYX 0:85b3fd62ea1a 1236 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1237 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1238 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 1239 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 1240 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1241 }
NYX 0:85b3fd62ea1a 1242 }
NYX 0:85b3fd62ea1a 1243
NYX 0:85b3fd62ea1a 1244 /* Return function status */
NYX 0:85b3fd62ea1a 1245 return HAL_OK;
NYX 0:85b3fd62ea1a 1246 }
NYX 0:85b3fd62ea1a 1247
NYX 0:85b3fd62ea1a 1248 /**
NYX 0:85b3fd62ea1a 1249 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using Interrupt.
NYX 0:85b3fd62ea1a 1250 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1251 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1252 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1253 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
NYX 0:85b3fd62ea1a 1254 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1255 * @retval HAL status
NYX 0:85b3fd62ea1a 1256 */
NYX 0:85b3fd62ea1a 1257 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 1258 {
NYX 0:85b3fd62ea1a 1259 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1260 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1261
NYX 0:85b3fd62ea1a 1262 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 1263 {
NYX 0:85b3fd62ea1a 1264 /* Process Locked */
NYX 0:85b3fd62ea1a 1265 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1266
NYX 0:85b3fd62ea1a 1267 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 1268 hcryp->pCrypInBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 1269 hcryp->pCrypOutBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 1270 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 1271
NYX 0:85b3fd62ea1a 1272 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1273 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1274
NYX 0:85b3fd62ea1a 1275 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1276 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1277 {
NYX 0:85b3fd62ea1a 1278 /* Set the key */
NYX 0:85b3fd62ea1a 1279 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1280
NYX 0:85b3fd62ea1a 1281 /* Set the CRYP peripheral in AES CBC mode */
NYX 0:85b3fd62ea1a 1282 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC);
NYX 0:85b3fd62ea1a 1283
NYX 0:85b3fd62ea1a 1284 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 1285 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 1286
NYX 0:85b3fd62ea1a 1287 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1288 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1289
NYX 0:85b3fd62ea1a 1290 /* Set the phase */
NYX 0:85b3fd62ea1a 1291 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1292 }
NYX 0:85b3fd62ea1a 1293 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 1294 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1295
NYX 0:85b3fd62ea1a 1296 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1297 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1298
NYX 0:85b3fd62ea1a 1299 /* Return function status */
NYX 0:85b3fd62ea1a 1300 return HAL_OK;
NYX 0:85b3fd62ea1a 1301 }
NYX 0:85b3fd62ea1a 1302 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 1303 {
NYX 0:85b3fd62ea1a 1304 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 1305 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 1306 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1307 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1308 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1309 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1310 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1311 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1312 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1313 hcryp->pCrypInBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1314 hcryp->CrypInCount -= 16U;
NYX 0:85b3fd62ea1a 1315 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 1316 {
NYX 0:85b3fd62ea1a 1317 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 1318 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 1319 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1320 }
NYX 0:85b3fd62ea1a 1321 }
NYX 0:85b3fd62ea1a 1322 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 1323 {
NYX 0:85b3fd62ea1a 1324 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 1325 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 1326 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1327 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1328 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1329 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1330 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1331 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1332 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1333 hcryp->pCrypOutBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1334 hcryp->CrypOutCount -= 16U;
NYX 0:85b3fd62ea1a 1335 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 1336 {
NYX 0:85b3fd62ea1a 1337 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1338 /* Process Locked */
NYX 0:85b3fd62ea1a 1339 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1340 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1341 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 1342 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 1343 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1344 }
NYX 0:85b3fd62ea1a 1345 }
NYX 0:85b3fd62ea1a 1346
NYX 0:85b3fd62ea1a 1347 /* Return function status */
NYX 0:85b3fd62ea1a 1348 return HAL_OK;
NYX 0:85b3fd62ea1a 1349 }
NYX 0:85b3fd62ea1a 1350
NYX 0:85b3fd62ea1a 1351 /**
NYX 0:85b3fd62ea1a 1352 * @brief Initializes the CRYP peripheral in AES CTR encryption mode using Interrupt.
NYX 0:85b3fd62ea1a 1353 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1354 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1355 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1356 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
NYX 0:85b3fd62ea1a 1357 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1358 * @retval HAL status
NYX 0:85b3fd62ea1a 1359 */
NYX 0:85b3fd62ea1a 1360 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 1361 {
NYX 0:85b3fd62ea1a 1362 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1363 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1364
NYX 0:85b3fd62ea1a 1365 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 1366 {
NYX 0:85b3fd62ea1a 1367 /* Process Locked */
NYX 0:85b3fd62ea1a 1368 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1369
NYX 0:85b3fd62ea1a 1370 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 1371 hcryp->pCrypInBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 1372 hcryp->pCrypOutBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 1373 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 1374
NYX 0:85b3fd62ea1a 1375 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1376 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1377
NYX 0:85b3fd62ea1a 1378 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1379 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1380 {
NYX 0:85b3fd62ea1a 1381 /* Set the key */
NYX 0:85b3fd62ea1a 1382 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1383
NYX 0:85b3fd62ea1a 1384 /* Set the CRYP peripheral in AES CTR mode */
NYX 0:85b3fd62ea1a 1385 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR);
NYX 0:85b3fd62ea1a 1386
NYX 0:85b3fd62ea1a 1387 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 1388 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 1389
NYX 0:85b3fd62ea1a 1390 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1391 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1392
NYX 0:85b3fd62ea1a 1393 /* Set the phase */
NYX 0:85b3fd62ea1a 1394 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1395 }
NYX 0:85b3fd62ea1a 1396 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 1397 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1398
NYX 0:85b3fd62ea1a 1399 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1400 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1401
NYX 0:85b3fd62ea1a 1402 /* Return function status */
NYX 0:85b3fd62ea1a 1403 return HAL_OK;
NYX 0:85b3fd62ea1a 1404 }
NYX 0:85b3fd62ea1a 1405 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 1406 {
NYX 0:85b3fd62ea1a 1407 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 1408 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 1409 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1410 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1411 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1412 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1413 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1414 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1415 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1416 hcryp->pCrypInBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1417 hcryp->CrypInCount -= 16U;
NYX 0:85b3fd62ea1a 1418 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 1419 {
NYX 0:85b3fd62ea1a 1420 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 1421 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 1422 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1423 }
NYX 0:85b3fd62ea1a 1424 }
NYX 0:85b3fd62ea1a 1425 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 1426 {
NYX 0:85b3fd62ea1a 1427 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 1428 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 1429 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1430 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1431 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1432 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1433 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1434 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1435 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1436 hcryp->pCrypOutBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1437 hcryp->CrypOutCount -= 16U;
NYX 0:85b3fd62ea1a 1438 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 1439 {
NYX 0:85b3fd62ea1a 1440 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1441 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1442 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1443 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1444 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 1445 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 1446 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1447 }
NYX 0:85b3fd62ea1a 1448 }
NYX 0:85b3fd62ea1a 1449
NYX 0:85b3fd62ea1a 1450 /* Return function status */
NYX 0:85b3fd62ea1a 1451 return HAL_OK;
NYX 0:85b3fd62ea1a 1452 }
NYX 0:85b3fd62ea1a 1453
NYX 0:85b3fd62ea1a 1454
NYX 0:85b3fd62ea1a 1455 /**
NYX 0:85b3fd62ea1a 1456 * @brief Initializes the CRYP peripheral in AES ECB decryption mode using Interrupt.
NYX 0:85b3fd62ea1a 1457 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1458 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1459 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1460 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 1461 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1462 * @retval HAL status
NYX 0:85b3fd62ea1a 1463 */
NYX 0:85b3fd62ea1a 1464 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 1465 {
NYX 0:85b3fd62ea1a 1466 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 1467
NYX 0:85b3fd62ea1a 1468 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1469 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1470
NYX 0:85b3fd62ea1a 1471 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 1472 {
NYX 0:85b3fd62ea1a 1473 /* Process Locked */
NYX 0:85b3fd62ea1a 1474 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1475
NYX 0:85b3fd62ea1a 1476 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 1477 hcryp->pCrypInBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 1478 hcryp->pCrypOutBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 1479 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 1480
NYX 0:85b3fd62ea1a 1481 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1482 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1483
NYX 0:85b3fd62ea1a 1484 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1485 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1486 {
NYX 0:85b3fd62ea1a 1487 /* Set the key */
NYX 0:85b3fd62ea1a 1488 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1489
NYX 0:85b3fd62ea1a 1490 /* Set the CRYP peripheral in AES Key mode */
NYX 0:85b3fd62ea1a 1491 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 1492 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1493 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1494
NYX 0:85b3fd62ea1a 1495 /* Get tick */
NYX 0:85b3fd62ea1a 1496 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 1497
NYX 0:85b3fd62ea1a 1498 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
NYX 0:85b3fd62ea1a 1499 {
NYX 0:85b3fd62ea1a 1500 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 1501 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
NYX 0:85b3fd62ea1a 1502 {
NYX 0:85b3fd62ea1a 1503 /* Change state */
NYX 0:85b3fd62ea1a 1504 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
NYX 0:85b3fd62ea1a 1505
NYX 0:85b3fd62ea1a 1506 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1507 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1508
NYX 0:85b3fd62ea1a 1509 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 1510 }
NYX 0:85b3fd62ea1a 1511 }
NYX 0:85b3fd62ea1a 1512
NYX 0:85b3fd62ea1a 1513 /* Reset the ALGOMODE bits*/
NYX 0:85b3fd62ea1a 1514 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
NYX 0:85b3fd62ea1a 1515
NYX 0:85b3fd62ea1a 1516 /* Set the CRYP peripheral in AES ECB decryption mode */
NYX 0:85b3fd62ea1a 1517 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 1518
NYX 0:85b3fd62ea1a 1519 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1520 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1521
NYX 0:85b3fd62ea1a 1522 /* Set the phase */
NYX 0:85b3fd62ea1a 1523 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1524 }
NYX 0:85b3fd62ea1a 1525
NYX 0:85b3fd62ea1a 1526 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 1527 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1528
NYX 0:85b3fd62ea1a 1529 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1530 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1531
NYX 0:85b3fd62ea1a 1532 /* Return function status */
NYX 0:85b3fd62ea1a 1533 return HAL_OK;
NYX 0:85b3fd62ea1a 1534 }
NYX 0:85b3fd62ea1a 1535 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 1536 {
NYX 0:85b3fd62ea1a 1537 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 1538 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 1539 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1540 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1541 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1542 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1543 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1544 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1545 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1546 hcryp->pCrypInBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1547 hcryp->CrypInCount -= 16U;
NYX 0:85b3fd62ea1a 1548 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 1549 {
NYX 0:85b3fd62ea1a 1550 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 1551 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 1552 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1553 }
NYX 0:85b3fd62ea1a 1554 }
NYX 0:85b3fd62ea1a 1555 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 1556 {
NYX 0:85b3fd62ea1a 1557 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 1558 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 1559 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1560 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1561 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1562 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1563 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1564 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1565 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1566 hcryp->pCrypOutBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1567 hcryp->CrypOutCount -= 16U;
NYX 0:85b3fd62ea1a 1568 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 1569 {
NYX 0:85b3fd62ea1a 1570 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1571 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1572 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1573 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1574 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 1575 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 1576 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1577 }
NYX 0:85b3fd62ea1a 1578 }
NYX 0:85b3fd62ea1a 1579
NYX 0:85b3fd62ea1a 1580 /* Return function status */
NYX 0:85b3fd62ea1a 1581 return HAL_OK;
NYX 0:85b3fd62ea1a 1582 }
NYX 0:85b3fd62ea1a 1583
NYX 0:85b3fd62ea1a 1584 /**
NYX 0:85b3fd62ea1a 1585 * @brief Initializes the CRYP peripheral in AES CBC decryption mode using IT.
NYX 0:85b3fd62ea1a 1586 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1587 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1588 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1589 * @param Size: Length of the plaintext buffer, must be a multiple of 16
NYX 0:85b3fd62ea1a 1590 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1591 * @retval HAL status
NYX 0:85b3fd62ea1a 1592 */
NYX 0:85b3fd62ea1a 1593 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 1594 {
NYX 0:85b3fd62ea1a 1595
NYX 0:85b3fd62ea1a 1596 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 1597 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1598 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1599
NYX 0:85b3fd62ea1a 1600 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 1601 {
NYX 0:85b3fd62ea1a 1602 /* Process Locked */
NYX 0:85b3fd62ea1a 1603 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1604
NYX 0:85b3fd62ea1a 1605 /* Get the buffer addresses and sizes */
NYX 0:85b3fd62ea1a 1606 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 1607 hcryp->pCrypInBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 1608 hcryp->pCrypOutBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 1609 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 1610
NYX 0:85b3fd62ea1a 1611 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1612 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1613
NYX 0:85b3fd62ea1a 1614 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1615 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1616 {
NYX 0:85b3fd62ea1a 1617 /* Set the key */
NYX 0:85b3fd62ea1a 1618 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1619
NYX 0:85b3fd62ea1a 1620 /* Set the CRYP peripheral in AES Key mode */
NYX 0:85b3fd62ea1a 1621 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 1622
NYX 0:85b3fd62ea1a 1623 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1624 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1625
NYX 0:85b3fd62ea1a 1626 /* Get tick */
NYX 0:85b3fd62ea1a 1627 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 1628
NYX 0:85b3fd62ea1a 1629 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
NYX 0:85b3fd62ea1a 1630 {
NYX 0:85b3fd62ea1a 1631 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 1632 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
NYX 0:85b3fd62ea1a 1633 {
NYX 0:85b3fd62ea1a 1634 /* Change state */
NYX 0:85b3fd62ea1a 1635 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
NYX 0:85b3fd62ea1a 1636
NYX 0:85b3fd62ea1a 1637 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1638 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1639
NYX 0:85b3fd62ea1a 1640 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 1641 }
NYX 0:85b3fd62ea1a 1642 }
NYX 0:85b3fd62ea1a 1643
NYX 0:85b3fd62ea1a 1644 /* Reset the ALGOMODE bits*/
NYX 0:85b3fd62ea1a 1645 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
NYX 0:85b3fd62ea1a 1646
NYX 0:85b3fd62ea1a 1647 /* Set the CRYP peripheral in AES CBC decryption mode */
NYX 0:85b3fd62ea1a 1648 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 1649
NYX 0:85b3fd62ea1a 1650 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 1651 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 1652
NYX 0:85b3fd62ea1a 1653 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1654 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1655
NYX 0:85b3fd62ea1a 1656 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1657 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1658
NYX 0:85b3fd62ea1a 1659 /* Set the phase */
NYX 0:85b3fd62ea1a 1660 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1661 }
NYX 0:85b3fd62ea1a 1662
NYX 0:85b3fd62ea1a 1663 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 1664 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1665
NYX 0:85b3fd62ea1a 1666 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1667 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1668
NYX 0:85b3fd62ea1a 1669 /* Return function status */
NYX 0:85b3fd62ea1a 1670 return HAL_OK;
NYX 0:85b3fd62ea1a 1671 }
NYX 0:85b3fd62ea1a 1672 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 1673 {
NYX 0:85b3fd62ea1a 1674 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 1675 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 1676 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1677 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1678 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1679 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1680 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1681 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1682 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1683 hcryp->pCrypInBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1684 hcryp->CrypInCount -= 16U;
NYX 0:85b3fd62ea1a 1685 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 1686 {
NYX 0:85b3fd62ea1a 1687 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 1688 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 1689 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1690 }
NYX 0:85b3fd62ea1a 1691 }
NYX 0:85b3fd62ea1a 1692 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 1693 {
NYX 0:85b3fd62ea1a 1694 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 1695 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 1696 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1697 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1698 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1699 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1700 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1701 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1702 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1703 hcryp->pCrypOutBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1704 hcryp->CrypOutCount -= 16U;
NYX 0:85b3fd62ea1a 1705 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 1706 {
NYX 0:85b3fd62ea1a 1707 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1708 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1709 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1710 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1711 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 1712 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 1713 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1714 }
NYX 0:85b3fd62ea1a 1715 }
NYX 0:85b3fd62ea1a 1716
NYX 0:85b3fd62ea1a 1717 /* Return function status */
NYX 0:85b3fd62ea1a 1718 return HAL_OK;
NYX 0:85b3fd62ea1a 1719 }
NYX 0:85b3fd62ea1a 1720
NYX 0:85b3fd62ea1a 1721 /**
NYX 0:85b3fd62ea1a 1722 * @brief Initializes the CRYP peripheral in AES CTR decryption mode using Interrupt.
NYX 0:85b3fd62ea1a 1723 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1724 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1725 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1726 * @param Size: Length of the plaintext buffer, must be a multiple of 16
NYX 0:85b3fd62ea1a 1727 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1728 * @retval HAL status
NYX 0:85b3fd62ea1a 1729 */
NYX 0:85b3fd62ea1a 1730 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 1731 {
NYX 0:85b3fd62ea1a 1732 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1733 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1734
NYX 0:85b3fd62ea1a 1735 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 1736 {
NYX 0:85b3fd62ea1a 1737 /* Process Locked */
NYX 0:85b3fd62ea1a 1738 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1739
NYX 0:85b3fd62ea1a 1740 /* Get the buffer addresses and sizes */
NYX 0:85b3fd62ea1a 1741 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 1742 hcryp->pCrypInBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 1743 hcryp->pCrypOutBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 1744 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 1745
NYX 0:85b3fd62ea1a 1746 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1747 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1748
NYX 0:85b3fd62ea1a 1749 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1750 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1751 {
NYX 0:85b3fd62ea1a 1752 /* Set the key */
NYX 0:85b3fd62ea1a 1753 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1754
NYX 0:85b3fd62ea1a 1755 /* Set the CRYP peripheral in AES CTR mode */
NYX 0:85b3fd62ea1a 1756 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 1757
NYX 0:85b3fd62ea1a 1758 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 1759 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 1760
NYX 0:85b3fd62ea1a 1761 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1762 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1763
NYX 0:85b3fd62ea1a 1764 /* Set the phase */
NYX 0:85b3fd62ea1a 1765 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1766 }
NYX 0:85b3fd62ea1a 1767
NYX 0:85b3fd62ea1a 1768 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 1769 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1770
NYX 0:85b3fd62ea1a 1771 /* Enable CRYP */
NYX 0:85b3fd62ea1a 1772 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 1773
NYX 0:85b3fd62ea1a 1774 /* Return function status */
NYX 0:85b3fd62ea1a 1775 return HAL_OK;
NYX 0:85b3fd62ea1a 1776 }
NYX 0:85b3fd62ea1a 1777 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 1778 {
NYX 0:85b3fd62ea1a 1779 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 1780 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 1781 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1782 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1783 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1784 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1785 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1786 inputaddr+=4U;
NYX 0:85b3fd62ea1a 1787 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 1788 hcryp->pCrypInBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1789 hcryp->CrypInCount -= 16U;
NYX 0:85b3fd62ea1a 1790 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 1791 {
NYX 0:85b3fd62ea1a 1792 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 1793 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 1794 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1795 }
NYX 0:85b3fd62ea1a 1796 }
NYX 0:85b3fd62ea1a 1797 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 1798 {
NYX 0:85b3fd62ea1a 1799 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 1800 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 1801 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1802 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1803 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1804 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1805 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1806 outputaddr+=4U;
NYX 0:85b3fd62ea1a 1807 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 1808 hcryp->pCrypOutBuffPtr += 16U;
NYX 0:85b3fd62ea1a 1809 hcryp->CrypOutCount -= 16U;
NYX 0:85b3fd62ea1a 1810 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 1811 {
NYX 0:85b3fd62ea1a 1812 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 1813 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1814 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1815 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1816 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 1817 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 1818 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 1819 }
NYX 0:85b3fd62ea1a 1820 }
NYX 0:85b3fd62ea1a 1821
NYX 0:85b3fd62ea1a 1822 /* Return function status */
NYX 0:85b3fd62ea1a 1823 return HAL_OK;
NYX 0:85b3fd62ea1a 1824 }
NYX 0:85b3fd62ea1a 1825
NYX 0:85b3fd62ea1a 1826 /**
NYX 0:85b3fd62ea1a 1827 * @brief Initializes the CRYP peripheral in AES ECB encryption mode using DMA.
NYX 0:85b3fd62ea1a 1828 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1829 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1830 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1831 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
NYX 0:85b3fd62ea1a 1832 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1833 * @retval HAL status
NYX 0:85b3fd62ea1a 1834 */
NYX 0:85b3fd62ea1a 1835 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 1836 {
NYX 0:85b3fd62ea1a 1837 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1838 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1839
NYX 0:85b3fd62ea1a 1840 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 1841 {
NYX 0:85b3fd62ea1a 1842 /* Process Locked */
NYX 0:85b3fd62ea1a 1843 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1844
NYX 0:85b3fd62ea1a 1845 inputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 1846 outputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 1847
NYX 0:85b3fd62ea1a 1848 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1849 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1850
NYX 0:85b3fd62ea1a 1851 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1852 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1853 {
NYX 0:85b3fd62ea1a 1854 /* Set the key */
NYX 0:85b3fd62ea1a 1855 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1856
NYX 0:85b3fd62ea1a 1857 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 1858 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB);
NYX 0:85b3fd62ea1a 1859
NYX 0:85b3fd62ea1a 1860 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1861 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1862
NYX 0:85b3fd62ea1a 1863 /* Set the phase */
NYX 0:85b3fd62ea1a 1864 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1865 }
NYX 0:85b3fd62ea1a 1866 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 1867 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 1868
NYX 0:85b3fd62ea1a 1869 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1870 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1871
NYX 0:85b3fd62ea1a 1872 /* Return function status */
NYX 0:85b3fd62ea1a 1873 return HAL_OK;
NYX 0:85b3fd62ea1a 1874 }
NYX 0:85b3fd62ea1a 1875 else
NYX 0:85b3fd62ea1a 1876 {
NYX 0:85b3fd62ea1a 1877 return HAL_ERROR;
NYX 0:85b3fd62ea1a 1878 }
NYX 0:85b3fd62ea1a 1879 }
NYX 0:85b3fd62ea1a 1880
NYX 0:85b3fd62ea1a 1881 /**
NYX 0:85b3fd62ea1a 1882 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA.
NYX 0:85b3fd62ea1a 1883 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1884 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1885 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1886 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 1887 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1888 * @retval HAL status
NYX 0:85b3fd62ea1a 1889 */
NYX 0:85b3fd62ea1a 1890 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 1891 {
NYX 0:85b3fd62ea1a 1892 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1893 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1894
NYX 0:85b3fd62ea1a 1895 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 1896 {
NYX 0:85b3fd62ea1a 1897 /* Process Locked */
NYX 0:85b3fd62ea1a 1898 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1899
NYX 0:85b3fd62ea1a 1900 inputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 1901 outputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 1902
NYX 0:85b3fd62ea1a 1903 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1904 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1905
NYX 0:85b3fd62ea1a 1906 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1907 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1908 {
NYX 0:85b3fd62ea1a 1909 /* Set the key */
NYX 0:85b3fd62ea1a 1910 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1911
NYX 0:85b3fd62ea1a 1912 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 1913 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC);
NYX 0:85b3fd62ea1a 1914
NYX 0:85b3fd62ea1a 1915 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 1916 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 1917
NYX 0:85b3fd62ea1a 1918 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1919 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1920
NYX 0:85b3fd62ea1a 1921 /* Set the phase */
NYX 0:85b3fd62ea1a 1922 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1923 }
NYX 0:85b3fd62ea1a 1924 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 1925 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 1926
NYX 0:85b3fd62ea1a 1927 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1928 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1929
NYX 0:85b3fd62ea1a 1930 /* Return function status */
NYX 0:85b3fd62ea1a 1931 return HAL_OK;
NYX 0:85b3fd62ea1a 1932 }
NYX 0:85b3fd62ea1a 1933 else
NYX 0:85b3fd62ea1a 1934 {
NYX 0:85b3fd62ea1a 1935 return HAL_ERROR;
NYX 0:85b3fd62ea1a 1936 }
NYX 0:85b3fd62ea1a 1937 }
NYX 0:85b3fd62ea1a 1938
NYX 0:85b3fd62ea1a 1939 /**
NYX 0:85b3fd62ea1a 1940 * @brief Initializes the CRYP peripheral in AES CTR encryption mode using DMA.
NYX 0:85b3fd62ea1a 1941 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 1942 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 1943 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 1944 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 1945 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 1946 * @retval HAL status
NYX 0:85b3fd62ea1a 1947 */
NYX 0:85b3fd62ea1a 1948 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 1949 {
NYX 0:85b3fd62ea1a 1950 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 1951 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 1952
NYX 0:85b3fd62ea1a 1953 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 1954 {
NYX 0:85b3fd62ea1a 1955 /* Process Locked */
NYX 0:85b3fd62ea1a 1956 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 1957
NYX 0:85b3fd62ea1a 1958 inputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 1959 outputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 1960
NYX 0:85b3fd62ea1a 1961 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 1962 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 1963
NYX 0:85b3fd62ea1a 1964 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 1965 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 1966 {
NYX 0:85b3fd62ea1a 1967 /* Set the key */
NYX 0:85b3fd62ea1a 1968 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 1969
NYX 0:85b3fd62ea1a 1970 /* Set the CRYP peripheral in AES ECB mode */
NYX 0:85b3fd62ea1a 1971 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR);
NYX 0:85b3fd62ea1a 1972
NYX 0:85b3fd62ea1a 1973 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 1974 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 1975
NYX 0:85b3fd62ea1a 1976 /* Flush FIFO */
NYX 0:85b3fd62ea1a 1977 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 1978
NYX 0:85b3fd62ea1a 1979 /* Set the phase */
NYX 0:85b3fd62ea1a 1980 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 1981 }
NYX 0:85b3fd62ea1a 1982
NYX 0:85b3fd62ea1a 1983 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 1984 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 1985
NYX 0:85b3fd62ea1a 1986 /* Process Unlocked */
NYX 0:85b3fd62ea1a 1987 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 1988
NYX 0:85b3fd62ea1a 1989 /* Return function status */
NYX 0:85b3fd62ea1a 1990 return HAL_OK;
NYX 0:85b3fd62ea1a 1991 }
NYX 0:85b3fd62ea1a 1992 else
NYX 0:85b3fd62ea1a 1993 {
NYX 0:85b3fd62ea1a 1994 return HAL_ERROR;
NYX 0:85b3fd62ea1a 1995 }
NYX 0:85b3fd62ea1a 1996 }
NYX 0:85b3fd62ea1a 1997
NYX 0:85b3fd62ea1a 1998 /**
NYX 0:85b3fd62ea1a 1999 * @brief Initializes the CRYP peripheral in AES ECB decryption mode using DMA.
NYX 0:85b3fd62ea1a 2000 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2001 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2002 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2003 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
NYX 0:85b3fd62ea1a 2004 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2005 * @retval HAL status
NYX 0:85b3fd62ea1a 2006 */
NYX 0:85b3fd62ea1a 2007 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 2008 {
NYX 0:85b3fd62ea1a 2009 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 2010 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2011 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2012
NYX 0:85b3fd62ea1a 2013 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 2014 {
NYX 0:85b3fd62ea1a 2015 /* Process Locked */
NYX 0:85b3fd62ea1a 2016 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2017
NYX 0:85b3fd62ea1a 2018 inputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 2019 outputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 2020
NYX 0:85b3fd62ea1a 2021 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2022 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2023
NYX 0:85b3fd62ea1a 2024 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 2025 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 2026 {
NYX 0:85b3fd62ea1a 2027 /* Set the key */
NYX 0:85b3fd62ea1a 2028 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 2029
NYX 0:85b3fd62ea1a 2030 /* Set the CRYP peripheral in AES Key mode */
NYX 0:85b3fd62ea1a 2031 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2032
NYX 0:85b3fd62ea1a 2033 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2034 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2035
NYX 0:85b3fd62ea1a 2036 /* Get tick */
NYX 0:85b3fd62ea1a 2037 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 2038
NYX 0:85b3fd62ea1a 2039 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
NYX 0:85b3fd62ea1a 2040 {
NYX 0:85b3fd62ea1a 2041 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 2042 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
NYX 0:85b3fd62ea1a 2043 {
NYX 0:85b3fd62ea1a 2044 /* Change state */
NYX 0:85b3fd62ea1a 2045 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
NYX 0:85b3fd62ea1a 2046
NYX 0:85b3fd62ea1a 2047 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2048 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2049
NYX 0:85b3fd62ea1a 2050 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 2051 }
NYX 0:85b3fd62ea1a 2052 }
NYX 0:85b3fd62ea1a 2053
NYX 0:85b3fd62ea1a 2054 /* Reset the ALGOMODE bits*/
NYX 0:85b3fd62ea1a 2055 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
NYX 0:85b3fd62ea1a 2056
NYX 0:85b3fd62ea1a 2057 /* Set the CRYP peripheral in AES ECB decryption mode */
NYX 0:85b3fd62ea1a 2058 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2059
NYX 0:85b3fd62ea1a 2060 /* Flush FIFO */
NYX 0:85b3fd62ea1a 2061 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 2062
NYX 0:85b3fd62ea1a 2063 /* Set the phase */
NYX 0:85b3fd62ea1a 2064 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 2065 }
NYX 0:85b3fd62ea1a 2066
NYX 0:85b3fd62ea1a 2067 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 2068 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 2069
NYX 0:85b3fd62ea1a 2070 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2071 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2072
NYX 0:85b3fd62ea1a 2073 /* Return function status */
NYX 0:85b3fd62ea1a 2074 return HAL_OK;
NYX 0:85b3fd62ea1a 2075 }
NYX 0:85b3fd62ea1a 2076 else
NYX 0:85b3fd62ea1a 2077 {
NYX 0:85b3fd62ea1a 2078 return HAL_ERROR;
NYX 0:85b3fd62ea1a 2079 }
NYX 0:85b3fd62ea1a 2080 }
NYX 0:85b3fd62ea1a 2081
NYX 0:85b3fd62ea1a 2082 /**
NYX 0:85b3fd62ea1a 2083 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA.
NYX 0:85b3fd62ea1a 2084 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2085 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2086 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2087 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
NYX 0:85b3fd62ea1a 2088 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2089 * @retval HAL status
NYX 0:85b3fd62ea1a 2090 */
NYX 0:85b3fd62ea1a 2091 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 2092 {
NYX 0:85b3fd62ea1a 2093 uint32_t tickstart = 0U;
NYX 0:85b3fd62ea1a 2094 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2095 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2096
NYX 0:85b3fd62ea1a 2097 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 2098 {
NYX 0:85b3fd62ea1a 2099 /* Process Locked */
NYX 0:85b3fd62ea1a 2100 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2101
NYX 0:85b3fd62ea1a 2102 inputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 2103 outputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 2104
NYX 0:85b3fd62ea1a 2105 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2106 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2107
NYX 0:85b3fd62ea1a 2108 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 2109 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 2110 {
NYX 0:85b3fd62ea1a 2111 /* Set the key */
NYX 0:85b3fd62ea1a 2112 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 2113
NYX 0:85b3fd62ea1a 2114 /* Set the CRYP peripheral in AES Key mode */
NYX 0:85b3fd62ea1a 2115 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2116
NYX 0:85b3fd62ea1a 2117 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2118 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2119
NYX 0:85b3fd62ea1a 2120 /* Get tick */
NYX 0:85b3fd62ea1a 2121 tickstart = HAL_GetTick();
NYX 0:85b3fd62ea1a 2122
NYX 0:85b3fd62ea1a 2123 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
NYX 0:85b3fd62ea1a 2124 {
NYX 0:85b3fd62ea1a 2125 /* Check for the Timeout */
NYX 0:85b3fd62ea1a 2126 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
NYX 0:85b3fd62ea1a 2127 {
NYX 0:85b3fd62ea1a 2128 /* Change state */
NYX 0:85b3fd62ea1a 2129 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
NYX 0:85b3fd62ea1a 2130
NYX 0:85b3fd62ea1a 2131 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2132 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2133
NYX 0:85b3fd62ea1a 2134 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 2135 }
NYX 0:85b3fd62ea1a 2136 }
NYX 0:85b3fd62ea1a 2137
NYX 0:85b3fd62ea1a 2138 /* Reset the ALGOMODE bits*/
NYX 0:85b3fd62ea1a 2139 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
NYX 0:85b3fd62ea1a 2140
NYX 0:85b3fd62ea1a 2141 /* Set the CRYP peripheral in AES CBC decryption mode */
NYX 0:85b3fd62ea1a 2142 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2143
NYX 0:85b3fd62ea1a 2144 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 2145 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 2146
NYX 0:85b3fd62ea1a 2147 /* Flush FIFO */
NYX 0:85b3fd62ea1a 2148 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 2149
NYX 0:85b3fd62ea1a 2150 /* Set the phase */
NYX 0:85b3fd62ea1a 2151 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 2152 }
NYX 0:85b3fd62ea1a 2153
NYX 0:85b3fd62ea1a 2154 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 2155 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 2156
NYX 0:85b3fd62ea1a 2157 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2158 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2159
NYX 0:85b3fd62ea1a 2160 /* Return function status */
NYX 0:85b3fd62ea1a 2161 return HAL_OK;
NYX 0:85b3fd62ea1a 2162 }
NYX 0:85b3fd62ea1a 2163 else
NYX 0:85b3fd62ea1a 2164 {
NYX 0:85b3fd62ea1a 2165 return HAL_ERROR;
NYX 0:85b3fd62ea1a 2166 }
NYX 0:85b3fd62ea1a 2167 }
NYX 0:85b3fd62ea1a 2168
NYX 0:85b3fd62ea1a 2169 /**
NYX 0:85b3fd62ea1a 2170 * @brief Initializes the CRYP peripheral in AES CTR decryption mode using DMA.
NYX 0:85b3fd62ea1a 2171 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2172 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2173 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2174 * @param Size: Length of the plaintext buffer, must be a multiple of 16
NYX 0:85b3fd62ea1a 2175 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2176 * @retval HAL status
NYX 0:85b3fd62ea1a 2177 */
NYX 0:85b3fd62ea1a 2178 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 2179 {
NYX 0:85b3fd62ea1a 2180 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2181 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2182
NYX 0:85b3fd62ea1a 2183 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 2184 {
NYX 0:85b3fd62ea1a 2185 /* Process Locked */
NYX 0:85b3fd62ea1a 2186 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2187
NYX 0:85b3fd62ea1a 2188 inputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 2189 outputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 2190
NYX 0:85b3fd62ea1a 2191 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2192 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2193
NYX 0:85b3fd62ea1a 2194 /* Check if initialization phase has already been performed */
NYX 0:85b3fd62ea1a 2195 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
NYX 0:85b3fd62ea1a 2196 {
NYX 0:85b3fd62ea1a 2197 /* Set the key */
NYX 0:85b3fd62ea1a 2198 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 2199
NYX 0:85b3fd62ea1a 2200 /* Set the CRYP peripheral in AES CTR mode */
NYX 0:85b3fd62ea1a 2201 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2202
NYX 0:85b3fd62ea1a 2203 /* Set the Initialization Vector */
NYX 0:85b3fd62ea1a 2204 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
NYX 0:85b3fd62ea1a 2205
NYX 0:85b3fd62ea1a 2206 /* Flush FIFO */
NYX 0:85b3fd62ea1a 2207 __HAL_CRYP_FIFO_FLUSH(hcryp);
NYX 0:85b3fd62ea1a 2208
NYX 0:85b3fd62ea1a 2209 /* Set the phase */
NYX 0:85b3fd62ea1a 2210 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
NYX 0:85b3fd62ea1a 2211 }
NYX 0:85b3fd62ea1a 2212
NYX 0:85b3fd62ea1a 2213 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 2214 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 2215
NYX 0:85b3fd62ea1a 2216 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2217 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2218
NYX 0:85b3fd62ea1a 2219 /* Return function status */
NYX 0:85b3fd62ea1a 2220 return HAL_OK;
NYX 0:85b3fd62ea1a 2221 }
NYX 0:85b3fd62ea1a 2222 else
NYX 0:85b3fd62ea1a 2223 {
NYX 0:85b3fd62ea1a 2224 return HAL_ERROR;
NYX 0:85b3fd62ea1a 2225 }
NYX 0:85b3fd62ea1a 2226 }
NYX 0:85b3fd62ea1a 2227
NYX 0:85b3fd62ea1a 2228
NYX 0:85b3fd62ea1a 2229 /**
NYX 0:85b3fd62ea1a 2230 * @}
NYX 0:85b3fd62ea1a 2231 */
NYX 0:85b3fd62ea1a 2232
NYX 0:85b3fd62ea1a 2233 /** @defgroup CRYP_Exported_Functions_Group3 DES processing functions
NYX 0:85b3fd62ea1a 2234 * @brief processing functions.
NYX 0:85b3fd62ea1a 2235 *
NYX 0:85b3fd62ea1a 2236 @verbatim
NYX 0:85b3fd62ea1a 2237 ==============================================================================
NYX 0:85b3fd62ea1a 2238 ##### DES processing functions #####
NYX 0:85b3fd62ea1a 2239 ==============================================================================
NYX 0:85b3fd62ea1a 2240 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 2241 (+) Encrypt plaintext using DES using ECB or CBC chaining modes
NYX 0:85b3fd62ea1a 2242 (+) Decrypt cyphertext using ECB or CBC chaining modes
NYX 0:85b3fd62ea1a 2243 [..] Three processing functions are available:
NYX 0:85b3fd62ea1a 2244 (+) Polling mode
NYX 0:85b3fd62ea1a 2245 (+) Interrupt mode
NYX 0:85b3fd62ea1a 2246 (+) DMA mode
NYX 0:85b3fd62ea1a 2247
NYX 0:85b3fd62ea1a 2248 @endverbatim
NYX 0:85b3fd62ea1a 2249 * @{
NYX 0:85b3fd62ea1a 2250 */
NYX 0:85b3fd62ea1a 2251
NYX 0:85b3fd62ea1a 2252 /**
NYX 0:85b3fd62ea1a 2253 * @brief Initializes the CRYP peripheral in DES ECB encryption mode.
NYX 0:85b3fd62ea1a 2254 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2255 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2256 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2257 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2258 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2259 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 2260 * @retval HAL status
NYX 0:85b3fd62ea1a 2261 */
NYX 0:85b3fd62ea1a 2262 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 2263 {
NYX 0:85b3fd62ea1a 2264 /* Process Locked */
NYX 0:85b3fd62ea1a 2265 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2266
NYX 0:85b3fd62ea1a 2267 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2268 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2269
NYX 0:85b3fd62ea1a 2270 /* Set CRYP peripheral in DES ECB encryption mode */
NYX 0:85b3fd62ea1a 2271 CRYP_SetDESECBMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 2272
NYX 0:85b3fd62ea1a 2273 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2274 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2275
NYX 0:85b3fd62ea1a 2276 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 2277 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 2278 {
NYX 0:85b3fd62ea1a 2279 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 2280 }
NYX 0:85b3fd62ea1a 2281
NYX 0:85b3fd62ea1a 2282 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2283 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2284
NYX 0:85b3fd62ea1a 2285 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2286 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2287
NYX 0:85b3fd62ea1a 2288 /* Return function status */
NYX 0:85b3fd62ea1a 2289 return HAL_OK;
NYX 0:85b3fd62ea1a 2290 }
NYX 0:85b3fd62ea1a 2291
NYX 0:85b3fd62ea1a 2292 /**
NYX 0:85b3fd62ea1a 2293 * @brief Initializes the CRYP peripheral in DES ECB decryption mode.
NYX 0:85b3fd62ea1a 2294 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2295 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2296 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2297 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2298 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2299 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 2300 * @retval HAL status
NYX 0:85b3fd62ea1a 2301 */
NYX 0:85b3fd62ea1a 2302 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 2303 {
NYX 0:85b3fd62ea1a 2304 /* Process Locked */
NYX 0:85b3fd62ea1a 2305 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2306
NYX 0:85b3fd62ea1a 2307 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2308 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2309
NYX 0:85b3fd62ea1a 2310 /* Set CRYP peripheral in DES ECB decryption mode */
NYX 0:85b3fd62ea1a 2311 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2312
NYX 0:85b3fd62ea1a 2313 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2314 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2315
NYX 0:85b3fd62ea1a 2316 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 2317 if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 2318 {
NYX 0:85b3fd62ea1a 2319 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 2320 }
NYX 0:85b3fd62ea1a 2321
NYX 0:85b3fd62ea1a 2322 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2323 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2324
NYX 0:85b3fd62ea1a 2325 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2326 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2327
NYX 0:85b3fd62ea1a 2328 /* Return function status */
NYX 0:85b3fd62ea1a 2329 return HAL_OK;
NYX 0:85b3fd62ea1a 2330 }
NYX 0:85b3fd62ea1a 2331
NYX 0:85b3fd62ea1a 2332 /**
NYX 0:85b3fd62ea1a 2333 * @brief Initializes the CRYP peripheral in DES CBC encryption mode.
NYX 0:85b3fd62ea1a 2334 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2335 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2336 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2337 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2338 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2339 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 2340 * @retval HAL status
NYX 0:85b3fd62ea1a 2341 */
NYX 0:85b3fd62ea1a 2342 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 2343 {
NYX 0:85b3fd62ea1a 2344 /* Process Locked */
NYX 0:85b3fd62ea1a 2345 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2346
NYX 0:85b3fd62ea1a 2347 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2348 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2349
NYX 0:85b3fd62ea1a 2350 /* Set CRYP peripheral in DES CBC encryption mode */
NYX 0:85b3fd62ea1a 2351 CRYP_SetDESCBCMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 2352
NYX 0:85b3fd62ea1a 2353 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2354 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2355
NYX 0:85b3fd62ea1a 2356 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 2357 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 2358 {
NYX 0:85b3fd62ea1a 2359 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 2360 }
NYX 0:85b3fd62ea1a 2361
NYX 0:85b3fd62ea1a 2362 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2363 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2364
NYX 0:85b3fd62ea1a 2365 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2366 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2367
NYX 0:85b3fd62ea1a 2368 /* Return function status */
NYX 0:85b3fd62ea1a 2369 return HAL_OK;
NYX 0:85b3fd62ea1a 2370 }
NYX 0:85b3fd62ea1a 2371
NYX 0:85b3fd62ea1a 2372 /**
NYX 0:85b3fd62ea1a 2373 * @brief Initializes the CRYP peripheral in DES ECB decryption mode.
NYX 0:85b3fd62ea1a 2374 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2375 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2376 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2377 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2378 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2379 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 2380 * @retval HAL status
NYX 0:85b3fd62ea1a 2381 */
NYX 0:85b3fd62ea1a 2382 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 2383 {
NYX 0:85b3fd62ea1a 2384 /* Process Locked */
NYX 0:85b3fd62ea1a 2385 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2386
NYX 0:85b3fd62ea1a 2387 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2388 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2389
NYX 0:85b3fd62ea1a 2390 /* Set CRYP peripheral in DES CBC decryption mode */
NYX 0:85b3fd62ea1a 2391 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2392
NYX 0:85b3fd62ea1a 2393 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2394 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2395
NYX 0:85b3fd62ea1a 2396 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 2397 if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 2398 {
NYX 0:85b3fd62ea1a 2399 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 2400 }
NYX 0:85b3fd62ea1a 2401
NYX 0:85b3fd62ea1a 2402 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2403 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2404
NYX 0:85b3fd62ea1a 2405 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2406 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2407
NYX 0:85b3fd62ea1a 2408 /* Return function status */
NYX 0:85b3fd62ea1a 2409 return HAL_OK;
NYX 0:85b3fd62ea1a 2410 }
NYX 0:85b3fd62ea1a 2411
NYX 0:85b3fd62ea1a 2412 /**
NYX 0:85b3fd62ea1a 2413 * @brief Initializes the CRYP peripheral in DES ECB encryption mode using IT.
NYX 0:85b3fd62ea1a 2414 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2415 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2416 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2417 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2418 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2419 * @retval HAL status
NYX 0:85b3fd62ea1a 2420 */
NYX 0:85b3fd62ea1a 2421 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 2422 {
NYX 0:85b3fd62ea1a 2423 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2424 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2425
NYX 0:85b3fd62ea1a 2426 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 2427 {
NYX 0:85b3fd62ea1a 2428 /* Process Locked */
NYX 0:85b3fd62ea1a 2429 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2430
NYX 0:85b3fd62ea1a 2431 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 2432 hcryp->pCrypInBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 2433 hcryp->pCrypOutBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 2434 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 2435
NYX 0:85b3fd62ea1a 2436 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2437 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2438
NYX 0:85b3fd62ea1a 2439 /* Set CRYP peripheral in DES ECB encryption mode */
NYX 0:85b3fd62ea1a 2440 CRYP_SetDESECBMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 2441
NYX 0:85b3fd62ea1a 2442 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 2443 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 2444
NYX 0:85b3fd62ea1a 2445 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2446 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2447
NYX 0:85b3fd62ea1a 2448 /* Return function status */
NYX 0:85b3fd62ea1a 2449 return HAL_OK;
NYX 0:85b3fd62ea1a 2450 }
NYX 0:85b3fd62ea1a 2451 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 2452 {
NYX 0:85b3fd62ea1a 2453 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 2454 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 2455 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 2456 inputaddr+=4U;
NYX 0:85b3fd62ea1a 2457 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 2458
NYX 0:85b3fd62ea1a 2459 hcryp->pCrypInBuffPtr += 8U;
NYX 0:85b3fd62ea1a 2460 hcryp->CrypInCount -= 8U;
NYX 0:85b3fd62ea1a 2461 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 2462 {
NYX 0:85b3fd62ea1a 2463 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 2464 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 2465 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 2466 }
NYX 0:85b3fd62ea1a 2467 }
NYX 0:85b3fd62ea1a 2468 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 2469 {
NYX 0:85b3fd62ea1a 2470 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 2471 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 2472 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 2473 outputaddr+=4U;
NYX 0:85b3fd62ea1a 2474 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 2475
NYX 0:85b3fd62ea1a 2476 hcryp->pCrypOutBuffPtr += 8U;
NYX 0:85b3fd62ea1a 2477 hcryp->CrypOutCount -= 8U;
NYX 0:85b3fd62ea1a 2478 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 2479 {
NYX 0:85b3fd62ea1a 2480 /* Disable IT */
NYX 0:85b3fd62ea1a 2481 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 2482 /* Disable CRYP */
NYX 0:85b3fd62ea1a 2483 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 2484 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2485 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2486 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2487 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2488 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 2489 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 2490 }
NYX 0:85b3fd62ea1a 2491 }
NYX 0:85b3fd62ea1a 2492
NYX 0:85b3fd62ea1a 2493 /* Return function status */
NYX 0:85b3fd62ea1a 2494 return HAL_OK;
NYX 0:85b3fd62ea1a 2495 }
NYX 0:85b3fd62ea1a 2496
NYX 0:85b3fd62ea1a 2497 /**
NYX 0:85b3fd62ea1a 2498 * @brief Initializes the CRYP peripheral in DES CBC encryption mode using interrupt.
NYX 0:85b3fd62ea1a 2499 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2500 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2501 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2502 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2503 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2504 * @retval HAL status
NYX 0:85b3fd62ea1a 2505 */
NYX 0:85b3fd62ea1a 2506 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 2507 {
NYX 0:85b3fd62ea1a 2508 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2509 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2510
NYX 0:85b3fd62ea1a 2511 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 2512 {
NYX 0:85b3fd62ea1a 2513 /* Process Locked */
NYX 0:85b3fd62ea1a 2514 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2515
NYX 0:85b3fd62ea1a 2516 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 2517 hcryp->pCrypInBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 2518 hcryp->pCrypOutBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 2519 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 2520
NYX 0:85b3fd62ea1a 2521 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2522 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2523
NYX 0:85b3fd62ea1a 2524 /* Set CRYP peripheral in DES CBC encryption mode */
NYX 0:85b3fd62ea1a 2525 CRYP_SetDESCBCMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 2526
NYX 0:85b3fd62ea1a 2527 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 2528 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 2529
NYX 0:85b3fd62ea1a 2530 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2531 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2532
NYX 0:85b3fd62ea1a 2533 /* Return function status */
NYX 0:85b3fd62ea1a 2534 return HAL_OK;
NYX 0:85b3fd62ea1a 2535 }
NYX 0:85b3fd62ea1a 2536
NYX 0:85b3fd62ea1a 2537 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 2538 {
NYX 0:85b3fd62ea1a 2539 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 2540 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 2541 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 2542 inputaddr+=4U;
NYX 0:85b3fd62ea1a 2543 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 2544
NYX 0:85b3fd62ea1a 2545 hcryp->pCrypInBuffPtr += 8U;
NYX 0:85b3fd62ea1a 2546 hcryp->CrypInCount -= 8U;
NYX 0:85b3fd62ea1a 2547 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 2548 {
NYX 0:85b3fd62ea1a 2549 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 2550 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 2551 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 2552 }
NYX 0:85b3fd62ea1a 2553 }
NYX 0:85b3fd62ea1a 2554 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 2555 {
NYX 0:85b3fd62ea1a 2556 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 2557 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 2558 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 2559 outputaddr+=4U;
NYX 0:85b3fd62ea1a 2560 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 2561
NYX 0:85b3fd62ea1a 2562 hcryp->pCrypOutBuffPtr += 8U;
NYX 0:85b3fd62ea1a 2563 hcryp->CrypOutCount -= 8U;
NYX 0:85b3fd62ea1a 2564 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 2565 {
NYX 0:85b3fd62ea1a 2566 /* Disable IT */
NYX 0:85b3fd62ea1a 2567 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 2568 /* Disable CRYP */
NYX 0:85b3fd62ea1a 2569 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 2570 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2571 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2572 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2573 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2574 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 2575 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 2576 }
NYX 0:85b3fd62ea1a 2577 }
NYX 0:85b3fd62ea1a 2578
NYX 0:85b3fd62ea1a 2579 /* Return function status */
NYX 0:85b3fd62ea1a 2580 return HAL_OK;
NYX 0:85b3fd62ea1a 2581 }
NYX 0:85b3fd62ea1a 2582
NYX 0:85b3fd62ea1a 2583 /**
NYX 0:85b3fd62ea1a 2584 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using IT.
NYX 0:85b3fd62ea1a 2585 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2586 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2587 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2588 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2589 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2590 * @retval HAL status
NYX 0:85b3fd62ea1a 2591 */
NYX 0:85b3fd62ea1a 2592 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 2593 {
NYX 0:85b3fd62ea1a 2594 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2595 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2596
NYX 0:85b3fd62ea1a 2597 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 2598 {
NYX 0:85b3fd62ea1a 2599 /* Process Locked */
NYX 0:85b3fd62ea1a 2600 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2601
NYX 0:85b3fd62ea1a 2602 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 2603 hcryp->pCrypInBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 2604 hcryp->pCrypOutBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 2605 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 2606
NYX 0:85b3fd62ea1a 2607 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2608 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2609
NYX 0:85b3fd62ea1a 2610 /* Set CRYP peripheral in DES ECB decryption mode */
NYX 0:85b3fd62ea1a 2611 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2612
NYX 0:85b3fd62ea1a 2613 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 2614 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 2615
NYX 0:85b3fd62ea1a 2616 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2617 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2618
NYX 0:85b3fd62ea1a 2619 /* Return function status */
NYX 0:85b3fd62ea1a 2620 return HAL_OK;
NYX 0:85b3fd62ea1a 2621 }
NYX 0:85b3fd62ea1a 2622 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 2623 {
NYX 0:85b3fd62ea1a 2624 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 2625 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 2626 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 2627 inputaddr+=4U;
NYX 0:85b3fd62ea1a 2628 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 2629
NYX 0:85b3fd62ea1a 2630 hcryp->pCrypInBuffPtr += 8U;
NYX 0:85b3fd62ea1a 2631 hcryp->CrypInCount -= 8U;
NYX 0:85b3fd62ea1a 2632 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 2633 {
NYX 0:85b3fd62ea1a 2634 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 2635 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 2636 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 2637 }
NYX 0:85b3fd62ea1a 2638 }
NYX 0:85b3fd62ea1a 2639 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 2640 {
NYX 0:85b3fd62ea1a 2641 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 2642 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 2643 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 2644 outputaddr+=4U;
NYX 0:85b3fd62ea1a 2645 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 2646
NYX 0:85b3fd62ea1a 2647 hcryp->pCrypOutBuffPtr += 8U;
NYX 0:85b3fd62ea1a 2648 hcryp->CrypOutCount -= 8U;
NYX 0:85b3fd62ea1a 2649 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 2650 {
NYX 0:85b3fd62ea1a 2651 /* Disable IT */
NYX 0:85b3fd62ea1a 2652 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 2653 /* Disable CRYP */
NYX 0:85b3fd62ea1a 2654 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 2655 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2656 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2657 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2658 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2659 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 2660 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 2661 }
NYX 0:85b3fd62ea1a 2662 }
NYX 0:85b3fd62ea1a 2663
NYX 0:85b3fd62ea1a 2664 /* Return function status */
NYX 0:85b3fd62ea1a 2665 return HAL_OK;
NYX 0:85b3fd62ea1a 2666 }
NYX 0:85b3fd62ea1a 2667
NYX 0:85b3fd62ea1a 2668 /**
NYX 0:85b3fd62ea1a 2669 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using interrupt.
NYX 0:85b3fd62ea1a 2670 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2671 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2672 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2673 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2674 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2675 * @retval HAL status
NYX 0:85b3fd62ea1a 2676 */
NYX 0:85b3fd62ea1a 2677 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 2678 {
NYX 0:85b3fd62ea1a 2679 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2680 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2681
NYX 0:85b3fd62ea1a 2682 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 2683 {
NYX 0:85b3fd62ea1a 2684 /* Process Locked */
NYX 0:85b3fd62ea1a 2685 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2686
NYX 0:85b3fd62ea1a 2687 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 2688 hcryp->pCrypInBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 2689 hcryp->pCrypOutBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 2690 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 2691
NYX 0:85b3fd62ea1a 2692 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2693 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2694
NYX 0:85b3fd62ea1a 2695 /* Set CRYP peripheral in DES CBC decryption mode */
NYX 0:85b3fd62ea1a 2696 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2697
NYX 0:85b3fd62ea1a 2698 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 2699 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 2700
NYX 0:85b3fd62ea1a 2701 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2702 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2703
NYX 0:85b3fd62ea1a 2704 /* Return function status */
NYX 0:85b3fd62ea1a 2705 return HAL_OK;
NYX 0:85b3fd62ea1a 2706 }
NYX 0:85b3fd62ea1a 2707 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 2708 {
NYX 0:85b3fd62ea1a 2709 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 2710 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 2711 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 2712 inputaddr+=4U;
NYX 0:85b3fd62ea1a 2713 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 2714
NYX 0:85b3fd62ea1a 2715 hcryp->pCrypInBuffPtr += 8U;
NYX 0:85b3fd62ea1a 2716 hcryp->CrypInCount -= 8U;
NYX 0:85b3fd62ea1a 2717 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 2718 {
NYX 0:85b3fd62ea1a 2719 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 2720 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 2721 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 2722 }
NYX 0:85b3fd62ea1a 2723 }
NYX 0:85b3fd62ea1a 2724 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 2725 {
NYX 0:85b3fd62ea1a 2726 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 2727 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 2728 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 2729 outputaddr+=4U;
NYX 0:85b3fd62ea1a 2730 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 2731
NYX 0:85b3fd62ea1a 2732 hcryp->pCrypOutBuffPtr += 8U;
NYX 0:85b3fd62ea1a 2733 hcryp->CrypOutCount -= 8U;
NYX 0:85b3fd62ea1a 2734 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 2735 {
NYX 0:85b3fd62ea1a 2736 /* Disable IT */
NYX 0:85b3fd62ea1a 2737 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 2738 /* Disable CRYP */
NYX 0:85b3fd62ea1a 2739 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 2740 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2741 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2742 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2743 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2744 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 2745 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 2746 }
NYX 0:85b3fd62ea1a 2747 }
NYX 0:85b3fd62ea1a 2748
NYX 0:85b3fd62ea1a 2749 /* Return function status */
NYX 0:85b3fd62ea1a 2750 return HAL_OK;
NYX 0:85b3fd62ea1a 2751 }
NYX 0:85b3fd62ea1a 2752
NYX 0:85b3fd62ea1a 2753 /**
NYX 0:85b3fd62ea1a 2754 * @brief Initializes the CRYP peripheral in DES ECB encryption mode using DMA.
NYX 0:85b3fd62ea1a 2755 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2756 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2757 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2758 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2759 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2760 * @retval HAL status
NYX 0:85b3fd62ea1a 2761 */
NYX 0:85b3fd62ea1a 2762 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 2763 {
NYX 0:85b3fd62ea1a 2764 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2765 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2766
NYX 0:85b3fd62ea1a 2767 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 2768 {
NYX 0:85b3fd62ea1a 2769 /* Process Locked */
NYX 0:85b3fd62ea1a 2770 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2771
NYX 0:85b3fd62ea1a 2772 inputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 2773 outputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 2774
NYX 0:85b3fd62ea1a 2775 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2776 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2777
NYX 0:85b3fd62ea1a 2778 /* Set CRYP peripheral in DES ECB encryption mode */
NYX 0:85b3fd62ea1a 2779 CRYP_SetDESECBMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 2780
NYX 0:85b3fd62ea1a 2781 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 2782 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 2783
NYX 0:85b3fd62ea1a 2784 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2785 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2786
NYX 0:85b3fd62ea1a 2787 /* Return function status */
NYX 0:85b3fd62ea1a 2788 return HAL_OK;
NYX 0:85b3fd62ea1a 2789 }
NYX 0:85b3fd62ea1a 2790 else
NYX 0:85b3fd62ea1a 2791 {
NYX 0:85b3fd62ea1a 2792 return HAL_ERROR;
NYX 0:85b3fd62ea1a 2793 }
NYX 0:85b3fd62ea1a 2794 }
NYX 0:85b3fd62ea1a 2795
NYX 0:85b3fd62ea1a 2796 /**
NYX 0:85b3fd62ea1a 2797 * @brief Initializes the CRYP peripheral in DES CBC encryption mode using DMA.
NYX 0:85b3fd62ea1a 2798 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2799 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2800 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2801 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2802 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2803 * @retval HAL status
NYX 0:85b3fd62ea1a 2804 */
NYX 0:85b3fd62ea1a 2805 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 2806 {
NYX 0:85b3fd62ea1a 2807 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2808 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2809
NYX 0:85b3fd62ea1a 2810 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 2811 {
NYX 0:85b3fd62ea1a 2812 /* Process Locked */
NYX 0:85b3fd62ea1a 2813 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2814
NYX 0:85b3fd62ea1a 2815 inputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 2816 outputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 2817
NYX 0:85b3fd62ea1a 2818 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2819 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2820
NYX 0:85b3fd62ea1a 2821 /* Set CRYP peripheral in DES CBC encryption mode */
NYX 0:85b3fd62ea1a 2822 CRYP_SetDESCBCMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 2823
NYX 0:85b3fd62ea1a 2824 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 2825 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 2826
NYX 0:85b3fd62ea1a 2827 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2828 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2829
NYX 0:85b3fd62ea1a 2830 /* Return function status */
NYX 0:85b3fd62ea1a 2831 return HAL_OK;
NYX 0:85b3fd62ea1a 2832 }
NYX 0:85b3fd62ea1a 2833 else
NYX 0:85b3fd62ea1a 2834 {
NYX 0:85b3fd62ea1a 2835 return HAL_ERROR;
NYX 0:85b3fd62ea1a 2836 }
NYX 0:85b3fd62ea1a 2837 }
NYX 0:85b3fd62ea1a 2838
NYX 0:85b3fd62ea1a 2839 /**
NYX 0:85b3fd62ea1a 2840 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using DMA.
NYX 0:85b3fd62ea1a 2841 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2842 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2843 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2844 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2845 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2846 * @retval HAL status
NYX 0:85b3fd62ea1a 2847 */
NYX 0:85b3fd62ea1a 2848 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 2849 {
NYX 0:85b3fd62ea1a 2850 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2851 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2852
NYX 0:85b3fd62ea1a 2853 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 2854 {
NYX 0:85b3fd62ea1a 2855 /* Process Locked */
NYX 0:85b3fd62ea1a 2856 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2857
NYX 0:85b3fd62ea1a 2858 inputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 2859 outputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 2860
NYX 0:85b3fd62ea1a 2861 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2862 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2863
NYX 0:85b3fd62ea1a 2864 /* Set CRYP peripheral in DES ECB decryption mode */
NYX 0:85b3fd62ea1a 2865 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2866
NYX 0:85b3fd62ea1a 2867 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 2868 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 2869
NYX 0:85b3fd62ea1a 2870 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2871 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2872
NYX 0:85b3fd62ea1a 2873 /* Return function status */
NYX 0:85b3fd62ea1a 2874 return HAL_OK;
NYX 0:85b3fd62ea1a 2875 }
NYX 0:85b3fd62ea1a 2876 else
NYX 0:85b3fd62ea1a 2877 {
NYX 0:85b3fd62ea1a 2878 return HAL_ERROR;
NYX 0:85b3fd62ea1a 2879 }
NYX 0:85b3fd62ea1a 2880 }
NYX 0:85b3fd62ea1a 2881
NYX 0:85b3fd62ea1a 2882 /**
NYX 0:85b3fd62ea1a 2883 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using DMA.
NYX 0:85b3fd62ea1a 2884 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2885 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2886 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2887 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2888 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2889 * @retval HAL status
NYX 0:85b3fd62ea1a 2890 */
NYX 0:85b3fd62ea1a 2891 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 2892 {
NYX 0:85b3fd62ea1a 2893 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 2894 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 2895
NYX 0:85b3fd62ea1a 2896 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 2897 {
NYX 0:85b3fd62ea1a 2898 /* Process Locked */
NYX 0:85b3fd62ea1a 2899 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2900
NYX 0:85b3fd62ea1a 2901 inputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 2902 outputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 2903
NYX 0:85b3fd62ea1a 2904 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2905 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2906
NYX 0:85b3fd62ea1a 2907 /* Set CRYP peripheral in DES CBC decryption mode */
NYX 0:85b3fd62ea1a 2908 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 2909
NYX 0:85b3fd62ea1a 2910 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 2911 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 2912
NYX 0:85b3fd62ea1a 2913 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2914 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2915
NYX 0:85b3fd62ea1a 2916 /* Return function status */
NYX 0:85b3fd62ea1a 2917 return HAL_OK;
NYX 0:85b3fd62ea1a 2918 }
NYX 0:85b3fd62ea1a 2919 else
NYX 0:85b3fd62ea1a 2920 {
NYX 0:85b3fd62ea1a 2921 return HAL_ERROR;
NYX 0:85b3fd62ea1a 2922 }
NYX 0:85b3fd62ea1a 2923 }
NYX 0:85b3fd62ea1a 2924
NYX 0:85b3fd62ea1a 2925 /**
NYX 0:85b3fd62ea1a 2926 * @}
NYX 0:85b3fd62ea1a 2927 */
NYX 0:85b3fd62ea1a 2928
NYX 0:85b3fd62ea1a 2929 /** @defgroup CRYP_Exported_Functions_Group4 TDES processing functions
NYX 0:85b3fd62ea1a 2930 * @brief processing functions.
NYX 0:85b3fd62ea1a 2931 *
NYX 0:85b3fd62ea1a 2932 @verbatim
NYX 0:85b3fd62ea1a 2933 ==============================================================================
NYX 0:85b3fd62ea1a 2934 ##### TDES processing functions #####
NYX 0:85b3fd62ea1a 2935 ==============================================================================
NYX 0:85b3fd62ea1a 2936 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 2937 (+) Encrypt plaintext using TDES based on ECB or CBC chaining modes
NYX 0:85b3fd62ea1a 2938 (+) Decrypt cyphertext using TDES based on ECB or CBC chaining modes
NYX 0:85b3fd62ea1a 2939 [..] Three processing functions are available:
NYX 0:85b3fd62ea1a 2940 (+) Polling mode
NYX 0:85b3fd62ea1a 2941 (+) Interrupt mode
NYX 0:85b3fd62ea1a 2942 (+) DMA mode
NYX 0:85b3fd62ea1a 2943
NYX 0:85b3fd62ea1a 2944 @endverbatim
NYX 0:85b3fd62ea1a 2945 * @{
NYX 0:85b3fd62ea1a 2946 */
NYX 0:85b3fd62ea1a 2947
NYX 0:85b3fd62ea1a 2948 /**
NYX 0:85b3fd62ea1a 2949 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode
NYX 0:85b3fd62ea1a 2950 * then encrypt pPlainData. The cypher data are available in pCypherData
NYX 0:85b3fd62ea1a 2951 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2952 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2953 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2954 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2955 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2956 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 2957 * @retval HAL status
NYX 0:85b3fd62ea1a 2958 */
NYX 0:85b3fd62ea1a 2959 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 2960 {
NYX 0:85b3fd62ea1a 2961 /* Process Locked */
NYX 0:85b3fd62ea1a 2962 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 2963
NYX 0:85b3fd62ea1a 2964 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2965 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 2966
NYX 0:85b3fd62ea1a 2967 /* Set CRYP peripheral in TDES ECB encryption mode */
NYX 0:85b3fd62ea1a 2968 CRYP_SetTDESECBMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 2969
NYX 0:85b3fd62ea1a 2970 /* Enable CRYP */
NYX 0:85b3fd62ea1a 2971 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 2972
NYX 0:85b3fd62ea1a 2973 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 2974 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 2975 {
NYX 0:85b3fd62ea1a 2976 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 2977 }
NYX 0:85b3fd62ea1a 2978
NYX 0:85b3fd62ea1a 2979 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 2980 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 2981
NYX 0:85b3fd62ea1a 2982 /* Process Unlocked */
NYX 0:85b3fd62ea1a 2983 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 2984
NYX 0:85b3fd62ea1a 2985 /* Return function status */
NYX 0:85b3fd62ea1a 2986 return HAL_OK;
NYX 0:85b3fd62ea1a 2987 }
NYX 0:85b3fd62ea1a 2988
NYX 0:85b3fd62ea1a 2989 /**
NYX 0:85b3fd62ea1a 2990 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode
NYX 0:85b3fd62ea1a 2991 * then decrypted pCypherData. The cypher data are available in pPlainData
NYX 0:85b3fd62ea1a 2992 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 2993 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 2994 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 2995 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 2996 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 2997 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 2998 * @retval HAL status
NYX 0:85b3fd62ea1a 2999 */
NYX 0:85b3fd62ea1a 3000 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 3001 {
NYX 0:85b3fd62ea1a 3002 /* Process Locked */
NYX 0:85b3fd62ea1a 3003 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3004
NYX 0:85b3fd62ea1a 3005 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3006 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3007
NYX 0:85b3fd62ea1a 3008 /* Set CRYP peripheral in TDES ECB decryption mode */
NYX 0:85b3fd62ea1a 3009 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 3010
NYX 0:85b3fd62ea1a 3011 /* Enable CRYP */
NYX 0:85b3fd62ea1a 3012 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 3013
NYX 0:85b3fd62ea1a 3014 /* Write Cypher Data and Get Plain Data */
NYX 0:85b3fd62ea1a 3015 if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 3016 {
NYX 0:85b3fd62ea1a 3017 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 3018 }
NYX 0:85b3fd62ea1a 3019
NYX 0:85b3fd62ea1a 3020 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3021 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 3022
NYX 0:85b3fd62ea1a 3023 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3024 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3025
NYX 0:85b3fd62ea1a 3026 /* Return function status */
NYX 0:85b3fd62ea1a 3027 return HAL_OK;
NYX 0:85b3fd62ea1a 3028 }
NYX 0:85b3fd62ea1a 3029
NYX 0:85b3fd62ea1a 3030 /**
NYX 0:85b3fd62ea1a 3031 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode
NYX 0:85b3fd62ea1a 3032 * then encrypt pPlainData. The cypher data are available in pCypherData
NYX 0:85b3fd62ea1a 3033 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3034 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3035 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3036 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3037 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3038 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 3039 * @retval HAL status
NYX 0:85b3fd62ea1a 3040 */
NYX 0:85b3fd62ea1a 3041 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 3042 {
NYX 0:85b3fd62ea1a 3043 /* Process Locked */
NYX 0:85b3fd62ea1a 3044 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3045
NYX 0:85b3fd62ea1a 3046 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3047 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3048
NYX 0:85b3fd62ea1a 3049 /* Set CRYP peripheral in TDES CBC encryption mode */
NYX 0:85b3fd62ea1a 3050 CRYP_SetTDESCBCMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 3051
NYX 0:85b3fd62ea1a 3052 /* Enable CRYP */
NYX 0:85b3fd62ea1a 3053 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 3054
NYX 0:85b3fd62ea1a 3055 /* Write Plain Data and Get Cypher Data */
NYX 0:85b3fd62ea1a 3056 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 3057 {
NYX 0:85b3fd62ea1a 3058 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 3059 }
NYX 0:85b3fd62ea1a 3060
NYX 0:85b3fd62ea1a 3061 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3062 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 3063
NYX 0:85b3fd62ea1a 3064 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3065 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3066
NYX 0:85b3fd62ea1a 3067 /* Return function status */
NYX 0:85b3fd62ea1a 3068 return HAL_OK;
NYX 0:85b3fd62ea1a 3069 }
NYX 0:85b3fd62ea1a 3070
NYX 0:85b3fd62ea1a 3071 /**
NYX 0:85b3fd62ea1a 3072 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode
NYX 0:85b3fd62ea1a 3073 * then decrypted pCypherData. The cypher data are available in pPlainData
NYX 0:85b3fd62ea1a 3074 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3075 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3076 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3077 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3078 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3079 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 3080 * @retval HAL status
NYX 0:85b3fd62ea1a 3081 */
NYX 0:85b3fd62ea1a 3082 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 3083 {
NYX 0:85b3fd62ea1a 3084 /* Process Locked */
NYX 0:85b3fd62ea1a 3085 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3086
NYX 0:85b3fd62ea1a 3087 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3088 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3089
NYX 0:85b3fd62ea1a 3090 /* Set CRYP peripheral in TDES CBC decryption mode */
NYX 0:85b3fd62ea1a 3091 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 3092
NYX 0:85b3fd62ea1a 3093 /* Enable CRYP */
NYX 0:85b3fd62ea1a 3094 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 3095
NYX 0:85b3fd62ea1a 3096 /* Write Cypher Data and Get Plain Data */
NYX 0:85b3fd62ea1a 3097 if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
NYX 0:85b3fd62ea1a 3098 {
NYX 0:85b3fd62ea1a 3099 return HAL_TIMEOUT;
NYX 0:85b3fd62ea1a 3100 }
NYX 0:85b3fd62ea1a 3101
NYX 0:85b3fd62ea1a 3102 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3103 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 3104
NYX 0:85b3fd62ea1a 3105 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3106 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3107
NYX 0:85b3fd62ea1a 3108 /* Return function status */
NYX 0:85b3fd62ea1a 3109 return HAL_OK;
NYX 0:85b3fd62ea1a 3110 }
NYX 0:85b3fd62ea1a 3111
NYX 0:85b3fd62ea1a 3112 /**
NYX 0:85b3fd62ea1a 3113 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode using interrupt.
NYX 0:85b3fd62ea1a 3114 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3115 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3116 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3117 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3118 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3119 * @retval HAL status
NYX 0:85b3fd62ea1a 3120 */
NYX 0:85b3fd62ea1a 3121 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 3122 {
NYX 0:85b3fd62ea1a 3123 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 3124 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 3125
NYX 0:85b3fd62ea1a 3126 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 3127 {
NYX 0:85b3fd62ea1a 3128 /* Process Locked */
NYX 0:85b3fd62ea1a 3129 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3130
NYX 0:85b3fd62ea1a 3131 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 3132 hcryp->pCrypInBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 3133 hcryp->pCrypOutBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 3134 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 3135
NYX 0:85b3fd62ea1a 3136 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3137 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3138
NYX 0:85b3fd62ea1a 3139 /* Set CRYP peripheral in TDES ECB encryption mode */
NYX 0:85b3fd62ea1a 3140 CRYP_SetTDESECBMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 3141
NYX 0:85b3fd62ea1a 3142 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 3143 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 3144
NYX 0:85b3fd62ea1a 3145 /* Enable CRYP */
NYX 0:85b3fd62ea1a 3146 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 3147
NYX 0:85b3fd62ea1a 3148 /* Return function status */
NYX 0:85b3fd62ea1a 3149 return HAL_OK;
NYX 0:85b3fd62ea1a 3150 }
NYX 0:85b3fd62ea1a 3151 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 3152 {
NYX 0:85b3fd62ea1a 3153 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 3154 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 3155 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 3156 inputaddr+=4U;
NYX 0:85b3fd62ea1a 3157 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 3158
NYX 0:85b3fd62ea1a 3159 hcryp->pCrypInBuffPtr += 8U;
NYX 0:85b3fd62ea1a 3160 hcryp->CrypInCount -= 8U;
NYX 0:85b3fd62ea1a 3161 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 3162 {
NYX 0:85b3fd62ea1a 3163 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 3164 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 3165 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 3166 }
NYX 0:85b3fd62ea1a 3167 }
NYX 0:85b3fd62ea1a 3168 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 3169 {
NYX 0:85b3fd62ea1a 3170 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 3171 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 3172 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 3173 outputaddr+=4U;
NYX 0:85b3fd62ea1a 3174 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 3175
NYX 0:85b3fd62ea1a 3176 hcryp->pCrypOutBuffPtr += 8U;
NYX 0:85b3fd62ea1a 3177 hcryp->CrypOutCount -= 8U;
NYX 0:85b3fd62ea1a 3178 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 3179 {
NYX 0:85b3fd62ea1a 3180 /* Disable IT */
NYX 0:85b3fd62ea1a 3181 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 3182 /* Disable CRYP */
NYX 0:85b3fd62ea1a 3183 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 3184 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3185 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3186 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3187 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 3188 /* Call the Output data transfer complete callback */
NYX 0:85b3fd62ea1a 3189 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 3190 }
NYX 0:85b3fd62ea1a 3191 }
NYX 0:85b3fd62ea1a 3192
NYX 0:85b3fd62ea1a 3193 /* Return function status */
NYX 0:85b3fd62ea1a 3194 return HAL_OK;
NYX 0:85b3fd62ea1a 3195 }
NYX 0:85b3fd62ea1a 3196
NYX 0:85b3fd62ea1a 3197 /**
NYX 0:85b3fd62ea1a 3198 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode.
NYX 0:85b3fd62ea1a 3199 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3200 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3201 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3202 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3203 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3204 * @retval HAL status
NYX 0:85b3fd62ea1a 3205 */
NYX 0:85b3fd62ea1a 3206 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 3207 {
NYX 0:85b3fd62ea1a 3208 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 3209 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 3210
NYX 0:85b3fd62ea1a 3211 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 3212 {
NYX 0:85b3fd62ea1a 3213 /* Process Locked */
NYX 0:85b3fd62ea1a 3214 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3215
NYX 0:85b3fd62ea1a 3216 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 3217 hcryp->pCrypInBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 3218 hcryp->pCrypOutBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 3219 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 3220
NYX 0:85b3fd62ea1a 3221 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3222 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3223
NYX 0:85b3fd62ea1a 3224 /* Set CRYP peripheral in TDES CBC encryption mode */
NYX 0:85b3fd62ea1a 3225 CRYP_SetTDESCBCMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 3226
NYX 0:85b3fd62ea1a 3227 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 3228 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 3229
NYX 0:85b3fd62ea1a 3230 /* Enable CRYP */
NYX 0:85b3fd62ea1a 3231 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 3232
NYX 0:85b3fd62ea1a 3233 /* Return function status */
NYX 0:85b3fd62ea1a 3234 return HAL_OK;
NYX 0:85b3fd62ea1a 3235 }
NYX 0:85b3fd62ea1a 3236 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 3237 {
NYX 0:85b3fd62ea1a 3238 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 3239 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 3240 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 3241 inputaddr+=4U;
NYX 0:85b3fd62ea1a 3242 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 3243
NYX 0:85b3fd62ea1a 3244 hcryp->pCrypInBuffPtr += 8U;
NYX 0:85b3fd62ea1a 3245 hcryp->CrypInCount -= 8U;
NYX 0:85b3fd62ea1a 3246 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 3247 {
NYX 0:85b3fd62ea1a 3248 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 3249 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 3250 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 3251 }
NYX 0:85b3fd62ea1a 3252 }
NYX 0:85b3fd62ea1a 3253 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 3254 {
NYX 0:85b3fd62ea1a 3255 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 3256 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 3257 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 3258 outputaddr+=4U;
NYX 0:85b3fd62ea1a 3259 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 3260
NYX 0:85b3fd62ea1a 3261 hcryp->pCrypOutBuffPtr += 8U;
NYX 0:85b3fd62ea1a 3262 hcryp->CrypOutCount -= 8U;
NYX 0:85b3fd62ea1a 3263 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 3264 {
NYX 0:85b3fd62ea1a 3265 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 3266 /* Disable CRYP */
NYX 0:85b3fd62ea1a 3267 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 3268 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3269 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3270 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3271 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 3272 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 3273 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 3274 }
NYX 0:85b3fd62ea1a 3275 }
NYX 0:85b3fd62ea1a 3276
NYX 0:85b3fd62ea1a 3277 /* Return function status */
NYX 0:85b3fd62ea1a 3278 return HAL_OK;
NYX 0:85b3fd62ea1a 3279 }
NYX 0:85b3fd62ea1a 3280
NYX 0:85b3fd62ea1a 3281 /**
NYX 0:85b3fd62ea1a 3282 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode.
NYX 0:85b3fd62ea1a 3283 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3284 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3285 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3286 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3287 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3288 * @retval HAL status
NYX 0:85b3fd62ea1a 3289 */
NYX 0:85b3fd62ea1a 3290 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 3291 {
NYX 0:85b3fd62ea1a 3292 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 3293 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 3294
NYX 0:85b3fd62ea1a 3295 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 3296 {
NYX 0:85b3fd62ea1a 3297 /* Process Locked */
NYX 0:85b3fd62ea1a 3298 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3299
NYX 0:85b3fd62ea1a 3300 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 3301 hcryp->pCrypInBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 3302 hcryp->pCrypOutBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 3303 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 3304
NYX 0:85b3fd62ea1a 3305 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3306 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3307
NYX 0:85b3fd62ea1a 3308 /* Set CRYP peripheral in TDES ECB decryption mode */
NYX 0:85b3fd62ea1a 3309 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 3310
NYX 0:85b3fd62ea1a 3311 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 3312 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 3313
NYX 0:85b3fd62ea1a 3314 /* Enable CRYP */
NYX 0:85b3fd62ea1a 3315 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 3316
NYX 0:85b3fd62ea1a 3317 /* Return function status */
NYX 0:85b3fd62ea1a 3318 return HAL_OK;
NYX 0:85b3fd62ea1a 3319 }
NYX 0:85b3fd62ea1a 3320 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 3321 {
NYX 0:85b3fd62ea1a 3322 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 3323 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 3324 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 3325 inputaddr+=4U;
NYX 0:85b3fd62ea1a 3326 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 3327
NYX 0:85b3fd62ea1a 3328 hcryp->pCrypInBuffPtr += 8U;
NYX 0:85b3fd62ea1a 3329 hcryp->CrypInCount -= 8U;
NYX 0:85b3fd62ea1a 3330 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 3331 {
NYX 0:85b3fd62ea1a 3332 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 3333 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 3334 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 3335 }
NYX 0:85b3fd62ea1a 3336 }
NYX 0:85b3fd62ea1a 3337 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 3338 {
NYX 0:85b3fd62ea1a 3339 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 3340 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 3341 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 3342 outputaddr+=4U;
NYX 0:85b3fd62ea1a 3343 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 3344
NYX 0:85b3fd62ea1a 3345 hcryp->pCrypOutBuffPtr += 8U;
NYX 0:85b3fd62ea1a 3346 hcryp->CrypOutCount -= 8U;
NYX 0:85b3fd62ea1a 3347 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 3348 {
NYX 0:85b3fd62ea1a 3349 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 3350 /* Disable CRYP */
NYX 0:85b3fd62ea1a 3351 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 3352 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3353 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3354 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3355 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 3356 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 3357 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 3358 }
NYX 0:85b3fd62ea1a 3359 }
NYX 0:85b3fd62ea1a 3360
NYX 0:85b3fd62ea1a 3361 /* Return function status */
NYX 0:85b3fd62ea1a 3362 return HAL_OK;
NYX 0:85b3fd62ea1a 3363 }
NYX 0:85b3fd62ea1a 3364
NYX 0:85b3fd62ea1a 3365 /**
NYX 0:85b3fd62ea1a 3366 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode.
NYX 0:85b3fd62ea1a 3367 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3368 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3369 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3370 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3371 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3372 * @retval HAL status
NYX 0:85b3fd62ea1a 3373 */
NYX 0:85b3fd62ea1a 3374 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 3375 {
NYX 0:85b3fd62ea1a 3376 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 3377 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 3378
NYX 0:85b3fd62ea1a 3379 if(hcryp->State == HAL_CRYP_STATE_READY)
NYX 0:85b3fd62ea1a 3380 {
NYX 0:85b3fd62ea1a 3381 /* Process Locked */
NYX 0:85b3fd62ea1a 3382 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3383
NYX 0:85b3fd62ea1a 3384 hcryp->CrypInCount = Size;
NYX 0:85b3fd62ea1a 3385 hcryp->pCrypInBuffPtr = pCypherData;
NYX 0:85b3fd62ea1a 3386 hcryp->pCrypOutBuffPtr = pPlainData;
NYX 0:85b3fd62ea1a 3387 hcryp->CrypOutCount = Size;
NYX 0:85b3fd62ea1a 3388
NYX 0:85b3fd62ea1a 3389 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3390 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3391
NYX 0:85b3fd62ea1a 3392 /* Set CRYP peripheral in TDES CBC decryption mode */
NYX 0:85b3fd62ea1a 3393 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 3394
NYX 0:85b3fd62ea1a 3395 /* Enable Interrupts */
NYX 0:85b3fd62ea1a 3396 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 3397
NYX 0:85b3fd62ea1a 3398 /* Enable CRYP */
NYX 0:85b3fd62ea1a 3399 __HAL_CRYP_ENABLE(hcryp);
NYX 0:85b3fd62ea1a 3400
NYX 0:85b3fd62ea1a 3401 /* Return function status */
NYX 0:85b3fd62ea1a 3402 return HAL_OK;
NYX 0:85b3fd62ea1a 3403 }
NYX 0:85b3fd62ea1a 3404 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
NYX 0:85b3fd62ea1a 3405 {
NYX 0:85b3fd62ea1a 3406 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 3407 /* Write the Input block in the IN FIFO */
NYX 0:85b3fd62ea1a 3408 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 3409 inputaddr+=4U;
NYX 0:85b3fd62ea1a 3410 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 3411
NYX 0:85b3fd62ea1a 3412 hcryp->pCrypInBuffPtr += 8U;
NYX 0:85b3fd62ea1a 3413 hcryp->CrypInCount -= 8U;
NYX 0:85b3fd62ea1a 3414 if(hcryp->CrypInCount == 0U)
NYX 0:85b3fd62ea1a 3415 {
NYX 0:85b3fd62ea1a 3416 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
NYX 0:85b3fd62ea1a 3417 /* Call the Input data transfer complete callback */
NYX 0:85b3fd62ea1a 3418 HAL_CRYP_InCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 3419 }
NYX 0:85b3fd62ea1a 3420 }
NYX 0:85b3fd62ea1a 3421 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
NYX 0:85b3fd62ea1a 3422 {
NYX 0:85b3fd62ea1a 3423 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 3424 /* Read the Output block from the Output FIFO */
NYX 0:85b3fd62ea1a 3425 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 3426 outputaddr+=4U;
NYX 0:85b3fd62ea1a 3427 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
NYX 0:85b3fd62ea1a 3428
NYX 0:85b3fd62ea1a 3429 hcryp->pCrypOutBuffPtr += 8U;
NYX 0:85b3fd62ea1a 3430 hcryp->CrypOutCount -= 8U;
NYX 0:85b3fd62ea1a 3431 if(hcryp->CrypOutCount == 0U)
NYX 0:85b3fd62ea1a 3432 {
NYX 0:85b3fd62ea1a 3433 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
NYX 0:85b3fd62ea1a 3434 /* Disable CRYP */
NYX 0:85b3fd62ea1a 3435 __HAL_CRYP_DISABLE(hcryp);
NYX 0:85b3fd62ea1a 3436 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3437 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3438 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3439 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 3440 /* Call Input transfer complete callback */
NYX 0:85b3fd62ea1a 3441 HAL_CRYP_OutCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 3442 }
NYX 0:85b3fd62ea1a 3443 }
NYX 0:85b3fd62ea1a 3444
NYX 0:85b3fd62ea1a 3445 /* Return function status */
NYX 0:85b3fd62ea1a 3446 return HAL_OK;
NYX 0:85b3fd62ea1a 3447 }
NYX 0:85b3fd62ea1a 3448
NYX 0:85b3fd62ea1a 3449 /**
NYX 0:85b3fd62ea1a 3450 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode using DMA.
NYX 0:85b3fd62ea1a 3451 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3452 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3453 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3454 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3455 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3456 * @retval HAL status
NYX 0:85b3fd62ea1a 3457 */
NYX 0:85b3fd62ea1a 3458 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 3459 {
NYX 0:85b3fd62ea1a 3460 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 3461 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 3462
NYX 0:85b3fd62ea1a 3463 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 3464 {
NYX 0:85b3fd62ea1a 3465 /* Process Locked */
NYX 0:85b3fd62ea1a 3466 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3467
NYX 0:85b3fd62ea1a 3468 inputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 3469 outputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 3470
NYX 0:85b3fd62ea1a 3471 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3472 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3473
NYX 0:85b3fd62ea1a 3474 /* Set CRYP peripheral in TDES ECB encryption mode */
NYX 0:85b3fd62ea1a 3475 CRYP_SetTDESECBMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 3476
NYX 0:85b3fd62ea1a 3477 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 3478 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 3479
NYX 0:85b3fd62ea1a 3480 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3481 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3482
NYX 0:85b3fd62ea1a 3483 /* Return function status */
NYX 0:85b3fd62ea1a 3484 return HAL_OK;
NYX 0:85b3fd62ea1a 3485 }
NYX 0:85b3fd62ea1a 3486 else
NYX 0:85b3fd62ea1a 3487 {
NYX 0:85b3fd62ea1a 3488 return HAL_ERROR;
NYX 0:85b3fd62ea1a 3489 }
NYX 0:85b3fd62ea1a 3490 }
NYX 0:85b3fd62ea1a 3491
NYX 0:85b3fd62ea1a 3492 /**
NYX 0:85b3fd62ea1a 3493 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode using DMA.
NYX 0:85b3fd62ea1a 3494 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3495 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3496 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3497 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3498 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3499 * @retval HAL status
NYX 0:85b3fd62ea1a 3500 */
NYX 0:85b3fd62ea1a 3501 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 3502 {
NYX 0:85b3fd62ea1a 3503 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 3504 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 3505
NYX 0:85b3fd62ea1a 3506 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 3507 {
NYX 0:85b3fd62ea1a 3508 /* Process Locked */
NYX 0:85b3fd62ea1a 3509 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3510
NYX 0:85b3fd62ea1a 3511 inputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 3512 outputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 3513
NYX 0:85b3fd62ea1a 3514 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3515 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3516
NYX 0:85b3fd62ea1a 3517 /* Set CRYP peripheral in TDES CBC encryption mode */
NYX 0:85b3fd62ea1a 3518 CRYP_SetTDESCBCMode(hcryp, 0U);
NYX 0:85b3fd62ea1a 3519
NYX 0:85b3fd62ea1a 3520 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 3521 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 3522
NYX 0:85b3fd62ea1a 3523 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3524 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3525
NYX 0:85b3fd62ea1a 3526 /* Return function status */
NYX 0:85b3fd62ea1a 3527 return HAL_OK;
NYX 0:85b3fd62ea1a 3528 }
NYX 0:85b3fd62ea1a 3529 else
NYX 0:85b3fd62ea1a 3530 {
NYX 0:85b3fd62ea1a 3531 return HAL_ERROR;
NYX 0:85b3fd62ea1a 3532 }
NYX 0:85b3fd62ea1a 3533 }
NYX 0:85b3fd62ea1a 3534
NYX 0:85b3fd62ea1a 3535 /**
NYX 0:85b3fd62ea1a 3536 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode using DMA.
NYX 0:85b3fd62ea1a 3537 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3538 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3539 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3540 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3541 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3542 * @retval HAL status
NYX 0:85b3fd62ea1a 3543 */
NYX 0:85b3fd62ea1a 3544 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 3545 {
NYX 0:85b3fd62ea1a 3546 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 3547 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 3548
NYX 0:85b3fd62ea1a 3549 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 3550 {
NYX 0:85b3fd62ea1a 3551 /* Process Locked */
NYX 0:85b3fd62ea1a 3552 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3553
NYX 0:85b3fd62ea1a 3554 inputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 3555 outputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 3556
NYX 0:85b3fd62ea1a 3557 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3558 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3559
NYX 0:85b3fd62ea1a 3560 /* Set CRYP peripheral in TDES ECB decryption mode */
NYX 0:85b3fd62ea1a 3561 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 3562
NYX 0:85b3fd62ea1a 3563 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 3564 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 3565
NYX 0:85b3fd62ea1a 3566 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3567 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3568
NYX 0:85b3fd62ea1a 3569 /* Return function status */
NYX 0:85b3fd62ea1a 3570 return HAL_OK;
NYX 0:85b3fd62ea1a 3571 }
NYX 0:85b3fd62ea1a 3572 else
NYX 0:85b3fd62ea1a 3573 {
NYX 0:85b3fd62ea1a 3574 return HAL_ERROR;
NYX 0:85b3fd62ea1a 3575 }
NYX 0:85b3fd62ea1a 3576 }
NYX 0:85b3fd62ea1a 3577
NYX 0:85b3fd62ea1a 3578 /**
NYX 0:85b3fd62ea1a 3579 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode using DMA.
NYX 0:85b3fd62ea1a 3580 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3581 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3582 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 3583 * @param Size: Length of the plaintext buffer, must be a multiple of 8
NYX 0:85b3fd62ea1a 3584 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 3585 * @retval HAL status
NYX 0:85b3fd62ea1a 3586 */
NYX 0:85b3fd62ea1a 3587 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 3588 {
NYX 0:85b3fd62ea1a 3589 uint32_t inputaddr;
NYX 0:85b3fd62ea1a 3590 uint32_t outputaddr;
NYX 0:85b3fd62ea1a 3591
NYX 0:85b3fd62ea1a 3592 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
NYX 0:85b3fd62ea1a 3593 {
NYX 0:85b3fd62ea1a 3594 /* Process Locked */
NYX 0:85b3fd62ea1a 3595 __HAL_LOCK(hcryp);
NYX 0:85b3fd62ea1a 3596
NYX 0:85b3fd62ea1a 3597 inputaddr = (uint32_t)pCypherData;
NYX 0:85b3fd62ea1a 3598 outputaddr = (uint32_t)pPlainData;
NYX 0:85b3fd62ea1a 3599
NYX 0:85b3fd62ea1a 3600 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3601 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3602
NYX 0:85b3fd62ea1a 3603 /* Set CRYP peripheral in TDES CBC decryption mode */
NYX 0:85b3fd62ea1a 3604 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
NYX 0:85b3fd62ea1a 3605
NYX 0:85b3fd62ea1a 3606 /* Set the input and output addresses and start DMA transfer */
NYX 0:85b3fd62ea1a 3607 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
NYX 0:85b3fd62ea1a 3608
NYX 0:85b3fd62ea1a 3609 /* Process Unlocked */
NYX 0:85b3fd62ea1a 3610 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 3611
NYX 0:85b3fd62ea1a 3612 /* Return function status */
NYX 0:85b3fd62ea1a 3613 return HAL_OK;
NYX 0:85b3fd62ea1a 3614 }
NYX 0:85b3fd62ea1a 3615 else
NYX 0:85b3fd62ea1a 3616 {
NYX 0:85b3fd62ea1a 3617 return HAL_ERROR;
NYX 0:85b3fd62ea1a 3618 }
NYX 0:85b3fd62ea1a 3619 }
NYX 0:85b3fd62ea1a 3620
NYX 0:85b3fd62ea1a 3621 /**
NYX 0:85b3fd62ea1a 3622 * @}
NYX 0:85b3fd62ea1a 3623 */
NYX 0:85b3fd62ea1a 3624
NYX 0:85b3fd62ea1a 3625 /** @defgroup CRYP_Exported_Functions_Group5 DMA callback functions
NYX 0:85b3fd62ea1a 3626 * @brief DMA callback functions.
NYX 0:85b3fd62ea1a 3627 *
NYX 0:85b3fd62ea1a 3628 @verbatim
NYX 0:85b3fd62ea1a 3629 ==============================================================================
NYX 0:85b3fd62ea1a 3630 ##### DMA callback functions #####
NYX 0:85b3fd62ea1a 3631 ==============================================================================
NYX 0:85b3fd62ea1a 3632 [..] This section provides DMA callback functions:
NYX 0:85b3fd62ea1a 3633 (+) DMA Input data transfer complete
NYX 0:85b3fd62ea1a 3634 (+) DMA Output data transfer complete
NYX 0:85b3fd62ea1a 3635 (+) DMA error
NYX 0:85b3fd62ea1a 3636
NYX 0:85b3fd62ea1a 3637 @endverbatim
NYX 0:85b3fd62ea1a 3638 * @{
NYX 0:85b3fd62ea1a 3639 */
NYX 0:85b3fd62ea1a 3640
NYX 0:85b3fd62ea1a 3641 /**
NYX 0:85b3fd62ea1a 3642 * @brief Input FIFO transfer completed callbacks.
NYX 0:85b3fd62ea1a 3643 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3644 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3645 * @retval None
NYX 0:85b3fd62ea1a 3646 */
NYX 0:85b3fd62ea1a 3647 __weak void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 3648 {
NYX 0:85b3fd62ea1a 3649 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 3650 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 3651 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 3652 the HAL_CRYP_InCpltCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 3653 */
NYX 0:85b3fd62ea1a 3654 }
NYX 0:85b3fd62ea1a 3655
NYX 0:85b3fd62ea1a 3656 /**
NYX 0:85b3fd62ea1a 3657 * @brief Output FIFO transfer completed callbacks.
NYX 0:85b3fd62ea1a 3658 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3659 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3660 * @retval None
NYX 0:85b3fd62ea1a 3661 */
NYX 0:85b3fd62ea1a 3662 __weak void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 3663 {
NYX 0:85b3fd62ea1a 3664 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 3665 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 3666 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 3667 the HAL_CRYP_OutCpltCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 3668 */
NYX 0:85b3fd62ea1a 3669 }
NYX 0:85b3fd62ea1a 3670
NYX 0:85b3fd62ea1a 3671 /**
NYX 0:85b3fd62ea1a 3672 * @brief CRYP error callbacks.
NYX 0:85b3fd62ea1a 3673 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3674 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3675 * @retval None
NYX 0:85b3fd62ea1a 3676 */
NYX 0:85b3fd62ea1a 3677 __weak void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 3678 {
NYX 0:85b3fd62ea1a 3679 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 3680 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 3681 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 3682 the HAL_CRYP_ErrorCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 3683 */
NYX 0:85b3fd62ea1a 3684 }
NYX 0:85b3fd62ea1a 3685
NYX 0:85b3fd62ea1a 3686 /**
NYX 0:85b3fd62ea1a 3687 * @}
NYX 0:85b3fd62ea1a 3688 */
NYX 0:85b3fd62ea1a 3689
NYX 0:85b3fd62ea1a 3690 /** @defgroup CRYP_Exported_Functions_Group6 CRYP IRQ handler management
NYX 0:85b3fd62ea1a 3691 * @brief CRYP IRQ handler.
NYX 0:85b3fd62ea1a 3692 *
NYX 0:85b3fd62ea1a 3693 @verbatim
NYX 0:85b3fd62ea1a 3694 ==============================================================================
NYX 0:85b3fd62ea1a 3695 ##### CRYP IRQ handler management #####
NYX 0:85b3fd62ea1a 3696 ==============================================================================
NYX 0:85b3fd62ea1a 3697 [..] This section provides CRYP IRQ handler function.
NYX 0:85b3fd62ea1a 3698
NYX 0:85b3fd62ea1a 3699 @endverbatim
NYX 0:85b3fd62ea1a 3700 * @{
NYX 0:85b3fd62ea1a 3701 */
NYX 0:85b3fd62ea1a 3702
NYX 0:85b3fd62ea1a 3703 /**
NYX 0:85b3fd62ea1a 3704 * @brief This function handles CRYP interrupt request.
NYX 0:85b3fd62ea1a 3705 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3706 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3707 * @retval None
NYX 0:85b3fd62ea1a 3708 */
NYX 0:85b3fd62ea1a 3709 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 3710 {
NYX 0:85b3fd62ea1a 3711 switch(CRYP->CR & CRYP_CR_ALGOMODE_DIRECTION)
NYX 0:85b3fd62ea1a 3712 {
NYX 0:85b3fd62ea1a 3713 case CRYP_CR_ALGOMODE_TDES_ECB_ENCRYPT:
NYX 0:85b3fd62ea1a 3714 HAL_CRYP_TDESECB_Encrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3715 break;
NYX 0:85b3fd62ea1a 3716
NYX 0:85b3fd62ea1a 3717 case CRYP_CR_ALGOMODE_TDES_ECB_DECRYPT:
NYX 0:85b3fd62ea1a 3718 HAL_CRYP_TDESECB_Decrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3719 break;
NYX 0:85b3fd62ea1a 3720
NYX 0:85b3fd62ea1a 3721 case CRYP_CR_ALGOMODE_TDES_CBC_ENCRYPT:
NYX 0:85b3fd62ea1a 3722 HAL_CRYP_TDESCBC_Encrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3723 break;
NYX 0:85b3fd62ea1a 3724
NYX 0:85b3fd62ea1a 3725 case CRYP_CR_ALGOMODE_TDES_CBC_DECRYPT:
NYX 0:85b3fd62ea1a 3726 HAL_CRYP_TDESCBC_Decrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3727 break;
NYX 0:85b3fd62ea1a 3728
NYX 0:85b3fd62ea1a 3729 case CRYP_CR_ALGOMODE_DES_ECB_ENCRYPT:
NYX 0:85b3fd62ea1a 3730 HAL_CRYP_DESECB_Encrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3731 break;
NYX 0:85b3fd62ea1a 3732
NYX 0:85b3fd62ea1a 3733 case CRYP_CR_ALGOMODE_DES_ECB_DECRYPT:
NYX 0:85b3fd62ea1a 3734 HAL_CRYP_DESECB_Decrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3735 break;
NYX 0:85b3fd62ea1a 3736
NYX 0:85b3fd62ea1a 3737 case CRYP_CR_ALGOMODE_DES_CBC_ENCRYPT:
NYX 0:85b3fd62ea1a 3738 HAL_CRYP_DESCBC_Encrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3739 break;
NYX 0:85b3fd62ea1a 3740
NYX 0:85b3fd62ea1a 3741 case CRYP_CR_ALGOMODE_DES_CBC_DECRYPT:
NYX 0:85b3fd62ea1a 3742 HAL_CRYP_DESCBC_Decrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3743 break;
NYX 0:85b3fd62ea1a 3744
NYX 0:85b3fd62ea1a 3745 case CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT:
NYX 0:85b3fd62ea1a 3746 HAL_CRYP_AESECB_Encrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3747 break;
NYX 0:85b3fd62ea1a 3748
NYX 0:85b3fd62ea1a 3749 case CRYP_CR_ALGOMODE_AES_ECB_DECRYPT:
NYX 0:85b3fd62ea1a 3750 HAL_CRYP_AESECB_Decrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3751 break;
NYX 0:85b3fd62ea1a 3752
NYX 0:85b3fd62ea1a 3753 case CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT:
NYX 0:85b3fd62ea1a 3754 HAL_CRYP_AESCBC_Encrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3755 break;
NYX 0:85b3fd62ea1a 3756
NYX 0:85b3fd62ea1a 3757 case CRYP_CR_ALGOMODE_AES_CBC_DECRYPT:
NYX 0:85b3fd62ea1a 3758 HAL_CRYP_AESCBC_Decrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3759 break;
NYX 0:85b3fd62ea1a 3760
NYX 0:85b3fd62ea1a 3761 case CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT:
NYX 0:85b3fd62ea1a 3762 HAL_CRYP_AESCTR_Encrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3763 break;
NYX 0:85b3fd62ea1a 3764
NYX 0:85b3fd62ea1a 3765 case CRYP_CR_ALGOMODE_AES_CTR_DECRYPT:
NYX 0:85b3fd62ea1a 3766 HAL_CRYP_AESCTR_Decrypt_IT(hcryp, NULL, 0U, NULL);
NYX 0:85b3fd62ea1a 3767 break;
NYX 0:85b3fd62ea1a 3768
NYX 0:85b3fd62ea1a 3769 default:
NYX 0:85b3fd62ea1a 3770 break;
NYX 0:85b3fd62ea1a 3771 }
NYX 0:85b3fd62ea1a 3772 }
NYX 0:85b3fd62ea1a 3773
NYX 0:85b3fd62ea1a 3774 /**
NYX 0:85b3fd62ea1a 3775 * @}
NYX 0:85b3fd62ea1a 3776 */
NYX 0:85b3fd62ea1a 3777
NYX 0:85b3fd62ea1a 3778 /** @defgroup CRYP_Exported_Functions_Group7 Peripheral State functions
NYX 0:85b3fd62ea1a 3779 * @brief Peripheral State functions.
NYX 0:85b3fd62ea1a 3780 *
NYX 0:85b3fd62ea1a 3781 @verbatim
NYX 0:85b3fd62ea1a 3782 ==============================================================================
NYX 0:85b3fd62ea1a 3783 ##### Peripheral State functions #####
NYX 0:85b3fd62ea1a 3784 ==============================================================================
NYX 0:85b3fd62ea1a 3785 [..]
NYX 0:85b3fd62ea1a 3786 This subsection permits to get in run-time the status of the peripheral.
NYX 0:85b3fd62ea1a 3787
NYX 0:85b3fd62ea1a 3788 @endverbatim
NYX 0:85b3fd62ea1a 3789 * @{
NYX 0:85b3fd62ea1a 3790 */
NYX 0:85b3fd62ea1a 3791
NYX 0:85b3fd62ea1a 3792 /**
NYX 0:85b3fd62ea1a 3793 * @brief Returns the CRYP state.
NYX 0:85b3fd62ea1a 3794 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 3795 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 3796 * @retval HAL state
NYX 0:85b3fd62ea1a 3797 */
NYX 0:85b3fd62ea1a 3798 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 3799 {
NYX 0:85b3fd62ea1a 3800 return hcryp->State;
NYX 0:85b3fd62ea1a 3801 }
NYX 0:85b3fd62ea1a 3802
NYX 0:85b3fd62ea1a 3803 /**
NYX 0:85b3fd62ea1a 3804 * @}
NYX 0:85b3fd62ea1a 3805 */
NYX 0:85b3fd62ea1a 3806
NYX 0:85b3fd62ea1a 3807
NYX 0:85b3fd62ea1a 3808 /**
NYX 0:85b3fd62ea1a 3809 * @}
NYX 0:85b3fd62ea1a 3810 */
NYX 0:85b3fd62ea1a 3811
NYX 0:85b3fd62ea1a 3812 #endif /* CRYP */
NYX 0:85b3fd62ea1a 3813
NYX 0:85b3fd62ea1a 3814 #if defined (AES)
NYX 0:85b3fd62ea1a 3815
NYX 0:85b3fd62ea1a 3816 /** @defgroup AES AES
NYX 0:85b3fd62ea1a 3817 * @brief AES HAL module driver.
NYX 0:85b3fd62ea1a 3818 * @{
NYX 0:85b3fd62ea1a 3819 */
NYX 0:85b3fd62ea1a 3820
NYX 0:85b3fd62ea1a 3821 /* Private typedef -----------------------------------------------------------*/
NYX 0:85b3fd62ea1a 3822 /* Private define ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 3823 /* Private macro -------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 3824 /* Private variables ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 3825 /* Private functions --------------------------------------------------------*/
NYX 0:85b3fd62ea1a 3826
NYX 0:85b3fd62ea1a 3827 /** @defgroup CRYP_Private_Functions CRYP Private Functions
NYX 0:85b3fd62ea1a 3828 * @{
NYX 0:85b3fd62ea1a 3829 */
NYX 0:85b3fd62ea1a 3830
NYX 0:85b3fd62ea1a 3831 static HAL_StatusTypeDef CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp);
NYX 0:85b3fd62ea1a 3832 static HAL_StatusTypeDef CRYP_SetKey(CRYP_HandleTypeDef *hcryp);
NYX 0:85b3fd62ea1a 3833 static HAL_StatusTypeDef CRYP_AES_IT(CRYP_HandleTypeDef *hcryp);
NYX 0:85b3fd62ea1a 3834
NYX 0:85b3fd62ea1a 3835 /**
NYX 0:85b3fd62ea1a 3836 * @}
NYX 0:85b3fd62ea1a 3837 */
NYX 0:85b3fd62ea1a 3838
NYX 0:85b3fd62ea1a 3839 /* Exported functions ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 3840
NYX 0:85b3fd62ea1a 3841 /** @defgroup CRYP_Exported_Functions CRYP Exported Functions
NYX 0:85b3fd62ea1a 3842 * @{
NYX 0:85b3fd62ea1a 3843 */
NYX 0:85b3fd62ea1a 3844
NYX 0:85b3fd62ea1a 3845 /** @defgroup CRYP_Exported_Functions_Group1 Initialization and deinitialization functions
NYX 0:85b3fd62ea1a 3846 * @brief Initialization and Configuration functions.
NYX 0:85b3fd62ea1a 3847 *
NYX 0:85b3fd62ea1a 3848 @verbatim
NYX 0:85b3fd62ea1a 3849 ==============================================================================
NYX 0:85b3fd62ea1a 3850 ##### Initialization and deinitialization functions #####
NYX 0:85b3fd62ea1a 3851 ==============================================================================
NYX 0:85b3fd62ea1a 3852 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 3853 (+) Initialize the CRYP according to the specified parameters
NYX 0:85b3fd62ea1a 3854 in the CRYP_InitTypeDef and creates the associated handle
NYX 0:85b3fd62ea1a 3855 (+) DeInitialize the CRYP peripheral
NYX 0:85b3fd62ea1a 3856 (+) Initialize the CRYP MSP (MCU Specific Package)
NYX 0:85b3fd62ea1a 3857 (+) De-Initialize the CRYP MSP
NYX 0:85b3fd62ea1a 3858
NYX 0:85b3fd62ea1a 3859 [..]
NYX 0:85b3fd62ea1a 3860 (@) Specific care must be taken to format the key and the Initialization Vector IV!
NYX 0:85b3fd62ea1a 3861
NYX 0:85b3fd62ea1a 3862 [..] If the key is defined as a 128-bit long array key[127..0] = {b127 ... b0} where
NYX 0:85b3fd62ea1a 3863 b127 is the MSB and b0 the LSB, the key must be stored in MCU memory
NYX 0:85b3fd62ea1a 3864 (+) as a sequence of words where the MSB word comes first (occupies the
NYX 0:85b3fd62ea1a 3865 lowest memory address)
NYX 0:85b3fd62ea1a 3866 (+) where each word is byte-swapped:
NYX 0:85b3fd62ea1a 3867 (++) address n+0 : 0b b103 .. b96 b111 .. b104 b119 .. b112 b127 .. b120
NYX 0:85b3fd62ea1a 3868 (++) address n+4 : 0b b71 .. b64 b79 .. b72 b87 .. b80 b95 .. b88
NYX 0:85b3fd62ea1a 3869 (++) address n+8 : 0b b39 .. b32 b47 .. b40 b55 .. b48 b63 .. b56
NYX 0:85b3fd62ea1a 3870 (++) address n+C : 0b b7 .. b0 b15 .. b8 b23 .. b16 b31 .. b24
NYX 0:85b3fd62ea1a 3871 [..] Hereafter, another illustration when considering a 128-bit long key made of 16 bytes {B15..B0}.
NYX 0:85b3fd62ea1a 3872 The 4 32-bit words that make the key must be stored as follows in MCU memory:
NYX 0:85b3fd62ea1a 3873 (+) address n+0 : 0x B12 B13 B14 B15
NYX 0:85b3fd62ea1a 3874 (+) address n+4 : 0x B8 B9 B10 B11
NYX 0:85b3fd62ea1a 3875 (+) address n+8 : 0x B4 B5 B6 B7
NYX 0:85b3fd62ea1a 3876 (+) address n+C : 0x B0 B1 B2 B3
NYX 0:85b3fd62ea1a 3877 [..] which leads to the expected setting
NYX 0:85b3fd62ea1a 3878 (+) AES_KEYR3 = 0x B15 B14 B13 B12
NYX 0:85b3fd62ea1a 3879 (+) AES_KEYR2 = 0x B11 B10 B9 B8
NYX 0:85b3fd62ea1a 3880 (+) AES_KEYR1 = 0x B7 B6 B5 B4
NYX 0:85b3fd62ea1a 3881 (+) AES_KEYR0 = 0x B3 B2 B1 B0
NYX 0:85b3fd62ea1a 3882
NYX 0:85b3fd62ea1a 3883 [..] Same format must be applied for a 256-bit long key made of 32 bytes {B31..B0}.
NYX 0:85b3fd62ea1a 3884 The 8 32-bit words that make the key must be stored as follows in MCU memory:
NYX 0:85b3fd62ea1a 3885 (+) address n+00 : 0x B28 B29 B30 B31
NYX 0:85b3fd62ea1a 3886 (+) address n+04 : 0x B24 B25 B26 B27
NYX 0:85b3fd62ea1a 3887 (+) address n+08 : 0x B20 B21 B22 B23
NYX 0:85b3fd62ea1a 3888 (+) address n+0C : 0x B16 B17 B18 B19
NYX 0:85b3fd62ea1a 3889 (+) address n+10 : 0x B12 B13 B14 B15
NYX 0:85b3fd62ea1a 3890 (+) address n+14 : 0x B8 B9 B10 B11
NYX 0:85b3fd62ea1a 3891 (+) address n+18 : 0x B4 B5 B6 B7
NYX 0:85b3fd62ea1a 3892 (+) address n+1C : 0x B0 B1 B2 B3
NYX 0:85b3fd62ea1a 3893 [..] which leads to the expected setting
NYX 0:85b3fd62ea1a 3894 (+) AES_KEYR7 = 0x B31 B30 B29 B28
NYX 0:85b3fd62ea1a 3895 (+) AES_KEYR6 = 0x B27 B26 B25 B24
NYX 0:85b3fd62ea1a 3896 (+) AES_KEYR5 = 0x B23 B22 B21 B20
NYX 0:85b3fd62ea1a 3897 (+) AES_KEYR4 = 0x B19 B18 B17 B16
NYX 0:85b3fd62ea1a 3898 (+) AES_KEYR3 = 0x B15 B14 B13 B12
NYX 0:85b3fd62ea1a 3899 (+) AES_KEYR2 = 0x B11 B10 B9 B8
NYX 0:85b3fd62ea1a 3900 (+) AES_KEYR1 = 0x B7 B6 B5 B4
NYX 0:85b3fd62ea1a 3901 (+) AES_KEYR0 = 0x B3 B2 B1 B0
NYX 0:85b3fd62ea1a 3902
NYX 0:85b3fd62ea1a 3903 [..] Initialization Vector IV (4 32-bit words) format must follow the same as
NYX 0:85b3fd62ea1a 3904 that of a 128-bit long key.
NYX 0:85b3fd62ea1a 3905
NYX 0:85b3fd62ea1a 3906 [..]
NYX 0:85b3fd62ea1a 3907
NYX 0:85b3fd62ea1a 3908 @endverbatim
NYX 0:85b3fd62ea1a 3909 * @{
NYX 0:85b3fd62ea1a 3910 */
NYX 0:85b3fd62ea1a 3911
NYX 0:85b3fd62ea1a 3912 /**
NYX 0:85b3fd62ea1a 3913 * @brief Initialize the CRYP according to the specified
NYX 0:85b3fd62ea1a 3914 * parameters in the CRYP_InitTypeDef and initialize the associated handle.
NYX 0:85b3fd62ea1a 3915 * @note Specific care must be taken to format the key and the Initialization Vector IV
NYX 0:85b3fd62ea1a 3916 * stored in the MCU memory before calling HAL_CRYP_Init(). Refer to explanations
NYX 0:85b3fd62ea1a 3917 * hereabove.
NYX 0:85b3fd62ea1a 3918 * @retval HAL status
NYX 0:85b3fd62ea1a 3919 */
NYX 0:85b3fd62ea1a 3920 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 3921 {
NYX 0:85b3fd62ea1a 3922 /* Check the CRYP handle allocation */
NYX 0:85b3fd62ea1a 3923 if(hcryp == NULL)
NYX 0:85b3fd62ea1a 3924 {
NYX 0:85b3fd62ea1a 3925 return HAL_ERROR;
NYX 0:85b3fd62ea1a 3926 }
NYX 0:85b3fd62ea1a 3927
NYX 0:85b3fd62ea1a 3928 /* Check the instance */
NYX 0:85b3fd62ea1a 3929 assert_param(IS_AES_ALL_INSTANCE(hcryp->Instance));
NYX 0:85b3fd62ea1a 3930
NYX 0:85b3fd62ea1a 3931 /* Check the parameters */
NYX 0:85b3fd62ea1a 3932 assert_param(IS_CRYP_KEYSIZE(hcryp->Init.KeySize));
NYX 0:85b3fd62ea1a 3933 assert_param(IS_CRYP_DATATYPE(hcryp->Init.DataType));
NYX 0:85b3fd62ea1a 3934 assert_param(IS_CRYP_ALGOMODE(hcryp->Init.OperatingMode));
NYX 0:85b3fd62ea1a 3935 /* ChainingMode parameter is irrelevant when mode is set to Key derivation */
NYX 0:85b3fd62ea1a 3936 if (hcryp->Init.OperatingMode != CRYP_ALGOMODE_KEYDERIVATION)
NYX 0:85b3fd62ea1a 3937 {
NYX 0:85b3fd62ea1a 3938 assert_param(IS_CRYP_CHAINMODE(hcryp->Init.ChainingMode));
NYX 0:85b3fd62ea1a 3939 }
NYX 0:85b3fd62ea1a 3940 assert_param(IS_CRYP_WRITE(hcryp->Init.KeyWriteFlag));
NYX 0:85b3fd62ea1a 3941
NYX 0:85b3fd62ea1a 3942 /*========================================================*/
NYX 0:85b3fd62ea1a 3943 /* Check the proper operating/chaining modes combinations */
NYX 0:85b3fd62ea1a 3944 /*========================================================*/
NYX 0:85b3fd62ea1a 3945 /* Check the proper chaining when the operating mode is key derivation and decryption */
NYX 0:85b3fd62ea1a 3946 #if defined(AES_CR_NPBLB)
NYX 0:85b3fd62ea1a 3947 if ((hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION_DECRYPT) &&\
NYX 0:85b3fd62ea1a 3948 ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CTR) \
NYX 0:85b3fd62ea1a 3949 || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC) \
NYX 0:85b3fd62ea1a 3950 || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CCM_CMAC)))
NYX 0:85b3fd62ea1a 3951 #else
NYX 0:85b3fd62ea1a 3952 if ((hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION_DECRYPT) &&\
NYX 0:85b3fd62ea1a 3953 ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CTR) \
NYX 0:85b3fd62ea1a 3954 || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC) \
NYX 0:85b3fd62ea1a 3955 || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)))
NYX 0:85b3fd62ea1a 3956 #endif
NYX 0:85b3fd62ea1a 3957 {
NYX 0:85b3fd62ea1a 3958 return HAL_ERROR;
NYX 0:85b3fd62ea1a 3959 }
NYX 0:85b3fd62ea1a 3960 /* Check that key derivation is not set in CMAC mode or CCM mode when applicable */
NYX 0:85b3fd62ea1a 3961 #if defined(AES_CR_NPBLB)
NYX 0:85b3fd62ea1a 3962 if ((hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION)
NYX 0:85b3fd62ea1a 3963 && (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CCM_CMAC))
NYX 0:85b3fd62ea1a 3964 #else
NYX 0:85b3fd62ea1a 3965 if ((hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION)
NYX 0:85b3fd62ea1a 3966 && (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC))
NYX 0:85b3fd62ea1a 3967 #endif
NYX 0:85b3fd62ea1a 3968 {
NYX 0:85b3fd62ea1a 3969 return HAL_ERROR;
NYX 0:85b3fd62ea1a 3970 }
NYX 0:85b3fd62ea1a 3971
NYX 0:85b3fd62ea1a 3972
NYX 0:85b3fd62ea1a 3973 /*================*/
NYX 0:85b3fd62ea1a 3974 /* Initialization */
NYX 0:85b3fd62ea1a 3975 /*================*/
NYX 0:85b3fd62ea1a 3976 /* Initialization start */
NYX 0:85b3fd62ea1a 3977 if(hcryp->State == HAL_CRYP_STATE_RESET)
NYX 0:85b3fd62ea1a 3978 {
NYX 0:85b3fd62ea1a 3979 /* Allocate lock resource and initialize it */
NYX 0:85b3fd62ea1a 3980 hcryp->Lock = HAL_UNLOCKED;
NYX 0:85b3fd62ea1a 3981
NYX 0:85b3fd62ea1a 3982 /* Init the low level hardware */
NYX 0:85b3fd62ea1a 3983 HAL_CRYP_MspInit(hcryp);
NYX 0:85b3fd62ea1a 3984 }
NYX 0:85b3fd62ea1a 3985
NYX 0:85b3fd62ea1a 3986 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 3987 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 3988
NYX 0:85b3fd62ea1a 3989 /* Disable the Peripheral */
NYX 0:85b3fd62ea1a 3990 __HAL_CRYP_DISABLE();
NYX 0:85b3fd62ea1a 3991
NYX 0:85b3fd62ea1a 3992 /*=============================================================*/
NYX 0:85b3fd62ea1a 3993 /* AES initialization common to all operating modes */
NYX 0:85b3fd62ea1a 3994 /*=============================================================*/
NYX 0:85b3fd62ea1a 3995 /* Set the Key size selection */
NYX 0:85b3fd62ea1a 3996 MODIFY_REG(hcryp->Instance->CR, AES_CR_KEYSIZE, hcryp->Init.KeySize);
NYX 0:85b3fd62ea1a 3997
NYX 0:85b3fd62ea1a 3998 /* Set the default CRYP phase when this parameter is not used.
NYX 0:85b3fd62ea1a 3999 Phase is updated below in case of GCM/GMAC/CMAC(/CCM) setting. */
NYX 0:85b3fd62ea1a 4000 hcryp->Phase = HAL_CRYP_PHASE_NOT_USED;
NYX 0:85b3fd62ea1a 4001
NYX 0:85b3fd62ea1a 4002
NYX 0:85b3fd62ea1a 4003
NYX 0:85b3fd62ea1a 4004 /*=============================================================*/
NYX 0:85b3fd62ea1a 4005 /* Carry on the initialization based on the AES operating mode */
NYX 0:85b3fd62ea1a 4006 /*=============================================================*/
NYX 0:85b3fd62ea1a 4007 /* Key derivation */
NYX 0:85b3fd62ea1a 4008 if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION)
NYX 0:85b3fd62ea1a 4009 {
NYX 0:85b3fd62ea1a 4010 MODIFY_REG(hcryp->Instance->CR, AES_CR_MODE, CRYP_ALGOMODE_KEYDERIVATION);
NYX 0:85b3fd62ea1a 4011
NYX 0:85b3fd62ea1a 4012 /* Configure the Key registers */
NYX 0:85b3fd62ea1a 4013 if (CRYP_SetKey(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4014 {
NYX 0:85b3fd62ea1a 4015 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4016 }
NYX 0:85b3fd62ea1a 4017 }
NYX 0:85b3fd62ea1a 4018 else
NYX 0:85b3fd62ea1a 4019 /* Encryption / Decryption (with or without key derivation) / authentication */
NYX 0:85b3fd62ea1a 4020 {
NYX 0:85b3fd62ea1a 4021 /* Set data type, operating and chaining modes.
NYX 0:85b3fd62ea1a 4022 In case of GCM or GMAC, data type is forced to 0b00 */
NYX 0:85b3fd62ea1a 4023 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
NYX 0:85b3fd62ea1a 4024 {
NYX 0:85b3fd62ea1a 4025 MODIFY_REG(hcryp->Instance->CR, AES_CR_DATATYPE|AES_CR_MODE|AES_CR_CHMOD, hcryp->Init.OperatingMode|hcryp->Init.ChainingMode);
NYX 0:85b3fd62ea1a 4026 }
NYX 0:85b3fd62ea1a 4027 else
NYX 0:85b3fd62ea1a 4028 {
NYX 0:85b3fd62ea1a 4029 MODIFY_REG(hcryp->Instance->CR, AES_CR_DATATYPE|AES_CR_MODE|AES_CR_CHMOD, hcryp->Init.DataType|hcryp->Init.OperatingMode|hcryp->Init.ChainingMode);
NYX 0:85b3fd62ea1a 4030 }
NYX 0:85b3fd62ea1a 4031
NYX 0:85b3fd62ea1a 4032
NYX 0:85b3fd62ea1a 4033 /* Specify the encryption/decryption phase in case of Galois counter mode (GCM),
NYX 0:85b3fd62ea1a 4034 Galois message authentication code (GMAC), cipher message authentication code (CMAC)
NYX 0:85b3fd62ea1a 4035 or Counter with Cipher Mode (CCM) when applicable */
NYX 0:85b3fd62ea1a 4036 #if defined(AES_CR_NPBLB)
NYX 0:85b3fd62ea1a 4037 if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
NYX 0:85b3fd62ea1a 4038 || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CCM_CMAC))
NYX 0:85b3fd62ea1a 4039 #else
NYX 0:85b3fd62ea1a 4040 if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
NYX 0:85b3fd62ea1a 4041 || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC))
NYX 0:85b3fd62ea1a 4042 #endif
NYX 0:85b3fd62ea1a 4043 {
NYX 0:85b3fd62ea1a 4044 MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, hcryp->Init.GCMCMACPhase);
NYX 0:85b3fd62ea1a 4045 hcryp->Phase = HAL_CRYP_PHASE_START;
NYX 0:85b3fd62ea1a 4046 }
NYX 0:85b3fd62ea1a 4047
NYX 0:85b3fd62ea1a 4048
NYX 0:85b3fd62ea1a 4049 /* Configure the Key registers if no need to bypass this step */
NYX 0:85b3fd62ea1a 4050 if (hcryp->Init.KeyWriteFlag == CRYP_KEY_WRITE_ENABLE)
NYX 0:85b3fd62ea1a 4051 {
NYX 0:85b3fd62ea1a 4052 if (CRYP_SetKey(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4053 {
NYX 0:85b3fd62ea1a 4054 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4055 }
NYX 0:85b3fd62ea1a 4056 }
NYX 0:85b3fd62ea1a 4057
NYX 0:85b3fd62ea1a 4058 /* If applicable, configure the Initialization Vector */
NYX 0:85b3fd62ea1a 4059 if (hcryp->Init.ChainingMode != CRYP_CHAINMODE_AES_ECB)
NYX 0:85b3fd62ea1a 4060 {
NYX 0:85b3fd62ea1a 4061 if (CRYP_SetInitVector(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4062 {
NYX 0:85b3fd62ea1a 4063 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4064 }
NYX 0:85b3fd62ea1a 4065 }
NYX 0:85b3fd62ea1a 4066 }
NYX 0:85b3fd62ea1a 4067
NYX 0:85b3fd62ea1a 4068 #if defined(AES_CR_NPBLB)
NYX 0:85b3fd62ea1a 4069 /* Clear NPBLB field */
NYX 0:85b3fd62ea1a 4070 CLEAR_BIT(hcryp->Instance->CR, AES_CR_NPBLB);
NYX 0:85b3fd62ea1a 4071 #endif
NYX 0:85b3fd62ea1a 4072
NYX 0:85b3fd62ea1a 4073 /* Reset CrypInCount and CrypOutCount */
NYX 0:85b3fd62ea1a 4074 hcryp->CrypInCount = 0U;
NYX 0:85b3fd62ea1a 4075 hcryp->CrypOutCount = 0U;
NYX 0:85b3fd62ea1a 4076
NYX 0:85b3fd62ea1a 4077 /* Reset ErrorCode field */
NYX 0:85b3fd62ea1a 4078 hcryp->ErrorCode = HAL_CRYP_ERROR_NONE;
NYX 0:85b3fd62ea1a 4079
NYX 0:85b3fd62ea1a 4080 /* Reset Mode suspension request */
NYX 0:85b3fd62ea1a 4081 hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
NYX 0:85b3fd62ea1a 4082
NYX 0:85b3fd62ea1a 4083 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 4084 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 4085
NYX 0:85b3fd62ea1a 4086 /* Enable the Peripheral */
NYX 0:85b3fd62ea1a 4087 __HAL_CRYP_ENABLE();
NYX 0:85b3fd62ea1a 4088
NYX 0:85b3fd62ea1a 4089 /* Return function status */
NYX 0:85b3fd62ea1a 4090 return HAL_OK;
NYX 0:85b3fd62ea1a 4091 }
NYX 0:85b3fd62ea1a 4092
NYX 0:85b3fd62ea1a 4093 /**
NYX 0:85b3fd62ea1a 4094 * @brief DeInitialize the CRYP peripheral.
NYX 0:85b3fd62ea1a 4095 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4096 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4097 * @retval HAL status
NYX 0:85b3fd62ea1a 4098 */
NYX 0:85b3fd62ea1a 4099 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4100 {
NYX 0:85b3fd62ea1a 4101 /* Check the CRYP handle allocation */
NYX 0:85b3fd62ea1a 4102 if(hcryp == NULL)
NYX 0:85b3fd62ea1a 4103 {
NYX 0:85b3fd62ea1a 4104 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4105 }
NYX 0:85b3fd62ea1a 4106
NYX 0:85b3fd62ea1a 4107 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 4108 hcryp->State = HAL_CRYP_STATE_BUSY;
NYX 0:85b3fd62ea1a 4109
NYX 0:85b3fd62ea1a 4110 /* Set the default CRYP phase */
NYX 0:85b3fd62ea1a 4111 hcryp->Phase = HAL_CRYP_PHASE_READY;
NYX 0:85b3fd62ea1a 4112
NYX 0:85b3fd62ea1a 4113 /* Reset CrypInCount and CrypOutCount */
NYX 0:85b3fd62ea1a 4114 hcryp->CrypInCount = 0U;
NYX 0:85b3fd62ea1a 4115 hcryp->CrypOutCount = 0U;
NYX 0:85b3fd62ea1a 4116
NYX 0:85b3fd62ea1a 4117 /* Disable the CRYP Peripheral Clock */
NYX 0:85b3fd62ea1a 4118 __HAL_CRYP_DISABLE();
NYX 0:85b3fd62ea1a 4119
NYX 0:85b3fd62ea1a 4120 /* DeInit the low level hardware: CLOCK, NVIC.*/
NYX 0:85b3fd62ea1a 4121 HAL_CRYP_MspDeInit(hcryp);
NYX 0:85b3fd62ea1a 4122
NYX 0:85b3fd62ea1a 4123 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 4124 hcryp->State = HAL_CRYP_STATE_RESET;
NYX 0:85b3fd62ea1a 4125
NYX 0:85b3fd62ea1a 4126 /* Release Lock */
NYX 0:85b3fd62ea1a 4127 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 4128
NYX 0:85b3fd62ea1a 4129 /* Return function status */
NYX 0:85b3fd62ea1a 4130 return HAL_OK;
NYX 0:85b3fd62ea1a 4131 }
NYX 0:85b3fd62ea1a 4132
NYX 0:85b3fd62ea1a 4133 /**
NYX 0:85b3fd62ea1a 4134 * @brief Initialize the CRYP MSP.
NYX 0:85b3fd62ea1a 4135 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4136 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4137 * @retval None
NYX 0:85b3fd62ea1a 4138 */
NYX 0:85b3fd62ea1a 4139 __weak void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4140 {
NYX 0:85b3fd62ea1a 4141 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 4142 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 4143
NYX 0:85b3fd62ea1a 4144 /* NOTE : This function should not be modified; when the callback is needed,
NYX 0:85b3fd62ea1a 4145 the HAL_CRYP_MspInit can be implemented in the user file
NYX 0:85b3fd62ea1a 4146 */
NYX 0:85b3fd62ea1a 4147 }
NYX 0:85b3fd62ea1a 4148
NYX 0:85b3fd62ea1a 4149 /**
NYX 0:85b3fd62ea1a 4150 * @brief DeInitialize CRYP MSP.
NYX 0:85b3fd62ea1a 4151 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4152 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4153 * @retval None
NYX 0:85b3fd62ea1a 4154 */
NYX 0:85b3fd62ea1a 4155 __weak void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4156 {
NYX 0:85b3fd62ea1a 4157 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 4158 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 4159
NYX 0:85b3fd62ea1a 4160 /* NOTE : This function should not be modified; when the callback is needed,
NYX 0:85b3fd62ea1a 4161 the HAL_CRYP_MspDeInit can be implemented in the user file
NYX 0:85b3fd62ea1a 4162 */
NYX 0:85b3fd62ea1a 4163 }
NYX 0:85b3fd62ea1a 4164
NYX 0:85b3fd62ea1a 4165 /**
NYX 0:85b3fd62ea1a 4166 * @}
NYX 0:85b3fd62ea1a 4167 */
NYX 0:85b3fd62ea1a 4168
NYX 0:85b3fd62ea1a 4169 /** @defgroup CRYP_Exported_Functions_Group2 AES processing functions
NYX 0:85b3fd62ea1a 4170 * @brief Processing functions.
NYX 0:85b3fd62ea1a 4171 *
NYX 0:85b3fd62ea1a 4172 @verbatim
NYX 0:85b3fd62ea1a 4173 ==============================================================================
NYX 0:85b3fd62ea1a 4174 ##### AES processing functions #####
NYX 0:85b3fd62ea1a 4175 ==============================================================================
NYX 0:85b3fd62ea1a 4176 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 4177 (+) Encrypt plaintext using AES algorithm in different chaining modes
NYX 0:85b3fd62ea1a 4178 (+) Decrypt cyphertext using AES algorithm in different chaining modes
NYX 0:85b3fd62ea1a 4179 [..] Three processing functions are available:
NYX 0:85b3fd62ea1a 4180 (+) Polling mode
NYX 0:85b3fd62ea1a 4181 (+) Interrupt mode
NYX 0:85b3fd62ea1a 4182 (+) DMA mode
NYX 0:85b3fd62ea1a 4183
NYX 0:85b3fd62ea1a 4184 @endverbatim
NYX 0:85b3fd62ea1a 4185 * @{
NYX 0:85b3fd62ea1a 4186 */
NYX 0:85b3fd62ea1a 4187
NYX 0:85b3fd62ea1a 4188
NYX 0:85b3fd62ea1a 4189 /**
NYX 0:85b3fd62ea1a 4190 * @brief Encrypt pPlainData in AES ECB encryption mode. The cypher data are available in pCypherData.
NYX 0:85b3fd62ea1a 4191 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4192 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4193 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4194 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4195 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4196 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 4197 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4198 * resort to generic HAL_CRYPEx_AES() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4199 * @retval HAL status
NYX 0:85b3fd62ea1a 4200 */
NYX 0:85b3fd62ea1a 4201 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 4202 {
NYX 0:85b3fd62ea1a 4203 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4204 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4205 {
NYX 0:85b3fd62ea1a 4206 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4207 }
NYX 0:85b3fd62ea1a 4208 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4209 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_ECB;
NYX 0:85b3fd62ea1a 4210 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4211 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4212 {
NYX 0:85b3fd62ea1a 4213 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4214 }
NYX 0:85b3fd62ea1a 4215
NYX 0:85b3fd62ea1a 4216 return HAL_CRYPEx_AES(hcryp, pPlainData, Size, pCypherData, Timeout);
NYX 0:85b3fd62ea1a 4217 }
NYX 0:85b3fd62ea1a 4218
NYX 0:85b3fd62ea1a 4219
NYX 0:85b3fd62ea1a 4220 /**
NYX 0:85b3fd62ea1a 4221 * @brief Encrypt pPlainData in AES CBC encryption mode with key derivation. The cypher data are available in pCypherData.
NYX 0:85b3fd62ea1a 4222 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4223 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4224 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4225 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4226 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4227 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 4228 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4229 * resort to generic HAL_CRYPEx_AES() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4230 * @retval HAL status
NYX 0:85b3fd62ea1a 4231 */
NYX 0:85b3fd62ea1a 4232 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 4233 {
NYX 0:85b3fd62ea1a 4234 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4235 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4236 {
NYX 0:85b3fd62ea1a 4237 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4238 }
NYX 0:85b3fd62ea1a 4239 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4240 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CBC;
NYX 0:85b3fd62ea1a 4241 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4242 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4243 {
NYX 0:85b3fd62ea1a 4244 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4245 }
NYX 0:85b3fd62ea1a 4246
NYX 0:85b3fd62ea1a 4247 return HAL_CRYPEx_AES(hcryp, pPlainData, Size, pCypherData, Timeout);
NYX 0:85b3fd62ea1a 4248 }
NYX 0:85b3fd62ea1a 4249
NYX 0:85b3fd62ea1a 4250
NYX 0:85b3fd62ea1a 4251 /**
NYX 0:85b3fd62ea1a 4252 * @brief Encrypt pPlainData in AES CTR encryption mode. The cypher data are available in pCypherData
NYX 0:85b3fd62ea1a 4253 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4254 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4255 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4256 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4257 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4258 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 4259 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4260 * resort to generic HAL_CRYPEx_AES() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4261 * @retval HAL status
NYX 0:85b3fd62ea1a 4262 */
NYX 0:85b3fd62ea1a 4263 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 4264 {
NYX 0:85b3fd62ea1a 4265 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4266 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4267 {
NYX 0:85b3fd62ea1a 4268 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4269 }
NYX 0:85b3fd62ea1a 4270 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4271 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR;
NYX 0:85b3fd62ea1a 4272 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4273 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4274 {
NYX 0:85b3fd62ea1a 4275 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4276 }
NYX 0:85b3fd62ea1a 4277
NYX 0:85b3fd62ea1a 4278 return HAL_CRYPEx_AES(hcryp, pPlainData, Size, pCypherData, Timeout);
NYX 0:85b3fd62ea1a 4279 }
NYX 0:85b3fd62ea1a 4280
NYX 0:85b3fd62ea1a 4281 /**
NYX 0:85b3fd62ea1a 4282 * @brief Decrypt pCypherData in AES ECB decryption mode with key derivation,
NYX 0:85b3fd62ea1a 4283 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4284 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4285 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4286 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4287 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4288 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4289 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 4290 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4291 * resort to generic HAL_CRYPEx_AES() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4292 * @retval HAL status
NYX 0:85b3fd62ea1a 4293 */
NYX 0:85b3fd62ea1a 4294 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 4295 {
NYX 0:85b3fd62ea1a 4296 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4297 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4298 {
NYX 0:85b3fd62ea1a 4299 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4300 }
NYX 0:85b3fd62ea1a 4301 hcryp->Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT;
NYX 0:85b3fd62ea1a 4302 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_ECB;
NYX 0:85b3fd62ea1a 4303 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4304 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4305 {
NYX 0:85b3fd62ea1a 4306 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4307 }
NYX 0:85b3fd62ea1a 4308
NYX 0:85b3fd62ea1a 4309 return HAL_CRYPEx_AES(hcryp, pCypherData, Size, pPlainData, Timeout);
NYX 0:85b3fd62ea1a 4310 }
NYX 0:85b3fd62ea1a 4311
NYX 0:85b3fd62ea1a 4312 /**
NYX 0:85b3fd62ea1a 4313 * @brief Decrypt pCypherData in AES ECB decryption mode with key derivation,
NYX 0:85b3fd62ea1a 4314 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4315 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4316 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4317 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4318 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4319 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4320 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 4321 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4322 * resort to generic HAL_CRYPEx_AES() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4323 * @retval HAL status
NYX 0:85b3fd62ea1a 4324 */
NYX 0:85b3fd62ea1a 4325 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 4326 {
NYX 0:85b3fd62ea1a 4327 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4328 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4329 {
NYX 0:85b3fd62ea1a 4330 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4331 }
NYX 0:85b3fd62ea1a 4332 hcryp->Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT;
NYX 0:85b3fd62ea1a 4333 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CBC;
NYX 0:85b3fd62ea1a 4334 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4335 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4336 {
NYX 0:85b3fd62ea1a 4337 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4338 }
NYX 0:85b3fd62ea1a 4339
NYX 0:85b3fd62ea1a 4340 return HAL_CRYPEx_AES(hcryp, pCypherData, Size, pPlainData, Timeout);
NYX 0:85b3fd62ea1a 4341 }
NYX 0:85b3fd62ea1a 4342
NYX 0:85b3fd62ea1a 4343 /**
NYX 0:85b3fd62ea1a 4344 * @brief Decrypt pCypherData in AES CTR decryption mode,
NYX 0:85b3fd62ea1a 4345 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4346 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4347 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4348 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4349 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4350 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4351 * @param Timeout: Specify Timeout value
NYX 0:85b3fd62ea1a 4352 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4353 * resort to generic HAL_CRYPEx_AES() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4354 * @retval HAL status
NYX 0:85b3fd62ea1a 4355 */
NYX 0:85b3fd62ea1a 4356 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
NYX 0:85b3fd62ea1a 4357 {
NYX 0:85b3fd62ea1a 4358 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4359 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4360 {
NYX 0:85b3fd62ea1a 4361 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4362 }
NYX 0:85b3fd62ea1a 4363 hcryp->Init.OperatingMode = CRYP_ALGOMODE_DECRYPT;
NYX 0:85b3fd62ea1a 4364 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR;
NYX 0:85b3fd62ea1a 4365 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4366 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4367 {
NYX 0:85b3fd62ea1a 4368 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4369 }
NYX 0:85b3fd62ea1a 4370
NYX 0:85b3fd62ea1a 4371 return HAL_CRYPEx_AES(hcryp, pCypherData, Size, pPlainData, Timeout);
NYX 0:85b3fd62ea1a 4372 }
NYX 0:85b3fd62ea1a 4373
NYX 0:85b3fd62ea1a 4374 /**
NYX 0:85b3fd62ea1a 4375 * @brief Encrypt pPlainData in AES ECB encryption mode using Interrupt,
NYX 0:85b3fd62ea1a 4376 * the cypher data are available in pCypherData.
NYX 0:85b3fd62ea1a 4377 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4378 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4379 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4380 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4381 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4382 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4383 * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4384 * @retval HAL status
NYX 0:85b3fd62ea1a 4385 */
NYX 0:85b3fd62ea1a 4386 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 4387 {
NYX 0:85b3fd62ea1a 4388 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4389 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4390 {
NYX 0:85b3fd62ea1a 4391 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4392 }
NYX 0:85b3fd62ea1a 4393 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4394 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_ECB;
NYX 0:85b3fd62ea1a 4395 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4396 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4397 {
NYX 0:85b3fd62ea1a 4398 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4399 }
NYX 0:85b3fd62ea1a 4400
NYX 0:85b3fd62ea1a 4401 return HAL_CRYPEx_AES_IT(hcryp, pPlainData, Size, pCypherData);
NYX 0:85b3fd62ea1a 4402 }
NYX 0:85b3fd62ea1a 4403
NYX 0:85b3fd62ea1a 4404 /**
NYX 0:85b3fd62ea1a 4405 * @brief Encrypt pPlainData in AES CBC encryption mode using Interrupt,
NYX 0:85b3fd62ea1a 4406 * the cypher data are available in pCypherData.
NYX 0:85b3fd62ea1a 4407 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4408 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4409 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4410 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4411 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4412 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4413 * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4414 * @retval HAL status
NYX 0:85b3fd62ea1a 4415 */
NYX 0:85b3fd62ea1a 4416 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 4417 {
NYX 0:85b3fd62ea1a 4418 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4419 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4420 {
NYX 0:85b3fd62ea1a 4421 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4422 }
NYX 0:85b3fd62ea1a 4423 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4424 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CBC;
NYX 0:85b3fd62ea1a 4425 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4426 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4427 {
NYX 0:85b3fd62ea1a 4428 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4429 }
NYX 0:85b3fd62ea1a 4430
NYX 0:85b3fd62ea1a 4431 return HAL_CRYPEx_AES_IT(hcryp, pPlainData, Size, pCypherData);
NYX 0:85b3fd62ea1a 4432 }
NYX 0:85b3fd62ea1a 4433
NYX 0:85b3fd62ea1a 4434
NYX 0:85b3fd62ea1a 4435 /**
NYX 0:85b3fd62ea1a 4436 * @brief Encrypt pPlainData in AES CTR encryption mode using Interrupt,
NYX 0:85b3fd62ea1a 4437 * the cypher data are available in pCypherData.
NYX 0:85b3fd62ea1a 4438 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4439 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4440 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4441 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4442 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4443 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4444 * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4445 * @retval HAL status
NYX 0:85b3fd62ea1a 4446 */
NYX 0:85b3fd62ea1a 4447 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 4448 {
NYX 0:85b3fd62ea1a 4449 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4450 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4451 {
NYX 0:85b3fd62ea1a 4452 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4453 }
NYX 0:85b3fd62ea1a 4454 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4455 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR;
NYX 0:85b3fd62ea1a 4456 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4457 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4458 {
NYX 0:85b3fd62ea1a 4459 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4460 }
NYX 0:85b3fd62ea1a 4461
NYX 0:85b3fd62ea1a 4462 return HAL_CRYPEx_AES_IT(hcryp, pPlainData, Size, pCypherData);
NYX 0:85b3fd62ea1a 4463 }
NYX 0:85b3fd62ea1a 4464
NYX 0:85b3fd62ea1a 4465 /**
NYX 0:85b3fd62ea1a 4466 * @brief Decrypt pCypherData in AES ECB decryption mode using Interrupt,
NYX 0:85b3fd62ea1a 4467 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4468 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4469 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4470 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4471 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4472 * @param pPlainData: Pointer to the plaintext buffer.
NYX 0:85b3fd62ea1a 4473 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4474 * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4475 * @retval HAL status
NYX 0:85b3fd62ea1a 4476 */
NYX 0:85b3fd62ea1a 4477 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 4478 {
NYX 0:85b3fd62ea1a 4479 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4480 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4481 {
NYX 0:85b3fd62ea1a 4482 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4483 }
NYX 0:85b3fd62ea1a 4484 hcryp->Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT;
NYX 0:85b3fd62ea1a 4485 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_ECB;
NYX 0:85b3fd62ea1a 4486 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4487 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4488 {
NYX 0:85b3fd62ea1a 4489 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4490 }
NYX 0:85b3fd62ea1a 4491
NYX 0:85b3fd62ea1a 4492 return HAL_CRYPEx_AES_IT(hcryp, pCypherData, Size, pPlainData);
NYX 0:85b3fd62ea1a 4493 }
NYX 0:85b3fd62ea1a 4494
NYX 0:85b3fd62ea1a 4495 /**
NYX 0:85b3fd62ea1a 4496 * @brief Decrypt pCypherData in AES CBC decryption mode using Interrupt,
NYX 0:85b3fd62ea1a 4497 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4498 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4499 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4500 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4501 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4502 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4503 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4504 * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4505 * @retval HAL status
NYX 0:85b3fd62ea1a 4506 */
NYX 0:85b3fd62ea1a 4507 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 4508 {
NYX 0:85b3fd62ea1a 4509 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4510 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4511 {
NYX 0:85b3fd62ea1a 4512 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4513 }
NYX 0:85b3fd62ea1a 4514 hcryp->Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT;
NYX 0:85b3fd62ea1a 4515 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CBC;
NYX 0:85b3fd62ea1a 4516 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4517 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4518 {
NYX 0:85b3fd62ea1a 4519 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4520 }
NYX 0:85b3fd62ea1a 4521
NYX 0:85b3fd62ea1a 4522 return HAL_CRYPEx_AES_IT(hcryp, pCypherData, Size, pPlainData);
NYX 0:85b3fd62ea1a 4523 }
NYX 0:85b3fd62ea1a 4524
NYX 0:85b3fd62ea1a 4525 /**
NYX 0:85b3fd62ea1a 4526 * @brief Decrypt pCypherData in AES CTR decryption mode using Interrupt,
NYX 0:85b3fd62ea1a 4527 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4528 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4529 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4530 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4531 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4532 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4533 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4534 * resort to generic HAL_CRYPEx_AES_IT() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4535 * @retval HAL status
NYX 0:85b3fd62ea1a 4536 */
NYX 0:85b3fd62ea1a 4537 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 4538 {
NYX 0:85b3fd62ea1a 4539 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4540 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4541 {
NYX 0:85b3fd62ea1a 4542 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4543 }
NYX 0:85b3fd62ea1a 4544 hcryp->Init.OperatingMode = CRYP_ALGOMODE_DECRYPT;
NYX 0:85b3fd62ea1a 4545 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR;
NYX 0:85b3fd62ea1a 4546 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4547 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4548 {
NYX 0:85b3fd62ea1a 4549 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4550 }
NYX 0:85b3fd62ea1a 4551
NYX 0:85b3fd62ea1a 4552 return HAL_CRYPEx_AES_IT(hcryp, pCypherData, Size, pPlainData);
NYX 0:85b3fd62ea1a 4553 }
NYX 0:85b3fd62ea1a 4554
NYX 0:85b3fd62ea1a 4555 /**
NYX 0:85b3fd62ea1a 4556 * @brief Encrypt pPlainData in AES ECB encryption mode using DMA,
NYX 0:85b3fd62ea1a 4557 * the cypher data are available in pCypherData.
NYX 0:85b3fd62ea1a 4558 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4559 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4560 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4561 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4562 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4563 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4564 * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4565 * @note pPlainData and pCypherData buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the IP.
NYX 0:85b3fd62ea1a 4566 * @retval HAL status
NYX 0:85b3fd62ea1a 4567 */
NYX 0:85b3fd62ea1a 4568 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 4569 {
NYX 0:85b3fd62ea1a 4570 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4571 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4572 {
NYX 0:85b3fd62ea1a 4573 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4574 }
NYX 0:85b3fd62ea1a 4575 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4576 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_ECB;
NYX 0:85b3fd62ea1a 4577 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4578 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4579 {
NYX 0:85b3fd62ea1a 4580 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4581 }
NYX 0:85b3fd62ea1a 4582
NYX 0:85b3fd62ea1a 4583 return HAL_CRYPEx_AES_DMA(hcryp, pPlainData, Size, pCypherData);
NYX 0:85b3fd62ea1a 4584 }
NYX 0:85b3fd62ea1a 4585
NYX 0:85b3fd62ea1a 4586
NYX 0:85b3fd62ea1a 4587
NYX 0:85b3fd62ea1a 4588 /**
NYX 0:85b3fd62ea1a 4589 * @brief Encrypt pPlainData in AES CBC encryption mode using DMA,
NYX 0:85b3fd62ea1a 4590 * the cypher data are available in pCypherData.
NYX 0:85b3fd62ea1a 4591 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4592 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4593 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4594 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4595 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4596 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4597 * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4598 * @note pPlainData and pCypherData buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the IP.
NYX 0:85b3fd62ea1a 4599 * @retval HAL status
NYX 0:85b3fd62ea1a 4600 */
NYX 0:85b3fd62ea1a 4601 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 4602 {
NYX 0:85b3fd62ea1a 4603 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4604 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4605 {
NYX 0:85b3fd62ea1a 4606 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4607 }
NYX 0:85b3fd62ea1a 4608 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4609 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CBC;
NYX 0:85b3fd62ea1a 4610 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4611 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4612 {
NYX 0:85b3fd62ea1a 4613 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4614 }
NYX 0:85b3fd62ea1a 4615
NYX 0:85b3fd62ea1a 4616 return HAL_CRYPEx_AES_DMA(hcryp, pPlainData, Size, pCypherData);
NYX 0:85b3fd62ea1a 4617 }
NYX 0:85b3fd62ea1a 4618
NYX 0:85b3fd62ea1a 4619 /**
NYX 0:85b3fd62ea1a 4620 * @brief Encrypt pPlainData in AES CTR encryption mode using DMA,
NYX 0:85b3fd62ea1a 4621 * the cypher data are available in pCypherData.
NYX 0:85b3fd62ea1a 4622 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4623 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4624 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4625 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4626 * @param pCypherData: Pointer to the cyphertext buffer.
NYX 0:85b3fd62ea1a 4627 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4628 * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4629 * @note pPlainData and pCypherData buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the IP.
NYX 0:85b3fd62ea1a 4630 * @retval HAL status
NYX 0:85b3fd62ea1a 4631 */
NYX 0:85b3fd62ea1a 4632 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
NYX 0:85b3fd62ea1a 4633 {
NYX 0:85b3fd62ea1a 4634 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4635 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4636 {
NYX 0:85b3fd62ea1a 4637 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4638 }
NYX 0:85b3fd62ea1a 4639 hcryp->Init.OperatingMode = CRYP_ALGOMODE_ENCRYPT;
NYX 0:85b3fd62ea1a 4640 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR;
NYX 0:85b3fd62ea1a 4641 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4642 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4643 {
NYX 0:85b3fd62ea1a 4644 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4645 }
NYX 0:85b3fd62ea1a 4646
NYX 0:85b3fd62ea1a 4647 return HAL_CRYPEx_AES_DMA(hcryp, pPlainData, Size, pCypherData);
NYX 0:85b3fd62ea1a 4648 }
NYX 0:85b3fd62ea1a 4649
NYX 0:85b3fd62ea1a 4650 /**
NYX 0:85b3fd62ea1a 4651 * @brief Decrypt pCypherData in AES ECB decryption mode using DMA,
NYX 0:85b3fd62ea1a 4652 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4653 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4654 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4655 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4656 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4657 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4658 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4659 * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4660 * @note pPlainData and pCypherData buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the IP.
NYX 0:85b3fd62ea1a 4661 * @retval HAL status
NYX 0:85b3fd62ea1a 4662 */
NYX 0:85b3fd62ea1a 4663 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 4664 {
NYX 0:85b3fd62ea1a 4665 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4666 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4667 {
NYX 0:85b3fd62ea1a 4668 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4669 }
NYX 0:85b3fd62ea1a 4670 hcryp->Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT;
NYX 0:85b3fd62ea1a 4671 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_ECB;
NYX 0:85b3fd62ea1a 4672 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4673 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4674 {
NYX 0:85b3fd62ea1a 4675 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4676 }
NYX 0:85b3fd62ea1a 4677
NYX 0:85b3fd62ea1a 4678 return HAL_CRYPEx_AES_DMA(hcryp, pCypherData, Size, pPlainData);
NYX 0:85b3fd62ea1a 4679 }
NYX 0:85b3fd62ea1a 4680
NYX 0:85b3fd62ea1a 4681 /**
NYX 0:85b3fd62ea1a 4682 * @brief Decrypt pCypherData in AES CBC decryption mode using DMA,
NYX 0:85b3fd62ea1a 4683 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4684 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4685 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4686 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4687 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4688 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4689 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4690 * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4691 * @note pPlainData and pCypherData buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the IP.
NYX 0:85b3fd62ea1a 4692 * @retval HAL status
NYX 0:85b3fd62ea1a 4693 */
NYX 0:85b3fd62ea1a 4694 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 4695 {
NYX 0:85b3fd62ea1a 4696 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4697 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4698 {
NYX 0:85b3fd62ea1a 4699 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4700 }
NYX 0:85b3fd62ea1a 4701 hcryp->Init.OperatingMode = CRYP_ALGOMODE_KEYDERIVATION_DECRYPT;
NYX 0:85b3fd62ea1a 4702 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CBC;
NYX 0:85b3fd62ea1a 4703 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4704 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4705 {
NYX 0:85b3fd62ea1a 4706 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4707 }
NYX 0:85b3fd62ea1a 4708
NYX 0:85b3fd62ea1a 4709 return HAL_CRYPEx_AES_DMA(hcryp, pCypherData, Size, pPlainData);
NYX 0:85b3fd62ea1a 4710 }
NYX 0:85b3fd62ea1a 4711
NYX 0:85b3fd62ea1a 4712 /**
NYX 0:85b3fd62ea1a 4713 * @brief Decrypt pCypherData in AES CTR decryption mode using DMA,
NYX 0:85b3fd62ea1a 4714 * the decyphered data are available in pPlainData.
NYX 0:85b3fd62ea1a 4715 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4716 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4717 * @param pCypherData: Pointer to the cyphertext buffer
NYX 0:85b3fd62ea1a 4718 * @param Size: Length of the plaintext buffer in bytes, must be a multiple of 16.
NYX 0:85b3fd62ea1a 4719 * @param pPlainData: Pointer to the plaintext buffer
NYX 0:85b3fd62ea1a 4720 * @note This API is provided only to maintain compatibility with legacy software. Users should directly
NYX 0:85b3fd62ea1a 4721 * resort to generic HAL_CRYPEx_AES_DMA() API instead (usage recommended).
NYX 0:85b3fd62ea1a 4722 * @note pPlainData and pCypherData buffers must be 32-bit aligned to ensure a correct DMA transfer to and from the IP.
NYX 0:85b3fd62ea1a 4723 * @retval HAL status
NYX 0:85b3fd62ea1a 4724 */
NYX 0:85b3fd62ea1a 4725 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
NYX 0:85b3fd62ea1a 4726 {
NYX 0:85b3fd62ea1a 4727 /* Re-initialize AES IP with proper parameters */
NYX 0:85b3fd62ea1a 4728 if (HAL_CRYP_DeInit(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4729 {
NYX 0:85b3fd62ea1a 4730 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4731 }
NYX 0:85b3fd62ea1a 4732 hcryp->Init.OperatingMode = CRYP_ALGOMODE_DECRYPT;
NYX 0:85b3fd62ea1a 4733 hcryp->Init.ChainingMode = CRYP_CHAINMODE_AES_CTR;
NYX 0:85b3fd62ea1a 4734 hcryp->Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE;
NYX 0:85b3fd62ea1a 4735 if (HAL_CRYP_Init(hcryp) != HAL_OK)
NYX 0:85b3fd62ea1a 4736 {
NYX 0:85b3fd62ea1a 4737 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4738 }
NYX 0:85b3fd62ea1a 4739
NYX 0:85b3fd62ea1a 4740 return HAL_CRYPEx_AES_DMA(hcryp, pCypherData, Size, pPlainData);
NYX 0:85b3fd62ea1a 4741 }
NYX 0:85b3fd62ea1a 4742
NYX 0:85b3fd62ea1a 4743
NYX 0:85b3fd62ea1a 4744 /**
NYX 0:85b3fd62ea1a 4745 * @}
NYX 0:85b3fd62ea1a 4746 */
NYX 0:85b3fd62ea1a 4747
NYX 0:85b3fd62ea1a 4748 /** @defgroup CRYP_Exported_Functions_Group3 Callback functions
NYX 0:85b3fd62ea1a 4749 * @brief Callback functions.
NYX 0:85b3fd62ea1a 4750 *
NYX 0:85b3fd62ea1a 4751 @verbatim
NYX 0:85b3fd62ea1a 4752 ==============================================================================
NYX 0:85b3fd62ea1a 4753 ##### Callback functions #####
NYX 0:85b3fd62ea1a 4754 ==============================================================================
NYX 0:85b3fd62ea1a 4755 [..] This section provides Interruption and DMA callback functions:
NYX 0:85b3fd62ea1a 4756 (+) DMA Input data transfer complete
NYX 0:85b3fd62ea1a 4757 (+) DMA Output data transfer complete
NYX 0:85b3fd62ea1a 4758 (+) DMA or Interrupt error
NYX 0:85b3fd62ea1a 4759
NYX 0:85b3fd62ea1a 4760 @endverbatim
NYX 0:85b3fd62ea1a 4761 * @{
NYX 0:85b3fd62ea1a 4762 */
NYX 0:85b3fd62ea1a 4763
NYX 0:85b3fd62ea1a 4764 /**
NYX 0:85b3fd62ea1a 4765 * @brief CRYP error callback.
NYX 0:85b3fd62ea1a 4766 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4767 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4768 * @retval None
NYX 0:85b3fd62ea1a 4769 */
NYX 0:85b3fd62ea1a 4770 __weak void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4771 {
NYX 0:85b3fd62ea1a 4772 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 4773 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 4774
NYX 0:85b3fd62ea1a 4775 /* NOTE : This function should not be modified; when the callback is needed,
NYX 0:85b3fd62ea1a 4776 the HAL_CRYP_ErrorCallback can be implemented in the user file
NYX 0:85b3fd62ea1a 4777 */
NYX 0:85b3fd62ea1a 4778 }
NYX 0:85b3fd62ea1a 4779
NYX 0:85b3fd62ea1a 4780 /**
NYX 0:85b3fd62ea1a 4781 * @brief Input DMA transfer complete callback.
NYX 0:85b3fd62ea1a 4782 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4783 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4784 * @retval None
NYX 0:85b3fd62ea1a 4785 */
NYX 0:85b3fd62ea1a 4786 __weak void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4787 {
NYX 0:85b3fd62ea1a 4788 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 4789 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 4790
NYX 0:85b3fd62ea1a 4791 /* NOTE : This function should not be modified; when the callback is needed,
NYX 0:85b3fd62ea1a 4792 the HAL_CRYP_InCpltCallback can be implemented in the user file
NYX 0:85b3fd62ea1a 4793 */
NYX 0:85b3fd62ea1a 4794 }
NYX 0:85b3fd62ea1a 4795
NYX 0:85b3fd62ea1a 4796 /**
NYX 0:85b3fd62ea1a 4797 * @brief Output DMA transfer complete callback.
NYX 0:85b3fd62ea1a 4798 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4799 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4800 * @retval None
NYX 0:85b3fd62ea1a 4801 */
NYX 0:85b3fd62ea1a 4802 __weak void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4803 {
NYX 0:85b3fd62ea1a 4804 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 4805 UNUSED(hcryp);
NYX 0:85b3fd62ea1a 4806
NYX 0:85b3fd62ea1a 4807 /* NOTE : This function should not be modified; when the callback is needed,
NYX 0:85b3fd62ea1a 4808 the HAL_CRYP_OutCpltCallback can be implemented in the user file
NYX 0:85b3fd62ea1a 4809 */
NYX 0:85b3fd62ea1a 4810 }
NYX 0:85b3fd62ea1a 4811
NYX 0:85b3fd62ea1a 4812 /**
NYX 0:85b3fd62ea1a 4813 * @}
NYX 0:85b3fd62ea1a 4814 */
NYX 0:85b3fd62ea1a 4815
NYX 0:85b3fd62ea1a 4816 /** @defgroup CRYP_Exported_Functions_Group4 CRYP IRQ handler
NYX 0:85b3fd62ea1a 4817 * @brief AES IRQ handler.
NYX 0:85b3fd62ea1a 4818 *
NYX 0:85b3fd62ea1a 4819 @verbatim
NYX 0:85b3fd62ea1a 4820 ==============================================================================
NYX 0:85b3fd62ea1a 4821 ##### AES IRQ handler management #####
NYX 0:85b3fd62ea1a 4822 ==============================================================================
NYX 0:85b3fd62ea1a 4823 [..] This section provides AES IRQ handler function.
NYX 0:85b3fd62ea1a 4824
NYX 0:85b3fd62ea1a 4825 @endverbatim
NYX 0:85b3fd62ea1a 4826 * @{
NYX 0:85b3fd62ea1a 4827 */
NYX 0:85b3fd62ea1a 4828
NYX 0:85b3fd62ea1a 4829 /**
NYX 0:85b3fd62ea1a 4830 * @brief Handle AES interrupt request.
NYX 0:85b3fd62ea1a 4831 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4832 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4833 * @retval None
NYX 0:85b3fd62ea1a 4834 */
NYX 0:85b3fd62ea1a 4835 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4836 {
NYX 0:85b3fd62ea1a 4837 /* Check if error occurred */
NYX 0:85b3fd62ea1a 4838 if (__HAL_CRYP_GET_IT_SOURCE(CRYP_IT_ERRIE) != RESET)
NYX 0:85b3fd62ea1a 4839 {
NYX 0:85b3fd62ea1a 4840 /* If Write Error occurred */
NYX 0:85b3fd62ea1a 4841 if (__HAL_CRYP_GET_FLAG(CRYP_IT_WRERR) != RESET)
NYX 0:85b3fd62ea1a 4842 {
NYX 0:85b3fd62ea1a 4843 hcryp->ErrorCode |= HAL_CRYP_WRITE_ERROR;
NYX 0:85b3fd62ea1a 4844 hcryp->State = HAL_CRYP_STATE_ERROR;
NYX 0:85b3fd62ea1a 4845 }
NYX 0:85b3fd62ea1a 4846 /* If Read Error occurred */
NYX 0:85b3fd62ea1a 4847 if (__HAL_CRYP_GET_FLAG(CRYP_IT_RDERR) != RESET)
NYX 0:85b3fd62ea1a 4848 {
NYX 0:85b3fd62ea1a 4849 hcryp->ErrorCode |= HAL_CRYP_READ_ERROR;
NYX 0:85b3fd62ea1a 4850 hcryp->State = HAL_CRYP_STATE_ERROR;
NYX 0:85b3fd62ea1a 4851 }
NYX 0:85b3fd62ea1a 4852
NYX 0:85b3fd62ea1a 4853 /* If an error has been reported */
NYX 0:85b3fd62ea1a 4854 if (hcryp->State == HAL_CRYP_STATE_ERROR)
NYX 0:85b3fd62ea1a 4855 {
NYX 0:85b3fd62ea1a 4856 /* Disable Error and Computation Complete Interrupts */
NYX 0:85b3fd62ea1a 4857 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
NYX 0:85b3fd62ea1a 4858 /* Clear all Interrupt flags */
NYX 0:85b3fd62ea1a 4859 __HAL_CRYP_CLEAR_FLAG(CRYP_ERR_CLEAR|CRYP_CCF_CLEAR);
NYX 0:85b3fd62ea1a 4860
NYX 0:85b3fd62ea1a 4861 /* Process Unlocked */
NYX 0:85b3fd62ea1a 4862 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 4863
NYX 0:85b3fd62ea1a 4864 HAL_CRYP_ErrorCallback(hcryp);
NYX 0:85b3fd62ea1a 4865
NYX 0:85b3fd62ea1a 4866 return;
NYX 0:85b3fd62ea1a 4867 }
NYX 0:85b3fd62ea1a 4868 }
NYX 0:85b3fd62ea1a 4869
NYX 0:85b3fd62ea1a 4870 /* Check if computation complete interrupt is enabled
NYX 0:85b3fd62ea1a 4871 and if the computation complete flag is raised */
NYX 0:85b3fd62ea1a 4872 if((__HAL_CRYP_GET_FLAG(CRYP_IT_CCF) != RESET) && (__HAL_CRYP_GET_IT_SOURCE(CRYP_IT_CCFIE) != RESET))
NYX 0:85b3fd62ea1a 4873 {
NYX 0:85b3fd62ea1a 4874 #if defined(AES_CR_NPBLB)
NYX 0:85b3fd62ea1a 4875 if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
NYX 0:85b3fd62ea1a 4876 || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CCM_CMAC))
NYX 0:85b3fd62ea1a 4877 #else
NYX 0:85b3fd62ea1a 4878 if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC)
NYX 0:85b3fd62ea1a 4879 || (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC))
NYX 0:85b3fd62ea1a 4880 #endif
NYX 0:85b3fd62ea1a 4881 {
NYX 0:85b3fd62ea1a 4882 /* To ensure proper suspension requests management, CCF flag
NYX 0:85b3fd62ea1a 4883 is reset in CRYP_AES_Auth_IT() according to the current
NYX 0:85b3fd62ea1a 4884 phase under handling */
NYX 0:85b3fd62ea1a 4885 CRYP_AES_Auth_IT(hcryp);
NYX 0:85b3fd62ea1a 4886 }
NYX 0:85b3fd62ea1a 4887 else
NYX 0:85b3fd62ea1a 4888 {
NYX 0:85b3fd62ea1a 4889 /* Clear Computation Complete Flag */
NYX 0:85b3fd62ea1a 4890 __HAL_CRYP_CLEAR_FLAG(CRYP_CCF_CLEAR);
NYX 0:85b3fd62ea1a 4891 CRYP_AES_IT(hcryp);
NYX 0:85b3fd62ea1a 4892 }
NYX 0:85b3fd62ea1a 4893 }
NYX 0:85b3fd62ea1a 4894 }
NYX 0:85b3fd62ea1a 4895
NYX 0:85b3fd62ea1a 4896 /**
NYX 0:85b3fd62ea1a 4897 * @}
NYX 0:85b3fd62ea1a 4898 */
NYX 0:85b3fd62ea1a 4899
NYX 0:85b3fd62ea1a 4900 /** @defgroup CRYP_Exported_Functions_Group5 Peripheral State functions
NYX 0:85b3fd62ea1a 4901 * @brief Peripheral State functions.
NYX 0:85b3fd62ea1a 4902 *
NYX 0:85b3fd62ea1a 4903 @verbatim
NYX 0:85b3fd62ea1a 4904 ==============================================================================
NYX 0:85b3fd62ea1a 4905 ##### Peripheral State functions #####
NYX 0:85b3fd62ea1a 4906 ==============================================================================
NYX 0:85b3fd62ea1a 4907 [..]
NYX 0:85b3fd62ea1a 4908 This subsection permits to get in run-time the status of the peripheral.
NYX 0:85b3fd62ea1a 4909
NYX 0:85b3fd62ea1a 4910 @endverbatim
NYX 0:85b3fd62ea1a 4911 * @{
NYX 0:85b3fd62ea1a 4912 */
NYX 0:85b3fd62ea1a 4913
NYX 0:85b3fd62ea1a 4914 /**
NYX 0:85b3fd62ea1a 4915 * @brief Return the CRYP handle state.
NYX 0:85b3fd62ea1a 4916 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4917 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4918 * @retval HAL state
NYX 0:85b3fd62ea1a 4919 */
NYX 0:85b3fd62ea1a 4920 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4921 {
NYX 0:85b3fd62ea1a 4922 /* Return CRYP handle state */
NYX 0:85b3fd62ea1a 4923 return hcryp->State;
NYX 0:85b3fd62ea1a 4924 }
NYX 0:85b3fd62ea1a 4925
NYX 0:85b3fd62ea1a 4926 /**
NYX 0:85b3fd62ea1a 4927 * @brief Return the CRYP peripheral error.
NYX 0:85b3fd62ea1a 4928 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4929 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4930 * @note The returned error is a bit-map combination of possible errors
NYX 0:85b3fd62ea1a 4931 * @retval Error bit-map
NYX 0:85b3fd62ea1a 4932 */
NYX 0:85b3fd62ea1a 4933 uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4934 {
NYX 0:85b3fd62ea1a 4935 return hcryp->ErrorCode;
NYX 0:85b3fd62ea1a 4936 }
NYX 0:85b3fd62ea1a 4937
NYX 0:85b3fd62ea1a 4938 /**
NYX 0:85b3fd62ea1a 4939 * @}
NYX 0:85b3fd62ea1a 4940 */
NYX 0:85b3fd62ea1a 4941
NYX 0:85b3fd62ea1a 4942 /**
NYX 0:85b3fd62ea1a 4943 * @}
NYX 0:85b3fd62ea1a 4944 */
NYX 0:85b3fd62ea1a 4945
NYX 0:85b3fd62ea1a 4946 /** @addtogroup CRYP_Private_Functions
NYX 0:85b3fd62ea1a 4947 * @{
NYX 0:85b3fd62ea1a 4948 */
NYX 0:85b3fd62ea1a 4949
NYX 0:85b3fd62ea1a 4950
NYX 0:85b3fd62ea1a 4951 /**
NYX 0:85b3fd62ea1a 4952 * @brief Write the Key in KeyRx registers.
NYX 0:85b3fd62ea1a 4953 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4954 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4955 * @retval None
NYX 0:85b3fd62ea1a 4956 */
NYX 0:85b3fd62ea1a 4957 static HAL_StatusTypeDef CRYP_SetKey(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4958 {
NYX 0:85b3fd62ea1a 4959 uint32_t keyaddr = 0x0U;
NYX 0:85b3fd62ea1a 4960
NYX 0:85b3fd62ea1a 4961 if ((uint32_t)(hcryp->Init.pKey == NULL))
NYX 0:85b3fd62ea1a 4962 {
NYX 0:85b3fd62ea1a 4963 return HAL_ERROR;
NYX 0:85b3fd62ea1a 4964 }
NYX 0:85b3fd62ea1a 4965
NYX 0:85b3fd62ea1a 4966
NYX 0:85b3fd62ea1a 4967 keyaddr = (uint32_t)(hcryp->Init.pKey);
NYX 0:85b3fd62ea1a 4968
NYX 0:85b3fd62ea1a 4969 if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B)
NYX 0:85b3fd62ea1a 4970 {
NYX 0:85b3fd62ea1a 4971 hcryp->Instance->KEYR7 = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 4972 keyaddr+=4U;
NYX 0:85b3fd62ea1a 4973 hcryp->Instance->KEYR6 = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 4974 keyaddr+=4U;
NYX 0:85b3fd62ea1a 4975 hcryp->Instance->KEYR5 = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 4976 keyaddr+=4U;
NYX 0:85b3fd62ea1a 4977 hcryp->Instance->KEYR4 = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 4978 keyaddr+=4U;
NYX 0:85b3fd62ea1a 4979 }
NYX 0:85b3fd62ea1a 4980
NYX 0:85b3fd62ea1a 4981 hcryp->Instance->KEYR3 = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 4982 keyaddr+=4U;
NYX 0:85b3fd62ea1a 4983 hcryp->Instance->KEYR2 = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 4984 keyaddr+=4U;
NYX 0:85b3fd62ea1a 4985 hcryp->Instance->KEYR1 = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 4986 keyaddr+=4U;
NYX 0:85b3fd62ea1a 4987 hcryp->Instance->KEYR0 = __REV(*(uint32_t*)(keyaddr));
NYX 0:85b3fd62ea1a 4988
NYX 0:85b3fd62ea1a 4989 return HAL_OK;
NYX 0:85b3fd62ea1a 4990 }
NYX 0:85b3fd62ea1a 4991
NYX 0:85b3fd62ea1a 4992 /**
NYX 0:85b3fd62ea1a 4993 * @brief Write the InitVector/InitCounter in IVRx registers.
NYX 0:85b3fd62ea1a 4994 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 4995 * the configuration information for CRYP module
NYX 0:85b3fd62ea1a 4996 * @retval None
NYX 0:85b3fd62ea1a 4997 */
NYX 0:85b3fd62ea1a 4998 static HAL_StatusTypeDef CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 4999 {
NYX 0:85b3fd62ea1a 5000 uint32_t ivaddr = 0x0U;
NYX 0:85b3fd62ea1a 5001
NYX 0:85b3fd62ea1a 5002 #if !defined(AES_CR_NPBLB)
NYX 0:85b3fd62ea1a 5003 if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
NYX 0:85b3fd62ea1a 5004 {
NYX 0:85b3fd62ea1a 5005 hcryp->Instance->IVR3 = 0U;
NYX 0:85b3fd62ea1a 5006 hcryp->Instance->IVR2 = 0U;
NYX 0:85b3fd62ea1a 5007 hcryp->Instance->IVR1 = 0U;
NYX 0:85b3fd62ea1a 5008 hcryp->Instance->IVR0 = 0U;
NYX 0:85b3fd62ea1a 5009 }
NYX 0:85b3fd62ea1a 5010 else
NYX 0:85b3fd62ea1a 5011 #endif
NYX 0:85b3fd62ea1a 5012 {
NYX 0:85b3fd62ea1a 5013 if (hcryp->Init.pInitVect == NULL)
NYX 0:85b3fd62ea1a 5014 {
NYX 0:85b3fd62ea1a 5015 return HAL_ERROR;
NYX 0:85b3fd62ea1a 5016 }
NYX 0:85b3fd62ea1a 5017
NYX 0:85b3fd62ea1a 5018 ivaddr = (uint32_t)(hcryp->Init.pInitVect);
NYX 0:85b3fd62ea1a 5019
NYX 0:85b3fd62ea1a 5020 hcryp->Instance->IVR3 = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 5021 ivaddr+=4U;
NYX 0:85b3fd62ea1a 5022 hcryp->Instance->IVR2 = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 5023 ivaddr+=4U;
NYX 0:85b3fd62ea1a 5024 hcryp->Instance->IVR1 = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 5025 ivaddr+=4U;
NYX 0:85b3fd62ea1a 5026 hcryp->Instance->IVR0 = __REV(*(uint32_t*)(ivaddr));
NYX 0:85b3fd62ea1a 5027 }
NYX 0:85b3fd62ea1a 5028 return HAL_OK;
NYX 0:85b3fd62ea1a 5029 }
NYX 0:85b3fd62ea1a 5030
NYX 0:85b3fd62ea1a 5031
NYX 0:85b3fd62ea1a 5032
NYX 0:85b3fd62ea1a 5033 /**
NYX 0:85b3fd62ea1a 5034 * @brief Handle CRYP block input/output data handling under interruption.
NYX 0:85b3fd62ea1a 5035 * @note The function is called under interruption only, once
NYX 0:85b3fd62ea1a 5036 * interruptions have been enabled by HAL_CRYPEx_AES_IT().
NYX 0:85b3fd62ea1a 5037 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 5038 * the configuration information for CRYP module.
NYX 0:85b3fd62ea1a 5039 * @retval HAL status
NYX 0:85b3fd62ea1a 5040 */
NYX 0:85b3fd62ea1a 5041 static HAL_StatusTypeDef CRYP_AES_IT(CRYP_HandleTypeDef *hcryp)
NYX 0:85b3fd62ea1a 5042 {
NYX 0:85b3fd62ea1a 5043 uint32_t inputaddr = 0U;
NYX 0:85b3fd62ea1a 5044 uint32_t outputaddr = 0U;
NYX 0:85b3fd62ea1a 5045
NYX 0:85b3fd62ea1a 5046 if(hcryp->State == HAL_CRYP_STATE_BUSY)
NYX 0:85b3fd62ea1a 5047 {
NYX 0:85b3fd62ea1a 5048 if (hcryp->Init.OperatingMode != CRYP_ALGOMODE_KEYDERIVATION)
NYX 0:85b3fd62ea1a 5049 {
NYX 0:85b3fd62ea1a 5050 /* Get the output data address */
NYX 0:85b3fd62ea1a 5051 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
NYX 0:85b3fd62ea1a 5052
NYX 0:85b3fd62ea1a 5053 /* Read the last available output block from the Data Output Register */
NYX 0:85b3fd62ea1a 5054 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
NYX 0:85b3fd62ea1a 5055 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5056 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
NYX 0:85b3fd62ea1a 5057 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5058 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
NYX 0:85b3fd62ea1a 5059 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5060 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
NYX 0:85b3fd62ea1a 5061 hcryp->pCrypOutBuffPtr += 16U;
NYX 0:85b3fd62ea1a 5062 hcryp->CrypOutCount -= 16U;
NYX 0:85b3fd62ea1a 5063
NYX 0:85b3fd62ea1a 5064 }
NYX 0:85b3fd62ea1a 5065 else
NYX 0:85b3fd62ea1a 5066 {
NYX 0:85b3fd62ea1a 5067 /* Read the derived key from the Key registers */
NYX 0:85b3fd62ea1a 5068 if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B)
NYX 0:85b3fd62ea1a 5069 {
NYX 0:85b3fd62ea1a 5070 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR7);
NYX 0:85b3fd62ea1a 5071 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5072 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR6);
NYX 0:85b3fd62ea1a 5073 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5074 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR5);
NYX 0:85b3fd62ea1a 5075 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5076 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR4);
NYX 0:85b3fd62ea1a 5077 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5078 }
NYX 0:85b3fd62ea1a 5079
NYX 0:85b3fd62ea1a 5080 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR3);
NYX 0:85b3fd62ea1a 5081 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5082 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR2);
NYX 0:85b3fd62ea1a 5083 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5084 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR1);
NYX 0:85b3fd62ea1a 5085 outputaddr+=4U;
NYX 0:85b3fd62ea1a 5086 *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR0);
NYX 0:85b3fd62ea1a 5087 }
NYX 0:85b3fd62ea1a 5088
NYX 0:85b3fd62ea1a 5089 /* In case of ciphering or deciphering, check if all output text has been retrieved;
NYX 0:85b3fd62ea1a 5090 In case of key derivation, stop right there */
NYX 0:85b3fd62ea1a 5091 if ((hcryp->CrypOutCount == 0U) || (hcryp->Init.OperatingMode == CRYP_ALGOMODE_KEYDERIVATION))
NYX 0:85b3fd62ea1a 5092 {
NYX 0:85b3fd62ea1a 5093 /* Disable Computation Complete Flag and Errors Interrupts */
NYX 0:85b3fd62ea1a 5094 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
NYX 0:85b3fd62ea1a 5095 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 5096 hcryp->State = HAL_CRYP_STATE_READY;
NYX 0:85b3fd62ea1a 5097
NYX 0:85b3fd62ea1a 5098 /* Process Unlocked */
NYX 0:85b3fd62ea1a 5099 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 5100
NYX 0:85b3fd62ea1a 5101 /* Call computation complete callback */
NYX 0:85b3fd62ea1a 5102 HAL_CRYPEx_ComputationCpltCallback(hcryp);
NYX 0:85b3fd62ea1a 5103
NYX 0:85b3fd62ea1a 5104 return HAL_OK;
NYX 0:85b3fd62ea1a 5105 }
NYX 0:85b3fd62ea1a 5106 /* If suspension flag has been raised, suspend processing */
NYX 0:85b3fd62ea1a 5107 else if (hcryp->SuspendRequest == HAL_CRYP_SUSPEND)
NYX 0:85b3fd62ea1a 5108 {
NYX 0:85b3fd62ea1a 5109 /* reset ModeSuspend */
NYX 0:85b3fd62ea1a 5110 hcryp->SuspendRequest = HAL_CRYP_SUSPEND_NONE;
NYX 0:85b3fd62ea1a 5111
NYX 0:85b3fd62ea1a 5112 /* Disable Computation Complete Flag and Errors Interrupts */
NYX 0:85b3fd62ea1a 5113 __HAL_CRYP_DISABLE_IT(CRYP_IT_CCFIE|CRYP_IT_ERRIE);
NYX 0:85b3fd62ea1a 5114 /* Change the CRYP state */
NYX 0:85b3fd62ea1a 5115 hcryp->State = HAL_CRYP_STATE_SUSPENDED;
NYX 0:85b3fd62ea1a 5116
NYX 0:85b3fd62ea1a 5117 /* Process Unlocked */
NYX 0:85b3fd62ea1a 5118 __HAL_UNLOCK(hcryp);
NYX 0:85b3fd62ea1a 5119
NYX 0:85b3fd62ea1a 5120 return HAL_OK;
NYX 0:85b3fd62ea1a 5121 }
NYX 0:85b3fd62ea1a 5122 else /* Process the rest of input data */
NYX 0:85b3fd62ea1a 5123 {
NYX 0:85b3fd62ea1a 5124 /* Get the Intput data address */
NYX 0:85b3fd62ea1a 5125 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
NYX 0:85b3fd62ea1a 5126
NYX 0:85b3fd62ea1a 5127 /* Increment/decrement instance pointer/counter */
NYX 0:85b3fd62ea1a 5128 hcryp->pCrypInBuffPtr += 16U;
NYX 0:85b3fd62ea1a 5129 hcryp->CrypInCount -= 16U;
NYX 0:85b3fd62ea1a 5130
NYX 0:85b3fd62ea1a 5131 /* Write the next input block in the Data Input register */
NYX 0:85b3fd62ea1a 5132 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 5133 inputaddr+=4U;
NYX 0:85b3fd62ea1a 5134 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 5135 inputaddr+=4U;
NYX 0:85b3fd62ea1a 5136 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 5137 inputaddr+=4U;
NYX 0:85b3fd62ea1a 5138 hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
NYX 0:85b3fd62ea1a 5139
NYX 0:85b3fd62ea1a 5140 return HAL_OK;
NYX 0:85b3fd62ea1a 5141 }
NYX 0:85b3fd62ea1a 5142 }
NYX 0:85b3fd62ea1a 5143 else
NYX 0:85b3fd62ea1a 5144 {
NYX 0:85b3fd62ea1a 5145 return HAL_BUSY;
NYX 0:85b3fd62ea1a 5146 }
NYX 0:85b3fd62ea1a 5147 }
NYX 0:85b3fd62ea1a 5148
NYX 0:85b3fd62ea1a 5149 /**
NYX 0:85b3fd62ea1a 5150 * @}
NYX 0:85b3fd62ea1a 5151 */
NYX 0:85b3fd62ea1a 5152
NYX 0:85b3fd62ea1a 5153 #endif /* AES */
NYX 0:85b3fd62ea1a 5154
NYX 0:85b3fd62ea1a 5155 #endif /* HAL_CRYP_MODULE_ENABLED */
NYX 0:85b3fd62ea1a 5156
NYX 0:85b3fd62ea1a 5157 /**
NYX 0:85b3fd62ea1a 5158 * @}
NYX 0:85b3fd62ea1a 5159 */
NYX 0:85b3fd62ea1a 5160
NYX 0:85b3fd62ea1a 5161 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/