Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AES - Advanced Encryption Standard module

Driver for the AES (Advanced Encryption Standard) module.

Provides functions for configuring and initiating ciphering/deciphering with AES algorithms. Several modes(ECB, CBC, OFB, CFB or CTR) and key sizes(128-, 192- or 256-bit) are supported, in addition to manual or DMA-based data input to the AES module.

Data Structures

struct  aes_config
 AES Configuration structure. More...
 
struct  aes_dev_inst
 AES driver software instance structure. More...
 

Typedefs

typedef void(* aes_callback_t )(void)
 Interrupt callback function type for AES. More...
 
typedef enum aes_interrupt_source aes_interrupt_source_t
 AES interrupt source type. More...
 

Enumerations

enum  aes_cfb_size {
  AES_CFB_SIZE_128 = 0,
  AES_CFB_SIZE_64,
  AES_CFB_SIZE_32,
  AES_CFB_SIZE_16,
  AES_CFB_SIZE_8
}
 AES CFB size. More...
 
enum  aes_countermeature_type {
  AES_COUNTERMEASURE_TYPE_1 = 0x01,
  AES_COUNTERMEASURE_TYPE_2 = 0x02,
  AES_COUNTERMEASURE_TYPE_3 = 0x04,
  AES_COUNTERMEASURE_TYPE_4 = 0x08,
  AES_COUNTERMEASURE_TYPE_ALL = 0x0F
}
 AES CounterMeasure type. More...
 
enum  aes_dma_mode {
  AES_MANUAL_MODE = 0,
  AES_DMA_MODE
}
 AES DMA mode. More...
 
enum  aes_encrypt_mode {
  AES_DECRYPTION = 0,
  AES_ENCRYPTION
}
 AES Processing mode. More...
 
enum  aes_interrupt_source {
  AES_INTERRUPT_INPUT_BUFFER_READY = AESA_IER_ODATARDY,
  AES_INTERRUPT_OUTPUT_DATA_READY = AESA_IER_IBUFRDY
}
 AES interrupt source type. More...
 
enum  aes_key_size {
  AES_KEY_SIZE_128 = 0,
  AES_KEY_SIZE_192,
  AES_KEY_SIZE_256
}
 AES Cryptographic key size. More...
 
enum  aes_opmode {
  AES_ECB_MODE = 0,
  AES_CBC_MODE,
  AES_OFB_MODE,
  AES_CFB_MODE,
  AES_CTR_MODE
}
 AES Confidentiality mode. More...
 

Functions

static void aes_decryption_key_generate (struct aes_dev_inst *const dev_inst)
 Starts the computation of the last Nk words of the expanded key. More...
 
void aes_disable (struct aes_dev_inst *const dev_inst)
 Disable the AES. More...
 
static void aes_disable_interrupt (struct aes_dev_inst *const dev_inst, aes_interrupt_source_t source)
 Disable the AES interrupt. More...
 
void aes_enable (struct aes_dev_inst *const dev_inst)
 Enable the AES. More...
 
static void aes_enable_interrupt (struct aes_dev_inst *const dev_inst, aes_interrupt_source_t source)
 Enable the AES interrupt. More...
 
void aes_get_config_defaults (struct aes_config *const cfg)
 Initializes a AES configuration structure to defaults. More...
 
bool aes_init (struct aes_dev_inst *const dev_inst, Aesa *const aes, struct aes_config *const cfg)
 Initialize the AES module. More...
 
static uint32_t aes_read_input_buffer_pointer (struct aes_dev_inst *const dev_inst)
 Read the input buffer pointer position. More...
 
static uint32_t aes_read_interrupt_mask (struct aes_dev_inst *const dev_inst)
 Get the AES interrupt mask status. More...
 
static uint32_t aes_read_output_buffer_pointer (struct aes_dev_inst *const dev_inst)
 Read the output buffer pointer position. More...
 
static uint32_t aes_read_output_data (struct aes_dev_inst *const dev_inst)
 Read the output data. More...
 
static uint32_t aes_read_status (struct aes_dev_inst *const dev_inst)
 Get the AES status. More...
 
static void aes_reset (struct aes_dev_inst *const dev_inst)
 Perform a software reset of the AES. More...
 
void aes_set_callback (struct aes_dev_inst *const dev_inst, aes_interrupt_source_t source, aes_callback_t callback, uint8_t irq_level)
 Set callback for AES. More...
 
static void aes_set_config (struct aes_dev_inst *const dev_inst)
 Configure the AES. More...
 
static void aes_set_new_message (struct aes_dev_inst *const dev_inst)
 Notifies the module that the next input data block is the beginning of a new message. More...
 
static void aes_write_drng_seed (struct aes_dev_inst *const dev_inst, uint32_t ul_drng_seed)
 Write the DRNG seed. More...
 
