EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-doc-5.1.2
em_crypto.c
Go to the documentation of this file.
1 /***************************************************************************/
32 #include "em_device.h"
33 
34 #if defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0)
35 
36 #include "em_crypto.h"
37 #include "em_assert.h"
38 
39 /***************************************************************************/
44 /***************************************************************************/
49 /*******************************************************************************
50  ******************************* DEFINES ***********************************
51  ******************************************************************************/
52 
55 #define CRYPTO_INSTRUCTIONS_PER_REG (4)
56 #define CRYPTO_INSTRUCTIONS_MAX (12)
57 #define CRYPTO_INSTRUCTION_REGS (CRYPTO_INSTRUCTIONS_MAX/CRYPTO_INSTRUCTIONS_PER_REG)
58 
59 #define CRYPTO_SHA1_BLOCK_SIZE_IN_BITS (512)
60 #define CRYPTO_SHA1_BLOCK_SIZE_IN_BYTES (CRYPTO_SHA1_BLOCK_SIZE_IN_BITS/8)
61 #define CRYPTO_SHA1_BLOCK_SIZE_IN_32BIT_WORDS (CRYPTO_SHA1_BLOCK_SIZE_IN_BYTES/sizeof(uint32_t))
62 #define CRYPTO_SHA1_DIGEST_SIZE_IN_32BIT_WORDS (CRYPTO_SHA1_DIGEST_SIZE_IN_BYTES/sizeof(uint32_t))
63 
64 #define CRYPTO_SHA256_BLOCK_SIZE_IN_BITS (512)
65 #define CRYPTO_SHA256_BLOCK_SIZE_IN_BYTES (CRYPTO_SHA256_BLOCK_SIZE_IN_BITS/8)
66 #define CRYPTO_SHA256_BLOCK_SIZE_IN_32BIT_WORDS (CRYPTO_SHA256_BLOCK_SIZE_IN_BYTES/sizeof(uint32_t))
67 
68 #define CRYPTO_SHA256_DIGEST_SIZE_IN_32BIT_WORDS (CRYPTO_SHA256_DIGEST_SIZE_IN_BYTES/sizeof(uint32_t))
69 
70 #define PARTIAL_OPERAND_WIDTH_LOG2 (7) /* 2^7 = 128 */
71 #define PARTIAL_OPERAND_WIDTH (1<<PARTIAL_OPERAND_WIDTH_LOG2)
72 #define PARTIAL_OPERAND_WIDTH_MASK (PARTIAL_OPERAND_WIDTH-1)
73 #define PARTIAL_OPERAND_WIDTH_IN_BYTES (PARTIAL_OPERAND_WIDTH/8)
74 #define PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS (PARTIAL_OPERAND_WIDTH_IN_BYTES/sizeof(uint32_t))
75 
76 #define SWAP32(x) (__REV(x))
77 
78 #define CRYPTO_AES_BLOCKSIZE (16)
79 
80 /*******************************************************************************
81  *********************** STATIC FUNCTIONS **********************************
82  ******************************************************************************/
83 
84 static inline void CRYPTO_AES_ProcessLoop(CRYPTO_TypeDef *crypto,
85  uint32_t len,
87  uint32_t * in,
89  uint32_t * out);
90 
91 static void CRYPTO_AES_CBCx(CRYPTO_TypeDef *crypto,
92  uint8_t * out,
93  const uint8_t * in,
94  unsigned int len,
95  const uint8_t * key,
96  const uint8_t * iv,
97  bool encrypt,
98  CRYPTO_KeyWidth_TypeDef keyWidth);
99 
100 static void CRYPTO_AES_CFBx(CRYPTO_TypeDef *crypto,
101  uint8_t * out,
102  const uint8_t * in,
103  unsigned int len,
104  const uint8_t * key,
105  const uint8_t * iv,
106  bool encrypt,
107  CRYPTO_KeyWidth_TypeDef keyWidth);
108 
109 static void CRYPTO_AES_CTRx(CRYPTO_TypeDef *crypto,
110  uint8_t * out,
111  const uint8_t * in,
112  unsigned int len,
113  const uint8_t * key,
114  uint8_t * ctr,
116  CRYPTO_KeyWidth_TypeDef keyWidth);
117 
118 static void CRYPTO_AES_ECBx(CRYPTO_TypeDef *crypto,
119  uint8_t * out,
120  const uint8_t * in,
121  unsigned int len,
122  const uint8_t * key,
123  bool encrypt,
124  CRYPTO_KeyWidth_TypeDef keyWidth);
125 
126 static void CRYPTO_AES_OFBx(CRYPTO_TypeDef *crypto,
127  uint8_t * out,
128  const uint8_t * in,
129  unsigned int len,
130  const uint8_t * key,
131  const uint8_t * iv,
132  CRYPTO_KeyWidth_TypeDef keyWidth);
133 
134 #ifdef USE_VARIABLE_SIZED_DATA_LOADS
135 /***************************************************************************/
147 __STATIC_INLINE
148 void CRYPTO_DataWriteVariableSize(CRYPTO_DataReg_TypeDef dataReg,
149  const CRYPTO_Data_TypeDef val,
150  int valSize)
151 {
152  int i;
153  volatile uint32_t * reg = (volatile uint32_t *) dataReg;
154 
155  if (valSize < 4)
156  {
157  /* Non optimal write of data. */
158  for (i = 0; i < valSize; i++)
159  *reg = *val++;
160  for (; i < 4; i++)
161  *reg = 0;
162  }
163  else
164  {
165  CRYPTO_BurstToCrypto(reg, &val[0]);
166  }
167 }
168 #endif
169 
172 /*******************************************************************************
173  ************************** GLOBAL FUNCTIONS *******************************
174  ******************************************************************************/
175 
176 /***************************************************************************/
191  CRYPTO_ModulusId_TypeDef modulusId)
192 {
193  uint32_t temp = crypto->WAC & (~(_CRYPTO_WAC_MODULUS_MASK | _CRYPTO_WAC_MODOP_MASK));
194 
195  switch (modulusId)
196  {
197  case cryptoModulusBin256:
198  case cryptoModulusBin128:
202 #ifdef _CRYPTO_WAC_MODULUS_ECCBIN233N
207 #endif
208  crypto->WAC = temp | modulusId | CRYPTO_WAC_MODOP_BINARY;
209  break;
210 
214 #ifdef _CRYPTO_WAC_MODULUS_ECCPRIME256P
218 #endif
219  crypto->WAC = temp | modulusId | CRYPTO_WAC_MODOP_REGULAR;
220  break;
221 
222  default:
223  /* Unknown modulus identifier. */
224  EFM_ASSERT(0);
225  }
226 }
227 
228 /***************************************************************************/
246  CRYPTO_KeyWidth_TypeDef keyWidth)
247 {
248  EFM_ASSERT(val);
249 
250  CRYPTO_BurstFromCrypto(&crypto->KEY, &val[0]);
251  if (keyWidth == cryptoKey256Bits)
252  {
253  CRYPTO_BurstFromCrypto(&crypto->KEY, &val[4]);
254  }
255 }
256 
257 /***************************************************************************/
278  const uint8_t * msg,
279  uint64_t msgLen,
280  CRYPTO_SHA1_Digest_TypeDef msgDigest)
281 {
282  uint32_t temp;
283  uint32_t len;
284  int blockLen;
285  uint32_t shaBlock[CRYPTO_SHA1_BLOCK_SIZE_IN_32BIT_WORDS]=
286  {
287  /* Initial value */
288  0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
289  };
290  uint8_t * p8ShaBlock = (uint8_t *) shaBlock;
291 
292  /* Initialize crypto module to do SHA-1. */
293  crypto->CTRL = CRYPTO_CTRL_SHA_SHA1;
294  crypto->SEQCTRL = 0;
295  crypto->SEQCTRLB = 0;
296 
297  /* Set result width of MADD32 operation. */
299 
300  /* Write init value to DDATA1. */
301  CRYPTO_DDataWrite(&crypto->DDATA1, shaBlock);
302 
303  /* Copy data to DDATA0 and select DDATA0 and DDATA1 for SHA operation. */
304  CRYPTO_EXECUTE_2(crypto,
307 
308  len = msgLen;
309 
310  while (len >= CRYPTO_SHA1_BLOCK_SIZE_IN_BYTES)
311  {
312  /* Write block to QDATA1. */
313  CRYPTO_QDataWrite(&crypto->QDATA1BIG, (uint32_t *) msg);
314 
315  /* Execute SHA */
316  CRYPTO_EXECUTE_3(crypto,
320 
321  len -= CRYPTO_SHA1_BLOCK_SIZE_IN_BYTES;
322  msg += CRYPTO_SHA1_BLOCK_SIZE_IN_BYTES;
323  }
324 
325  blockLen = 0;
326 
327  /* Build the last (or second to last) block */
328  for (; len; len--)
329  p8ShaBlock[blockLen++] = *msg++;
330 
331  /* append the '1' bit */
332  p8ShaBlock[blockLen++] = 0x80;
333 
334  /* if the length is currently above 56 bytes we append zeros
335  * then compress. Then we can fall back to padding zeros and length
336  * encoding like normal.
337  */
338  if (blockLen > 56)
339  {
340  while (blockLen < 64)
341  p8ShaBlock[blockLen++] = 0;
342 
343  /* Write block to QDATA1BIG. */
344  CRYPTO_QDataWrite(&crypto->QDATA1BIG, shaBlock);
345 
346  /* Execute SHA */
347  CRYPTO_EXECUTE_3(crypto,
351  blockLen = 0;
352  }
353 
354  /* pad upto 56 bytes of zeroes */
355  while (blockLen < 56)
356  p8ShaBlock[blockLen++] = 0;
357 
358  /* And finally, encode the message length. */
359  {
360  uint64_t msgLenInBits = msgLen << 3;
361  temp = msgLenInBits >> 32;
362  *(uint32_t*)&p8ShaBlock[56] = SWAP32(temp);
363  temp = msgLenInBits & 0xFFFFFFFF;
364  *(uint32_t*)&p8ShaBlock[60] = SWAP32(temp);
365  }
366 
367  /* Write block to QDATA1BIG. */
368  CRYPTO_QDataWrite(&crypto->QDATA1BIG, shaBlock);
369 
370  /* Execute SHA */
371  CRYPTO_EXECUTE_3(crypto,
375 
376  /* Read resulting message digest from DDATA0BIG. */
377  ((uint32_t*)msgDigest)[0] = crypto->DDATA0BIG;
378  ((uint32_t*)msgDigest)[1] = crypto->DDATA0BIG;
379  ((uint32_t*)msgDigest)[2] = crypto->DDATA0BIG;
380  ((uint32_t*)msgDigest)[3] = crypto->DDATA0BIG;
381  ((uint32_t*)msgDigest)[4] = crypto->DDATA0BIG;
382  temp = crypto->DDATA0BIG;
383  temp = crypto->DDATA0BIG;
384  temp = crypto->DDATA0BIG;
385 }
386 
387 /***************************************************************************/
408  const uint8_t * msg,
409  uint64_t msgLen,
411 {
412  uint32_t temp;
413  uint32_t len;
414  int blockLen;
415  uint32_t shaBlock[CRYPTO_SHA256_BLOCK_SIZE_IN_32BIT_WORDS]=
416  {
417  /* Initial value */
418  0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
419  0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
420  };
421  uint8_t * p8ShaBlock = (uint8_t *) shaBlock;
422 
423  /* Initialize crypyo module to do SHA-256 (SHA-2). */
424  crypto->CTRL = CRYPTO_CTRL_SHA_SHA2;
425  crypto->SEQCTRL = 0;
426  crypto->SEQCTRLB = 0;
427 
428  /* Set result width of MADD32 operation. */
430 
431  /* Write init value to DDATA1. */
432  CRYPTO_DDataWrite(&crypto->DDATA1, shaBlock);
433 
434  /* Copy data ot DDATA0 and select DDATA0 and DDATA1 for SHA operation. */
435  CRYPTO_EXECUTE_2(crypto,
438  len = msgLen;
439 
440  while (len >= CRYPTO_SHA256_BLOCK_SIZE_IN_BYTES)
441  {
442  /* Write block to QDATA1BIG. */
443  CRYPTO_QDataWrite(&crypto->QDATA1BIG, (uint32_t *) msg);
444 
445  /* Execute SHA */
446  CRYPTO_EXECUTE_3(crypto,
450 
451  len -= CRYPTO_SHA256_BLOCK_SIZE_IN_BYTES;
452  msg += CRYPTO_SHA256_BLOCK_SIZE_IN_BYTES;
453  }
454 
455  blockLen = 0;
456 
457  /* Build the last (or second to last) block */
458  for (; len; len--)
459  p8ShaBlock[blockLen++] = *msg++;
460 
461  /* append the '1' bit */
462  p8ShaBlock[blockLen++] = 0x80;
463 
464  /* if the length is currently above 56 bytes we append zeros
465  * then compress. Then we can fall back to padding zeros and length
466  * encoding like normal.
467  */
468  if (blockLen > 56)
469  {
470  while (blockLen < 64)
471  p8ShaBlock[blockLen++] = 0;
472 
473  /* Write block to QDATA1BIG. */
474  CRYPTO_QDataWrite(&crypto->QDATA1BIG, shaBlock);
475 
476  /* Execute SHA */
477  CRYPTO_EXECUTE_3(crypto,
481  blockLen = 0;
482  }
483 
484  /* Pad upto 56 bytes of zeroes */
485  while (blockLen < 56)
486  p8ShaBlock[blockLen++] = 0;
487 
488  /* And finally, encode the message length. */
489  {
490  uint64_t msgLenInBits = msgLen << 3;
491  temp = msgLenInBits >> 32;
492  *(uint32_t *)&p8ShaBlock[56] = SWAP32(temp);
493  temp = msgLenInBits & 0xFFFFFFFF;
494  *(uint32_t *)&p8ShaBlock[60] = SWAP32(temp);
495  }
496 
497  /* Write the final block to QDATA1BIG. */
498  CRYPTO_QDataWrite(&crypto->QDATA1BIG, shaBlock);
499 
500  /* Execute SHA */
501  CRYPTO_EXECUTE_3(crypto,
505 
506  /* Read resulting message digest from DDATA0BIG. */
507  CRYPTO_DDataRead(&crypto->DDATA0BIG, (uint32_t *)msgDigest);
508 }
509 
510 /***************************************************************************/
517 __STATIC_INLINE void cryptoBigintZeroize(uint32_t * words32bits,
518  int num32bitWords)
519 {
520  while (num32bitWords--)
521  *words32bits++ = 0;
522 }
523 
524 /***************************************************************************/
531 __STATIC_INLINE void cryptoBigintIncrement(uint32_t * words32bits,
532  int num32bitWords)
533 {
534  int i;
535  for (i=0; i<num32bitWords; i++)
536  if (++words32bits[i] != 0)
537  break;
538  return;
539 }
540 
541 /***************************************************************************/
559  uint32_t * A, int aSize,
560  uint32_t * B, int bSize,
561  uint32_t * R, int rSize)
562 {
563  int i, j;
564 
565  /**************** Initializations ******************/
566 
567 #ifdef USE_VARIABLE_SIZED_DATA_LOADS
568  int numWordsLastOperandA = (aSize&PARTIAL_OPERAND_WIDTH_MASK)>>5;
569  int numPartialOperandsA = numWordsLastOperandA ?
570  (aSize >> PARTIAL_OPERAND_WIDTH_LOG2) + 1 :
571  aSize >> PARTIAL_OPERAND_WIDTH_LOG2;
572  int numWordsLastOperandB = (bSize&PARTIAL_OPERAND_WIDTH_MASK)>>5;
573  int numPartialOperandsB = numWordsLastOperandB ?
574  (bSize >> PARTIAL_OPERAND_WIDTH_LOG2) + 1 :
575  bSize >> PARTIAL_OPERAND_WIDTH_LOG2;
576  int numWordsLastOperandR = (rSize&PARTIAL_OPERAND_WIDTH_MASK)>>5;
577  int numPartialOperandsR = numWordsLastOperandR ?
578  (rSize >> PARTIAL_OPERAND_WIDTH_LOG2) + 1 :
579  rSize >> PARTIAL_OPERAND_WIDTH_LOG2;
580  EFM_ASSERT(numPartialOperandsA + numPartialOperandsB <= numPartialOperandsR);
581 #else
582  int numPartialOperandsA = aSize >> PARTIAL_OPERAND_WIDTH_LOG2;
583  int numPartialOperandsB = bSize >> PARTIAL_OPERAND_WIDTH_LOG2;
584  EFM_ASSERT((aSize & PARTIAL_OPERAND_WIDTH_MASK) == 0);
585  EFM_ASSERT((bSize & PARTIAL_OPERAND_WIDTH_MASK) == 0);
586 #endif
587  EFM_ASSERT(aSize + bSize <= rSize);
588 
589  /* Set R to zero. */
590  cryptoBigintZeroize(R, rSize >> 5);
591 
592  /* Set multiplication width. */
594 
595  /* Setup DMA request signalling in order for MCU to run in parallel with
596  CRYPTO instruction sequence execution, and prepare data loading which
597  can take place immediately when CRYPTO is ready inside the instruction
598  sequence. */
599  crypto->CTRL =
602 
603  CRYPTO_EXECUTE_4(crypto,
604  CRYPTO_CMD_INSTR_CCLR, /* Carry = 0 */
605  CRYPTO_CMD_INSTR_CLR, /* DDATA0 = 0 */
606  /* clear result accumulation register */
609  /*
610  register map:
611  DDATA0: working register
612  DDATA1: B(j)
613  DDATA2: R(i+j+1) and R(i+j), combined with DMA entry for B(j)
614  DDATA3: A(i)
615  */
616 
617  CRYPTO_SEQ_LOAD_10(crypto,
618  /* Temporarily load partial operand B(j) to DATA0. */
619  /* R(i+j+1) is still in DATA1 */
621  /* Move B(j) to DDATA1 */
623 
624  /* Restore previous partial result (now R(i+j)) */
626 
627  /* Load next partial result R(i+j+1) */
629 
630  /* Execute partial multiplication A(i)inDDATA1 * B(j)inDDATA3*/
632 
633  /* Add the result to the previous partial result */
634  /* AND take the previous carry value into account */
635  /* at the right place (bit 128, ADDIC instruction */
638 
639  /* Save the new partial result (lower half) */
642  /* Reset the operand selector for next*/
644  );
645 
646  /**************** End Initializations ******************/
647 
648  for(i=0; i<numPartialOperandsA; i++)
649  {
650  /* Load partial operand #1 A>>(i*PARTIAL_OPERAND_WIDTH) to DDATA1. */
651 #ifdef USE_VARIABLE_SIZED_DATA_LOADS
652  if ( (numWordsLastOperandA != 0) && ( i == numPartialOperandsA-1 ) )
653  CRYPTO_DataWriteVariableSize(&crypto->DATA2,
654  &A[i*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS],
655  numWordsLastOperandA);
656  else
657  CRYPTO_DataWrite(&crypto->DATA2, &A[i*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
658 #else
659  CRYPTO_DataWrite(&crypto->DATA2, &A[i*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
660 #endif
661 
662  /* Load partial result in R>>(i*PARTIAL_OPERAND_WIDTH) to DATA1. */
663 #ifdef USE_VARIABLE_SIZED_DATA_LOADS
664  if ( (numWordsLastOperandR != 0) && ( i == numPartialOperandsR-1 ) )
665  CRYPTO_DataWriteVariableSize(&crypto->DATA1,
666  &R[i*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS],
667  numWordsLastOperandR);
668  else
669  CRYPTO_DataWrite(&crypto->DATA1, &R[i*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
670 #else
671  CRYPTO_DataWrite(&crypto->DATA1, &R[i*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
672 #endif
673 
674  /* Clear carry */
675  crypto->CMD = CRYPTO_CMD_INSTR_CCLR;
676 
677  /* Setup number of sequence iterations and block size. */
679  | (PARTIAL_OPERAND_WIDTH_IN_BYTES * numPartialOperandsB);
680 
681  /* Execute the MULtiply instruction sequence. */
683 
684  for (j=0; j<numPartialOperandsB; j++)
685  {
686  /* Load partial operand 2 B>>(j*`PARTIAL_OPERAND_WIDTH) to DDATA2
687  (via DATA0). */
688 #ifdef USE_VARIABLE_SIZED_DATA_LOADS
689  if ( (numWordsLastOperandB != 0) && ( j == numPartialOperandsB-1 ) )
690  CRYPTO_DataWriteVariableSize(&crypto->DATA0,
691  &B[j*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS],
692  numWordsLastOperandB);
693  else
694  CRYPTO_DataWrite(&crypto->DATA0,
695  &B[j*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
696 #else
697  CRYPTO_DataWrite(&crypto->DATA0,
698  &B[j*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
699 #endif
700 
701  /* Load most significant partial result
702  R>>((i+j+1)*`PARTIAL_OPERAND_WIDTH) into DATA1. */
703 #ifdef USE_VARIABLE_SIZED_DATA_LOADS
704  if ( (numWordsLastOperandR != 0) && ( (i+j+1) == numPartialOperandsR-1 ) )
705  CRYPTO_DataWriteVariableSize(&crypto->DATA1,
706  &R[(i+j+1)*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS],
707  numWordsLastOperandR);
708  else
709  CRYPTO_DataWrite(&crypto->DATA1,
710  &R[(i+j+1)*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
711 #else
712  CRYPTO_DataWrite(&crypto->DATA1,
713  &R[(i+j+1)*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
714 #endif
715  /* Store least significant partial result */
716  CRYPTO_DataRead(&crypto->DATA0,
717  &R[(i+j)*PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
718 
719  } /* for (j=0; j<numPartialOperandsB; j++) */
720 
721  /* Handle carry at the end of the inner loop. */
722  if (CRYPTO_CarryIsSet(crypto))
723  cryptoBigintIncrement(&R[(i+numPartialOperandsB+1)
724  *PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS],
725  (numPartialOperandsA-i-1)
726  *PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS);
727 
728  CRYPTO_DataRead(&crypto->DATA1,
729  &R[(i+numPartialOperandsB)
730  * PARTIAL_OPERAND_WIDTH_IN_32BIT_WORDS]);
731 
732  } /* for (i=0; i<numPartialOperandsA; i++) */
733 }
734 
735 /***************************************************************************/
801  uint8_t * out,
802  const uint8_t * in,
803  unsigned int len,
804  const uint8_t * key,
805  const uint8_t * iv,
806  bool encrypt)
807 {
808  crypto->CTRL = CRYPTO_CTRL_AES_AES128;
809  CRYPTO_AES_CBCx(crypto, out, in, len, key, iv, encrypt, cryptoKey128Bits);
810 }
811 
812 /***************************************************************************/
847  uint8_t * out,
848  const uint8_t * in,
849  unsigned int len,
850  const uint8_t * key,
851  const uint8_t * iv,
852  bool encrypt)
853 {
854  crypto->CTRL = CRYPTO_CTRL_AES_AES256;
855  CRYPTO_AES_CBCx(crypto, out, in, len, key, iv, encrypt, cryptoKey256Bits);
856 }
857 
858 /***************************************************************************/
920  uint8_t * out,
921  const uint8_t * in,
922  unsigned int len,
923  const uint8_t * key,
924  const uint8_t * iv,
925  bool encrypt)
926 {
927  crypto->CTRL = CRYPTO_CTRL_AES_AES128;
928  CRYPTO_AES_CFBx(crypto, out, in, len, key, iv, encrypt, cryptoKey128Bits);
929 }
930 
931 /***************************************************************************/
963  uint8_t * out,
964  const uint8_t * in,
965  unsigned int len,
966  const uint8_t * key,
967  const uint8_t * iv,
968  bool encrypt)
969 {
970  crypto->CTRL = CRYPTO_CTRL_AES_AES256;
971  CRYPTO_AES_CFBx(crypto, out, in, len, key, iv, encrypt, cryptoKey256Bits);
972 }
973 
974 /***************************************************************************/
1039  uint8_t * out,
1040  const uint8_t * in,
1041  unsigned int len,
1042  const uint8_t * key,
1043  uint8_t * ctr,
1045 {
1046  crypto->CTRL = CRYPTO_CTRL_AES_AES128;
1047  CRYPTO_AES_CTRx(crypto, out, in, len, key, ctr, ctrFunc, cryptoKey128Bits);
1048 }
1049 
1050 /***************************************************************************/
1085  uint8_t * out,
1086  const uint8_t * in,
1087  unsigned int len,
1088  const uint8_t * key,
1089  uint8_t * ctr,
1091 {
1092  crypto->CTRL = CRYPTO_CTRL_AES_AES256;
1093  CRYPTO_AES_CTRx(crypto, out, in, len, key, ctr, ctrFunc, cryptoKey256Bits);
1094 }
1095 
1096 /***************************************************************************/
1110 void CRYPTO_AES_CTRUpdate32Bit(uint8_t * ctr)
1111 {
1112  uint32_t * _ctr = (uint32_t *) ctr;
1113 
1114  _ctr[3] = __REV(__REV(_ctr[3]) + 1);
1115 }
1116 
1117 /***************************************************************************/
1136  uint8_t * out,
1137  const uint8_t * in)
1138 {
1139  uint32_t * _out = (uint32_t *) out;
1140  const uint32_t * _in = (const uint32_t *) in;
1141 
1142  /* Setup CRYPTO in AES-128 mode. */
1143  crypto->CTRL = CRYPTO_CTRL_AES_AES128;
1144 
1145  /* Load key */
1146  CRYPTO_BurstToCrypto(&crypto->KEYBUF, &_in[0]);
1147 
1148  /* Do dummy encryption to generate decrypt key */
1149  crypto->CMD = CRYPTO_CMD_INSTR_AESENC;
1150 
1151  /* Save decryption key */
1152  CRYPTO_BurstFromCrypto(&crypto->KEY, &_out[0]);
1153 }
1154 
1155 /***************************************************************************/
1174  uint8_t * out,
1175  const uint8_t * in)
1176 {
1177  uint32_t * _out = (uint32_t *) out;
1178  const uint32_t * _in = (const uint32_t *) in;
1179 
1180  /* Setup CRYPTO in AES-256 mode. */
1181  crypto->CTRL = CRYPTO_CTRL_AES_AES256;
1182 
1183  /* Load key */
1184  CRYPTO_BurstToCrypto(&crypto->KEYBUF, &_in[0]);
1185  CRYPTO_BurstToCrypto(&crypto->KEYBUF, &_in[4]);
1186 
1187  /* Do dummy encryption to generate decrypt key */
1188  crypto->CMD = CRYPTO_CMD_INSTR_AESENC;
1189 
1190  /* Save decryption key */
1191  CRYPTO_BurstFromCrypto(&crypto->KEY, &_out[0]);
1192  CRYPTO_BurstFromCrypto(&crypto->KEY, &_out[4]);
1193 }
1194 
1195 /***************************************************************************/
1251  uint8_t * out,
1252  const uint8_t * in,
1253  unsigned int len,
1254  const uint8_t * key,
1255  bool encrypt)
1256 {
1257  crypto->CTRL = CRYPTO_CTRL_AES_AES128;
1258  CRYPTO_AES_ECBx(crypto, out, in, len, key, encrypt, cryptoKey128Bits);
1259 }
1260 
1261 /***************************************************************************/
1293  uint8_t * out,
1294  const uint8_t * in,
1295  unsigned int len,
1296  const uint8_t * key,
1297  bool encrypt)
1298 {
1299  crypto->CTRL = CRYPTO_CTRL_AES_AES256;
1300  CRYPTO_AES_ECBx(crypto, out, in, len, key, encrypt, cryptoKey256Bits);
1301 }
1302 
1303 /***************************************************************************/
1364  uint8_t * out,
1365  const uint8_t * in,
1366  unsigned int len,
1367  const uint8_t * key,
1368  const uint8_t * iv)
1369 {
1370  crypto->CTRL = CRYPTO_CTRL_AES_AES128;
1371  CRYPTO_AES_OFBx(crypto, out, in, len, key, iv, cryptoKey128Bits);
1372 }
1373 
1374 /***************************************************************************/
1403  uint8_t * out,
1404  const uint8_t * in,
1405  unsigned int len,
1406  const uint8_t * key,
1407  const uint8_t * iv)
1408 {
1409  crypto->CTRL = CRYPTO_CTRL_AES_AES256;
1410  CRYPTO_AES_OFBx(crypto, out, in, len, key, iv, cryptoKey256Bits);
1411 }
1412 
1413 /*******************************************************************************
1414  ************************** LOCAL FUNCTIONS *******************************
1415  ******************************************************************************/
1416 
1417 /***************************************************************************/
1453 static void CRYPTO_AES_CBCx(CRYPTO_TypeDef * crypto,
1454  uint8_t * out,
1455  const uint8_t * in,
1456  unsigned int len,
1457  const uint8_t * key,
1458  const uint8_t * iv,
1459  bool encrypt,
1460  CRYPTO_KeyWidth_TypeDef keyWidth)
1461 {
1462  EFM_ASSERT(!(len % CRYPTO_AES_BLOCKSIZE));
1463 
1464  /* Initialize control registers. */
1465  crypto->WAC = 0;
1466 
1467  CRYPTO_KeyBufWrite(crypto, (uint32_t *)key, keyWidth);
1468 
1469  if (encrypt)
1470  {
1471  CRYPTO_DataWrite(&crypto->DATA0, (uint32_t *)iv);
1472 
1473  crypto->SEQ0 =
1476 
1477  CRYPTO_AES_ProcessLoop(crypto, len,
1478  &crypto->DATA1, (uint32_t *) in,
1479  &crypto->DATA0, (uint32_t *) out);
1480  }
1481  else
1482  {
1483  CRYPTO_DataWrite(&crypto->DATA2, (uint32_t *) iv);
1484 
1485  crypto->SEQ0 =
1490 
1491  crypto->SEQ1 = 0;
1492 
1493  /* The following call is equivalent to the last call in the
1494  'if( encrypt )' branch. However moving this
1495  call outside the conditional scope results in slightly poorer
1496  performance for some compiler optimizations. */
1497  CRYPTO_AES_ProcessLoop(crypto, len,
1498  &crypto->DATA1, (uint32_t *) in,
1499  &crypto->DATA0, (uint32_t *) out);
1500  }
1501 }
1502 
1503 /***************************************************************************/
1537 static void CRYPTO_AES_CFBx(CRYPTO_TypeDef * crypto,
1538  uint8_t * out,
1539  const uint8_t * in,
1540  unsigned int len,
1541  const uint8_t * key,
1542  const uint8_t * iv,
1543  bool encrypt,
1544  CRYPTO_KeyWidth_TypeDef keyWidth)
1545 {
1546  EFM_ASSERT(!(len % CRYPTO_AES_BLOCKSIZE));
1547 
1548  /* Initialize control registers. */
1549  crypto->WAC = 0;
1550 
1551  /* Load Key */
1552  CRYPTO_KeyBufWrite(crypto, (uint32_t *)key, keyWidth);
1553 
1554  /* Load instructions to CRYPTO sequencer. */
1555  if (encrypt)
1556  {
1557  /* Load IV */
1558  CRYPTO_DataWrite(&crypto->DATA0, (uint32_t *)iv);
1559 
1560  crypto->SEQ0 =
1563 
1564  CRYPTO_AES_ProcessLoop(crypto, len,
1565  &crypto->DATA1, (uint32_t *)in,
1566  &crypto->DATA0, (uint32_t *)out
1567  );
1568  }
1569  else
1570  {
1571  /* Load IV */
1572  CRYPTO_DataWrite(&crypto->DATA2, (uint32_t *)iv);
1573 
1574  crypto->SEQ0 =
1579  crypto->SEQ1 = 0;
1580 
1581  CRYPTO_AES_ProcessLoop(crypto, len,
1582  &crypto->DATA1, (uint32_t *)in,
1583  &crypto->DATA0, (uint32_t *)out
1584  );
1585  }
1586 }
1587 
1588 /***************************************************************************/
1625 static void CRYPTO_AES_CTRx(CRYPTO_TypeDef * crypto,
1626  uint8_t * out,
1627  const uint8_t * in,
1628  unsigned int len,
1629  const uint8_t * key,
1630  uint8_t * ctr,
1632  CRYPTO_KeyWidth_TypeDef keyWidth)
1633 {
1634  (void) ctrFunc;
1635 
1636  EFM_ASSERT(!(len % CRYPTO_AES_BLOCKSIZE));
1637 
1638  /* Initialize control registers. */
1640  crypto->WAC = 0;
1641 
1642  CRYPTO_KeyBufWrite(crypto, (uint32_t *)key, keyWidth);
1643 
1644  CRYPTO_DataWrite(&crypto->DATA1, (uint32_t *) ctr);
1645 
1650 
1652 
1653  CRYPTO_AES_ProcessLoop(crypto, len,
1654  &crypto->DATA2, (uint32_t *) in,
1655  &crypto->DATA0, (uint32_t *) out);
1656 
1657  CRYPTO_DataRead(&crypto->DATA1, (uint32_t *) ctr);
1658 }
1659 
1660 /***************************************************************************/
1693 static void CRYPTO_AES_ECBx(CRYPTO_TypeDef * crypto,
1694  uint8_t * out,
1695  const uint8_t * in,
1696  unsigned int len,
1697  const uint8_t * key,
1698  bool encrypt,
1699  CRYPTO_KeyWidth_TypeDef keyWidth)
1700 {
1701  EFM_ASSERT(!(len % CRYPTO_AES_BLOCKSIZE));
1702 
1703  crypto->WAC = 0;
1704 
1705  CRYPTO_KeyBufWrite(crypto, (uint32_t *)key, keyWidth);
1706 
1707  if (encrypt)
1708  {
1709  crypto->SEQ0 =
1712  }
1713  else
1714  {
1715  crypto->SEQ0 =
1718  }
1719 
1720  CRYPTO_AES_ProcessLoop(crypto, len,
1721  &crypto->DATA0, (uint32_t *) in,
1722  &crypto->DATA1, (uint32_t *) out);
1723 }
1724 
1725 /***************************************************************************/
1756 static void CRYPTO_AES_OFBx(CRYPTO_TypeDef * crypto,
1757  uint8_t * out,
1758  const uint8_t * in,
1759  unsigned int len,
1760  const uint8_t * key,
1761  const uint8_t * iv,
1762  CRYPTO_KeyWidth_TypeDef keyWidth)
1763 {
1764  EFM_ASSERT(!(len % CRYPTO_AES_BLOCKSIZE));
1765 
1766  crypto->WAC = 0;
1767 
1768  CRYPTO_KeyBufWrite(crypto, (uint32_t *)key, keyWidth);
1769 
1770  CRYPTO_DataWrite(&crypto->DATA2, (uint32_t *)iv);
1771 
1772  crypto->SEQ0 =
1777  crypto->SEQ1 =
1780 
1781  CRYPTO_AES_ProcessLoop(crypto, len,
1782  &crypto->DATA0, (uint32_t *) in,
1783  &crypto->DATA1, (uint32_t *) out);
1784 }
1785 
1786 /***************************************************************************/
1814 static inline void CRYPTO_AES_ProcessLoop(CRYPTO_TypeDef * crypto,
1815  uint32_t len,
1816  CRYPTO_DataReg_TypeDef inReg,
1817  uint32_t * in,
1818  CRYPTO_DataReg_TypeDef outReg,
1819  uint32_t * out)
1820 {
1821  len /= CRYPTO_AES_BLOCKSIZE;
1822  crypto->SEQCTRL = 16 << _CRYPTO_SEQCTRL_LENGTHA_SHIFT;
1823 
1824  while (len--)
1825  {
1826  /* Load data and trigger encryption */
1827  CRYPTO_DataWrite(inReg, (uint32_t *)in);
1828 
1829  crypto->CMD = CRYPTO_CMD_SEQSTART;
1830 
1831  /* Save encrypted/decrypted data */
1832  CRYPTO_DataRead(outReg, (uint32_t *)out);
1833 
1834  out += 4;
1835  in += 4;
1836  }
1837 }
1838 
1842 #endif /* defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0) */
void CRYPTO_AES_OFB128(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv)
AES Output feedback (OFB) cipher mode encryption/decryption, 128 bit key.
Definition: em_crypto.c:1363
#define CRYPTO_CTRL_DMA1MODE_FULL
#define _CRYPTO_WAC_MODULUS_MASK
__STATIC_INLINE void CRYPTO_InstructionSequenceExecute(CRYPTO_TypeDef *crypto)
Execute the current programmed instruction sequence.
Definition: em_crypto.h:1050
#define CRYPTO_CMD_INSTR_SELDDATA0DDATA1
__IOM uint32_t DATA0
Emlib peripheral API "assert" implementation.
#define CRYPTO_CMD_INSTR_SELDDATA2DDATA3
#define CRYPTO_CMD_INSTR_DATA0TODATA2
void CRYPTO_ModulusSet(CRYPTO_TypeDef *crypto, CRYPTO_ModulusId_TypeDef modType)
Set the modulus type used for wide arithmetic operations.
Definition: em_crypto.c:190
#define CRYPTO_CTRL_AES_AES128
__STATIC_INLINE void CRYPTO_DataRead(CRYPTO_DataReg_TypeDef dataReg, CRYPTO_Data_TypeDef val)
Read 128 bits of data from a DATAX register in the CRYPTO module.
Definition: em_crypto.h:758
__IOM uint32_t DDATA1
void CRYPTO_AES_CTRUpdate32Bit(uint8_t *ctr)
Update last 32 bits of 128 bit counter, by incrementing with 1.
Definition: em_crypto.c:1110
#define CRYPTO_CMD_INSTR_MULO
static void CRYPTO_AES_ECBx(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, bool encrypt, CRYPTO_KeyWidth_TypeDef keyWidth)
Electronic Codebook (ECB) cipher mode encryption/decryption, 128/256 bit key.
Definition: em_crypto.c:1693
__IOM uint32_t SEQ0
#define CRYPTO_WAC_MODOP_REGULAR
__STATIC_INLINE void cryptoBigintIncrement(uint32_t *words32bits, int num32bitWords)
Increment value of 32bit word array by one.
Definition: em_crypto.c:531
#define _CRYPTO_SEQ0_INSTR0_SHIFT
#define CRYPTO_WAC_MODOP_BINARY
void CRYPTO_AES_OFB256(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv)
AES Output feedback (OFB) cipher mode encryption/decryption, 256 bit key.
Definition: em_crypto.c:1402
__STATIC_INLINE bool CRYPTO_CarryIsSet(CRYPTO_TypeDef *crypto)
Quick read access of the Carry bit from arithmetic operations.
Definition: em_crypto.h:915
void CRYPTO_AES_CTR256(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, uint8_t *ctr, CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc)
AES Counter (CTR) cipher mode encryption/decryption, 256 bit key.
Definition: em_crypto.c:1084
uint32_t CRYPTO_Data_TypeDef[CRYPTO_DATA_SIZE_IN_32BIT_WORDS]
Definition: em_crypto.h:423
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
void CRYPTO_AES_CBC128(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
AES Cipher-block chaining (CBC) cipher mode encryption/decryption, 128 bit key.
Definition: em_crypto.c:800
void CRYPTO_AES_CTR128(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, uint8_t *ctr, CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc)
AES Counter (CTR) cipher mode encryption/decryption, 128 bit key.
Definition: em_crypto.c:1038
#define CRYPTO_CMD_INSTR_AESDEC
__IOM uint32_t WAC
#define CRYPTO_CMD_INSTR_SELDDATA1DDATA3
volatile uint32_t * CRYPTO_DataReg_TypeDef
Definition: em_crypto.h:464
__STATIC_INLINE void CRYPTO_ResultWidthSet(CRYPTO_TypeDef *crypto, CRYPTO_ResultWidth_TypeDef resultWidth)
Set the width of the results of the non-modulus instructions.
Definition: em_crypto.h:637
__STATIC_INLINE void CRYPTO_QDataWrite(CRYPTO_QDataReg_TypeDef qdataReg, CRYPTO_QData_TypeDef val)
Write 512 bits of data to a QDATAX register in the CRYPTO module.
Definition: em_crypto.h:814
#define CRYPTO_CMD_INSTR_DATATODMA0
#define _CRYPTO_SEQ0_INSTR1_SHIFT
static void CRYPTO_AES_CBCx(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt, CRYPTO_KeyWidth_TypeDef keyWidth)
Cipher-block chaining (CBC) cipher mode encryption/decryption, 128/256 bit key.
Definition: em_crypto.c:1453
void CRYPTO_AES_DecryptKey128(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in)
Generate 128 bit AES decryption key from 128 bit encryption key. The decryption key is used for some ...
Definition: em_crypto.c:1135
void CRYPTO_SHA_256(CRYPTO_TypeDef *crypto, const uint8_t *msg, uint64_t msgLen, CRYPTO_SHA256_Digest_TypeDef digest)
Perform a SHA-256 hash operation on a message.
Definition: em_crypto.c:407
__IOM uint32_t KEY
void CRYPTO_AES_ECB256(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, bool encrypt)
AES Electronic Codebook (ECB) cipher mode encryption/decryption, 256 bit key.
Definition: em_crypto.c:1292
__IOM uint32_t DDATA0BIG
__STATIC_INLINE void CRYPTO_KeyBufWrite(CRYPTO_TypeDef *crypto, CRYPTO_KeyBuf_TypeDef val, CRYPTO_KeyWidth_TypeDef keyWidth)
Set the key value to be used by the CRYPTO module.
Definition: em_crypto.h:860
#define _CRYPTO_SEQ1_INSTR5_SHIFT
__STATIC_INLINE void CRYPTO_BurstFromCrypto(volatile uint32_t *reg, uint32_t *val)
Read a 128 bit value from a crypto register.
Definition: em_crypto.h:714
__STATIC_INLINE void CRYPTO_DDataRead(CRYPTO_DDataReg_TypeDef ddataReg, CRYPTO_DData_TypeDef val)
Read 256 bits of data from a DDATAX register in the CRYPTO module.
Definition: em_crypto.h:795
#define CRYPTO_CMD_INSTR_DATA1TODATA0
#define CRYPTO_CMD_INSTR_DATA1INC
#define CRYPTO_CMD_INSTR_ADDIC
__IOM uint32_t SEQCTRL
#define CRYPTO_CTRL_SHA_SHA1
void CRYPTO_AES_ECB128(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, bool encrypt)
AES Electronic Codebook (ECB) cipher mode encryption/decryption, 128 bit key.
Definition: em_crypto.c:1250
__IOM uint32_t SEQCTRLB
#define CRYPTO_CMD_INSTR_DDATA1TODDATA0
CRYPTO_KeyWidth_TypeDef
Definition: em_crypto.h:528
#define _CRYPTO_SEQCTRL_LENGTHA_SHIFT
__STATIC_INLINE void CRYPTO_DataWrite(CRYPTO_DataReg_TypeDef dataReg, const CRYPTO_Data_TypeDef val)
Write 128 bits of data to a DATAX register in the CRYPTO module.
Definition: em_crypto.h:740
void CRYPTO_KeyRead(CRYPTO_TypeDef *crypto, CRYPTO_KeyBuf_TypeDef val, CRYPTO_KeyWidth_TypeDef keyWidth)
Read the key value currently used by the CRYPTO module.
Definition: em_crypto.c:244
uint8_t CRYPTO_SHA1_Digest_TypeDef[CRYPTO_SHA1_DIGEST_SIZE_IN_BYTES]
Definition: em_crypto.h:562
#define CRYPTO_WAC_RESULTWIDTH_256BIT
void CRYPTO_Mul(CRYPTO_TypeDef *crypto, uint32_t *A, int aSize, uint32_t *B, int bSize, uint32_t *R, int rSize)
Multiply two big integers.
Definition: em_crypto.c:558
#define CRYPTO_CMD_INSTR_SELDDATA0DDATA2
#define _CRYPTO_SEQ0_INSTR3_SHIFT
#define CRYPTO_CTRL_DMA0RSEL_DATA0
#define CRYPTO_CTRL_AES_AES256
#define CRYPTO_CMD_INSTR_AESENC
#define CRYPTO_CMD_INSTR_DDATA0TODDATA1
__IOM uint32_t CMD
void CRYPTO_AES_CFB128(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
AES Cipher feedback (CFB) cipher mode encryption/decryption, 128 bit key.
Definition: em_crypto.c:919
#define CRYPTO_CMD_INSTR_MADD32
static void CRYPTO_AES_CTRx(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, uint8_t *ctr, CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc, CRYPTO_KeyWidth_TypeDef keyWidth)
Counter (CTR) cipher mode encryption/decryption, 128/256 bit key.
Definition: em_crypto.c:1625
#define CRYPTO_CMD_INSTR_DATA0TODATA1
#define CRYPTO_CMD_INSTR_DATA1TODATA2
#define CRYPTO_CMD_INSTR_DDATA0TODDATA2
Cryptography accelerator peripheral API.
#define CRYPTO_CMD_INSTR_DMA1TODATA
#define CRYPTO_CTRL_DMA0MODE_FULL
#define CRYPTO_CMD_SEQSTART
void(* CRYPTO_AES_CtrFuncPtr_TypeDef)(uint8_t *ctr)
AES counter modification function pointer.
Definition: em_crypto.h:578
__STATIC_INLINE void CRYPTO_BurstToCrypto(volatile uint32_t *reg, const uint32_t *val)
Write a 128 bit value into a crypto register.
Definition: em_crypto.h:682
uint32_t CRYPTO_KeyBuf_TypeDef[CRYPTO_KEYBUF_SIZE_IN_32BIT_WORDS]
Definition: em_crypto.h:457
#define _CRYPTO_WAC_MODOP_MASK
#define _CRYPTO_SEQ1_INSTR4_SHIFT
#define CRYPTO_CTRL_INCWIDTH_INCWIDTH4
#define CRYPTO_CMD_INSTR_DATA0TODATA3
__STATIC_INLINE void CRYPTO_DDataWrite(CRYPTO_DDataReg_TypeDef ddataReg, const CRYPTO_DData_TypeDef val)
Write 256 bits of data to a DDATAX register in the CRYPTO module.
Definition: em_crypto.h:776
__IOM uint32_t KEYBUF
#define CRYPTO_CMD_INSTR_DDATA2TODDATA1
void CRYPTO_AES_CFB256(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
AES Cipher feedback (CFB) cipher mode encryption/decryption, 256 bit key.
Definition: em_crypto.c:962
CRYPTO_ModulusId_TypeDef
Definition: em_crypto.h:481
#define CRYPTO_CTRL_SHA_SHA2
__IOM uint32_t SEQ1
void CRYPTO_AES_DecryptKey256(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in)
Generate 256 bit AES decryption key from 256 bit encryption key. The decryption key is used for some ...
Definition: em_crypto.c:1173
#define CRYPTO_WAC_MULWIDTH_MUL128
static void CRYPTO_AES_CFBx(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt, CRYPTO_KeyWidth_TypeDef keyWidth)
Cipher feedback (CFB) cipher mode encryption/decryption, 128/256 bit key.
Definition: em_crypto.c:1537
#define CRYPTO_CMD_INSTR_SHA
uint8_t CRYPTO_SHA256_Digest_TypeDef[CRYPTO_SHA256_DIGEST_SIZE_IN_BYTES]
Definition: em_crypto.h:565
void CRYPTO_AES_CBC256(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, bool encrypt)
AES Cipher-block chaining (CBC) cipher mode encryption/decryption, 256 bit key.
Definition: em_crypto.c:846
#define CRYPTO_CMD_INSTR_DATA1TODATA0XOR
__IOM uint32_t DATA1
__STATIC_INLINE void cryptoBigintZeroize(uint32_t *words32bits, int num32bitWords)
Set 32bit word array to zero.
Definition: em_crypto.c:517
void CRYPTO_SHA_1(CRYPTO_TypeDef *crypto, const uint8_t *msg, uint64_t msgLen, CRYPTO_SHA1_Digest_TypeDef digest)
Perform a SHA-1 hash operation on a message.
Definition: em_crypto.c:277
__IOM uint32_t QDATA1BIG
#define CRYPTO_CMD_INSTR_CCLR
static void CRYPTO_AES_ProcessLoop(CRYPTO_TypeDef *crypto, uint32_t len, CRYPTO_DataReg_TypeDef inReg, uint32_t *in, CRYPTO_DataReg_TypeDef outReg, uint32_t *out)
Function performs generic AES loop.
Definition: em_crypto.c:1814
__IOM uint32_t CTRL
#define CRYPTO_CTRL_DMA1RSEL_DATA1
#define CRYPTO_CMD_INSTR_CLR
static void CRYPTO_AES_OFBx(CRYPTO_TypeDef *crypto, uint8_t *out, const uint8_t *in, unsigned int len, const uint8_t *key, const uint8_t *iv, CRYPTO_KeyWidth_TypeDef keyWidth)
Output feedback (OFB) cipher mode encryption/decryption, 128/256 bit key.
Definition: em_crypto.c:1756
#define CRYPTO_SEQCTRL_BLOCKSIZE_16BYTES
#define CRYPTO_CMD_INSTR_DMA0TODATA
#define _CRYPTO_SEQ0_INSTR2_SHIFT
#define CRYPTO_CMD_INSTR_DATA2TODATA0XOR
__IOM uint32_t DATA2
#define CRYPTO_CMD_INSTR_DATA2TODATA0