annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_cryp_ex.c @ 75:2b3f8ed4a0b8

Update version info
author Ideenmodellierer
date Thu, 04 Oct 2018 20:41:21 +0200
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_ex.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 Extended 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 CRYP extension peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Extended AES processing functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 The CRYP Extension HAL driver can be used as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 (#)Initialize the CRYP low level resources by implementing the HAL_CRYP_MspInit():
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 (##) Enable the CRYP interface clock using __HAL_RCC_CRYP_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 (##) In case of using interrupts (e.g. HAL_CRYPEx_AESGCM_Encrypt_IT())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 (+++) Configure the CRYP interrupt priority using HAL_NVIC_SetPriority()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 (+++) Enable the CRYP IRQ handler using HAL_NVIC_EnableIRQ()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 (+) In CRYP IRQ handler, call HAL_CRYP_IRQHandler()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 (##) In case of using DMA to control data transfer (e.g. HAL_AES_ECB_Encrypt_DMA())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (+++) Enable the DMAx interface clock using __DMAx_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 (+++) Configure and enable two DMA streams one for managing data transfer from
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 memory to peripheral (input stream) and another stream for managing data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 transfer from peripheral to memory (output stream)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (+++) Associate the initialized DMA handle to the CRYP DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 using __HAL_LINKDMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (+++) Configure the priority and enable the NVIC for the transfer complete
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 interrupt on the two DMA Streams. The output stream should have higher
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 priority than the input stream HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (#)Initialize the CRYP HAL using HAL_CRYP_Init(). This function configures mainly:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 (##) The data type: 1-bit, 8-bit, 16-bit and 32-bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 (##) The key size: 128, 192 and 256. This parameter is relevant only for AES
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 (##) The encryption/decryption key. Its size depends on the algorithm
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 used for encryption/decryption
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 (##) The initialization vector (counter). It is not used ECB mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 (#)Three processing (encryption/decryption) functions are available:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 (##) Polling mode: encryption and decryption APIs are blocking functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 i.e. they process the data and wait till the processing is finished
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 e.g. HAL_CRYPEx_AESGCM_Encrypt()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 (##) Interrupt mode: encryption and decryption APIs are not blocking functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 i.e. they process the data under interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 e.g. HAL_CRYPEx_AESGCM_Encrypt_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 (##) DMA mode: encryption and decryption APIs are not blocking functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 i.e. the data transfer is ensured by DMA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 e.g. HAL_CRYPEx_AESGCM_Encrypt_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 (#)When the processing function is called at first time after HAL_CRYP_Init()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 the CRYP peripheral is initialized and processes the buffer in input.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 At second call, the processing function performs an append of the already
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 processed buffer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 When a new data block is to be processed, call HAL_CRYP_Init() then the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 processing function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 (#)In AES-GCM and AES-CCM modes are an authenticated encryption algorithms
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 which provide authentication messages.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 HAL_AES_GCM_Finish() and HAL_AES_CCM_Finish() are used to provide those
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 authentication messages.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 Call those functions after the processing ones (polling, interrupt or DMA).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 e.g. in AES-CCM mode call HAL_CRYPEx_AESCCM_Encrypt() to encrypt the plain data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 then call HAL_CRYPEx_AESCCM_Finish() to get the authentication message
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 @note: For CCM Encrypt/Decrypt API's, only DataType = 8-bit is supported by this version.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 @note: The HAL_CRYPEx_AESGCM_xxxx() implementation is limited to 32bits inputs data length
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 (Plain/Cyphertext, Header) compared with GCM standards specifications (800-38D).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 (#)Call HAL_CRYP_DeInit() to deinitialize the CRYP peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 *
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 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 * @{
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 /** @defgroup CRYPEx CRYPEx
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 * @brief CRYP Extension HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 * @{
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 #ifdef HAL_CRYP_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 #if defined(STM32F437xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 /** @addtogroup CRYPEx_Private_define
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 #define CRYPEx_TIMEOUT_VALUE 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 /**
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 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 /** @defgroup CRYPEx_Private_Functions_prototypes CRYP Private Functions Prototypes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 static void CRYPEx_GCMCCM_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 static void CRYPEx_GCMCCM_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key, uint32_t KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 static HAL_StatusTypeDef CRYPEx_GCMCCM_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
134 static HAL_StatusTypeDef CRYPEx_GCMCCM_SetHeaderPhase(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 static void CRYPEx_GCMCCM_DMAInCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 static void CRYPEx_GCMCCM_DMAOutCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 static void CRYPEx_GCMCCM_DMAError(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 static void CRYPEx_GCMCCM_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 /** @addtogroup CRYPEx_Private_Functions
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 * @brief DMA CRYP Input Data process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 static void CRYPEx_GCMCCM_DMAInCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 CRYP_HandleTypeDef* hcryp = ( CRYP_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 /* Disable the DMA transfer for input Fifo request by resetting the DIEN bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 in the DMACR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 CRYP->DMACR &= (uint32_t)(~CRYP_DMACR_DIEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 /* Call input data transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 HAL_CRYP_InCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 * @brief DMA CRYP Output Data process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 static void CRYPEx_GCMCCM_DMAOutCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 CRYP_HandleTypeDef* hcryp = ( CRYP_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 /* Disable the DMA transfer for output Fifo request by resetting the DOEN bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 in the DMACR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 CRYP->DMACR &= (uint32_t)(~CRYP_DMACR_DOEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 /* Call output data transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 HAL_CRYP_OutCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 * @brief DMA CRYP communication error callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 static void CRYPEx_GCMCCM_DMAError(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 CRYP_HandleTypeDef* hcryp = ( CRYP_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 hcryp->State= HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 HAL_CRYP_ErrorCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 * @brief Writes the Key in Key registers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 * @param Key: Pointer to Key buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 * @param KeySize: Size of Key
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 static void CRYPEx_GCMCCM_SetKey(CRYP_HandleTypeDef *hcryp, uint8_t *Key, uint32_t KeySize)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 uint32_t keyaddr = (uint32_t)Key;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 switch(KeySize)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 case CRYP_KEYSIZE_256B:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 /* Key Initialisation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 CRYP->K0LR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 CRYP->K0RR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 CRYP->K1LR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 CRYP->K1RR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 CRYP->K2LR = __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->K2RR = __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->K3LR = __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->K3RR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 case CRYP_KEYSIZE_192B:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 CRYP->K1LR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 CRYP->K1RR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 CRYP->K2LR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 CRYP->K2RR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 CRYP->K3LR = __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->K3RR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 case CRYP_KEYSIZE_128B:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 CRYP->K2LR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 CRYP->K2RR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 CRYP->K3LR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 keyaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 CRYP->K3RR = __REV(*(uint32_t*)(keyaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 * @brief Writes the InitVector/InitCounter in IV registers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 * @param InitVector: Pointer to InitVector/InitCounter buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 static void CRYPEx_GCMCCM_SetInitVector(CRYP_HandleTypeDef *hcryp, uint8_t *InitVector)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 uint32_t ivaddr = (uint32_t)InitVector;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 CRYP->IV0LR = __REV(*(uint32_t*)(ivaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 ivaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 CRYP->IV0RR = __REV(*(uint32_t*)(ivaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 ivaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 CRYP->IV1LR = __REV(*(uint32_t*)(ivaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 ivaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 CRYP->IV1RR = __REV(*(uint32_t*)(ivaddr));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 * @brief Process Data: Writes Input data in polling mode and read the Output data.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 * @param Input: Pointer to the Input buffer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 * @param Ilength: Length of the Input buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 * @param Output: Pointer to the returned buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 * @param Timeout: Timeout value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 static HAL_StatusTypeDef CRYPEx_GCMCCM_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
290 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 uint32_t i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 uint32_t inputaddr = (uint32_t)Input;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 uint32_t outputaddr = (uint32_t)Output;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 for(i=0; (i < Ilength); i+=16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 /* Write the Input block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_OFNE))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 /* Read the Output block from the OUT FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 * @brief Sets the header phase
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 * @param Input: Pointer to the Input buffer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 * @param Ilength: Length of the Input buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 * @param Timeout: Timeout value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 static HAL_StatusTypeDef CRYPEx_GCMCCM_SetHeaderPhase(CRYP_HandleTypeDef *hcryp, uint8_t* Input, uint16_t Ilength, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 uint32_t loopcounter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 uint32_t headeraddr = (uint32_t)Input;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 /***************************** Header phase *********************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 if(hcryp->Init.HeaderSize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 /* Select header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 __HAL_CRYP_SET_PHASE(CRYP_PHASE_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 for(loopcounter = 0; (loopcounter < hcryp->Init.HeaderSize); loopcounter+=16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_IFEM))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 /* Write the Input block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 /* Wait until the complete message has been processed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 while((CRYP->SR & CRYP_FLAG_BUSY) == CRYP_FLAG_BUSY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 }
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 * @brief Sets the DMA configuration and start the DMA transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 * @param inputaddr: Address of the Input buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 * @param Size: Size of the Input buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 * @param outputaddr: Address of the Output buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 static void CRYPEx_GCMCCM_SetDMAConfig(CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 /* Set the CRYP DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 hcryp->hdmain->XferCpltCallback = CRYPEx_GCMCCM_DMAInCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 hcryp->hdmain->XferErrorCallback = CRYPEx_GCMCCM_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 /* Set the CRYP DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 hcryp->hdmaout->XferCpltCallback = CRYPEx_GCMCCM_DMAOutCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 hcryp->hdmaout->XferErrorCallback = CRYPEx_GCMCCM_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 /* Enable the DMA In DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&CRYP->DR, Size/4);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 /* Enable In DMA request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 CRYP->DMACR = CRYP_DMACR_DIEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 /* Enable the DMA Out DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&CRYP->DOUT, outputaddr, Size/4);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 /* Enable Out DMA request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 CRYP->DMACR |= CRYP_DMACR_DOEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 }
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 /* Exported functions---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 /** @addtogroup CRYPEx_Exported_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 /** @defgroup CRYPEx_Exported_Functions_Group1 Extended AES processing functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 * @brief Extended processing functions.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 ##### Extended AES processing functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 (+) Encrypt plaintext using AES-128/192/256 using GCM and CCM chaining modes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 (+) Decrypt cyphertext using AES-128/192/256 using GCM and CCM chaining modes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 (+) Finish the processing. This function is available only for GCM and CCM
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 [..] Three processing methods are available:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 (+) Polling mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 (+) Interrupt mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 (+) DMA mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 @endverbatim
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 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 * @brief Initializes the CRYP peripheral in AES CCM encryption mode then
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 * encrypt pPlainData. The cypher data are available in pCypherData.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 * @param Size: Length of the plaintext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 HAL_StatusTypeDef HAL_CRYPEx_AESCCM_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
504 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 uint32_t headersize = hcryp->Init.HeaderSize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 uint32_t headeraddr = (uint32_t)hcryp->Init.Header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 uint32_t loopcounter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 uint32_t bufferidx = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 uint8_t blockb0[16] = {0};/* Block B0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 uint8_t ctr[16] = {0}; /* Counter */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 uint32_t b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 /************************ Formatting the header block *********************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 /* Check that the associated data (or header) length is lower than 2^16 - 2^8 = 65536 - 256 = 65280 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 if(headersize < 65280)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize >> 8) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 headersize += 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 /* Header is encoded as 0xff || 0xfe || [headersize]32, i.e., six octets */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 hcryp->Init.pScratch[bufferidx++] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 hcryp->Init.pScratch[bufferidx++] = 0xFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 hcryp->Init.pScratch[bufferidx++] = headersize & 0xff000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 hcryp->Init.pScratch[bufferidx++] = headersize & 0x00ff0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 hcryp->Init.pScratch[bufferidx++] = headersize & 0x0000ff00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 hcryp->Init.pScratch[bufferidx++] = headersize & 0x000000ff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 headersize += 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 /* Copy the header buffer in internal buffer "hcryp->Init.pScratch" */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 for(loopcounter = 0; loopcounter < headersize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 hcryp->Init.pScratch[bufferidx++] = hcryp->Init.Header[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 /* Check if the header size is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 if ((headersize % 16) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 /* Padd the header buffer with 0s till the hcryp->Init.pScratch length is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 for(loopcounter = headersize; loopcounter <= ((headersize/16) + 1) * 16; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 hcryp->Init.pScratch[loopcounter] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 /* Set the header size to modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 headersize = ((headersize/16) + 1) * 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 /* Set the pointer headeraddr to hcryp->Init.pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 headeraddr = (uint32_t)hcryp->Init.pScratch;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 /*********************** Formatting the block B0 **************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 blockb0[0] = 0x40;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 /* Flags byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 /* blockb0[0] |= 0u | (((( (uint8_t) hcryp->Init.TagSize - 2) / 2) & 0x07 ) << 3 ) | ( ( (uint8_t) (15 - hcryp->Init.IVSize) - 1) & 0x07) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)(((uint8_t)(hcryp->Init.TagSize - (uint8_t)(2))) >> 1) & (uint8_t)0x07 ) << 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)((uint8_t)(15) - hcryp->Init.IVSize) - (uint8_t)1) & (uint8_t)0x07);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 for (loopcounter = 0; loopcounter < hcryp->Init.IVSize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 blockb0[loopcounter+1] = hcryp->Init.pInitVect[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 for ( ; loopcounter < 13; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 blockb0[loopcounter+1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 blockb0[14] = (Size >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 blockb0[15] = (Size & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 /************************* Formatting the initial counter *****************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 /* Byte 0:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 Bits 7 and 6 are reserved and shall be set to 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 Bits 3, 4, and 5 shall also be set to 0, to ensure that all the counter blocks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 are distinct from B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 Bits 0, 1, and 2 contain the same encoding of q as in B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 ctr[0] = blockb0[0] & 0x07;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 /* byte 1 to NonceSize is the IV (Nonce) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 for(loopcounter = 1; loopcounter < hcryp->Init.IVSize + 1; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 ctr[loopcounter] = blockb0[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 /* Set the LSB to 1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 ctr[15] |= 0x01;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 /* Set the CRYP peripheral in AES CCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CCM_ENCRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 CRYPEx_GCMCCM_SetInitVector(hcryp, ctr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 /* Select init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 __HAL_CRYP_SET_PHASE(CRYP_PHASE_INIT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 /* Write the blockb0 block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 /***************************** Header phase *******************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 /* Select header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 __HAL_CRYP_SET_PHASE(CRYP_PHASE_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 for(loopcounter = 0; (loopcounter < headersize); loopcounter+=16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_IFEM))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 /* Write the header block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 while((CRYP->SR & CRYP_FLAG_BUSY) == CRYP_FLAG_BUSY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 /* Save formatted counter into the scratch buffer pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 for(loopcounter = 0; (loopcounter < 16); loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 hcryp->Init.pScratch[loopcounter] = ctr[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 /* Reset bit 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 hcryp->Init.pScratch[15] &= 0xfe;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 /* Write Plain Data and Get Cypher Data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 if(CRYPEx_GCMCCM_ProcessData(hcryp,pPlainData, Size, pCypherData, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 return HAL_TIMEOUT;
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 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 * @brief Initializes the CRYP peripheral in AES GCM encryption mode then
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 * encrypt pPlainData. The cypher data are available in pCypherData.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 * @param Size: Length of the plaintext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 HAL_StatusTypeDef HAL_CRYPEx_AESGCM_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
760 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 /* Set the CRYP peripheral in AES GCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_GCM_ENCRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 CRYPEx_GCMCCM_SetInitVector(hcryp, hcryp->Init.pInitVect);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 /* Set the header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 if(CRYPEx_GCMCCM_SetHeaderPhase(hcryp, hcryp->Init.Header, hcryp->Init.HeaderSize, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 /* Disable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 /* Write Plain Data and Get Cypher Data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 if(CRYPEx_GCMCCM_ProcessData(hcryp, pPlainData, Size, pCypherData, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 * @brief Initializes the CRYP peripheral in AES GCM decryption mode then
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 * decrypted pCypherData. The cypher data are available in pPlainData.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 * @param Size: Length of the cyphertext buffer, must be a multiple of 16
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 Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 HAL_StatusTypeDef HAL_CRYPEx_AESGCM_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
858 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 uint32_t tickstart = 0;
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 peripheral 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 CRYPEx_GCMCCM_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 GCM decryption mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_GCM_DECRYPT);
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 CRYPEx_GCMCCM_SetInitVector(hcryp, hcryp->Init.pInitVect);
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 the CRYP peripheral */
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 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
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 HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 }
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 /* Set the header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 if(CRYPEx_GCMCCM_SetHeaderPhase(hcryp, hcryp->Init.Header, hcryp->Init.HeaderSize, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 /* Disable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 /* Write Plain Data and Get Cypher Data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 if(CRYPEx_GCMCCM_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 * @brief Computes the authentication TAG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 * @param Size: Total length of the plain/cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 * @param AuthTag: Pointer to the authentication buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Finish(CRYP_HandleTypeDef *hcryp, uint32_t Size, uint8_t *AuthTag, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 uint64_t headerlength = hcryp->Init.HeaderSize * 8; /* Header length in bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 uint64_t inputlength = Size * 8; /* input length in bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 uint32_t tagaddr = (uint32_t)AuthTag;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 if(hcryp->Phase == HAL_CRYP_PHASE_PROCESS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 /* Change the CRYP phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 hcryp->Phase = HAL_CRYP_PHASE_FINAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 /* Disable CRYP to start the final phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 /* Select final phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 __HAL_CRYP_SET_PHASE(CRYP_PHASE_FINAL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 /* Write the number of bits in header (64 bits) followed by the number of bits
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 in the payload */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 if(hcryp->Init.DataType == CRYP_DATATYPE_1B)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 CRYP->DR = __RBIT(headerlength >> 32);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 CRYP->DR = __RBIT(headerlength);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 CRYP->DR = __RBIT(inputlength >> 32);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 CRYP->DR = __RBIT(inputlength);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 else if(hcryp->Init.DataType == CRYP_DATATYPE_8B)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 CRYP->DR = __REV(headerlength >> 32);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 CRYP->DR = __REV(headerlength);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 CRYP->DR = __REV(inputlength >> 32);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 CRYP->DR = __REV(inputlength);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 else if(hcryp->Init.DataType == CRYP_DATATYPE_16B)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 CRYP->DR = __ROR((uint32_t)(headerlength >> 32), 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 CRYP->DR = __ROR((uint32_t)headerlength, 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 CRYP->DR = __ROR((uint32_t)(inputlength >> 32), 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 CRYP->DR = __ROR((uint32_t)inputlength, 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 else if(hcryp->Init.DataType == CRYP_DATATYPE_32B)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 CRYP->DR = (uint32_t)(headerlength >> 32);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 CRYP->DR = (uint32_t)(headerlength);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 CRYP->DR = (uint32_t)(inputlength >> 32);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 CRYP->DR = (uint32_t)(inputlength);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_OFNE))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 /* Read the Auth TAG in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 *(uint32_t*)(tagaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 tagaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 *(uint32_t*)(tagaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 tagaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 *(uint32_t*)(tagaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 tagaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 *(uint32_t*)(tagaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 hcryp->State = HAL_CRYP_STATE_READY;
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 function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 return HAL_OK;
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 * @brief Computes the authentication TAG for AES CCM mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 * @note This API is called after HAL_AES_CCM_Encrypt()/HAL_AES_CCM_Decrypt()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 * @param AuthTag: Pointer to the authentication buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Finish(CRYP_HandleTypeDef *hcryp, uint8_t *AuthTag, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 uint32_t tagaddr = (uint32_t)AuthTag;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 uint32_t ctraddr = (uint32_t)hcryp->Init.pScratch;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 uint32_t temptag[4] = {0}; /* Temporary TAG (MAC) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 uint32_t loopcounter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 if(hcryp->Phase == HAL_CRYP_PHASE_PROCESS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 /* Change the CRYP phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 hcryp->Phase = HAL_CRYP_PHASE_FINAL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 /* Disable CRYP to start the final phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 /* Select final phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 __HAL_CRYP_SET_PHASE(CRYP_PHASE_FINAL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 /* Write the counter block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 CRYP->DR = *(uint32_t*)ctraddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 ctraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 CRYP->DR = *(uint32_t*)ctraddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 ctraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 CRYP->DR = *(uint32_t*)ctraddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 ctraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 CRYP->DR = *(uint32_t*)ctraddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_OFNE))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 /* Read the Auth TAG in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 temptag[0] = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 temptag[1] = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 temptag[2] = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 temptag[3] = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 /* Copy temporary authentication TAG in user TAG buffer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 for(loopcounter = 0; loopcounter < hcryp->Init.TagSize ; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 /* Set the authentication TAG buffer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 *((uint8_t*)tagaddr+loopcounter) = *((uint8_t*)temptag+loopcounter);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 }
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 * @brief Initializes the CRYP peripheral in AES CCM decryption mode then
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 * decrypted pCypherData. The cypher data are available in pPlainData.
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
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 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 HAL_StatusTypeDef HAL_CRYPEx_AESCCM_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
1152 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 uint32_t headersize = hcryp->Init.HeaderSize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 uint32_t headeraddr = (uint32_t)hcryp->Init.Header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 uint32_t loopcounter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 uint32_t bufferidx = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 uint8_t blockb0[16] = {0};/* Block B0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 uint8_t ctr[16] = {0}; /* Counter */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 uint32_t b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 /* Change the CRYP peripheral 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 /************************ Formatting the header block *********************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 /* Check that the associated data (or header) length is lower than 2^16 - 2^8 = 65536 - 256 = 65280 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 if(headersize < 65280)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize >> 8) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 headersize += 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 /* Header is encoded as 0xff || 0xfe || [headersize]32, i.e., six octets */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 hcryp->Init.pScratch[bufferidx++] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 hcryp->Init.pScratch[bufferidx++] = 0xFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 hcryp->Init.pScratch[bufferidx++] = headersize & 0xff000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 hcryp->Init.pScratch[bufferidx++] = headersize & 0x00ff0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 hcryp->Init.pScratch[bufferidx++] = headersize & 0x0000ff00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 hcryp->Init.pScratch[bufferidx++] = headersize & 0x000000ff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 headersize += 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 /* Copy the header buffer in internal buffer "hcryp->Init.pScratch" */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 for(loopcounter = 0; loopcounter < headersize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 hcryp->Init.pScratch[bufferidx++] = hcryp->Init.Header[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 /* Check if the header size is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 if ((headersize % 16) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 /* Padd the header buffer with 0s till the hcryp->Init.pScratch length is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 for(loopcounter = headersize; loopcounter <= ((headersize/16) + 1) * 16; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 hcryp->Init.pScratch[loopcounter] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 /* Set the header size to modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 headersize = ((headersize/16) + 1) * 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 /* Set the pointer headeraddr to hcryp->Init.pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 headeraddr = (uint32_t)hcryp->Init.pScratch;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 /*********************** Formatting the block B0 **************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 blockb0[0] = 0x40;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 /* Flags byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 /* blockb0[0] |= 0u | (((( (uint8_t) hcryp->Init.TagSize - 2) / 2) & 0x07 ) << 3 ) | ( ( (uint8_t) (15 - hcryp->Init.IVSize) - 1) & 0x07) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)(((uint8_t)(hcryp->Init.TagSize - (uint8_t)(2))) >> 1) & (uint8_t)0x07 ) << 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)((uint8_t)(15) - hcryp->Init.IVSize) - (uint8_t)1) & (uint8_t)0x07);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 for (loopcounter = 0; loopcounter < hcryp->Init.IVSize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 blockb0[loopcounter+1] = hcryp->Init.pInitVect[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 for ( ; loopcounter < 13; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 blockb0[loopcounter+1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 blockb0[14] = (Size >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 blockb0[15] = (Size & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 /************************* Formatting the initial counter *****************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 /* Byte 0:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 Bits 7 and 6 are reserved and shall be set to 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 Bits 3, 4, and 5 shall also be set to 0, to ensure that all the counter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 blocks are distinct from B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 Bits 0, 1, and 2 contain the same encoding of q as in B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 ctr[0] = blockb0[0] & 0x07;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 /* byte 1 to NonceSize is the IV (Nonce) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 for(loopcounter = 1; loopcounter < hcryp->Init.IVSize + 1; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 ctr[loopcounter] = blockb0[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 /* Set the LSB to 1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 ctr[15] |= 0x01;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 /* Set the CRYP peripheral in AES CCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CCM_DECRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 CRYPEx_GCMCCM_SetInitVector(hcryp, ctr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 /* Select init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 __HAL_CRYP_SET_PHASE(CRYP_PHASE_INIT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 /* Write the blockb0 block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 /***************************** Header phase *******************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 /* Select header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 __HAL_CRYP_SET_PHASE(CRYP_PHASE_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 /* Enable Crypto processor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 for(loopcounter = 0; (loopcounter < headersize); loopcounter+=16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_IFEM))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 /* Write the header block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 while((CRYP->SR & CRYP_FLAG_BUSY) == CRYP_FLAG_BUSY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 /* Save formatted counter into the scratch buffer pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358 for(loopcounter = 0; (loopcounter < 16); loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 hcryp->Init.pScratch[loopcounter] = ctr[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362 /* Reset bit 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 hcryp->Init.pScratch[15] &= 0xfe;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377 /* Write Plain Data and Get Cypher Data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 if(CRYPEx_GCMCCM_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 * @brief Initializes the CRYP peripheral in AES GCM encryption mode using IT.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398 * @param Size: Length of the plaintext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402 HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405 uint32_t inputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406 uint32_t outputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408 if(hcryp->State == HAL_CRYP_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 /* Get the buffer addresses and sizes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 hcryp->CrypInCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415 hcryp->pCrypInBuffPtr = pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 hcryp->pCrypOutBuffPtr = pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417 hcryp->CrypOutCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428 /* Set the CRYP peripheral in AES GCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_GCM_ENCRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432 CRYPEx_GCMCCM_SetInitVector(hcryp, hcryp->Init.pInitVect);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437 /* Enable CRYP to start the init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 /* Set the header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 if(CRYPEx_GCMCCM_SetHeaderPhase(hcryp, hcryp->Init.Header, hcryp->Init.HeaderSize, 1) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 /* Disable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478 if(Size != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 /* Enable Interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 /* Change the CRYP state and phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495 else if (__HAL_CRYP_GET_IT(CRYP_IT_INI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 /* Write the Input block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506 hcryp->pCrypInBuffPtr += 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507 hcryp->CrypInCount -= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1508 if(hcryp->CrypInCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1509 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511 /* Call the Input data transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 HAL_CRYP_InCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 else if (__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 /* Read the Output block from the Output FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526 hcryp->pCrypOutBuffPtr += 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 hcryp->CrypOutCount -= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528 if(hcryp->CrypOutCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535 /* Call Input transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536 HAL_CRYP_OutCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1537 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1540 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 * @brief Initializes the CRYP peripheral in AES CCM encryption mode using interrupt.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549 * @param Size: Length of the plaintext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553 HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1554 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556 uint32_t inputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 uint32_t outputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559 uint32_t headersize = hcryp->Init.HeaderSize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560 uint32_t headeraddr = (uint32_t)hcryp->Init.Header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561 uint32_t loopcounter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562 uint32_t bufferidx = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563 uint8_t blockb0[16] = {0};/* Block B0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1564 uint8_t ctr[16] = {0}; /* Counter */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565 uint32_t b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567 if(hcryp->State == HAL_CRYP_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1571
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572 hcryp->CrypInCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573 hcryp->pCrypInBuffPtr = pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574 hcryp->pCrypOutBuffPtr = pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 hcryp->CrypOutCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1581 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1582 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1583 /************************ Formatting the header block *******************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586 /* Check that the associated data (or header) length is lower than 2^16 - 2^8 = 65536 - 256 = 65280 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587 if(headersize < 65280)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1589 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize >> 8) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1591 headersize += 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595 /* Header is encoded as 0xff || 0xfe || [headersize]32, i.e., six octets */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596 hcryp->Init.pScratch[bufferidx++] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597 hcryp->Init.pScratch[bufferidx++] = 0xFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 hcryp->Init.pScratch[bufferidx++] = headersize & 0xff000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 hcryp->Init.pScratch[bufferidx++] = headersize & 0x00ff0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600 hcryp->Init.pScratch[bufferidx++] = headersize & 0x0000ff00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 hcryp->Init.pScratch[bufferidx++] = headersize & 0x000000ff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602 headersize += 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1604 /* Copy the header buffer in internal buffer "hcryp->Init.pScratch" */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1605 for(loopcounter = 0; loopcounter < headersize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607 hcryp->Init.pScratch[bufferidx++] = hcryp->Init.Header[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 /* Check if the header size is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610 if ((headersize % 16) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1611 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1612 /* Padd the header buffer with 0s till the hcryp->Init.pScratch length is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613 for(loopcounter = headersize; loopcounter <= ((headersize/16) + 1) * 16; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 hcryp->Init.pScratch[loopcounter] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617 /* Set the header size to modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618 headersize = ((headersize/16) + 1) * 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620 /* Set the pointer headeraddr to hcryp->Init.pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1621 headeraddr = (uint32_t)hcryp->Init.pScratch;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1622 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1623 /*********************** Formatting the block B0 ************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1624 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1625 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626 blockb0[0] = 0x40;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 /* Flags byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629 /* blockb0[0] |= 0u | (((( (uint8_t) hcryp->Init.TagSize - 2) / 2) & 0x07 ) << 3 ) | ( ( (uint8_t) (15 - hcryp->Init.IVSize) - 1) & 0x07) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)(((uint8_t)(hcryp->Init.TagSize - (uint8_t)(2))) >> 1) & (uint8_t)0x07 ) << 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)((uint8_t)(15) - hcryp->Init.IVSize) - (uint8_t)1) & (uint8_t)0x07);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1633 for (loopcounter = 0; loopcounter < hcryp->Init.IVSize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635 blockb0[loopcounter+1] = hcryp->Init.pInitVect[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637 for ( ; loopcounter < 13; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639 blockb0[loopcounter+1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642 blockb0[14] = (Size >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643 blockb0[15] = (Size & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1644
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 /************************* Formatting the initial counter ***************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 /* Byte 0:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647 Bits 7 and 6 are reserved and shall be set to 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 Bits 3, 4, and 5 shall also be set to 0, to ensure that all the counter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649 blocks are distinct from B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1650 Bits 0, 1, and 2 contain the same encoding of q as in B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652 ctr[0] = blockb0[0] & 0x07;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653 /* byte 1 to NonceSize is the IV (Nonce) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654 for(loopcounter = 1; loopcounter < hcryp->Init.IVSize + 1; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656 ctr[loopcounter] = blockb0[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 /* Set the LSB to 1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659 ctr[15] |= 0x01;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 /* Set the CRYP peripheral in AES CCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CCM_ENCRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668 CRYPEx_GCMCCM_SetInitVector(hcryp, ctr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670 /* Select init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1671 __HAL_CRYP_SET_PHASE(CRYP_PHASE_INIT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673 b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674 /* Write the blockb0 block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1688
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1689 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1690 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1691 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1692 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1693 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1694 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1695 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1696
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1697 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1698 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1699
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1700 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1701 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1702 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1703 /***************************** Header phase *****************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1704 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1705 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1706 /* Select header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1707 __HAL_CRYP_SET_PHASE(CRYP_PHASE_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1708
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1709 /* Enable Crypto processor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1710 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1711
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1712 for(loopcounter = 0; (loopcounter < headersize); loopcounter+=16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1713 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1714 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1715 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1717 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_IFEM))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1718 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1719 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1720 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1721 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1722 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1723 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1724
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1725 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1726 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1727
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1728 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1729 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1730 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1731 /* Write the header block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1732 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1733 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1734 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1735 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1736 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1737 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1738 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1739 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1740 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1741
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1742 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1743 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1744
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1745 while((CRYP->SR & CRYP_FLAG_BUSY) == CRYP_FLAG_BUSY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1746 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1747 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1748 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1749 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1750 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1751 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1752
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1753 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1754 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1755
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1756 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1757 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1758 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1759 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1760 /* Save formatted counter into the scratch buffer pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1761 for(loopcounter = 0; (loopcounter < 16); loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1762 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1763 hcryp->Init.pScratch[loopcounter] = ctr[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1764 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1765 /* Reset bit 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1766 hcryp->Init.pScratch[15] &= 0xfe;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1767
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1768 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1769 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1770
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1771 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1772 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1773
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1774 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1775 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1776 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1777
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1778 if(Size != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1779 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1780 /* Enable Interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1781 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1782 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1783 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1784 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1785 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1786 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1787 /* Change the CRYP state and phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1788 hcryp->State = HAL_CRYP_STATE_READY;
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 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1792 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1793 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1794 else if (__HAL_CRYP_GET_IT(CRYP_IT_INI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1795 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1796 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1797 /* Write the Input block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1798 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1799 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1800 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1801 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1802 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1803 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1804 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1805 hcryp->pCrypInBuffPtr += 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1806 hcryp->CrypInCount -= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1807 if(hcryp->CrypInCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1808 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1809 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1810 /* Call Input transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1811 HAL_CRYP_InCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1812 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1813 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1814 else if (__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1815 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1816 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1817 /* Read the Output block from the Output FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1818 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1819 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1820 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1821 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1822 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1823 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1824 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1825 hcryp->pCrypOutBuffPtr += 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1826 hcryp->CrypOutCount -= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1827 if(hcryp->CrypOutCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1828 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1829 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1830 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1831 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1832 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1833 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1834 /* Call Input transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1835 HAL_CRYP_OutCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1836 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1837 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1838
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1839 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1840 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1841 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1842
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1843 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1844 * @brief Initializes the CRYP peripheral in AES GCM decryption mode using IT.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1845 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1846 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1847 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1848 * @param Size: Length of the cyphertext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1849 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1850 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1851 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1852 HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1853 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1854 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1855 uint32_t inputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1856 uint32_t outputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1857
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1858 if(hcryp->State == HAL_CRYP_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1859 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1860 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1861 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1862
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1863 /* Get the buffer addresses and sizes */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1864 hcryp->CrypInCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1865 hcryp->pCrypInBuffPtr = pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1866 hcryp->pCrypOutBuffPtr = pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1867 hcryp->CrypOutCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1868
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1869 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1870 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1871
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1872 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1873 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1874 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1875 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1876 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1877
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1878 /* Set the CRYP peripheral in AES GCM decryption mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1879 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_GCM_DECRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1880
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1881 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1882 CRYPEx_GCMCCM_SetInitVector(hcryp, hcryp->Init.pInitVect);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1883
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1884 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1885 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1886
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1887 /* Enable CRYP to start the init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1888 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1889
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1890 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1891 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1892
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1893 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1894 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1895 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1896 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1897 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1898 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1899 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1900
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1901 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1902 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1903
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1904 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1905 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1906 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1907
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1908 /* Set the header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1909 if(CRYPEx_GCMCCM_SetHeaderPhase(hcryp, hcryp->Init.Header, hcryp->Init.HeaderSize, 1) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1910 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1911 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1912 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1913 /* Disable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1914 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1915
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1916 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1917 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1918
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1919 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1920 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1921 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1922
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1923 if(Size != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1924 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1925 /* Enable Interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1926 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1927 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1928 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1929 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1930 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1931 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1932 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1933 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1934 /* Change the CRYP state and phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1935 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1936 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1937
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1938 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1939 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1940 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1941 else if (__HAL_CRYP_GET_IT(CRYP_IT_INI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1942 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1943 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1944 /* Write the Input block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1945 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1946 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1947 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1948 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1949 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1950 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1951 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1952 hcryp->pCrypInBuffPtr += 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1953 hcryp->CrypInCount -= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1954 if(hcryp->CrypInCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1955 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1956 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1957 /* Call the Input data transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1958 HAL_CRYP_InCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1959 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1960 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1961 else if (__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1962 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1963 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1964 /* Read the Output block from the Output FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1965 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1966 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1967 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1968 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1969 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1970 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1971 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1972 hcryp->pCrypOutBuffPtr += 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1973 hcryp->CrypOutCount -= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1974 if(hcryp->CrypOutCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1975 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1976 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1977 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1978 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1979 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1980 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1981 /* Call Input transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1982 HAL_CRYP_OutCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1983 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1984 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1985
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1986 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1987 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1988 }
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 * @brief Initializes the CRYP peripheral in AES CCM decryption mode using interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1992 * then decrypted pCypherData. The cypher data are available in pPlainData.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1993 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1994 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1995 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1996 * @param Size: Length of the plaintext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1997 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1998 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1999 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2000 HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2001 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2002 uint32_t inputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2003 uint32_t outputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2004 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2005 uint32_t headersize = hcryp->Init.HeaderSize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2006 uint32_t headeraddr = (uint32_t)hcryp->Init.Header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2007 uint32_t loopcounter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2008 uint32_t bufferidx = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2009 uint8_t blockb0[16] = {0};/* Block B0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2010 uint8_t ctr[16] = {0}; /* Counter */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2011 uint32_t b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2012
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2013 if(hcryp->State == HAL_CRYP_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2014 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2015 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2016 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2017
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2018 hcryp->CrypInCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2019 hcryp->pCrypInBuffPtr = pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2020 hcryp->pCrypOutBuffPtr = pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2021 hcryp->CrypOutCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2022
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2023 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2024 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2025
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2026 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2027 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2028 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2029 /************************ Formatting the header block *******************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2030 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2031 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2032 /* Check that the associated data (or header) length is lower than 2^16 - 2^8 = 65536 - 256 = 65280 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2033 if(headersize < 65280)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2034 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2035 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize >> 8) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2036 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2037 headersize += 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2038 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2039 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2040 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2041 /* Header is encoded as 0xff || 0xfe || [headersize]32, i.e., six octets */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2042 hcryp->Init.pScratch[bufferidx++] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2043 hcryp->Init.pScratch[bufferidx++] = 0xFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2044 hcryp->Init.pScratch[bufferidx++] = headersize & 0xff000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2045 hcryp->Init.pScratch[bufferidx++] = headersize & 0x00ff0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2046 hcryp->Init.pScratch[bufferidx++] = headersize & 0x0000ff00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2047 hcryp->Init.pScratch[bufferidx++] = headersize & 0x000000ff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2048 headersize += 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2049 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2050 /* Copy the header buffer in internal buffer "hcryp->Init.pScratch" */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2051 for(loopcounter = 0; loopcounter < headersize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2052 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2053 hcryp->Init.pScratch[bufferidx++] = hcryp->Init.Header[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2054 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2055 /* Check if the header size is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2056 if ((headersize % 16) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2057 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2058 /* Padd the header buffer with 0s till the hcryp->Init.pScratch length is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2059 for(loopcounter = headersize; loopcounter <= ((headersize/16) + 1) * 16; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2060 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2061 hcryp->Init.pScratch[loopcounter] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2062 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2063 /* Set the header size to modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2064 headersize = ((headersize/16) + 1) * 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2065 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2066 /* Set the pointer headeraddr to hcryp->Init.pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2067 headeraddr = (uint32_t)hcryp->Init.pScratch;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2068 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2069 /*********************** Formatting the block B0 ************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2070 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2071 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2072 blockb0[0] = 0x40;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2073 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2074 /* Flags byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2075 /* blockb0[0] |= 0u | (((( (uint8_t) hcryp->Init.TagSize - 2) / 2) & 0x07 ) << 3 ) | ( ( (uint8_t) (15 - hcryp->Init.IVSize) - 1) & 0x07) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2076 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)(((uint8_t)(hcryp->Init.TagSize - (uint8_t)(2))) >> 1) & (uint8_t)0x07 ) << 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2077 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)((uint8_t)(15) - hcryp->Init.IVSize) - (uint8_t)1) & (uint8_t)0x07);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2078
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2079 for (loopcounter = 0; loopcounter < hcryp->Init.IVSize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2080 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2081 blockb0[loopcounter+1] = hcryp->Init.pInitVect[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2082 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2083 for ( ; loopcounter < 13; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2084 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2085 blockb0[loopcounter+1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2086 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2087
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2088 blockb0[14] = (Size >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2089 blockb0[15] = (Size & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2090
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2091 /************************* Formatting the initial counter ***************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2092 /* Byte 0:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2093 Bits 7 and 6 are reserved and shall be set to 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2094 Bits 3, 4, and 5 shall also be set to 0, to ensure that all the counter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2095 blocks are distinct from B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2096 Bits 0, 1, and 2 contain the same encoding of q as in B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2097 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2098 ctr[0] = blockb0[0] & 0x07;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2099 /* byte 1 to NonceSize is the IV (Nonce) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2100 for(loopcounter = 1; loopcounter < hcryp->Init.IVSize + 1; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2101 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2102 ctr[loopcounter] = blockb0[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2103 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2104 /* Set the LSB to 1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2105 ctr[15] |= 0x01;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2106
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2107 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2108 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2110 /* Set the CRYP peripheral in AES CCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2111 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CCM_DECRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2112
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2113 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2114 CRYPEx_GCMCCM_SetInitVector(hcryp, ctr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2116 /* Select init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2117 __HAL_CRYP_SET_PHASE(CRYP_PHASE_INIT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2119 b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2120 /* Write the blockb0 block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2121 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2122 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2123 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2124 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2125 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2126 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2127 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2129 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2130 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2132 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2133 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2135 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2136 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2137 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2138 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2139 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2140 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2141 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2143 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2144 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2146 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2147 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2148 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2149 /***************************** Header phase *****************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2150 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2151 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2152 /* Select header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2153 __HAL_CRYP_SET_PHASE(CRYP_PHASE_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2155 /* Enable Crypto processor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2156 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2158 for(loopcounter = 0; (loopcounter < headersize); loopcounter+=16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2159 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2160 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2161 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2163 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_IFEM))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2164 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2165 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2166 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2167 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2168 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2169 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2170
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2171 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2172 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2174 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2175 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2176 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2177 /* Write the header block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2178 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2179 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2180 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2181 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2182 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2183 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2184 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2185 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2186 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2187
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2188 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2189 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2191 while((CRYP->SR & CRYP_FLAG_BUSY) == CRYP_FLAG_BUSY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2192 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2193 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2194 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2195 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2196 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2197 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2198
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2199 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2200 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2202 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2203 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2204 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2205 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2206 /* Save formatted counter into the scratch buffer pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2207 for(loopcounter = 0; (loopcounter < 16); loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2208 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2209 hcryp->Init.pScratch[loopcounter] = ctr[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2210 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2211 /* Reset bit 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2212 hcryp->Init.pScratch[15] &= 0xfe;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2213 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2214 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2216 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2217 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2219 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2220 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
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 /* Enable Interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2224 __HAL_CRYP_ENABLE_IT(CRYP_IT_INI | CRYP_IT_OUTI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2225
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2226 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2227 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2228
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2229 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2230 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2231 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2232 else if (__HAL_CRYP_GET_IT(CRYP_IT_INI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2233 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2234 inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2235 /* Write the Input block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2236 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2237 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2238 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2239 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2240 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2241 inputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2242 CRYP->DR = *(uint32_t*)(inputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2243 hcryp->pCrypInBuffPtr += 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2244 hcryp->CrypInCount -= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2245 if(hcryp->CrypInCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2246 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2247 __HAL_CRYP_DISABLE_IT(CRYP_IT_INI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2248 /* Call the Input data transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2249 HAL_CRYP_InCpltCallback(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2250 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2251 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2252 else if (__HAL_CRYP_GET_IT(CRYP_IT_OUTI))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2253 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2254 outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2255 /* Read the Output block from the Output FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2256 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2257 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2258 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2259 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2260 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2261 outputaddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2262 *(uint32_t*)(outputaddr) = CRYP->DOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2263 hcryp->pCrypOutBuffPtr += 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2264 hcryp->CrypOutCount -= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2265 if(hcryp->CrypOutCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2266 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2267 __HAL_CRYP_DISABLE_IT(CRYP_IT_OUTI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2268 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2269 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2270 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2271 hcryp->State = HAL_CRYP_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2272 /* Call Input transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2273 HAL_CRYP_OutCpltCallback(hcryp);
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2277 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2278 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2279 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2281 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2282 * @brief Initializes the CRYP peripheral in AES GCM encryption mode using DMA.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2283 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2284 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2285 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2286 * @param Size: Length of the plaintext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2287 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2288 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2289 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2290 HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2291 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2292 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2293 uint32_t inputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2294 uint32_t outputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2296 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
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 inputaddr = (uint32_t)pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2302 outputaddr = (uint32_t)pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2304 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2305 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2306
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2307 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2308 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2309 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2310 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2311 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2312
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2313 /* Set the CRYP peripheral in AES GCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2314 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_GCM_ENCRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2315
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2316 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2317 CRYPEx_GCMCCM_SetInitVector(hcryp, hcryp->Init.pInitVect);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2319 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2320 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2321
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2322 /* Enable CRYP to start the init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2323 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2324
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2325 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2326 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2327
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2328 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2329 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2330 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2331 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2332 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2333 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2334 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2335
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2336 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2337 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2339 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2340 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2342 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2343 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2345 /* Set the header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2346 if(CRYPEx_GCMCCM_SetHeaderPhase(hcryp, hcryp->Init.Header, hcryp->Init.HeaderSize, 1) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2347 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2348 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2349 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2350 /* Disable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2351 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2352
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2353 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2354 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2355
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2356 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2357 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2359 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2360 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2361 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2362
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2363 /* Set the input and output addresses and start DMA transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2364 CRYPEx_GCMCCM_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2365
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2366 /* Unlock process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2367 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2369 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2370 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2371 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2372 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2373 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2374 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2375 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2376 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2377
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2378 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2379 * @brief Initializes the CRYP peripheral in AES CCM encryption mode using interrupt.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2380 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2381 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2382 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2383 * @param Size: Length of the plaintext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2384 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2385 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2386 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2387 HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pPlainData, uint16_t Size, uint8_t *pCypherData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2388 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2389 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2390 uint32_t inputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2391 uint32_t outputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2392 uint32_t headersize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2393 uint32_t headeraddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2394 uint32_t loopcounter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2395 uint32_t bufferidx = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2396 uint8_t blockb0[16] = {0};/* Block B0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2397 uint8_t ctr[16] = {0}; /* Counter */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2398 uint32_t b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2399
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2400 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2401 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2402 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2403 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2404
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2405 inputaddr = (uint32_t)pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2406 outputaddr = (uint32_t)pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2408 headersize = hcryp->Init.HeaderSize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2409 headeraddr = (uint32_t)hcryp->Init.Header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2410
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2411 hcryp->CrypInCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2412 hcryp->pCrypInBuffPtr = pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2413 hcryp->pCrypOutBuffPtr = pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2414 hcryp->CrypOutCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2415
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2416 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2417 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2419 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2420 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2421 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2422 /************************ Formatting the header block *******************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2423 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2424 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2425 /* Check that the associated data (or header) length is lower than 2^16 - 2^8 = 65536 - 256 = 65280 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2426 if(headersize < 65280)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2427 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2428 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize >> 8) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2429 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2430 headersize += 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2431 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2432 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2433 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2434 /* Header is encoded as 0xff || 0xfe || [headersize]32, i.e., six octets */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2435 hcryp->Init.pScratch[bufferidx++] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2436 hcryp->Init.pScratch[bufferidx++] = 0xFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2437 hcryp->Init.pScratch[bufferidx++] = headersize & 0xff000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2438 hcryp->Init.pScratch[bufferidx++] = headersize & 0x00ff0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2439 hcryp->Init.pScratch[bufferidx++] = headersize & 0x0000ff00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2440 hcryp->Init.pScratch[bufferidx++] = headersize & 0x000000ff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2441 headersize += 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2442 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2443 /* Copy the header buffer in internal buffer "hcryp->Init.pScratch" */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2444 for(loopcounter = 0; loopcounter < headersize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2445 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2446 hcryp->Init.pScratch[bufferidx++] = hcryp->Init.Header[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2448 /* Check if the header size is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2449 if ((headersize % 16) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2450 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2451 /* Padd the header buffer with 0s till the hcryp->Init.pScratch length is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2452 for(loopcounter = headersize; loopcounter <= ((headersize/16) + 1) * 16; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2453 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2454 hcryp->Init.pScratch[loopcounter] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2455 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2456 /* Set the header size to modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2457 headersize = ((headersize/16) + 1) * 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2458 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2459 /* Set the pointer headeraddr to hcryp->Init.pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2460 headeraddr = (uint32_t)hcryp->Init.pScratch;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2461 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2462 /*********************** Formatting the block B0 ************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2463 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2464 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2465 blockb0[0] = 0x40;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2466 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2467 /* Flags byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2468 /* blockb0[0] |= 0u | (((( (uint8_t) hcryp->Init.TagSize - 2) / 2) & 0x07 ) << 3 ) | ( ( (uint8_t) (15 - hcryp->Init.IVSize) - 1) & 0x07) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2469 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)(((uint8_t)(hcryp->Init.TagSize - (uint8_t)(2))) >> 1) & (uint8_t)0x07 ) << 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2470 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)((uint8_t)(15) - hcryp->Init.IVSize) - (uint8_t)1) & (uint8_t)0x07);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2471
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2472 for (loopcounter = 0; loopcounter < hcryp->Init.IVSize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2473 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2474 blockb0[loopcounter+1] = hcryp->Init.pInitVect[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2475 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2476 for ( ; loopcounter < 13; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2477 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2478 blockb0[loopcounter+1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2479 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2480
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2481 blockb0[14] = (Size >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2482 blockb0[15] = (Size & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2483
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2484 /************************* Formatting the initial counter ***************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2485 /* Byte 0:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2486 Bits 7 and 6 are reserved and shall be set to 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2487 Bits 3, 4, and 5 shall also be set to 0, to ensure that all the counter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2488 blocks are distinct from B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2489 Bits 0, 1, and 2 contain the same encoding of q as in B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2490 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2491 ctr[0] = blockb0[0] & 0x07;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2492 /* byte 1 to NonceSize is the IV (Nonce) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2493 for(loopcounter = 1; loopcounter < hcryp->Init.IVSize + 1; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2494 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2495 ctr[loopcounter] = blockb0[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2496 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2497 /* Set the LSB to 1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2498 ctr[15] |= 0x01;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2499
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2500 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2501 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2503 /* Set the CRYP peripheral in AES CCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2504 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CCM_ENCRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2505
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2506 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2507 CRYPEx_GCMCCM_SetInitVector(hcryp, ctr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2508
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2509 /* Select init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2510 __HAL_CRYP_SET_PHASE(CRYP_PHASE_INIT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2511
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2512 b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2513 /* Write the blockb0 block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2514 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2515 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2516 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2517 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2518 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2519 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2520 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2521
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2522 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2523 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2524
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2525 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2526 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2527
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2528 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2529 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2530 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2531 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2532 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2533 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2534 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2535
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2536 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2537 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2539 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2540 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2541 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2542 /***************************** Header phase *****************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2543 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2544 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2545 /* Select header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2546 __HAL_CRYP_SET_PHASE(CRYP_PHASE_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2547
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2548 /* Enable Crypto processor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2549 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2550
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2551 for(loopcounter = 0; (loopcounter < headersize); loopcounter+=16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2552 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2553 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2554 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2555
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2556 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_IFEM))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2557 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2558 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2559 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2560 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2561 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2562 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2563
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2567 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2568 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2569 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2570 /* Write the header block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2571 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2572 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2573 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2574 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2575 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2576 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2577 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2578 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2579 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2580
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2581 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2582 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2583
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2584 while((CRYP->SR & CRYP_FLAG_BUSY) == CRYP_FLAG_BUSY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2585 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2586 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2587 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2588 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2589 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2590 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2591
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2592 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2593 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2594
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2595 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2596 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2597 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2598 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2599 /* Save formatted counter into the scratch buffer pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2600 for(loopcounter = 0; (loopcounter < 16); loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2601 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2602 hcryp->Init.pScratch[loopcounter] = ctr[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2603 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2604 /* Reset bit 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2605 hcryp->Init.pScratch[15] &= 0xfe;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2606
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2607 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2608 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2609
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2610 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2611 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2612
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2613 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2614 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2615 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2616
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2617 /* Set the input and output addresses and start DMA transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2618 CRYPEx_GCMCCM_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2619
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2620 /* Unlock process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2621 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2622
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2623 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2624 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2625 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2626 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2627 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2628 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2629 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2630 }
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 * @brief Initializes the CRYP peripheral in AES GCM decryption mode using DMA.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2634 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2635 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2636 * @param pCypherData: Pointer to the cyphertext buffer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2637 * @param Size: Length of the cyphertext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2638 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2639 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2640 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2641 HAL_StatusTypeDef HAL_CRYPEx_AESGCM_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2642 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2643 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2644 uint32_t inputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2645 uint32_t outputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2646
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2647 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2648 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2649 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2650 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2651
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2652 inputaddr = (uint32_t)pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2653 outputaddr = (uint32_t)pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2654
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2655 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2656 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2657
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2658 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2659 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2660 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2661 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2662 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2664 /* Set the CRYP peripheral in AES GCM decryption mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2665 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_GCM_DECRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2666
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2667 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2668 CRYPEx_GCMCCM_SetInitVector(hcryp, hcryp->Init.pInitVect);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2669
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2670 /* Enable CRYP to start the init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2671 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2672
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2673 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2674 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2675
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2676 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2677 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2678 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2679 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2680 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2681 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2682 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2683
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2684 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2685 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2686
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2687 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2688 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2689 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2690
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2691 /* Set the header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2692 if(CRYPEx_GCMCCM_SetHeaderPhase(hcryp, hcryp->Init.Header, hcryp->Init.HeaderSize, 1) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2693 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2694 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2695 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2696 /* Disable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2697 __HAL_CRYP_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2698
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2699 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2700 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2701
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2702 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2703 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2704 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2705
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2706 /* Set the input and output addresses and start DMA transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2707 CRYPEx_GCMCCM_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2708
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2709 /* Unlock process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2710 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2711
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2712 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2713 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2714 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2715 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2716 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2717 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2718 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2719 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2721 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2722 * @brief Initializes the CRYP peripheral in AES CCM decryption mode using DMA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2723 * then decrypted pCypherData. The cypher data are available in pPlainData.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2724 * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2725 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2726 * @param pCypherData: Pointer to the cyphertext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2727 * @param Size: Length of the plaintext buffer, must be a multiple of 16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2728 * @param pPlainData: Pointer to the plaintext buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2729 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2730 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2731 HAL_StatusTypeDef HAL_CRYPEx_AESCCM_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2732 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2733 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2734 uint32_t inputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2735 uint32_t outputaddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2736 uint32_t headersize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2737 uint32_t headeraddr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2738 uint32_t loopcounter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2739 uint32_t bufferidx = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2740 uint8_t blockb0[16] = {0};/* Block B0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2741 uint8_t ctr[16] = {0}; /* Counter */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2742 uint32_t b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2743
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2744 if((hcryp->State == HAL_CRYP_STATE_READY) || (hcryp->Phase == HAL_CRYP_PHASE_PROCESS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2745 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2746 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2747 __HAL_LOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2748
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2749 inputaddr = (uint32_t)pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2750 outputaddr = (uint32_t)pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2751
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2752 headersize = hcryp->Init.HeaderSize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2753 headeraddr = (uint32_t)hcryp->Init.Header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2754
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2755 hcryp->CrypInCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2756 hcryp->pCrypInBuffPtr = pCypherData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2757 hcryp->pCrypOutBuffPtr = pPlainData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2758 hcryp->CrypOutCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2759
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2760 /* Change the CRYP peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2761 hcryp->State = HAL_CRYP_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2762
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2763 /* Check if initialization phase has already been performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2764 if(hcryp->Phase == HAL_CRYP_PHASE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2765 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2766 /************************ Formatting the header block *******************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2767 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2768 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2769 /* Check that the associated data (or header) length is lower than 2^16 - 2^8 = 65536 - 256 = 65280 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2770 if(headersize < 65280)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2771 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2772 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize >> 8) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2773 hcryp->Init.pScratch[bufferidx++] = (uint8_t) ((headersize) & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2774 headersize += 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2775 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2776 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2777 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2778 /* Header is encoded as 0xff || 0xfe || [headersize]32, i.e., six octets */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2779 hcryp->Init.pScratch[bufferidx++] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2780 hcryp->Init.pScratch[bufferidx++] = 0xFE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2781 hcryp->Init.pScratch[bufferidx++] = headersize & 0xff000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2782 hcryp->Init.pScratch[bufferidx++] = headersize & 0x00ff0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2783 hcryp->Init.pScratch[bufferidx++] = headersize & 0x0000ff00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2784 hcryp->Init.pScratch[bufferidx++] = headersize & 0x000000ff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2785 headersize += 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2786 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2787 /* Copy the header buffer in internal buffer "hcryp->Init.pScratch" */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2788 for(loopcounter = 0; loopcounter < headersize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2789 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2790 hcryp->Init.pScratch[bufferidx++] = hcryp->Init.Header[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2791 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2792 /* Check if the header size is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2793 if ((headersize % 16) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2794 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2795 /* Padd the header buffer with 0s till the hcryp->Init.pScratch length is modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2796 for(loopcounter = headersize; loopcounter <= ((headersize/16) + 1) * 16; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2797 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2798 hcryp->Init.pScratch[loopcounter] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2799 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2800 /* Set the header size to modulo 16 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2801 headersize = ((headersize/16) + 1) * 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2802 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2803 /* Set the pointer headeraddr to hcryp->Init.pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2804 headeraddr = (uint32_t)hcryp->Init.pScratch;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2805 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2806 /*********************** Formatting the block B0 ************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2807 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2808 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2809 blockb0[0] = 0x40;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2810 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2811 /* Flags byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2812 /* blockb0[0] |= 0u | (((( (uint8_t) hcryp->Init.TagSize - 2) / 2) & 0x07 ) << 3 ) | ( ( (uint8_t) (15 - hcryp->Init.IVSize) - 1) & 0x07) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2813 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)(((uint8_t)(hcryp->Init.TagSize - (uint8_t)(2))) >> 1) & (uint8_t)0x07 ) << 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2814 blockb0[0] |= (uint8_t)((uint8_t)((uint8_t)((uint8_t)(15) - hcryp->Init.IVSize) - (uint8_t)1) & (uint8_t)0x07);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2815
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2816 for (loopcounter = 0; loopcounter < hcryp->Init.IVSize; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2817 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2818 blockb0[loopcounter+1] = hcryp->Init.pInitVect[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2819 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2820 for ( ; loopcounter < 13; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2821 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2822 blockb0[loopcounter+1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2823 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2824
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2825 blockb0[14] = (Size >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2826 blockb0[15] = (Size & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2827
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2828 /************************* Formatting the initial counter ***************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2829 /* Byte 0:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2830 Bits 7 and 6 are reserved and shall be set to 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2831 Bits 3, 4, and 5 shall also be set to 0, to ensure that all the counter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2832 blocks are distinct from B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2833 Bits 0, 1, and 2 contain the same encoding of q as in B0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2834 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2835 ctr[0] = blockb0[0] & 0x07;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2836 /* byte 1 to NonceSize is the IV (Nonce) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2837 for(loopcounter = 1; loopcounter < hcryp->Init.IVSize + 1; loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2838 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2839 ctr[loopcounter] = blockb0[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2840 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2841 /* Set the LSB to 1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2842 ctr[15] |= 0x01;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2843
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2844 /* Set the key */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2845 CRYPEx_GCMCCM_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2846
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2847 /* Set the CRYP peripheral in AES CCM mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2848 __HAL_CRYP_SET_MODE(CRYP_CR_ALGOMODE_AES_CCM_DECRYPT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2849
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2850 /* Set the Initialization Vector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2851 CRYPEx_GCMCCM_SetInitVector(hcryp, ctr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2852
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2853 /* Select init phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2854 __HAL_CRYP_SET_PHASE(CRYP_PHASE_INIT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2855
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2856 b0addr = (uint32_t)blockb0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2857 /* Write the blockb0 block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2858 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2859 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2860 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2861 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2862 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2863 b0addr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2864 CRYP->DR = *(uint32_t*)(b0addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2865
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2866 /* Enable the CRYP peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2867 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2868
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2869 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2870 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2871
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2872 while((CRYP->CR & CRYP_CR_CRYPEN) == CRYP_CR_CRYPEN)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2873 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2874 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2875
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2876 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2877 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2878 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2879 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2880
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2881 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2882 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2883
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2884 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2885
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2886 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2887 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2888 /***************************** Header phase *****************************/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2889 if(headersize != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2890 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2891 /* Select header phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2892 __HAL_CRYP_SET_PHASE(CRYP_PHASE_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2893
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2894 /* Enable Crypto processor */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2895 __HAL_CRYP_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2896
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2897 for(loopcounter = 0; (loopcounter < headersize); loopcounter+=16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2898 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2899 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2900 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2901
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2902 while(HAL_IS_BIT_CLR(CRYP->SR, CRYP_FLAG_IFEM))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2903 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2904 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2905 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2906 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2907 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2908 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2909
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2910 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2911 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2912
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2913 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2914 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2915 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2916 /* Write the header block in the IN FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2917 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2918 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2919 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2920 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2921 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2922 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2923 CRYP->DR = *(uint32_t*)(headeraddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2924 headeraddr+=4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2925 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2926
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2927 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2928 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2929
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2930 while((CRYP->SR & CRYP_FLAG_BUSY) == CRYP_FLAG_BUSY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2931 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2932 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2933 if((HAL_GetTick() - tickstart ) > CRYPEx_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2934 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2935 /* Change state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2936 hcryp->State = HAL_CRYP_STATE_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2937
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2938 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2939 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2940
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2941 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2942 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2943 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2944 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2945 /* Save formatted counter into the scratch buffer pScratch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2946 for(loopcounter = 0; (loopcounter < 16); loopcounter++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2947 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2948 hcryp->Init.pScratch[loopcounter] = ctr[loopcounter];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2949 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2950 /* Reset bit 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2951 hcryp->Init.pScratch[15] &= 0xfe;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2952 /* Select payload phase once the header phase is performed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2953 __HAL_CRYP_SET_PHASE(CRYP_PHASE_PAYLOAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2954
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2955 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2956 __HAL_CRYP_FIFO_FLUSH();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2957
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2958 /* Set the phase */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2959 hcryp->Phase = HAL_CRYP_PHASE_PROCESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2960 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2961 /* Set the input and output addresses and start DMA transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2962 CRYPEx_GCMCCM_SetDMAConfig(hcryp, inputaddr, Size, outputaddr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2963
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2964 /* Unlock process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2965 __HAL_UNLOCK(hcryp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2966
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2967 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2968 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2969 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2970 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2971 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2972 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2973 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2974 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2975
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2976 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2977 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2978 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2979
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2980 /** @defgroup CRYPEx_Exported_Functions_Group2 CRYPEx IRQ handler management
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2981 * @brief CRYPEx IRQ handler.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2982 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2983 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2984 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2985 ##### CRYPEx IRQ handler management #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2986 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2987 [..] This section provides CRYPEx IRQ handler function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2988
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2989 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2990 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2991 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2992
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2993 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2994 * @brief This function handles CRYPEx interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2995 * @param hcryp: pointer to a CRYPEx_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2996 * the configuration information for CRYP module
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2997 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2998 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2999
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3000 void HAL_CRYPEx_GCMCCM_IRQHandler(CRYP_HandleTypeDef *hcryp)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3001 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3002 switch(CRYP->CR & CRYP_CR_ALGOMODE_DIRECTION)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3003 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3004 case CRYP_CR_ALGOMODE_AES_GCM_ENCRYPT:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3005 HAL_CRYPEx_AESGCM_Encrypt_IT(hcryp, NULL, 0, NULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3006 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3007
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3008 case CRYP_CR_ALGOMODE_AES_GCM_DECRYPT:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3009 HAL_CRYPEx_AESGCM_Decrypt_IT(hcryp, NULL, 0, NULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3010 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3011
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3012 case CRYP_CR_ALGOMODE_AES_CCM_ENCRYPT:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3013 HAL_CRYPEx_AESCCM_Encrypt_IT(hcryp, NULL, 0, NULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3014 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3016 case CRYP_CR_ALGOMODE_AES_CCM_DECRYPT:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3017 HAL_CRYPEx_AESCCM_Decrypt_IT(hcryp, NULL, 0, NULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3018 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3019
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3020 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3021 break;
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 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3026 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3027 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3028
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3029 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3030 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3031 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3032 #endif /* STM32F437xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3033
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3034 #endif /* HAL_CRYP_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3035 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3036 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3037 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3038
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3039 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3040 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3041 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3042
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3043 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/