void aes_write_initvector (struct aes_dev_inst *const dev_inst, const uint32_t *p_vector)
 Write the initialization vector (for the CBC, CFB, OFB & CTR cipher modes) More...
 
static void aes_write_input_buffer_pointer (struct aes_dev_inst *const dev_inst, uint32_t ul_in_position)
 Write the input buffer pointer position. More...
 
static void aes_write_input_data (struct aes_dev_inst *const dev_inst, uint32_t ul_data)
 Write the input data. More...
 
void aes_write_key (struct aes_dev_inst *const dev_inst, const uint32_t *p_key)
 Write the 128/192/256bit cryptographic key. More...
 
static void aes_write_output_buffer_pointer (struct aes_dev_inst *const dev_inst, uint32_t ul_out_position)
 Write the output buffer pointer position. More...
 

typedef void(* aes_callback_t)(void)

Interrupt callback function type for AES.

The interrupt handler can be configured to do a function callback, the callback function must match the aes_callback_t type.

AES interrupt source type.

AES CFB size.

Enumerator
AES_CFB_SIZE_128 
AES_CFB_SIZE_64 
AES_CFB_SIZE_32 
AES_CFB_SIZE_16 
AES_CFB_SIZE_8 

AES CounterMeasure type.

Enumerator
AES_COUNTERMEASURE_TYPE_1 
AES_COUNTERMEASURE_TYPE_2 
AES_COUNTERMEASURE_TYPE_3 
AES_COUNTERMEASURE_TYPE_4 
AES_COUNTERMEASURE_TYPE_ALL 

AES DMA mode.

Enumerator
AES_MANUAL_MODE 
AES_DMA_MODE 

AES Processing mode.

Enumerator
AES_DECRYPTION 
AES_ENCRYPTION 

AES interrupt source type.

Enumerator
AES_INTERRUPT_INPUT_BUFFER_READY 
AES_INTERRUPT_OUTPUT_DATA_READY 

AES Cryptographic key size.

Enumerator
AES_KEY_SIZE_128 
AES_KEY_SIZE_192 
AES_KEY_SIZE_256 
enum aes_opmode

AES Confidentiality mode.

Enumerator
AES_ECB_MODE 
AES_CBC_MODE 
AES_OFB_MODE 
AES_CFB_MODE 
AES_CTR_MODE 

static void aes_decryption_key_generate ( struct aes_dev_inst *const  dev_inst)
inlinestatic

Starts the computation of the last Nk words of the expanded key.

Parameters
dev_instDevice structure pointer.

References aes_dev_inst::hw_dev.

void aes_disable ( struct aes_dev_inst *const  dev_inst)

Disable the AES.

Parameters
dev_instDevice structure pointer.

References aes_dev_inst::hw_dev, SLEEPMGR_SLEEP_0, sleepmgr_unlock_mode(), and sysclk_disable_peripheral_clock().

static void aes_disable_interrupt ( struct aes_dev_inst *const  dev_inst,
aes_interrupt_source_t  source 
)
inlinestatic

Disable the AES interrupt.

Parameters
dev_instDevice structure pointer.
sourceInterrupt source.

References aes_dev_inst::hw_dev.

static void aes_enable_interrupt ( struct aes_dev_inst *const  dev_inst,
aes_interrupt_source_t  source 
)
inlinestatic

Enable the AES interrupt.

Parameters
dev_instDevice structure pointer.
sourceInterrupt source.

References aes_dev_inst::hw_dev.

Referenced by aes_set_callback().

void aes_get_config_defaults ( struct aes_config *const  cfg)

Initializes a AES configuration structure to defaults.

Initializes a given AES configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.

The default configuration is as follows:

  • Encryption.
  • 128 key size.
  • Manual mode.
  • ECB mode.
  • Countermeasure.
Parameters
cfgConfiguration structure to initialize to default values.

References AES_CFB_SIZE_128, AES_COUNTERMEASURE_TYPE_ALL, AES_ECB_MODE, AES_ENCRYPTION, AES_KEY_SIZE_128, AES_MANUAL_MODE, Assert, aes_config::cfb_size, aes_config::countermeasure_mask, aes_config::dma_mode, aes_config::encrypt_mode, aes_config::key_size, and aes_config::opmode.

Referenced by main().

bool aes_init ( struct aes_dev_inst *const  dev_inst,
Aesa *const  aesa,
struct aes_config *const  cfg 
)

Initialize the AES module.

Parameters
dev_instDevice structure pointer.
aesaBase address of the AESA instance.
cfgPointer to AES configuration.
Return values
trueif the initialization was successful.
falseif initialization failed.

References aes_dev_inst::aes_cfg, aes_set_config(), Assert, aes_dev_inst::hw_dev, sysclk_disable_peripheral_clock(), and sysclk_enable_peripheral_clock().

