Unit tests for AES driver.
Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include <conf_test.h>
Macros | |
#define | AES_EXAMPLE_REFBUF_SIZE 4 |
#define | PDCA_RX_CHANNEL 0 |
#define | PDCA_TX_CHANNEL 1 |
Functions | |
static void | aes_callback (void) |
The AES interrupt call back function. More... | |
static void | aes_callback_pdca (void) |
The AES interrupt call back function. More... | |
int | main (void) |
Run AES driver unit tests. More... | |
static void | run_cbc_mode_test (const struct test_case *test) |
Test CBC mode encryption and decryption. More... | |
static void | run_cfb128_mode_test (const struct test_case *test) |
Test CFB128 mode encryption and decryption. More... | |
static void | run_ctr_mode_test (const struct test_case *test) |
Test CTR mode encryption and decryption. More... | |
static void | run_ecb_mode_test (const struct test_case *test) |
Test ECB mode encryption and decryption. More... | |
static void | run_ecb_mode_test_pdca (const struct test_case *test) |
Test ECB mode encryption and decryption with PDCA. More... | |
static void | run_ofb_mode_test (const struct test_case *test) |
Test OFB mode encryption and decryption. More... | |
Variables | |
volatile bool | flag = false |
struct aes_config | g_aes_cfg |
AES configuration. More... | |
struct aes_dev_inst | g_aes_inst |
AES instance. More... | |
static uint32_t | output_data [AES_EXAMPLE_REFBUF_SIZE] |
pdca_channel_config_t | PDCA_RX_OPTIONS |
PDCA channel options. More... | |
pdca_channel_config_t | PDCA_TX_OPTIONS |
volatile bool | state = false |
sample data from NIST-800-38A appendix F | |
const uint32_t | ref_plain_text [AES_EXAMPLE_REFBUF_SIZE] |
Reference plain data. More... | |
const uint32_t | ref_cipher_text_ecb [AES_EXAMPLE_REFBUF_SIZE] |
Reference ECB cipher data. More... | |
const uint32_t | ref_cipher_text_cbc [AES_EXAMPLE_REFBUF_SIZE] |
Reference CBC cipher data. More... | |
const uint32_t | ref_cipher_text_cfb128 [AES_EXAMPLE_REFBUF_SIZE] |
Reference CFB128 cipher data. More... | |
const uint32_t | ref_cipher_text_ofb [AES_EXAMPLE_REFBUF_SIZE] |
Reference OFB cipher data. More... | |
const uint32_t | ref_cipher_text_ctr [AES_EXAMPLE_REFBUF_SIZE] |
Reference CTR cipher data. More... | |
const uint32_t | key128 [4] |
Cipher 128 bits key array. More... | |
const uint32_t | init_vector [4] |
Init vector array for ECB, CBC, CFB128 and OFB mode. More... | |
const uint32_t | init_vector_ctr [4] |
Init vector array for CTR mode. More... | |
#define AES_EXAMPLE_REFBUF_SIZE 4 |
Referenced by run_ecb_mode_test_pdca().
#define PDCA_RX_CHANNEL 0 |
Referenced by aes_callback_pdca(), and run_ecb_mode_test_pdca().
#define PDCA_TX_CHANNEL 1 |
Referenced by run_ecb_mode_test_pdca().
|
static |
The AES interrupt call back function.
References aes_read_output_data(), g_aes_inst, output_data, and state.
Referenced by main(), and run_ecb_mode_test_pdca().
|
static |
The AES interrupt call back function.
References PDCA_CH_TRANSFER_COMPLETED, pdca_channel_enable(), pdca_get_channel_status(), PDCA_RX_CHANNEL, and state.
Referenced by run_ecb_mode_test_pdca().
int main | ( | void | ) |
Run AES driver unit tests.
References aes_callback(), aes_enable(), aes_get_config_defaults(), aes_init(), AES_INTERRUPT_INPUT_BUFFER_READY, aes_set_callback(), uart_rs232_options::baudrate, board_init(), cbc_mode_test(), cfb128_mode_test(), ctr_mode_test(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, ecb_mode_test(), ecb_mode_test_pdca(), g_aes_cfg, g_aes_inst, NULL, ofb_mode_test(), run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), run_ecb_mode_test(), run_ecb_mode_test_pdca(), run_ofb_mode_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.
|
static |
Test CBC mode encryption and decryption.
test | Current test case. |
References AES_CBC_MODE, AES_CFB_SIZE_128, aes_dev_inst::aes_cfg, AES_COUNTERMEASURE_TYPE_ALL, AES_DECRYPTION, AES_ENCRYPTION, AES_KEY_SIZE_128, AES_MANUAL_MODE, aes_set_config(), aes_set_new_message(), aes_write_initvector(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::countermeasure_mask, delay_ms, aes_config::dma_mode, aes_config::encrypt_mode, flag, g_aes_inst, init_vector, key128, aes_config::key_size, aes_config::opmode, output_data, ref_cipher_text_cbc, ref_plain_text, state, and test_assert_true.
Referenced by main().
|
static |
Test CFB128 mode encryption and decryption.
test | Current test case. |
References AES_CFB_MODE, AES_CFB_SIZE_128, aes_dev_inst::aes_cfg, AES_COUNTERMEASURE_TYPE_ALL, AES_DECRYPTION, AES_ENCRYPTION, AES_KEY_SIZE_128, AES_MANUAL_MODE, aes_set_config(), aes_set_new_message(), aes_write_initvector(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::countermeasure_mask, delay_ms, aes_config::dma_mode, aes_config::encrypt_mode, flag, g_aes_inst, init_vector, key128, aes_config::key_size, aes_config::opmode, output_data, ref_cipher_text_cfb128, ref_plain_text, state, and test_assert_true.
Referenced by main().
|
static |
Test CTR mode encryption and decryption.
test | Current test case. |
References AES_CFB_SIZE_128, aes_dev_inst::aes_cfg, AES_COUNTERMEASURE_TYPE_ALL, AES_CTR_MODE, AES_DECRYPTION, AES_ENCRYPTION, AES_KEY_SIZE_128, AES_MANUAL_MODE, aes_set_config(), aes_set_new_message(), aes_write_initvector(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::countermeasure_mask, delay_ms, aes_config::dma_mode, aes_config::encrypt_mode, flag, g_aes_inst, init_vector_ctr, key128, aes_config::key_size, aes_config::opmode, output_data, ref_cipher_text_ctr, ref_plain_text, state, and test_assert_true.
Referenced by main().
|
static |
Test ECB mode encryption and decryption.
test | Current test case. |
References AES_CFB_SIZE_128, aes_dev_inst::aes_cfg, AES_COUNTERMEASURE_TYPE_ALL, AES_DECRYPTION, AES_ECB_MODE, AES_ENCRYPTION, AES_KEY_SIZE_128, AES_MANUAL_MODE, aes_set_config(), aes_set_new_message(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::countermeasure_mask, delay_ms, aes_config::dma_mode, aes_config::encrypt_mode, flag, g_aes_inst, key128, aes_config::key_size, aes_config::opmode, output_data, ref_cipher_text_ecb, ref_plain_text, state, and test_assert_true.
Referenced by main().
|
static |
Test ECB mode encryption and decryption with PDCA.
test | Current test case. |
References pdca_channel_config_t::addr, aes_callback(), aes_callback_pdca(), AES_CFB_SIZE_128, aes_dev_inst::aes_cfg, AES_COUNTERMEASURE_TYPE_ALL, AES_DECRYPTION, AES_DMA_MODE, AES_ECB_MODE, AES_ENCRYPTION, AES_EXAMPLE_REFBUF_SIZE, AES_INTERRUPT_INPUT_BUFFER_READY, AES_KEY_SIZE_128, aes_set_callback(), aes_set_config(), aes_set_new_message(), aes_write_key(), aes_config::cfb_size, aes_config::countermeasure_mask, delay_ms, aes_config::dma_mode, aes_config::encrypt_mode, flag, g_aes_inst, key128, aes_config::key_size, aes_config::opmode, output_data, pdca_channel_disable(), pdca_channel_enable(), pdca_channel_set_config(), pdca_disable(), pdca_enable(), PDCA_RX_CHANNEL, PDCA_TX_CHANNEL, pdca_channel_config_t::pid, pdca_channel_config_t::r_addr, pdca_channel_config_t::r_size, ref_cipher_text_ecb, ref_plain_text, pdca_channel_config_t::size, state, test_assert_true, and pdca_channel_config_t::transfer_size.
Referenced by main().
|
static |
Test OFB mode encryption and decryption.
test | Current test case. |
References AES_CFB_SIZE_128, aes_dev_inst::aes_cfg, AES_COUNTERMEASURE_TYPE_ALL, AES_DECRYPTION, AES_ENCRYPTION, AES_KEY_SIZE_128, AES_MANUAL_MODE, AES_OFB_MODE, aes_set_config(), aes_set_new_message(), aes_write_initvector(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::countermeasure_mask, delay_ms, aes_config::dma_mode, aes_config::encrypt_mode, flag, g_aes_inst, init_vector, key128, aes_config::key_size, aes_config::opmode, output_data, ref_cipher_text_ofb, ref_plain_text, state, and test_assert_true.
Referenced by main().
struct aes_config g_aes_cfg |
AES configuration.
struct aes_dev_inst g_aes_inst |
AES instance.
const uint32_t init_vector[4] |
Init vector array for ECB, CBC, CFB128 and OFB mode.
const uint32_t init_vector_ctr[4] |
Init vector array for CTR mode.
const uint32_t key128[4] |
Cipher 128 bits key array.
|
static |
pdca_channel_config_t PDCA_RX_OPTIONS |
PDCA channel options.
pdca_channel_config_t PDCA_TX_OPTIONS |
const uint32_t ref_cipher_text_cbc[AES_EXAMPLE_REFBUF_SIZE] |
Reference CBC cipher data.
const uint32_t ref_cipher_text_cfb128[AES_EXAMPLE_REFBUF_SIZE] |
Reference CFB128 cipher data.
const uint32_t ref_cipher_text_ctr[AES_EXAMPLE_REFBUF_SIZE] |
Reference CTR cipher data.
const uint32_t ref_cipher_text_ecb[AES_EXAMPLE_REFBUF_SIZE] |
Reference ECB cipher data.
const uint32_t ref_cipher_text_ofb[AES_EXAMPLE_REFBUF_SIZE] |
Reference OFB cipher data.
const uint32_t ref_plain_text[AES_EXAMPLE_REFBUF_SIZE] |
Reference plain data.