Microchip® Advanced Software Framework

Quick Start Guide for the AES Driver

This is the quick start guide for the SAM4C/4E/V71/V70/S70/E70 Advanced Encryption Standard (AES) Driver, with step-by-step instructions on how to configure and use the driver for a specific use case.

The code examples can be copied into any function that needs to control the AES module, such as the main application loop, for example.

Use Cases

AES Basic Usage

This use case will demonstrate how to initialize the AES module to perform encryption or decryption of data.

Setup Steps

Prerequisites

This module requires the following service:

Setup Code

Add this to the main loop or a setup function:

struct aes_config   g_aes_cfg;
aes_get_config_defaults(&g_aes_cfg);
aes_init(AES, &g_aes_cfg);
aes_enable(); 

Workflow

  1. Enable the AES module:
    aes_enable(); 
  2. Set the AES interrupt and callback:
    aes_set_callback(AES, AES_INTERRUPT_DATA_READY,
        aes_callback, 1); 
  3. Initialize the AES to ECB cipher mode:
    g_aes_cfg.encrypt_mode = AES_ENCRYPTION;
    g_aes_cfg.key_size = AES_KEY_SIZE_128;
    g_aes_cfg.start_mode = AES_AUTO_MODE;
    g_aes_cfg.opmode = AES_ECB_MODE;
    g_aes_cfg.cfb_size = AES_CFB_SIZE_128;
    g_aes_cfg.lod = false;
    aes_set_config(AES, &g_aes_cfg);  

Usage Steps

Usage Code

Plain text can be encrypted by:

aes_write_key(AES, key128);
aes_write_input_data(AES, ref_plain_text); 

The cipher text can be retrieved after it's been encrypted by:

aes_read_output_data(AES, output_data);