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

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

//! [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]

//! [module_enable_register]
	/* Enable AES interrupt. */
	aes_register_callback(aes_callback,AES_CALLBACK_ENCRYPTION_COMPLETE);
	aes_enable_callback(&aes_instance,AES_CALLBACK_ENCRYPTION_COMPLETE);
//! [module_enable_register]

//! [setup_init]
	printf("Start test\r\n");
//! [encryption_decryption]
//![ECB_MODE]
	ecb_mode_test();
//![ECB_MODE]
//![CBC_MODE]
	cbc_mode_test();
//![CBC_MODE]
//![CFB_MODE]
	cfb128_mode_test();
//![CFB_MODE]
//![OFB_MODE]
	ofb_mode_test();
//![OFB_MODE]
//![CTR_MODE]
	ctr_mode_test();
//![CTR_MODE]

//! [encryption_decryption]

	while(1) ;

}
Exemple #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(&g_aes_inst, AESA, &g_aes_cfg);
	aes_enable(&g_aes_inst);

	/* Enable AES interrupt. */
	aes_set_callback(&g_aes_inst, AES_INTERRUPT_INPUT_BUFFER_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':
			printf("ECB mode encryption and decryption test with PDCA.\r\n");
			ecb_mode_test_pdca();
			break;

		default:
			break;
		}
	}
}