]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_aes.h
Add Pearl Gecko demo.
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_aes.h
1 /***************************************************************************//**\r
2  * @file em_aes.h\r
3  * @brief Advanced encryption standard (AES) accelerator peripheral API.\r
4  * @version 4.2.1\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>\r
8  *******************************************************************************\r
9  *\r
10  * Permission is granted to anyone to use this software for any purpose,\r
11  * including commercial applications, and to alter it and redistribute it\r
12  * freely, subject to the following restrictions:\r
13  *\r
14  * 1. The origin of this software must not be misrepresented; you must not\r
15  *    claim that you wrote the original software.\r
16  * 2. Altered source versions must be plainly marked as such, and must not be\r
17  *    misrepresented as being the original software.\r
18  * 3. This notice may not be removed or altered from any source distribution.\r
19  *\r
20  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no\r
21  * obligation to support this Software. Silicon Labs is providing the\r
22  * Software "AS IS", with no express or implied warranties of any kind,\r
23  * including, but not limited to, any implied warranties of merchantability\r
24  * or fitness for any particular purpose or warranties against infringement\r
25  * of any proprietary rights of a third party.\r
26  *\r
27  * Silicon Labs will not be liable for any consequential, incidental, or\r
28  * special damages, or any other relief, or for any claim by any third party,\r
29  * arising from your use of this Software.\r
30  *\r
31  ******************************************************************************/\r
32 \r
33 #ifndef __SILICON_LABS_EM_AES_H__\r
34 #define __SILICON_LABS_EM_AES_H__\r
35 \r
36 #include "em_device.h"\r
37 #if defined(AES_COUNT) && (AES_COUNT > 0)\r
38 \r
39 #include <stdbool.h>\r
40 \r
41 #ifdef __cplusplus\r
42 extern "C" {\r
43 #endif\r
44 \r
45 /***************************************************************************//**\r
46  * @addtogroup EM_Library\r
47  * @{\r
48  ******************************************************************************/\r
49 \r
50 /***************************************************************************//**\r
51  * @addtogroup AES\r
52  * @{\r
53  ******************************************************************************/\r
54 \r
55 /*******************************************************************************\r
56  ******************************   TYPEDEFS   ***********************************\r
57  ******************************************************************************/\r
58 \r
59 /**\r
60  * @brief\r
61  *   AES counter modification function pointer.\r
62  * @details\r
63  *   Parameters:\r
64  *   @li ctr - Ptr to byte array (16 bytes) holding counter to be modified.\r
65  */\r
66 typedef void (*AES_CtrFuncPtr_TypeDef)(uint8_t *ctr);\r
67 \r
68 /*******************************************************************************\r
69  *****************************   PROTOTYPES   **********************************\r
70  ******************************************************************************/\r
71 \r
72 void AES_CBC128(uint8_t *out,\r
73                 const uint8_t *in,\r
74                 unsigned int len,\r
75                 const uint8_t *key,\r
76                 const uint8_t *iv,\r
77                 bool encrypt);\r
78 \r
79 #if defined( AES_CTRL_AES256 )\r
80 void AES_CBC256(uint8_t *out,\r
81                 const uint8_t *in,\r
82                 unsigned int len,\r
83                 const uint8_t *key,\r
84                 const uint8_t *iv,\r
85                 bool encrypt);\r
86 #endif\r
87 \r
88 void AES_CFB128(uint8_t *out,\r
89                 const uint8_t *in,\r
90                 unsigned int len,\r
91                 const uint8_t *key,\r
92                 const uint8_t *iv,\r
93                 bool encrypt);\r
94 \r
95 #if defined( AES_CTRL_AES256 )\r
96 void AES_CFB256(uint8_t *out,\r
97                 const uint8_t *in,\r
98                 unsigned int len,\r
99                 const uint8_t *key,\r
100                 const uint8_t *iv,\r
101                 bool encrypt);\r
102 #endif\r
103 \r
104 void AES_CTR128(uint8_t *out,\r
105                 const uint8_t *in,\r
106                 unsigned int len,\r
107                 const uint8_t *key,\r
108                 uint8_t *ctr,\r
109                 AES_CtrFuncPtr_TypeDef ctrFunc);\r
110 \r
111 #if defined( AES_CTRL_AES256 )\r
112 void AES_CTR256(uint8_t *out,\r
113                 const uint8_t *in,\r
114                 unsigned int len,\r
115                 const uint8_t *key,\r
116                 uint8_t *ctr,\r
117                 AES_CtrFuncPtr_TypeDef ctrFunc);\r
118 #endif\r
119 \r
120 void AES_CTRUpdate32Bit(uint8_t *ctr);\r
121 \r
122 void AES_DecryptKey128(uint8_t *out, const uint8_t *in);\r
123 \r
124 #if defined( AES_CTRL_AES256 )\r
125 void AES_DecryptKey256(uint8_t *out, const uint8_t *in);\r
126 #endif\r
127 \r
128 void AES_ECB128(uint8_t *out,\r
129                 const uint8_t *in,\r
130                 unsigned int len,\r
131                 const uint8_t *key,\r
132                 bool encrypt);\r
133 \r
134 #if defined( AES_CTRL_AES256 )\r
135 void AES_ECB256(uint8_t *out,\r
136                 const uint8_t *in,\r
137                 unsigned int len,\r
138                 const uint8_t *key,\r
139                 bool encrypt);\r
140 #endif\r
141 \r
142 /***************************************************************************//**\r
143  * @brief\r
144  *   Clear one or more pending AES interrupts.\r
145  *\r
146  * @param[in] flags\r
147  *   Pending AES interrupt source to clear. Use a bitwise logic OR combination of\r
148  *   valid interrupt flags for the AES module (AES_IF_nnn).\r
149  ******************************************************************************/\r
150 __STATIC_INLINE void AES_IntClear(uint32_t flags)\r
151 {\r
152   AES->IFC = flags;\r
153 }\r
154 \r
155 \r
156 /***************************************************************************//**\r
157  * @brief\r
158  *   Disable one or more AES interrupts.\r
159  *\r
160  * @param[in] flags\r
161  *   AES interrupt sources to disable. Use a bitwise logic OR combination of\r
162  *   valid interrupt flags for the AES module (AES_IF_nnn).\r
163  ******************************************************************************/\r
164 __STATIC_INLINE void AES_IntDisable(uint32_t flags)\r
165 {\r
166   AES->IEN &= ~(flags);\r
167 }\r
168 \r
169 \r
170 /***************************************************************************//**\r
171  * @brief\r
172  *   Enable one or more AES interrupts.\r
173  *\r
174  * @note\r
175  *   Depending on the use, a pending interrupt may already be set prior to\r
176  *   enabling the interrupt. Consider using AES_IntClear() prior to enabling\r
177  *   if such a pending interrupt should be ignored.\r
178  *\r
179  * @param[in] flags\r
180  *   AES interrupt sources to enable. Use a bitwise logic OR combination of\r
181  *   valid interrupt flags for the AES module (AES_IF_nnn).\r
182  ******************************************************************************/\r
183 __STATIC_INLINE void AES_IntEnable(uint32_t flags)\r
184 {\r
185   AES->IEN |= flags;\r
186 }\r
187 \r
188 \r
189 /***************************************************************************//**\r
190  * @brief\r
191  *   Get pending AES interrupt flags.\r
192  *\r
193  * @note\r
194  *   The event bits are not cleared by the use of this function.\r
195  *\r
196  * @return\r
197  *   AES interrupt sources pending. A bitwise logic OR combination of valid\r
198  *   interrupt flags for the AES module (AES_IF_nnn).\r
199  ******************************************************************************/\r
200 __STATIC_INLINE uint32_t AES_IntGet(void)\r
201 {\r
202   return AES->IF;\r
203 }\r
204 \r
205 \r
206 /***************************************************************************//**\r
207  * @brief\r
208  *   Get enabled and pending AES interrupt flags.\r
209  *   Useful for handling more interrupt sources in the same interrupt handler.\r
210  *\r
211  * @note\r
212  *   Interrupt flags are not cleared by the use of this function.\r
213  *\r
214  * @return\r
215  *   Pending and enabled AES interrupt sources\r
216  *   The return value is the bitwise AND of\r
217  *   - the enabled interrupt sources in AES_IEN and\r
218  *   - the pending interrupt flags AES_IF\r
219  ******************************************************************************/\r
220 __STATIC_INLINE uint32_t AES_IntGetEnabled(void)\r
221 {\r
222   uint32_t ien;\r
223 \r
224   ien = AES->IEN;\r
225   return AES->IF & ien;\r
226 }\r
227 \r
228 \r
229 /***************************************************************************//**\r
230  * @brief\r
231  *   Set one or more pending AES interrupts from SW.\r
232  *\r
233  * @param[in] flags\r
234  *   AES interrupt sources to set to pending. Use a bitwise logic OR combination\r
235  *   of valid interrupt flags for the AES module (AES_IF_nnn).\r
236  ******************************************************************************/\r
237 __STATIC_INLINE void AES_IntSet(uint32_t flags)\r
238 {\r
239   AES->IFS = flags;\r
240 }\r
241 \r
242 \r
243 void AES_OFB128(uint8_t *out,\r
244                 const uint8_t *in,\r
245                 unsigned int len,\r
246                 const uint8_t *key,\r
247                 const uint8_t *iv);\r
248 \r
249 #if defined( AES_CTRL_AES256 )\r
250 void AES_OFB256(uint8_t *out,\r
251                 const uint8_t *in,\r
252                 unsigned int len,\r
253                 const uint8_t *key,\r
254                 const uint8_t *iv);\r
255 #endif\r
256 \r
257 \r
258 /** @} (end addtogroup AES) */\r
259 /** @} (end addtogroup EM_Library) */\r
260 \r
261 #ifdef __cplusplus\r
262 }\r
263 #endif\r
264 \r
265 #endif /* defined(AES_COUNT) && (AES_COUNT > 0) */\r
266 #endif /* __SILICON_LABS_EM_AES_H__ */\r
267 \r
268 \r