void InitTimer(void) { uint32_t ui32SysClock = ROM_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); printf("Clock=%dMHz\n", ui32SysClock/1000000) ; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, -1); ROM_TimerEnable(TIMER0_BASE, TIMER_A); }
int32_t main(void) { g_ui32SysClock = ROM_SysCtlClockFreqSet(SYSCTL_USE_PLL | SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_CFG_VCO_480, 120000000); // Reset index for FFT data inputIndex = 0; MAP_FPULazyStackingEnable(); MAP_FPUEnable(); // Set up ADC sampling and interrupt configureADC(); while(1); /* main function does not return */ }
//***************************************************************************** // // This example decrypts a block of payload using AES128 in CCM mode. It // does the decryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32Payload[16], pui32Tag[4], ui32Errors, ui32Idx; uint32_t ui32PayloadLength, ui32TagLength; uint32_t ui32NonceLength, ui32AuthDataLength; uint32_t *pui32Nonce, *pui32AuthData, ui32SysClock; uint32_t *pui32Key, *pui32ExpPayload, *pui32CipherText; uint8_t ui8Vector; uint8_t *pui8ExpTag, *pui8Tag; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "aes128-ccm-decrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); GrContextForegroundSet(&sContext, ClrWhite); GrStringDrawCentered(&sContext, "Connect a terminal to", -1, GrContextDpyWidthGet(&sContext) / 2, 60, false); GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1, GrContextDpyWidthGet(&sContext) / 2, 80, false); GrStringDrawCentered(&sContext, "for more information.", -1, GrContextDpyWidthGet(&sContext) / 2, 100, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32Payload[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } pui8Tag = (uint8_t *)pui32Tag; // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Configure the system clock to run off the internal 16MHz oscillator. // ROM_SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_OSC, 16000000); // // Enable AES interrupts. // ROM_IntEnable(INT_AES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting AES128 CCM decryption demo.\n"); GrStringDrawCentered(&sContext, "Starting demo...", -1, GrContextDpyWidthGet(&sContext) / 2, 140, false); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and AES modules. // if(!AESInit()) { UARTprintf("Initialization of the AES module failed.\n"); ui32Errors |= 0x00000001; } // // Loop through all the given vectors. // for(ui8Vector = 0; (ui8Vector < (sizeof(g_psAESCCMTestVectors) / sizeof(g_psAESCCMTestVectors[0]))) && (ui32Errors == 0); ui8Vector++) { UARTprintf("Starting vector #%d\n", ui8Vector); // // Get the current vector's data members. // pui32Key = g_psAESCCMTestVectors[ui8Vector].pui32Key; pui32ExpPayload = g_psAESCCMTestVectors[ui8Vector].pui32Payload; ui32PayloadLength = g_psAESCCMTestVectors[ui8Vector].ui32PayloadLength; pui32AuthData = g_psAESCCMTestVectors[ui8Vector].pui32AuthData; ui32AuthDataLength = g_psAESCCMTestVectors[ui8Vector].ui32AuthDataLength; pui32CipherText = g_psAESCCMTestVectors[ui8Vector].pui32CipherText; pui8ExpTag = (uint8_t *)g_psAESCCMTestVectors[ui8Vector].pui32Tag; ui32TagLength = g_psAESCCMTestVectors[ui8Vector].ui32TagLength; pui32Nonce = g_psAESCCMTestVectors[ui8Vector].pui32Nonce; ui32NonceLength = g_psAESCCMTestVectors[ui8Vector].ui32NonceLength; // // Perform the decryption without uDMA. // UARTprintf("Performing decryption without uDMA.\n"); AES128CCMDecrypt(pui32Key, pui32CipherText, pui32Payload, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32Payload[ui32Idx] != pui32ExpPayload[ui32Idx]) { UARTprintf("Payload mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpPayload[ui32Idx], pui32Payload[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < ui32TagLength; ui32Idx++) { if(pui8Tag[ui32Idx] != pui8ExpTag[ui32Idx]) { UARTprintf("Tag mismatch on byte %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui8ExpTag[ui32Idx], pui8Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32Payload[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Perform the decryption with uDMA. // UARTprintf("Performing decryption with uDMA.\n"); AES128CCMDecrypt(pui32Key, pui32CipherText, pui32Payload, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32Payload[ui32Idx] != pui32ExpPayload[ui32Idx]) { UARTprintf("Payload mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpPayload[ui32Idx], pui32Payload[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < ui32TagLength; ui32Idx++) { if(pui8Tag[ui32Idx] != pui8ExpTag[ui32Idx]) { UARTprintf("Tag mismatch on byte %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui8ExpTag[ui32Idx], pui8Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32Payload[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); GrStringDrawCentered(&sContext, "Demo failed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } else { UARTprintf("Demo completed successfully.\n"); GrStringDrawCentered(&sContext, "Demo passed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } while(1) { } }