Xmega Application Note | |||||
This file contains an example application that demonstrates the AES driver. It shows how to use AES module
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_interrupt.c.
#include "avr_compiler.h"
#include "AES_driver.h"
Go to the source code of this file.
Defines | |
#define | BLOCK_COUNT 9 |
#define | BLOCK_LENGTH 16 |
Functions | |
ISR (AES_INT_vect) | |
Interrupt vector proceccing data after one encrypt/decrypt complete. | |
int | main (void) |
Variables | |
uint8_t | block_ans [BLOCK_LENGTH *BLOCK_COUNT] |
Variable used to store decrypted plaintext from Cipher Block Chaining. | |
uint8_t | cipher_block_ans [BLOCK_LENGTH *BLOCK_COUNT] |
Variable used to store ciphertext from Cipher Block Chaining. | |
uint8_t | data_block [BLOCK_LENGTH *BLOCK_COUNT] |
Plain text used during Cipher Block Chaining. | |
uint8_t | init [BLOCK_LENGTH] |
Initialisation vector (IV) used during Cipher Block Chaining. | |
AES_interrupt_driver_t | interrupt_driver |
uint8_t | key [BLOCK_LENGTH] |
uint8_t | lastsubkey [BLOCK_LENGTH] |
bool | success |
#define BLOCK_COUNT 9 |
Definition at line 54 of file AES_example_interrupt.c.
#define BLOCK_LENGTH 16 |
Definition at line 53 of file AES_example_interrupt.c.
ISR | ( | AES_INT_vect | ) |
Interrupt vector proceccing data after one encrypt/decrypt complete.
Definition at line 173 of file AES_example_interrupt.c.
References AES_interrupt_handler().
00174 { 00175 /* Run AES interrupts according to interrupt_driver. */ 00176 AES_interrupt_handler(&interrupt_driver); 00177 }
int main | ( | void | ) |
Definition at line 90 of file AES_example_interrupt.c.
References AES_interrupt_driver_finished(), AES_interrupt_driver_init(), AES_interrupt_driver_start(), AES_lastsubkey_generate(), AES_software_reset, block_ans, BLOCK_COUNT, BLOCK_LENGTH, cipher_block_ans, data_block, init, key, lastsubkey, and success.
00091 { 00092 /* Assume that everything is ok*/ 00093 success = true; 00094 00095 /* Before using the AES it is recommended to do an AES software reset to put 00096 * the module in known state, in case other parts of your code has accessed 00097 * the AES module. */ 00098 AES_software_reset(); 00099 00100 /* Initialize AES interrupt driver for encryption. */ 00101 AES_interrupt_driver_init(&interrupt_driver, 00102 data_block, 00103 cipher_block_ans, 00104 key, 00105 init, 00106 BLOCK_COUNT, 00107 false); 00108 00109 /* Enable PMIC interrupt to level low. */ 00110 PMIC.CTRL |= PMIC_LOLVLEN_bm; 00111 00112 /* Enable global interrupts. */ 00113 sei(); 00114 00115 /* Start interrupt driver. */ 00116 success = AES_interrupt_driver_start(&interrupt_driver, AES_INTLVL_LO_gc); 00117 00118 if(success){ 00119 do{ 00120 /* Wait until all the encryption is finished. */ 00121 }while(!AES_interrupt_driver_finished(&interrupt_driver)); 00122 }else{ 00123 while(true){ 00124 /* If the example ends up here something is wrong. */ 00125 nop(); 00126 } 00127 } 00128 00129 /* Before doing a decryption generate and store the last sub key of the 00130 * extended key. */ 00131 success = AES_lastsubkey_generate(key, lastsubkey); 00132 00133 /* Initialize AES interrupt driver for decryption. */ 00134 AES_interrupt_driver_init(&interrupt_driver, 00135 cipher_block_ans, 00136 block_ans, 00137 lastsubkey, 00138 init, 00139 BLOCK_COUNT, 00140 true); 00141 00142 /* Start interrupt driver. */ 00143 success = AES_interrupt_driver_start(&interrupt_driver, AES_INTLVL_LO_gc); 00144 00145 if(success){ 00146 do{ 00147 /* Wait until the decryption is finished. */ 00148 }while(!AES_interrupt_driver_finished(&interrupt_driver)); 00149 } 00150 00151 /* Check if decrypted answer is equal to plaintext. */ 00152 for(uint16_t i = 0; i < BLOCK_LENGTH * BLOCK_COUNT ; i++ ){ 00153 if (data_block[i] != block_ans[i]){ 00154 success = false; 00155 } 00156 } 00157 00158 if(success){ 00159 while(true){ 00160 /* If the example ends up here every thing is ok. */ 00161 nop(); 00162 } 00163 }else{ 00164 while(true){ 00165 /* If the example ends up here something is wrong. */ 00166 nop(); 00167 } 00168 } 00169 }
uint8_t block_ans[BLOCK_LENGTH *BLOCK_COUNT] |
Variable used to store decrypted plaintext from Cipher Block Chaining.
Definition at line 85 of file AES_example_interrupt.c.
Referenced by main().
uint8_t cipher_block_ans[BLOCK_LENGTH *BLOCK_COUNT] |
Variable used to store ciphertext from Cipher Block Chaining.
Definition at line 82 of file AES_example_interrupt.c.
Referenced by main().
uint8_t data_block[BLOCK_LENGTH *BLOCK_COUNT] |
Initial value:
{ "AVR1318: Using the XMEGA built-in AES accelerator." "This is a little textstring which will be encrypted" "and decrypted with CBC in the AES module." }
This data block need to be exactly [BLOCK_LENGTH * BLOCK_COUNT] bytes.
Definition at line 74 of file AES_example_interrupt.c.
Referenced by main().
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 67 of file AES_example_interrupt.c.
Referenced by main().
Definition at line 57 of file AES_example_interrupt.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 60 of file AES_example_interrupt.c.
uint8_t lastsubkey[BLOCK_LENGTH] |
Definition at line 64 of file AES_example_interrupt.c.
bool success |
Definition at line 88 of file AES_example_interrupt.c.
Generated on Wed Apr 23 08:53:42 2008 for AVR1318 Using the XMEGA built in AES accelerator by ![]() |