Referenced by main().

static uint32_t aes_read_input_buffer_pointer ( struct aes_dev_inst *const  dev_inst)
inlinestatic

Read the input buffer pointer position.

Parameters
dev_instDevice structure pointer.
Returns
the input buffer pointer position.

References aes_dev_inst::hw_dev.

static uint32_t aes_read_interrupt_mask ( struct aes_dev_inst *const  dev_inst)
inlinestatic

Get the AES interrupt mask status.

Parameters
dev_instDevice structure pointer.
Returns
the content of the interrupt mask register.

References aes_dev_inst::hw_dev.

static uint32_t aes_read_output_buffer_pointer ( struct aes_dev_inst *const  dev_inst)
inlinestatic

Read the output buffer pointer position.

Parameters
dev_instDevice structure pointer.
Returns
the output buffer pointer position.

References aes_dev_inst::hw_dev.

static uint32_t aes_read_output_data ( struct aes_dev_inst *const  dev_inst)
inlinestatic

Read the output data.

Parameters
dev_instDevice structure pointer.
Returns
the output data.

References aes_dev_inst::hw_dev.

Referenced by aes_callback().

static uint32_t aes_read_status ( struct aes_dev_inst *const  dev_inst)
inlinestatic

Get the AES status.

Parameters
dev_instDevice structure pointer.
Returns
the content of the status register.

References aes_dev_inst::hw_dev.

static void aes_reset ( struct aes_dev_inst *const  dev_inst)
inlinestatic

Perform a software reset of the AES.

Parameters
dev_instDevice structure pointer.

References aes_dev_inst::hw_dev.

void aes_set_callback ( struct aes_dev_inst *const  dev_inst,
aes_interrupt_source_t  source,
aes_callback_t  callback,
uint8_t  irq_level 
)

Set callback for AES.

Parameters
dev_instDevice structure pointer.
sourceInterrupt source.
callbackcallback function pointer.
irq_levelinterrupt level.

References aes_callback_pointer, aes_enable_interrupt(), and irq_register_handler.

Referenced by main(), and run_ecb_mode_test_pdca().

static void aes_set_new_message ( struct aes_dev_inst *const  dev_inst)
inlinestatic

Notifies the module that the next input data block is the beginning of a new message.

Parameters
dev_instDevice structure pointer.

References aes_dev_inst::hw_dev.

Referenced by run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), run_ecb_mode_test(), run_ecb_mode_test_pdca(), and run_ofb_mode_test().

static void aes_write_drng_seed ( struct aes_dev_inst *const  dev_inst,
uint32_t  ul_drng_seed 
)
inlinestatic

Write the DRNG seed.

Parameters
dev_instDevice structure pointer.
ul_drng_seedDRNG seed.

References aes_dev_inst::hw_dev.

void aes_write_initvector ( struct aes_dev_inst *const  dev_inst,
const uint32_t *  p_vector 
)

Write the initialization vector (for the CBC, CFB, OFB & CTR cipher modes)

Parameters
dev_instDevice structure pointer.
*p_vectorPointer on 4 contiguous 32bit words.

References aes_dev_inst::hw_dev.

Referenced by run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), and run_ofb_mode_test().

static void aes_write_input_buffer_pointer ( struct aes_dev_inst *const  dev_inst,
uint32_t  ul_in_position 
)
inlinestatic

Write the input buffer pointer position.

Parameters
dev_instDevice structure pointer.
ul_in_positionInput buffer pointer position.

References aes_dev_inst::hw_dev.

static void aes_write_input_data ( struct aes_dev_inst *const  dev_inst,
uint32_t  ul_data 
)
inlinestatic

Write the input data.

Parameters
dev_instDevice structure pointer.
ul_dataInput data.

References aes_dev_inst::hw_dev.

Referenced by run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), run_ecb_mode_test(), and run_ofb_mode_test().

void aes_write_key ( struct aes_dev_inst *const  dev_inst,
const uint32_t *  p_key 
)

Write the 128/192/256bit cryptographic key.

Parameters
dev_instDevice structure pointer.
*p_keyPointer on 4/6/8 contiguous 32bit words.
Note
The key size depends on the AES configuration.

References aes_dev_inst::hw_dev.

Referenced by run_cbc_mode_test(), run_cfb128_mode_test(), run_ctr_mode_test(), run_ecb_mode_test(), run_ecb_mode_test_pdca(), and run_ofb_mode_test().

static void aes_write_output_buffer_pointer ( struct aes_dev_inst *const  dev_inst,
uint32_t  ul_out_position 
)
inlinestatic

Write the output buffer pointer position.

Parameters
dev_instDevice structure pointer.
ul_out_positionOutput buffer pointer position.

References aes_dev_inst::hw_dev.