include/aes.h File Reference

Interface of Asynchronous Advanced Encryption Standard (AES) driver. More...

#include <stdint.h>
#include <stdbool.h>
#include <compiler.h>
#include <dmac/dma_controller.h>

Include dependency graph for aes.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  aes_module
 AES module struct. More...
struct  aes_request
 AES request struct. More...

Defines

#define AES_DECRYPT   0 << 0
 Set AES mode to decrypt.
#define AES_ENCRYPT   1 << 0
 Set AES mode to encrypt.
#define AES_KEYSIZE_128   0 << 10
 Use 128bit key.
#define AES_KEYSIZE_192   1 << 10
 Use 192bit key.
#define AES_KEYSIZE_256   2 << 10
 Use 256bit key.
#define AES_KEYSIZE_MASK   3 << 10
 Keysize mask.
#define AES_OPMODE_ECB   0 << 12
 Set AES operation mode to ECB.
#define AES_OPMODE_CBC   1 << 12
 Set AES operation mode to CBC.
#define AES_OPMODE_OFB   2 << 12
 Set AES operation mode to OFB.
#define AES_OPMODE_CFB   3 << 12
 Set AES operation mode to CFB.
#define AES_OPMODE_CTR   4 << 12
 Set AES operation mode to CTR.

Functions

void aes_init (struct aes_module *module, uint32_t mode)
 Initialize AES module.
void aes_free (struct aes_module *module)
 Free AES module.
void aes_load_key (struct aes_module *module, const uint32_t *key)
 Load AES key.
void aes_set_cipher (struct aes_module *module, uint32_t mode)
 Change AES cipher mode.
uint32_t aes_get_cipher (struct aes_module *module)
 Get AES cipher mode.
void aes_load_init_vector (struct aes_module *module, const uint32_t *key)
 Load initialization vector.
void aes_submit_request (struct aes_request *req)
 Submit AES request.
int aes_duplicate_buffer_refs (struct slist *copy, struct slist *original)
 Create duplicate references to the data in a buffer list.
void aes_free_duplicate_buffers (struct slist *buf_list)
 Free a duplicated buffer list.
struct aes_requestaes_alloc_request (struct aes_module *module)
 Allocate AES request.
void aes_free_request (struct aes_request *req)
 Free AES request.
void aes_prepare_request (struct aes_request *req, struct slist *buf_list)
 Prepare an AES request.


Detailed Description

Interface of Asynchronous Advanced Encryption Standard (AES) driver.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file aes.h.


Define Documentation

#define AES_DECRYPT   0 << 0

Set AES mode to decrypt.

Definition at line 50 of file aes.h.

#define AES_ENCRYPT   1 << 0

Set AES mode to encrypt.

Definition at line 51 of file aes.h.

#define AES_KEYSIZE_128   0 << 10

Use 128bit key.

Definition at line 52 of file aes.h.

Referenced by aes_load_key().

#define AES_KEYSIZE_192   1 << 10

Use 192bit key.

Definition at line 53 of file aes.h.

Referenced by aes_load_key().

#define AES_KEYSIZE_256   2 << 10

Use 256bit key.

Definition at line 54 of file aes.h.

Referenced by aes_load_key().

#define AES_KEYSIZE_MASK   3 << 10

Keysize mask.

Definition at line 55 of file aes.h.

Referenced by aes_load_key().

#define AES_OPMODE_CBC   1 << 12

Set AES operation mode to CBC.

Definition at line 57 of file aes.h.

#define AES_OPMODE_CFB   3 << 12

Set AES operation mode to CFB.

Definition at line 59 of file aes.h.

#define AES_OPMODE_CTR   4 << 12

Set AES operation mode to CTR.

Definition at line 60 of file aes.h.

#define AES_OPMODE_ECB   0 << 12

Set AES operation mode to ECB.

Definition at line 56 of file aes.h.

#define AES_OPMODE_OFB   2 << 12

Set AES operation mode to OFB.

Definition at line 58 of file aes.h.


Function Documentation

struct aes_request* aes_alloc_request ( struct aes_module module  )  [read]

Allocate AES request.

This function will allocate memory for one AES request.

Parameters:
module Pointer to AES module struct
Returns:
Pointer to newly allocated AES request struct

Definition at line 356 of file aes.c.

References assert, aes_request::module, and aes_module::port.

int aes_duplicate_buffer_refs ( struct slist copy,
struct slist original 
)

Create duplicate references to the data in a buffer list.

This function will create a duplicate buffer list, mirroring the buffers in the original buffer list. The new buffers will refer to the data stored in the original buffers. If the two buffer lists are submitted as tx and rx buffers to the AES driver, the encryption will be performed in-place.

Parameters:
copy Duplicated buffer list
original The original buffer list
Returns:
0 Successfull duplication

-1 Duplication failed, no new buffers allocated

Definition at line 228 of file aes.c.

References buffer::addr, aes_free_duplicate_buffers(), assert, buffer::len, buffer::node, buffer_addr_t::phys, buffer_addr_t::ptr, slist_for_each, slist_insert_tail(), and unlikely.

