void
main()
{
unsigned int uiConfig,uiDataLength;
unsigned char *puiKey1,*puiData,*puiResult, *puiIV,
uiIV[8]={0x6d, 0x8e, 0xca, 0xc4, 0x3b, 0x27, 0xc8, 0x85};
#ifdef USER_INPUT
unsigned int uiKeySize;
unsigned int ui32CharCount;
unsigned char * pui8Result;
#endif
puiIV=&uiIV[0];
//
// Initialize the board
//
BoardInit();
//
// Configuring UART for Receiving input and displaying output
// 1. PinMux setting
// 2. Initialize UART
// 3. Displaying Banner
//
PinMuxConfig();
InitTerm();
DisplayBanner(APP_NAME);
//
// Enable DES Module
//
MAP_PRCMPeripheralClkEnable(PRCM_DTHE, PRCM_RUN_MODE_CLK);
//
// Enable interrupts.
//
MAP_DESIntRegister(DES_BASE, DESIntHandler);
//
// Read values either from User or from Vector based on macro USER_INPUT
// defined or not
//
#ifdef USER_INPUT
while(FOREVER)
{
//
// Read the values from the user over uart and Populate the variables
//
puiData=ReadFromUser(&uiConfig,&uiKeySize,&puiKey1,&uiDataLength,
&puiResult);
if(puiData==NULL)
{
continue;
}
#else
UART_PRINT("Running DES-ECB Vectors\n\r");
//
// Load Default values
//
puiData=LoadDefaultValues(DES_CFG_DIR_ENCRYPT | DES_CFG_MODE_ECB |
DES_CFG_SINGLE,&uiConfig,&puiIV,&puiKey1,&uiDataLength,&puiResult);
#endif
//
// Carry out Encryption
//
UART_PRINT("\n\r Encryption in progress....");
DESCrypt(uiConfig,puiKey1,puiData,puiResult,uiDataLength,puiIV);
UART_PRINT("\n\r Encryption done, cipher text created");
//
// Copy Result into Data Vector to continue with Decryption. and change
// config value
//
memcpy(puiData,puiResult,uiDataLength);
uiConfig &= ~(1 << 2);
//
// Carry out Decrypt Function
//
UART_PRINT("\n\r\n\r Decryption in progress....");
DESCrypt(uiConfig,puiKey1,puiData,puiResult,uiDataLength,uiIV);
UART_PRINT("\n\r Decryption done");
#ifdef USER_INPUT
//
// Display Plain Text
//
UART_PRINT("\n\r Text after decryption :");
pui8Result = (unsigned char *)puiResult;
for(ui32CharCount=0;ui32CharCount<uiDataLength;ui32CharCount++)
{
UART_PRINT("%c",*(pui8Result+ui32CharCount));
}
UART_PRINT("\n\r");
}
#else
//
// Comapre Cipher Text and Plain Text with the expected values from
// predefined vector
//
if(memcmp(puiData,psDESTestVectors.pui32CipherText,
psDESTestVectors.ui32DataLength)==0)
{
UART_PRINT("\n\r\n\r Encryption verified");
}
if(memcmp(puiResult,psDESTestVectors.pui32PlainText,
psDESTestVectors.ui32DataLength)==0)
{
UART_PRINT("\n\r Decryption verification successful");
}
while(FOREVER);
#endif
} |