annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_cryp.c @ 112:fdf0272e9213 FlipDisplay

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