Referenced by aes_prepare_request().

Here is the call graph for this function:

void aes_free ( struct aes_module module  ) 

Free AES module.

This function will free the DMA channels allocated by aes_init(), which afterwards will have to be run again in order to use the AES module.

Parameters:
module Pointer to AES module struct

Definition at line 92 of file aes.c.

References assert, aes_module::dma_rx_channel, aes_module::dma_tx_channel, and aes_module::port.

void aes_free_duplicate_buffers ( struct slist buf_list  ) 

Free a duplicated buffer list.

This function will free all the buffers allocated by aes_duplicate_buffer_refs().

Parameters:
buf_list The buffer list to free

Definition at line 201 of file aes.c.

References assert, buffer::node, slist_is_empty(), and slist_pop_head.

Referenced by aes_duplicate_buffer_refs().

Here is the call graph for this function:

void aes_free_request ( struct aes_request req  ) 

Free AES request.

This function will free the memory allocate by an AES request.

Parameters:
req Pointer to AES request struct

Definition at line 378 of file aes.c.

References assert, aes_request::rx_buf_list, slist_is_empty(), and aes_request::tx_buf_list.

Here is the call graph for this function:

uint32_t aes_get_cipher ( struct aes_module module  ) 

Get AES cipher mode.

This function will return the current AES cipher mode. It can be used to make sure the correct mode is enabled before submitting requests.

Parameters:
module Pointer to AES module struct

Definition at line 129 of file aes.c.

References assert, and aes_module::mode.

void aes_init ( struct aes_module module,
uint32_t  mode 
)

Initialize AES module.

This function will initialize the AES hardware module and create the DMA channels needed for it to operate. The operation mode can be set by the mode bit field.

Parameters:
module Pointer to AES module struct
mode AES mode bit field

Definition at line 68 of file aes.c.

References assert, aes_module::counter, aes_module::dma_rx_channel, aes_module::dma_tx_channel, aes_module::mode, and aes_module::port.

void aes_load_init_vector ( struct aes_module module,
const uint32_t *  vector 
)

Load initialization vector.

This function will load an initialization vector to the AES module. This vector is needed for when performing block chained encryption.

Parameters:
module Pointer to AES module struct
key Initialization vector

Definition at line 145 of file aes.c.

References assert, and aes_module::port.

void aes_load_key ( struct aes_module module,
const uint32_t *  key 
)

Load AES key.

This function will load the key the AES module will use for encryption and decryption into the hardware. aes_init() must be run first and the key provided here must correspond to the keysize selected when the module was initialized.

Parameters:
module Pointer to AES module struct
key AES key

Definition at line 167 of file aes.c.

References AES_KEYSIZE_128, AES_KEYSIZE_192, AES_KEYSIZE_256, AES_KEYSIZE_MASK, assert, aes_module::mode, aes_module::port, and unhandled_case.

void aes_prepare_request ( struct aes_request req,
struct slist buf_list 
)

Prepare an AES request.

This function will prepare an AES request for submittion. The buffers in buf_list is copied to an inernal list in the request. A new bufer list mirroring the input buffer list is created and will be used to hold the AES output (encrypted data when encrypting). When the operation is done, the input buffers are thrown away and a pointer to the output buffer list is returned to the callback function.

Parameters:
req Pointer to AES request struct
buf_list Buffer list containing input data.

Definition at line 399 of file aes.c.

References aes_duplicate_buffer_refs(), assert, aes_request::rx_buf_list, slist_init(), slist_is_empty(), slist_move_to_tail(), and aes_request::tx_buf_list.

Here is the call graph for this function:

void aes_set_cipher ( struct aes_module module,
uint32_t  mode 
)

Change AES cipher mode.

This function will change the current AES cipher mode to encrypt or decrypt, depending on the mode paramater.

Parameters:
module Pointer to AES module struct
mode AES cipher mode mask

Definition at line 110 of file aes.c.

References assert, aes_module::mode, and aes_module::port.

void aes_submit_request ( struct aes_request req  ) 

Submit AES request.

This function will submit one AES request for encryption/decryption by the AES hardware module. It will allocate two DMA requests for transfer to and from the AES module and submit these to their repsective DMA channels. The memory allocated for DMA requests will automatically be freed prior to calling the callback.

Parameters:
req Pointer to AES request struct

Definition at line 320 of file aes.c.

References assert, dmac_request::buf_list, DMA_FROM_DEVICE, aes_module::dma_rx_channel, DMA_TO_DEVICE, aes_module::dma_tx_channel, dmac_chan_submit_request(), aes_request::done_counter, aes_request::module, aes_request::rx_buf_list, aes_request::rx_req, slist_is_empty(), slist_move_to_tail(), aes_request::tx_buf_list, and aes_request::tx_req.

Here is the call graph for this function:


Generated on Tue Sep 15 10:20:30 2009 for libavr32 by  doxygen 1.5.8