AES example for SAM.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include <string.h>
Macros | |
#define | AES_EXAMPLE_REFBUF_SIZE 4 |
[cipher_data] More... | |
Functions | |
static void | aes_callback (void) |
The AES interrupt call back function. More... | |
static void | cbc_mode_test (void) |
CBC mode encryption and decryption test. More... | |
static void | cfb128_mode_test (void) |
CFB128 mode encryption and decryption test. More... | |
static void | configure_usart (void) |
[module_var] More... | |
static void | ctr_mode_test (void) |
CTR mode encryption and decryption test. More... | |
static void | ecb_mode_test (void) |
ECB mode encryption and decryption test. More... | |
int | main (void) |
[setup] More... | |
static void | ofb_mode_test (void) |
OFB mode encryption and decryption test. More... | |
Variables | |
struct aes_module | aes_instance |
struct aes_config | g_aes_cfg |
AES configuration. More... | |
static uint32_t | output_data [AES_EXAMPLE_REFBUF_SIZE] |
[cipher_data] More... | |
volatile bool | state = false |
struct usart_module | usart_instance |
sample data from NIST-800-38A appendix F | |
uint32_t | ref_plain_text [AES_EXAMPLE_REFBUF_SIZE] |
Reference plain data. More... | |
uint32_t | ref_cipher_text_ecb [AES_EXAMPLE_REFBUF_SIZE] |
Reference ECB cipher data. More... | |
uint32_t | ref_cipher_text_cbc [AES_EXAMPLE_REFBUF_SIZE] |
Reference CBC cipher data. More... | |
uint32_t | ref_cipher_text_cfb128 [AES_EXAMPLE_REFBUF_SIZE] |
Reference CFB128 cipher data. More... | |
uint32_t | ref_cipher_text_ofb [AES_EXAMPLE_REFBUF_SIZE] |
Reference OFB cipher data. More... | |
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 |
[cipher_data]
|
static |
The AES interrupt call back function.
References aes_instance, aes_read_output_data(), output_data, and state.
Referenced by main().
|
static |
CBC mode encryption and decryption test.
References AES_AUTO_START, AES_CBC_MODE, AES_CFB_SIZE_128, aes_clear_new_message(), AES_DECRYPTION, AES_ENCRYPTION, aes_instance, AES_KEY_SIZE_128, AES_MANUAL_START, aes_set_config(), aes_set_new_message(), aes_start(), aes_write_init_vector(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::encrypt_mode, g_aes_cfg, init_vector, key128, aes_config::key_size, aes_config::lod, aes_config::opmode, output_data, ref_cipher_text_cbc, ref_plain_text, aes_config::start_mode, and state.
Referenced by main().
|
static |
CFB128 mode encryption and decryption test.
References AES_CFB_MODE, AES_CFB_SIZE_128, aes_clear_new_message(), AES_DECRYPTION, AES_ENCRYPTION, aes_instance, AES_KEY_SIZE_128, AES_MANUAL_START, aes_set_config(), aes_set_new_message(), aes_start(), aes_write_init_vector(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::encrypt_mode, g_aes_cfg, init_vector, key128, aes_config::key_size, aes_config::lod, aes_config::opmode, output_data, ref_cipher_text_cfb128, ref_plain_text, aes_config::start_mode, and state.
Referenced by main().
|
static |
[module_var]
[setup]
References usart_config::baudrate, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, usart_enable(), usart_get_config_defaults(), and usart_instance.
|
static |
CTR mode encryption and decryption test.
References AES_AUTO_START, AES_CFB_SIZE_128, aes_clear_new_message(), AES_CTR_MODE, AES_DECRYPTION, AES_ENCRYPTION, aes_instance, AES_KEY_SIZE_128, AES_MANUAL_START, aes_set_config(), aes_set_new_message(), aes_start(), aes_write_init_vector(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::encrypt_mode, g_aes_cfg, init_vector_ctr, key128, aes_config::key_size, aes_config::lod, aes_config::opmode, output_data, ref_cipher_text_ctr, ref_plain_text, aes_config::start_mode, and state.
Referenced by main().
|
static |
ECB mode encryption and decryption test.
References AES_AUTO_START, AES_CFB_SIZE_128, aes_clear_new_message(), AES_DECRYPTION, AES_ECB_MODE, AES_ENCRYPTION, aes_instance, AES_KEY_SIZE_128, aes_set_config(), aes_set_new_message(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::encrypt_mode, g_aes_cfg, key128, aes_config::key_size, aes_config::lod, aes_config::opmode, output_data, ref_cipher_text_ecb, ref_plain_text, aes_config::start_mode, and state.
Referenced by main().
int main | ( | void | ) |
[setup]
The main function.
[setup_init]
[setup_config]
[setup_config] [setup_config_defaults]
[setup_config_defaults]
[module_enable]
[module_enable]
[module_enable_register]
[module_enable_register]
[setup_init]
[encryption_decryption] [ECB_MODE]
[ECB_MODE] [CBC_MODE]
[CBC_MODE] [CFB_MODE]
[CFB_MODE] [OFB_MODE]
[OFB_MODE] [CTR_MODE]
[CTR_MODE]
[encryption_decryption]
References aes_callback(), AES_CALLBACK_ENCRYPTION_COMPLETE, aes_enable(), aes_enable_callback(), aes_get_config_defaults(), aes_init(), aes_instance, aes_register_callback(), cbc_mode_test(), cfb128_mode_test(), configure_usart(), ctr_mode_test(), ecb_mode_test(), g_aes_cfg, ofb_mode_test(), and system_init().
|
static |
OFB mode encryption and decryption test.
References AES_AUTO_START, AES_CFB_SIZE_128, aes_clear_new_message(), AES_DECRYPTION, AES_ENCRYPTION, aes_instance, AES_KEY_SIZE_128, AES_MANUAL_START, AES_OFB_MODE, aes_set_config(), aes_set_new_message(), aes_start(), aes_write_init_vector(), aes_write_input_data(), aes_write_key(), aes_config::cfb_size, aes_config::encrypt_mode, g_aes_cfg, init_vector, key128, aes_config::key_size, aes_config::lod, aes_config::opmode, output_data, ref_cipher_text_ofb, ref_plain_text, aes_config::start_mode, and state.
Referenced by main().
struct aes_module aes_instance |
Referenced by aes_callback(), AESEncode(), AESInit(), cbc_mode_test(), cfb128_mode_test(), ctr_mode_test(), ecb_mode_test(), ecb_mode_test_dma(), main(), ofb_mode_test(), run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), run_ecb_mode_test(), run_ecb_mode_test_dma(), and run_ofb_mode_test().
struct aes_config g_aes_cfg |
AES configuration.
Referenced by AESEncode(), AESInit(), cbc_mode_test(), cfb128_mode_test(), ctr_mode_test(), ecb_mode_test(), ecb_mode_test_dma(), main(), ofb_mode_test(), run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), run_ecb_mode_test(), run_ecb_mode_test_dma(), and run_ofb_mode_test().
const uint32_t init_vector[4] |
Init vector array for ECB, CBC, CFB128 and OFB mode.
Referenced by cbc_mode_test(), cfb128_mode_test(), ofb_mode_test(), run_cbc_mode_test(), run_cfb128_mode_test(), and run_ofb_mode_test().
const uint32_t init_vector_ctr[4] |
Init vector array for CTR mode.
Referenced by ctr_mode_test(), and run_ctr_mode_test().
const uint32_t key128[4] |
Cipher 128 bits key array.
Referenced by cbc_mode_test(), cfb128_mode_test(), ctr_mode_test(), ecb_mode_test(), ecb_mode_test_dma(), ofb_mode_test(), run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), run_ecb_mode_test(), run_ecb_mode_test_dma(), and run_ofb_mode_test().
|
static |
[cipher_data]
[module_var]
Referenced by aes_callback(), cbc_mode_test(), cfb128_mode_test(), ctr_mode_test(), ecb_mode_test(), and ofb_mode_test().
uint32_t ref_cipher_text_cbc[AES_EXAMPLE_REFBUF_SIZE] |
Reference CBC cipher data.
Referenced by cbc_mode_test(), and run_cbc_mode_test().
uint32_t ref_cipher_text_cfb128[AES_EXAMPLE_REFBUF_SIZE] |
Reference CFB128 cipher data.
Referenced by cfb128_mode_test(), and run_cfb128_mode_test().
uint32_t ref_cipher_text_ctr[AES_EXAMPLE_REFBUF_SIZE] |
Reference CTR cipher data.
Referenced by ctr_mode_test(), and run_ctr_mode_test().
uint32_t ref_cipher_text_ecb[AES_EXAMPLE_REFBUF_SIZE] |
Reference ECB cipher data.
Referenced by ecb_mode_test(), ecb_mode_test_dma(), run_ecb_mode_test(), and run_ecb_mode_test_dma().
uint32_t ref_cipher_text_ofb[AES_EXAMPLE_REFBUF_SIZE] |
Reference OFB cipher data.
Referenced by ofb_mode_test(), and run_ofb_mode_test().
uint32_t ref_plain_text[AES_EXAMPLE_REFBUF_SIZE] |
Reference plain data.
Referenced by cbc_mode_test(), cfb128_mode_test(), configure_dma_aes_wr(), ctr_mode_test(), ecb_mode_test(), ofb_mode_test(), run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), run_ecb_mode_test(), and run_ofb_mode_test().
struct usart_module usart_instance |