Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
44 #if (SAMA5D3_CRYPTO_CIPHER_SUPPORT == ENABLED)
58 p = (uint32_t *) input;
59 TDES->TDES_IDATAR[0] =
p[0];
60 TDES->TDES_IDATAR[1] =
p[1];
63 TDES->TDES_CR = TDES_CR_START;
66 while((TDES->TDES_ISR & TDES_ISR_DATRDY) == 0)
71 p = (uint32_t *) output;
72 p[0] = TDES->TDES_ODATAR[0];
73 p[1] = TDES->TDES_ODATAR[1];
77 #if (DES_SUPPORT == ENABLED)
90 uint8_t *output,
size_t length, uint32_t mode)
98 TDES->TDES_CR = TDES_CR_SWRST;
101 TDES->TDES_MR = TDES_MR_SMOD_MANUAL_START | TDES_MR_TDESMOD(0) | mode;
104 TDES->TDES_KEY1WR[0] = context->
ks[0];
105 TDES->TDES_KEY1WR[1] = context->
ks[1];
112 TDES->TDES_IVR[0] =
p[0];
113 TDES->TDES_IVR[1] =
p[1];
160 if(context == NULL || key == NULL)
186 TDES_MR_CIPHER | TDES_MR_OPMOD_ECB);
205 #if (DES3_SUPPORT == ENABLED)
218 uint8_t *output,
size_t length, uint32_t mode)
226 TDES->TDES_CR = TDES_CR_SWRST;
229 TDES->TDES_MR = TDES_MR_SMOD_MANUAL_START | TDES_MR_TDESMOD(1) | mode;
232 TDES->TDES_KEY1WR[0] = context->
k1.
ks[0];
233 TDES->TDES_KEY1WR[1] = context->
k1.
ks[1];
234 TDES->TDES_KEY2WR[0] = context->
k2.
ks[0];
235 TDES->TDES_KEY2WR[1] = context->
k2.
ks[1];
236 TDES->TDES_KEY3WR[0] = context->
k3.
ks[0];
237 TDES->TDES_KEY3WR[1] = context->
k3.
ks[1];
244 TDES->TDES_IVR[0] =
p[0];
245 TDES->TDES_IVR[1] =
p[1];
292 if(context == NULL || key == NULL)
304 else if(keyLen == 16)
313 else if(keyLen == 24)
343 TDES_MR_CIPHER | TDES_MR_OPMOD_ECB);
362 #if (AES_SUPPORT == ENABLED)
374 temp = AES->AES_MR & ~AES_MR_KEYSIZE_Msk;
377 if(context->
nr == 10)
380 AES->AES_MR = temp | AES_MR_KEYSIZE_AES128;
383 AES->AES_KEYWR[0] = context->
ek[0];
384 AES->AES_KEYWR[1] = context->
ek[1];
385 AES->AES_KEYWR[2] = context->
ek[2];
386 AES->AES_KEYWR[3] = context->
ek[3];
388 else if(context->
nr == 12)
391 AES->AES_MR = temp | AES_MR_KEYSIZE_AES192;
394 AES->AES_KEYWR[0] = context->
ek[0];
395 AES->AES_KEYWR[1] = context->
ek[1];
396 AES->AES_KEYWR[2] = context->
ek[2];
397 AES->AES_KEYWR[3] = context->
ek[3];
398 AES->AES_KEYWR[4] = context->
ek[4];
399 AES->AES_KEYWR[5] = context->
ek[5];
404 AES->AES_MR = temp | AES_MR_KEYSIZE_AES256;
407 AES->AES_KEYWR[0] = context->
ek[0];
408 AES->AES_KEYWR[1] = context->
ek[1];
409 AES->AES_KEYWR[2] = context->
ek[2];
410 AES->AES_KEYWR[3] = context->
ek[3];
411 AES->AES_KEYWR[4] = context->
ek[4];
412 AES->AES_KEYWR[5] = context->
ek[5];
413 AES->AES_KEYWR[6] = context->
ek[6];
414 AES->AES_KEYWR[7] = context->
ek[7];
430 p = (uint32_t *) input;
431 AES->AES_IDATAR[0] =
p[0];
432 AES->AES_IDATAR[1] =
p[1];
433 AES->AES_IDATAR[2] =
p[2];
434 AES->AES_IDATAR[3] =
p[3];
437 AES->AES_CR = AES_CR_START;
440 while((AES->AES_ISR & AES_ISR_DATRDY) == 0)
445 p = (uint32_t *) output;
446 p[0] = AES->AES_ODATAR[0];
447 p[1] = AES->AES_ODATAR[1];
448 p[2] = AES->AES_ODATAR[2];
449 p[3] = AES->AES_ODATAR[3];
464 uint8_t *output,
size_t length, uint32_t mode)
472 AES->AES_CR = AES_CR_SWRST;
475 AES->AES_MR = AES_MR_SMOD_MANUAL_START | mode;
484 AES->AES_IVR[0] =
p[0];
485 AES->AES_IVR[1] =
p[1];
486 AES->AES_IVR[2] =
p[2];
487 AES->AES_IVR[3] =
p[3];
534 if(context == NULL || key == NULL)
543 else if(keyLen == 24)
548 else if(keyLen == 32)
597 #if (ECB_SUPPORT == ENABLED)
610 const uint8_t *
p, uint8_t *
c,
size_t length)
617 #if (DES_SUPPORT == ENABLED)
640 #if (DES3_SUPPORT == ENABLED)
663 #if (AES_SUPPORT == ENABLED)
723 const uint8_t *
c, uint8_t *
p,
size_t length)
730 #if (DES_SUPPORT == ENABLED)
752 #if (DES3_SUPPORT == ENABLED)
774 #if (AES_SUPPORT == ENABLED)
822 #if (CBC_SUPPORT == ENABLED)
836 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
843 #if (DES_SUPPORT == ENABLED)
869 #if (DES3_SUPPORT == ENABLED)
895 #if (AES_SUPPORT == ENABLED)
971 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
978 #if (DES_SUPPORT == ENABLED)
1008 #if (DES3_SUPPORT == ENABLED)
1038 #if (AES_SUPPORT == ENABLED)
1109 #if (CFB_SUPPORT == ENABLED)
1124 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
1131 #if (DES_SUPPORT == ENABLED)
1143 TDES_MR_OPMOD_CFB | TDES_MR_CFBS_SIZE_64BIT);
1158 #if (DES3_SUPPORT == ENABLED)
1170 TDES_MR_OPMOD_CFB | TDES_MR_CFBS_SIZE_64BIT);
1185 #if (AES_SUPPORT == ENABLED)
1197 AES_MR_OPMOD_CFB | AES_MR_CFBS_SIZE_128BIT);
1215 if((
s % 8) == 0 &&
s >= 1 &&
s <= (cipher->
blockSize * 8))
1234 for(i = 0; i <
n; i++)
1274 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
1281 #if (DES_SUPPORT == ENABLED)
1293 TDES_MR_CFBS_SIZE_64BIT);
1308 #if (DES3_SUPPORT == ENABLED)
1320 TDES_MR_CFBS_SIZE_64BIT);
1335 #if (AES_SUPPORT == ENABLED)
1347 AES_MR_CFBS_SIZE_128BIT);
1365 if((
s % 8) == 0 &&
s >= 1 &&
s <= (cipher->
blockSize * 8))
1388 for(i = 0; i <
n; i++)
1411 #if (OFB_SUPPORT == ENABLED)
1426 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
1433 #if (DES_SUPPORT == ENABLED)
1460 #if (DES3_SUPPORT == ENABLED)
1487 #if (AES_SUPPORT == ENABLED)
1517 if((
s % 8) == 0 &&
s >= 1 &&
s <= (cipher->
blockSize * 8))
1536 for(i = 0; i <
n; i++)
CipherAlgoDecryptBlock decryptBlock
void aesLoadKey(AesContext *context)
Load AES key.
void des3EncryptBlock(Des3Context *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using Triple DES algorithm.
Collection of AEAD algorithms.
void desProcessData(DesContext *context, uint8_t *iv, const uint8_t *input, uint8_t *output, size_t length, uint32_t mode)
Perform DES encryption or decryption.
error_t des3Init(Des3Context *context, const uint8_t *key, size_t keyLen)
Initialize a Triple DES context using the supplied key.
void desProcessDataBlock(const uint8_t *input, uint8_t *output)
Encrypt/decrypt a 16-byte block using DES algorithm.
CipherAlgoEncryptBlock encryptBlock
error_t cbcDecrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CBC decryption.
void aesEncryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using AES algorithm.
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.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
void desEncryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using DES algorithm.
error_t cbcEncrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CBC encryption.
OsMutex sama5d3CryptoMutex
@ ERROR_INVALID_KEY_LENGTH
void des3ProcessData(Des3Context *context, uint8_t *iv, const uint8_t *input, uint8_t *output, size_t length, uint32_t mode)
Perform Triple DES encryption or decryption.
General definitions for cryptographic algorithms.
error_t ecbDecrypt(const CipherAlgo *cipher, void *context, const uint8_t *c, uint8_t *p, size_t length)
ECB decryption.
Block cipher modes of operation.
SAMA5D3 hardware cryptographic accelerator.
error_t ecbEncrypt(const CipherAlgo *cipher, void *context, const uint8_t *p, uint8_t *c, size_t length)
ECB encryption.
Triple DES algorithm context.
void des3DecryptBlock(Des3Context *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using Triple DES algorithm.
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.
void desDecryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using DES algorithm.
void aesDecryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 16-byte block using AES algorithm.
void aesProcessDataBlock(const uint8_t *input, uint8_t *output)
Encrypt/decrypt a 16-byte block using AES algorithm.
error_t aesInit(AesContext *context, const uint8_t *key, size_t keyLen)
Key expansion.
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.
#define osMemset(p, value, length)
SAMA5D3 cipher hardware accelerator.
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.
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.
#define osMemmove(dest, src, length)
error_t desInit(DesContext *context, const uint8_t *key, size_t keyLen)
Initialize a DES context using the supplied key.