2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_cryp.c
\r
4 * @author MCD Application Team
\r
6 * @date 24-March-2015
\r
7 * @brief CRYP HAL module driver.
\r
8 * This file provides firmware functions to manage the following
\r
9 * functionalities of the Cryptography (CRYP) peripheral:
\r
10 * + Initialization and de-initialization functions
\r
11 * + AES processing functions
\r
12 * + DES processing functions
\r
13 * + TDES processing functions
\r
14 * + DMA callback functions
\r
15 * + CRYP IRQ handler management
\r
16 * + Peripheral State functions
\r
19 ==============================================================================
\r
20 ##### How to use this driver #####
\r
21 ==============================================================================
\r
23 The CRYP HAL driver can be used as follows:
\r
25 (#)Initialize the CRYP low level resources by implementing the HAL_CRYP_MspInit():
\r
26 (##) Enable the CRYP interface clock using __HAL_RCC_CRYP_CLK_ENABLE()
\r
27 (##) In case of using interrupts (e.g. HAL_CRYP_AESECB_Encrypt_IT())
\r
28 (+++) Configure the CRYP interrupt priority using HAL_NVIC_SetPriority()
\r
29 (+++) Enable the CRYP IRQ handler using HAL_NVIC_EnableIRQ()
\r
30 (+++) In CRYP IRQ handler, call HAL_CRYP_IRQHandler()
\r
31 (##) In case of using DMA to control data transfer (e.g. HAL_CRYP_AESECB_Encrypt_DMA())
\r
32 (+++) Enable the DMAx interface clock using __DMAx_CLK_ENABLE()
\r
33 (+++) Configure and enable two DMA streams one for managing data transfer from
\r
34 memory to peripheral (input stream) and another stream for managing data
\r
35 transfer from peripheral to memory (output stream)
\r
36 (+++) Associate the initialized DMA handle to the CRYP DMA handle
\r
37 using __HAL_LINKDMA()
\r
38 (+++) Configure the priority and enable the NVIC for the transfer complete
\r
39 interrupt on the two DMA Streams. The output stream should have higher
\r
40 priority than the input stream HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
\r
42 (#)Initialize the CRYP HAL using HAL_CRYP_Init(). This function configures mainly:
\r
43 (##) The data type: 1-bit, 8-bit, 16-bit and 32-bit
\r
44 (##) The key size: 128, 192 and 256. This parameter is relevant only for AES
\r
45 (##) The encryption/decryption key. It's size depends on the algorithm
\r
46 used for encryption/decryption
\r
47 (##) The initialization vector (counter). It is not used ECB mode.
\r
49 (#)Three processing (encryption/decryption) functions are available:
\r
50 (##) Polling mode: encryption and decryption APIs are blocking functions
\r
51 i.e. they process the data and wait till the processing is finished,
\r
52 e.g. HAL_CRYP_AESCBC_Encrypt()
\r
53 (##) Interrupt mode: encryption and decryption APIs are not blocking functions
\r
54 i.e. they process the data under interrupt,
\r
55 e.g. HAL_CRYP_AESCBC_Encrypt_IT()
\r
56 (##) DMA mode: encryption and decryption APIs are not blocking functions
\r
57 i.e. the data transfer is ensured by DMA,
\r
58 e.g. HAL_CRYP_AESCBC_Encrypt_DMA()
\r
60 (#)When the processing function is called at first time after HAL_CRYP_Init()
\r
61 the CRYP peripheral is initialized and processes the buffer in input.
\r
62 At second call, the processing function performs an append of the already
\r
64 When a new data block is to be processed, call HAL_CRYP_Init() then the
\r
65 processing function.
\r
67 (#)Call HAL_CRYP_DeInit() to deinitialize the CRYP peripheral.
\r
70 ******************************************************************************
\r
73 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
75 * Redistribution and use in source and binary forms, with or without modification,
\r
76 * are permitted provided that the following conditions are met:
\r
77 * 1. Redistributions of source code must retain the above copyright notice,
\r
78 * this list of conditions and the following disclaimer.
\r
79 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
80 * this list of conditions and the following disclaimer in the documentation
\r
81 * and/or other materials provided with the distribution.
\r
82 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
83 * may be used to endorse or promote products derived from this software
\r
84 * without specific prior written permission.
\r
86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
89 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
92 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
93 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
94 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
95 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
97 ******************************************************************************
\r
100 /* Includes ------------------------------------------------------------------*/
\r
101 #include "stm32f7xx_hal.h"
\r
103 /** @addtogroup STM32F7xx_HAL_Driver
\r
107 /** @defgroup CRYP CRYP
\r
108 * @brief CRYP HAL module driver.
\r
112 #ifdef HAL_CRYP_MODULE_ENABLED
\r
114 #if defined(STM32F756xx)
\r
116 /* Private typedef -----------------------------------------------------------*/
\r
117 /* Private define ------------------------------------------------------------*/
\r
118 /** @addtogroup CRYP_Private_define
\r
121 #define CRYP_TIMEOUT_VALUE 1
\r
126 /* Private macro -------------------------------------------------------------*/
\r
127 /* Private variables ---------------------------------------------------------*/
\r
128 /* Private function prototypes -----------------------------------------------*/
\r
129 /** @addtogroup CRYP_Private_Functions_prototypes
\r
132 static void CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector, uint32_t IVSize);
\r
133 static void CRYP_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key, uint32_t KeySize);
\r
134 static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout);
\r
135 static HAL_StatusTypeDef CRYP_ProcessData2Words(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout);
\r
136 static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma);
\r
137 static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma);
\r
138 static void CRYP_DMAError(DMA_HandleTypeDef *hdma);
\r
139 static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr);
\r
140 static void CRYP_SetTDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction);
\r
141 static void CRYP_SetTDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction);
\r
142 static void CRYP_SetDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction);
\r
143 static void CRYP_SetDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction);
\r
147 /* Private functions ---------------------------------------------------------*/
\r
149 /** @addtogroup CRYP_Private_Functions
\r
154 * @brief DMA CRYP Input Data process complete callback.
\r
155 * @param hdma: DMA handle
\r
158 static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma)
\r
160 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
\r
162 /* Disable the DMA transfer for input FIFO request by resetting the DIEN bit
\r
163 in the DMACR register */
\r
164 hcryp->Instance->DMACR &= (uint32_t)(~CRYP_DMACR_DIEN);
\r
166 /* Call input data transfer complete callback */
\r
167 HAL_CRYP_InCpltCallback(hcryp);
\r
171 * @brief DMA CRYP Output Data process complete callback.
\r
172 * @param hdma: DMA handle
\r
175 static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma)
\r
177 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
\r
179 /* Disable the DMA transfer for output FIFO request by resetting the DOEN bit
\r
180 in the DMACR register */
\r
181 hcryp->Instance->DMACR &= (uint32_t)(~CRYP_DMACR_DOEN);
\r
184 __HAL_CRYP_DISABLE(hcryp);
\r
186 /* Change the CRYP state to ready */
\r
187 hcryp->State = HAL_CRYP_STATE_READY;
\r
189 /* Call output data transfer complete callback */
\r
190 HAL_CRYP_OutCpltCallback(hcryp);
\r
194 * @brief DMA CRYP communication error callback.
\r
195 * @param hdma: DMA handle
\r
198 static void CRYP_DMAError(DMA_HandleTypeDef *hdma)
\r
200 CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
\r
201 hcryp->State= HAL_CRYP_STATE_READY;
\r
202 HAL_CRYP_ErrorCallback(hcryp);
\r
206 * @brief Writes the Key in Key registers.
\r
207 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
208 * the configuration information for CRYP module
\r
209 * @param Key: Pointer to Key buffer
\r
210 * @param KeySize: Size of Key
\r
213 static void CRYP_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key, uint32_t KeySize)
\r
215 uint32_t keyaddr = (uint32_t)Key;
\r
219 case CRYP_KEYSIZE_256B:
\r
220 /* Key Initialisation */
\r
221 hcryp->Instance->K0LR = __REV(*(uint32_t*)(keyaddr));
\r
223 hcryp->Instance->K0RR = __REV(*(uint32_t*)(keyaddr));
\r
225 hcryp->Instance->K1LR = __REV(*(uint32_t*)(keyaddr));
\r
227 hcryp->Instance->K1RR = __REV(*(uint32_t*)(keyaddr));
\r
229 hcryp->Instance->K2LR = __REV(*(uint32_t*)(keyaddr));
\r
231 hcryp->Instance->K2RR = __REV(*(uint32_t*)(keyaddr));
\r
233 hcryp->Instance->K3LR = __REV(*(uint32_t*)(keyaddr));
\r
235 hcryp->Instance->K3RR = __REV(*(uint32_t*)(keyaddr));
\r
237 case CRYP_KEYSIZE_192B:
\r
238 hcryp->Instance->K1LR = __REV(*(uint32_t*)(keyaddr));
\r
240 hcryp->Instance->K1RR = __REV(*(uint32_t*)(keyaddr));
\r
242 hcryp->Instance->K2LR = __REV(*(uint32_t*)(keyaddr));
\r
244 hcryp->Instance->K2RR = __REV(*(uint32_t*)(keyaddr));
\r
246 hcryp->Instance->K3LR = __REV(*(uint32_t*)(keyaddr));
\r
248 hcryp->Instance->K3RR = __REV(*(uint32_t*)(keyaddr));
\r
250 case CRYP_KEYSIZE_128B:
\r
251 hcryp->Instance->K2LR = __REV(*(uint32_t*)(keyaddr));
\r
253 hcryp->Instance->K2RR = __REV(*(uint32_t*)(keyaddr));
\r
255 hcryp->Instance->K3LR = __REV(*(uint32_t*)(keyaddr));
\r
257 hcryp->Instance->K3RR = __REV(*(uint32_t*)(keyaddr));
\r
265 * @brief Writes the InitVector/InitCounter in IV registers.
\r
266 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
267 * the configuration information for CRYP module
\r
268 * @param InitVector: Pointer to InitVector/InitCounter buffer
\r
269 * @param IVSize: Size of the InitVector/InitCounter
\r
272 static void CRYP_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector, uint32_t IVSize)
\r
274 uint32_t ivaddr = (uint32_t)InitVector;
\r
278 case CRYP_KEYSIZE_128B:
\r
279 hcryp->Instance->IV0LR = __REV(*(uint32_t*)(ivaddr));
\r
281 hcryp->Instance->IV0RR = __REV(*(uint32_t*)(ivaddr));
\r
283 hcryp->Instance->IV1LR = __REV(*(uint32_t*)(ivaddr));
\r
285 hcryp->Instance->IV1RR = __REV(*(uint32_t*)(ivaddr));
\r
287 /* Whatever key size 192 or 256, Init vector is written in IV0LR and IV0RR */
\r
288 case CRYP_KEYSIZE_192B:
\r
289 hcryp->Instance->IV0LR = __REV(*(uint32_t*)(ivaddr));
\r
291 hcryp->Instance->IV0RR = __REV(*(uint32_t*)(ivaddr));
\r
293 case CRYP_KEYSIZE_256B:
\r
294 hcryp->Instance->IV0LR = __REV(*(uint32_t*)(ivaddr));
\r
296 hcryp->Instance->IV0RR = __REV(*(uint32_t*)(ivaddr));
\r
304 * @brief Process Data: Writes Input data in polling mode and read the output data
\r
305 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
306 * the configuration information for CRYP module
\r
307 * @param Input: Pointer to the Input buffer
\r
308 * @param Ilength: Length of the Input buffer, must be a multiple of 16.
\r
309 * @param Output: Pointer to the returned buffer
\r
310 * @param Timeout: Timeout value
\r
313 static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout)
\r
315 uint32_t tickstart = 0;
\r
318 uint32_t inputaddr = (uint32_t)Input;
\r
319 uint32_t outputaddr = (uint32_t)Output;
\r
321 for(i=0; (i < Ilength); i+=16)
\r
323 /* Write the Input block in the IN FIFO */
\r
324 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
326 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
328 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
330 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
334 tickstart = HAL_GetTick();
\r
336 while(HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE))
\r
338 /* Check for the Timeout */
\r
339 if(Timeout != HAL_MAX_DELAY)
\r
341 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
344 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
346 /* Process Unlocked */
\r
347 __HAL_UNLOCK(hcryp);
\r
349 return HAL_TIMEOUT;
\r
353 /* Read the Output block from the Output FIFO */
\r
354 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
356 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
358 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
360 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
363 /* Return function status */
\r
368 * @brief Process Data: Write Input data in polling mode.
\r
369 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
370 * the configuration information for CRYP module
\r
371 * @param Input: Pointer to the Input buffer
\r
372 * @param Ilength: Length of the Input buffer, must be a multiple of 8
\r
373 * @param Output: Pointer to the returned buffer
\r
374 * @param Timeout: Specify Timeout value
\r
377 static HAL_StatusTypeDef CRYP_ProcessData2Words(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout)
\r
379 uint32_t tickstart = 0;
\r
382 uint32_t inputaddr = (uint32_t)Input;
\r
383 uint32_t outputaddr = (uint32_t)Output;
\r
385 for(i=0; (i < Ilength); i+=8)
\r
387 /* Write the Input block in the IN FIFO */
\r
388 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
390 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
394 tickstart = HAL_GetTick();
\r
396 while(HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE))
\r
398 /* Check for the Timeout */
\r
399 if(Timeout != HAL_MAX_DELAY)
\r
401 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
404 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
406 /* Process Unlocked */
\r
407 __HAL_UNLOCK(hcryp);
\r
409 return HAL_TIMEOUT;
\r
413 /* Read the Output block from the Output FIFO */
\r
414 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
416 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
419 /* Return function status */
\r
424 * @brief Set the DMA configuration and start the DMA transfer
\r
425 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
426 * the configuration information for CRYP module
\r
427 * @param inputaddr: address of the Input buffer
\r
428 * @param Size: Size of the Input buffer, must be a multiple of 16.
\r
429 * @param outputaddr: address of the Output buffer
\r
432 static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr)
\r
434 /* Set the CRYP DMA transfer complete callback */
\r
435 hcryp->hdmain->XferCpltCallback = CRYP_DMAInCplt;
\r
436 /* Set the DMA error callback */
\r
437 hcryp->hdmain->XferErrorCallback = CRYP_DMAError;
\r
439 /* Set the CRYP DMA transfer complete callback */
\r
440 hcryp->hdmaout->XferCpltCallback = CRYP_DMAOutCplt;
\r
441 /* Set the DMA error callback */
\r
442 hcryp->hdmaout->XferErrorCallback = CRYP_DMAError;
\r
445 __HAL_CRYP_ENABLE(hcryp);
\r
447 /* Enable the DMA In DMA Stream */
\r
448 HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DR, Size/4);
\r
450 /* Enable In DMA request */
\r
451 hcryp->Instance->DMACR = (CRYP_DMACR_DIEN);
\r
453 /* Enable the DMA Out DMA Stream */
\r
454 HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUT, outputaddr, Size/4);
\r
456 /* Enable Out DMA request */
\r
457 hcryp->Instance->DMACR |= CRYP_DMACR_DOEN;
\r
462 * @brief Sets the CRYP peripheral in DES ECB mode.
\r
463 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
464 * the configuration information for CRYP module
\r
465 * @param Direction: Encryption or decryption
\r
468 static void CRYP_SetDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
\r
470 /* Check if initialization phase has already been performed */
\r
471 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
473 /* Set the CRYP peripheral in AES ECB mode */
\r
474 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_DES_ECB | Direction);
\r
477 hcryp->Instance->K1LR = __REV(*(uint32_t*)(hcryp->Init.pKey));
\r
478 hcryp->Instance->K1RR = __REV(*(uint32_t*)(hcryp->Init.pKey+4));
\r
481 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
483 /* Set the phase */
\r
484 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
489 * @brief Sets the CRYP peripheral in DES CBC mode.
\r
490 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
491 * the configuration information for CRYP module
\r
492 * @param Direction: Encryption or decryption
\r
495 static void CRYP_SetDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
\r
497 /* Check if initialization phase has already been performed */
\r
498 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
500 /* Set the CRYP peripheral in AES ECB mode */
\r
501 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_DES_CBC | Direction);
\r
504 hcryp->Instance->K1LR = __REV(*(uint32_t*)(hcryp->Init.pKey));
\r
505 hcryp->Instance->K1RR = __REV(*(uint32_t*)(hcryp->Init.pKey+4));
\r
507 /* Set the Initialization Vector */
\r
508 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_256B);
\r
511 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
513 /* Set the phase */
\r
514 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
519 * @brief Sets the CRYP peripheral in TDES ECB mode.
\r
520 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
521 * the configuration information for CRYP module
\r
522 * @param Direction: Encryption or decryption
\r
525 static void CRYP_SetTDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
\r
527 /* Check if initialization phase has already been performed */
\r
528 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
530 /* Set the CRYP peripheral in AES ECB mode */
\r
531 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_TDES_ECB | Direction);
\r
534 CRYP_SetKey(hcryp, hcryp->Init.pKey, CRYP_KEYSIZE_192B);
\r
537 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
539 /* Set the phase */
\r
540 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
545 * @brief Sets the CRYP peripheral in TDES CBC mode
\r
546 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
547 * the configuration information for CRYP module
\r
548 * @param Direction: Encryption or decryption
\r
551 static void CRYP_SetTDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
\r
553 /* Check if initialization phase has already been performed */
\r
554 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
556 /* Set the CRYP peripheral in AES CBC mode */
\r
557 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_TDES_CBC | Direction);
\r
560 CRYP_SetKey(hcryp, hcryp->Init.pKey, CRYP_KEYSIZE_192B);
\r
562 /* Set the Initialization Vector */
\r
563 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_256B);
\r
566 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
568 /* Set the phase */
\r
569 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
577 /* Exported functions --------------------------------------------------------*/
\r
578 /** @addtogroup CRYP_Exported_Functions
\r
582 /** @defgroup CRYP_Exported_Functions_Group1 Initialization and de-initialization functions
\r
583 * @brief Initialization and Configuration functions.
\r
586 ==============================================================================
\r
587 ##### Initialization and de-initialization functions #####
\r
588 ==============================================================================
\r
589 [..] This section provides functions allowing to:
\r
590 (+) Initialize the CRYP according to the specified parameters
\r
591 in the CRYP_InitTypeDef and creates the associated handle
\r
592 (+) DeInitialize the CRYP peripheral
\r
593 (+) Initialize the CRYP MSP
\r
594 (+) DeInitialize CRYP MSP
\r
601 * @brief Initializes the CRYP according to the specified
\r
602 * parameters in the CRYP_InitTypeDef and creates the associated handle.
\r
603 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
604 * the configuration information for CRYP module
\r
605 * @retval HAL status
\r
607 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp)
\r
609 /* Check the CRYP handle allocation */
\r
615 /* Check the parameters */
\r
616 assert_param(IS_CRYP_KEYSIZE(hcryp->Init.KeySize));
\r
617 assert_param(IS_CRYP_DATATYPE(hcryp->Init.DataType));
\r
619 if(hcryp->State == HAL_CRYP_STATE_RESET)
\r
621 /* Allocate lock resource and initialize it */
\r
622 hcryp->Lock = HAL_UNLOCKED;
\r
623 /* Init the low level hardware */
\r
624 HAL_CRYP_MspInit(hcryp);
\r
627 /* Change the CRYP state */
\r
628 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
630 /* Set the key size and data type*/
\r
631 CRYP->CR = (uint32_t) (hcryp->Init.KeySize | hcryp->Init.DataType);
\r
633 /* Reset CrypInCount and CrypOutCount */
\r
634 hcryp->CrypInCount = 0;
\r
635 hcryp->CrypOutCount = 0;
\r
637 /* Change the CRYP state */
\r
638 hcryp->State = HAL_CRYP_STATE_READY;
\r
640 /* Set the default CRYP phase */
\r
641 hcryp->Phase = HAL_CRYP_PHASE_READY;
\r
643 /* Return function status */
\r
648 * @brief DeInitializes the CRYP peripheral.
\r
649 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
650 * the configuration information for CRYP module
\r
651 * @retval HAL status
\r
653 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp)
\r
655 /* Check the CRYP handle allocation */
\r
661 /* Change the CRYP state */
\r
662 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
664 /* Set the default CRYP phase */
\r
665 hcryp->Phase = HAL_CRYP_PHASE_READY;
\r
667 /* Reset CrypInCount and CrypOutCount */
\r
668 hcryp->CrypInCount = 0;
\r
669 hcryp->CrypOutCount = 0;
\r
671 /* Disable the CRYP Peripheral Clock */
\r
672 __HAL_CRYP_DISABLE(hcryp);
\r
674 /* DeInit the low level hardware: CLOCK, NVIC.*/
\r
675 HAL_CRYP_MspDeInit(hcryp);
\r
677 /* Change the CRYP state */
\r
678 hcryp->State = HAL_CRYP_STATE_RESET;
\r
681 __HAL_UNLOCK(hcryp);
\r
683 /* Return function status */
\r
688 * @brief Initializes the CRYP MSP.
\r
689 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
690 * the configuration information for CRYP module
\r
693 __weak void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp)
\r
695 /* NOTE : This function Should not be modified, when the callback is needed,
\r
696 the HAL_CRYP_MspInit could be implemented in the user file
\r
701 * @brief DeInitializes CRYP MSP.
\r
702 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
703 * the configuration information for CRYP module
\r
706 __weak void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp)
\r
708 /* NOTE : This function Should not be modified, when the callback is needed,
\r
709 the HAL_CRYP_MspDeInit could be implemented in the user file
\r
717 /** @defgroup CRYP_Exported_Functions_Group2 AES processing functions
\r
718 * @brief processing functions.
\r
721 ==============================================================================
\r
722 ##### AES processing functions #####
\r
723 ==============================================================================
\r
724 [..] This section provides functions allowing to:
\r
725 (+) Encrypt plaintext using AES-128/192/256 using chaining modes
\r
726 (+) Decrypt cyphertext using AES-128/192/256 using chaining modes
\r
727 [..] Three processing functions are available:
\r
737 * @brief Initializes the CRYP peripheral in AES ECB encryption mode
\r
738 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
739 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
740 * the configuration information for CRYP module
\r
741 * @param pPlainData: Pointer to the plaintext buffer
\r
742 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
743 * @param pCypherData: Pointer to the cyphertext buffer
\r
744 * @param Timeout: Specify Timeout value
\r
745 * @retval HAL status
\r
747 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
749 /* Process Locked */
\r
752 /* Change the CRYP state */
\r
753 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
755 /* Check if initialization phase has already been performed */
\r
756 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
759 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
761 /* Set the CRYP peripheral in AES ECB mode */
\r
762 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB);
\r
765 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
768 __HAL_CRYP_ENABLE(hcryp);
\r
770 /* Set the phase */
\r
771 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
774 /* Write Plain Data and Get Cypher Data */
\r
775 if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
777 return HAL_TIMEOUT;
\r
780 /* Change the CRYP state */
\r
781 hcryp->State = HAL_CRYP_STATE_READY;
\r
783 /* Process Unlocked */
\r
784 __HAL_UNLOCK(hcryp);
\r
786 /* Return function status */
\r
791 * @brief Initializes the CRYP peripheral in AES CBC encryption mode
\r
792 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
793 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
794 * the configuration information for CRYP module
\r
795 * @param pPlainData: Pointer to the plaintext buffer
\r
796 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
797 * @param pCypherData: Pointer to the cyphertext buffer
\r
798 * @param Timeout: Specify Timeout value
\r
799 * @retval HAL status
\r
801 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
803 /* Process Locked */
\r
806 /* Change the CRYP state */
\r
807 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
809 /* Check if initialization phase has already been performed */
\r
810 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
813 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
815 /* Set the CRYP peripheral in AES ECB mode */
\r
816 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC);
\r
818 /* Set the Initialization Vector */
\r
819 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
822 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
825 __HAL_CRYP_ENABLE(hcryp);
\r
827 /* Set the phase */
\r
828 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
831 /* Write Plain Data and Get Cypher Data */
\r
832 if(CRYP_ProcessData(hcryp,pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
834 return HAL_TIMEOUT;
\r
837 /* Change the CRYP state */
\r
838 hcryp->State = HAL_CRYP_STATE_READY;
\r
840 /* Process Unlocked */
\r
841 __HAL_UNLOCK(hcryp);
\r
843 /* Return function status */
\r
848 * @brief Initializes the CRYP peripheral in AES CTR encryption mode
\r
849 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
850 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
851 * the configuration information for CRYP module
\r
852 * @param pPlainData: Pointer to the plaintext buffer
\r
853 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
854 * @param pCypherData: Pointer to the cyphertext buffer
\r
855 * @param Timeout: Specify Timeout value
\r
856 * @retval HAL status
\r
858 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
860 /* Process Locked */
\r
863 /* Change the CRYP state */
\r
864 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
866 /* Check if initialization phase has already been performed */
\r
867 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
870 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
872 /* Set the CRYP peripheral in AES ECB mode */
\r
873 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR);
\r
875 /* Set the Initialization Vector */
\r
876 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
879 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
882 __HAL_CRYP_ENABLE(hcryp);
\r
884 /* Set the phase */
\r
885 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
888 /* Write Plain Data and Get Cypher Data */
\r
889 if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
891 return HAL_TIMEOUT;
\r
894 /* Change the CRYP state */
\r
895 hcryp->State = HAL_CRYP_STATE_READY;
\r
897 /* Process Unlocked */
\r
898 __HAL_UNLOCK(hcryp);
\r
900 /* Return function status */
\r
907 * @brief Initializes the CRYP peripheral in AES ECB decryption mode
\r
908 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
909 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
910 * the configuration information for CRYP module
\r
911 * @param pCypherData: Pointer to the cyphertext buffer
\r
912 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
913 * @param pPlainData: Pointer to the plaintext buffer
\r
914 * @param Timeout: Specify Timeout value
\r
915 * @retval HAL status
\r
917 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
919 uint32_t tickstart = 0;
\r
921 /* Process Locked */
\r
924 /* Change the CRYP state */
\r
925 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
927 /* Check if initialization phase has already been performed */
\r
928 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
931 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
933 /* Set the CRYP peripheral in AES Key mode */
\r
934 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
937 __HAL_CRYP_ENABLE(hcryp);
\r
940 tickstart = HAL_GetTick();
\r
942 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
\r
944 /* Check for the Timeout */
\r
945 if(Timeout != HAL_MAX_DELAY)
\r
947 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
950 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
952 /* Process Unlocked */
\r
953 __HAL_UNLOCK(hcryp);
\r
955 return HAL_TIMEOUT;
\r
961 __HAL_CRYP_DISABLE(hcryp);
\r
963 /* Reset the ALGOMODE bits*/
\r
964 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
966 /* Set the CRYP peripheral in AES ECB decryption mode */
\r
967 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
\r
969 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
972 __HAL_CRYP_ENABLE(hcryp);
\r
974 /* Set the phase */
\r
975 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
978 /* Write Plain Data and Get Cypher Data */
\r
979 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
981 return HAL_TIMEOUT;
\r
984 /* Change the CRYP state */
\r
985 hcryp->State = HAL_CRYP_STATE_READY;
\r
987 /* Process Unlocked */
\r
988 __HAL_UNLOCK(hcryp);
\r
990 /* Return function status */
\r
995 * @brief Initializes the CRYP peripheral in AES ECB decryption mode
\r
996 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
997 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
998 * the configuration information for CRYP module
\r
999 * @param pCypherData: Pointer to the cyphertext buffer
\r
1000 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1001 * @param pPlainData: Pointer to the plaintext buffer
\r
1002 * @param Timeout: Specify Timeout value
\r
1003 * @retval HAL status
\r
1005 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
1007 uint32_t tickstart = 0;
\r
1009 /* Process Locked */
\r
1010 __HAL_LOCK(hcryp);
\r
1012 /* Change the CRYP state */
\r
1013 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1015 /* Check if initialization phase has already been performed */
\r
1016 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1019 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1021 /* Set the CRYP peripheral in AES Key mode */
\r
1022 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
1025 __HAL_CRYP_ENABLE(hcryp);
\r
1028 tickstart = HAL_GetTick();
\r
1030 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
\r
1032 /* Check for the Timeout */
\r
1033 if(Timeout != HAL_MAX_DELAY)
\r
1035 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
1037 /* Change state */
\r
1038 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
1040 /* Process Unlocked */
\r
1041 __HAL_UNLOCK(hcryp);
\r
1043 return HAL_TIMEOUT;
\r
1048 /* Reset the ALGOMODE bits*/
\r
1049 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
1051 /* Set the CRYP peripheral in AES CBC decryption mode */
\r
1052 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
\r
1054 /* Set the Initialization Vector */
\r
1055 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1058 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1061 __HAL_CRYP_ENABLE(hcryp);
\r
1063 /* Set the phase */
\r
1064 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1067 /* Write Plain Data and Get Cypher Data */
\r
1068 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
1070 return HAL_TIMEOUT;
\r
1073 /* Change the CRYP state */
\r
1074 hcryp->State = HAL_CRYP_STATE_READY;
\r
1076 /* Process Unlocked */
\r
1077 __HAL_UNLOCK(hcryp);
\r
1079 /* Return function status */
\r
1084 * @brief Initializes the CRYP peripheral in AES CTR decryption mode
\r
1085 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
1086 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1087 * the configuration information for CRYP module
\r
1088 * @param pCypherData: Pointer to the cyphertext buffer
\r
1089 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1090 * @param pPlainData: Pointer to the plaintext buffer
\r
1091 * @param Timeout: Specify Timeout value
\r
1092 * @retval HAL status
\r
1094 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
1096 /* Process Locked */
\r
1097 __HAL_LOCK(hcryp);
\r
1099 /* Check if initialization phase has already been performed */
\r
1100 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1102 /* Change the CRYP state */
\r
1103 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1106 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1108 /* Set the CRYP peripheral in AES CTR mode */
\r
1109 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
\r
1111 /* Set the Initialization Vector */
\r
1112 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1115 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1118 __HAL_CRYP_ENABLE(hcryp);
\r
1120 /* Set the phase */
\r
1121 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1124 /* Write Plain Data and Get Cypher Data */
\r
1125 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
1127 return HAL_TIMEOUT;
\r
1130 /* Change the CRYP state */
\r
1131 hcryp->State = HAL_CRYP_STATE_READY;
\r
1133 /* Process Unlocked */
\r
1134 __HAL_UNLOCK(hcryp);
\r
1136 /* Return function status */
\r
1141 * @brief Initializes the CRYP peripheral in AES ECB encryption mode using Interrupt.
\r
1142 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1143 * the configuration information for CRYP module
\r
1144 * @param pPlainData: Pointer to the plaintext buffer
\r
1145 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1146 * @param pCypherData: Pointer to the cyphertext buffer
\r
1147 * @retval HAL status
\r
1149 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1151 uint32_t inputaddr;
\r
1152 uint32_t outputaddr;
\r
1154 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1156 /* Process Locked */
\r
1157 __HAL_LOCK(hcryp);
\r
1159 hcryp->CrypInCount = Size;
\r
1160 hcryp->pCrypInBuffPtr = pPlainData;
\r
1161 hcryp->pCrypOutBuffPtr = pCypherData;
\r
1162 hcryp->CrypOutCount = Size;
\r
1164 /* Change the CRYP state */
\r
1165 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1167 /* Check if initialization phase has already been performed */
\r
1168 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1171 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1173 /* Set the CRYP peripheral in AES ECB mode */
\r
1174 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB);
\r
1177 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1179 /* Set the phase */
\r
1180 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1183 /* Enable Interrupts */
\r
1184 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
1187 __HAL_CRYP_ENABLE(hcryp);
\r
1189 /* Return function status */
\r
1192 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
1194 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1195 /* Write the Input block in the IN FIFO */
\r
1196 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1198 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1200 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1202 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1203 hcryp->pCrypInBuffPtr += 16;
\r
1204 hcryp->CrypInCount -= 16;
\r
1205 if(hcryp->CrypInCount == 0)
\r
1207 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
1208 /* Call the Input data transfer complete callback */
\r
1209 HAL_CRYP_InCpltCallback(hcryp);
\r
1212 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
1214 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1215 /* Read the Output block from the Output FIFO */
\r
1216 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1218 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1220 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1222 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1223 hcryp->pCrypOutBuffPtr += 16;
\r
1224 hcryp->CrypOutCount -= 16;
\r
1225 if(hcryp->CrypOutCount == 0)
\r
1227 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
1228 /* Process Locked */
\r
1229 __HAL_UNLOCK(hcryp);
\r
1230 /* Change the CRYP state */
\r
1231 hcryp->State = HAL_CRYP_STATE_READY;
\r
1232 /* Call Input transfer complete callback */
\r
1233 HAL_CRYP_OutCpltCallback(hcryp);
\r
1237 /* Return function status */
\r
1242 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using Interrupt.
\r
1243 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1244 * the configuration information for CRYP module
\r
1245 * @param pPlainData: Pointer to the plaintext buffer
\r
1246 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1247 * @param pCypherData: Pointer to the cyphertext buffer
\r
1248 * @retval HAL status
\r
1250 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1252 uint32_t inputaddr;
\r
1253 uint32_t outputaddr;
\r
1255 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1257 /* Process Locked */
\r
1258 __HAL_LOCK(hcryp);
\r
1260 hcryp->CrypInCount = Size;
\r
1261 hcryp->pCrypInBuffPtr = pPlainData;
\r
1262 hcryp->pCrypOutBuffPtr = pCypherData;
\r
1263 hcryp->CrypOutCount = Size;
\r
1265 /* Change the CRYP state */
\r
1266 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1268 /* Check if initialization phase has already been performed */
\r
1269 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1272 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1274 /* Set the CRYP peripheral in AES CBC mode */
\r
1275 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC);
\r
1277 /* Set the Initialization Vector */
\r
1278 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1281 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1283 /* Set the phase */
\r
1284 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1286 /* Enable Interrupts */
\r
1287 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
1290 __HAL_CRYP_ENABLE(hcryp);
\r
1292 /* Return function status */
\r
1295 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
1297 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1298 /* Write the Input block in the IN FIFO */
\r
1299 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1301 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1303 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1305 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1306 hcryp->pCrypInBuffPtr += 16;
\r
1307 hcryp->CrypInCount -= 16;
\r
1308 if(hcryp->CrypInCount == 0)
\r
1310 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
1311 /* Call the Input data transfer complete callback */
\r
1312 HAL_CRYP_InCpltCallback(hcryp);
\r
1315 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
1317 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1318 /* Read the Output block from the Output FIFO */
\r
1319 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1321 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1323 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1325 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1326 hcryp->pCrypOutBuffPtr += 16;
\r
1327 hcryp->CrypOutCount -= 16;
\r
1328 if(hcryp->CrypOutCount == 0)
\r
1330 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
1331 /* Process Locked */
\r
1332 __HAL_UNLOCK(hcryp);
\r
1333 /* Change the CRYP state */
\r
1334 hcryp->State = HAL_CRYP_STATE_READY;
\r
1335 /* Call Input transfer complete callback */
\r
1336 HAL_CRYP_OutCpltCallback(hcryp);
\r
1340 /* Return function status */
\r
1345 * @brief Initializes the CRYP peripheral in AES CTR encryption mode using Interrupt.
\r
1346 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1347 * the configuration information for CRYP module
\r
1348 * @param pPlainData: Pointer to the plaintext buffer
\r
1349 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1350 * @param pCypherData: Pointer to the cyphertext buffer
\r
1351 * @retval HAL status
\r
1353 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1355 uint32_t inputaddr;
\r
1356 uint32_t outputaddr;
\r
1358 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1360 /* Process Locked */
\r
1361 __HAL_LOCK(hcryp);
\r
1363 hcryp->CrypInCount = Size;
\r
1364 hcryp->pCrypInBuffPtr = pPlainData;
\r
1365 hcryp->pCrypOutBuffPtr = pCypherData;
\r
1366 hcryp->CrypOutCount = Size;
\r
1368 /* Change the CRYP state */
\r
1369 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1371 /* Check if initialization phase has already been performed */
\r
1372 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1375 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1377 /* Set the CRYP peripheral in AES CTR mode */
\r
1378 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR);
\r
1380 /* Set the Initialization Vector */
\r
1381 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1384 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1386 /* Set the phase */
\r
1387 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1389 /* Enable Interrupts */
\r
1390 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
1393 __HAL_CRYP_ENABLE(hcryp);
\r
1395 /* Return function status */
\r
1398 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
1400 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1401 /* Write the Input block in the IN FIFO */
\r
1402 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1404 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1406 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1408 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1409 hcryp->pCrypInBuffPtr += 16;
\r
1410 hcryp->CrypInCount -= 16;
\r
1411 if(hcryp->CrypInCount == 0)
\r
1413 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
1414 /* Call the Input data transfer complete callback */
\r
1415 HAL_CRYP_InCpltCallback(hcryp);
\r
1418 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
1420 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1421 /* Read the Output block from the Output FIFO */
\r
1422 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1424 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1426 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1428 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1429 hcryp->pCrypOutBuffPtr += 16;
\r
1430 hcryp->CrypOutCount -= 16;
\r
1431 if(hcryp->CrypOutCount == 0)
\r
1433 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
1434 /* Process Unlocked */
\r
1435 __HAL_UNLOCK(hcryp);
\r
1436 /* Change the CRYP state */
\r
1437 hcryp->State = HAL_CRYP_STATE_READY;
\r
1438 /* Call Input transfer complete callback */
\r
1439 HAL_CRYP_OutCpltCallback(hcryp);
\r
1443 /* Return function status */
\r
1449 * @brief Initializes the CRYP peripheral in AES ECB decryption mode using Interrupt.
\r
1450 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1451 * the configuration information for CRYP module
\r
1452 * @param pCypherData: Pointer to the cyphertext buffer
\r
1453 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1454 * @param pPlainData: Pointer to the plaintext buffer
\r
1455 * @retval HAL status
\r
1457 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
1459 uint32_t tickstart = 0;
\r
1461 uint32_t inputaddr;
\r
1462 uint32_t outputaddr;
\r
1464 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1466 /* Process Locked */
\r
1467 __HAL_LOCK(hcryp);
\r
1469 hcryp->CrypInCount = Size;
\r
1470 hcryp->pCrypInBuffPtr = pCypherData;
\r
1471 hcryp->pCrypOutBuffPtr = pPlainData;
\r
1472 hcryp->CrypOutCount = Size;
\r
1474 /* Change the CRYP state */
\r
1475 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1477 /* Check if initialization phase has already been performed */
\r
1478 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1481 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1483 /* Set the CRYP peripheral in AES Key mode */
\r
1484 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
1486 __HAL_CRYP_ENABLE(hcryp);
\r
1489 tickstart = HAL_GetTick();
\r
1491 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
\r
1493 /* Check for the Timeout */
\r
1494 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
\r
1496 /* Change state */
\r
1497 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
1499 /* Process Unlocked */
\r
1500 __HAL_UNLOCK(hcryp);
\r
1502 return HAL_TIMEOUT;
\r
1506 /* Reset the ALGOMODE bits*/
\r
1507 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
1509 /* Set the CRYP peripheral in AES ECB decryption mode */
\r
1510 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
\r
1513 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1515 /* Set the phase */
\r
1516 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1519 /* Enable Interrupts */
\r
1520 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
1523 __HAL_CRYP_ENABLE(hcryp);
\r
1525 /* Return function status */
\r
1528 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
1530 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1531 /* Write the Input block in the IN FIFO */
\r
1532 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1534 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1536 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1538 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1539 hcryp->pCrypInBuffPtr += 16;
\r
1540 hcryp->CrypInCount -= 16;
\r
1541 if(hcryp->CrypInCount == 0)
\r
1543 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
1544 /* Call the Input data transfer complete callback */
\r
1545 HAL_CRYP_InCpltCallback(hcryp);
\r
1548 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
1550 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1551 /* Read the Output block from the Output FIFO */
\r
1552 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1554 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1556 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1558 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1559 hcryp->pCrypOutBuffPtr += 16;
\r
1560 hcryp->CrypOutCount -= 16;
\r
1561 if(hcryp->CrypOutCount == 0)
\r
1563 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
1564 /* Process Unlocked */
\r
1565 __HAL_UNLOCK(hcryp);
\r
1566 /* Change the CRYP state */
\r
1567 hcryp->State = HAL_CRYP_STATE_READY;
\r
1568 /* Call Input transfer complete callback */
\r
1569 HAL_CRYP_OutCpltCallback(hcryp);
\r
1573 /* Return function status */
\r
1578 * @brief Initializes the CRYP peripheral in AES CBC decryption mode using IT.
\r
1579 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1580 * the configuration information for CRYP module
\r
1581 * @param pCypherData: Pointer to the cyphertext buffer
\r
1582 * @param Size: Length of the plaintext buffer, must be a multiple of 16
\r
1583 * @param pPlainData: Pointer to the plaintext buffer
\r
1584 * @retval HAL status
\r
1586 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
1589 uint32_t tickstart = 0;
\r
1590 uint32_t inputaddr;
\r
1591 uint32_t outputaddr;
\r
1593 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1595 /* Process Locked */
\r
1596 __HAL_LOCK(hcryp);
\r
1598 /* Get the buffer addresses and sizes */
\r
1599 hcryp->CrypInCount = Size;
\r
1600 hcryp->pCrypInBuffPtr = pCypherData;
\r
1601 hcryp->pCrypOutBuffPtr = pPlainData;
\r
1602 hcryp->CrypOutCount = Size;
\r
1604 /* Change the CRYP state */
\r
1605 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1607 /* Check if initialization phase has already been performed */
\r
1608 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1611 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1613 /* Set the CRYP peripheral in AES Key mode */
\r
1614 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
1617 __HAL_CRYP_ENABLE(hcryp);
\r
1620 tickstart = HAL_GetTick();
\r
1622 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
\r
1624 /* Check for the Timeout */
\r
1625 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
\r
1627 /* Change state */
\r
1628 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
1630 /* Process Unlocked */
\r
1631 __HAL_UNLOCK(hcryp);
\r
1633 return HAL_TIMEOUT;
\r
1637 /* Reset the ALGOMODE bits*/
\r
1638 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
1640 /* Set the CRYP peripheral in AES CBC decryption mode */
\r
1641 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
\r
1643 /* Set the Initialization Vector */
\r
1644 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1647 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1650 __HAL_CRYP_ENABLE(hcryp);
\r
1652 /* Set the phase */
\r
1653 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1656 /* Enable Interrupts */
\r
1657 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
1660 __HAL_CRYP_ENABLE(hcryp);
\r
1662 /* Return function status */
\r
1665 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
1667 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1668 /* Write the Input block in the IN FIFO */
\r
1669 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1671 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1673 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1675 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1676 hcryp->pCrypInBuffPtr += 16;
\r
1677 hcryp->CrypInCount -= 16;
\r
1678 if(hcryp->CrypInCount == 0)
\r
1680 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
1681 /* Call the Input data transfer complete callback */
\r
1682 HAL_CRYP_InCpltCallback(hcryp);
\r
1685 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
1687 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1688 /* Read the Output block from the Output FIFO */
\r
1689 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1691 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1693 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1695 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1696 hcryp->pCrypOutBuffPtr += 16;
\r
1697 hcryp->CrypOutCount -= 16;
\r
1698 if(hcryp->CrypOutCount == 0)
\r
1700 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
1701 /* Process Unlocked */
\r
1702 __HAL_UNLOCK(hcryp);
\r
1703 /* Change the CRYP state */
\r
1704 hcryp->State = HAL_CRYP_STATE_READY;
\r
1705 /* Call Input transfer complete callback */
\r
1706 HAL_CRYP_OutCpltCallback(hcryp);
\r
1710 /* Return function status */
\r
1715 * @brief Initializes the CRYP peripheral in AES CTR decryption mode using Interrupt.
\r
1716 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1717 * the configuration information for CRYP module
\r
1718 * @param pCypherData: Pointer to the cyphertext buffer
\r
1719 * @param Size: Length of the plaintext buffer, must be a multiple of 16
\r
1720 * @param pPlainData: Pointer to the plaintext buffer
\r
1721 * @retval HAL status
\r
1723 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
1725 uint32_t inputaddr;
\r
1726 uint32_t outputaddr;
\r
1728 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1730 /* Process Locked */
\r
1731 __HAL_LOCK(hcryp);
\r
1733 /* Get the buffer addresses and sizes */
\r
1734 hcryp->CrypInCount = Size;
\r
1735 hcryp->pCrypInBuffPtr = pCypherData;
\r
1736 hcryp->pCrypOutBuffPtr = pPlainData;
\r
1737 hcryp->CrypOutCount = Size;
\r
1739 /* Change the CRYP state */
\r
1740 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1742 /* Check if initialization phase has already been performed */
\r
1743 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1746 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1748 /* Set the CRYP peripheral in AES CTR mode */
\r
1749 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
\r
1751 /* Set the Initialization Vector */
\r
1752 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1755 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1757 /* Set the phase */
\r
1758 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1761 /* Enable Interrupts */
\r
1762 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
1765 __HAL_CRYP_ENABLE(hcryp);
\r
1767 /* Return function status */
\r
1770 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
1772 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1773 /* Write the Input block in the IN FIFO */
\r
1774 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1776 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1778 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1780 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
1781 hcryp->pCrypInBuffPtr += 16;
\r
1782 hcryp->CrypInCount -= 16;
\r
1783 if(hcryp->CrypInCount == 0)
\r
1785 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
1786 /* Call the Input data transfer complete callback */
\r
1787 HAL_CRYP_InCpltCallback(hcryp);
\r
1790 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
1792 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1793 /* Read the Output block from the Output FIFO */
\r
1794 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1796 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1798 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1800 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
1801 hcryp->pCrypOutBuffPtr += 16;
\r
1802 hcryp->CrypOutCount -= 16;
\r
1803 if(hcryp->CrypOutCount == 0)
\r
1805 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
1806 /* Process Unlocked */
\r
1807 __HAL_UNLOCK(hcryp);
\r
1808 /* Change the CRYP state */
\r
1809 hcryp->State = HAL_CRYP_STATE_READY;
\r
1810 /* Call Input transfer complete callback */
\r
1811 HAL_CRYP_OutCpltCallback(hcryp);
\r
1815 /* Return function status */
\r
1820 * @brief Initializes the CRYP peripheral in AES ECB encryption mode using DMA.
\r
1821 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1822 * the configuration information for CRYP module
\r
1823 * @param pPlainData: Pointer to the plaintext buffer
\r
1824 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1825 * @param pCypherData: Pointer to the cyphertext buffer
\r
1826 * @retval HAL status
\r
1828 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1830 uint32_t inputaddr;
\r
1831 uint32_t outputaddr;
\r
1833 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
1835 /* Process Locked */
\r
1836 __HAL_LOCK(hcryp);
\r
1838 inputaddr = (uint32_t)pPlainData;
\r
1839 outputaddr = (uint32_t)pCypherData;
\r
1841 /* Change the CRYP state */
\r
1842 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1844 /* Check if initialization phase has already been performed */
\r
1845 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1848 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1850 /* Set the CRYP peripheral in AES ECB mode */
\r
1851 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB);
\r
1854 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1856 /* Set the phase */
\r
1857 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1859 /* Set the input and output addresses and start DMA transfer */
\r
1860 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
1862 /* Process Unlocked */
\r
1863 __HAL_UNLOCK(hcryp);
\r
1865 /* Return function status */
\r
1870 return HAL_ERROR;
\r
1875 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA.
\r
1876 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1877 * the configuration information for CRYP module
\r
1878 * @param pPlainData: Pointer to the plaintext buffer
\r
1879 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1880 * @param pCypherData: Pointer to the cyphertext buffer
\r
1881 * @retval HAL status
\r
1883 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1885 uint32_t inputaddr;
\r
1886 uint32_t outputaddr;
\r
1888 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
1890 /* Process Locked */
\r
1891 __HAL_LOCK(hcryp);
\r
1893 inputaddr = (uint32_t)pPlainData;
\r
1894 outputaddr = (uint32_t)pCypherData;
\r
1896 /* Change the CRYP state */
\r
1897 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1899 /* Check if initialization phase has already been performed */
\r
1900 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1903 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1905 /* Set the CRYP peripheral in AES ECB mode */
\r
1906 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC);
\r
1908 /* Set the Initialization Vector */
\r
1909 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1912 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1914 /* Set the phase */
\r
1915 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1917 /* Set the input and output addresses and start DMA transfer */
\r
1918 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
1920 /* Process Unlocked */
\r
1921 __HAL_UNLOCK(hcryp);
\r
1923 /* Return function status */
\r
1928 return HAL_ERROR;
\r
1933 * @brief Initializes the CRYP peripheral in AES CTR encryption mode using DMA.
\r
1934 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1935 * the configuration information for CRYP module
\r
1936 * @param pPlainData: Pointer to the plaintext buffer
\r
1937 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1938 * @param pCypherData: Pointer to the cyphertext buffer
\r
1939 * @retval HAL status
\r
1941 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1943 uint32_t inputaddr;
\r
1944 uint32_t outputaddr;
\r
1946 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
1948 /* Process Locked */
\r
1949 __HAL_LOCK(hcryp);
\r
1951 inputaddr = (uint32_t)pPlainData;
\r
1952 outputaddr = (uint32_t)pCypherData;
\r
1954 /* Change the CRYP state */
\r
1955 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1957 /* Check if initialization phase has already been performed */
\r
1958 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1961 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1963 /* Set the CRYP peripheral in AES ECB mode */
\r
1964 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR);
\r
1966 /* Set the Initialization Vector */
\r
1967 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1970 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
1972 /* Set the phase */
\r
1973 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1976 /* Set the input and output addresses and start DMA transfer */
\r
1977 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
1979 /* Process Unlocked */
\r
1980 __HAL_UNLOCK(hcryp);
\r
1982 /* Return function status */
\r
1987 return HAL_ERROR;
\r
1992 * @brief Initializes the CRYP peripheral in AES ECB decryption mode using DMA.
\r
1993 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1994 * the configuration information for CRYP module
\r
1995 * @param pCypherData: Pointer to the cyphertext buffer
\r
1996 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1997 * @param pPlainData: Pointer to the plaintext buffer
\r
1998 * @retval HAL status
\r
2000 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2002 uint32_t tickstart = 0;
\r
2003 uint32_t inputaddr;
\r
2004 uint32_t outputaddr;
\r
2006 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2008 /* Process Locked */
\r
2009 __HAL_LOCK(hcryp);
\r
2011 inputaddr = (uint32_t)pCypherData;
\r
2012 outputaddr = (uint32_t)pPlainData;
\r
2014 /* Change the CRYP state */
\r
2015 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2017 /* Check if initialization phase has already been performed */
\r
2018 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
2021 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
2023 /* Set the CRYP peripheral in AES Key mode */
\r
2024 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
2027 __HAL_CRYP_ENABLE(hcryp);
\r
2030 tickstart = HAL_GetTick();
\r
2032 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
\r
2034 /* Check for the Timeout */
\r
2035 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
\r
2037 /* Change state */
\r
2038 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
2040 /* Process Unlocked */
\r
2041 __HAL_UNLOCK(hcryp);
\r
2043 return HAL_TIMEOUT;
\r
2047 /* Reset the ALGOMODE bits*/
\r
2048 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
2050 /* Set the CRYP peripheral in AES ECB decryption mode */
\r
2051 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
\r
2054 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
2056 /* Set the phase */
\r
2057 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
2060 /* Set the input and output addresses and start DMA transfer */
\r
2061 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2063 /* Process Unlocked */
\r
2064 __HAL_UNLOCK(hcryp);
\r
2066 /* Return function status */
\r
2071 return HAL_ERROR;
\r
2076 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA.
\r
2077 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2078 * the configuration information for CRYP module
\r
2079 * @param pCypherData: Pointer to the cyphertext buffer
\r
2080 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
2081 * @param pPlainData: Pointer to the plaintext buffer
\r
2082 * @retval HAL status
\r
2084 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2086 uint32_t tickstart = 0;
\r
2087 uint32_t inputaddr;
\r
2088 uint32_t outputaddr;
\r
2090 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2092 /* Process Locked */
\r
2093 __HAL_LOCK(hcryp);
\r
2095 inputaddr = (uint32_t)pCypherData;
\r
2096 outputaddr = (uint32_t)pPlainData;
\r
2098 /* Change the CRYP state */
\r
2099 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2101 /* Check if initialization phase has already been performed */
\r
2102 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
2105 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
2107 /* Set the CRYP peripheral in AES Key mode */
\r
2108 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
2111 __HAL_CRYP_ENABLE(hcryp);
\r
2114 tickstart = HAL_GetTick();
\r
2116 while(HAL_IS_BIT_SET(hcryp->Instance->SR, CRYP_FLAG_BUSY))
\r
2118 /* Check for the Timeout */
\r
2119 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
\r
2121 /* Change state */
\r
2122 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
2124 /* Process Unlocked */
\r
2125 __HAL_UNLOCK(hcryp);
\r
2127 return HAL_TIMEOUT;
\r
2131 /* Reset the ALGOMODE bits*/
\r
2132 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
2134 /* Set the CRYP peripheral in AES CBC decryption mode */
\r
2135 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
\r
2137 /* Set the Initialization Vector */
\r
2138 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
2141 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
2143 /* Set the phase */
\r
2144 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
2147 /* Set the input and output addresses and start DMA transfer */
\r
2148 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2150 /* Process Unlocked */
\r
2151 __HAL_UNLOCK(hcryp);
\r
2153 /* Return function status */
\r
2158 return HAL_ERROR;
\r
2163 * @brief Initializes the CRYP peripheral in AES CTR decryption mode using DMA.
\r
2164 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2165 * the configuration information for CRYP module
\r
2166 * @param pCypherData: Pointer to the cyphertext buffer
\r
2167 * @param Size: Length of the plaintext buffer, must be a multiple of 16
\r
2168 * @param pPlainData: Pointer to the plaintext buffer
\r
2169 * @retval HAL status
\r
2171 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2173 uint32_t inputaddr;
\r
2174 uint32_t outputaddr;
\r
2176 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2178 /* Process Locked */
\r
2179 __HAL_LOCK(hcryp);
\r
2181 inputaddr = (uint32_t)pCypherData;
\r
2182 outputaddr = (uint32_t)pPlainData;
\r
2184 /* Change the CRYP state */
\r
2185 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2187 /* Check if initialization phase has already been performed */
\r
2188 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
2191 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
2193 /* Set the CRYP peripheral in AES CTR mode */
\r
2194 __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
\r
2196 /* Set the Initialization Vector */
\r
2197 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
2200 __HAL_CRYP_FIFO_FLUSH(hcryp);
\r
2202 /* Set the phase */
\r
2203 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
2206 /* Set the input and output addresses and start DMA transfer */
\r
2207 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2209 /* Process Unlocked */
\r
2210 __HAL_UNLOCK(hcryp);
\r
2212 /* Return function status */
\r
2217 return HAL_ERROR;
\r
2226 /** @defgroup CRYP_Exported_Functions_Group3 DES processing functions
\r
2227 * @brief processing functions.
\r
2230 ==============================================================================
\r
2231 ##### DES processing functions #####
\r
2232 ==============================================================================
\r
2233 [..] This section provides functions allowing to:
\r
2234 (+) Encrypt plaintext using DES using ECB or CBC chaining modes
\r
2235 (+) Decrypt cyphertext using ECB or CBC chaining modes
\r
2236 [..] Three processing functions are available:
\r
2238 (+) Interrupt mode
\r
2246 * @brief Initializes the CRYP peripheral in DES ECB encryption mode.
\r
2247 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2248 * the configuration information for CRYP module
\r
2249 * @param pPlainData: Pointer to the plaintext buffer
\r
2250 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2251 * @param pCypherData: Pointer to the cyphertext buffer
\r
2252 * @param Timeout: Specify Timeout value
\r
2253 * @retval HAL status
\r
2255 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2257 /* Process Locked */
\r
2258 __HAL_LOCK(hcryp);
\r
2260 /* Change the CRYP state */
\r
2261 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2263 /* Set CRYP peripheral in DES ECB encryption mode */
\r
2264 CRYP_SetDESECBMode(hcryp, 0);
\r
2267 __HAL_CRYP_ENABLE(hcryp);
\r
2269 /* Write Plain Data and Get Cypher Data */
\r
2270 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2272 return HAL_TIMEOUT;
\r
2275 /* Change the CRYP state */
\r
2276 hcryp->State = HAL_CRYP_STATE_READY;
\r
2278 /* Process Unlocked */
\r
2279 __HAL_UNLOCK(hcryp);
\r
2281 /* Return function status */
\r
2286 * @brief Initializes the CRYP peripheral in DES ECB decryption mode.
\r
2287 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2288 * the configuration information for CRYP module
\r
2289 * @param pPlainData: Pointer to the plaintext buffer
\r
2290 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2291 * @param pCypherData: Pointer to the cyphertext buffer
\r
2292 * @param Timeout: Specify Timeout value
\r
2293 * @retval HAL status
\r
2295 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2297 /* Process Locked */
\r
2298 __HAL_LOCK(hcryp);
\r
2300 /* Change the CRYP state */
\r
2301 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2303 /* Set CRYP peripheral in DES ECB decryption mode */
\r
2304 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
2307 __HAL_CRYP_ENABLE(hcryp);
\r
2309 /* Write Plain Data and Get Cypher Data */
\r
2310 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2312 return HAL_TIMEOUT;
\r
2315 /* Change the CRYP state */
\r
2316 hcryp->State = HAL_CRYP_STATE_READY;
\r
2318 /* Process Unlocked */
\r
2319 __HAL_UNLOCK(hcryp);
\r
2321 /* Return function status */
\r
2326 * @brief Initializes the CRYP peripheral in DES CBC encryption mode.
\r
2327 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2328 * the configuration information for CRYP module
\r
2329 * @param pPlainData: Pointer to the plaintext buffer
\r
2330 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2331 * @param pCypherData: Pointer to the cyphertext buffer
\r
2332 * @param Timeout: Specify Timeout value
\r
2333 * @retval HAL status
\r
2335 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2337 /* Process Locked */
\r
2338 __HAL_LOCK(hcryp);
\r
2340 /* Change the CRYP state */
\r
2341 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2343 /* Set CRYP peripheral in DES CBC encryption mode */
\r
2344 CRYP_SetDESCBCMode(hcryp, 0);
\r
2347 __HAL_CRYP_ENABLE(hcryp);
\r
2349 /* Write Plain Data and Get Cypher Data */
\r
2350 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2352 return HAL_TIMEOUT;
\r
2355 /* Change the CRYP state */
\r
2356 hcryp->State = HAL_CRYP_STATE_READY;
\r
2358 /* Process Unlocked */
\r
2359 __HAL_UNLOCK(hcryp);
\r
2361 /* Return function status */
\r
2366 * @brief Initializes the CRYP peripheral in DES ECB decryption mode.
\r
2367 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2368 * the configuration information for CRYP module
\r
2369 * @param pPlainData: Pointer to the plaintext buffer
\r
2370 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2371 * @param pCypherData: Pointer to the cyphertext buffer
\r
2372 * @param Timeout: Specify Timeout value
\r
2373 * @retval HAL status
\r
2375 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2377 /* Process Locked */
\r
2378 __HAL_LOCK(hcryp);
\r
2380 /* Change the CRYP state */
\r
2381 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2383 /* Set CRYP peripheral in DES CBC decryption mode */
\r
2384 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
2387 __HAL_CRYP_ENABLE(hcryp);
\r
2389 /* Write Plain Data and Get Cypher Data */
\r
2390 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2392 return HAL_TIMEOUT;
\r
2395 /* Change the CRYP state */
\r
2396 hcryp->State = HAL_CRYP_STATE_READY;
\r
2398 /* Process Unlocked */
\r
2399 __HAL_UNLOCK(hcryp);
\r
2401 /* Return function status */
\r
2406 * @brief Initializes the CRYP peripheral in DES ECB encryption mode using IT.
\r
2407 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2408 * the configuration information for CRYP module
\r
2409 * @param pPlainData: Pointer to the plaintext buffer
\r
2410 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2411 * @param pCypherData: Pointer to the cyphertext buffer
\r
2412 * @retval HAL status
\r
2414 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
2416 uint32_t inputaddr;
\r
2417 uint32_t outputaddr;
\r
2419 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
2421 /* Process Locked */
\r
2422 __HAL_LOCK(hcryp);
\r
2424 hcryp->CrypInCount = Size;
\r
2425 hcryp->pCrypInBuffPtr = pPlainData;
\r
2426 hcryp->pCrypOutBuffPtr = pCypherData;
\r
2427 hcryp->CrypOutCount = Size;
\r
2429 /* Change the CRYP state */
\r
2430 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2432 /* Set CRYP peripheral in DES ECB encryption mode */
\r
2433 CRYP_SetDESECBMode(hcryp, 0);
\r
2435 /* Enable Interrupts */
\r
2436 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
2439 __HAL_CRYP_ENABLE(hcryp);
\r
2441 /* Return function status */
\r
2444 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
2446 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
2447 /* Write the Input block in the IN FIFO */
\r
2448 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
2450 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
2452 hcryp->pCrypInBuffPtr += 8;
\r
2453 hcryp->CrypInCount -= 8;
\r
2454 if(hcryp->CrypInCount == 0)
\r
2456 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
2457 /* Call the Input data transfer complete callback */
\r
2458 HAL_CRYP_InCpltCallback(hcryp);
\r
2461 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
2463 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
2464 /* Read the Output block from the Output FIFO */
\r
2465 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
2467 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
2469 hcryp->pCrypOutBuffPtr += 8;
\r
2470 hcryp->CrypOutCount -= 8;
\r
2471 if(hcryp->CrypOutCount == 0)
\r
2474 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
2475 /* Disable CRYP */
\r
2476 __HAL_CRYP_DISABLE(hcryp);
\r
2477 /* Process Unlocked */
\r
2478 __HAL_UNLOCK(hcryp);
\r
2479 /* Change the CRYP state */
\r
2480 hcryp->State = HAL_CRYP_STATE_READY;
\r
2481 /* Call Input transfer complete callback */
\r
2482 HAL_CRYP_OutCpltCallback(hcryp);
\r
2486 /* Return function status */
\r
2491 * @brief Initializes the CRYP peripheral in DES CBC encryption mode using interrupt.
\r
2492 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2493 * the configuration information for CRYP module
\r
2494 * @param pPlainData: Pointer to the plaintext buffer
\r
2495 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2496 * @param pCypherData: Pointer to the cyphertext buffer
\r
2497 * @retval HAL status
\r
2499 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
2501 uint32_t inputaddr;
\r
2502 uint32_t outputaddr;
\r
2504 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
2506 /* Process Locked */
\r
2507 __HAL_LOCK(hcryp);
\r
2509 hcryp->CrypInCount = Size;
\r
2510 hcryp->pCrypInBuffPtr = pPlainData;
\r
2511 hcryp->pCrypOutBuffPtr = pCypherData;
\r
2512 hcryp->CrypOutCount = Size;
\r
2514 /* Change the CRYP state */
\r
2515 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2517 /* Set CRYP peripheral in DES CBC encryption mode */
\r
2518 CRYP_SetDESCBCMode(hcryp, 0);
\r
2520 /* Enable Interrupts */
\r
2521 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
2524 __HAL_CRYP_ENABLE(hcryp);
\r
2526 /* Return function status */
\r
2530 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
2532 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
2533 /* Write the Input block in the IN FIFO */
\r
2534 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
2536 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
2538 hcryp->pCrypInBuffPtr += 8;
\r
2539 hcryp->CrypInCount -= 8;
\r
2540 if(hcryp->CrypInCount == 0)
\r
2542 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
2543 /* Call the Input data transfer complete callback */
\r
2544 HAL_CRYP_InCpltCallback(hcryp);
\r
2547 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
2549 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
2550 /* Read the Output block from the Output FIFO */
\r
2551 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
2553 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
2555 hcryp->pCrypOutBuffPtr += 8;
\r
2556 hcryp->CrypOutCount -= 8;
\r
2557 if(hcryp->CrypOutCount == 0)
\r
2560 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
2561 /* Disable CRYP */
\r
2562 __HAL_CRYP_DISABLE(hcryp);
\r
2563 /* Process Unlocked */
\r
2564 __HAL_UNLOCK(hcryp);
\r
2565 /* Change the CRYP state */
\r
2566 hcryp->State = HAL_CRYP_STATE_READY;
\r
2567 /* Call Input transfer complete callback */
\r
2568 HAL_CRYP_OutCpltCallback(hcryp);
\r
2572 /* Return function status */
\r
2577 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using IT.
\r
2578 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2579 * the configuration information for CRYP module
\r
2580 * @param pPlainData: Pointer to the plaintext buffer
\r
2581 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2582 * @param pCypherData: Pointer to the cyphertext buffer
\r
2583 * @retval HAL status
\r
2585 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2587 uint32_t inputaddr;
\r
2588 uint32_t outputaddr;
\r
2590 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
2592 /* Process Locked */
\r
2593 __HAL_LOCK(hcryp);
\r
2595 hcryp->CrypInCount = Size;
\r
2596 hcryp->pCrypInBuffPtr = pCypherData;
\r
2597 hcryp->pCrypOutBuffPtr = pPlainData;
\r
2598 hcryp->CrypOutCount = Size;
\r
2600 /* Change the CRYP state */
\r
2601 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2603 /* Set CRYP peripheral in DES ECB decryption mode */
\r
2604 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
2606 /* Enable Interrupts */
\r
2607 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
2610 __HAL_CRYP_ENABLE(hcryp);
\r
2612 /* Return function status */
\r
2615 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
2617 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
2618 /* Write the Input block in the IN FIFO */
\r
2619 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
2621 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
2623 hcryp->pCrypInBuffPtr += 8;
\r
2624 hcryp->CrypInCount -= 8;
\r
2625 if(hcryp->CrypInCount == 0)
\r
2627 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
2628 /* Call the Input data transfer complete callback */
\r
2629 HAL_CRYP_InCpltCallback(hcryp);
\r
2632 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
2634 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
2635 /* Read the Output block from the Output FIFO */
\r
2636 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
2638 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
2640 hcryp->pCrypOutBuffPtr += 8;
\r
2641 hcryp->CrypOutCount -= 8;
\r
2642 if(hcryp->CrypOutCount == 0)
\r
2645 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
2646 /* Disable CRYP */
\r
2647 __HAL_CRYP_DISABLE(hcryp);
\r
2648 /* Process Unlocked */
\r
2649 __HAL_UNLOCK(hcryp);
\r
2650 /* Change the CRYP state */
\r
2651 hcryp->State = HAL_CRYP_STATE_READY;
\r
2652 /* Call Input transfer complete callback */
\r
2653 HAL_CRYP_OutCpltCallback(hcryp);
\r
2657 /* Return function status */
\r
2662 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using interrupt.
\r
2663 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2664 * the configuration information for CRYP module
\r
2665 * @param pPlainData: Pointer to the plaintext buffer
\r
2666 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2667 * @param pCypherData: Pointer to the cyphertext buffer
\r
2668 * @retval HAL status
\r
2670 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2672 uint32_t inputaddr;
\r
2673 uint32_t outputaddr;
\r
2675 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
2677 /* Process Locked */
\r
2678 __HAL_LOCK(hcryp);
\r
2680 hcryp->CrypInCount = Size;
\r
2681 hcryp->pCrypInBuffPtr = pCypherData;
\r
2682 hcryp->pCrypOutBuffPtr = pPlainData;
\r
2683 hcryp->CrypOutCount = Size;
\r
2685 /* Change the CRYP state */
\r
2686 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2688 /* Set CRYP peripheral in DES CBC decryption mode */
\r
2689 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
2691 /* Enable Interrupts */
\r
2692 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
2695 __HAL_CRYP_ENABLE(hcryp);
\r
2697 /* Return function status */
\r
2700 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
2702 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
2703 /* Write the Input block in the IN FIFO */
\r
2704 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
2706 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
2708 hcryp->pCrypInBuffPtr += 8;
\r
2709 hcryp->CrypInCount -= 8;
\r
2710 if(hcryp->CrypInCount == 0)
\r
2712 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
2713 /* Call the Input data transfer complete callback */
\r
2714 HAL_CRYP_InCpltCallback(hcryp);
\r
2717 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
2719 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
2720 /* Read the Output block from the Output FIFO */
\r
2721 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
2723 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
2725 hcryp->pCrypOutBuffPtr += 8;
\r
2726 hcryp->CrypOutCount -= 8;
\r
2727 if(hcryp->CrypOutCount == 0)
\r
2730 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
2731 /* Disable CRYP */
\r
2732 __HAL_CRYP_DISABLE(hcryp);
\r
2733 /* Process Unlocked */
\r
2734 __HAL_UNLOCK(hcryp);
\r
2735 /* Change the CRYP state */
\r
2736 hcryp->State = HAL_CRYP_STATE_READY;
\r
2737 /* Call Input transfer complete callback */
\r
2738 HAL_CRYP_OutCpltCallback(hcryp);
\r
2742 /* Return function status */
\r
2747 * @brief Initializes the CRYP peripheral in DES ECB encryption mode using DMA.
\r
2748 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2749 * the configuration information for CRYP module
\r
2750 * @param pPlainData: Pointer to the plaintext buffer
\r
2751 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2752 * @param pCypherData: Pointer to the cyphertext buffer
\r
2753 * @retval HAL status
\r
2755 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
2757 uint32_t inputaddr;
\r
2758 uint32_t outputaddr;
\r
2760 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2762 /* Process Locked */
\r
2763 __HAL_LOCK(hcryp);
\r
2765 inputaddr = (uint32_t)pPlainData;
\r
2766 outputaddr = (uint32_t)pCypherData;
\r
2768 /* Change the CRYP state */
\r
2769 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2771 /* Set CRYP peripheral in DES ECB encryption mode */
\r
2772 CRYP_SetDESECBMode(hcryp, 0);
\r
2774 /* Set the input and output addresses and start DMA transfer */
\r
2775 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2777 /* Process Unlocked */
\r
2778 __HAL_UNLOCK(hcryp);
\r
2780 /* Return function status */
\r
2785 return HAL_ERROR;
\r
2790 * @brief Initializes the CRYP peripheral in DES CBC encryption mode using DMA.
\r
2791 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2792 * the configuration information for CRYP module
\r
2793 * @param pPlainData: Pointer to the plaintext buffer
\r
2794 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2795 * @param pCypherData: Pointer to the cyphertext buffer
\r
2796 * @retval HAL status
\r
2798 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
2800 uint32_t inputaddr;
\r
2801 uint32_t outputaddr;
\r
2803 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2805 /* Process Locked */
\r
2806 __HAL_LOCK(hcryp);
\r
2808 inputaddr = (uint32_t)pPlainData;
\r
2809 outputaddr = (uint32_t)pCypherData;
\r
2811 /* Change the CRYP state */
\r
2812 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2814 /* Set CRYP peripheral in DES CBC encryption mode */
\r
2815 CRYP_SetDESCBCMode(hcryp, 0);
\r
2817 /* Set the input and output addresses and start DMA transfer */
\r
2818 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2820 /* Process Unlocked */
\r
2821 __HAL_UNLOCK(hcryp);
\r
2823 /* Return function status */
\r
2828 return HAL_ERROR;
\r
2833 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using DMA.
\r
2834 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2835 * the configuration information for CRYP module
\r
2836 * @param pPlainData: Pointer to the plaintext buffer
\r
2837 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2838 * @param pCypherData: Pointer to the cyphertext buffer
\r
2839 * @retval HAL status
\r
2841 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2843 uint32_t inputaddr;
\r
2844 uint32_t outputaddr;
\r
2846 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2848 /* Process Locked */
\r
2849 __HAL_LOCK(hcryp);
\r
2851 inputaddr = (uint32_t)pCypherData;
\r
2852 outputaddr = (uint32_t)pPlainData;
\r
2854 /* Change the CRYP state */
\r
2855 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2857 /* Set CRYP peripheral in DES ECB decryption mode */
\r
2858 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
2860 /* Set the input and output addresses and start DMA transfer */
\r
2861 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2863 /* Process Unlocked */
\r
2864 __HAL_UNLOCK(hcryp);
\r
2866 /* Return function status */
\r
2871 return HAL_ERROR;
\r
2876 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using DMA.
\r
2877 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2878 * the configuration information for CRYP module
\r
2879 * @param pPlainData: Pointer to the plaintext buffer
\r
2880 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2881 * @param pCypherData: Pointer to the cyphertext buffer
\r
2882 * @retval HAL status
\r
2884 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2886 uint32_t inputaddr;
\r
2887 uint32_t outputaddr;
\r
2889 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2891 /* Process Locked */
\r
2892 __HAL_LOCK(hcryp);
\r
2894 inputaddr = (uint32_t)pCypherData;
\r
2895 outputaddr = (uint32_t)pPlainData;
\r
2897 /* Change the CRYP state */
\r
2898 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2900 /* Set CRYP peripheral in DES CBC decryption mode */
\r
2901 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
2903 /* Set the input and output addresses and start DMA transfer */
\r
2904 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2906 /* Process Unlocked */
\r
2907 __HAL_UNLOCK(hcryp);
\r
2909 /* Return function status */
\r
2914 return HAL_ERROR;
\r
2922 /** @defgroup CRYP_Exported_Functions_Group4 TDES processing functions
\r
2923 * @brief processing functions.
\r
2926 ==============================================================================
\r
2927 ##### TDES processing functions #####
\r
2928 ==============================================================================
\r
2929 [..] This section provides functions allowing to:
\r
2930 (+) Encrypt plaintext using TDES based on ECB or CBC chaining modes
\r
2931 (+) Decrypt cyphertext using TDES based on ECB or CBC chaining modes
\r
2932 [..] Three processing functions are available:
\r
2934 (+) Interrupt mode
\r
2942 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode
\r
2943 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
2944 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2945 * the configuration information for CRYP module
\r
2946 * @param pPlainData: Pointer to the plaintext buffer
\r
2947 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2948 * @param pCypherData: Pointer to the cyphertext buffer
\r
2949 * @param Timeout: Specify Timeout value
\r
2950 * @retval HAL status
\r
2952 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2954 /* Process Locked */
\r
2955 __HAL_LOCK(hcryp);
\r
2957 /* Change the CRYP state */
\r
2958 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2960 /* Set CRYP peripheral in TDES ECB encryption mode */
\r
2961 CRYP_SetTDESECBMode(hcryp, 0);
\r
2964 __HAL_CRYP_ENABLE(hcryp);
\r
2966 /* Write Plain Data and Get Cypher Data */
\r
2967 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2969 return HAL_TIMEOUT;
\r
2972 /* Change the CRYP state */
\r
2973 hcryp->State = HAL_CRYP_STATE_READY;
\r
2975 /* Process Unlocked */
\r
2976 __HAL_UNLOCK(hcryp);
\r
2978 /* Return function status */
\r
2983 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode
\r
2984 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
2985 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2986 * the configuration information for CRYP module
\r
2987 * @param pPlainData: Pointer to the plaintext buffer
\r
2988 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2989 * @param pCypherData: Pointer to the cyphertext buffer
\r
2990 * @param Timeout: Specify Timeout value
\r
2991 * @retval HAL status
\r
2993 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
2995 /* Process Locked */
\r
2996 __HAL_LOCK(hcryp);
\r
2998 /* Change the CRYP state */
\r
2999 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3001 /* Set CRYP peripheral in TDES ECB decryption mode */
\r
3002 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
3005 __HAL_CRYP_ENABLE(hcryp);
\r
3007 /* Write Cypher Data and Get Plain Data */
\r
3008 if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
3010 return HAL_TIMEOUT;
\r
3013 /* Change the CRYP state */
\r
3014 hcryp->State = HAL_CRYP_STATE_READY;
\r
3016 /* Process Unlocked */
\r
3017 __HAL_UNLOCK(hcryp);
\r
3019 /* Return function status */
\r
3024 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode
\r
3025 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
3026 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3027 * the configuration information for CRYP module
\r
3028 * @param pPlainData: Pointer to the plaintext buffer
\r
3029 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3030 * @param pCypherData: Pointer to the cyphertext buffer
\r
3031 * @param Timeout: Specify Timeout value
\r
3032 * @retval HAL status
\r
3034 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
3036 /* Process Locked */
\r
3037 __HAL_LOCK(hcryp);
\r
3039 /* Change the CRYP state */
\r
3040 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3042 /* Set CRYP peripheral in TDES CBC encryption mode */
\r
3043 CRYP_SetTDESCBCMode(hcryp, 0);
\r
3046 __HAL_CRYP_ENABLE(hcryp);
\r
3048 /* Write Plain Data and Get Cypher Data */
\r
3049 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
3051 return HAL_TIMEOUT;
\r
3054 /* Change the CRYP state */
\r
3055 hcryp->State = HAL_CRYP_STATE_READY;
\r
3057 /* Process Unlocked */
\r
3058 __HAL_UNLOCK(hcryp);
\r
3060 /* Return function status */
\r
3065 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode
\r
3066 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
3067 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3068 * the configuration information for CRYP module
\r
3069 * @param pCypherData: Pointer to the cyphertext buffer
\r
3070 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3071 * @param pPlainData: Pointer to the plaintext buffer
\r
3072 * @param Timeout: Specify Timeout value
\r
3073 * @retval HAL status
\r
3075 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
3077 /* Process Locked */
\r
3078 __HAL_LOCK(hcryp);
\r
3080 /* Change the CRYP state */
\r
3081 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3083 /* Set CRYP peripheral in TDES CBC decryption mode */
\r
3084 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
3087 __HAL_CRYP_ENABLE(hcryp);
\r
3089 /* Write Cypher Data and Get Plain Data */
\r
3090 if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
3092 return HAL_TIMEOUT;
\r
3095 /* Change the CRYP state */
\r
3096 hcryp->State = HAL_CRYP_STATE_READY;
\r
3098 /* Process Unlocked */
\r
3099 __HAL_UNLOCK(hcryp);
\r
3101 /* Return function status */
\r
3106 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode using interrupt.
\r
3107 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3108 * the configuration information for CRYP module
\r
3109 * @param pPlainData: Pointer to the plaintext buffer
\r
3110 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3111 * @param pCypherData: Pointer to the cyphertext buffer
\r
3112 * @retval HAL status
\r
3114 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
3116 uint32_t inputaddr;
\r
3117 uint32_t outputaddr;
\r
3119 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
3121 /* Process Locked */
\r
3122 __HAL_LOCK(hcryp);
\r
3124 hcryp->CrypInCount = Size;
\r
3125 hcryp->pCrypInBuffPtr = pPlainData;
\r
3126 hcryp->pCrypOutBuffPtr = pCypherData;
\r
3127 hcryp->CrypOutCount = Size;
\r
3129 /* Change the CRYP state */
\r
3130 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3132 /* Set CRYP peripheral in TDES ECB encryption mode */
\r
3133 CRYP_SetTDESECBMode(hcryp, 0);
\r
3135 /* Enable Interrupts */
\r
3136 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
3139 __HAL_CRYP_ENABLE(hcryp);
\r
3141 /* Return function status */
\r
3144 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
3146 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
3147 /* Write the Input block in the IN FIFO */
\r
3148 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
3150 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
3152 hcryp->pCrypInBuffPtr += 8;
\r
3153 hcryp->CrypInCount -= 8;
\r
3154 if(hcryp->CrypInCount == 0)
\r
3156 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
3157 /* Call the Input data transfer complete callback */
\r
3158 HAL_CRYP_InCpltCallback(hcryp);
\r
3161 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
3163 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
3164 /* Read the Output block from the Output FIFO */
\r
3165 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
3167 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
3169 hcryp->pCrypOutBuffPtr += 8;
\r
3170 hcryp->CrypOutCount -= 8;
\r
3171 if(hcryp->CrypOutCount == 0)
\r
3174 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
3175 /* Disable CRYP */
\r
3176 __HAL_CRYP_DISABLE(hcryp);
\r
3177 /* Process Unlocked */
\r
3178 __HAL_UNLOCK(hcryp);
\r
3179 /* Change the CRYP state */
\r
3180 hcryp->State = HAL_CRYP_STATE_READY;
\r
3181 /* Call the Output data transfer complete callback */
\r
3182 HAL_CRYP_OutCpltCallback(hcryp);
\r
3186 /* Return function status */
\r
3191 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode.
\r
3192 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3193 * the configuration information for CRYP module
\r
3194 * @param pPlainData: Pointer to the plaintext buffer
\r
3195 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3196 * @param pCypherData: Pointer to the cyphertext buffer
\r
3197 * @retval HAL status
\r
3199 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
3201 uint32_t inputaddr;
\r
3202 uint32_t outputaddr;
\r
3204 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
3206 /* Process Locked */
\r
3207 __HAL_LOCK(hcryp);
\r
3209 hcryp->CrypInCount = Size;
\r
3210 hcryp->pCrypInBuffPtr = pPlainData;
\r
3211 hcryp->pCrypOutBuffPtr = pCypherData;
\r
3212 hcryp->CrypOutCount = Size;
\r
3214 /* Change the CRYP state */
\r
3215 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3217 /* Set CRYP peripheral in TDES CBC encryption mode */
\r
3218 CRYP_SetTDESCBCMode(hcryp, 0);
\r
3220 /* Enable Interrupts */
\r
3221 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
3224 __HAL_CRYP_ENABLE(hcryp);
\r
3226 /* Return function status */
\r
3229 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
3231 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
3232 /* Write the Input block in the IN FIFO */
\r
3233 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
3235 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
3237 hcryp->pCrypInBuffPtr += 8;
\r
3238 hcryp->CrypInCount -= 8;
\r
3239 if(hcryp->CrypInCount == 0)
\r
3241 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
3242 /* Call the Input data transfer complete callback */
\r
3243 HAL_CRYP_InCpltCallback(hcryp);
\r
3246 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
3248 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
3249 /* Read the Output block from the Output FIFO */
\r
3250 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
3252 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
3254 hcryp->pCrypOutBuffPtr += 8;
\r
3255 hcryp->CrypOutCount -= 8;
\r
3256 if(hcryp->CrypOutCount == 0)
\r
3258 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
3259 /* Disable CRYP */
\r
3260 __HAL_CRYP_DISABLE(hcryp);
\r
3261 /* Process Unlocked */
\r
3262 __HAL_UNLOCK(hcryp);
\r
3263 /* Change the CRYP state */
\r
3264 hcryp->State = HAL_CRYP_STATE_READY;
\r
3265 /* Call Input transfer complete callback */
\r
3266 HAL_CRYP_OutCpltCallback(hcryp);
\r
3270 /* Return function status */
\r
3275 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode.
\r
3276 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3277 * the configuration information for CRYP module
\r
3278 * @param pPlainData: Pointer to the plaintext buffer
\r
3279 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3280 * @param pCypherData: Pointer to the cyphertext buffer
\r
3281 * @retval HAL status
\r
3283 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
3285 uint32_t inputaddr;
\r
3286 uint32_t outputaddr;
\r
3288 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
3290 /* Process Locked */
\r
3291 __HAL_LOCK(hcryp);
\r
3293 hcryp->CrypInCount = Size;
\r
3294 hcryp->pCrypInBuffPtr = pCypherData;
\r
3295 hcryp->pCrypOutBuffPtr = pPlainData;
\r
3296 hcryp->CrypOutCount = Size;
\r
3298 /* Change the CRYP state */
\r
3299 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3301 /* Set CRYP peripheral in TDES ECB decryption mode */
\r
3302 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
3304 /* Enable Interrupts */
\r
3305 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
3308 __HAL_CRYP_ENABLE(hcryp);
\r
3310 /* Return function status */
\r
3313 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
3315 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
3316 /* Write the Input block in the IN FIFO */
\r
3317 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
3319 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
3321 hcryp->pCrypInBuffPtr += 8;
\r
3322 hcryp->CrypInCount -= 8;
\r
3323 if(hcryp->CrypInCount == 0)
\r
3325 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
3326 /* Call the Input data transfer complete callback */
\r
3327 HAL_CRYP_InCpltCallback(hcryp);
\r
3330 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
3332 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
3333 /* Read the Output block from the Output FIFO */
\r
3334 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
3336 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
3338 hcryp->pCrypOutBuffPtr += 8;
\r
3339 hcryp->CrypOutCount -= 8;
\r
3340 if(hcryp->CrypOutCount == 0)
\r
3342 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
3343 /* Disable CRYP */
\r
3344 __HAL_CRYP_DISABLE(hcryp);
\r
3345 /* Process Unlocked */
\r
3346 __HAL_UNLOCK(hcryp);
\r
3347 /* Change the CRYP state */
\r
3348 hcryp->State = HAL_CRYP_STATE_READY;
\r
3349 /* Call Input transfer complete callback */
\r
3350 HAL_CRYP_OutCpltCallback(hcryp);
\r
3354 /* Return function status */
\r
3359 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode.
\r
3360 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3361 * the configuration information for CRYP module
\r
3362 * @param pCypherData: Pointer to the cyphertext buffer
\r
3363 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3364 * @param pPlainData: Pointer to the plaintext buffer
\r
3365 * @retval HAL status
\r
3367 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
3369 uint32_t inputaddr;
\r
3370 uint32_t outputaddr;
\r
3372 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
3374 /* Process Locked */
\r
3375 __HAL_LOCK(hcryp);
\r
3377 hcryp->CrypInCount = Size;
\r
3378 hcryp->pCrypInBuffPtr = pCypherData;
\r
3379 hcryp->pCrypOutBuffPtr = pPlainData;
\r
3380 hcryp->CrypOutCount = Size;
\r
3382 /* Change the CRYP state */
\r
3383 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3385 /* Set CRYP peripheral in TDES CBC decryption mode */
\r
3386 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
3388 /* Enable Interrupts */
\r
3389 __HAL_CRYP_ENABLE_IT(hcryp, CRYP_IT_INI | CRYP_IT_OUTI);
\r
3392 __HAL_CRYP_ENABLE(hcryp);
\r
3394 /* Return function status */
\r
3397 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_INI))
\r
3399 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
3400 /* Write the Input block in the IN FIFO */
\r
3401 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
3403 hcryp->Instance->DR = *(uint32_t*)(inputaddr);
\r
3405 hcryp->pCrypInBuffPtr += 8;
\r
3406 hcryp->CrypInCount -= 8;
\r
3407 if(hcryp->CrypInCount == 0)
\r
3409 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_INI);
\r
3410 /* Call the Input data transfer complete callback */
\r
3411 HAL_CRYP_InCpltCallback(hcryp);
\r
3414 else if(__HAL_CRYP_GET_IT(hcryp, CRYP_IT_OUTI))
\r
3416 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
3417 /* Read the Output block from the Output FIFO */
\r
3418 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
3420 *(uint32_t*)(outputaddr) = hcryp->Instance->DOUT;
\r
3422 hcryp->pCrypOutBuffPtr += 8;
\r
3423 hcryp->CrypOutCount -= 8;
\r
3424 if(hcryp->CrypOutCount == 0)
\r
3426 __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_OUTI);
\r
3427 /* Disable CRYP */
\r
3428 __HAL_CRYP_DISABLE(hcryp);
\r
3429 /* Process Unlocked */
\r
3430 __HAL_UNLOCK(hcryp);
\r
3431 /* Change the CRYP state */
\r
3432 hcryp->State = HAL_CRYP_STATE_READY;
\r
3433 /* Call Input transfer complete callback */
\r
3434 HAL_CRYP_OutCpltCallback(hcryp);
\r
3438 /* Return function status */
\r
3443 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode using DMA.
\r
3444 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3445 * the configuration information for CRYP module
\r
3446 * @param pPlainData: Pointer to the plaintext buffer
\r
3447 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3448 * @param pCypherData: Pointer to the cyphertext buffer
\r
3449 * @retval HAL status
\r
3451 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
3453 uint32_t inputaddr;
\r
3454 uint32_t outputaddr;
\r
3456 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
3458 /* Process Locked */
\r
3459 __HAL_LOCK(hcryp);
\r
3461 inputaddr = (uint32_t)pPlainData;
\r
3462 outputaddr = (uint32_t)pCypherData;
\r
3464 /* Change the CRYP state */
\r
3465 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3467 /* Set CRYP peripheral in TDES ECB encryption mode */
\r
3468 CRYP_SetTDESECBMode(hcryp, 0);
\r
3470 /* Set the input and output addresses and start DMA transfer */
\r
3471 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
3473 /* Process Unlocked */
\r
3474 __HAL_UNLOCK(hcryp);
\r
3476 /* Return function status */
\r
3481 return HAL_ERROR;
\r
3486 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode using DMA.
\r
3487 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3488 * the configuration information for CRYP module
\r
3489 * @param pPlainData: Pointer to the plaintext buffer
\r
3490 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3491 * @param pCypherData: Pointer to the cyphertext buffer
\r
3492 * @retval HAL status
\r
3494 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
3496 uint32_t inputaddr;
\r
3497 uint32_t outputaddr;
\r
3499 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
3501 /* Process Locked */
\r
3502 __HAL_LOCK(hcryp);
\r
3504 inputaddr = (uint32_t)pPlainData;
\r
3505 outputaddr = (uint32_t)pCypherData;
\r
3507 /* Change the CRYP state */
\r
3508 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3510 /* Set CRYP peripheral in TDES CBC encryption mode */
\r
3511 CRYP_SetTDESCBCMode(hcryp, 0);
\r
3513 /* Set the input and output addresses and start DMA transfer */
\r
3514 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
3516 /* Process Unlocked */
\r
3517 __HAL_UNLOCK(hcryp);
\r
3519 /* Return function status */
\r
3524 return HAL_ERROR;
\r
3529 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode using DMA.
\r
3530 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3531 * the configuration information for CRYP module
\r
3532 * @param pPlainData: Pointer to the plaintext buffer
\r
3533 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3534 * @param pCypherData: Pointer to the cyphertext buffer
\r
3535 * @retval HAL status
\r
3537 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
3539 uint32_t inputaddr;
\r
3540 uint32_t outputaddr;
\r
3542 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
3544 /* Process Locked */
\r
3545 __HAL_LOCK(hcryp);
\r
3547 inputaddr = (uint32_t)pCypherData;
\r
3548 outputaddr = (uint32_t)pPlainData;
\r
3550 /* Change the CRYP state */
\r
3551 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3553 /* Set CRYP peripheral in TDES ECB decryption mode */
\r
3554 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
3556 /* Set the input and output addresses and start DMA transfer */
\r
3557 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
3559 /* Process Unlocked */
\r
3560 __HAL_UNLOCK(hcryp);
\r
3562 /* Return function status */
\r
3567 return HAL_ERROR;
\r
3572 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode using DMA.
\r
3573 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3574 * the configuration information for CRYP module
\r
3575 * @param pCypherData: Pointer to the cyphertext buffer
\r
3576 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3577 * @param pPlainData: Pointer to the plaintext buffer
\r
3578 * @retval HAL status
\r
3580 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
3582 uint32_t inputaddr;
\r
3583 uint32_t outputaddr;
\r
3585 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
3587 /* Process Locked */
\r
3588 __HAL_LOCK(hcryp);
\r
3590 inputaddr = (uint32_t)pCypherData;
\r
3591 outputaddr = (uint32_t)pPlainData;
\r
3593 /* Change the CRYP state */
\r
3594 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3596 /* Set CRYP peripheral in TDES CBC decryption mode */
\r
3597 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
3599 /* Set the input and output addresses and start DMA transfer */
\r
3600 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
3602 /* Process Unlocked */
\r
3603 __HAL_UNLOCK(hcryp);
\r
3605 /* Return function status */
\r
3610 return HAL_ERROR;
\r
3618 /** @defgroup CRYP_Exported_Functions_Group5 DMA callback functions
\r
3619 * @brief DMA callback functions.
\r
3622 ==============================================================================
\r
3623 ##### DMA callback functions #####
\r
3624 ==============================================================================
\r
3625 [..] This section provides DMA callback functions:
\r
3626 (+) DMA Input data transfer complete
\r
3627 (+) DMA Output data transfer complete
\r
3635 * @brief Input FIFO transfer completed callbacks.
\r
3636 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3637 * the configuration information for CRYP module
\r
3640 __weak void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp)
\r
3642 /* NOTE : This function Should not be modified, when the callback is needed,
\r
3643 the HAL_CRYP_InCpltCallback could be implemented in the user file
\r
3648 * @brief Output FIFO transfer completed callbacks.
\r
3649 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3650 * the configuration information for CRYP module
\r
3653 __weak void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp)
\r
3655 /* NOTE : This function Should not be modified, when the callback is needed,
\r
3656 the HAL_CRYP_OutCpltCallback could be implemented in the user file
\r
3661 * @brief CRYP error callbacks.
\r
3662 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3663 * the configuration information for CRYP module
\r
3666 __weak void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
\r
3668 /* NOTE : This function Should not be modified, when the callback is needed,
\r
3669 the HAL_CRYP_ErrorCallback could be implemented in the user file
\r
3677 /** @defgroup CRYP_Exported_Functions_Group6 CRYP IRQ handler management
\r
3678 * @brief CRYP IRQ handler.
\r
3681 ==============================================================================
\r
3682 ##### CRYP IRQ handler management #####
\r
3683 ==============================================================================
\r
3684 [..] This section provides CRYP IRQ handler function.
\r
3691 * @brief This function handles CRYP interrupt request.
\r
3692 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3693 * the configuration information for CRYP module
\r
3696 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp)
\r
3698 switch(CRYP->CR & CRYP_CR_ALGOMODE_DIRECTION)
\r
3700 case CRYP_CR_ALGOMODE_TDES_ECB_ENCRYPT:
\r
3701 HAL_CRYP_TDESECB_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3704 case CRYP_CR_ALGOMODE_TDES_ECB_DECRYPT:
\r
3705 HAL_CRYP_TDESECB_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3708 case CRYP_CR_ALGOMODE_TDES_CBC_ENCRYPT:
\r
3709 HAL_CRYP_TDESCBC_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3712 case CRYP_CR_ALGOMODE_TDES_CBC_DECRYPT:
\r
3713 HAL_CRYP_TDESCBC_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3716 case CRYP_CR_ALGOMODE_DES_ECB_ENCRYPT:
\r
3717 HAL_CRYP_DESECB_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3720 case CRYP_CR_ALGOMODE_DES_ECB_DECRYPT:
\r
3721 HAL_CRYP_DESECB_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3724 case CRYP_CR_ALGOMODE_DES_CBC_ENCRYPT:
\r
3725 HAL_CRYP_DESCBC_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3728 case CRYP_CR_ALGOMODE_DES_CBC_DECRYPT:
\r
3729 HAL_CRYP_DESCBC_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3732 case CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT:
\r
3733 HAL_CRYP_AESECB_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3736 case CRYP_CR_ALGOMODE_AES_ECB_DECRYPT:
\r
3737 HAL_CRYP_AESECB_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3740 case CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT:
\r
3741 HAL_CRYP_AESCBC_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3744 case CRYP_CR_ALGOMODE_AES_CBC_DECRYPT:
\r
3745 HAL_CRYP_AESCBC_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3748 case CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT:
\r
3749 HAL_CRYP_AESCTR_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3752 case CRYP_CR_ALGOMODE_AES_CTR_DECRYPT:
\r
3753 HAL_CRYP_AESCTR_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3765 /** @defgroup CRYP_Exported_Functions_Group7 Peripheral State functions
\r
3766 * @brief Peripheral State functions.
\r
3769 ==============================================================================
\r
3770 ##### Peripheral State functions #####
\r
3771 ==============================================================================
\r
3773 This subsection permits to get in run-time the status of the peripheral.
\r
3780 * @brief Returns the CRYP state.
\r
3781 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3782 * the configuration information for CRYP module
\r
3783 * @retval HAL state
\r
3785 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp)
\r
3787 return hcryp->State;
\r
3798 #endif /* STM32F756xx */
\r
3800 #endif /* HAL_CRYP_MODULE_ENABLED */
\r
3809 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r