示例#1
0
/**
 * \brief Application entry point for usart_dmac_serial example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Configure UART for debug message output. */
	configure_console();

	/* Output example information. */
	puts(STRING_HEADER);

	/* Configure USART. */
	configure_usart();

	/* Configure DMAC. */
	configure_dmac();

	/* Configure DMAC RX channel. */
	configure_dmac_rx();

	while (1) {
	}
}
示例#2
0
文件: aes_example.c 项目: marekr/asf
/**
 * \brief ECB mode encryption and decryption test with DMA.
 */
static void ecb_mode_test_dma(void)
{
	/* Configure DMAC. */
	configure_dmac();
	/* Disable DMAC channel. */
	dmac_channel_disable(DMAC, AES_DMA_TX_CH);
	dmac_channel_disable(DMAC, AES_DMA_RX_CH);

	printf("\r\n-----------------------------------\r\n");
	printf("- 128bit cryptographic key\r\n");
	printf("- ECB cipher mode\r\n");
	printf("- DMA mode\r\n");
	printf("- input of 4 32bit words with DMA\r\n");
	printf("-----------------------------------\r\n");

	state = false;

	/* Configure the AES. */
	g_aes_cfg.encrypt_mode = AES_ENCRYPTION;
	g_aes_cfg.key_size = AES_KEY_SIZE_128;
	g_aes_cfg.start_mode = AES_IDATAR0_START;
	g_aes_cfg.opmode = AES_ECB_MODE;
	g_aes_cfg.cfb_size = AES_CFB_SIZE_128;
	g_aes_cfg.lod = false;
	aes_set_config(AES, &g_aes_cfg);

	/* Set the cryptographic key. */
	aes_write_key(AES, key128);

	/* The initialization vector is not used by the ECB cipher mode. */

	/* Write the data to be ciphered by DMA. */
	aes_dma_transmit_config(ref_plain_text, AES_EXAMPLE_REFBUF_SIZE);
	aes_dma_receive_config(output_data, AES_EXAMPLE_REFBUF_SIZE);
	/* Enable DMAC channel. */
	dmac_channel_enable(DMAC, AES_DMA_RX_CH);
	dmac_channel_enable(DMAC, AES_DMA_TX_CH);

	/* Wait for the end of the encryption process. */
	while (false == state) {
	}

	/* Disable DMAC channel. */
	dmac_channel_disable(DMAC, AES_DMA_TX_CH);
	dmac_channel_disable(DMAC, AES_DMA_RX_CH);

	if ((ref_cipher_text_ecb[0] != output_data[0]) ||
			(ref_cipher_text_ecb[1] != output_data[1]) ||
			(ref_cipher_text_ecb[2] != output_data[2]) ||
			(ref_cipher_text_ecb[3] != output_data[3])) {
		printf("\r\nKO!!!\r\n");
	} else {
		printf("\r\nOK!!!\r\n");
	}

	printf("\r\n-----------------------------------\r\n");
	printf("- 128bit cryptographic key\r\n");
	printf("- ECB decipher mode\r\n");
	printf("- DMA mode\r\n");
	printf("- input of 4 32bit words with DMA\r\n");
	printf("-----------------------------------\r\n");

	state = false;

	/* Configure the AES. */
	g_aes_cfg.encrypt_mode = AES_DECRYPTION;
	g_aes_cfg.key_size = AES_KEY_SIZE_128;
	g_aes_cfg.start_mode = AES_IDATAR0_START;
	g_aes_cfg.opmode = AES_ECB_MODE;
	g_aes_cfg.cfb_size = AES_CFB_SIZE_128;
	g_aes_cfg.lod = false;
	aes_set_config(AES, &g_aes_cfg);

	/* Set the cryptographic key. */
	aes_write_key(AES, key128);

	/* The initialization vector is not used by the ECB cipher mode. */

	/* Write the data to be ciphered by DMA. */
	aes_dma_transmit_config(ref_cipher_text_ecb, AES_EXAMPLE_REFBUF_SIZE);
	aes_dma_receive_config(output_data, AES_EXAMPLE_REFBUF_SIZE);
	/* Enable DMAC channel. */
	dmac_channel_enable(DMAC, AES_DMA_RX_CH);
	dmac_channel_enable(DMAC, AES_DMA_TX_CH);

	/* Wait for the end of the decryption process. */
	while (false == state) {
	}

	/* Disable DMAC channel. */
	dmac_channel_disable(DMAC, AES_DMA_TX_CH);
	dmac_channel_disable(DMAC, AES_DMA_RX_CH);

	/* check the result. */
	if ((ref_plain_text[0] != output_data[0]) ||
			(ref_plain_text[1] != output_data[1]) ||
			(ref_plain_text[2] != output_data[2]) ||
			(ref_plain_text[3] != output_data[3])) {
		printf("\r\nKO!!!\r\n");
	} else {
		printf("\r\nOK!!!\r\n");
	}

	/* Disable DMAC module */
	dmac_disable(DMAC);
}
示例#3
0
/**
 * \brief Test ECB mode encryption and decryption with DMA.
 *
 * \param test Current test case.
 */
