Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
37 #include "driverlib/des.h"
38 #include "driverlib/aes.h"
48 #if (MSP432E4_CRYPTO_CIPHER_SUPPORT == ENABLED)
59 DES->SYSCONFIG |= DES_SYSCONFIG_SOFTRESET;
62 while((DES->SYSSTATUS & DES_SYSSTATUS_RESETDONE) == 0)
67 if((DES->CTRL & DES_CTRL_CONTEXT) != 0)
69 mode |= DES_CTRL_CONTEXT;
77 #if (DES_SUPPORT == ENABLED)
90 uint8_t *output,
size_t length, uint32_t mode)
101 DES->KEY1_L = context->
ks[0];
102 DES->KEY1_H = context->
ks[1];
119 while((DES->CTRL & DES_CTRL_INPUT_READY) == 0)
128 while((DES->CTRL & DES_CTRL_OUTPUT_READY) == 0)
154 while((DES->CTRL & DES_CTRL_INPUT_READY) == 0)
159 DES->DATA_L = buffer[0];
160 DES->DATA_H = buffer[1];
163 while((DES->CTRL & DES_CTRL_OUTPUT_READY) == 0)
168 buffer[0] = DES->DATA_L;
169 buffer[1] = DES->DATA_H;
201 if(context == NULL || key == NULL)
227 DES_CFG_DIR_ENCRYPT | DES_CFG_MODE_ECB);
242 DES_CFG_DIR_DECRYPT | DES_CFG_MODE_ECB);
246 #if (DES3_SUPPORT == ENABLED)
259 uint8_t *output,
size_t length, uint32_t mode)
270 DES->KEY1_L = context->
k1.
ks[0];
271 DES->KEY1_H = context->
k1.
ks[1];
272 DES->KEY2_L = context->
k2.
ks[0];
273 DES->KEY2_H = context->
k2.
ks[1];
274 DES->KEY3_L = context->
k3.
ks[0];
275 DES->KEY3_H = context->
k3.
ks[1];
292 while((DES->CTRL & DES_CTRL_INPUT_READY) == 0)
301 while((DES->CTRL & DES_CTRL_OUTPUT_READY) == 0)
327 while((DES->CTRL & DES_CTRL_INPUT_READY) == 0)
332 DES->DATA_L = buffer[0];
333 DES->DATA_H = buffer[1];
336 while((DES->CTRL & DES_CTRL_OUTPUT_READY) == 0)
341 buffer[0] = DES->DATA_L;
342 buffer[1] = DES->DATA_H;
374 if(context == NULL || key == NULL)
386 else if(keyLen == 16)
395 else if(keyLen == 24)
425 DES_CFG_DIR_ENCRYPT | DES_CFG_MODE_ECB);
440 DES_CFG_DIR_DECRYPT | DES_CFG_MODE_ECB);
444 #if (AES_SUPPORT == ENABLED)
454 AES->SYSCONFIG |= AES_SYSCONFIG_SOFTRESET;
457 while((AES->SYSSTATUS & AES_SYSSTATUS_RESETDONE) == 0)
462 if((AES->CTRL & AES_CTRL_SAVE_CONTEXT) != 0)
464 mode |= AES_CTRL_SAVE_CONTEXT;
482 temp = AES->CTRL & ~AES_CTRL_KEY_SIZE_M;
485 if(context->
nr == 10)
488 AES->CTRL = temp | AES_CTRL_KEY_SIZE_128;
491 AES->KEY1_0 = context->
ek[0];
492 AES->KEY1_1 = context->
ek[1];
493 AES->KEY1_2 = context->
ek[2];
494 AES->KEY1_3 = context->
ek[3];
496 else if(context->
nr == 12)
499 AES->CTRL = temp | AES_CTRL_KEY_SIZE_192;
502 AES->KEY1_0 = context->
ek[0];
503 AES->KEY1_1 = context->
ek[1];
504 AES->KEY1_2 = context->
ek[2];
505 AES->KEY1_3 = context->
ek[3];
506 AES->KEY1_4 = context->
ek[4];
507 AES->KEY1_5 = context->
ek[5];
512 AES->CTRL = temp | AES_CTRL_KEY_SIZE_256;
515 AES->KEY1_0 = context->
ek[0];
516 AES->KEY1_1 = context->
ek[1];
517 AES->KEY1_2 = context->
ek[2];
518 AES->KEY1_3 = context->
ek[3];
519 AES->KEY1_4 = context->
ek[4];
520 AES->KEY1_5 = context->
ek[5];
521 AES->KEY1_6 = context->
ek[6];
522 AES->KEY1_7 = context->
ek[7];
538 uint8_t *output,
size_t length, uint32_t mode)
564 while((AES->CTRL & AES_CTRL_INPUT_READY) == 0)
570 AES->DATA_IN_2 =
LOAD32LE(input + 4);
571 AES->DATA_IN_1 =
LOAD32LE(input + 8);
572 AES->DATA_IN_0 =
LOAD32LE(input + 12);
575 while((AES->CTRL & AES_CTRL_OUTPUT_READY) == 0)
580 temp = AES->DATA_IN_3;
582 temp = AES->DATA_IN_2;
584 temp = AES->DATA_IN_1;
586 temp = AES->DATA_IN_0;
605 while((AES->CTRL & AES_CTRL_INPUT_READY) == 0)
610 AES->DATA_IN_3 = buffer[0];
611 AES->DATA_IN_2 = buffer[1];
612 AES->DATA_IN_1 = buffer[2];
613 AES->DATA_IN_0 = buffer[3];
616 while((AES->CTRL & AES_CTRL_OUTPUT_READY) == 0)
621 buffer[0] = AES->DATA_IN_3;
622 buffer[1] = AES->DATA_IN_2;
623 buffer[2] = AES->DATA_IN_1;
624 buffer[3] = AES->DATA_IN_0;
660 if(context == NULL || key == NULL)
669 else if(keyLen == 24)
674 else if(keyLen == 32)
704 AES_CFG_DIR_ENCRYPT | AES_CFG_MODE_ECB);
719 AES_CFG_DIR_DECRYPT | AES_CFG_MODE_ECB);
723 #if (ECB_SUPPORT == ENABLED)
736 const uint8_t *
p, uint8_t *
c,
size_t length)
743 #if (DES_SUPPORT == ENABLED)
766 #if (DES3_SUPPORT == ENABLED)
789 #if (AES_SUPPORT == ENABLED)
849 const uint8_t *
c, uint8_t *
p,
size_t length)
856 #if (DES_SUPPORT == ENABLED)
879 #if (DES3_SUPPORT == ENABLED)
902 #if (AES_SUPPORT == ENABLED)
951 #if (CBC_SUPPORT == ENABLED)
965 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
972 #if (DES_SUPPORT == ENABLED)
995 #if (DES3_SUPPORT == ENABLED)
1018 #if (AES_SUPPORT == ENABLED)
1051 c[i] =
p[i] ^
iv[i];
1091 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
1098 #if (DES_SUPPORT == ENABLED)
1121 #if (DES3_SUPPORT == ENABLED)
1144 #if (AES_SUPPORT == ENABLED)
1208 #if (CFB_SUPPORT == ENABLED)
1223 uint8_t *
iv,
const uint8_t *
p, uint8_t *
c,
size_t length)
1230 #if (DES_SUPPORT == ENABLED)
1257 #if (DES3_SUPPORT == ENABLED)
1284 #if (AES_SUPPORT == ENABLED)
1314 if((
s % 8) == 0 &&
s >= 1 &&
s <= (cipher->
blockSize * 8))
1333 for(i = 0; i <
n; i++)
1373 uint8_t *
iv,
const uint8_t *
c, uint8_t *
p,
size_t length)
1380 #if (DES_SUPPORT == ENABLED)
1407 #if (DES3_SUPPORT == ENABLED)
1434 #if (AES_SUPPORT == ENABLED)
1464 if((
s % 8) == 0 &&
s >= 1 &&
s <= (cipher->
blockSize * 8))
1487 for(i = 0; i <
n; i++)
1510 #if (CTR_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
1525 uint8_t *
t,
const uint8_t *
p, uint8_t *
c,
size_t length)
1559 AES_CFG_MODE_CTR | AES_CFG_CTR_WIDTH_128);
1586 for(i = 0; i <
n; i++)
1612 #if (GCM_SUPPORT == ENABLED && AES_SUPPORT == ENABLED)
1628 const uint8_t *
a,
size_t aLen,
const uint8_t *input, uint8_t *output,
1629 size_t length, uint8_t *
t, uint32_t mode)
1638 if(aLen > 0 ||
length > 0)
1653 AES->C_LENGTH_0 =
length;
1654 AES->C_LENGTH_1 = 0;
1657 AES->AUTH_LENGTH = aLen;
1663 while((AES->CTRL & AES_CTRL_INPUT_READY) == 0)
1686 while((AES->CTRL & AES_CTRL_INPUT_READY) == 0)
1691 AES->DATA_IN_3 = buffer[0];
1692 AES->DATA_IN_2 = buffer[1];
1693 AES->DATA_IN_1 = buffer[2];
1694 AES->DATA_IN_0 = buffer[3];
1701 while((AES->CTRL & AES_CTRL_INPUT_READY) == 0)
1707 AES->DATA_IN_2 =
LOAD32LE(input + 4);
1708 AES->DATA_IN_1 =
LOAD32LE(input + 8);
1709 AES->DATA_IN_0 =
LOAD32LE(input + 12);
1712 while((AES->CTRL & AES_CTRL_OUTPUT_READY) == 0)
1717 temp = AES->DATA_IN_3;
1719 temp = AES->DATA_IN_2;
1721 temp = AES->DATA_IN_1;
1723 temp = AES->DATA_IN_0;
1740 while((AES->CTRL & AES_CTRL_INPUT_READY) == 0)
1745 AES->DATA_IN_3 = buffer[0];
1746 AES->DATA_IN_2 = buffer[1];
1747 AES->DATA_IN_1 = buffer[2];
1748 AES->DATA_IN_0 = buffer[3];
1751 while((AES->CTRL & AES_CTRL_OUTPUT_READY) == 0)
1756 buffer[0] = AES->DATA_IN_3;
1757 buffer[1] = AES->DATA_IN_2;
1758 buffer[2] = AES->DATA_IN_1;
1759 buffer[3] = AES->DATA_IN_0;
1766 while((AES->CTRL & AES_CTRL_SVCTXTRDY) == 0)
1771 temp = AES->TAG_OUT_0;
1773 temp = AES->TAG_OUT_1;
1775 temp = AES->TAG_OUT_2;
1777 temp = AES->TAG_OUT_3;
1783 aesSetMode(AES_CFG_DIR_ENCRYPT | AES_CFG_MODE_CTR |
1784 AES_CFG_CTR_WIDTH_32);
1797 while((AES->CTRL & AES_CTRL_INPUT_READY) == 0)
1808 while((AES->CTRL & AES_CTRL_OUTPUT_READY) == 0)
1813 temp = AES->DATA_IN_3;
1815 temp = AES->DATA_IN_2;
1817 temp = AES->DATA_IN_1;
1819 temp = AES->DATA_IN_0;
1837 void *cipherContext)
1840 if(context == NULL || cipherContext == NULL)
1872 size_t ivLen,
const uint8_t *
a,
size_t aLen,
const uint8_t *
p,
1873 uint8_t *
c,
size_t length, uint8_t *
t,
size_t tLen)
1875 uint8_t authTag[16];
1886 if(tLen < 4 || tLen > 16)
1891 AES_CFG_DIR_ENCRYPT);
1917 size_t ivLen,
const uint8_t *
a,
size_t aLen,
const uint8_t *
c,
1918 uint8_t *
p,
size_t length,
const uint8_t *
t,
size_t tLen)
1922 uint8_t authTag[16];
1933 if(tLen < 4 || tLen > 16)
1938 AES_CFG_DIR_DECRYPT);
1941 for(
mask = 0, i = 0; i < tLen; i++)
1943 mask |= authTag[i] ^
t[i];
void gcmProcessData(AesContext *context, const uint8_t *iv, const uint8_t *a, size_t aLen, const uint8_t *input, uint8_t *output, size_t length, uint8_t *t, uint32_t mode)
Perform AES-GCM encryption or decryption.
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.
CipherAlgoDecryptBlock decryptBlock
void des3DecryptBlock(Des3Context *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using Triple DES algorithm.
void des3EncryptBlock(Des3Context *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using Triple DES algorithm.
error_t ctrEncrypt(const CipherAlgo *cipher, void *context, uint_t m, uint8_t *t, const uint8_t *p, uint8_t *c, size_t length)
CTR encryption.
Collection of AEAD algorithms.
void desEncryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Encrypt 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.
OsMutex msp432e4CryptoMutex
error_t aesInit(AesContext *context, const uint8_t *key, size_t keyLen)
Key expansion.
void aesSetMode(uint32_t mode)
Set AES operation mode.
CipherAlgoEncryptBlock encryptBlock
error_t gcmDecrypt(GcmContext *context, const uint8_t *iv, size_t ivLen, const uint8_t *a, size_t aLen, const uint8_t *c, uint8_t *p, size_t length, const uint8_t *t, size_t tLen)
Authenticated decryption using GCM.
MSP432E4 hardware cryptographic accelerator.
error_t gcmInit(GcmContext *context, const CipherAlgo *cipherAlgo, void *cipherContext)
Initialize GCM context.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
#define osMemcpy(dest, src, length)
error_t ecbEncrypt(const CipherAlgo *cipher, void *context, const uint8_t *p, uint8_t *c, size_t length)
ECB encryption.
@ ERROR_FAILURE
Generic error code.
void aesLoadKey(AesContext *context)
Load AES key.
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.
@ ERROR_INVALID_KEY_LENGTH
General definitions for cryptographic algorithms.
error_t desInit(DesContext *context, const uint8_t *key, size_t keyLen)
Initialize a DES context using the supplied key.
Block cipher modes of operation.
const CipherAlgo * cipherAlgo
Cipher algorithm.
error_t ecbDecrypt(const CipherAlgo *cipher, void *context, const uint8_t *c, uint8_t *p, size_t length)
ECB decryption.
error_t gcmEncrypt(GcmContext *context, const uint8_t *iv, size_t ivLen, const uint8_t *a, size_t aLen, const uint8_t *p, uint8_t *c, size_t length, uint8_t *t, size_t tLen)
Authenticated encryption using GCM.
void desDecryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using DES algorithm.
Triple DES algorithm context.
void desSetMode(uint32_t mode)
Set DES operation mode.
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 osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t des3Init(Des3Context *context, const uint8_t *key, size_t keyLen)
Initialize a Triple DES context using the supplied key.
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.
Common interface for encryption algorithms.
error_t cbcDecrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *c, uint8_t *p, size_t length)
CBC decryption.
MSP432E4 cipher hardware accelerator.
void aesEncryptBlock(AesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 16-byte block using AES algorithm.
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.
#define osMemset(p, value, length)
void * cipherContext
Cipher algorithm context.
error_t cbcEncrypt(const CipherAlgo *cipher, void *context, uint8_t *iv, const uint8_t *p, uint8_t *c, size_t length)
CBC encryption.
void ctrIncBlock(uint8_t *ctr, uint32_t inc, size_t blockSize, size_t m)
Increment counter block.
#define osMemmove(dest, src, length)