Exemple #1
0
/**
 * \brief The AES interrupt handler.
 */
void AES_Handler(void)
{
	uint32_t status = aes_read_interrupt_status(AES);
	uint32_t mask = aes_read_interrupt_mask(AES);

	if ((status & AES_ISR_DATRDY) && (mask & AES_IMR_DATRDY)) {
		if(aes_callback_pointer[0]) {
			aes_callback_pointer[0]();
		}
	}

	if ((status & AES_ISR_URAD) && (mask & AES_IMR_URAD)) {
		if(aes_callback_pointer[1]) {
			aes_callback_pointer[1]();
		}
	}
}
Exemple #2
0
/**
 * \brief GCM mode decryption test.
 */
static void gcm_mode_decryption_test(void)
{
	printf("\r\n-----------------------------------\r\n");
	printf("- 256bit cryptographic key\r\n");
	printf("- GCM Decryption\r\n");
	printf("- Auto start mode\r\n");
	printf("- input of 160-bit effective words\r\n");
	printf("-----------------------------------\r\n");

	/* Configure the AES. */
	g_aes_cfg.encrypt_mode = AES_DECRYPTION;
	g_aes_cfg.key_size = AES_KEY_SIZE_256;
	g_aes_cfg.start_mode = AES_AUTO_START;
	g_aes_cfg.opmode = AES_GCM_MODE;
	g_aes_cfg.cfb_size = AES_CFB_SIZE_128;
	g_aes_cfg.lod = false;
	g_aes_cfg.gtag_en = false;
	aes_set_config(AES, &g_aes_cfg);

	/* AES-GCM Input Configuration */
	gcm_input_data.key = aes_key;
	gcm_input_data.key_len = AES_KEY_SIZE;
	gcm_input_data.iv = aes_iv;
	gcm_input_data.iv_len = AES_IV_SIZE;
	gcm_input_data.input = aes_cipher_text;
	gcm_input_data.text_len = AES_PDATA_EFFECTIVE_SIZE;
	gcm_input_data.aad = aes_aad;
	gcm_input_data.aad_len = AES_AAD_EFFECTIVE_SIZE;
	gcm_input_data.output = output_data;
	gcm_input_data.tag = tag_data;

	/* Write the key to generate GCMH Subkey */
	aes_write_key(AES, gcm_input_data.key);

	/* Wait for the GCMH to generate */
	while (!(aes_read_interrupt_status(AES) & AES_ISR_DATRDY)) {
	}

	/* Generate J0 using IV(96 Bits) */
	uint32_t i;
	/* J0 data array */
	uint32_t j0[4];

	for (i = 0; i < 3; i++) {
		j0[i] = gcm_input_data.iv[i];
	}
	/* Write the j0 + 1 in IV register */
	j0[3] = 0x02000000;

	aes_write_initvector(AES, (uint32_t *)j0);

	/* set AADLEN */
	aes_write_authen_datalength(AES, gcm_input_data.aad_len);

	/* Set CLEN */
	aes_write_pctext_length(AES, gcm_input_data.text_len);

	/* Write AAD Data for TAG generation */
	uint32_t offset = 0;
	for (i = 0; i < (AES_AAD_SIZE / 4); i++) {
		/* write the input data */
		aes_write_input_data(AES, (gcm_input_data.aad + offset));
		/* Wait till TAG is ready */
		while (!(aes_read_interrupt_status(AES) & AES_ISR_DATRDY)) {
		}
		/* 16-Byte Boundaries */
		offset += 4;
	}

	/* Reset offset to zero */
	offset = 0;

	/* Write plain text for cipher text generation */
	for (i = 0; i < (AES_PDATA_SIZE / 4); i++) {
		/* write the input data */
		aes_write_input_data(AES, (gcm_input_data.input + offset));
		/* Wait for the operation to complete */
		while (!(aes_read_interrupt_status(AES) & AES_ISR_DATRDY)) {
		}
		aes_read_output_data(AES,
				(uint32_t *)(gcm_input_data.output + offset));
		offset += 4;
	}

	if (memcmp(output_data, aes_plain_text,
			AES_PDATA_EFFECTIVE_SIZE) != 0) {
		printf("\n\rDEC COMPARE FAILED! ");
	} else {
		printf("\n\rDEC COMPARE SUCCESS! ");
	}
}