//***************************************************************************** // //! AES Crypt Function //! //! This function Configures Key,Mode and carries out Encryption/Decryption in //! CPU mode //! \param uiConfig - Configuration Value //! \param uiKeySize - KeySize used.(128,192 or 256 bit) //! \param puiKey1 - Key Used //! \param puiData - Input Data //! \param puiResult - Resultant Output Data //! \param uiDataLength - Input Data Length //! \param uiIV - Initialization Vector used //! //! \return none // //***************************************************************************** void AESCrypt(unsigned int uiConfig,unsigned int uiKeySize,unsigned int *puiKey1, unsigned int *puiData,unsigned int *puiResult, unsigned int uiDataLength,unsigned int *uiIV) { // // Step1: Enable Interrupts // Step2: Wait for Context Ready Inteerupt // Step3: Set the Configuration Parameters (Direction,AES Mode and Key Size) // Step4: Set the Initialization Vector // Step5: Write Key // Step6: Start the Crypt Process // // // Clear the flags. // g_bContextInIntFlag = false; g_bDataInIntFlag = false; g_bContextOutIntFlag = false; g_bDataOutIntFlag = false; // // Enable all interrupts. // MAP_AESIntEnable(AES_BASE, AES_INT_CONTEXT_IN | AES_INT_CONTEXT_OUT | AES_INT_DATA_IN | AES_INT_DATA_OUT); // // Wait for the context in flag, the flag will be set in the Interrupt handler. // while(!g_bContextInIntFlag) { } // // Configure the AES module with direction (encryption or decryption) and // the key size. // MAP_AESConfigSet(AES_BASE, uiConfig |uiKeySize); // // Write the initial value registers if needed, depends on the mode. // if(((uiConfig & AES_CFG_MODE_M) == AES_CFG_MODE_CBC) || ((uiConfig & AES_CFG_MODE_M) == AES_CFG_MODE_CFB) || ((uiConfig & AES_CFG_MODE_M) == AES_CFG_MODE_CTR) || ((uiConfig & AES_CFG_MODE_M) == AES_CFG_MODE_ICM) ) { MAP_AESIVSet(AES_BASE, (unsigned char *)uiIV); } // // Write key1. // MAP_AESKey1Set(AES_BASE,(unsigned char *)puiKey1,uiKeySize); // // Start Crypt Process // MAP_AESDataProcess(AES_BASE, (unsigned char *)puiData, (unsigned char *)puiResult, uiDataLength); }
//***************************************************************************** // //! AES Crypt Function //! //! This function Configures Key,Mode and carries out Encryption/Decryption in //! CPU mode //! \param uiConfig - Configuration Value //! \param uiKeySize - KeySize used.(128,192 or 256 bit) //! \param puiKey1 - Key Used //! \param puiData - Input Data //! \param puiResult - Resultant Output Data //! \param uiDataLength - Input Data Length //! \param uiIV - Initialization Vector used //! //! \return none // //***************************************************************************** void AESCrypt(unsigned int uiConfig,unsigned int uiKeySize,unsigned int *puiKey1,unsigned int *puiData, unsigned int *puiResult,unsigned int uiDataLength,unsigned int *uiIV) { // // Step1: Reset the Module // Step2: Enable Interrupts // Step3: Wait for Context Ready Inteerupt // Step4: Set the Configuration Parameters (Direction,AES Mode and Key Size) // Step5: Set the Initialization Vector // Step6: Write Key // Step7: Start the Crypt Process // MAP_PRCMPeripheralReset(PRCM_DTHE); // // Clear the flags. // g_bContextInIntFlag = false; g_bDataInIntFlag = false; g_bContextOutIntFlag = false; g_bDataOutIntFlag = false; // // Enable all interrupts. // MAP_AESIntEnable(AES_BASE, AES_INT_CONTEXT_IN | AES_INT_CONTEXT_OUT | AES_INT_DATA_IN | AES_INT_DATA_OUT); // // Wait for the context in flag, the flag will be set in the Interrupt handler. // while(!g_bContextInIntFlag) { } // // Configure the AES module with direction (encryption or decryption) and the key size. // MAP_AESConfigSet(AES_BASE, uiConfig | uiKeySize); // // Write the initial value registers if needed, depends on the mode. // if(((uiConfig & AES_CFG_MODE_M) == AES_CFG_MODE_CBC) || ((uiConfig & AES_CFG_MODE_M) == AES_CFG_MODE_CFB) || ((uiConfig & AES_CFG_MODE_M) == AES_CFG_MODE_CTR) || ((uiConfig & AES_CFG_MODE_M) == AES_CFG_MODE_ICM) ) { MAP_AESIVSet(AES_BASE, (unsigned char *)uiIV); } // // Write key1. // //char key[] = "no-preshared-key"; MAP_AESKey1Set(AES_BASE,(unsigned char *)puiKey1, uiKeySize); // // Start Crypt Process // //if (uiConfig == 4) //{ // unsigned char puiBuff[100] = {0x3A, 0xC1, 0xFE, 0x31, 0x71, 0x16, 0x09, 0x6C, 0x61, 0xF8, 0x91, 0xA1, 0x7A, 0xCA, 0xA2, 0x8F, 0xCC, 0xE2, 0x2A, 0x71, 0x20, 0x0C, 0x6E, 0xB9, 0x58, 0x82, 0xB5, 0xA1, 0x8E, 0xEC, 0xDC, 0xB5, 0x0E, 0x4F, 0x6C, 0x6A, 0x6A, 0xD4, 0x52, 0xFF, 0x86, 0xFA, 0x2B, 0xAD, 0x11, 0x4B, 0xA7, 0x41, 0x2F, 0x1B, 0xFB, 0x97, 0xB0, 0x1E, 0x06, 0x35, 0xA9, 0x07, 0x3C, 0x9B, 0xBE, 0xA1, 0x4E, 0x58}; //MQTT_payload_string(puiBuff); //} //else //{ // unsigned char puiBuff[100] = {0x88, 0xEC, 0x18, 0x67, 0x4A, 0x63, 0x62, 0x84, 0xE6, 0xBF, 0xAF, 0xC9, 0x56, 0x77, 0x8C, 0xE8, 0xCC, 0xE2, 0x2A, 0x71, 0x20, 0x0C, 0x6E, 0xB9, 0x58, 0x82, 0xB5, 0xA1, 0x8E, 0xEC, 0xDC, 0xB5, 0x0E, 0x4F, 0x6C, 0x6A, 0x6A, 0xD4, 0x52, 0xFF, 0x86, 0xFA, 0x2B, 0xAD, 0x11, 0x4B, 0xA7, 0x41, 0xA4, 0x02, 0xB7, 0x8D, 0x75, 0x6A, 0x96, 0x8F, 0xA9, 0xC4, 0x9F, 0xAD, 0x6F, 0xE9, 0x6A, 0x25}; //} // unsigned char resBuff[100]; MAP_AESDataProcess(AES_BASE, (unsigned char *)puiData, (unsigned char *)puiResult, uiDataLength); }