void
main()
{
unsigned int uiConfig,uiKeySize,*puiKey1,*puiData,*puiResult,
uiDataLength,uiIV[4]={0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c};
#ifdef USER_INPUT
unsigned int ui32CharCount;
unsigned char* pui8Result;
#else
unsigned int *puiIV;
puiIV=&uiIV[0];
#endif
BoardInit();
//
// Configuring UART for Receiving input and displaying output
// 1. PinMux setting
// 2. Initialize UART
// 3. Displaying Banner
//
PinMuxConfig();
InitTerm();
DisplayBanner(APP_NAME);
//
// Enable AES Module
//
MAP_PRCMPeripheralClkEnable(PRCM_DTHE, PRCM_RUN_MODE_CLK);
//
// Enable AES interrupts.
//
MAP_AESIntRegister(AES_BASE, AESIntHandler);
#ifdef USER_INPUT
while(FOREVER)
{
//
// Read values either from User or from Vector based on macro USER_INPUT
// defined or not
//
//
// Read the values from the user over uart and Populate the variables
//
puiData = ReadFromUser(&uiConfig,&uiKeySize,&puiKey1,&uiDataLength,\
&puiResult);
if(puiData==NULL)
{
UART_PRINT("\n\rInvalid Input. Please try again. \n\r");
continue;
}
#else
//
// Load Default values
//
puiData = LoadDefaultValues(AES_CFG_DIR_ENCRYPT | AES_CFG_MODE_CBC ,
&uiConfig,&uiKeySize,&puiIV,&puiKey1,
&uiDataLength,&puiResult);
#endif
//
// Carry out Encryption
//
UART_PRINT("\n\r Encryption in progress....");
AESCrypt(uiConfig,uiKeySize,puiKey1,puiData,puiResult,uiDataLength,uiIV);
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 Decryption
//
UART_PRINT("\n\r\n\r Decryption in progress....");
AESCrypt(uiConfig,uiKeySize,puiKey1,puiData,puiResult,uiDataLength,uiIV);
UART_PRINT("\n\r Decryption done");
//
// Display/Verify Result
//
#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
//
// Compare Cipher Text and Plain Text with the expected values from
// predefined vector
//
if(memcmp(puiData,psAESCBCTestVectors.pui32CipherText,
psAESCBCTestVectors.ui32DataLength)==0)
{
UART_PRINT("\n\r\n\r Encryption verification Successful");
}
else
{
UART_PRINT("\n\r\n\r Error in Encryption");
}
if(memcmp(puiResult,psAESCBCTestVectors.pui32PlainText,
psAESCBCTestVectors.ui32DataLength)==0)
{
UART_PRINT("\n\r Decryption verification Successful");
}
else
{
UART_PRINT("\n\r\n\r Error in Decryption");
}
while(FOREVER);
#endif
} |
感谢分享