Esempio n. 1
0
/**
 * \brief The main function.
 */
int main(void)
{
//! [setup_init]

	/* Initialize the system and console*/
	system_init();
	configure_usart();

//! [setup_dma]
	/* Configure AES DMA and enable callback */
	configure_dma_aes_wr();
	configure_dma_aes_rd();

	dma_register_callback(&example_resource_tx, transfer_tx_rx_done,
			DMA_CALLBACK_TRANSFER_DONE);
	dma_enable_callback(&example_resource_tx, DMA_CALLBACK_TRANSFER_DONE);

	dma_register_callback(&example_resource_rx, transfer_tx_rx_done,
			DMA_CALLBACK_TRANSFER_DONE);
	dma_enable_callback(&example_resource_rx, DMA_CALLBACK_TRANSFER_DONE);
//! [setup_dma]

//! [setup_config]
	aes_get_config_defaults(&g_aes_cfg);
//! [setup_config]
//! [setup_config_defaults]
	aes_init(&aes_instance,AES, &g_aes_cfg);
//! [setup_config_defaults]

//! [module_enable]
	aes_enable(&aes_instance);
//! [module_enable]

//! [setup_init]

//! [encryption_decryption]
	/* ECB mode encryption test with DMA */
	ecb_mode_test_dma();
//! [encryption_decryption]

	while(1) ;

}
Esempio n. 2
0
/**
 * \brief The main function.
 */
int main(void)
{
	uint8_t key;

	/* Initialize the SAM system */
	sysclk_init();
	board_init();

	/* Initialize the console  */
	configure_console();

	/* Output example information */
	printf("-- AES Example --\r\n");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/* Enable the AES module. */
	aes_get_config_defaults(&g_aes_cfg);
	aes_init(AES, &g_aes_cfg);
	aes_enable();

	/* Enable AES interrupt. */
	aes_set_callback(AES, AES_INTERRUPT_DATA_READY,
			aes_callback, 1);

	/* Display menu */
	display_menu();

	while (1) {
		scanf("%c", (char *)&key);

		switch (key) {
		case 'h':
			display_menu();
			break;

		case '1':
			printf("ECB mode encryption and decryption test.\r\n");
			ecb_mode_test();
			break;

		case '2':
			printf("CBC mode encryption and decryption test.\r\n");
			cbc_mode_test();
			break;

		case '3':
			printf("CFB128 mode encryption and decryption test.\r\n");
			cfb128_mode_test();
			break;

		case '4':
			printf("OFB mode encryption and decryption test.\r\n");
			ofb_mode_test();
			break;

		case '5':
			printf("CTR mode encryption and decryption test.\r\n");
			ctr_mode_test();
			break;

		case 'd':
			#if SAM4E
			printf(
					"ECB mode encryption and decryption test with DMA.\r\n");
			ecb_mode_test_dma();
			#else
			printf("This mode is not supported by device.\r\n");
			#endif
			break;

		case 'p':
			#if SAM4C || SAM4CP || SAM4CM
			printf(
					"ECB mode encryption and decryption test with PDC.\r\n");
			ecb_mode_test_pdc();
			#else
			printf("This mode is not supported by device.\r\n");
			#endif
			break;

		default:
			break;
		}
	}
}