Xmega Application Note | |||||
This file contains an example application that demonstrates the AES driver using polled functions. Both single AES and Cipher Block Chaining AES encyption and decryption is done.
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_polled.c.
#include "avr_compiler.h"
#include "AES_driver.h"
Go to the source code of this file.
Defines | |
#define | BLOCK_COUNT 3 |
#define | BLOCK_LENGTH 16 |
Functions | |
int | main (void) |
Variables | |
uint8_t | block_ans [BLOCK_LENGTH *BLOCK_COUNT] |
uint8_t | cipher_block_ans [BLOCK_LENGTH *BLOCK_COUNT] |
uint8_t | data [BLOCK_LENGTH] |
uint8_t | data_block [BLOCK_LENGTH *BLOCK_COUNT] |
uint8_t | init [BLOCK_LENGTH] |
uint8_t | key [BLOCK_LENGTH] |
uint8_t | lastsubkey [BLOCK_LENGTH] |
uint8_t | single_ans [BLOCK_LENGTH] |
bool | success |
#define BLOCK_COUNT 3 |
Definition at line 55 of file AES_example_polled.c.
#define BLOCK_LENGTH 16 |
Definition at line 54 of file AES_example_polled.c.
int main | ( | void | ) |
Definition at line 93 of file AES_example_polled.c.
References AES_CBC_decrypt(), AES_CBC_encrypt(), AES_decrypt(), AES_encrypt(), AES_lastsubkey_generate(), AES_software_reset, block_ans, BLOCK_COUNT, BLOCK_LENGTH, cipher_block_ans, data, data_block, init, key, lastsubkey, single_ans, and success.
00094 { 00095 /* Assume that everything is ok*/ 00096 success = true; 00097 00098 /* Before using the AES it is recommended to do an AES software reset to put 00099 * the module in known state, in case other parts of your code has accessed 00100 * the AES module. */ 00101 AES_software_reset(); 00102 00103 /* Generate last subkey. */ 00104 AES_lastsubkey_generate(key, lastsubkey); 00105 00106 /* Do AES encryption and decryption of a single block. */ 00107 success = AES_encrypt(data, single_ans, key); 00108 success = AES_decrypt(single_ans, single_ans, lastsubkey); 00109 00110 /* Check if decrypted answer is equal to plaintext. */ 00111 for(uint8_t i = 0; i < BLOCK_LENGTH ; i++ ){ 00112 if (data[i] != single_ans[i]){ 00113 success = false; 00114 } 00115 } 00116 00117 /* Do AES Cipher Block Chaining encryption and decryption on three blocks. */ 00118 success = AES_CBC_encrypt(data_block, cipher_block_ans, key, init, 00119 BLOCK_COUNT); 00120 success = AES_CBC_decrypt(cipher_block_ans, block_ans, lastsubkey, 00121 init, BLOCK_COUNT); 00122 00123 /* Check if decrypted answer is equal to plaintext. */ 00124 for(uint8_t i = 0; i < BLOCK_LENGTH * BLOCK_COUNT ; i++ ){ 00125 if (data_block[i] != block_ans[i]){ 00126 success = false; 00127 } 00128 } 00129 00130 if(success){ 00131 while(true){ 00132 /* If the example ends up here every thing is ok. */ 00133 nop(); 00134 } 00135 }else{ 00136 while(true){ 00137 /* If the example ends up here something is wrong. */ 00138 nop(); 00139 } 00140 } 00141 }
uint8_t block_ans[BLOCK_LENGTH *BLOCK_COUNT] |
Definition at line 88 of file AES_example_polled.c.
uint8_t cipher_block_ans[BLOCK_LENGTH *BLOCK_COUNT] |
Definition at line 85 of file AES_example_polled.c.
uint8_t data[BLOCK_LENGTH] |
Initial value:
{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16}
Definition at line 58 of file AES_example_polled.c.
Referenced by main().
uint8_t data_block[BLOCK_LENGTH *BLOCK_COUNT] |
Initial value:
{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0xAB, 0xBA, 0x00, 0x00, 0xDE, 0xAD, 0x00, 0x00, 0xAB, 0xBA, 0x00, 0x00, 0xDE, 0xAD, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00}
Definition at line 76 of file AES_example_polled.c.
uint8_t init[BLOCK_LENGTH] |
Initial value:
{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}
Definition at line 72 of file AES_example_polled.c.
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 65 of file AES_example_polled.c.
uint8_t lastsubkey[BLOCK_LENGTH] |
Definition at line 69 of file AES_example_polled.c.
uint8_t single_ans[BLOCK_LENGTH] |
bool success |
Definition at line 91 of file AES_example_polled.c.
Generated on Wed Apr 23 08:53:42 2008 for AVR1318 Using the XMEGA built in AES accelerator by ![]() |