2 ******************************************************************************
\r
3 * @file stm32l1xx_aes.h
\r
4 * @author MCD Application Team
\r
6 * @date 05-March-2012
\r
7 * @brief This file contains all the functions prototypes for the AES firmware
\r
9 ******************************************************************************
\r
12 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
\r
14 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
\r
15 * You may not use this file except in compliance with the License.
\r
16 * You may obtain a copy of the License at:
\r
18 * http://www.st.com/software_license_agreement_liberty_v2
\r
20 * Unless required by applicable law or agreed to in writing, software
\r
21 * distributed under the License is distributed on an "AS IS" BASIS,
\r
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
23 * See the License for the specific language governing permissions and
\r
24 * limitations under the License.
\r
26 ******************************************************************************
\r
29 /* Define to prevent recursive inclusion -------------------------------------*/
\r
30 #ifndef __STM32L1xx_AES_H
\r
31 #define __STM32L1xx_AES_H
\r
37 /* Includes ------------------------------------------------------------------*/
\r
38 #include "stm32l1xx.h"
\r
40 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
48 /* Exported types ------------------------------------------------------------*/
\r
51 * @brief AES Init structure definition
\r
55 uint32_t AES_Operation; /*!< Specifies the AES mode of operation.
\r
56 This parameter can be a value of @ref AES_possible_Operation_modes */
\r
57 uint32_t AES_Chaining; /*!< Specifies the AES Chaining modes: ECB, CBC or CTR.
\r
58 This parameter can be a value of @ref AES_possible_chaining_modes */
\r
59 uint32_t AES_DataType; /*!< Specifies the AES data swapping: 32-bit, 16-bit, 8-bit or 1-bit.
\r
60 This parameter can be a value of @ref AES_Data_Types */
\r
64 * @brief AES Key(s) structure definition
\r
68 uint32_t AES_Key0; /*!< Key[31:0] */
\r
69 uint32_t AES_Key1; /*!< Key[63:32] */
\r
70 uint32_t AES_Key2; /*!< Key[95:64] */
\r
71 uint32_t AES_Key3; /*!< Key[127:96] */
\r
72 }AES_KeyInitTypeDef;
\r
75 * @brief AES Initialization Vectors (IV) structure definition
\r
79 uint32_t AES_IV0; /*!< Init Vector IV[31:0] */
\r
80 uint32_t AES_IV1; /*!< Init Vector IV[63:32] */
\r
81 uint32_t AES_IV2; /*!< Init Vector IV[95:64] */
\r
82 uint32_t AES_IV3; /*!< Init Vector IV[127:96] */
\r
85 /* Exported constants --------------------------------------------------------*/
\r
87 /** @defgroup AES_Exported_Constants
\r
91 /** @defgroup AES_possible_Operation_modes
\r
94 #define AES_Operation_Encryp ((uint32_t)0x00000000) /*!< AES in Encryption mode */
\r
95 #define AES_Operation_KeyDeriv AES_CR_MODE_0 /*!< AES in Key Derivation mode */
\r
96 #define AES_Operation_Decryp AES_CR_MODE_1 /*!< AES in Decryption mode */
\r
97 #define AES_Operation_KeyDerivAndDecryp AES_CR_MODE /*!< AES in Key Derivation and Decryption mode */
\r
99 #define IS_AES_MODE(OPERATION) (((OPERATION) == AES_Operation_Encryp) || \
\r
100 ((OPERATION) == AES_Operation_KeyDeriv) || \
\r
101 ((OPERATION) == AES_Operation_Decryp) || \
\r
102 ((OPERATION) == AES_Operation_KeyDerivAndDecryp))
\r
108 /** @defgroup AES_possible_chaining_modes
\r
111 #define AES_Chaining_ECB ((uint32_t)0x00000000) /*!< AES in ECB chaining mode */
\r
112 #define AES_Chaining_CBC AES_CR_CHMOD_0 /*!< AES in CBC chaining mode */
\r
113 #define AES_Chaining_CTR AES_CR_CHMOD_1 /*!< AES in CTR chaining mode */
\r
115 #define IS_AES_CHAINING(CHAINING) (((CHAINING) == AES_Chaining_ECB) || \
\r
116 ((CHAINING) == AES_Chaining_CBC) || \
\r
117 ((CHAINING) == AES_Chaining_CTR))
\r
122 /** @defgroup AES_Data_Types
\r
125 #define AES_DataType_32b ((uint32_t)0x00000000) /*!< 32-bit data. No swapping */
\r
126 #define AES_DataType_16b AES_CR_DATATYPE_0 /*!< 16-bit data. Each half word is swapped */
\r
127 #define AES_DataType_8b AES_CR_DATATYPE_1 /*!< 8-bit data. All bytes are swapped */
\r
128 #define AES_DataType_1b AES_CR_DATATYPE /*!< 1-bit data. In the word all bits are swapped */
\r
130 #define IS_AES_DATATYPE(DATATYPE) (((DATATYPE) == AES_DataType_32b) || \
\r
131 ((DATATYPE) == AES_DataType_16b)|| \
\r
132 ((DATATYPE) == AES_DataType_8b) || \
\r
133 ((DATATYPE) == AES_DataType_1b))
\r
138 /** @defgroup AES_Flags
\r
141 #define AES_FLAG_CCF AES_SR_CCF /*!< Computation Complete Flag */
\r
142 #define AES_FLAG_RDERR AES_SR_RDERR /*!< Read Error Flag */
\r
143 #define AES_FLAG_WRERR AES_SR_WRERR /*!< Write Error Flag */
\r
145 #define IS_AES_FLAG(FLAG) (((FLAG) == AES_FLAG_CCF) || \
\r
146 ((FLAG) == AES_FLAG_RDERR) || \
\r
147 ((FLAG) == AES_FLAG_WRERR))
\r
152 /** @defgroup AES_Interrupts
\r
155 #define AES_IT_CC AES_CR_CCIE /*!< Computation Complete interrupt */
\r
156 #define AES_IT_ERR AES_CR_ERRIE /*!< Error interrupt */
\r
158 #define IS_AES_IT(IT) ((((IT) & (uint32_t)0xFFFFF9FF) == 0x00) && ((IT) != 0x00))
\r
159 #define IS_AES_GET_IT(IT) (((IT) == AES_IT_CC) || ((IT) == AES_IT_ERR))
\r
165 /** @defgroup AES_DMA_Transfer_modes
\r
168 #define AES_DMATransfer_In AES_CR_DMAINEN /*!< DMA requests enabled for input transfer phase */
\r
169 #define AES_DMATransfer_Out AES_CR_DMAOUTEN /*!< DMA requests enabled for input transfer phase */
\r
170 #define AES_DMATransfer_InOut (AES_CR_DMAINEN | AES_CR_DMAOUTEN) /*!< DMA requests enabled for both input and output phases */
\r
172 #define IS_AES_DMA_TRANSFER(TRANSFER) (((TRANSFER) == AES_DMATransfer_In) || \
\r
173 ((TRANSFER) == AES_DMATransfer_Out) || \
\r
174 ((TRANSFER) == AES_DMATransfer_InOut))
\r
183 /* Exported macro ------------------------------------------------------------*/
\r
184 /* Exported functions ------------------------------------------------------- */
\r
186 /* Initialization and configuration functions *********************************/
\r
187 void AES_DeInit(void);
\r
188 void AES_Init(AES_InitTypeDef* AES_InitStruct);
\r
189 void AES_KeyInit(AES_KeyInitTypeDef* AES_KeyInitStruct);
\r
190 void AES_IVInit(AES_IVInitTypeDef* AES_IVInitStruct);
\r
191 void AES_Cmd(FunctionalState NewState);
\r
193 /* Structures initialization functions ****************************************/
\r
194 void AES_StructInit(AES_InitTypeDef* AES_InitStruct);
\r
195 void AES_KeyStructInit(AES_KeyInitTypeDef* AES_KeyInitStruct);
\r
196 void AES_IVStructInit(AES_IVInitTypeDef* AES_IVInitStruct);
\r
198 /* AES Read and Write functions **********************************************/
\r
199 void AES_WriteSubData(uint32_t Data);
\r
200 uint32_t AES_ReadSubData(void);
\r
201 void AES_ReadKey(AES_KeyInitTypeDef* AES_KeyInitStruct);
\r
202 void AES_ReadIV(AES_IVInitTypeDef* AES_IVInitStruct);
\r
204 /* DMA transfers management function ******************************************/
\r
205 void AES_DMAConfig(uint32_t AES_DMATransfer, FunctionalState NewState);
\r
207 /* Interrupts and flags management functions **********************************/
\r
208 void AES_ITConfig(uint32_t AES_IT, FunctionalState NewState);
\r
209 FlagStatus AES_GetFlagStatus(uint32_t AES_FLAG);
\r
210 void AES_ClearFlag(uint32_t AES_FLAG);
\r
211 ITStatus AES_GetITStatus(uint32_t AES_IT);
\r
212 void AES_ClearITPendingBit(uint32_t AES_IT);
\r
214 /* High Level AES functions **************************************************/
\r
215 ErrorStatus AES_ECB_Encrypt(uint8_t* Key, uint8_t* Input, uint32_t Ilength, uint8_t* Output);
\r
216 ErrorStatus AES_ECB_Decrypt(uint8_t* Key, uint8_t* Input, uint32_t Ilength, uint8_t* Output);
\r
217 ErrorStatus AES_CBC_Encrypt(uint8_t* Key, uint8_t InitVectors[16], uint8_t* Input, uint32_t Ilength, uint8_t* Output);
\r
218 ErrorStatus AES_CBC_Decrypt(uint8_t* Key, uint8_t InitVectors[16], uint8_t* Input, uint32_t Ilength, uint8_t* Output);
\r
219 ErrorStatus AES_CTR_Encrypt(uint8_t* Key, uint8_t InitVectors[16], uint8_t* Input, uint32_t Ilength, uint8_t* Output);
\r
220 ErrorStatus AES_CTR_Decrypt(uint8_t* Key, uint8_t InitVectors[16], uint8_t* Input, uint32_t Ilength, uint8_t* Output);
\r
226 #endif /*__STM32L1xx_AES_H */
\r
236 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r