Xmega Application Note


AES_example_backtoback.c File Reference


Detailed Description

XMEGA AES back to back driver example source.

This file contains an example application that demonstrates the AES driver using back to back polled functions.

Application note:
AVR1318 Using the XMEGA built in AES accelerator
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
891
Date
2007-11-15 13:52:12 +0100 (to, 15 nov 2007)

Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file AES_example_backtoback.c.

#include "avr_compiler.h"
#include "AES_driver.h"

Include dependency graph for AES_example_backtoback.c:

Go to the source code of this file.

Defines

#define BLOCK_COUNT   3
#define BLOCK_LENGTH   16

Functions

int main (void)

Variables

uint8_t data1 [BLOCK_LENGTH]
uint8_t data2 [BLOCK_LENGTH]
uint8_t key [BLOCK_LENGTH]
uint8_t lastsubkey [BLOCK_LENGTH]
uint8_t read_key [BLOCK_LENGTH]
uint8_t single_ans1 [BLOCK_LENGTH]
uint8_t single_ans2 [BLOCK_LENGTH]
bool success


Define Documentation

#define BLOCK_COUNT   3

Definition at line 54 of file AES_example_backtoback.c.

Referenced by main().

#define BLOCK_LENGTH   16

Definition at line 53 of file AES_example_backtoback.c.

Referenced by main().


Function Documentation

int main ( void   ) 

Definition at line 79 of file AES_example_backtoback.c.

References AES_decrypt_backtoback(), AES_encrypt(), AES_encrypt_backtoback(), AES_software_reset, BLOCK_LENGTH, data1, data2, key, single_ans1, single_ans2, and success.

00080 {
00081         /* Assume that everything is ok*/
00082         success = true;
00083 
00084         /* Before using the AES it is recommended to do an AES software reset to put
00085          * the module in known state, in case other parts of your code has accessed
00086          * the AES module. */
00087         AES_software_reset();
00088 
00089         /* Do AES encryption and decryption every other time with the same key on
00090          * two data blocks. */
00091         success = AES_encrypt(data1, single_ans1, key);
00092         success = AES_decrypt_backtoback(single_ans1, single_ans1);
00093         success = AES_encrypt_backtoback(data2, single_ans2);
00094         success = AES_decrypt_backtoback(single_ans2, single_ans2);
00095 
00096         /* Check if decrypted answers is equal to plaintext. */
00097         for(uint8_t i = 0; i < BLOCK_LENGTH ; i++ ){
00098                 if (data1[i] != single_ans1[i]){
00099                         success = false;
00100                 }
00101                 if (data2[i] != single_ans2[i]){
00102                         success = false;
00103                 }
00104         }
00105 
00106         if(success){
00107                 while(true){
00108                         /* If the example ends up here every thing is ok. */
00109                         nop();
00110                 }
00111         }else{
00112                 while(true){
00113                         /* If the example ends up here something is wrong. */
00114                         nop();
00115                 }
00116         }
00117 }

Here is the call graph for this function:


Variable Documentation

uint8_t data1[BLOCK_LENGTH]

Initial value:

{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                              0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16}

Definition at line 57 of file AES_example_backtoback.c.

Referenced by main().

uint8_t data2[BLOCK_LENGTH]

Initial value:

{0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xCC, 0xCC,
                              0xCC, 0xDD, 0xDD, 0xDD, 0xEE, 0xEE, 0xEE, 0x0F}

Definition at line 60 of file AES_example_backtoback.c.

Referenced by main().

uint8_t key[BLOCK_LENGTH]

Initial value:

 {0x94, 0x74, 0xB8, 0xE8, 0xC7, 0x3B, 0xCA, 0x7D,
                             0x28, 0x34, 0x76, 0xAB, 0x38, 0xCF, 0x37, 0xC2}

Definition at line 68 of file AES_example_backtoback.c.

Referenced by main().

uint8_t lastsubkey[BLOCK_LENGTH]

Definition at line 72 of file AES_example_backtoback.c.

Referenced by main().

uint8_t read_key[BLOCK_LENGTH]

Definition at line 73 of file AES_example_backtoback.c.

uint8_t single_ans1[BLOCK_LENGTH]

Definition at line 64 of file AES_example_backtoback.c.

Referenced by main().

uint8_t single_ans2[BLOCK_LENGTH]

Definition at line 65 of file AES_example_backtoback.c.

Referenced by main().

bool success

Definition at line 76 of file AES_example_backtoback.c.

Referenced by main().

@DOC_TITLE@
Generated on Wed Apr 23 08:53:41 2008 for AVR1318 Using the XMEGA built in AES accelerator by doxygen 1.5.5