コード例 #1
0
/**
 * \brief Generate AES sub key
 *
 * Get AES sub key by encryption of dummy data.
 *
 * \param key           Pointer to AES key input.
 * \param last_sub_key  Pointer to AES sub key output.
 *
 */
static bool aes_lastsubkey_generate(t_key key, t_key last_sub_key)
{
	bool keygen_ok;

	aes_software_reset();

	/* Set AES encryption of a single block in manual mode. */
	aes_configure(AES_ENCRYPT, AES_MANUAL, AES_XOR_OFF);

	/* Load key into AES key memory. */
	aes_set_key(key);

	/* Load dummy data into AES state memory. It isn't important what is
	 * written, just that a write cycle occurs. */
	aes_write_inputdata(dummy_data);

	/* Start encryption. */
	aes_start();

	do {
		/* Wait until AES is finished or an error occurs. */
	} while (aes_is_busy());

	/* If not error. */
	if (!aes_is_error()) {
		/* Store the last subkey. */
		aes_get_key(last_sub_key);
		aes_clear_interrupt_flag();
		keygen_ok = true;
	} else {
		aes_clear_error_flag();
		keygen_ok = false;
	}
	return keygen_ok;
}
コード例 #2
0
/**
 * \brief Test AES get and set key value functions.
 *
 * This test sets a key in the AES module, and reads it back with
 * the get function.
 *
 * \param test Current test case.
 */
static void run_aes_set_and_get_key_test(const struct test_case *test)
{
	t_key read_key;
	bool  success;

	set_buffer(read_key, 0x00);

	/* Reset the module */
	aes_software_reset();

	aes_set_key(encryption_key);
	aes_get_key(read_key);

	/* Check if read_key is the same as what was set */
	success = compare_data_block(encryption_key, read_key);

	test_assert_true(test, success,
			"Key read from AES module is not as set");
}
コード例 #3
0
/**
 * \brief Generate AES sub key
 *
 * \note Get AES sub key by encryption of dummy data.
 *
 * \param key           Pointer to AES key input.
 * \param last_sub_key  Pointer to AES sub key output.
 *
 */
static bool aes_lastsubkey_generate(t_key key, t_key last_sub_key)
{
	bool keygen_ok;
	uint8_t i;

	/* Before using the AES it is recommended to do an AES software reset to
	 * put the module in known state, in case other parts of your code has
	 * accessed the AES module. */
	aes_software_reset();

	/* Set AES encryption of a single block in manual mode. */
	aes_configure(AES_ENCRYPT, AES_MANUAL, AES_XOR_OFF);

	/* Load key into AES key memory. */
	aes_set_key(key);

	/* Load dummy data into AES state memory. */
	for (i = 0; i < BLOCK_LENGTH; i++) {
		AES.STATE = 0x00;
	}

	/* Start encryption. */
	aes_start();

	do {
		/* Wait until AES is finished or an error occurs. */
	} while (aes_is_busy());

	/* If not error. */
	if (!aes_is_error()) {
		/* Store the last subkey. */
		aes_get_key(last_sub_key);
		aes_clear_interrupt_flag();
		keygen_ok = true;
	} else {
		aes_clear_error_flag();
		keygen_ok = false;
	}
	return keygen_ok;
}