EFM32 Gecko Software Documentation  efm32g-doc-5.1.2
em_aes.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef EM_AES_H
34 #define EM_AES_H
35 
36 #include "em_device.h"
37 #if defined(AES_COUNT) && (AES_COUNT > 0)
38 
39 #include <stdbool.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /***************************************************************************/
50 /***************************************************************************/
105 /*******************************************************************************
106  ****************************** TYPEDEFS ***********************************
107  ******************************************************************************/
108 
116 typedef void (*AES_CtrFuncPtr_TypeDef)(uint8_t *ctr);
117 
118 /*******************************************************************************
119  ***************************** PROTOTYPES **********************************
120  ******************************************************************************/
121 
122 void AES_CBC128(uint8_t *out,
123  const uint8_t *in,
124  unsigned int len,
125  const uint8_t *key,
126  const uint8_t *iv,
127  bool encrypt);
128 
129 #if defined( AES_CTRL_AES256 )
130 void AES_CBC256(uint8_t *out,
131  const uint8_t *in,
132  unsigned int len,
133  const uint8_t *key,
134  const uint8_t *iv,
135  bool encrypt);
136 #endif
137 
138 void AES_CFB128(uint8_t *out,
139  const uint8_t *in,
140  unsigned int len,
141  const uint8_t *key,
142  const uint8_t *iv,
143  bool encrypt);
144 
145 #if defined( AES_CTRL_AES256 )
146 void AES_CFB256(uint8_t *out,
147  const uint8_t *in,
148  unsigned int len,
149  const uint8_t *key,
150  const uint8_t *iv,
151  bool encrypt);
152 #endif
153 
154 void AES_CTR128(uint8_t *out,
155  const uint8_t *in,
156  unsigned int len,
157  const uint8_t *key,
158  uint8_t *ctr,
159  AES_CtrFuncPtr_TypeDef ctrFunc);
160 
161 #if defined( AES_CTRL_AES256 )
162 void AES_CTR256(uint8_t *out,
163  const uint8_t *in,
164  unsigned int len,
165  const uint8_t *key,
166  uint8_t *ctr,
167  AES_CtrFuncPtr_TypeDef ctrFunc);
168 #endif
169 
170 void AES_CTRUpdate32Bit(uint8_t *ctr);
171 
172 void AES_DecryptKey128(uint8_t *out, const uint8_t *in);
173 
174 #if defined( AES_CTRL_AES256 )
175 void AES_DecryptKey256(uint8_t *out, const uint8_t *in);
176 #endif
177 
178 void AES_ECB128(uint8_t *out,
179  const uint8_t *in,
180  unsigned int len,
181  const uint8_t *key,
182  bool encrypt);
183 
184 #if defined( AES_CTRL_AES256 )
185 void AES_ECB256(uint8_t *out,
186  const uint8_t *in,
187  unsigned int len,
188  const uint8_t *key,
189  bool encrypt);
190 #endif
191 
192 /***************************************************************************/
200 __STATIC_INLINE void AES_IntClear(uint32_t flags)
201 {
202  AES->IFC = flags;
203 }
204 
205 
206 /***************************************************************************/
214 __STATIC_INLINE void AES_IntDisable(uint32_t flags)
215 {
216  AES->IEN &= ~(flags);
217 }
218 
219 
220 /***************************************************************************/
233 __STATIC_INLINE void AES_IntEnable(uint32_t flags)
234 {
235  AES->IEN |= flags;
236 }
237 
238 
239 /***************************************************************************/
250 __STATIC_INLINE uint32_t AES_IntGet(void)
251 {
252  return AES->IF;
253 }
254 
255 
256 /***************************************************************************/
270 __STATIC_INLINE uint32_t AES_IntGetEnabled(void)
271 {
272  uint32_t ien;
273 
274  ien = AES->IEN;
275  return AES->IF & ien;
276 }
277 
278 
279 /***************************************************************************/
287 __STATIC_INLINE void AES_IntSet(uint32_t flags)
288 {
289  AES->IFS = flags;
290 }
291 
292 
293 void AES_OFB128(uint8_t *out,
294  const uint8_t *in,
295  unsigned int len,
296  const uint8_t *key,
297  const uint8_t *iv);
298 
299 #if defined( AES_CTRL_AES256 )
300 void AES_OFB256(uint8_t *out,
301  const uint8_t *in,
302  unsigned int len,
303  const uint8_t *key,
304  const uint8_t *iv);
305 #endif
306 
307 
311 #ifdef __cplusplus
312 }
313 #endif
314 
315 #endif /* defined(AES_COUNT) && (AES_COUNT > 0) */
316 #endif /* EM_AES_H */
317 
318 
__STATIC_INLINE uint32_t AES_IntGet(void)
Get pending AES interrupt flags.
Definition: em_aes.h:250
void AES_CTRUpdate32Bit(uint8_t *ctr)
Update last 32 bits of 128 bit counter, by incrementing with 1.
Definition: em_aes.c:850
__STATIC_INLINE void AES_IntDisable(uint32_t flags)
Disable one or more AES interrupts.
Definition: em_aes.h:214
__STATIC_INLINE uint32_t AES_IntGetEnabled(void)
Get enabled and pending AES interrupt flags. Useful for handling more interrupt sources in the same i...
Definition: em_aes.h:270
__STATIC_INLINE void AES_IntEnable(uint32_t flags)
Enable one or more AES interrupts.
Definition: em_aes.h:233
void AES_DecryptKey128(uint8_t *out, const uint8_t *in)
Generate 128 bit decryption key from 128 bit encryption key. The decryption key is used for some ciph...
Definition: em_aes.c:873
void AES_CFB256(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
Cipher feedback (CFB) cipher mode encryption/decryption, 256 bit key.
Definition: em_aes.c:562
__STATIC_INLINE void AES_IntClear(uint32_t flags)
Clear one or more pending AES interrupts.
Definition: em_aes.h:200
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
void AES_CTR128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, uint8_t *ctr, AES_CtrFuncPtr_TypeDef ctrFunc)
Counter (CTR) cipher mode encryption/decryption, 128 bit key.
Definition: em_aes.c:687
void AES_OFB256(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv)
Output feedback (OFB) cipher mode encryption/decryption, 256 bit key.
Definition: em_aes.c:1299
void AES_CTR256(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, uint8_t *ctr, AES_CtrFuncPtr_TypeDef ctrFunc)
Counter (CTR) cipher mode encryption/decryption, 256 bit key.
Definition: em_aes.c:785
void AES_OFB128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv)
Output feedback (OFB) cipher mode encryption/decryption, 128 bit key.
Definition: em_aes.c:1213
__STATIC_INLINE void AES_IntSet(uint32_t flags)
Set one or more pending AES interrupts from SW.
Definition: em_aes.h:287
void AES_CBC128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
Cipher-block chaining (CBC) cipher mode encryption/decryption, 128 bit key.
Definition: em_aes.c:124
void AES_CBC256(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
Cipher-block chaining (CBC) cipher mode encryption/decryption, 256 bit key.
Definition: em_aes.c:289
#define AES
void(* AES_CtrFuncPtr_TypeDef)(uint8_t *ctr)
AES counter modification function pointer.
Definition: em_aes.h:116
void AES_DecryptKey256(uint8_t *out, const uint8_t *in)
Generate 256 bit decryption key from 256 bit encryption key. The decryption key is used for some ciph...
Definition: em_aes.c:918
void AES_ECB256(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, bool encrypt)
Electronic Codebook (ECB) cipher mode encryption/decryption, 256 bit key.
Definition: em_aes.c:1102
void AES_ECB128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, bool encrypt)
Electronic Codebook (ECB) cipher mode encryption/decryption, 128 bit key.
Definition: em_aes.c:1001
void AES_CFB128(uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
Cipher feedback (CFB) cipher mode encryption/decryption, 128 bit key.
Definition: em_aes.c:453