SLAA547C July 2013 – July 2021 MSP430FR5739
The following code example shows the encryption and decryption process using 3DES with and without CBC. The key scheduler is set to populate both key schedules. The results of the operations are stored in the original data array.
#include "msp430xxxx.h"
#include "TI_DES.h"
int main( void )
{
des_ctx dc1; // Key schedule structure
unsigned char *cp;
unsigned char data[] = {0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8,
0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a};
unsigned char key[8] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
unsigned char key1[8] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xfe};
unsigned char key2[8] = {0x01,0x23,0x45,0x67,0x89,0xab,0xdc,0xfe};
cp = data;
///First 8 bytes of Data will be Encrypted then Decrypted
TripleDES_ENC( &dc, cp, 1, key, key1, key2); // 3DES Encrypt
TripleDES_DEC( &dc, cp, 1, key, key1, key2); // 3DES Decrypt
/// All 16 Bytes of Data will be Encrypted then Decrypted with CBC
TripleDES_ENC_CBC( &dc, cp, 2, key, key1, key2); // 3DES Encrypt
TripleDES_DEC_CBC( &dc, cp, 2, key, key1, key2); // 3DES Decrypt
return 0;
}