00001
00050 #include "avr_compiler.h"
00051 #include "AES_driver.h"
00052
00053 #define BLOCK_LENGTH 16
00054 #define BLOCK_COUNT 9
00055
00056
00057 AES_interrupt_driver_t interrupt_driver;
00058
00059
00060 uint8_t key[BLOCK_LENGTH] = { 0x94, 0x74, 0xB8, 0xE8, 0xC7, 0x3B, 0xCA, 0x7D,
00061 0x28, 0x34, 0x76, 0xAB, 0x38, 0xCF, 0x37, 0xC2};
00062
00063
00064 uint8_t lastsubkey[BLOCK_LENGTH];
00065
00067 uint8_t init[BLOCK_LENGTH] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
00068 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
00069
00074 uint8_t data_block[BLOCK_LENGTH * BLOCK_COUNT] =
00075 {
00076 "AVR1318: Using the XMEGA built-in AES accelerator."
00077 "This is a little textstring which will be encrypted"
00078 "and decrypted with CBC in the AES module."
00079 };
00080
00082 uint8_t cipher_block_ans[BLOCK_LENGTH * BLOCK_COUNT];
00083
00085 uint8_t block_ans[BLOCK_LENGTH * BLOCK_COUNT];
00086
00087
00088 bool success;
00089
00090 int main(void)
00091 {
00092
00093 success = true;
00094
00095
00096
00097
00098 AES_software_reset();
00099
00100
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
00110 PMIC.CTRL |= PMIC_LOLVLEN_bm;
00111
00112
00113 sei();
00114
00115
00116 success = AES_interrupt_driver_start(&interrupt_driver, AES_INTLVL_LO_gc);
00117
00118 if(success){
00119 do{
00120
00121 }while(!AES_interrupt_driver_finished(&interrupt_driver));
00122 }else{
00123 while(true){
00124
00125 nop();
00126 }
00127 }
00128
00129
00130
00131 success = AES_lastsubkey_generate(key, lastsubkey);
00132
00133
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
00143 success = AES_interrupt_driver_start(&interrupt_driver, AES_INTLVL_LO_gc);
00144
00145 if(success){
00146 do{
00147
00148 }while(!AES_interrupt_driver_finished(&interrupt_driver));
00149 }
00150
00151
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
00161 nop();
00162 }
00163 }else{
00164 while(true){
00165
00166 nop();
00167 }
00168 }
00169 }
00170
00171
00173 ISR(AES_INT_vect)
00174 {
00175
00176 AES_interrupt_handler(&interrupt_driver);
00177 }