sam4l_crypto_cipher.c
Go to the documentation of this file.
1 /**
2  * @file sam4l_crypto_cipher.c
3  * @brief SAM4L cipher hardware accelerator
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "sam4l.h"
36 #include "core/crypto.h"
41 #include "debug.h"
42 
43 //Check crypto library configuration
44 #if (SAM4L_CRYPTO_CIPHER_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
45 
46 
47 /**
48  * @brief Encrypt/decrypt a 16-byte block using AES algorithm
49  * @param[in] input Input block to be encrypted/decrypted
50  * @param[out] output Resulting block
51  **/
52 
53 void aesProcessDataBlock(const uint8_t *input, uint8_t *output)
54 {
55  uint32_t *p;
56 
57  //The IBUFRDY bit is set when the input buffer is ready to receive data
58  while((AESA->AESA_SR & AESA_SR_IBUFRDY) == 0)
59  {
60  }
61 
62  //Write input block
63  p = (uint32_t *) input;
64  AESA->AESA_IDATA = p[0];
65  AESA->AESA_IDATA = p[1];
66  AESA->AESA_IDATA = p[2];
67  AESA->AESA_IDATA = p[3];
68 
69  //The ODATARDY bit is set when the encryption or decryption operation has
70  //completed and the processed data can be read from the output buffer
71  while((AESA->AESA_SR & AESA_SR_ODATARDY) == 0)
72  {
73  }
74 
75  //Read output block
76  p = (uint32_t *) output;
77  p[0] = AESA->AESA_ODATA;
78  p[1] = AESA->AESA_ODATA;
79  p[2] = AESA->AESA_ODATA;
80  p[3] = AESA->AESA_ODATA;
81 }
82 
83 
84 /**
85  * @brief Perform AES encryption or decryption
86  * @param[in] context AES algorithm context
87  * @param[in] iv Initialization vector
88  * @param[in] input Data to be encrypted/decrypted
89  * @param[out] output Data resulting from the encryption/decryption process
90  * @param[in] length Total number of data bytes to be processed
91  * @param[in] mode Operation mode
92  **/
93 
94 void aesProcessData(AesContext *context, uint8_t *iv, const uint8_t *input,
95  uint8_t *output, size_t length, uint32_t mode)
96 {
97  uint32_t *p;
98 
99  //Acquire exclusive access to the AES module
101 
102  //Enable AES module
103  AESA->AESA_CTRL = AESA_CTRL_ENABLE;
104 
105  //Set operation mode
106  AESA->AESA_MODE = AESA_MODE_CTYPE(15) | mode;
107 
108  //Set encryption key
109  AESA->AESA_KEY[0].AESA_KEY = context->ek[0];
110  AESA->AESA_KEY[1].AESA_KEY = context->ek[1];
111  AESA->AESA_KEY[2].AESA_KEY = context->ek[2];
112  AESA->AESA_KEY[3].AESA_KEY = context->ek[3];
113 
114  //Valid initialization vector?
115  if(iv != NULL)
116  {
117  //Set initialization vector
118  p = (uint32_t *) iv;
119  AESA->AESA_INITVECT[0].AESA_INITVECT = p[0];
120  AESA->AESA_INITVECT[1].AESA_INITVECT = p[1];
121  AESA->AESA_INITVECT[2].AESA_INITVECT = p[2];
122  AESA->AESA_INITVECT[3].AESA_INITVECT = p[3];
123 
124  //Notify the module that the next input data block is the beginning
125  //of a new message
126  AESA->AESA_CTRL |= AESA_CTRL_NEWMSG;
127  }
128 
129  //Reset input and output buffer pointers
130  AESA->AESA_DATABUFPTR = 0;
131 
132  //Process data
133  while(length >= AES_BLOCK_SIZE)
134  {
135  //The data is encrypted block by block
136  aesProcessDataBlock(input, output);
137 
138  //Next block
139  input += AES_BLOCK_SIZE;
140  output += AES_BLOCK_SIZE;
142  }
143 
144  //Process final block of data
145  if(length > 0)
146  {
147  uint8_t buffer[AES_BLOCK_SIZE];
148 
149  //Copy input data
150  osMemset(buffer, 0, AES_BLOCK_SIZE);
151  osMemcpy(buffer, input, length);
152 
153  //Encrypt the final block of data
154  aesProcessDataBlock(buffer, buffer);
155 
156  //Copy output data
157  osMemcpy(output, buffer, length);
158  }
159 
160  //Disabled AES module
161  AESA->AESA_CTRL = 0;
162 
163  //Release exclusive access to the AES module
165 }
166 
167 
168 /**
169  * @brief Key expansion
170  * @param[in] context Pointer to the AES context to initialize
171  * @param[in] key Pointer to the key
172  * @param[in] keyLen Length of the key
173  * @return Error code
174  **/
175 
176 error_t aesInit(AesContext *context, const uint8_t *key, size_t keyLen)
177 {
178  //Check parameters
179  if(context == NULL || key == NULL)
181 
182  //192 and 256-bit keys are not supported
183  if(keyLen != 16)
185 
186  //10 rounds are required for 128-bit key
187  context->nr = 10;
188 
189  //Copy the original key
190  context->ek[0] = LOAD32LE(key);
191  context->ek[1] = LOAD32LE(key + 4);
192  context->ek[2] = LOAD32LE(key + 8);
193  context->ek[3] = LOAD32LE(key + 12);
194 
195  //No error to report
196  return NO_ERROR;
197 }
198 
199 
200 /**
201  * @brief Encrypt a 16-byte block using AES algorithm
202  * @param[in] context Pointer to the AES context
203  * @param[in] input Plaintext block to encrypt
204  * @param[out] output Ciphertext block resulting from encryption
205  **/
206 
207 void aesEncryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
208 {
209  //Perform AES encryption
210  aesProcessData(context, NULL, input, output, AES_BLOCK_SIZE,
211  AESA_MODE_ENCRYPT | AESA_MODE_OPMODE_ECB);
212 }
213 
214 
215 /**
216  * @brief Decrypt a 16-byte block using AES algorithm
217  * @param[in] context Pointer to the AES context
218  * @param[in] input Ciphertext block to decrypt
219  * @param[out] output Plaintext block resulting from decryption
220  **/
221 
222 void aesDecryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
223 {
224  //Perform AES decryption
225  aesProcessData(context, NULL, input, output, AES_BLOCK_SIZE,
227 }
228 
229 
230 #if (ECB_SUPPORT == ENABLED)
231 
232 /**
233  * @brief ECB encryption
234  * @param[in] cipher Cipher algorithm
235  * @param[in] context Cipher algorithm context
236  * @param[in] p Plaintext to be encrypted
237  * @param[out] c Ciphertext resulting from the encryption
238  * @param[in] length Total number of data bytes to be encrypted
239  * @return Error code
240  **/
241 
242 error_t ecbEncrypt(const CipherAlgo *cipher, void *context,
243  const uint8_t *p, uint8_t *c, size_t length)
244 {
245  error_t error;
246 
247  //Initialize status code
248  error = NO_ERROR;
249 
250  //AES cipher algorithm?
251  if(cipher == AES_CIPHER_ALGO)
252  {
253  //Check the length of the payload
254  if(length == 0)
255  {
256  //No data to process
257  }
258  else if((length % AES_BLOCK_SIZE) == 0)
259  {
260  //Encrypt payload data
261  aesProcessData(context, NULL, p, c, length, AESA_MODE_ENCRYPT |
263  }
264  else
265  {
266  //The length of the payload must be a multiple of the block size
267  error = ERROR_INVALID_LENGTH;
268  }
269  }
270  else
271  {
272  //ECB mode operates in a block-by-block fashion
273  while(length >= cipher->blockSize)
274  {
275  //Encrypt current block
276  cipher->encryptBlock(context, p, c);
277 
278  //Next block
279  p += cipher->blockSize;
280  c += cipher->blockSize;
281  length -= cipher->blockSize;
282  }
283 
284  //The length of the payload must be a multiple of the block size
285  if(length != 0)
286  {
287  error = ERROR_INVALID_LENGTH;
288  }
289  }
290 
291  //Return status code
292  return error;
293 }
294 
295 
296 /**
297  * @brief ECB decryption
298  * @param[in] cipher Cipher algorithm
299  * @param[in] context Cipher algorithm context
300  * @param[in] c Ciphertext to be decrypted
301  * @param[out] p Plaintext resulting from the decryption
302  * @param[in] length Total number of data bytes to be decrypted
303  * @return Error code
304  **/
305 
306 error_t ecbDecrypt(const CipherAlgo *cipher, void *context,
307  const uint8_t *c, uint8_t *p, size_t length)
308 {
309  error_t error;
310 
311  //Initialize status code
312  error = NO_ERROR;
313 
314  //AES cipher algorithm?
315  if(cipher == AES_CIPHER_ALGO)
316  {
317  //Check the length of the payload
318  if(length == 0)
319  {
320  //No data to process
321  }
322  else if((length % AES_BLOCK_SIZE) == 0)
323  {
324  //Decrypt payload data
325  aesProcessData(context, NULL, c, p, length, AESA_MODE_OPMODE_ECB);
326  }
327  else
328  {
329  //The length of the payload must be a multiple of the block size
330  error = ERROR_INVALID_LENGTH;
331  }
332  }
333  else
334  {
335  //ECB mode operates in a block-by-block fashion
336  while(length >= cipher->blockSize)
337  {
338  //Decrypt current block
339  cipher->decryptBlock(context, c, p);
340 
341  //Next block
342  c += cipher->blockSize;
343  p += cipher->blockSize;
344  length -= cipher->blockSize;
345  }
346 
347  //The length of the payload must be a multiple of the block size
348  if(length != 0)
349  {
350  error = ERROR_INVALID_LENGTH;
351  }
352  }
353 
354  //Return status code
355  return error;
356 }
357 
358 #endif
359 #if (CBC_SUPPORT == ENABLED)
360 
361 /**
362  * @brief CBC encryption
363  * @param[in] cipher Cipher algorithm
364  * @param[in] context Cipher algorithm context
365  * @param[in,out] iv Initialization vector
366  * @param[in] p Plaintext to be encrypted
367  * @param[out] c Ciphertext resulting from the encryption
368  * @param[in] length Total number of data bytes to be encrypted
369  * @return Error code
370  **/
371 
372 error_t cbcEncrypt(const CipherAlgo *cipher, void *context,
373  uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
374 {
375  error_t error;
376 
377  //Initialize status code
378  error = NO_ERROR;
379 
380  //AES cipher algorithm?
381  if(cipher == AES_CIPHER_ALGO)
382  {
383  //Check the length of the payload
384  if(length == 0)
385  {
386  //No data to process
387  }
388  else if((length % AES_BLOCK_SIZE) == 0)
389  {
390  //Encrypt payload data
391  aesProcessData(context, iv, p, c, length, AESA_MODE_ENCRYPT |
393 
394  //Update the value of the initialization vector
396  }
397  else
398  {
399  //The length of the payload must be a multiple of the block size
400  error = ERROR_INVALID_LENGTH;
401  }
402  }
403  else
404  {
405  size_t i;
406 
407  //CBC mode operates in a block-by-block fashion
408  while(length >= cipher->blockSize)
409  {
410  //XOR input block with IV contents
411  for(i = 0; i < cipher->blockSize; i++)
412  {
413  c[i] = p[i] ^ iv[i];
414  }
415 
416  //Encrypt the current block based upon the output of the previous
417  //encryption
418  cipher->encryptBlock(context, c, c);
419 
420  //Update IV with output block contents
421  osMemcpy(iv, c, cipher->blockSize);
422 
423  //Next block
424  p += cipher->blockSize;
425  c += cipher->blockSize;
426  length -= cipher->blockSize;
427  }
428 
429  //The length of the payload must be a multiple of the block size
430  if(length != 0)
431  {
432  error = ERROR_INVALID_LENGTH;
433  }
434  }
435 
436  //Return status code
437  return error;
438 }
439 
440 
441 /**
442  * @brief CBC decryption
443  * @param[in] cipher Cipher algorithm
444  * @param[in] context Cipher algorithm context
445  * @param[in,out] iv Initialization vector
446  * @param[in] c Ciphertext to be decrypted
447  * @param[out] p Plaintext resulting from the decryption
448  * @param[in] length Total number of data bytes to be decrypted
449  * @return Error code
450  **/
451 
452 error_t cbcDecrypt(const CipherAlgo *cipher, void *context,
453  uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
454 {
455  error_t error;
456 
457  //Initialize status code
458  error = NO_ERROR;
459 
460  //AES cipher algorithm?
461  if(cipher == AES_CIPHER_ALGO)
462  {
463  //Check the length of the payload
464  if(length == 0)
465  {
466  //No data to process
467  }
468  else if((length % AES_BLOCK_SIZE) == 0)
469  {
470  uint8_t block[AES_BLOCK_SIZE];
471 
472  //Save the last input block
474 
475  //Decrypt payload data
477 
478  //Update the value of the initialization vector
480  }
481  else
482  {
483  //The length of the payload must be a multiple of the block size
484  error = ERROR_INVALID_LENGTH;
485  }
486  }
487  else
488  {
489  size_t i;
490  uint8_t t[16];
491 
492  //CBC mode operates in a block-by-block fashion
493  while(length >= cipher->blockSize)
494  {
495  //Save input block
496  osMemcpy(t, c, cipher->blockSize);
497 
498  //Decrypt the current block
499  cipher->decryptBlock(context, c, p);
500 
501  //XOR output block with IV contents
502  for(i = 0; i < cipher->blockSize; i++)
503  {
504  p[i] ^= iv[i];
505  }
506 
507  //Update IV with input block contents
508  osMemcpy(iv, t, cipher->blockSize);
509 
510  //Next block
511  c += cipher->blockSize;
512  p += cipher->blockSize;
513  length -= cipher->blockSize;
514  }
515 
516  //The length of the payload must be a multiple of the block size
517  if(length != 0)
518  {
519  error = ERROR_INVALID_LENGTH;
520  }
521  }
522 
523  //Return status code
524  return error;
525 }
526 
527 #endif
528 #if (CFB_SUPPORT == ENABLED)
529 
530 /**
531  * @brief CFB encryption
532  * @param[in] cipher Cipher algorithm
533  * @param[in] context Cipher algorithm context
534  * @param[in] s Size of the plaintext and ciphertext segments
535  * @param[in,out] iv Initialization vector
536  * @param[in] p Plaintext to be encrypted
537  * @param[out] c Ciphertext resulting from the encryption
538  * @param[in] length Total number of data bytes to be encrypted
539  * @return Error code
540  **/
541 
542 error_t cfbEncrypt(const CipherAlgo *cipher, void *context, uint_t s,
543  uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
544 {
545  error_t error;
546 
547  //Initialize status code
548  error = NO_ERROR;
549 
550  //AES cipher algorithm?
551  if(cipher == AES_CIPHER_ALGO)
552  {
553  //Check the value of the parameter
554  if(s == (AES_BLOCK_SIZE * 8))
555  {
556  //Check the length of the payload
557  if(length > 0)
558  {
559  //Encrypt payload data
560  aesProcessData(context, iv, p, c, length, AESA_MODE_ENCRYPT |
562  }
563  else
564  {
565  //No data to process
566  }
567  }
568  else
569  {
570  //The value of the parameter is not valid
571  error = ERROR_INVALID_PARAMETER;
572  }
573  }
574  else
575  {
576  //Check the value of the parameter
577  if((s % 8) == 0 && s >= 1 && s <= (cipher->blockSize * 8))
578  {
579  size_t i;
580  size_t n;
581  uint8_t o[16];
582 
583  //Determine the size, in bytes, of the plaintext and ciphertext segments
584  s = s / 8;
585 
586  //Process each plaintext segment
587  while(length > 0)
588  {
589  //Compute the number of bytes to process at a time
590  n = MIN(length, s);
591 
592  //Compute O(j) = CIPH(I(j))
593  cipher->encryptBlock(context, iv, o);
594 
595  //Compute C(j) = P(j) XOR MSB(O(j))
596  for(i = 0; i < n; i++)
597  {
598  c[i] = p[i] ^ o[i];
599  }
600 
601  //Compute I(j+1) = LSB(I(j)) | C(j)
602  osMemmove(iv, iv + s, cipher->blockSize - s);
603  osMemcpy(iv + cipher->blockSize - s, c, s);
604 
605  //Next block
606  p += n;
607  c += n;
608  length -= n;
609  }
610  }
611  else
612  {
613  //The value of the parameter is not valid
614  error = ERROR_INVALID_PARAMETER;
615  }
616  }
617 
618  //Return status code
619  return error;
620 }
621 
622 
623 /**
624  * @brief CFB decryption
625  * @param[in] cipher Cipher algorithm
626  * @param[in] context Cipher algorithm context
627  * @param[in] s Size of the plaintext and ciphertext segments
628  * @param[in,out] iv Initialization vector
629  * @param[in] c Ciphertext to be decrypted
630  * @param[out] p Plaintext resulting from the decryption
631  * @param[in] length Total number of data bytes to be decrypted
632  * @return Error code
633  **/
634 
635 error_t cfbDecrypt(const CipherAlgo *cipher, void *context, uint_t s,
636  uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
637 {
638  error_t error;
639 
640  //Initialize status code
641  error = NO_ERROR;
642 
643  //AES cipher algorithm?
644  if(cipher == AES_CIPHER_ALGO)
645  {
646  //Check the value of the parameter
647  if(s == (AES_BLOCK_SIZE * 8))
648  {
649  //Check the length of the payload
650  if(length > 0)
651  {
652  //Decrypt payload data
655  }
656  else
657  {
658  //No data to process
659  }
660  }
661  else
662  {
663  //The value of the parameter is not valid
664  error = ERROR_INVALID_PARAMETER;
665  }
666  }
667  else
668  {
669  //Check the value of the parameter
670  if((s % 8) == 0 && s >= 1 && s <= (cipher->blockSize * 8))
671  {
672  size_t i;
673  size_t n;
674  uint8_t o[16];
675 
676  //Determine the size, in bytes, of the plaintext and ciphertext segments
677  s = s / 8;
678 
679  //Process each ciphertext segment
680  while(length > 0)
681  {
682  //Compute the number of bytes to process at a time
683  n = MIN(length, s);
684 
685  //Compute O(j) = CIPH(I(j))
686  cipher->encryptBlock(context, iv, o);
687 
688  //Compute I(j+1) = LSB(I(j)) | C(j)
689  osMemmove(iv, iv + s, cipher->blockSize - s);
690  osMemcpy(iv + cipher->blockSize - s, c, s);
691 
692  //Compute P(j) = C(j) XOR MSB(O(j))
693  for(i = 0; i < n; i++)
694  {
695  p[i] = c[i] ^ o[i];
696  }
697 
698  //Next block
699  c += n;
700  p += n;
701  length -= n;
702  }
703  }
704  else
705  {
706  //The value of the parameter is not valid
707  error = ERROR_INVALID_PARAMETER;
708  }
709  }
710 
711  //Return status code
712  return error;
713 }
714 
715 #endif
716 #if (OFB_SUPPORT == ENABLED)
717 
718 /**
719  * @brief OFB encryption
720  * @param[in] cipher Cipher algorithm
721  * @param[in] context Cipher algorithm context
722  * @param[in] s Size of the plaintext and ciphertext segments
723  * @param[in,out] iv Initialization vector
724  * @param[in] p Plaintext to be encrypted
725  * @param[out] c Ciphertext resulting from the encryption
726  * @param[in] length Total number of data bytes to be encrypted
727  * @return Error code
728  **/
729 
730 error_t ofbEncrypt(const CipherAlgo *cipher, void *context, uint_t s,
731  uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
732 {
733  error_t error;
734 
735  //Initialize status code
736  error = NO_ERROR;
737 
738  //AES cipher algorithm?
739  if(cipher == AES_CIPHER_ALGO)
740  {
741  //Check the value of the parameter
742  if(s == (AES_BLOCK_SIZE * 8))
743  {
744  //Check the length of the payload
745  if(length > 0)
746  {
747  //Encrypt payload data
748  aesProcessData(context, iv, p, c, length, AESA_MODE_ENCRYPT |
750  }
751  else
752  {
753  //No data to process
754  }
755  }
756  else
757  {
758  //The value of the parameter is not valid
759  error = ERROR_INVALID_PARAMETER;
760  }
761  }
762  else
763  {
764  //Check the value of the parameter
765  if((s % 8) == 0 && s >= 1 && s <= (cipher->blockSize * 8))
766  {
767  size_t i;
768  size_t n;
769  uint8_t o[16];
770 
771  //Determine the size, in bytes, of the plaintext and ciphertext segments
772  s = s / 8;
773 
774  //Process each plaintext segment
775  while(length > 0)
776  {
777  //Compute the number of bytes to process at a time
778  n = MIN(length, s);
779 
780  //Compute O(j) = CIPH(I(j))
781  cipher->encryptBlock(context, iv, o);
782 
783  //Compute C(j) = P(j) XOR MSB(O(j))
784  for(i = 0; i < n; i++)
785  {
786  c[i] = p[i] ^ o[i];
787  }
788 
789  //Compute I(j+1) = LSB(I(j)) | O(j)
790  osMemmove(iv, iv + s, cipher->blockSize - s);
791  osMemcpy(iv + cipher->blockSize - s, o, s);
792 
793  //Next block
794  p += n;
795  c += n;
796  length -= n;
797  }
798  }
799  else
800  {
801  //The value of the parameter is not valid
802  error = ERROR_INVALID_PARAMETER;
803  }
804  }
805 
806  //Return status code
807  return error;
808 }
809 
810 #endif
811 #endif
uint16_t block
Definition: tftp_common.h:115
CipherAlgoDecryptBlock decryptBlock
Definition: crypto.h:1077
#define AESA_MODE_OPMODE_OFB
uint8_t p
Definition: ndp.h:300
uint8_t t
Definition: lldp_ext_med.h:212
error_t ofbEncrypt(const CipherAlgo *cipher, void *context, uint_t s, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
OFB encryption.
uint8_t o
Collection of AEAD algorithms.
SAM4L hardware cryptographic accelerator.
size_t blockSize
Definition: crypto.h:1072
error_t cbcDecrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CBC decryption.
OsMutex sam4lCryptoMutex
Definition: sam4l_crypto.c:43
error_t ecbEncrypt(const CipherAlgo *cipher, void *context, const uint8_t *p, uint8_t *c, size_t length)
ECB encryption.
void aesProcessDataBlock(const uint8_t *input, uint8_t *output)
Encrypt/decrypt a 16-byte block using AES algorithm.
CipherAlgoEncryptBlock encryptBlock
Definition: crypto.h:1076
AES algorithm context.
Definition: aes.h:58
#define AES_BLOCK_SIZE
Definition: aes.h:43
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
error_t
Error codes.
Definition: error.h:43
@ ERROR_INVALID_KEY_LENGTH
Definition: error.h:107
@ ERROR_INVALID_LENGTH
Definition: error.h:111
General definitions for cryptographic algorithms.
error_t cbcEncrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CBC encryption.
uint8_t iv[]
Definition: ike.h:1502
Block cipher modes of operation.
SAM4L cipher hardware accelerator.
uint8_t length
Definition: tcp.h:368
#define MIN(a, b)
Definition: os_port.h:63
#define AESA_MODE_OPMODE_ECB
error_t aesInit(AesContext *context, const uint8_t *key, size_t keyLen)
Key expansion.
error_t cfbEncrypt(const CipherAlgo *cipher, void *context, uint_t s, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CFB encryption.
void aesProcessData(AesContext *context, uint8_t *iv, const uint8_t *input, uint8_t *output, size_t length, uint32_t mode)
Perform AES encryption or decryption.
uint_t nr
Definition: aes.h:59
void aesEncryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using AES algorithm.
#define AESA_MODE_CFBS_128BIT
uint8_t n
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
Common interface for encryption algorithms.
Definition: crypto.h:1068
void aesDecryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using AES algorithm.
#define AES_CIPHER_ALGO
Definition: aes.h:45
error_t ecbDecrypt(const CipherAlgo *cipher, void *context, const uint8_t *c, uint8_t *p, size_t length)
ECB decryption.
uint8_t s
Definition: igmp_common.h:234
#define AESA_MODE_OPMODE_CBC
#define LOAD32LE(p)
Definition: cpu_endian.h:203
uint32_t ek[60]
Definition: aes.h:60
unsigned int uint_t
Definition: compiler_port.h:50
#define osMemset(p, value, length)
Definition: os_port.h:135
error_t cfbDecrypt(const CipherAlgo *cipher, void *context, uint_t s, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CFB decryption.
@ NO_ERROR
Success.
Definition: error.h:44
uint8_t c
Definition: ndp.h:514
Debugging facilities.
#define osMemmove(dest, src, length)
Definition: os_port.h:147
#define AESA_MODE_OPMODE_CFB