34 #if defined(AES_COUNT) && (AES_COUNT > 0)
53 #define AES_BLOCKSIZE 16
132 uint32_t *_out = (uint32_t *)out;
133 const uint32_t *_in = (
const uint32_t *)in;
134 const uint32_t *_key = (
const uint32_t *)key;
135 const uint32_t *_iv = (
const uint32_t *)iv;
139 EFM_ASSERT(!(len % AES_BLOCKSIZE));
142 len /= AES_BLOCKSIZE;
144 #if defined( AES_CTRL_KEYBUFEN )
148 for (i = 3; i >= 0; i--)
150 AES->KEYHA = __REV(_key[i]);
158 #if defined( AES_CTRL_KEYBUFEN )
166 for (i = 3; i >= 0; i--)
168 AES->DATA = __REV(_iv[i]);
174 #if !defined( AES_CTRL_KEYBUFEN )
176 for (i = 3; i >= 0; i--)
178 AES->KEYLA = __REV(_key[i]);
183 for (i = 3; i >= 0; i--)
185 AES->XORDATA = __REV(_in[i]);
194 for (i = 3; i >= 0; i--)
196 _out[i] = __REV(
AES->DATA);
204 #if defined( AES_CTRL_KEYBUFEN )
211 for (i = 0; i < 4; i++)
219 #if !defined( AES_CTRL_KEYBUFEN )
221 for (i = 3; i >= 0; i--)
223 AES->KEYLA = __REV(_key[i]);
228 for (i = 3; i >= 0; i--)
230 AES->DATA = __REV(_in[i]);
239 for (i = 3; i >= 0; i--)
241 AES->XORDATA = __REV(prev[i]);
248 for (i = 3; i >= 0; i--)
250 _out[i] = __REV(
AES->DATA);
258 #if defined( AES_CTRL_AES256 )
298 uint32_t *_out = (uint32_t *)out;
299 const uint32_t *_in = (
const uint32_t *)in;
300 const uint32_t *_key = (
const uint32_t *)key;
301 const uint32_t *_iv = (
const uint32_t *)iv;
305 EFM_ASSERT(!(len % AES_BLOCKSIZE));
308 len /= AES_BLOCKSIZE;
317 for (i = 3; i >= 0; i--)
319 AES->DATA = __REV(_iv[i]);
326 for (i = 3, j = 7; i >= 0; i--, j--)
328 AES->KEYLA = __REV(_key[j]);
329 AES->KEYHA = __REV(_key[i]);
331 AES->XORDATA = __REV(_in[i]);
340 for (i = 3; i >= 0; i--)
342 _out[i] = __REV(
AES->DATA);
353 for (i = 0; i < 4; i++)
362 for (i = 3, j = 7; i >= 0; i--, j--)
364 AES->KEYLA = __REV(_key[j]);
365 AES->KEYHA = __REV(_key[i]);
367 AES->DATA = __REV(_in[i]);
375 for (i = 3; i >= 0; i--)
377 AES->XORDATA = __REV(prev[i]);
384 for (i = 3; i >= 0; i--)
386 _out[i] = __REV(
AES->DATA);
461 uint32_t *_out = (uint32_t *)out;
462 const uint32_t *_in = (
const uint32_t *)in;
463 const uint32_t *_key = (
const uint32_t *)key;
464 const uint32_t *_iv = (
const uint32_t *)iv;
465 const uint32_t *data;
468 EFM_ASSERT(!(len % AES_BLOCKSIZE));
470 #if defined( AES_CTRL_KEYBUFEN )
476 #if defined( AES_CTRL_KEYBUFEN )
478 for (i = 3; i >= 0; i--)
480 AES->KEYHA = __REV(_key[i]);
486 len /= AES_BLOCKSIZE;
489 #if !defined( AES_CTRL_KEYBUFEN )
491 for (i = 3; i >= 0; i--)
493 AES->KEYLA = __REV(_key[i]);
498 for (i = 3; i >= 0; i--)
500 AES->DATA = __REV(data[i]);
511 for (i = 0; i < 4; i++)
523 for (i = 3; i >= 0; i--)
525 _out[i] = __REV(
AES->DATA) ^ _in[i];
533 #if defined( AES_CTRL_AES256 )
571 uint32_t *_out = (uint32_t *)out;
572 const uint32_t *_in = (
const uint32_t *)in;
573 const uint32_t *_key = (
const uint32_t *)key;
574 const uint32_t *_iv = (
const uint32_t *)iv;
575 const uint32_t *data;
578 EFM_ASSERT(!(len % AES_BLOCKSIZE));
585 len /= AES_BLOCKSIZE;
589 for (i = 3, j = 7; i >= 0; i--, j--)
591 AES->KEYLA = __REV(_key[j]);
592 AES->KEYHA = __REV(_key[i]);
594 AES->DATA = __REV(data[i]);
605 for (i = 0; i < 4; i++)
616 for (i = 3; i >= 0; i--)
618 _out[i] = __REV(
AES->DATA) ^ _in[i];
695 uint32_t *_out = (uint32_t *)out;
696 const uint32_t *_in = (
const uint32_t *)in;
697 const uint32_t *_key = (
const uint32_t *)key;
698 uint32_t *_ctr = (uint32_t *)ctr;
700 EFM_ASSERT(!(len % AES_BLOCKSIZE));
703 #if defined( AES_CTRL_KEYBUFEN )
709 #if defined( AES_CTRL_KEYBUFEN )
713 for (i = 3; i >= 0; i--)
715 AES->KEYHA = __REV(_key[i]);
721 len /= AES_BLOCKSIZE;
724 #if !defined( AES_CTRL_KEYBUFEN )
726 for (i = 3; i >= 0; i--)
728 AES->KEYLA = __REV(_key[i]);
733 for (i = 3; i >= 0; i--)
735 AES->DATA = __REV(_ctr[i]);
745 for (i = 3; i >= 0; i--)
747 _out[i] = __REV(
AES->DATA) ^ _in[i];
755 #if defined( AES_CTRL_AES256 )
794 uint32_t *_out = (uint32_t *)out;
795 const uint32_t *_in = (
const uint32_t *)in;
796 const uint32_t *_key = (
const uint32_t *)key;
797 uint32_t *_ctr = (uint32_t *)ctr;
799 EFM_ASSERT(!(len % AES_BLOCKSIZE));
806 len /= AES_BLOCKSIZE;
810 for (i = 3, j = 7; i >= 0; i--, j--)
812 AES->KEYLA = __REV(_key[j]);
813 AES->KEYHA = __REV(_key[i]);
815 AES->DATA = __REV(_ctr[i]);
825 for (i = 3; i >= 0; i--)
827 _out[i] = __REV(
AES->DATA) ^ _in[i];
852 uint32_t *_ctr = (uint32_t *)ctr;
854 _ctr[3] = __REV(__REV(_ctr[3]) + 1);
876 uint32_t *_out = (uint32_t *)out;
877 const uint32_t *_in = (
const uint32_t *)in;
880 for (i = 3; i >= 0; i--)
882 AES->KEYLA = __REV(_in[i]);
895 for (i = 3; i >= 0; i--)
897 _out[i] = __REV(
AES->KEYLA);
902 #if defined( AES_CTRL_AES256 )
922 uint32_t *_out = (uint32_t *)out;
923 const uint32_t *_in = (
const uint32_t *)in;
926 for (i = 3, j = 7; i >= 0; i--, j--)
928 AES->KEYLA = __REV(_in[j]);
929 AES->KEYHA = __REV(_in[i]);
941 for (i = 3, j = 7; i >= 0; i--, j--)
943 _out[j] = __REV(
AES->KEYLA);
944 _out[i] = __REV(
AES->KEYHA);
1008 uint32_t *_out = (uint32_t *)out;
1009 const uint32_t *_in = (
const uint32_t *)in;
1010 const uint32_t *_key = (
const uint32_t *)key;
1012 EFM_ASSERT(!(len % AES_BLOCKSIZE));
1014 #if defined( AES_CTRL_KEYBUFEN )
1016 for (i = 3; i >= 0; i--)
1018 AES->KEYHA = __REV(_key[i]);
1025 #if defined( AES_CTRL_KEYBUFEN )
1034 #if defined( AES_CTRL_KEYBUFEN )
1042 len /= AES_BLOCKSIZE;
1045 #if !defined( AES_CTRL_KEYBUFEN )
1047 for (i = 3; i >= 0; i--)
1049 AES->KEYLA = __REV(_key[i]);
1054 for (i = 3; i >= 0; i--)
1056 AES->DATA = __REV(_in[i]);
1065 for (i = 3; i >= 0; i--)
1067 _out[i] = __REV(
AES->DATA);
1074 #if defined( AES_CTRL_AES256 )
1110 uint32_t *_out = (uint32_t *)out;
1111 const uint32_t *_in = (
const uint32_t *)in;
1112 const uint32_t *_key = (
const uint32_t *)key;
1114 EFM_ASSERT(!(len % AES_BLOCKSIZE));
1128 len /= AES_BLOCKSIZE;
1132 for (i = 3, j = 7; i >= 0; i--, j--)
1134 AES->KEYLA = __REV(_key[j]);
1135 AES->KEYHA = __REV(_key[i]);
1137 AES->DATA = __REV(_in[i]);
1146 for (i = 3; i >= 0; i--)
1148 _out[i] = __REV(
AES->DATA);
1220 uint32_t *_out = (uint32_t *)out;
1221 const uint32_t *_in = (
const uint32_t *)in;
1222 const uint32_t *_key = (
const uint32_t *)key;
1223 const uint32_t *_iv = (
const uint32_t *)iv;
1225 EFM_ASSERT(!(len % AES_BLOCKSIZE));
1228 #if defined( AES_CTRL_KEYBUFEN )
1236 for (i = 3; i >= 0; i--)
1238 #if defined( AES_CTRL_KEYBUFEN )
1239 AES->KEYHA = __REV(_key[i]);
1241 AES->DATA = __REV(_iv[i]);
1245 len /= AES_BLOCKSIZE;
1248 #if !defined( AES_CTRL_KEYBUFEN )
1250 for (i = 3; i >= 0; i--)
1252 AES->KEYLA = __REV(_key[i]);
1263 for (i = 3; i >= 0; i--)
1265 _out[i] = __REV(
AES->DATA) ^ _in[i];
1273 #if defined( AES_CTRL_AES256 )
1307 uint32_t *_out = (uint32_t *)out;
1308 const uint32_t *_in = (
const uint32_t *)in;
1309 const uint32_t *_key = (
const uint32_t *)key;
1310 const uint32_t *_iv = (
const uint32_t *)iv;
1312 EFM_ASSERT(!(len % AES_BLOCKSIZE));
1318 for (i = 3; i >= 0; i--)
1320 AES->DATA = __REV(_iv[i]);
1324 len /= AES_BLOCKSIZE;
1328 for (i = 3, j = 7; i >= 0; i--, j--)
1330 AES->KEYLA = __REV(_key[j]);
1331 AES->KEYHA = __REV(_key[i]);
1341 for (i = 3; i >= 0; i--)
1343 _out[i] = __REV(
AES->DATA) ^ _in[i];
void AES_CTRUpdate32Bit(uint8_t *ctr)
Update last 32 bits of 128 bit counter, by incrementing with 1.
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...
Emlib peripheral API "assert" implementation.
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.
__STATIC_INLINE void AES_IntClear(uint32_t flags)
Clear one or more pending AES interrupts.
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.
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.
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.
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.
#define AES_CTRL_XORSTART
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.
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.
void(* AES_CtrFuncPtr_TypeDef)(uint8_t *ctr)
AES counter modification function pointer.
Advanced encryption standard (AES) accelerator peripheral API.
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...
#define AES_CTRL_KEYBUFEN
#define AES_CTRL_DATASTART
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.
#define AES_STATUS_RUNNING
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.
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.