static void run_ecb_mode_test_dma(const struct test_case *test)
{
	/* Configure DMAC. */
	configure_dmac();
	/* Disable DMAC channel. */
	dmac_channel_disable(DMAC, AES_DMA_TX_CH);
	dmac_channel_disable(DMAC, AES_DMA_RX_CH);

	/* Configure the AES. */
	g_aes_cfg.encrypt_mode = AES_ENCRYPTION;
	g_aes_cfg.key_size = AES_KEY_SIZE_128;
	g_aes_cfg.start_mode = AES_DMA_MODE;
	g_aes_cfg.opmode = AES_ECB_MODE;
	g_aes_cfg.cfb_size = AES_CFB_SIZE_128;
	g_aes_cfg.lod = false;
	aes_set_config(AES, &g_aes_cfg);

	/* Set the cryptographic key. */
	aes_write_key(AES, key128);

	/* The initialization vector is not used by the ECB cipher mode. */

	/* Write the data to be ciphered by DMA. */
	aes_dma_transmit_config(ref_plain_text, AES_EXAMPLE_REFBUF_SIZE);
	aes_dma_receive_config(output_data, AES_EXAMPLE_REFBUF_SIZE);
	/* Enable DMAC channel. */
	dmac_channel_enable(DMAC, AES_DMA_RX_CH);
	dmac_channel_enable(DMAC, AES_DMA_TX_CH);

	/* Wait for the end of the encryption process. */
	delay_ms(30);

	/* Disable DMAC channel. */
	dmac_channel_disable(DMAC, AES_DMA_TX_CH);
	dmac_channel_disable(DMAC, AES_DMA_RX_CH);

	if ((ref_cipher_text_ecb[0] != output_data[0]) ||
			(ref_cipher_text_ecb[1] != output_data[1]) ||
			(ref_cipher_text_ecb[2] != output_data[2]) ||
			(ref_cipher_text_ecb[3] != output_data[3])) {
		flag = false;
	} else {
		flag = true;
	}

	test_assert_true(test, flag == true, "ECB mode encryption not work!");

	/* Configure the AES. */
	g_aes_cfg.encrypt_mode = AES_DECRYPTION;
	g_aes_cfg.key_size = AES_KEY_SIZE_128;
	g_aes_cfg.start_mode = AES_DMA_MODE;
	g_aes_cfg.opmode = AES_ECB_MODE;
	g_aes_cfg.cfb_size = AES_CFB_SIZE_128;
	g_aes_cfg.lod = false;
	aes_set_config(AES, &g_aes_cfg);

	/* Set the cryptographic key. */
	aes_write_key(AES, key128);

	/* The initialization vector is not used by the ECB cipher mode. */

	/* Write the data to be ciphered by DMA. */
	aes_dma_transmit_config(ref_cipher_text_ecb, AES_EXAMPLE_REFBUF_SIZE);
	aes_dma_receive_config(output_data, AES_EXAMPLE_REFBUF_SIZE);
	/* Enable DMAC channel. */
	dmac_channel_enable(DMAC, AES_DMA_RX_CH);
	dmac_channel_enable(DMAC, AES_DMA_TX_CH);

	/* Wait for the end of the decryption process. */
	delay_ms(30);

	/* Disable DMAC channel. */
	dmac_channel_disable(DMAC, AES_DMA_TX_CH);
	dmac_channel_disable(DMAC, AES_DMA_RX_CH);

	/* check the result. */
	if ((ref_plain_text[0] != output_data[0]) ||
			(ref_plain_text[1] != output_data[1]) ||
			(ref_plain_text[2] != output_data[2]) ||
			(ref_plain_text[3] != output_data[3])) {
		flag = false;
	} else {
		flag = true;
	}

	test_assert_true(test, flag == true, "ECB mode decryption not work!");

	/* Disable DMAC module */
	dmac_disable(DMAC);
}