2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_cryp.c
\r
4 * @author MCD Application Team
\r
6 * @date 06-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 __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 CRYP->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 CRYP->DMACR &= (uint32_t)(~CRYP_DMACR_DOEN);
\r
184 __HAL_CRYP_DISABLE();
\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 CRYP->K0LR = __REV(*(uint32_t*)(keyaddr));
\r
223 CRYP->K0RR = __REV(*(uint32_t*)(keyaddr));
\r
225 CRYP->K1LR = __REV(*(uint32_t*)(keyaddr));
\r
227 CRYP->K1RR = __REV(*(uint32_t*)(keyaddr));
\r
229 CRYP->K2LR = __REV(*(uint32_t*)(keyaddr));
\r
231 CRYP->K2RR = __REV(*(uint32_t*)(keyaddr));
\r
233 CRYP->K3LR = __REV(*(uint32_t*)(keyaddr));
\r
235 CRYP->K3RR = __REV(*(uint32_t*)(keyaddr));
\r
237 case CRYP_KEYSIZE_192B:
\r
238 CRYP->K1LR = __REV(*(uint32_t*)(keyaddr));
\r
240 CRYP->K1RR = __REV(*(uint32_t*)(keyaddr));
\r
242 CRYP->K2LR = __REV(*(uint32_t*)(keyaddr));
\r
244 CRYP->K2RR = __REV(*(uint32_t*)(keyaddr));
\r
246 CRYP->K3LR = __REV(*(uint32_t*)(keyaddr));
\r
248 CRYP->K3RR = __REV(*(uint32_t*)(keyaddr));
\r
250 case CRYP_KEYSIZE_128B:
\r
251 CRYP->K2LR = __REV(*(uint32_t*)(keyaddr));
\r
253 CRYP->K2RR = __REV(*(uint32_t*)(keyaddr));
\r
255 CRYP->K3LR = __REV(*(uint32_t*)(keyaddr));
\r
257 CRYP->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 CRYP->IV0LR = __REV(*(uint32_t*)(ivaddr));
\r
281 CRYP->IV0RR = __REV(*(uint32_t*)(ivaddr));
\r
283 CRYP->IV1LR = __REV(*(uint32_t*)(ivaddr));
\r
285 CRYP->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 CRYP->IV0LR = __REV(*(uint32_t*)(ivaddr));
\r
291 CRYP->IV0RR = __REV(*(uint32_t*)(ivaddr));
\r
293 case CRYP_KEYSIZE_256B:
\r
294 CRYP->IV0LR = __REV(*(uint32_t*)(ivaddr));
\r
296 CRYP->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
312 static HAL_StatusTypeDef CRYP_ProcessData(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout)
\r
314 uint32_t tickstart = 0;
\r
317 uint32_t inputaddr = (uint32_t)Input;
\r
318 uint32_t outputaddr = (uint32_t)Output;
\r
320 for(i=0; (i < Ilength); i+=16)
\r
322 /* Write the Input block in the IN FIFO */
\r
323 CRYP->DR = *(uint32_t*)(inputaddr);
\r
325 CRYP->DR = *(uint32_t*)(inputaddr);
\r
327 CRYP->DR = *(uint32_t*)(inputaddr);
\r
329 CRYP->DR = *(uint32_t*)(inputaddr);
\r
333 tickstart = HAL_GetTick();
\r
335 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_OFNE))
\r
337 /* Check for the Timeout */
\r
338 if(Timeout != HAL_MAX_DELAY)
\r
340 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
343 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
345 /* Process Unlocked */
\r
346 __HAL_UNLOCK(hcryp);
\r
348 return HAL_TIMEOUT;
\r
352 /* Read the Output block from the Output FIFO */
\r
353 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
355 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
357 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
359 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
362 /* Return function status */
\r
367 * @brief Process Data: Write Input data in polling mode.
\r
368 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
369 * the configuration information for CRYP module
\r
370 * @param Input: Pointer to the Input buffer
\r
371 * @param Ilength: Length of the Input buffer, must be a multiple of 8
\r
372 * @param Output: Pointer to the returned buffer
\r
373 * @param Timeout: Specify Timeout value
\r
376 static HAL_StatusTypeDef CRYP_ProcessData2Words(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint8_t* Output, uint32_t Timeout)
\r
378 uint32_t tickstart = 0;
\r
381 uint32_t inputaddr = (uint32_t)Input;
\r
382 uint32_t outputaddr = (uint32_t)Output;
\r
384 for(i=0; (i < Ilength); i+=8)
\r
386 /* Write the Input block in the IN FIFO */
\r
387 CRYP->DR = *(uint32_t*)(inputaddr);
\r
389 CRYP->DR = *(uint32_t*)(inputaddr);
\r
393 tickstart = HAL_GetTick();
\r
395 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_OFNE))
\r
397 /* Check for the Timeout */
\r
398 if(Timeout != HAL_MAX_DELAY)
\r
400 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
403 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
405 /* Process Unlocked */
\r
406 __HAL_UNLOCK(hcryp);
\r
408 return HAL_TIMEOUT;
\r
412 /* Read the Output block from the Output FIFO */
\r
413 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
415 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
418 /* Return function status */
\r
423 * @brief Set the DMA configuration and start the DMA transfer
\r
424 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
425 * the configuration information for CRYP module
\r
426 * @param inputaddr: address of the Input buffer
\r
427 * @param Size: Size of the Input buffer, must be a multiple of 16.
\r
428 * @param outputaddr: address of the Output buffer
\r
431 static void CRYP_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr)
\r
433 /* Set the CRYP DMA transfer complete callback */
\r
434 hcryp->hdmain->XferCpltCallback = CRYP_DMAInCplt;
\r
435 /* Set the DMA error callback */
\r
436 hcryp->hdmain->XferErrorCallback = CRYP_DMAError;
\r
438 /* Set the CRYP DMA transfer complete callback */
\r
439 hcryp->hdmaout->XferCpltCallback = CRYP_DMAOutCplt;
\r
440 /* Set the DMA error callback */
\r
441 hcryp->hdmaout->XferErrorCallback = CRYP_DMAError;
\r
444 __HAL_CRYP_ENABLE();
\r
446 /* Enable the DMA In DMA Stream */
\r
447 HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&CRYP->DR, Size/4);
\r
449 /* Enable In DMA request */
\r
450 CRYP->DMACR = (CRYP_DMACR_DIEN);
\r
452 /* Enable the DMA Out DMA Stream */
\r
453 HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&CRYP->DOUT, outputaddr, Size/4);
\r
455 /* Enable Out DMA request */
\r
456 CRYP->DMACR |= CRYP_DMACR_DOEN;
\r
461 * @brief Sets the CRYP peripheral in DES ECB mode.
\r
462 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
463 * the configuration information for CRYP module
\r
464 * @param Direction: Encryption or decryption
\r
467 static void CRYP_SetDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
\r
469 /* Check if initialization phase has already been performed */
\r
470 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
472 /* Set the CRYP peripheral in AES ECB mode */
\r
473 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_DES_ECB | Direction);
\r
476 CRYP->K1LR = __REV(*(uint32_t*)(hcryp->Init.pKey));
\r
477 CRYP->K1RR = __REV(*(uint32_t*)(hcryp->Init.pKey+4));
\r
480 __HAL_CRYP_FIFO_FLUSH();
\r
482 /* Set the phase */
\r
483 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
488 * @brief Sets the CRYP peripheral in DES CBC mode.
\r
489 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
490 * the configuration information for CRYP module
\r
491 * @param Direction: Encryption or decryption
\r
494 static void CRYP_SetDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
\r
496 /* Check if initialization phase has already been performed */
\r
497 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
499 /* Set the CRYP peripheral in AES ECB mode */
\r
500 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_DES_CBC | Direction);
\r
503 CRYP->K1LR = __REV(*(uint32_t*)(hcryp->Init.pKey));
\r
504 CRYP->K1RR = __REV(*(uint32_t*)(hcryp->Init.pKey+4));
\r
506 /* Set the Initialization Vector */
\r
507 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_256B);
\r
510 __HAL_CRYP_FIFO_FLUSH();
\r
512 /* Set the phase */
\r
513 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
518 * @brief Sets the CRYP peripheral in TDES ECB mode.
\r
519 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
520 * the configuration information for CRYP module
\r
521 * @param Direction: Encryption or decryption
\r
524 static void CRYP_SetTDESECBMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
\r
526 /* Check if initialization phase has already been performed */
\r
527 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
529 /* Set the CRYP peripheral in AES ECB mode */
\r
530 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_TDES_ECB | Direction);
\r
533 CRYP_SetKey(hcryp, hcryp->Init.pKey, CRYP_KEYSIZE_192B);
\r
536 __HAL_CRYP_FIFO_FLUSH();
\r
538 /* Set the phase */
\r
539 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
544 * @brief Sets the CRYP peripheral in TDES CBC mode
\r
545 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
546 * the configuration information for CRYP module
\r
547 * @param Direction: Encryption or decryption
\r
550 static void CRYP_SetTDESCBCMode(CRYP_HandleTypeDef *hcryp, uint32_t Direction)
\r
552 /* Check if initialization phase has already been performed */
\r
553 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
555 /* Set the CRYP peripheral in AES CBC mode */
\r
556 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_TDES_CBC | Direction);
\r
559 CRYP_SetKey(hcryp, hcryp->Init.pKey, CRYP_KEYSIZE_192B);
\r
561 /* Set the Initialization Vector */
\r
562 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_256B);
\r
565 __HAL_CRYP_FIFO_FLUSH();
\r
567 /* Set the phase */
\r
568 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
576 /* Exported functions --------------------------------------------------------*/
\r
577 /** @addtogroup CRYP_Exported_Functions
\r
581 /** @defgroup CRYP_Exported_Functions_Group1 Initialization and de-initialization functions
\r
582 * @brief Initialization and Configuration functions.
\r
585 ==============================================================================
\r
586 ##### Initialization and de-initialization functions #####
\r
587 ==============================================================================
\r
588 [..] This section provides functions allowing to:
\r
589 (+) Initialize the CRYP according to the specified parameters
\r
590 in the CRYP_InitTypeDef and creates the associated handle
\r
591 (+) DeInitialize the CRYP peripheral
\r
592 (+) Initialize the CRYP MSP
\r
593 (+) DeInitialize CRYP MSP
\r
600 * @brief Initializes the CRYP according to the specified
\r
601 * parameters in the CRYP_InitTypeDef and creates the associated handle.
\r
602 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
603 * the configuration information for CRYP module
\r
604 * @retval HAL status
\r
606 HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp)
\r
608 /* Check the CRYP handle allocation */
\r
614 /* Check the parameters */
\r
615 assert_param(IS_CRYP_KEYSIZE(hcryp->Init.KeySize));
\r
616 assert_param(IS_CRYP_DATATYPE(hcryp->Init.DataType));
\r
618 if(hcryp->State == HAL_CRYP_STATE_RESET)
\r
620 /* Init the low level hardware */
\r
621 HAL_CRYP_MspInit(hcryp);
\r
624 /* Change the CRYP state */
\r
625 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
627 /* Set the key size and data type*/
\r
628 CRYP->CR = (uint32_t) (hcryp->Init.KeySize | hcryp->Init.DataType);
\r
630 /* Reset CrypInCount and CrypOutCount */
\r
631 hcryp->CrypInCount = 0;
\r
632 hcryp->CrypOutCount = 0;
\r
634 /* Change the CRYP state */
\r
635 hcryp->State = HAL_CRYP_STATE_READY;
\r
637 /* Set the default CRYP phase */
\r
638 hcryp->Phase = HAL_CRYP_PHASE_READY;
\r
640 /* Return function status */
\r
645 * @brief DeInitializes the CRYP peripheral.
\r
646 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
647 * the configuration information for CRYP module
\r
648 * @retval HAL status
\r
650 HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp)
\r
652 /* Check the CRYP handle allocation */
\r
658 /* Change the CRYP state */
\r
659 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
661 /* Set the default CRYP phase */
\r
662 hcryp->Phase = HAL_CRYP_PHASE_READY;
\r
664 /* Reset CrypInCount and CrypOutCount */
\r
665 hcryp->CrypInCount = 0;
\r
666 hcryp->CrypOutCount = 0;
\r
668 /* Disable the CRYP Peripheral Clock */
\r
669 __HAL_CRYP_DISABLE();
\r
671 /* DeInit the low level hardware: CLOCK, NVIC.*/
\r
672 HAL_CRYP_MspDeInit(hcryp);
\r
674 /* Change the CRYP state */
\r
675 hcryp->State = HAL_CRYP_STATE_RESET;
\r
678 __HAL_UNLOCK(hcryp);
\r
680 /* Return function status */
\r
685 * @brief Initializes the CRYP MSP.
\r
686 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
687 * the configuration information for CRYP module
\r
690 __weak void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp)
\r
692 /* NOTE : This function Should not be modified, when the callback is needed,
\r
693 the HAL_CRYP_MspInit could be implemented in the user file
\r
698 * @brief DeInitializes CRYP MSP.
\r
699 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
700 * the configuration information for CRYP module
\r
703 __weak void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp)
\r
705 /* NOTE : This function Should not be modified, when the callback is needed,
\r
706 the HAL_CRYP_MspDeInit could be implemented in the user file
\r
714 /** @defgroup CRYP_Exported_Functions_Group2 AES processing functions
\r
715 * @brief processing functions.
\r
718 ==============================================================================
\r
719 ##### AES processing functions #####
\r
720 ==============================================================================
\r
721 [..] This section provides functions allowing to:
\r
722 (+) Encrypt plaintext using AES-128/192/256 using chaining modes
\r
723 (+) Decrypt cyphertext using AES-128/192/256 using chaining modes
\r
724 [..] Three processing functions are available:
\r
734 * @brief Initializes the CRYP peripheral in AES ECB encryption mode
\r
735 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
736 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
737 * the configuration information for CRYP module
\r
738 * @param pPlainData: Pointer to the plaintext buffer
\r
739 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
740 * @param pCypherData: Pointer to the cyphertext buffer
\r
741 * @param Timeout: Specify Timeout value
\r
742 * @retval HAL status
\r
744 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
746 /* Process Locked */
\r
749 /* Change the CRYP state */
\r
750 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
752 /* Check if initialization phase has already been performed */
\r
753 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
756 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
758 /* Set the CRYP peripheral in AES ECB mode */
\r
759 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB);
\r
762 __HAL_CRYP_FIFO_FLUSH();
\r
765 __HAL_CRYP_ENABLE();
\r
767 /* Set the phase */
\r
768 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
771 /* Write Plain Data and Get Cypher Data */
\r
772 if(CRYP_ProcessData(hcryp,pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
774 return HAL_TIMEOUT;
\r
777 /* Change the CRYP state */
\r
778 hcryp->State = HAL_CRYP_STATE_READY;
\r
780 /* Process Unlocked */
\r
781 __HAL_UNLOCK(hcryp);
\r
783 /* Return function status */
\r
788 * @brief Initializes the CRYP peripheral in AES CBC encryption mode
\r
789 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
790 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
791 * the configuration information for CRYP module
\r
792 * @param pPlainData: Pointer to the plaintext buffer
\r
793 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
794 * @param pCypherData: Pointer to the cyphertext buffer
\r
795 * @param Timeout: Specify Timeout value
\r
796 * @retval HAL status
\r
798 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
800 /* Process Locked */
\r
803 /* Change the CRYP state */
\r
804 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
806 /* Check if initialization phase has already been performed */
\r
807 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
810 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
812 /* Set the CRYP peripheral in AES ECB mode */
\r
813 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC);
\r
815 /* Set the Initialization Vector */
\r
816 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
819 __HAL_CRYP_FIFO_FLUSH();
\r
822 __HAL_CRYP_ENABLE();
\r
824 /* Set the phase */
\r
825 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
828 /* Write Plain Data and Get Cypher Data */
\r
829 if(CRYP_ProcessData(hcryp,pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
831 return HAL_TIMEOUT;
\r
834 /* Change the CRYP state */
\r
835 hcryp->State = HAL_CRYP_STATE_READY;
\r
837 /* Process Unlocked */
\r
838 __HAL_UNLOCK(hcryp);
\r
840 /* Return function status */
\r
845 * @brief Initializes the CRYP peripheral in AES CTR encryption mode
\r
846 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
847 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
848 * the configuration information for CRYP module
\r
849 * @param pPlainData: Pointer to the plaintext buffer
\r
850 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
851 * @param pCypherData: Pointer to the cyphertext buffer
\r
852 * @param Timeout: Specify Timeout value
\r
853 * @retval HAL status
\r
855 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
857 /* Process Locked */
\r
860 /* Change the CRYP state */
\r
861 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
863 /* Check if initialization phase has already been performed */
\r
864 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
867 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
869 /* Set the CRYP peripheral in AES ECB mode */
\r
870 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR);
\r
872 /* Set the Initialization Vector */
\r
873 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
876 __HAL_CRYP_FIFO_FLUSH();
\r
879 __HAL_CRYP_ENABLE();
\r
881 /* Set the phase */
\r
882 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
885 /* Write Plain Data and Get Cypher Data */
\r
886 if(CRYP_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
888 return HAL_TIMEOUT;
\r
891 /* Change the CRYP state */
\r
892 hcryp->State = HAL_CRYP_STATE_READY;
\r
894 /* Process Unlocked */
\r
895 __HAL_UNLOCK(hcryp);
\r
897 /* Return function status */
\r
904 * @brief Initializes the CRYP peripheral in AES ECB decryption mode
\r
905 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
906 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
907 * the configuration information for CRYP module
\r
908 * @param pCypherData: Pointer to the cyphertext buffer
\r
909 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
910 * @param pPlainData: Pointer to the plaintext buffer
\r
911 * @param Timeout: Specify Timeout value
\r
912 * @retval HAL status
\r
914 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
916 uint32_t tickstart = 0;
\r
918 /* Process Locked */
\r
921 /* Change the CRYP state */
\r
922 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
924 /* Check if initialization phase has already been performed */
\r
925 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
928 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
930 /* Set the CRYP peripheral in AES Key mode */
\r
931 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
934 __HAL_CRYP_ENABLE();
\r
937 tickstart = HAL_GetTick();
\r
939 while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY))
\r
941 /* Check for the Timeout */
\r
942 if(Timeout != HAL_MAX_DELAY)
\r
944 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
947 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
949 /* Process Unlocked */
\r
950 __HAL_UNLOCK(hcryp);
\r
952 return HAL_TIMEOUT;
\r
958 __HAL_CRYP_DISABLE();
\r
960 /* Reset the ALGOMODE bits*/
\r
961 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
963 /* Set the CRYP peripheral in AES ECB decryption mode */
\r
964 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
\r
966 __HAL_CRYP_FIFO_FLUSH();
\r
969 __HAL_CRYP_ENABLE();
\r
971 /* Set the phase */
\r
972 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
975 /* Write Plain Data and Get Cypher Data */
\r
976 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
978 return HAL_TIMEOUT;
\r
981 /* Change the CRYP state */
\r
982 hcryp->State = HAL_CRYP_STATE_READY;
\r
984 /* Process Unlocked */
\r
985 __HAL_UNLOCK(hcryp);
\r
987 /* Return function status */
\r
992 * @brief Initializes the CRYP peripheral in AES ECB decryption mode
\r
993 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
994 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
995 * the configuration information for CRYP module
\r
996 * @param pCypherData: Pointer to the cyphertext buffer
\r
997 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
998 * @param pPlainData: Pointer to the plaintext buffer
\r
999 * @param Timeout: Specify Timeout value
\r
1000 * @retval HAL status
\r
1002 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
1004 uint32_t tickstart = 0;
\r
1006 /* Process Locked */
\r
1007 __HAL_LOCK(hcryp);
\r
1009 /* Change the CRYP state */
\r
1010 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1012 /* Check if initialization phase has already been performed */
\r
1013 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1016 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1018 /* Set the CRYP peripheral in AES Key mode */
\r
1019 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
1022 __HAL_CRYP_ENABLE();
\r
1025 tickstart = HAL_GetTick();
\r
1027 while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY))
\r
1029 /* Check for the Timeout */
\r
1030 if(Timeout != HAL_MAX_DELAY)
\r
1032 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
1034 /* Change state */
\r
1035 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
1037 /* Process Unlocked */
\r
1038 __HAL_UNLOCK(hcryp);
\r
1040 return HAL_TIMEOUT;
\r
1045 /* Reset the ALGOMODE bits*/
\r
1046 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
1048 /* Set the CRYP peripheral in AES CBC decryption mode */
\r
1049 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
\r
1051 /* Set the Initialization Vector */
\r
1052 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1055 __HAL_CRYP_FIFO_FLUSH();
\r
1058 __HAL_CRYP_ENABLE();
\r
1060 /* Set the phase */
\r
1061 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1064 /* Write Plain Data and Get Cypher Data */
\r
1065 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
1067 return HAL_TIMEOUT;
\r
1070 /* Change the CRYP state */
\r
1071 hcryp->State = HAL_CRYP_STATE_READY;
\r
1073 /* Process Unlocked */
\r
1074 __HAL_UNLOCK(hcryp);
\r
1076 /* Return function status */
\r
1081 * @brief Initializes the CRYP peripheral in AES CTR decryption mode
\r
1082 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
1083 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1084 * the configuration information for CRYP module
\r
1085 * @param pCypherData: Pointer to the cyphertext buffer
\r
1086 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1087 * @param pPlainData: Pointer to the plaintext buffer
\r
1088 * @param Timeout: Specify Timeout value
\r
1089 * @retval HAL status
\r
1091 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
1093 /* Process Locked */
\r
1094 __HAL_LOCK(hcryp);
\r
1096 /* Check if initialization phase has already been performed */
\r
1097 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1099 /* Change the CRYP state */
\r
1100 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1103 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1105 /* Set the CRYP peripheral in AES CTR mode */
\r
1106 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
\r
1108 /* Set the Initialization Vector */
\r
1109 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1112 __HAL_CRYP_FIFO_FLUSH();
\r
1115 __HAL_CRYP_ENABLE();
\r
1117 /* Set the phase */
\r
1118 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1121 /* Write Plain Data and Get Cypher Data */
\r
1122 if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
1124 return HAL_TIMEOUT;
\r
1127 /* Change the CRYP state */
\r
1128 hcryp->State = HAL_CRYP_STATE_READY;
\r
1130 /* Process Unlocked */
\r
1131 __HAL_UNLOCK(hcryp);
\r
1133 /* Return function status */
\r
1138 * @brief Initializes the CRYP peripheral in AES ECB encryption mode using Interrupt.
\r
1139 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1140 * the configuration information for CRYP module
\r
1141 * @param pPlainData: Pointer to the plaintext buffer
\r
1142 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1143 * @param pCypherData: Pointer to the cyphertext buffer
\r
1144 * @retval HAL status
\r
1146 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1148 uint32_t inputaddr;
\r
1149 uint32_t outputaddr;
\r
1151 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1153 /* Process Locked */
\r
1154 __HAL_LOCK(hcryp);
\r
1156 hcryp->CrypInCount = Size;
\r
1157 hcryp->pCrypInBuffPtr = pPlainData;
\r
1158 hcryp->pCrypOutBuffPtr = pCypherData;
\r
1159 hcryp->CrypOutCount = Size;
\r
1161 /* Change the CRYP state */
\r
1162 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1164 /* Check if initialization phase has already been performed */
\r
1165 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1168 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1170 /* Set the CRYP peripheral in AES ECB mode */
\r
1171 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB);
\r
1174 __HAL_CRYP_FIFO_FLUSH();
\r
1176 /* Set the phase */
\r
1177 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1180 /* Enable Interrupts */
\r
1181 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
1184 __HAL_CRYP_ENABLE();
\r
1186 /* Return function status */
\r
1189 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
1191 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1192 /* Write the Input block in the IN FIFO */
\r
1193 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1195 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1197 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1199 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1200 hcryp->pCrypInBuffPtr += 16;
\r
1201 hcryp->CrypInCount -= 16;
\r
1202 if(hcryp->CrypInCount == 0)
\r
1204 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
1205 /* Call the Input data transfer complete callback */
\r
1206 HAL_CRYP_InCpltCallback(hcryp);
\r
1209 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
1211 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1212 /* Read the Output block from the Output FIFO */
\r
1213 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1215 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1217 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1219 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1220 hcryp->pCrypOutBuffPtr += 16;
\r
1221 hcryp->CrypOutCount -= 16;
\r
1222 if(hcryp->CrypOutCount == 0)
\r
1224 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
1225 /* Process Locked */
\r
1226 __HAL_UNLOCK(hcryp);
\r
1227 /* Change the CRYP state */
\r
1228 hcryp->State = HAL_CRYP_STATE_READY;
\r
1229 /* Call Input transfer complete callback */
\r
1230 HAL_CRYP_OutCpltCallback(hcryp);
\r
1234 /* Return function status */
\r
1239 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using Interrupt.
\r
1240 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1241 * the configuration information for CRYP module
\r
1242 * @param pPlainData: Pointer to the plaintext buffer
\r
1243 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1244 * @param pCypherData: Pointer to the cyphertext buffer
\r
1245 * @retval HAL status
\r
1247 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1249 uint32_t inputaddr;
\r
1250 uint32_t outputaddr;
\r
1252 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1254 /* Process Locked */
\r
1255 __HAL_LOCK(hcryp);
\r
1257 hcryp->CrypInCount = Size;
\r
1258 hcryp->pCrypInBuffPtr = pPlainData;
\r
1259 hcryp->pCrypOutBuffPtr = pCypherData;
\r
1260 hcryp->CrypOutCount = Size;
\r
1262 /* Change the CRYP state */
\r
1263 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1265 /* Check if initialization phase has already been performed */
\r
1266 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1269 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1271 /* Set the CRYP peripheral in AES CBC mode */
\r
1272 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC);
\r
1274 /* Set the Initialization Vector */
\r
1275 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1278 __HAL_CRYP_FIFO_FLUSH();
\r
1280 /* Set the phase */
\r
1281 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1283 /* Enable Interrupts */
\r
1284 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
1287 __HAL_CRYP_ENABLE();
\r
1289 /* Return function status */
\r
1292 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
1294 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1295 /* Write the Input block in the IN FIFO */
\r
1296 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1298 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1300 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1302 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1303 hcryp->pCrypInBuffPtr += 16;
\r
1304 hcryp->CrypInCount -= 16;
\r
1305 if(hcryp->CrypInCount == 0)
\r
1307 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
1308 /* Call the Input data transfer complete callback */
\r
1309 HAL_CRYP_InCpltCallback(hcryp);
\r
1312 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
1314 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1315 /* Read the Output block from the Output FIFO */
\r
1316 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1318 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1320 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1322 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1323 hcryp->pCrypOutBuffPtr += 16;
\r
1324 hcryp->CrypOutCount -= 16;
\r
1325 if(hcryp->CrypOutCount == 0)
\r
1327 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
1328 /* Process Locked */
\r
1329 __HAL_UNLOCK(hcryp);
\r
1330 /* Change the CRYP state */
\r
1331 hcryp->State = HAL_CRYP_STATE_READY;
\r
1332 /* Call Input transfer complete callback */
\r
1333 HAL_CRYP_OutCpltCallback(hcryp);
\r
1337 /* Return function status */
\r
1342 * @brief Initializes the CRYP peripheral in AES CTR encryption mode using Interrupt.
\r
1343 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1344 * the configuration information for CRYP module
\r
1345 * @param pPlainData: Pointer to the plaintext buffer
\r
1346 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1347 * @param pCypherData: Pointer to the cyphertext buffer
\r
1348 * @retval HAL status
\r
1350 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1352 uint32_t inputaddr;
\r
1353 uint32_t outputaddr;
\r
1355 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1357 /* Process Locked */
\r
1358 __HAL_LOCK(hcryp);
\r
1360 hcryp->CrypInCount = Size;
\r
1361 hcryp->pCrypInBuffPtr = pPlainData;
\r
1362 hcryp->pCrypOutBuffPtr = pCypherData;
\r
1363 hcryp->CrypOutCount = Size;
\r
1365 /* Change the CRYP state */
\r
1366 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1368 /* Check if initialization phase has already been performed */
\r
1369 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1372 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1374 /* Set the CRYP peripheral in AES CTR mode */
\r
1375 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR);
\r
1377 /* Set the Initialization Vector */
\r
1378 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1381 __HAL_CRYP_FIFO_FLUSH();
\r
1383 /* Set the phase */
\r
1384 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1386 /* Enable Interrupts */
\r
1387 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
1390 __HAL_CRYP_ENABLE();
\r
1392 /* Return function status */
\r
1395 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
1397 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1398 /* Write the Input block in the IN FIFO */
\r
1399 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1401 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1403 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1405 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1406 hcryp->pCrypInBuffPtr += 16;
\r
1407 hcryp->CrypInCount -= 16;
\r
1408 if(hcryp->CrypInCount == 0)
\r
1410 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
1411 /* Call the Input data transfer complete callback */
\r
1412 HAL_CRYP_InCpltCallback(hcryp);
\r
1415 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
1417 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1418 /* Read the Output block from the Output FIFO */
\r
1419 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1421 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1423 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1425 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1426 hcryp->pCrypOutBuffPtr += 16;
\r
1427 hcryp->CrypOutCount -= 16;
\r
1428 if(hcryp->CrypOutCount == 0)
\r
1430 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
1431 /* Process Unlocked */
\r
1432 __HAL_UNLOCK(hcryp);
\r
1433 /* Change the CRYP state */
\r
1434 hcryp->State = HAL_CRYP_STATE_READY;
\r
1435 /* Call Input transfer complete callback */
\r
1436 HAL_CRYP_OutCpltCallback(hcryp);
\r
1440 /* Return function status */
\r
1446 * @brief Initializes the CRYP peripheral in AES ECB decryption mode using Interrupt.
\r
1447 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1448 * the configuration information for CRYP module
\r
1449 * @param pCypherData: Pointer to the cyphertext buffer
\r
1450 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1451 * @param pPlainData: Pointer to the plaintext buffer
\r
1452 * @retval HAL status
\r
1454 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
1456 uint32_t tickstart = 0;
\r
1458 uint32_t inputaddr;
\r
1459 uint32_t outputaddr;
\r
1461 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1463 /* Process Locked */
\r
1464 __HAL_LOCK(hcryp);
\r
1466 hcryp->CrypInCount = Size;
\r
1467 hcryp->pCrypInBuffPtr = pCypherData;
\r
1468 hcryp->pCrypOutBuffPtr = pPlainData;
\r
1469 hcryp->CrypOutCount = Size;
\r
1471 /* Change the CRYP state */
\r
1472 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1474 /* Check if initialization phase has already been performed */
\r
1475 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1478 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1480 /* Set the CRYP peripheral in AES Key mode */
\r
1481 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
1483 __HAL_CRYP_ENABLE();
\r
1486 tickstart = HAL_GetTick();
\r
1488 while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY))
\r
1490 /* Check for the Timeout */
\r
1491 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
\r
1493 /* Change state */
\r
1494 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
1496 /* Process Unlocked */
\r
1497 __HAL_UNLOCK(hcryp);
\r
1499 return HAL_TIMEOUT;
\r
1503 /* Reset the ALGOMODE bits*/
\r
1504 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
1506 /* Set the CRYP peripheral in AES ECB decryption mode */
\r
1507 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
\r
1510 __HAL_CRYP_FIFO_FLUSH();
\r
1512 /* Set the phase */
\r
1513 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1516 /* Enable Interrupts */
\r
1517 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
1520 __HAL_CRYP_ENABLE();
\r
1522 /* Return function status */
\r
1525 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
1527 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1528 /* Write the Input block in the IN FIFO */
\r
1529 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1531 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1533 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1535 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1536 hcryp->pCrypInBuffPtr += 16;
\r
1537 hcryp->CrypInCount -= 16;
\r
1538 if(hcryp->CrypInCount == 0)
\r
1540 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
1541 /* Call the Input data transfer complete callback */
\r
1542 HAL_CRYP_InCpltCallback(hcryp);
\r
1545 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
1547 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1548 /* Read the Output block from the Output FIFO */
\r
1549 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1551 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1553 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1555 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1556 hcryp->pCrypOutBuffPtr += 16;
\r
1557 hcryp->CrypOutCount -= 16;
\r
1558 if(hcryp->CrypOutCount == 0)
\r
1560 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
1561 /* Process Unlocked */
\r
1562 __HAL_UNLOCK(hcryp);
\r
1563 /* Change the CRYP state */
\r
1564 hcryp->State = HAL_CRYP_STATE_READY;
\r
1565 /* Call Input transfer complete callback */
\r
1566 HAL_CRYP_OutCpltCallback(hcryp);
\r
1570 /* Return function status */
\r
1575 * @brief Initializes the CRYP peripheral in AES CBC decryption mode using IT.
\r
1576 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1577 * the configuration information for CRYP module
\r
1578 * @param pCypherData: Pointer to the cyphertext buffer
\r
1579 * @param Size: Length of the plaintext buffer, must be a multiple of 16
\r
1580 * @param pPlainData: Pointer to the plaintext buffer
\r
1581 * @retval HAL status
\r
1583 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
1586 uint32_t tickstart = 0;
\r
1587 uint32_t inputaddr;
\r
1588 uint32_t outputaddr;
\r
1590 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1592 /* Process Locked */
\r
1593 __HAL_LOCK(hcryp);
\r
1595 /* Get the buffer addresses and sizes */
\r
1596 hcryp->CrypInCount = Size;
\r
1597 hcryp->pCrypInBuffPtr = pCypherData;
\r
1598 hcryp->pCrypOutBuffPtr = pPlainData;
\r
1599 hcryp->CrypOutCount = Size;
\r
1601 /* Change the CRYP state */
\r
1602 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1604 /* Check if initialization phase has already been performed */
\r
1605 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1608 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1610 /* Set the CRYP peripheral in AES Key mode */
\r
1611 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
1614 __HAL_CRYP_ENABLE();
\r
1617 tickstart = HAL_GetTick();
\r
1619 while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY))
\r
1621 /* Check for the Timeout */
\r
1622 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
\r
1624 /* Change state */
\r
1625 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
1627 /* Process Unlocked */
\r
1628 __HAL_UNLOCK(hcryp);
\r
1630 return HAL_TIMEOUT;
\r
1634 /* Reset the ALGOMODE bits*/
\r
1635 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
1637 /* Set the CRYP peripheral in AES CBC decryption mode */
\r
1638 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
\r
1640 /* Set the Initialization Vector */
\r
1641 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1644 __HAL_CRYP_FIFO_FLUSH();
\r
1647 __HAL_CRYP_ENABLE();
\r
1649 /* Set the phase */
\r
1650 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1653 /* Enable Interrupts */
\r
1654 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
1657 __HAL_CRYP_ENABLE();
\r
1659 /* Return function status */
\r
1662 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
1664 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1665 /* Write the Input block in the IN FIFO */
\r
1666 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1668 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1670 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1672 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1673 hcryp->pCrypInBuffPtr += 16;
\r
1674 hcryp->CrypInCount -= 16;
\r
1675 if(hcryp->CrypInCount == 0)
\r
1677 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
1678 /* Call the Input data transfer complete callback */
\r
1679 HAL_CRYP_InCpltCallback(hcryp);
\r
1682 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
1684 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1685 /* Read the Output block from the Output FIFO */
\r
1686 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1688 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1690 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1692 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1693 hcryp->pCrypOutBuffPtr += 16;
\r
1694 hcryp->CrypOutCount -= 16;
\r
1695 if(hcryp->CrypOutCount == 0)
\r
1697 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
1698 /* Process Unlocked */
\r
1699 __HAL_UNLOCK(hcryp);
\r
1700 /* Change the CRYP state */
\r
1701 hcryp->State = HAL_CRYP_STATE_READY;
\r
1702 /* Call Input transfer complete callback */
\r
1703 HAL_CRYP_OutCpltCallback(hcryp);
\r
1707 /* Return function status */
\r
1712 * @brief Initializes the CRYP peripheral in AES CTR decryption mode using Interrupt.
\r
1713 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1714 * the configuration information for CRYP module
\r
1715 * @param pCypherData: Pointer to the cyphertext buffer
\r
1716 * @param Size: Length of the plaintext buffer, must be a multiple of 16
\r
1717 * @param pPlainData: Pointer to the plaintext buffer
\r
1718 * @retval HAL status
\r
1720 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
1722 uint32_t inputaddr;
\r
1723 uint32_t outputaddr;
\r
1725 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
1727 /* Process Locked */
\r
1728 __HAL_LOCK(hcryp);
\r
1730 /* Get the buffer addresses and sizes */
\r
1731 hcryp->CrypInCount = Size;
\r
1732 hcryp->pCrypInBuffPtr = pCypherData;
\r
1733 hcryp->pCrypOutBuffPtr = pPlainData;
\r
1734 hcryp->CrypOutCount = Size;
\r
1736 /* Change the CRYP state */
\r
1737 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1739 /* Check if initialization phase has already been performed */
\r
1740 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1743 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1745 /* Set the CRYP peripheral in AES CTR mode */
\r
1746 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
\r
1748 /* Set the Initialization Vector */
\r
1749 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1752 __HAL_CRYP_FIFO_FLUSH();
\r
1754 /* Set the phase */
\r
1755 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1758 /* Enable Interrupts */
\r
1759 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
1762 __HAL_CRYP_ENABLE();
\r
1764 /* Return function status */
\r
1767 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
1769 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
1770 /* Write the Input block in the IN FIFO */
\r
1771 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1773 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1775 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1777 CRYP->DR = *(uint32_t*)(inputaddr);
\r
1778 hcryp->pCrypInBuffPtr += 16;
\r
1779 hcryp->CrypInCount -= 16;
\r
1780 if(hcryp->CrypInCount == 0)
\r
1782 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
1783 /* Call the Input data transfer complete callback */
\r
1784 HAL_CRYP_InCpltCallback(hcryp);
\r
1787 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
1789 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
1790 /* Read the Output block from the Output FIFO */
\r
1791 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1793 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1795 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1797 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
1798 hcryp->pCrypOutBuffPtr += 16;
\r
1799 hcryp->CrypOutCount -= 16;
\r
1800 if(hcryp->CrypOutCount == 0)
\r
1802 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
1803 /* Process Unlocked */
\r
1804 __HAL_UNLOCK(hcryp);
\r
1805 /* Change the CRYP state */
\r
1806 hcryp->State = HAL_CRYP_STATE_READY;
\r
1807 /* Call Input transfer complete callback */
\r
1808 HAL_CRYP_OutCpltCallback(hcryp);
\r
1812 /* Return function status */
\r
1817 * @brief Initializes the CRYP peripheral in AES ECB encryption mode using DMA.
\r
1818 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1819 * the configuration information for CRYP module
\r
1820 * @param pPlainData: Pointer to the plaintext buffer
\r
1821 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1822 * @param pCypherData: Pointer to the cyphertext buffer
\r
1823 * @retval HAL status
\r
1825 HAL_StatusTypeDef HAL_CRYP_AESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1827 uint32_t inputaddr;
\r
1828 uint32_t outputaddr;
\r
1830 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
1832 /* Process Locked */
\r
1833 __HAL_LOCK(hcryp);
\r
1835 inputaddr = (uint32_t)pPlainData;
\r
1836 outputaddr = (uint32_t)pCypherData;
\r
1838 /* Change the CRYP state */
\r
1839 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1841 /* Check if initialization phase has already been performed */
\r
1842 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1845 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1847 /* Set the CRYP peripheral in AES ECB mode */
\r
1848 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB);
\r
1851 __HAL_CRYP_FIFO_FLUSH();
\r
1853 /* Set the phase */
\r
1854 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1856 /* Set the input and output addresses and start DMA transfer */
\r
1857 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
1859 /* Process Unlocked */
\r
1860 __HAL_UNLOCK(hcryp);
\r
1862 /* Return function status */
\r
1867 return HAL_ERROR;
\r
1872 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA.
\r
1873 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1874 * the configuration information for CRYP module
\r
1875 * @param pPlainData: Pointer to the plaintext buffer
\r
1876 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1877 * @param pCypherData: Pointer to the cyphertext buffer
\r
1878 * @retval HAL status
\r
1880 HAL_StatusTypeDef HAL_CRYP_AESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1882 uint32_t inputaddr;
\r
1883 uint32_t outputaddr;
\r
1885 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
1887 /* Process Locked */
\r
1888 __HAL_LOCK(hcryp);
\r
1890 inputaddr = (uint32_t)pPlainData;
\r
1891 outputaddr = (uint32_t)pCypherData;
\r
1893 /* Change the CRYP state */
\r
1894 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1896 /* Check if initialization phase has already been performed */
\r
1897 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1900 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1902 /* Set the CRYP peripheral in AES ECB mode */
\r
1903 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC);
\r
1905 /* Set the Initialization Vector */
\r
1906 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1909 __HAL_CRYP_FIFO_FLUSH();
\r
1911 /* Set the phase */
\r
1912 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1914 /* Set the input and output addresses and start DMA transfer */
\r
1915 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
1917 /* Process Unlocked */
\r
1918 __HAL_UNLOCK(hcryp);
\r
1920 /* Return function status */
\r
1925 return HAL_ERROR;
\r
1930 * @brief Initializes the CRYP peripheral in AES CTR encryption mode using DMA.
\r
1931 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1932 * the configuration information for CRYP module
\r
1933 * @param pPlainData: Pointer to the plaintext buffer
\r
1934 * @param Size: Length of the plaintext buffer, must be a multiple of 16.
\r
1935 * @param pCypherData: Pointer to the cyphertext buffer
\r
1936 * @retval HAL status
\r
1938 HAL_StatusTypeDef HAL_CRYP_AESCTR_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
1940 uint32_t inputaddr;
\r
1941 uint32_t outputaddr;
\r
1943 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
1945 /* Process Locked */
\r
1946 __HAL_LOCK(hcryp);
\r
1948 inputaddr = (uint32_t)pPlainData;
\r
1949 outputaddr = (uint32_t)pCypherData;
\r
1951 /* Change the CRYP state */
\r
1952 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
1954 /* Check if initialization phase has already been performed */
\r
1955 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
1958 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
1960 /* Set the CRYP peripheral in AES ECB mode */
\r
1961 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR);
\r
1963 /* Set the Initialization Vector */
\r
1964 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
1967 __HAL_CRYP_FIFO_FLUSH();
\r
1969 /* Set the phase */
\r
1970 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
1973 /* Set the input and output addresses and start DMA transfer */
\r
1974 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
1976 /* Process Unlocked */
\r
1977 __HAL_UNLOCK(hcryp);
\r
1979 /* Return function status */
\r
1984 return HAL_ERROR;
\r
1989 * @brief Initializes the CRYP peripheral in AES ECB decryption mode using DMA.
\r
1990 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
1991 * the configuration information for CRYP module
\r
1992 * @param pCypherData: Pointer to the cyphertext buffer
\r
1993 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
1994 * @param pPlainData: Pointer to the plaintext buffer
\r
1995 * @retval HAL status
\r
1997 HAL_StatusTypeDef HAL_CRYP_AESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
1999 uint32_t tickstart = 0;
\r
2000 uint32_t inputaddr;
\r
2001 uint32_t outputaddr;
\r
2003 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2005 /* Process Locked */
\r
2006 __HAL_LOCK(hcryp);
\r
2008 inputaddr = (uint32_t)pCypherData;
\r
2009 outputaddr = (uint32_t)pPlainData;
\r
2011 /* Change the CRYP state */
\r
2012 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2014 /* Check if initialization phase has already been performed */
\r
2015 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
2018 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
2020 /* Set the CRYP peripheral in AES Key mode */
\r
2021 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
2024 __HAL_CRYP_ENABLE();
\r
2027 tickstart = HAL_GetTick();
\r
2029 while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY))
\r
2031 /* Check for the Timeout */
\r
2032 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
\r
2034 /* Change state */
\r
2035 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
2037 /* Process Unlocked */
\r
2038 __HAL_UNLOCK(hcryp);
\r
2040 return HAL_TIMEOUT;
\r
2044 /* Reset the ALGOMODE bits*/
\r
2045 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
2047 /* Set the CRYP peripheral in AES ECB decryption mode */
\r
2048 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_ECB | CRYP_CR_ALGODIR);
\r
2051 __HAL_CRYP_FIFO_FLUSH();
\r
2053 /* Set the phase */
\r
2054 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
2057 /* Set the input and output addresses and start DMA transfer */
\r
2058 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2060 /* Process Unlocked */
\r
2061 __HAL_UNLOCK(hcryp);
\r
2063 /* Return function status */
\r
2068 return HAL_ERROR;
\r
2073 * @brief Initializes the CRYP peripheral in AES CBC encryption mode using DMA.
\r
2074 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2075 * the configuration information for CRYP module
\r
2076 * @param pCypherData: Pointer to the cyphertext buffer
\r
2077 * @param Size: Length of the plaintext buffer, must be a multiple of 16 bytes
\r
2078 * @param pPlainData: Pointer to the plaintext buffer
\r
2079 * @retval HAL status
\r
2081 HAL_StatusTypeDef HAL_CRYP_AESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2083 uint32_t tickstart = 0;
\r
2084 uint32_t inputaddr;
\r
2085 uint32_t outputaddr;
\r
2087 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2089 /* Process Locked */
\r
2090 __HAL_LOCK(hcryp);
\r
2092 inputaddr = (uint32_t)pCypherData;
\r
2093 outputaddr = (uint32_t)pPlainData;
\r
2095 /* Change the CRYP state */
\r
2096 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2098 /* Check if initialization phase has already been performed */
\r
2099 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
2102 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
2104 /* Set the CRYP peripheral in AES Key mode */
\r
2105 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_KEY | CRYP_CR_ALGODIR);
\r
2108 __HAL_CRYP_ENABLE();
\r
2111 tickstart = HAL_GetTick();
\r
2113 while(HAL_IS_BIT_SET(CRYP->SR, CRYP_FLAG_BUSY))
\r
2115 /* Check for the Timeout */
\r
2116 if((HAL_GetTick() - tickstart ) > CRYP_TIMEOUT_VALUE)
\r
2118 /* Change state */
\r
2119 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
\r
2121 /* Process Unlocked */
\r
2122 __HAL_UNLOCK(hcryp);
\r
2124 return HAL_TIMEOUT;
\r
2128 /* Reset the ALGOMODE bits*/
\r
2129 CRYP->CR &= (uint32_t)(~CRYP_CR_ALGOMODE);
\r
2131 /* Set the CRYP peripheral in AES CBC decryption mode */
\r
2132 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CBC | CRYP_CR_ALGODIR);
\r
2134 /* Set the Initialization Vector */
\r
2135 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
2138 __HAL_CRYP_FIFO_FLUSH();
\r
2140 /* Set the phase */
\r
2141 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
2144 /* Set the input and output addresses and start DMA transfer */
\r
2145 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2147 /* Process Unlocked */
\r
2148 __HAL_UNLOCK(hcryp);
\r
2150 /* Return function status */
\r
2155 return HAL_ERROR;
\r
2160 * @brief Initializes the CRYP peripheral in AES CTR decryption mode using DMA.
\r
2161 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2162 * the configuration information for CRYP module
\r
2163 * @param pCypherData: Pointer to the cyphertext buffer
\r
2164 * @param Size: Length of the plaintext buffer, must be a multiple of 16
\r
2165 * @param pPlainData: Pointer to the plaintext buffer
\r
2166 * @retval HAL status
\r
2168 HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2170 uint32_t inputaddr;
\r
2171 uint32_t outputaddr;
\r
2173 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2175 /* Process Locked */
\r
2176 __HAL_LOCK(hcryp);
\r
2178 inputaddr = (uint32_t)pCypherData;
\r
2179 outputaddr = (uint32_t)pPlainData;
\r
2181 /* Change the CRYP state */
\r
2182 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2184 /* Check if initialization phase has already been performed */
\r
2185 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
\r
2188 CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
\r
2190 /* Set the CRYP peripheral in AES CTR mode */
\r
2191 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR);
\r
2193 /* Set the Initialization Vector */
\r
2194 CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B);
\r
2197 __HAL_CRYP_FIFO_FLUSH();
\r
2199 /* Set the phase */
\r
2200 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
\r
2203 /* Set the input and output addresses and start DMA transfer */
\r
2204 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2206 /* Process Unlocked */
\r
2207 __HAL_UNLOCK(hcryp);
\r
2209 /* Return function status */
\r
2214 return HAL_ERROR;
\r
2223 /** @defgroup CRYP_Exported_Functions_Group3 DES processing functions
\r
2224 * @brief processing functions.
\r
2227 ==============================================================================
\r
2228 ##### DES processing functions #####
\r
2229 ==============================================================================
\r
2230 [..] This section provides functions allowing to:
\r
2231 (+) Encrypt plaintext using DES using ECB or CBC chaining modes
\r
2232 (+) Decrypt cyphertext using ECB or CBC chaining modes
\r
2233 [..] Three processing functions are available:
\r
2235 (+) Interrupt mode
\r
2243 * @brief Initializes the CRYP peripheral in DES ECB encryption mode.
\r
2244 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2245 * the configuration information for CRYP module
\r
2246 * @param pPlainData: Pointer to the plaintext buffer
\r
2247 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2248 * @param pCypherData: Pointer to the cyphertext buffer
\r
2249 * @param Timeout: Specify Timeout value
\r
2250 * @retval HAL status
\r
2252 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2254 /* Process Locked */
\r
2255 __HAL_LOCK(hcryp);
\r
2257 /* Change the CRYP state */
\r
2258 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2260 /* Set CRYP peripheral in DES ECB encryption mode */
\r
2261 CRYP_SetDESECBMode(hcryp, 0);
\r
2264 __HAL_CRYP_ENABLE();
\r
2266 /* Write Plain Data and Get Cypher Data */
\r
2267 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2269 return HAL_TIMEOUT;
\r
2272 /* Change the CRYP state */
\r
2273 hcryp->State = HAL_CRYP_STATE_READY;
\r
2275 /* Process Unlocked */
\r
2276 __HAL_UNLOCK(hcryp);
\r
2278 /* Return function status */
\r
2283 * @brief Initializes the CRYP peripheral in DES ECB decryption mode.
\r
2284 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2285 * the configuration information for CRYP module
\r
2286 * @param pPlainData: Pointer to the plaintext buffer
\r
2287 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2288 * @param pCypherData: Pointer to the cyphertext buffer
\r
2289 * @param Timeout: Specify Timeout value
\r
2290 * @retval HAL status
\r
2292 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2294 /* Process Locked */
\r
2295 __HAL_LOCK(hcryp);
\r
2297 /* Change the CRYP state */
\r
2298 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2300 /* Set CRYP peripheral in DES ECB decryption mode */
\r
2301 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
2304 __HAL_CRYP_ENABLE();
\r
2306 /* Write Plain Data and Get Cypher Data */
\r
2307 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2309 return HAL_TIMEOUT;
\r
2312 /* Change the CRYP state */
\r
2313 hcryp->State = HAL_CRYP_STATE_READY;
\r
2315 /* Process Unlocked */
\r
2316 __HAL_UNLOCK(hcryp);
\r
2318 /* Return function status */
\r
2323 * @brief Initializes the CRYP peripheral in DES CBC encryption mode.
\r
2324 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2325 * the configuration information for CRYP module
\r
2326 * @param pPlainData: Pointer to the plaintext buffer
\r
2327 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2328 * @param pCypherData: Pointer to the cyphertext buffer
\r
2329 * @param Timeout: Specify Timeout value
\r
2330 * @retval HAL status
\r
2332 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2334 /* Process Locked */
\r
2335 __HAL_LOCK(hcryp);
\r
2337 /* Change the CRYP state */
\r
2338 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2340 /* Set CRYP peripheral in DES CBC encryption mode */
\r
2341 CRYP_SetDESCBCMode(hcryp, 0);
\r
2344 __HAL_CRYP_ENABLE();
\r
2346 /* Write Plain Data and Get Cypher Data */
\r
2347 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2349 return HAL_TIMEOUT;
\r
2352 /* Change the CRYP state */
\r
2353 hcryp->State = HAL_CRYP_STATE_READY;
\r
2355 /* Process Unlocked */
\r
2356 __HAL_UNLOCK(hcryp);
\r
2358 /* Return function status */
\r
2363 * @brief Initializes the CRYP peripheral in DES ECB decryption mode.
\r
2364 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2365 * the configuration information for CRYP module
\r
2366 * @param pPlainData: Pointer to the plaintext buffer
\r
2367 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2368 * @param pCypherData: Pointer to the cyphertext buffer
\r
2369 * @param Timeout: Specify Timeout value
\r
2370 * @retval HAL status
\r
2372 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2374 /* Process Locked */
\r
2375 __HAL_LOCK(hcryp);
\r
2377 /* Change the CRYP state */
\r
2378 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2380 /* Set CRYP peripheral in DES CBC decryption mode */
\r
2381 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
2384 __HAL_CRYP_ENABLE();
\r
2386 /* Write Plain Data and Get Cypher Data */
\r
2387 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2389 return HAL_TIMEOUT;
\r
2392 /* Change the CRYP state */
\r
2393 hcryp->State = HAL_CRYP_STATE_READY;
\r
2395 /* Process Unlocked */
\r
2396 __HAL_UNLOCK(hcryp);
\r
2398 /* Return function status */
\r
2403 * @brief Initializes the CRYP peripheral in DES ECB encryption mode using IT.
\r
2404 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2405 * the configuration information for CRYP module
\r
2406 * @param pPlainData: Pointer to the plaintext buffer
\r
2407 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2408 * @param pCypherData: Pointer to the cyphertext buffer
\r
2409 * @retval HAL status
\r
2411 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
2413 uint32_t inputaddr;
\r
2414 uint32_t outputaddr;
\r
2416 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
2418 /* Process Locked */
\r
2419 __HAL_LOCK(hcryp);
\r
2421 hcryp->CrypInCount = Size;
\r
2422 hcryp->pCrypInBuffPtr = pPlainData;
\r
2423 hcryp->pCrypOutBuffPtr = pCypherData;
\r
2424 hcryp->CrypOutCount = Size;
\r
2426 /* Change the CRYP state */
\r
2427 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2429 /* Set CRYP peripheral in DES ECB encryption mode */
\r
2430 CRYP_SetDESECBMode(hcryp, 0);
\r
2432 /* Enable Interrupts */
\r
2433 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
2436 __HAL_CRYP_ENABLE();
\r
2438 /* Return function status */
\r
2441 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
2443 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
2444 /* Write the Input block in the IN FIFO */
\r
2445 CRYP->DR = *(uint32_t*)(inputaddr);
\r
2447 CRYP->DR = *(uint32_t*)(inputaddr);
\r
2449 hcryp->pCrypInBuffPtr += 8;
\r
2450 hcryp->CrypInCount -= 8;
\r
2451 if(hcryp->CrypInCount == 0)
\r
2453 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
2454 /* Call the Input data transfer complete callback */
\r
2455 HAL_CRYP_InCpltCallback(hcryp);
\r
2458 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
2460 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
2461 /* Read the Output block from the Output FIFO */
\r
2462 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
2464 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
2466 hcryp->pCrypOutBuffPtr += 8;
\r
2467 hcryp->CrypOutCount -= 8;
\r
2468 if(hcryp->CrypOutCount == 0)
\r
2471 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
2472 /* Disable CRYP */
\r
2473 __HAL_CRYP_DISABLE();
\r
2474 /* Process Unlocked */
\r
2475 __HAL_UNLOCK(hcryp);
\r
2476 /* Change the CRYP state */
\r
2477 hcryp->State = HAL_CRYP_STATE_READY;
\r
2478 /* Call Input transfer complete callback */
\r
2479 HAL_CRYP_OutCpltCallback(hcryp);
\r
2483 /* Return function status */
\r
2488 * @brief Initializes the CRYP peripheral in DES CBC encryption mode using interrupt.
\r
2489 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2490 * the configuration information for CRYP module
\r
2491 * @param pPlainData: Pointer to the plaintext buffer
\r
2492 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2493 * @param pCypherData: Pointer to the cyphertext buffer
\r
2494 * @retval HAL status
\r
2496 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
2498 uint32_t inputaddr;
\r
2499 uint32_t outputaddr;
\r
2501 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
2503 /* Process Locked */
\r
2504 __HAL_LOCK(hcryp);
\r
2506 hcryp->CrypInCount = Size;
\r
2507 hcryp->pCrypInBuffPtr = pPlainData;
\r
2508 hcryp->pCrypOutBuffPtr = pCypherData;
\r
2509 hcryp->CrypOutCount = Size;
\r
2511 /* Change the CRYP state */
\r
2512 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2514 /* Set CRYP peripheral in DES CBC encryption mode */
\r
2515 CRYP_SetDESCBCMode(hcryp, 0);
\r
2517 /* Enable Interrupts */
\r
2518 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
2521 __HAL_CRYP_ENABLE();
\r
2523 /* Return function status */
\r
2527 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
2529 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
2530 /* Write the Input block in the IN FIFO */
\r
2531 CRYP->DR = *(uint32_t*)(inputaddr);
\r
2533 CRYP->DR = *(uint32_t*)(inputaddr);
\r
2535 hcryp->pCrypInBuffPtr += 8;
\r
2536 hcryp->CrypInCount -= 8;
\r
2537 if(hcryp->CrypInCount == 0)
\r
2539 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
2540 /* Call the Input data transfer complete callback */
\r
2541 HAL_CRYP_InCpltCallback(hcryp);
\r
2544 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
2546 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
2547 /* Read the Output block from the Output FIFO */
\r
2548 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
2550 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
2552 hcryp->pCrypOutBuffPtr += 8;
\r
2553 hcryp->CrypOutCount -= 8;
\r
2554 if(hcryp->CrypOutCount == 0)
\r
2557 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
2558 /* Disable CRYP */
\r
2559 __HAL_CRYP_DISABLE();
\r
2560 /* Process Unlocked */
\r
2561 __HAL_UNLOCK(hcryp);
\r
2562 /* Change the CRYP state */
\r
2563 hcryp->State = HAL_CRYP_STATE_READY;
\r
2564 /* Call Input transfer complete callback */
\r
2565 HAL_CRYP_OutCpltCallback(hcryp);
\r
2569 /* Return function status */
\r
2574 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using IT.
\r
2575 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2576 * the configuration information for CRYP module
\r
2577 * @param pPlainData: Pointer to the plaintext buffer
\r
2578 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2579 * @param pCypherData: Pointer to the cyphertext buffer
\r
2580 * @retval HAL status
\r
2582 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2584 uint32_t inputaddr;
\r
2585 uint32_t outputaddr;
\r
2587 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
2589 /* Process Locked */
\r
2590 __HAL_LOCK(hcryp);
\r
2592 hcryp->CrypInCount = Size;
\r
2593 hcryp->pCrypInBuffPtr = pCypherData;
\r
2594 hcryp->pCrypOutBuffPtr = pPlainData;
\r
2595 hcryp->CrypOutCount = Size;
\r
2597 /* Change the CRYP state */
\r
2598 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2600 /* Set CRYP peripheral in DES ECB decryption mode */
\r
2601 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
2603 /* Enable Interrupts */
\r
2604 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
2607 __HAL_CRYP_ENABLE();
\r
2609 /* Return function status */
\r
2612 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
2614 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
2615 /* Write the Input block in the IN FIFO */
\r
2616 CRYP->DR = *(uint32_t*)(inputaddr);
\r
2618 CRYP->DR = *(uint32_t*)(inputaddr);
\r
2620 hcryp->pCrypInBuffPtr += 8;
\r
2621 hcryp->CrypInCount -= 8;
\r
2622 if(hcryp->CrypInCount == 0)
\r
2624 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
2625 /* Call the Input data transfer complete callback */
\r
2626 HAL_CRYP_InCpltCallback(hcryp);
\r
2629 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
2631 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
2632 /* Read the Output block from the Output FIFO */
\r
2633 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
2635 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
2637 hcryp->pCrypOutBuffPtr += 8;
\r
2638 hcryp->CrypOutCount -= 8;
\r
2639 if(hcryp->CrypOutCount == 0)
\r
2642 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
2643 /* Disable CRYP */
\r
2644 __HAL_CRYP_DISABLE();
\r
2645 /* Process Unlocked */
\r
2646 __HAL_UNLOCK(hcryp);
\r
2647 /* Change the CRYP state */
\r
2648 hcryp->State = HAL_CRYP_STATE_READY;
\r
2649 /* Call Input transfer complete callback */
\r
2650 HAL_CRYP_OutCpltCallback(hcryp);
\r
2654 /* Return function status */
\r
2659 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using interrupt.
\r
2660 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2661 * the configuration information for CRYP module
\r
2662 * @param pPlainData: Pointer to the plaintext buffer
\r
2663 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2664 * @param pCypherData: Pointer to the cyphertext buffer
\r
2665 * @retval HAL status
\r
2667 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2669 uint32_t inputaddr;
\r
2670 uint32_t outputaddr;
\r
2672 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
2674 /* Process Locked */
\r
2675 __HAL_LOCK(hcryp);
\r
2677 hcryp->CrypInCount = Size;
\r
2678 hcryp->pCrypInBuffPtr = pCypherData;
\r
2679 hcryp->pCrypOutBuffPtr = pPlainData;
\r
2680 hcryp->CrypOutCount = Size;
\r
2682 /* Change the CRYP state */
\r
2683 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2685 /* Set CRYP peripheral in DES CBC decryption mode */
\r
2686 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
2688 /* Enable Interrupts */
\r
2689 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
2692 __HAL_CRYP_ENABLE();
\r
2694 /* Return function status */
\r
2697 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
2699 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
2700 /* Write the Input block in the IN FIFO */
\r
2701 CRYP->DR = *(uint32_t*)(inputaddr);
\r
2703 CRYP->DR = *(uint32_t*)(inputaddr);
\r
2705 hcryp->pCrypInBuffPtr += 8;
\r
2706 hcryp->CrypInCount -= 8;
\r
2707 if(hcryp->CrypInCount == 0)
\r
2709 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
2710 /* Call the Input data transfer complete callback */
\r
2711 HAL_CRYP_InCpltCallback(hcryp);
\r
2714 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
2716 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
2717 /* Read the Output block from the Output FIFO */
\r
2718 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
2720 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
2722 hcryp->pCrypOutBuffPtr += 8;
\r
2723 hcryp->CrypOutCount -= 8;
\r
2724 if(hcryp->CrypOutCount == 0)
\r
2727 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
2728 /* Disable CRYP */
\r
2729 __HAL_CRYP_DISABLE();
\r
2730 /* Process Unlocked */
\r
2731 __HAL_UNLOCK(hcryp);
\r
2732 /* Change the CRYP state */
\r
2733 hcryp->State = HAL_CRYP_STATE_READY;
\r
2734 /* Call Input transfer complete callback */
\r
2735 HAL_CRYP_OutCpltCallback(hcryp);
\r
2739 /* Return function status */
\r
2744 * @brief Initializes the CRYP peripheral in DES ECB encryption mode using DMA.
\r
2745 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2746 * the configuration information for CRYP module
\r
2747 * @param pPlainData: Pointer to the plaintext buffer
\r
2748 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2749 * @param pCypherData: Pointer to the cyphertext buffer
\r
2750 * @retval HAL status
\r
2752 HAL_StatusTypeDef HAL_CRYP_DESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
2754 uint32_t inputaddr;
\r
2755 uint32_t outputaddr;
\r
2757 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2759 /* Process Locked */
\r
2760 __HAL_LOCK(hcryp);
\r
2762 inputaddr = (uint32_t)pPlainData;
\r
2763 outputaddr = (uint32_t)pCypherData;
\r
2765 /* Change the CRYP state */
\r
2766 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2768 /* Set CRYP peripheral in DES ECB encryption mode */
\r
2769 CRYP_SetDESECBMode(hcryp, 0);
\r
2771 /* Set the input and output addresses and start DMA transfer */
\r
2772 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2774 /* Process Unlocked */
\r
2775 __HAL_UNLOCK(hcryp);
\r
2777 /* Return function status */
\r
2782 return HAL_ERROR;
\r
2787 * @brief Initializes the CRYP peripheral in DES CBC encryption mode using DMA.
\r
2788 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2789 * the configuration information for CRYP module
\r
2790 * @param pPlainData: Pointer to the plaintext buffer
\r
2791 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2792 * @param pCypherData: Pointer to the cyphertext buffer
\r
2793 * @retval HAL status
\r
2795 HAL_StatusTypeDef HAL_CRYP_DESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
2797 uint32_t inputaddr;
\r
2798 uint32_t outputaddr;
\r
2800 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2802 /* Process Locked */
\r
2803 __HAL_LOCK(hcryp);
\r
2805 inputaddr = (uint32_t)pPlainData;
\r
2806 outputaddr = (uint32_t)pCypherData;
\r
2808 /* Change the CRYP state */
\r
2809 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2811 /* Set CRYP peripheral in DES CBC encryption mode */
\r
2812 CRYP_SetDESCBCMode(hcryp, 0);
\r
2814 /* Set the input and output addresses and start DMA transfer */
\r
2815 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2817 /* Process Unlocked */
\r
2818 __HAL_UNLOCK(hcryp);
\r
2820 /* Return function status */
\r
2825 return HAL_ERROR;
\r
2830 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using DMA.
\r
2831 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2832 * the configuration information for CRYP module
\r
2833 * @param pPlainData: Pointer to the plaintext buffer
\r
2834 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2835 * @param pCypherData: Pointer to the cyphertext buffer
\r
2836 * @retval HAL status
\r
2838 HAL_StatusTypeDef HAL_CRYP_DESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2840 uint32_t inputaddr;
\r
2841 uint32_t outputaddr;
\r
2843 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2845 /* Process Locked */
\r
2846 __HAL_LOCK(hcryp);
\r
2848 inputaddr = (uint32_t)pCypherData;
\r
2849 outputaddr = (uint32_t)pPlainData;
\r
2851 /* Change the CRYP state */
\r
2852 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2854 /* Set CRYP peripheral in DES ECB decryption mode */
\r
2855 CRYP_SetDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
2857 /* Set the input and output addresses and start DMA transfer */
\r
2858 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2860 /* Process Unlocked */
\r
2861 __HAL_UNLOCK(hcryp);
\r
2863 /* Return function status */
\r
2868 return HAL_ERROR;
\r
2873 * @brief Initializes the CRYP peripheral in DES ECB decryption mode using DMA.
\r
2874 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2875 * the configuration information for CRYP module
\r
2876 * @param pPlainData: Pointer to the plaintext buffer
\r
2877 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2878 * @param pCypherData: Pointer to the cyphertext buffer
\r
2879 * @retval HAL status
\r
2881 HAL_StatusTypeDef HAL_CRYP_DESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
2883 uint32_t inputaddr;
\r
2884 uint32_t outputaddr;
\r
2886 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
2888 /* Process Locked */
\r
2889 __HAL_LOCK(hcryp);
\r
2891 inputaddr = (uint32_t)pCypherData;
\r
2892 outputaddr = (uint32_t)pPlainData;
\r
2894 /* Change the CRYP state */
\r
2895 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2897 /* Set CRYP peripheral in DES CBC decryption mode */
\r
2898 CRYP_SetDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
2900 /* Set the input and output addresses and start DMA transfer */
\r
2901 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
2903 /* Process Unlocked */
\r
2904 __HAL_UNLOCK(hcryp);
\r
2906 /* Return function status */
\r
2911 return HAL_ERROR;
\r
2919 /** @defgroup CRYP_Exported_Functions_Group4 TDES processing functions
\r
2920 * @brief processing functions.
\r
2923 ==============================================================================
\r
2924 ##### TDES processing functions #####
\r
2925 ==============================================================================
\r
2926 [..] This section provides functions allowing to:
\r
2927 (+) Encrypt plaintext using TDES based on ECB or CBC chaining modes
\r
2928 (+) Decrypt cyphertext using TDES based on ECB or CBC chaining modes
\r
2929 [..] Three processing functions are available:
\r
2931 (+) Interrupt mode
\r
2939 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode
\r
2940 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
2941 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2942 * the configuration information for CRYP module
\r
2943 * @param pPlainData: Pointer to the plaintext buffer
\r
2944 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2945 * @param pCypherData: Pointer to the cyphertext buffer
\r
2946 * @param Timeout: Specify Timeout value
\r
2947 * @retval HAL status
\r
2949 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
2951 /* Process Locked */
\r
2952 __HAL_LOCK(hcryp);
\r
2954 /* Change the CRYP state */
\r
2955 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2957 /* Set CRYP peripheral in TDES ECB encryption mode */
\r
2958 CRYP_SetTDESECBMode(hcryp, 0);
\r
2961 __HAL_CRYP_ENABLE();
\r
2963 /* Write Plain Data and Get Cypher Data */
\r
2964 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
2966 return HAL_TIMEOUT;
\r
2969 /* Change the CRYP state */
\r
2970 hcryp->State = HAL_CRYP_STATE_READY;
\r
2972 /* Process Unlocked */
\r
2973 __HAL_UNLOCK(hcryp);
\r
2975 /* Return function status */
\r
2980 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode
\r
2981 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
2982 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
2983 * the configuration information for CRYP module
\r
2984 * @param pPlainData: Pointer to the plaintext buffer
\r
2985 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
2986 * @param pCypherData: Pointer to the cyphertext buffer
\r
2987 * @param Timeout: Specify Timeout value
\r
2988 * @retval HAL status
\r
2990 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
2992 /* Process Locked */
\r
2993 __HAL_LOCK(hcryp);
\r
2995 /* Change the CRYP state */
\r
2996 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
2998 /* Set CRYP peripheral in TDES ECB decryption mode */
\r
2999 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
3002 __HAL_CRYP_ENABLE();
\r
3004 /* Write Cypher Data and Get Plain Data */
\r
3005 if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
3007 return HAL_TIMEOUT;
\r
3010 /* Change the CRYP state */
\r
3011 hcryp->State = HAL_CRYP_STATE_READY;
\r
3013 /* Process Unlocked */
\r
3014 __HAL_UNLOCK(hcryp);
\r
3016 /* Return function status */
\r
3021 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode
\r
3022 * then encrypt pPlainData. The cypher data are available in pCypherData
\r
3023 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3024 * the configuration information for CRYP module
\r
3025 * @param pPlainData: Pointer to the plaintext buffer
\r
3026 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3027 * @param pCypherData: Pointer to the cyphertext buffer
\r
3028 * @param Timeout: Specify Timeout value
\r
3029 * @retval HAL status
\r
3031 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData, uint32_t Timeout)
\r
3033 /* Process Locked */
\r
3034 __HAL_LOCK(hcryp);
\r
3036 /* Change the CRYP state */
\r
3037 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3039 /* Set CRYP peripheral in TDES CBC encryption mode */
\r
3040 CRYP_SetTDESCBCMode(hcryp, 0);
\r
3043 __HAL_CRYP_ENABLE();
\r
3045 /* Write Plain Data and Get Cypher Data */
\r
3046 if(CRYP_ProcessData2Words(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
\r
3048 return HAL_TIMEOUT;
\r
3051 /* Change the CRYP state */
\r
3052 hcryp->State = HAL_CRYP_STATE_READY;
\r
3054 /* Process Unlocked */
\r
3055 __HAL_UNLOCK(hcryp);
\r
3057 /* Return function status */
\r
3062 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode
\r
3063 * then decrypted pCypherData. The cypher data are available in pPlainData
\r
3064 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3065 * the configuration information for CRYP module
\r
3066 * @param pCypherData: Pointer to the cyphertext buffer
\r
3067 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3068 * @param pPlainData: Pointer to the plaintext buffer
\r
3069 * @param Timeout: Specify Timeout value
\r
3070 * @retval HAL status
\r
3072 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout)
\r
3074 /* Process Locked */
\r
3075 __HAL_LOCK(hcryp);
\r
3077 /* Change the CRYP state */
\r
3078 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3080 /* Set CRYP peripheral in TDES CBC decryption mode */
\r
3081 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
3084 __HAL_CRYP_ENABLE();
\r
3086 /* Write Cypher Data and Get Plain Data */
\r
3087 if(CRYP_ProcessData2Words(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
\r
3089 return HAL_TIMEOUT;
\r
3092 /* Change the CRYP state */
\r
3093 hcryp->State = HAL_CRYP_STATE_READY;
\r
3095 /* Process Unlocked */
\r
3096 __HAL_UNLOCK(hcryp);
\r
3098 /* Return function status */
\r
3103 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode using interrupt.
\r
3104 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3105 * the configuration information for CRYP module
\r
3106 * @param pPlainData: Pointer to the plaintext buffer
\r
3107 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3108 * @param pCypherData: Pointer to the cyphertext buffer
\r
3109 * @retval HAL status
\r
3111 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
3113 uint32_t inputaddr;
\r
3114 uint32_t outputaddr;
\r
3116 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
3118 /* Process Locked */
\r
3119 __HAL_LOCK(hcryp);
\r
3121 hcryp->CrypInCount = Size;
\r
3122 hcryp->pCrypInBuffPtr = pPlainData;
\r
3123 hcryp->pCrypOutBuffPtr = pCypherData;
\r
3124 hcryp->CrypOutCount = Size;
\r
3126 /* Change the CRYP state */
\r
3127 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3129 /* Set CRYP peripheral in TDES ECB encryption mode */
\r
3130 CRYP_SetTDESECBMode(hcryp, 0);
\r
3132 /* Enable Interrupts */
\r
3133 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
3136 __HAL_CRYP_ENABLE();
\r
3138 /* Return function status */
\r
3141 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
3143 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
3144 /* Write the Input block in the IN FIFO */
\r
3145 CRYP->DR = *(uint32_t*)(inputaddr);
\r
3147 CRYP->DR = *(uint32_t*)(inputaddr);
\r
3149 hcryp->pCrypInBuffPtr += 8;
\r
3150 hcryp->CrypInCount -= 8;
\r
3151 if(hcryp->CrypInCount == 0)
\r
3153 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
3154 /* Call the Input data transfer complete callback */
\r
3155 HAL_CRYP_InCpltCallback(hcryp);
\r
3158 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
3160 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
3161 /* Read the Output block from the Output FIFO */
\r
3162 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
3164 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
3166 hcryp->pCrypOutBuffPtr += 8;
\r
3167 hcryp->CrypOutCount -= 8;
\r
3168 if(hcryp->CrypOutCount == 0)
\r
3171 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
3172 /* Disable CRYP */
\r
3173 __HAL_CRYP_DISABLE();
\r
3174 /* Process Unlocked */
\r
3175 __HAL_UNLOCK(hcryp);
\r
3176 /* Change the CRYP state */
\r
3177 hcryp->State = HAL_CRYP_STATE_READY;
\r
3178 /* Call the Output data transfer complete callback */
\r
3179 HAL_CRYP_OutCpltCallback(hcryp);
\r
3183 /* Return function status */
\r
3188 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode.
\r
3189 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3190 * the configuration information for CRYP module
\r
3191 * @param pPlainData: Pointer to the plaintext buffer
\r
3192 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3193 * @param pCypherData: Pointer to the cyphertext buffer
\r
3194 * @retval HAL status
\r
3196 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
3198 uint32_t inputaddr;
\r
3199 uint32_t outputaddr;
\r
3201 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
3203 /* Process Locked */
\r
3204 __HAL_LOCK(hcryp);
\r
3206 hcryp->CrypInCount = Size;
\r
3207 hcryp->pCrypInBuffPtr = pPlainData;
\r
3208 hcryp->pCrypOutBuffPtr = pCypherData;
\r
3209 hcryp->CrypOutCount = Size;
\r
3211 /* Change the CRYP state */
\r
3212 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3214 /* Set CRYP peripheral in TDES CBC encryption mode */
\r
3215 CRYP_SetTDESCBCMode(hcryp, 0);
\r
3217 /* Enable Interrupts */
\r
3218 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
3221 __HAL_CRYP_ENABLE();
\r
3223 /* Return function status */
\r
3226 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
3228 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
3229 /* Write the Input block in the IN FIFO */
\r
3230 CRYP->DR = *(uint32_t*)(inputaddr);
\r
3232 CRYP->DR = *(uint32_t*)(inputaddr);
\r
3234 hcryp->pCrypInBuffPtr += 8;
\r
3235 hcryp->CrypInCount -= 8;
\r
3236 if(hcryp->CrypInCount == 0)
\r
3238 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
3239 /* Call the Input data transfer complete callback */
\r
3240 HAL_CRYP_InCpltCallback(hcryp);
\r
3243 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
3245 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
3246 /* Read the Output block from the Output FIFO */
\r
3247 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
3249 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
3251 hcryp->pCrypOutBuffPtr += 8;
\r
3252 hcryp->CrypOutCount -= 8;
\r
3253 if(hcryp->CrypOutCount == 0)
\r
3255 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
3256 /* Disable CRYP */
\r
3257 __HAL_CRYP_DISABLE();
\r
3258 /* Process Unlocked */
\r
3259 __HAL_UNLOCK(hcryp);
\r
3260 /* Change the CRYP state */
\r
3261 hcryp->State = HAL_CRYP_STATE_READY;
\r
3262 /* Call Input transfer complete callback */
\r
3263 HAL_CRYP_OutCpltCallback(hcryp);
\r
3267 /* Return function status */
\r
3272 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode.
\r
3273 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3274 * the configuration information for CRYP module
\r
3275 * @param pPlainData: Pointer to the plaintext buffer
\r
3276 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3277 * @param pCypherData: Pointer to the cyphertext buffer
\r
3278 * @retval HAL status
\r
3280 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
3282 uint32_t inputaddr;
\r
3283 uint32_t outputaddr;
\r
3285 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
3287 /* Process Locked */
\r
3288 __HAL_LOCK(hcryp);
\r
3290 hcryp->CrypInCount = Size;
\r
3291 hcryp->pCrypInBuffPtr = pCypherData;
\r
3292 hcryp->pCrypOutBuffPtr = pPlainData;
\r
3293 hcryp->CrypOutCount = Size;
\r
3295 /* Change the CRYP state */
\r
3296 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3298 /* Set CRYP peripheral in TDES ECB decryption mode */
\r
3299 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
3301 /* Enable Interrupts */
\r
3302 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
3305 __HAL_CRYP_ENABLE();
\r
3307 /* Return function status */
\r
3310 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
3312 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
3313 /* Write the Input block in the IN FIFO */
\r
3314 CRYP->DR = *(uint32_t*)(inputaddr);
\r
3316 CRYP->DR = *(uint32_t*)(inputaddr);
\r
3318 hcryp->pCrypInBuffPtr += 8;
\r
3319 hcryp->CrypInCount -= 8;
\r
3320 if(hcryp->CrypInCount == 0)
\r
3322 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
3323 /* Call the Input data transfer complete callback */
\r
3324 HAL_CRYP_InCpltCallback(hcryp);
\r
3327 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
3329 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
3330 /* Read the Output block from the Output FIFO */
\r
3331 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
3333 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
3335 hcryp->pCrypOutBuffPtr += 8;
\r
3336 hcryp->CrypOutCount -= 8;
\r
3337 if(hcryp->CrypOutCount == 0)
\r
3339 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
3340 /* Disable CRYP */
\r
3341 __HAL_CRYP_DISABLE();
\r
3342 /* Process Unlocked */
\r
3343 __HAL_UNLOCK(hcryp);
\r
3344 /* Change the CRYP state */
\r
3345 hcryp->State = HAL_CRYP_STATE_READY;
\r
3346 /* Call Input transfer complete callback */
\r
3347 HAL_CRYP_OutCpltCallback(hcryp);
\r
3351 /* Return function status */
\r
3356 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode.
\r
3357 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3358 * the configuration information for CRYP module
\r
3359 * @param pCypherData: Pointer to the cyphertext buffer
\r
3360 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3361 * @param pPlainData: Pointer to the plaintext buffer
\r
3362 * @retval HAL status
\r
3364 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
3366 uint32_t inputaddr;
\r
3367 uint32_t outputaddr;
\r
3369 if(hcryp->State == HAL_CRYP_STATE_READY)
\r
3371 /* Process Locked */
\r
3372 __HAL_LOCK(hcryp);
\r
3374 hcryp->CrypInCount = Size;
\r
3375 hcryp->pCrypInBuffPtr = pCypherData;
\r
3376 hcryp->pCrypOutBuffPtr = pPlainData;
\r
3377 hcryp->CrypOutCount = Size;
\r
3379 /* Change the CRYP state */
\r
3380 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3382 /* Set CRYP peripheral in TDES CBC decryption mode */
\r
3383 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
3385 /* Enable Interrupts */
\r
3386 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
\r
3389 __HAL_CRYP_ENABLE();
\r
3391 /* Return function status */
\r
3394 else if(__HAL_CRYP_GET_IT(CRYP_IT_INI))
\r
3396 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
\r
3397 /* Write the Input block in the IN FIFO */
\r
3398 CRYP->DR = *(uint32_t*)(inputaddr);
\r
3400 CRYP->DR = *(uint32_t*)(inputaddr);
\r
3402 hcryp->pCrypInBuffPtr += 8;
\r
3403 hcryp->CrypInCount -= 8;
\r
3404 if(hcryp->CrypInCount == 0)
\r
3406 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
\r
3407 /* Call the Input data transfer complete callback */
\r
3408 HAL_CRYP_InCpltCallback(hcryp);
\r
3411 else if(__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
\r
3413 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
\r
3414 /* Read the Output block from the Output FIFO */
\r
3415 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
3417 *(uint32_t*)(outputaddr) = CRYP->DOUT;
\r
3419 hcryp->pCrypOutBuffPtr += 8;
\r
3420 hcryp->CrypOutCount -= 8;
\r
3421 if(hcryp->CrypOutCount == 0)
\r
3423 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
\r
3424 /* Disable CRYP */
\r
3425 __HAL_CRYP_DISABLE();
\r
3426 /* Process Unlocked */
\r
3427 __HAL_UNLOCK(hcryp);
\r
3428 /* Change the CRYP state */
\r
3429 hcryp->State = HAL_CRYP_STATE_READY;
\r
3430 /* Call Input transfer complete callback */
\r
3431 HAL_CRYP_OutCpltCallback(hcryp);
\r
3435 /* Return function status */
\r
3440 * @brief Initializes the CRYP peripheral in TDES ECB encryption mode using DMA.
\r
3441 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3442 * the configuration information for CRYP module
\r
3443 * @param pPlainData: Pointer to the plaintext buffer
\r
3444 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3445 * @param pCypherData: Pointer to the cyphertext buffer
\r
3446 * @retval HAL status
\r
3448 HAL_StatusTypeDef HAL_CRYP_TDESECB_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
3450 uint32_t inputaddr;
\r
3451 uint32_t outputaddr;
\r
3453 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
3455 /* Process Locked */
\r
3456 __HAL_LOCK(hcryp);
\r
3458 inputaddr = (uint32_t)pPlainData;
\r
3459 outputaddr = (uint32_t)pCypherData;
\r
3461 /* Change the CRYP state */
\r
3462 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3464 /* Set CRYP peripheral in TDES ECB encryption mode */
\r
3465 CRYP_SetTDESECBMode(hcryp, 0);
\r
3467 /* Set the input and output addresses and start DMA transfer */
\r
3468 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
3470 /* Process Unlocked */
\r
3471 __HAL_UNLOCK(hcryp);
\r
3473 /* Return function status */
\r
3478 return HAL_ERROR;
\r
3483 * @brief Initializes the CRYP peripheral in TDES CBC encryption mode using DMA.
\r
3484 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3485 * the configuration information for CRYP module
\r
3486 * @param pPlainData: Pointer to the plaintext buffer
\r
3487 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3488 * @param pCypherData: Pointer to the cyphertext buffer
\r
3489 * @retval HAL status
\r
3491 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
\r
3493 uint32_t inputaddr;
\r
3494 uint32_t outputaddr;
\r
3496 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
3498 /* Process Locked */
\r
3499 __HAL_LOCK(hcryp);
\r
3501 inputaddr = (uint32_t)pPlainData;
\r
3502 outputaddr = (uint32_t)pCypherData;
\r
3504 /* Change the CRYP state */
\r
3505 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3507 /* Set CRYP peripheral in TDES CBC encryption mode */
\r
3508 CRYP_SetTDESCBCMode(hcryp, 0);
\r
3510 /* Set the input and output addresses and start DMA transfer */
\r
3511 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
3513 /* Process Unlocked */
\r
3514 __HAL_UNLOCK(hcryp);
\r
3516 /* Return function status */
\r
3521 return HAL_ERROR;
\r
3526 * @brief Initializes the CRYP peripheral in TDES ECB decryption mode using DMA.
\r
3527 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3528 * the configuration information for CRYP module
\r
3529 * @param pPlainData: Pointer to the plaintext buffer
\r
3530 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3531 * @param pCypherData: Pointer to the cyphertext buffer
\r
3532 * @retval HAL status
\r
3534 HAL_StatusTypeDef HAL_CRYP_TDESECB_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
3536 uint32_t inputaddr;
\r
3537 uint32_t outputaddr;
\r
3539 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
3541 /* Process Locked */
\r
3542 __HAL_LOCK(hcryp);
\r
3544 inputaddr = (uint32_t)pCypherData;
\r
3545 outputaddr = (uint32_t)pPlainData;
\r
3547 /* Change the CRYP state */
\r
3548 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3550 /* Set CRYP peripheral in TDES ECB decryption mode */
\r
3551 CRYP_SetTDESECBMode(hcryp, CRYP_CR_ALGODIR);
\r
3553 /* Set the input and output addresses and start DMA transfer */
\r
3554 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
3556 /* Process Unlocked */
\r
3557 __HAL_UNLOCK(hcryp);
\r
3559 /* Return function status */
\r
3564 return HAL_ERROR;
\r
3569 * @brief Initializes the CRYP peripheral in TDES CBC decryption mode using DMA.
\r
3570 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3571 * the configuration information for CRYP module
\r
3572 * @param pCypherData: Pointer to the cyphertext buffer
\r
3573 * @param Size: Length of the plaintext buffer, must be a multiple of 8
\r
3574 * @param pPlainData: Pointer to the plaintext buffer
\r
3575 * @retval HAL status
\r
3577 HAL_StatusTypeDef HAL_CRYP_TDESCBC_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
\r
3579 uint32_t inputaddr;
\r
3580 uint32_t outputaddr;
\r
3582 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
\r
3584 /* Process Locked */
\r
3585 __HAL_LOCK(hcryp);
\r
3587 inputaddr = (uint32_t)pCypherData;
\r
3588 outputaddr = (uint32_t)pPlainData;
\r
3590 /* Change the CRYP state */
\r
3591 hcryp->State = HAL_CRYP_STATE_BUSY;
\r
3593 /* Set CRYP peripheral in TDES CBC decryption mode */
\r
3594 CRYP_SetTDESCBCMode(hcryp, CRYP_CR_ALGODIR);
\r
3596 /* Set the input and output addresses and start DMA transfer */
\r
3597 CRYP_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
\r
3599 /* Process Unlocked */
\r
3600 __HAL_UNLOCK(hcryp);
\r
3602 /* Return function status */
\r
3607 return HAL_ERROR;
\r
3615 /** @defgroup CRYP_Exported_Functions_Group5 DMA callback functions
\r
3616 * @brief DMA callback functions.
\r
3619 ==============================================================================
\r
3620 ##### DMA callback functions #####
\r
3621 ==============================================================================
\r
3622 [..] This section provides DMA callback functions:
\r
3623 (+) DMA Input data transfer complete
\r
3624 (+) DMA Output data transfer complete
\r
3632 * @brief Input FIFO transfer completed callbacks.
\r
3633 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3634 * the configuration information for CRYP module
\r
3637 __weak void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp)
\r
3639 /* NOTE : This function Should not be modified, when the callback is needed,
\r
3640 the HAL_CRYP_InCpltCallback could be implemented in the user file
\r
3645 * @brief Output FIFO transfer completed callbacks.
\r
3646 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3647 * the configuration information for CRYP module
\r
3650 __weak void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp)
\r
3652 /* NOTE : This function Should not be modified, when the callback is needed,
\r
3653 the HAL_CRYP_OutCpltCallback could be implemented in the user file
\r
3658 * @brief CRYP error callbacks.
\r
3659 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3660 * the configuration information for CRYP module
\r
3663 __weak void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
\r
3665 /* NOTE : This function Should not be modified, when the callback is needed,
\r
3666 the HAL_CRYP_ErrorCallback could be implemented in the user file
\r
3674 /** @defgroup CRYP_Exported_Functions_Group6 CRYP IRQ handler management
\r
3675 * @brief CRYP IRQ handler.
\r
3678 ==============================================================================
\r
3679 ##### CRYP IRQ handler management #####
\r
3680 ==============================================================================
\r
3681 [..] This section provides CRYP IRQ handler function.
\r
3688 * @brief This function handles CRYP interrupt request.
\r
3689 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3690 * the configuration information for CRYP module
\r
3693 void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp)
\r
3695 switch(CRYP->CR & CRYP_CR_ALGOMODE_DIRECTION)
\r
3697 case CRYP_CR_ALGOMODE_TDES_ECB_ENCRYPT:
\r
3698 HAL_CRYP_TDESECB_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3701 case CRYP_CR_ALGOMODE_TDES_ECB_DECRYPT:
\r
3702 HAL_CRYP_TDESECB_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3705 case CRYP_CR_ALGOMODE_TDES_CBC_ENCRYPT:
\r
3706 HAL_CRYP_TDESCBC_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3709 case CRYP_CR_ALGOMODE_TDES_CBC_DECRYPT:
\r
3710 HAL_CRYP_TDESCBC_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3713 case CRYP_CR_ALGOMODE_DES_ECB_ENCRYPT:
\r
3714 HAL_CRYP_DESECB_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3717 case CRYP_CR_ALGOMODE_DES_ECB_DECRYPT:
\r
3718 HAL_CRYP_DESECB_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3721 case CRYP_CR_ALGOMODE_DES_CBC_ENCRYPT:
\r
3722 HAL_CRYP_DESCBC_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3725 case CRYP_CR_ALGOMODE_DES_CBC_DECRYPT:
\r
3726 HAL_CRYP_DESCBC_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3729 case CRYP_CR_ALGOMODE_AES_ECB_ENCRYPT:
\r
3730 HAL_CRYP_AESECB_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3733 case CRYP_CR_ALGOMODE_AES_ECB_DECRYPT:
\r
3734 HAL_CRYP_AESECB_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3737 case CRYP_CR_ALGOMODE_AES_CBC_ENCRYPT:
\r
3738 HAL_CRYP_AESCBC_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3741 case CRYP_CR_ALGOMODE_AES_CBC_DECRYPT:
\r
3742 HAL_CRYP_AESCBC_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3745 case CRYP_CR_ALGOMODE_AES_CTR_ENCRYPT:
\r
3746 HAL_CRYP_AESCTR_Encrypt_IT(hcryp, NULL, 0, NULL);
\r
3749 case CRYP_CR_ALGOMODE_AES_CTR_DECRYPT:
\r
3750 HAL_CRYP_AESCTR_Decrypt_IT(hcryp, NULL, 0, NULL);
\r
3762 /** @defgroup CRYP_Exported_Functions_Group7 Peripheral State functions
\r
3763 * @brief Peripheral State functions.
\r
3766 ==============================================================================
\r
3767 ##### Peripheral State functions #####
\r
3768 ==============================================================================
\r
3770 This subsection permits to get in run-time the status of the peripheral.
\r
3777 * @brief Returns the CRYP state.
\r
3778 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
\r
3779 * the configuration information for CRYP module
\r
3780 * @retval HAL state
\r
3782 HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp)
\r
3784 return hcryp->State;
\r
3795 #endif /* STM32F756xx */
\r
3797 #endif /* HAL_CRYP_MODULE_ENABLED */
\r
3806 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r