Microchip® Advanced Software Framework

aesa_example.c File Reference

AES example for SAM.

This file defines a useful set of functions for the AES on SAM devices.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <string.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...
 
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_console (void)
 Configure serial console. More...
 
static void ctr_mode_test (void)
 CTR mode encryption and decryption test. More...
 
static void display_menu (void)
 Display the user menu on the terminal. More...
 
static void ecb_mode_test (void)
 ECB mode encryption and decryption test. More...
 
static void ecb_mode_test_pdca (void)
 ECB mode encryption and decryption test with PDCA. More...
 
int main (void)
 The main function. More...
 
static void ofb_mode_test (void)
 OFB mode encryption and decryption test. More...
 

Variables

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 ecb_mode_test_pdca().

#define PDCA_RX_CHANNEL   0
#define PDCA_TX_CHANNEL   1

Referenced by ecb_mode_test_pdca().

static void aes_callback ( void  )
static

The AES interrupt call back function.

References aes_read_output_data(), g_aes_inst, output_data, and state.

Referenced by ecb_mode_test_pdca(), and main().

static void aes_callback_pdca ( void  )
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 ecb_mode_test_pdca().

static void configure_console ( void  )
static

Configure serial console.

References uart_rs232_options::baudrate, and stdio_serial_init().

Referenced by main().

static void display_menu ( void  )
static

Display the user menu on the terminal.

Referenced by main().

struct aes_config g_aes_cfg

AES configuration.

Referenced by main().

const uint32_t init_vector[4]
Initial value:
= {
0x03020100,
0x07060504,
0x0b0a0908,
0x0f0e0d0c
}

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]
Initial value:
= {
0xf3f2f1f0,
0xf7f6f5f4,
0xfbfaf9f8,
0xfffefdfc
}

Init vector array for CTR mode.

Referenced by ctr_mode_test(), and run_ctr_mode_test().

const uint32_t key128[4]
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]
Initial value:
= {
0xacab4976,
0x46b21981,
0x9b8ee9ce,
0x7d19e912
}

Reference CBC cipher data.

Referenced by cbc_mode_test(), and run_cbc_mode_test().

const uint32_t ref_cipher_text_cfb128[AES_EXAMPLE_REFBUF_SIZE]
Initial value:
= {
0x2ed93f3b,
0x20ad2db7,
0xf8493433,
0x4afb3ce8
}

Reference CFB128 cipher data.

Referenced by cfb128_mode_test(), and run_cfb128_mode_test().

const uint32_t ref_cipher_text_ctr[AES_EXAMPLE_REFBUF_SIZE]
Initial value:
= {
0x91614d87,
0x26e320b6,
0x6468ef1b,
0xceb60d99
}

Reference CTR cipher data.

Referenced by ctr_mode_test(), and run_ctr_mode_test().

const uint32_t ref_cipher_text_ecb[AES_EXAMPLE_REFBUF_SIZE]
Initial value:
= {
0xb47bd73a,
0x60367a0d,
0xf3ca9ea8,
0x97ef6624
}

Reference ECB cipher data.

Referenced by ecb_mode_test(), ecb_mode_test_pdca(), run_ecb_mode_test(), and run_ecb_mode_test_pdca().

const uint32_t ref_cipher_text_ofb[AES_EXAMPLE_REFBUF_SIZE]
Initial value:
= {
0x2ed93f3b,
0x20ad2db7,
0xf8493433,
0x4afb3ce8
}

Reference OFB cipher data.

Referenced by ofb_mode_test(), and run_ofb_mode_test().

const uint32_t ref_plain_text[AES_EXAMPLE_REFBUF_SIZE]
volatile bool state = false