EFM32 Leopard Gecko Software Documentation  efm32lg-doc-4.2.1
em_aes.c
Go to the documentation of this file.
1 /***************************************************************************/
33 #include "em_aes.h"
34 #if defined(AES_COUNT) && (AES_COUNT > 0)
35 
36 #include "em_assert.h"
37 /***************************************************************************/
42 /***************************************************************************/
80 /*******************************************************************************
81  ******************************* DEFINES ***********************************
82  ******************************************************************************/
83 
86 #define AES_BLOCKSIZE 16
87 
90 /*******************************************************************************
91  ************************** GLOBAL FUNCTIONS *******************************
92  ******************************************************************************/
93 
94 /***************************************************************************/
157 void AES_CBC128(uint8_t *out,
158  const uint8_t *in,
159  unsigned int len,
160  const uint8_t *key,
161  const uint8_t *iv,
162  bool encrypt)
163 {
164  int i;
165  uint32_t *_out = (uint32_t *)out;
166  const uint32_t *_in = (const uint32_t *)in;
167  const uint32_t *_key = (const uint32_t *)key;
168  const uint32_t *_iv = (const uint32_t *)iv;
169  /* Need to buffer one block when decrypting in case 'out' replaces 'in' */
170  uint32_t prev[4];
171 
172  EFM_ASSERT(!(len % AES_BLOCKSIZE));
173 
174  /* Number of blocks to process */
175  len /= AES_BLOCKSIZE;
176 
177  #if defined( AES_CTRL_KEYBUFEN )
178  if (key)
179  {
180  /* Load key into high key for key buffer usage */
181  for (i = 3; i >= 0; i--)
182  {
183  AES->KEYHA = __REV(_key[i]);
184  }
185  }
186  #endif
187 
188  if (encrypt)
189  {
190  /* Enable encryption with auto start using XOR */
191  #if defined( AES_CTRL_KEYBUFEN )
193  #else
194  AES->CTRL = AES_CTRL_XORSTART;
195  #endif
196 
197  /* Load initialization vector, since writing to DATA, it will */
198  /* not trigger encryption. */
199  for (i = 3; i >= 0; i--)
200  {
201  AES->DATA = __REV(_iv[i]);
202  }
203 
204  /* Encrypt data */
205  while (len--)
206  {
207  #if !defined( AES_CTRL_KEYBUFEN )
208  /* Load key */
209  for (i = 3; i >= 0; i--)
210  {
211  AES->KEYLA = __REV(_key[i]);
212  }
213  #endif
214 
215  /* Load data and trigger encryption */
216  for (i = 3; i >= 0; i--)
217  {
218  AES->XORDATA = __REV(_in[i]);
219  }
220  _in += 4;
221 
222  /* Wait for completion */
223  while (AES->STATUS & AES_STATUS_RUNNING)
224  ;
225 
226  /* Save encrypted data */
227  for (i = 3; i >= 0; i--)
228  {
229  _out[i] = __REV(AES->DATA);
230  }
231  _out += 4;
232  }
233  }
234  else
235  {
236  /* Select decryption mode */
237  #if defined( AES_CTRL_KEYBUFEN )
239  #else
241  #endif
242 
243  /* Copy init vector to previous buffer to avoid special handling */
244  for (i = 0; i < 4; i++)
245  {
246  prev[i] = _iv[i];
247  }
248 
249  /* Decrypt data */
250  while (len--)
251  {
252  #if !defined( AES_CTRL_KEYBUFEN )
253  /* Load key */
254  for (i = 3; i >= 0; i--)
255  {
256  AES->KEYLA = __REV(_key[i]);
257  }
258  #endif
259 
260  /* Load data and trigger decryption */
261  for (i = 3; i >= 0; i--)
262  {
263  AES->DATA = __REV(_in[i]);
264  }
265 
266  /* Wait for completion */
267  while (AES->STATUS & AES_STATUS_RUNNING)
268  ;
269 
270  /* In order to avoid additional buffer, we use HW directly for XOR and buffer */
271  /* (Writing to XORDATA will not trigger encoding, triggering enabled on DATA.) */
272  for (i = 3; i >= 0; i--)
273  {
274  AES->XORDATA = __REV(prev[i]);
275  prev[i] = _in[i];
276  }
277  _in += 4;
278 
279  /* Then fetch decrypted data, we have to do it in a separate loop */
280  /* due to internal auto-shifting of words */
281  for (i = 3; i >= 0; i--)
282  {
283  _out[i] = __REV(AES->DATA);
284  }
285  _out += 4;
286  }
287  }
288 }
289 
290 
291 #if defined( AES_CTRL_AES256 )
292 /***************************************************************************/
322 void AES_CBC256(uint8_t *out,
323  const uint8_t *in,
324  unsigned int len,
325  const uint8_t *key,
326  const uint8_t *iv,
327  bool encrypt)
328 {
329  int i;
330  int j;
331  uint32_t *_out = (uint32_t *)out;
332  const uint32_t *_in = (const uint32_t *)in;
333  const uint32_t *_key = (const uint32_t *)key;
334  const uint32_t *_iv = (const uint32_t *)iv;
335  /* Need to buffer one block when decrypting in case output replaces input */
336  uint32_t prev[4];
337 
338  EFM_ASSERT(!(len % AES_BLOCKSIZE));
339 
340  /* Number of blocks to process */
341  len /= AES_BLOCKSIZE;
342 
343  if (encrypt)
344  {
345  /* Enable encryption with auto start using XOR */
347 
348  /* Load initialization vector, since writing to DATA, it will */
349  /* not trigger encryption. */
350  for (i = 3; i >= 0; i--)
351  {
352  AES->DATA = __REV(_iv[i]);
353  }
354 
355  /* Encrypt data */
356  while (len--)
357  {
358  /* Load key and data and trigger encryption */
359  for (i = 3, j = 7; i >= 0; i--, j--)
360  {
361  AES->KEYLA = __REV(_key[j]);
362  AES->KEYHA = __REV(_key[i]);
363  /* Write data last, since will trigger encryption on last iteration */
364  AES->XORDATA = __REV(_in[i]);
365  }
366  _in += 4;
367 
368  /* Wait for completion */
369  while (AES->STATUS & AES_STATUS_RUNNING)
370  ;
371 
372  /* Save encrypted data */
373  for (i = 3; i >= 0; i--)
374  {
375  _out[i] = __REV(AES->DATA);
376  }
377  _out += 4;
378  }
379  }
380  else
381  {
382  /* Select decryption mode */
384 
385  /* Copy init vector to previous buffer to avoid special handling */
386  for (i = 0; i < 4; i++)
387  {
388  prev[i] = _iv[i];
389  }
390 
391  /* Decrypt data */
392  while (len--)
393  {
394  /* Load key and data and trigger decryption */
395  for (i = 3, j = 7; i >= 0; i--, j--)
396  {
397  AES->KEYLA = __REV(_key[j]);
398  AES->KEYHA = __REV(_key[i]);
399  /* Write data last, since will trigger encryption on last iteration */
400  AES->DATA = __REV(_in[i]);
401  }
402 
403  /* Wait for completion */
404  while (AES->STATUS & AES_STATUS_RUNNING)
405  ;
406 
407  /* In order to avoid additional buffer, we use HW directly for XOR and buffer */
408  for (i = 3; i >= 0; i--)
409  {
410  AES->XORDATA = __REV(prev[i]);
411  prev[i] = _in[i];
412  }
413  _in += 4;
414 
415  /* Then fetch decrypted data, we have to do it in a separate loop */
416  /* due to internal auto-shifting of words */
417  for (i = 3; i >= 0; i--)
418  {
419  _out[i] = __REV(AES->DATA);
420  }
421  _out += 4;
422  }
423  }
424 }
425 #endif
426 
427 
428 /***************************************************************************/
486 void AES_CFB128(uint8_t *out,
487  const uint8_t *in,
488  unsigned int len,
489  const uint8_t *key,
490  const uint8_t *iv,
491  bool encrypt)
492 {
493  int i;
494  uint32_t *_out = (uint32_t *)out;
495  const uint32_t *_in = (const uint32_t *)in;
496  const uint32_t *_key = (const uint32_t *)key;
497  const uint32_t *_iv = (const uint32_t *)iv;
498  const uint32_t *data;
499  uint32_t tmp[4];
500 
501  EFM_ASSERT(!(len % AES_BLOCKSIZE));
502 
503  #if defined( AES_CTRL_KEYBUFEN )
505  #else
506  AES->CTRL = AES_CTRL_DATASTART;
507  #endif
508 
509  #if defined( AES_CTRL_KEYBUFEN )
510  /* Load key into high key for key buffer usage */
511  for (i = 3; i >= 0; i--)
512  {
513  AES->KEYHA = __REV(_key[i]);
514  }
515  #endif
516 
517  /* Encrypt/decrypt data */
518  data = _iv;
519  len /= AES_BLOCKSIZE;
520  while (len--)
521  {
522  #if !defined( AES_CTRL_KEYBUFEN )
523  /* Load key */
524  for (i = 3; i >= 0; i--)
525  {
526  AES->KEYLA = __REV(_key[i]);
527  }
528  #endif
529 
530  /* Load data and trigger encryption */
531  for (i = 3; i >= 0; i--)
532  {
533  AES->DATA = __REV(data[i]);
534  }
535 
536  /* Do some required processing before waiting for completion */
537  if (encrypt)
538  {
539  data = _out;
540  }
541  else
542  {
543  /* Must copy current ciphertext block since it may be overwritten */
544  for (i = 0; i < 4; i++)
545  {
546  tmp[i] = _in[i];
547  }
548  data = tmp;
549  }
550 
551  /* Wait for completion */
552  while (AES->STATUS & AES_STATUS_RUNNING)
553  ;
554 
555  /* Save encrypted/decrypted data */
556  for (i = 3; i >= 0; i--)
557  {
558  _out[i] = __REV(AES->DATA) ^ _in[i];
559  }
560  _out += 4;
561  _in += 4;
562  }
563 }
564 
565 
566 #if defined( AES_CTRL_AES256 )
567 /***************************************************************************/
595 void AES_CFB256(uint8_t *out,
596  const uint8_t *in,
597  unsigned int len,
598  const uint8_t *key,
599  const uint8_t *iv,
600  bool encrypt)
601 {
602  int i;
603  int j;
604  uint32_t *_out = (uint32_t *)out;
605  const uint32_t *_in = (const uint32_t *)in;
606  const uint32_t *_key = (const uint32_t *)key;
607  const uint32_t *_iv = (const uint32_t *)iv;
608  const uint32_t *data;
609  uint32_t tmp[4];
610 
611  EFM_ASSERT(!(len % AES_BLOCKSIZE));
612 
613  /* Select encryption mode */
615 
616  /* Encrypt/decrypt data */
617  data = _iv;
618  len /= AES_BLOCKSIZE;
619  while (len--)
620  {
621  /* Load key and block to be encrypted/decrypted */
622  for (i = 3, j = 7; i >= 0; i--, j--)
623  {
624  AES->KEYLA = __REV(_key[j]);
625  AES->KEYHA = __REV(_key[i]);
626  /* Write data last, since will trigger encryption on last iteration */
627  AES->DATA = __REV(data[i]);
628  }
629 
630  /* Do some required processing before waiting for completion */
631  if (encrypt)
632  {
633  data = _out;
634  }
635  else
636  {
637  /* Must copy current ciphertext block since it may be overwritten */
638  for (i = 0; i < 4; i++)
639  {
640  tmp[i] = _in[i];
641  }
642  data = tmp;
643  }
644 
645  while (AES->STATUS & AES_STATUS_RUNNING)
646  ;
647 
648  /* Save encrypted/decrypted data */
649  for (i = 3; i >= 0; i--)
650  {
651  _out[i] = __REV(AES->DATA) ^ _in[i];
652  }
653  _out += 4;
654  _in += 4;
655  }
656 }
657 #endif
658 
659 
660 /***************************************************************************/
720 void AES_CTR128(uint8_t *out,
721  const uint8_t *in,
722  unsigned int len,
723  const uint8_t *key,
724  uint8_t *ctr,
725  AES_CtrFuncPtr_TypeDef ctrFunc)
726 {
727  int i;
728  uint32_t *_out = (uint32_t *)out;
729  const uint32_t *_in = (const uint32_t *)in;
730  const uint32_t *_key = (const uint32_t *)key;
731  uint32_t *_ctr = (uint32_t *)ctr;
732 
733  EFM_ASSERT(!(len % AES_BLOCKSIZE));
734  EFM_ASSERT(ctrFunc);
735 
736  #if defined( AES_CTRL_KEYBUFEN )
738  #else
739  AES->CTRL = AES_CTRL_DATASTART;
740  #endif
741 
742  #if defined( AES_CTRL_KEYBUFEN )
743  if (key)
744  {
745  /* Load key into high key for key buffer usage */
746  for (i = 3; i >= 0; i--)
747  {
748  AES->KEYHA = __REV(_key[i]);
749  }
750  }
751  #endif
752 
753  /* Encrypt/decrypt data */
754  len /= AES_BLOCKSIZE;
755  while (len--)
756  {
757  #if !defined( AES_CTRL_KEYBUFEN )
758  /* Load key */
759  for (i = 3; i >= 0; i--)
760  {
761  AES->KEYLA = __REV(_key[i]);
762  }
763  #endif
764 
765  /* Load ctr to be encrypted/decrypted */
766  for (i = 3; i >= 0; i--)
767  {
768  AES->DATA = __REV(_ctr[i]);
769  }
770  /* Increment ctr for next use */
771  ctrFunc(ctr);
772 
773  /* Wait for completion */
774  while (AES->STATUS & AES_STATUS_RUNNING)
775  ;
776 
777  /* Save encrypted/decrypted data */
778  for (i = 3; i >= 0; i--)
779  {
780  _out[i] = __REV(AES->DATA) ^ _in[i];
781  }
782  _out += 4;
783  _in += 4;
784  }
785 }
786 
787 
788 #if defined( AES_CTRL_AES256 )
789 /***************************************************************************/
818 void AES_CTR256(uint8_t *out,
819  const uint8_t *in,
820  unsigned int len,
821  const uint8_t *key,
822  uint8_t *ctr,
823  AES_CtrFuncPtr_TypeDef ctrFunc)
824 {
825  int i;
826  int j;
827  uint32_t *_out = (uint32_t *)out;
828  const uint32_t *_in = (const uint32_t *)in;
829  const uint32_t *_key = (const uint32_t *)key;
830  uint32_t *_ctr = (uint32_t *)ctr;
831 
832  EFM_ASSERT(!(len % AES_BLOCKSIZE));
833  EFM_ASSERT(ctrFunc);
834 
835  /* Select encryption mode, with auto trigger */
837 
838  /* Encrypt/decrypt data */
839  len /= AES_BLOCKSIZE;
840  while (len--)
841  {
842  /* Load key and block to be encrypted/decrypted */
843  for (i = 3, j = 7; i >= 0; i--, j--)
844  {
845  AES->KEYLA = __REV(_key[j]);
846  AES->KEYHA = __REV(_key[i]);
847  /* Write data last, since will trigger encryption on last iteration */
848  AES->DATA = __REV(_ctr[i]);
849  }
850  /* Increment ctr for next use */
851  ctrFunc(ctr);
852 
853  /* Wait for completion */
854  while (AES->STATUS & AES_STATUS_RUNNING)
855  ;
856 
857  /* Save encrypted/decrypted data */
858  for (i = 3; i >= 0; i--)
859  {
860  _out[i] = __REV(AES->DATA) ^ _in[i];
861  }
862  _out += 4;
863  _in += 4;
864  }
865 }
866 #endif
867 
868 
869 /***************************************************************************/
883 void AES_CTRUpdate32Bit(uint8_t *ctr)
884 {
885  uint32_t *_ctr = (uint32_t *)ctr;
886 
887  _ctr[3] = __REV(__REV(_ctr[3]) + 1);
888 }
889 
890 
891 /***************************************************************************/
906 void AES_DecryptKey128(uint8_t *out, const uint8_t *in)
907 {
908  int i;
909  uint32_t *_out = (uint32_t *)out;
910  const uint32_t *_in = (const uint32_t *)in;
911 
912  /* Load key */
913  for (i = 3; i >= 0; i--)
914  {
915  AES->KEYLA = __REV(_in[i]);
916  }
917 
918  /* Do dummy encryption to generate decrypt key */
919  AES->CTRL = 0;
921  AES->CMD = AES_CMD_START;
922 
923  /* Wait for completion */
924  while (AES->STATUS & AES_STATUS_RUNNING)
925  ;
926 
927  /* Save decryption key */
928  for (i = 3; i >= 0; i--)
929  {
930  _out[i] = __REV(AES->KEYLA);
931  }
932 }
933 
934 
935 #if defined( AES_CTRL_AES256 )
936 /***************************************************************************/
951 void AES_DecryptKey256(uint8_t *out, const uint8_t *in)
952 {
953  int i;
954  int j;
955  uint32_t *_out = (uint32_t *)out;
956  const uint32_t *_in = (const uint32_t *)in;
957 
958  /* Load key */
959  for (i = 3, j = 7; i >= 0; i--, j--)
960  {
961  AES->KEYLA = __REV(_in[j]);
962  AES->KEYHA = __REV(_in[i]);
963  }
964 
965  /* Do dummy encryption to generate decrypt key */
966  AES->CTRL = AES_CTRL_AES256;
967  AES->CMD = AES_CMD_START;
968 
969  /* Wait for completion */
970  while (AES->STATUS & AES_STATUS_RUNNING)
971  ;
972 
973  /* Save decryption key */
974  for (i = 3, j = 7; i >= 0; i--, j--)
975  {
976  _out[j] = __REV(AES->KEYLA);
977  _out[i] = __REV(AES->KEYHA);
978  }
979 }
980 #endif
981 
982 
983 /***************************************************************************/
1034 void AES_ECB128(uint8_t *out,
1035  const uint8_t *in,
1036  unsigned int len,
1037  const uint8_t *key,
1038  bool encrypt)
1039 {
1040  int i;
1041  uint32_t *_out = (uint32_t *)out;
1042  const uint32_t *_in = (const uint32_t *)in;
1043  const uint32_t *_key = (const uint32_t *)key;
1044 
1045  EFM_ASSERT(!(len % AES_BLOCKSIZE));
1046 
1047  #if defined( AES_CTRL_KEYBUFEN )
1048  /* Load key into high key for key buffer usage */
1049  for (i = 3; i >= 0; i--)
1050  {
1051  AES->KEYHA = __REV(_key[i]);
1052  }
1053  #endif
1054 
1055  if (encrypt)
1056  {
1057  /* Select encryption mode */
1058  #if defined( AES_CTRL_KEYBUFEN )
1060  #else
1061  AES->CTRL = AES_CTRL_DATASTART;
1062  #endif
1063  }
1064  else
1065  {
1066  /* Select decryption mode */
1067  #if defined( AES_CTRL_KEYBUFEN )
1069  #else
1071  #endif
1072  }
1073 
1074  /* Encrypt/decrypt data */
1075  len /= AES_BLOCKSIZE;
1076  while (len--)
1077  {
1078  #if !defined( AES_CTRL_KEYBUFEN )
1079  /* Load key */
1080  for (i = 3; i >= 0; i--)
1081  {
1082  AES->KEYLA = __REV(_key[i]);
1083  }
1084  #endif
1085 
1086  /* Load block to be encrypted/decrypted */
1087  for (i = 3; i >= 0; i--)
1088  {
1089  AES->DATA = __REV(_in[i]);
1090  }
1091  _in += 4;
1092 
1093  /* Wait for completion */
1094  while (AES->STATUS & AES_STATUS_RUNNING)
1095  ;
1096 
1097  /* Save encrypted/decrypted data */
1098  for (i = 3; i >= 0; i--)
1099  {
1100  _out[i] = __REV(AES->DATA);
1101  }
1102  _out += 4;
1103  }
1104 }
1105 
1106 
1107 #if defined( AES_CTRL_AES256 )
1108 /***************************************************************************/
1135 void AES_ECB256(uint8_t *out,
1136  const uint8_t *in,
1137  unsigned int len,
1138  const uint8_t *key,
1139  bool encrypt)
1140 {
1141  int i;
1142  int j;
1143  uint32_t *_out = (uint32_t *)out;
1144  const uint32_t *_in = (const uint32_t *)in;
1145  const uint32_t *_key = (const uint32_t *)key;
1146 
1147  EFM_ASSERT(!(len % AES_BLOCKSIZE));
1148 
1149  if (encrypt)
1150  {
1151  /* Select encryption mode */
1153  }
1154  else
1155  {
1156  /* Select decryption mode */
1158  }
1159 
1160  /* Encrypt/decrypt data */
1161  len /= AES_BLOCKSIZE;
1162  while (len--)
1163  {
1164  /* Load key and block to be encrypted/decrypted */
1165  for (i = 3, j = 7; i >= 0; i--, j--)
1166  {
1167  AES->KEYLA = __REV(_key[j]);
1168  AES->KEYHA = __REV(_key[i]);
1169  /* Write data last, since will trigger encryption on last iteration */
1170  AES->DATA = __REV(_in[i]);
1171  }
1172  _in += 4;
1173 
1174  /* Wait for completion */
1175  while (AES->STATUS & AES_STATUS_RUNNING)
1176  ;
1177 
1178  /* Save encrypted/decrypted data */
1179  for (i = 3; i >= 0; i--)
1180  {
1181  _out[i] = __REV(AES->DATA);
1182  }
1183  _out += 4;
1184  }
1185 }
1186 #endif
1187 
1188 
1189 /***************************************************************************/
1246 void AES_OFB128(uint8_t *out,
1247  const uint8_t *in,
1248  unsigned int len,
1249  const uint8_t *key,
1250  const uint8_t *iv)
1251 {
1252  int i;
1253  uint32_t *_out = (uint32_t *)out;
1254  const uint32_t *_in = (const uint32_t *)in;
1255  const uint32_t *_key = (const uint32_t *)key;
1256  const uint32_t *_iv = (const uint32_t *)iv;
1257 
1258  EFM_ASSERT(!(len % AES_BLOCKSIZE));
1259 
1260  /* Select encryption mode, trigger explicitly by command */
1261  #if defined( AES_CTRL_KEYBUFEN )
1262  AES->CTRL = AES_CTRL_KEYBUFEN;
1263  #else
1264  AES->CTRL = 0;
1265  #endif
1266 
1267  /* Load key into high key for key buffer usage */
1268  /* Load initialization vector */
1269  for (i = 3; i >= 0; i--)
1270  {
1271  #if defined( AES_CTRL_KEYBUFEN )
1272  AES->KEYHA = __REV(_key[i]);
1273  #endif
1274  AES->DATA = __REV(_iv[i]);
1275  }
1276 
1277  /* Encrypt/decrypt data */
1278  len /= AES_BLOCKSIZE;
1279  while (len--)
1280  {
1281  #if !defined( AES_CTRL_KEYBUFEN )
1282  /* Load key */
1283  for (i = 3; i >= 0; i--)
1284  {
1285  AES->KEYLA = __REV(_key[i]);
1286  }
1287  #endif
1288 
1289  AES->CMD = AES_CMD_START;
1290 
1291  /* Wait for completion */
1292  while (AES->STATUS & AES_STATUS_RUNNING)
1293  ;
1294 
1295  /* Save encrypted/decrypted data */
1296  for (i = 3; i >= 0; i--)
1297  {
1298  _out[i] = __REV(AES->DATA) ^ _in[i];
1299  }
1300  _out += 4;
1301  _in += 4;
1302  }
1303 }
1304 
1305 
1306 #if defined( AES_CTRL_AES256 )
1307 /***************************************************************************/
1332 void AES_OFB256(uint8_t *out,
1333  const uint8_t *in,
1334  unsigned int len,
1335  const uint8_t *key,
1336  const uint8_t *iv)
1337 {
1338  int i;
1339  int j;
1340  uint32_t *_out = (uint32_t *)out;
1341  const uint32_t *_in = (const uint32_t *)in;
1342  const uint32_t *_key = (const uint32_t *)key;
1343  const uint32_t *_iv = (const uint32_t *)iv;
1344 
1345  EFM_ASSERT(!(len % AES_BLOCKSIZE));
1346 
1347  /* Select encryption mode, trigger explicitly by command */
1348  AES->CTRL = AES_CTRL_AES256;
1349 
1350  /* Load initialization vector */
1351  for (i = 3; i >= 0; i--)
1352  {
1353  AES->DATA = __REV(_iv[i]);
1354  }
1355 
1356  /* Encrypt/decrypt data */
1357  len /= AES_BLOCKSIZE;
1358  while (len--)
1359  {
1360  /* Load key */
1361  for (i = 3, j = 7; i >= 0; i--, j--)
1362  {
1363  AES->KEYLA = __REV(_key[j]);
1364  AES->KEYHA = __REV(_key[i]);
1365  }
1366 
1367  AES->CMD = AES_CMD_START;
1368 
1369  /* Wait for completion */
1370  while (AES->STATUS & AES_STATUS_RUNNING)
1371  ;
1372 
1373  /* Save encrypted/decrypted data */
1374  for (i = 3; i >= 0; i--)
1375  {
1376  _out[i] = __REV(AES->DATA) ^ _in[i];
1377  }
1378  _out += 4;
1379  _in += 4;
1380  }
1381 }
1382 #endif
1383 
1384 
1387 #endif /* defined(AES_COUNT) && (AES_COUNT > 0) */
void AES_CTRUpdate32Bit(uint8_t *ctr)
Update last 32 bits of 128 bit counter, by incrementing with 1.
Definition: em_aes.c:883
#define AES_CTRL_KEYBUFEN
Definition: efm32lg_aes.h:81
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:906
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.
Definition: em_aes.c:595
__STATIC_INLINE void AES_IntClear(uint32_t flags)
Clear one or more pending AES interrupts.
Definition: em_aes.h:150
#define AES_CMD_START
Definition: efm32lg_aes.h:105
#define AES_IF_DONE
Definition: efm32lg_aes.h:137
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:720
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:1332
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:818
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:1246
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:157
#define AES_CTRL_DATASTART
Definition: efm32lg_aes.h:86
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:322
#define AES_CTRL_DECRYPT
Definition: efm32lg_aes.h:71
void(* AES_CtrFuncPtr_TypeDef)(uint8_t *ctr)
AES counter modification function pointer.
Definition: em_aes.h:66
Advanced encryption standard (AES) accelerator peripheral API.
#define AES
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:951
#define AES_STATUS_RUNNING
Definition: efm32lg_aes.h:119
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:1135
#define AES_CTRL_XORSTART
Definition: efm32lg_aes.h:91
#define AES_CTRL_AES256
Definition: efm32lg_aes.h:76
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:1034
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:486