This file provides an example for the AES on AVR32 UC3 devices.
Definition in file aes_example.c.
#include "board.h"
#include "print_funcs.h"
#include "gpio.h"
#include "pm.h"
#include "intc.h"
#include "usart.h"
#include "aes.h"
Go to the source code of this file.
Defines | |
#define | AES_EXAMPLE_REFBUF_SIZE 16 |
Board-Related Example Settings | |
#define | AES_EXAMPLE_LED1 LED0_GPIO |
#define | AES_EXAMPLE_LED2 LED1_GPIO |
#define | AES_EXAMPLE_LED3 LED2_GPIO |
#define | AES_EXAMPLE_LED4 LED3_GPIO |
#define | AES_EXAMPLE_USART (&AVR32_USART1) |
#define | AES_EXAMPLE_USART_BAUDRATE 57600 |
#define | AES_EXAMPLE_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION |
#define | AES_EXAMPLE_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN |
#define | AES_EXAMPLE_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION |
#define | AES_EXAMPLE_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN |
Example internal states | |
#define | AES_EXAMPLE_STATE_1 0 |
#define | AES_EXAMPLE_STATE_2 1 |
#define | AES_EXAMPLE_STATE_3 2 |
#define | AES_EXAMPLE_STATE_4 3 |
#define | AES_EXAMPLE_STATE_5 4 |
#define | AES_EXAMPLE_STATE_6 5 |
#define | AES_EXAMPLE_STATE_7 6 |
#define | AES_EXAMPLE_STATE_8 7 |
Functions | |
static void | aes_int_handler (void) |
The AES interrupt handler. | |
static void | init_hmatrix (void) |
Initializes the HSB bus matrix. | |
int | main (void) |
The main function. | |
Variables | |
const unsigned int | CBCRefInputData [AES_EXAMPLE_REFBUF_SIZE] |
const unsigned int | CBCRefOutputData [AES_EXAMPLE_REFBUF_SIZE] |
volatile unsigned int | ccountt0 |
volatile unsigned int | ccountt1 |
const unsigned int | CipherKey256 [8] |
volatile unsigned char | ContinueCBCProcess = TRUE |
const unsigned int | InitVectorCBC [4] |
volatile unsigned int | OutputData [AES_EXAMPLE_REFBUF_SIZE] |
pm_freq_param_t | pm_freq_param |
volatile unsigned char | state = 0 |
volatile unsigned long | Tempo |
volatile unsigned char | urad_evt = FALSE |
static const gpio_map_t | USART_GPIO_MAP |
static const usart_options_t | USART_OPTIONS |
#define AES_EXAMPLE_LED1 LED0_GPIO |
#define AES_EXAMPLE_LED2 LED1_GPIO |
#define AES_EXAMPLE_LED3 LED2_GPIO |
#define AES_EXAMPLE_LED4 LED3_GPIO |
#define AES_EXAMPLE_REFBUF_SIZE 16 |
#define AES_EXAMPLE_STATE_1 0 |
#define AES_EXAMPLE_STATE_2 1 |
#define AES_EXAMPLE_STATE_3 2 |
#define AES_EXAMPLE_STATE_4 3 |
#define AES_EXAMPLE_STATE_5 4 |
#define AES_EXAMPLE_STATE_6 5 |
Definition at line 136 of file aes_example.c.
#define AES_EXAMPLE_STATE_7 6 |
Definition at line 137 of file aes_example.c.
#define AES_EXAMPLE_STATE_8 7 |
#define AES_EXAMPLE_USART (&AVR32_USART1) |
#define AES_EXAMPLE_USART_BAUDRATE 57600 |
Definition at line 107 of file aes_example.c.
#define AES_EXAMPLE_USART_RX_FUNCTION AVR32_USART1_RXD_0_0_FUNCTION |
Definition at line 104 of file aes_example.c.
#define AES_EXAMPLE_USART_RX_PIN AVR32_USART1_RXD_0_0_PIN |
Definition at line 103 of file aes_example.c.
#define AES_EXAMPLE_USART_TX_FUNCTION AVR32_USART1_TXD_0_0_FUNCTION |
Definition at line 106 of file aes_example.c.
#define AES_EXAMPLE_USART_TX_PIN AVR32_USART1_TXD_0_0_PIN |
Definition at line 105 of file aes_example.c.
static void aes_int_handler | ( | void | ) | [static] |
The AES interrupt handler.
Definition at line 249 of file aes_example.c.
References AES_EXAMPLE_LED1, AES_EXAMPLE_LED2, AES_EXAMPLE_LED3, AES_EXAMPLE_LED4, AES_EXAMPLE_STATE_1, AES_EXAMPLE_STATE_2, AES_EXAMPLE_STATE_3, AES_EXAMPLE_STATE_4, AES_EXAMPLE_STATE_5, AES_EXAMPLE_STATE_8, aes_get_status(), aes_read_outputdata(), aes_swreset(), AES_URAT_READ_WRITEONLY, ccountt1, ContinueCBCProcess, OutputData, state, Tempo, and urad_evt.
Referenced by main().
00250 { 00251 ccountt1 = Get_system_register(AVR32_COUNT); 00252 if(AES_EXAMPLE_STATE_1 == state) 00253 { 00254 gpio_clr_gpio_pin(AES_EXAMPLE_LED1); 00255 // Read the output of the encryption process into OutputData[] (this will clear the DATRDY flag). 00256 aes_read_outputdata(&AVR32_AES, (unsigned int *)OutputData); 00257 state++; 00258 } 00259 else if(AES_EXAMPLE_STATE_2 == state) 00260 { 00261 gpio_clr_gpio_pin(AES_EXAMPLE_LED2); 00262 // Read the output of the encryption process into OutputData[] (this will clear the DATRDY flag). 00263 aes_read_outputdata(&AVR32_AES, (unsigned int *)OutputData); 00264 state++; 00265 } 00266 else if(AES_EXAMPLE_STATE_3 == state) 00267 { 00268 Tempo = aes_get_status(&AVR32_AES); 00269 if(Tempo & AVR32_AES_ISR_URAD_MASK) 00270 { 00271 urad_evt = TRUE; 00272 state++; 00273 if( AES_URAT_READ_WRITEONLY == ((Tempo & AVR32_AES_ISR_URAT_MASK)>>AVR32_AES_ISR_URAT_OFFSET )) 00274 gpio_clr_gpio_pin(AES_EXAMPLE_LED3); 00275 // The URAD and URAT fields of the AES status register can be reset only by 00276 // performing a sw reset of the AES module. 00277 aes_swreset(&AVR32_AES); 00278 } 00279 } 00280 else if(AES_EXAMPLE_STATE_4 == state) 00281 { 00282 gpio_clr_gpio_pin(AES_EXAMPLE_LED4); 00283 // Read the output of the decryption process into OutputData[] (this will clear the DATRDY flag). 00284 aes_read_outputdata(&AVR32_AES, (unsigned int *)OutputData); 00285 state++; 00286 } 00287 else if((AES_EXAMPLE_STATE_5 <= state) && (AES_EXAMPLE_STATE_8 >= state)) 00288 { 00289 // Read the output of the decryption process into OutputData[] (this will clear the DATRDY flag). 00290 aes_read_outputdata(&AVR32_AES, (unsigned int *)&OutputData[(state - AES_EXAMPLE_STATE_5)*4]); 00291 ContinueCBCProcess = TRUE; 00292 state++; 00293 } 00294 else 00295 while(1); 00296 }
static void init_hmatrix | ( | void | ) | [static] |
Initializes the HSB bus matrix.
Definition at line 301 of file aes_example.c.
Referenced by main().
00302 { 00303 // Set flashc master type to last default to save one cycle for 00304 // each branch. 00305 avr32_hmatrix_scfg_t scfg; 00306 00307 scfg = AVR32_HMATRIX.SCFG[AVR32_HMATRIX_SLAVE_FLASH]; 00308 scfg.defmstr_type = AVR32_HMATRIX_DEFMSTR_TYPE_LAST_DEFAULT; 00309 AVR32_HMATRIX.SCFG[AVR32_HMATRIX_SLAVE_FLASH] = scfg; 00310 }
int main | ( | void | ) |
The main function.
It sets up the USART module on EXAMPLE_USART. The terminal settings are 57600 8N1. Then it sets up the interrupt handler and waits for a USART interrupt to trigger.
Definition at line 320 of file aes_example.c.
References AES_CBC_MODE, aes_configure(), AES_ECB_MODE, AES_EXAMPLE_REFBUF_SIZE, AES_EXAMPLE_STATE_1, AES_EXAMPLE_STATE_2, AES_EXAMPLE_STATE_4, AES_EXAMPLE_STATE_8, AES_EXAMPLE_USART, aes_int_handler(), aes_isr_configure(), AES_KEY_SIZE_128, AES_KEY_SIZE_256, AES_PMODE_CIPHER, AES_PMODE_DECIPHER, aes_set_initvector(), aes_set_key(), aes_start(), AES_START_MODE_AUTO, AES_START_MODE_MANUAL, aes_write_inputdata(), CBCRefInputData, CBCRefOutputData, ccountt0, ccountt1, aes_config_t::CFBSize, CipherKey256, ContinueCBCProcess, aes_config_t::CounterMeasureMask, aes_isrconfig_t::datrdy, init_hmatrix(), InitVectorCBC, aes_config_t::KeySize, aes_config_t::LodMode, aes_config_t::OpMode, OutputData, pm_freq_param, aes_config_t::ProcessingDelay, aes_config_t::ProcessingMode, aes_config_t::StartMode, state, Tempo, aes_isrconfig_t::urad, urad_evt, USART_GPIO_MAP, and USART_OPTIONS.
00321 { 00322 aes_isrconfig_t AesIsrConf; // AES interrupts config structure 00323 aes_config_t AesConf; // AES config structure 00324 unsigned int CipherKey[8]; // CipherKey array 00325 unsigned int InputData[4]; // Input data array 00326 unsigned char TestResult = TRUE; 00327 unsigned int i; 00328 00329 00330 00331 #if BOARD == EVK1104 00332 if( PM_FREQ_STATUS_FAIL==pm_configure_clocks(&pm_freq_param) ) 00333 while(1); 00334 #endif 00335 00336 init_hmatrix(); 00337 00338 // Assign GPIO to USART. 00339 gpio_enable_module(USART_GPIO_MAP, 00340 sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0])); 00341 00342 // Initialize USART in RS232 mode. 00343 usart_init_rs232(AES_EXAMPLE_USART, &USART_OPTIONS, AES_EXAMPLE_CPU_FREQ); 00344 print(AES_EXAMPLE_USART, "\x1B[2J\x1B[H.: Using the AES :.\n\n"); 00345 00346 // Disable all interrupts. 00347 Disable_global_interrupt(); 00348 00349 // Initialize interrupt vectors. 00350 INTC_init_interrupts(); 00351 00352 // Register the AES interrupt handler to the interrupt controller. 00353 // aes_int_handler is the interrupt handler to register. 00354 // AVR32_AES_IRQ is the IRQ of the interrupt handler to register. 00355 // AVR32_INTC_INT0 is the interrupt priority level to assign to the group of 00356 // this IRQ. 00357 // void INTC_register_interrupt(__int_handler handler, unsigned int irq, unsigned int int_level); 00358 INTC_register_interrupt(&aes_int_handler, AVR32_AES_IRQ, AVR32_INTC_INT0); 00359 00360 // Enable all AES interrupts. 00361 AesIsrConf.datrdy = ENABLE; 00362 AesIsrConf.urad = ENABLE; 00363 aes_isr_configure(&AVR32_AES, &AesIsrConf); 00364 00365 // Enable all interrupts. 00366 Enable_global_interrupt(); 00367 00368 //**************************************************************************** 00369 // CIPHER IN MANUAL MODE: 00370 // - 128bit cryptographic key 00371 // - ECB cipher mode 00372 // - No counter measures 00373 // - input of 4 32bit words 00374 //**************************************************************************** 00375 print(AES_EXAMPLE_USART, "\n-----------------------------------\n"); 00376 print(AES_EXAMPLE_USART, "------ Cipher in Manual Mode ------\n"); 00377 print(AES_EXAMPLE_USART, " - 128bit cryptographic key\n"); 00378 print(AES_EXAMPLE_USART, " - ECB cipher mode\n"); 00379 print(AES_EXAMPLE_USART, " - No counter measures\n"); 00380 print(AES_EXAMPLE_USART, " - input of 4 32bit words\n"); 00381 print(AES_EXAMPLE_USART, "-----------------------------------\n"); 00382 00383 // Configure the AES. 00384 AesConf.ProcessingMode = AES_PMODE_CIPHER; // Cipher 00385 AesConf.ProcessingDelay = 0; // No delay: best performance 00386 AesConf.StartMode = AES_START_MODE_MANUAL; // Manual mode 00387 AesConf.KeySize = AES_KEY_SIZE_128; // 128bit cryptographic key 00388 AesConf.OpMode = AES_ECB_MODE; // ECB cipher mode 00389 AesConf.LodMode = 0; // LODMODE == 0 : the DATRDY flag 00390 // is cleared when one of the output data registers is read (because we're in 00391 // manual mode). 00392 AesConf.CFBSize = 0; // Don't-care because we're using the ECB mode. 00393 AesConf.CounterMeasureMask = 0; // Disable all counter measures. 00394 aes_configure(&AVR32_AES, &AesConf); 00395 00396 // Set the cryptographic key. 00397 // Key from FIPS-197 = 00010203 04050607 08090A0B 0C0D0E0F 00398 CipherKey[0] = 0x00010203; 00399 CipherKey[1] = 0x04050607; 00400 CipherKey[2] = 0x08090A0B; 00401 CipherKey[3] = 0x0C0D0E0F; 00402 aes_set_key(&AVR32_AES, CipherKey); 00403 00404 // The initialization vector is not used by the ECB cipher mode. 00405 00406 // Write the data to be ciphered to the authorized Input Data registers. 00407 // Plaintext from FIPS-197 = 00112233 44556677 8899AABB CCDDEEFF 00408 InputData[0] = 0x00112233; 00409 InputData[1] = 0x44556677; 00410 InputData[2] = 0x8899AABB; 00411 InputData[3] = 0xCCDDEEFF; 00412 aes_write_inputdata(&AVR32_AES, InputData); 00413 00414 ccountt0 = Get_system_register(AVR32_COUNT); 00415 // Start encryption. 00416 aes_start(&AVR32_AES); 00417 00418 // Wait for the end of the encryption process. 00419 while(AES_EXAMPLE_STATE_1 == state); 00420 00421 // Cipher result from FIPS-197 = 69c4e0d8 6a7b0430 d8cdb780 70b4c55a 00422 if(( 0x69c4e0d8 != OutputData[0] ) || ( 0x6a7b0430 != OutputData[1] ) 00423 || ( 0xd8cdb780 != OutputData[2] ) || ( 0x70b4c55a != OutputData[3] )) 00424 print(AES_EXAMPLE_USART, "\nKO!!!\n"); 00425 else 00426 { 00427 print(AES_EXAMPLE_USART, "\nOK!!! Nb cycles: "); 00428 print_ulong(AES_EXAMPLE_USART, ccountt1 - ccountt0); 00429 } 00430 00431 00432 //**************************************************************************** 00433 // CIPHER IN MANUAL MODE: 00434 // - 128bit cryptographic key 00435 // - ECB cipher mode 00436 // - All counter measures 00437 // - input of 4 32bit words 00438 //**************************************************************************** 00439 print(AES_EXAMPLE_USART, "\n-----------------------------------\n"); 00440 print(AES_EXAMPLE_USART, "------ Cipher in Manual Mode ------\n"); 00441 print(AES_EXAMPLE_USART, " - 128bit cryptographic key\n"); 00442 print(AES_EXAMPLE_USART, " - ECB cipher mode\n"); 00443 print(AES_EXAMPLE_USART, " - all counter measures\n"); 00444 print(AES_EXAMPLE_USART, " - input of 4 32bit words\n"); 00445 print(AES_EXAMPLE_USART, "-----------------------------------\n"); 00446 00447 // Configure the AES. 00448 AesConf.ProcessingMode = AES_PMODE_CIPHER; // Cipher 00449 AesConf.ProcessingDelay = 0; // No delay: best performance 00450 AesConf.StartMode = AES_START_MODE_MANUAL; // Manual mode 00451 AesConf.KeySize = AES_KEY_SIZE_128; // 128bit cryptographic key 00452 AesConf.OpMode = AES_ECB_MODE; // ECB cipher mode 00453 AesConf.LodMode = 0; // LODMODE == 0 : the DATRDY flag 00454 // is cleared when one of the output data registers is read (because we're in 00455 // manual mode). 00456 AesConf.CFBSize = 0; // Don't-care because we're using the ECB mode. 00457 AesConf.CounterMeasureMask = 31; // Enable all counter measures. 00458 aes_configure(&AVR32_AES, &AesConf); 00459 00460 // Set the cryptographic key. 00461 // Key from FIPS-197 = 00010203 04050607 08090A0B 0C0D0E0F 00462 CipherKey[0] = 0x00010203; 00463 CipherKey[1] = 0x04050607; 00464 CipherKey[2] = 0x08090A0B; 00465 CipherKey[3] = 0x0C0D0E0F; 00466 aes_set_key(&AVR32_AES, CipherKey); 00467 00468 // The initialization vector is not used by the ECB cipher mode. 00469 00470 // Write the data to be ciphered to the authorized Input Data registers. 00471 // Plaintext from FIPS-197 = 00112233 44556677 8899AABB CCDDEEFF 00472 InputData[0] = 0x00112233; 00473 InputData[1] = 0x44556677; 00474 InputData[2] = 0x8899AABB; 00475 InputData[3] = 0xCCDDEEFF; 00476 aes_write_inputdata(&AVR32_AES, InputData); 00477 00478 ccountt0 = Get_system_register(AVR32_COUNT); 00479 // Start encryption. 00480 aes_start(&AVR32_AES); 00481 00482 // Wait for the end of the encryption process. 00483 while(AES_EXAMPLE_STATE_2 == state); 00484 00485 // Cipher result from FIPS-197 = 69c4e0d8 6a7b0430 d8cdb780 70b4c55a 00486 if(( 0x69c4e0d8 != OutputData[0] ) || ( 0x6a7b0430 != OutputData[1] ) 00487 || ( 0xd8cdb780 != OutputData[2] ) || ( 0x70b4c55a != OutputData[3] )) 00488 print(AES_EXAMPLE_USART, "\nKO!!!\n"); 00489 else 00490 { 00491 print(AES_EXAMPLE_USART, "\nOK!!! Nb cycles: "); 00492 print_ulong(AES_EXAMPLE_USART, ccountt1 - ccountt0); 00493 } 00494 00495 //**************************************************************************** 00496 // CHECKING THE UNSPECIFIED REGISTER ACCESS DETECTION 00497 //**************************************************************************** 00498 print(AES_EXAMPLE_USART, "\n-----------------------------------\n"); 00499 print(AES_EXAMPLE_USART, "------ Checking the URAD ------\n"); 00500 print(AES_EXAMPLE_USART, "-----------------------------------\n"); 00501 // Read a write-only register. 00502 Tempo = AVR32_AES.keyw1r; 00503 while(FALSE == urad_evt); 00504 print(AES_EXAMPLE_USART, "\nOK!!!\n"); // If we're here, the URAD IT triggered. 00505 // Check the AES_EXAMPLE_LED3 on the board to know if the URAT was correctly set. 00506 00507 //**************************************************************************** 00508 // DECIPHER IN AUTO MODE: 00509 // - 128bit cryptographic key 00510 // - ECB cipher mode 00511 // - No counter measures 00512 // - input of 4 32bit words 00513 //**************************************************************************** 00514 print(AES_EXAMPLE_USART, "\n-----------------------------------\n"); 00515 print(AES_EXAMPLE_USART, "------ Decipher in Auto Mode ------\n"); 00516 print(AES_EXAMPLE_USART, " - 128bit cryptographic key\n"); 00517 print(AES_EXAMPLE_USART, " - ECB cipher mode\n"); 00518 print(AES_EXAMPLE_USART, " - No counter measures\n"); 00519 print(AES_EXAMPLE_USART, " - input of 4 32bit words\n"); 00520 print(AES_EXAMPLE_USART, "-----------------------------------\n"); 00521 00522 // Configure the AES. 00523 AesConf.ProcessingMode = AES_PMODE_DECIPHER; // Decipher 00524 AesConf.ProcessingDelay = 0; // No delay: best performance 00525 AesConf.StartMode = AES_START_MODE_AUTO; // Manual mode 00526 AesConf.KeySize = AES_KEY_SIZE_128; // 128bit cryptographic key 00527 AesConf.OpMode = AES_ECB_MODE; // ECB cipher mode 00528 AesConf.LodMode = 0; // LODMODE == 0 : the DATRDY flag 00529 // is cleared when one of the output data registers is read (because we're in 00530 // auto mode). 00531 AesConf.CFBSize = 0; // Don't-care because we're using the ECB mode. 00532 AesConf.CounterMeasureMask = 0; // Disable all counter measures. 00533 aes_configure(&AVR32_AES, &AesConf); 00534 00535 // Enable the AES interrupt (they've been disabled when we did an AES swreset 00536 // during the previous test) 00537 aes_isr_configure(&AVR32_AES, &AesIsrConf); 00538 00539 // Set the cryptographic key. 00540 // Key from FIPS-197 = 00010203 04050607 08090A0B 0C0D0E0F 00541 CipherKey[0] = 0x00010203; 00542 CipherKey[1] = 0x04050607; 00543 CipherKey[2] = 0x08090A0B; 00544 CipherKey[3] = 0x0C0D0E0F; 00545 aes_set_key(&AVR32_AES, CipherKey); 00546 00547 // The initialization vector is not used by the ECB cipher mode. 00548 00549 // Write the data to be deciphered to the authorized Input Data registers. 00550 // Use the result from the previous cipher process. 00551 AVR32_AES.idata1r = OutputData[0]; 00552 AVR32_AES.idata2r = OutputData[1]; 00553 AVR32_AES.idata3r = OutputData[2]; 00554 ccountt0 = Get_system_register(AVR32_COUNT); 00555 AVR32_AES.idata4r = OutputData[3]; 00556 // NOTE: since we're in auto mode, the deciphering process will start as soon 00557 // as the correct number of input data is written. In this case, the process 00558 // should start when we write the fourth 32bit word. We do not use the 00559 // aes_write_inputdata() function so that we can insert the CPU cycle counter 00560 // register just before writing the last 32bit word to the input. 00561 00562 // Wait for the end of the deciphering process. 00563 while(AES_EXAMPLE_STATE_4 == state); 00564 00565 // Plaintext from FIPS-197 = 00112233 44556677 8899AABB CCDDEEFF 00566 if(( 0x00112233 != OutputData[0] ) || ( 0x44556677 != OutputData[1] ) 00567 || ( 0x8899AABB != OutputData[2] ) || ( 0xCCDDEEFF != OutputData[3] )) 00568 print(AES_EXAMPLE_USART, "\nKO!!!\n"); 00569 else 00570 { 00571 print(AES_EXAMPLE_USART, "\nOK!!! Nb cycles: "); 00572 print_ulong(AES_EXAMPLE_USART, ccountt1 - ccountt0); 00573 } 00574 00575 00576 //**************************************************************************** 00577 // CIPHER IN AUTO MODE: 00578 // - 256bit cryptographic key 00579 // - CBC cipher mode 00580 // - No counter measures 00581 // - input of 16 32bit words in RAM 00582 // - output of 16 32bit words in RAM 00583 //**************************************************************************** 00584 print(AES_EXAMPLE_USART, "\n-----------------------------------\n"); 00585 print(AES_EXAMPLE_USART, "------ Cipher in Auto Mode ------\n"); 00586 print(AES_EXAMPLE_USART, " - 256bit cryptographic key\n"); 00587 print(AES_EXAMPLE_USART, " - CBC cipher mode\n"); 00588 print(AES_EXAMPLE_USART, " - No counter measures\n"); 00589 print(AES_EXAMPLE_USART, " - input of 16 32bit words\n"); 00590 print(AES_EXAMPLE_USART, " - output of 16 32bit words\n"); 00591 print(AES_EXAMPLE_USART, "-----------------------------------\n"); 00592 00593 // Configure the AES. 00594 AesConf.ProcessingMode = AES_PMODE_CIPHER; // Cipher 00595 AesConf.ProcessingDelay = 0; // No delay: best performance 00596 AesConf.StartMode = AES_START_MODE_AUTO; // Auto mode 00597 AesConf.KeySize = AES_KEY_SIZE_256; // 256bit cryptographic key 00598 AesConf.OpMode = AES_CBC_MODE; // CBC cipher mode 00599 AesConf.LodMode = 0; // LODMODE == 0 : the DATRDY flag 00600 // is cleared when one of the output data registers is read (because we're in 00601 // auto mode). 00602 AesConf.CFBSize = 0; // Don't-care because we're using the CBC mode. 00603 AesConf.CounterMeasureMask = 0; // Disable all counter measures. 00604 aes_configure(&AVR32_AES, &AesConf); 00605 00606 // Set the 256bit cryptographic key. 00607 aes_set_key(&AVR32_AES, CipherKey256); 00608 00609 // Set the initialization vector. 00610 aes_set_initvector(&AVR32_AES, InitVectorCBC); 00611 00612 ccountt0 = Get_system_register(AVR32_COUNT); 00613 // Write the data to be ciphered to the authorized Input Data registers. 00614 for(i=0; i<AES_EXAMPLE_REFBUF_SIZE; i+=4) 00615 { 00616 while(FALSE == ContinueCBCProcess); 00617 ContinueCBCProcess = FALSE; 00618 AVR32_AES.idata1r = CBCRefInputData[i]; 00619 AVR32_AES.idata2r = CBCRefInputData[i+1]; 00620 AVR32_AES.idata3r = CBCRefInputData[i+2]; 00621 AVR32_AES.idata4r = CBCRefInputData[i+3]; 00622 // NOTE: since we're in auto mode, the ciphering process will start as soon 00623 // as the correct number of input data is written. In this case, the process 00624 // should start when we write the fourth 32bit word. 00625 } 00626 00627 // Wait for the end of the ciphering process. 00628 while(AES_EXAMPLE_STATE_8 >= state); 00629 00630 // Check the results of the encryption. 00631 for(i=0; i<AES_EXAMPLE_REFBUF_SIZE; i++) 00632 { 00633 if(OutputData[i] != CBCRefOutputData[i]) 00634 { 00635 TestResult = FALSE; 00636 break; 00637 } 00638 } 00639 if(FALSE == TestResult) 00640 print(AES_EXAMPLE_USART, "\nKO!!!\n"); 00641 else 00642 { 00643 print(AES_EXAMPLE_USART, "\nOK!!! Nb cycles: "); 00644 print_ulong(AES_EXAMPLE_USART, ccountt1 - ccountt0); 00645 } 00646 00647 SLEEP(AVR32_PM_SMODE_STATIC); 00648 while (TRUE); 00649 } 00650 }
const unsigned int CBCRefInputData[AES_EXAMPLE_REFBUF_SIZE] |
Initial value:
{ 0x6bc1bee2, 0x2e409f96, 0xe93d7e11, 0x7393172a, 0xae2d8a57, 0x1e03ac9c, 0x9eb76fac, 0x45af8e51, 0x30c81c46, 0xa35ce411, 0xe5fbc119, 0x1a0a52ef, 0xf69f2445, 0xdf4f9b17, 0xad2b417b, 0xe66c3710 }
Definition at line 144 of file aes_example.c.
Referenced by main().
const unsigned int CBCRefOutputData[AES_EXAMPLE_REFBUF_SIZE] |
Initial value:
{ 0xf58c4c04, 0xd6e5f1ba, 0x779eabfb, 0x5f7bfbd6, 0x9cfc4e96, 0x7edb808d, 0x679f777b, 0xc6702c7d, 0x39f23369, 0xa9d9bacf, 0xa530e263, 0x04231461, 0xb2eb05e2, 0xc39be9fc, 0xda6c1907, 0x8c6a9d1b }
Definition at line 163 of file aes_example.c.
Referenced by main().
volatile unsigned int ccountt0 |
volatile unsigned int ccountt1 |
const unsigned int CipherKey256[8] |
Initial value:
{ 0x603deb10, 0x15ca71be, 0x2b73aef0, 0x857d7781, 0x1f352c07, 0x3b6108d7, 0x2d9810a3, 0x0914dff4 }
Definition at line 183 of file aes_example.c.
Referenced by main().
volatile unsigned char ContinueCBCProcess = TRUE |
const unsigned int InitVectorCBC[4] |
Initial value:
{ 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f }
Definition at line 196 of file aes_example.c.
Referenced by main().
volatile unsigned int OutputData[AES_EXAMPLE_REFBUF_SIZE] |
pm_freq_param_t pm_freq_param |
Initial value:
{ .cpu_f = AES_EXAMPLE_CPU_FREQ, .pba_f = AES_EXAMPLE_CPU_FREQ, .osc0_f = FOSC0, .osc0_startup = OSC0_STARTUP }
Definition at line 230 of file aes_example.c.
Referenced by main().
volatile unsigned char state = 0 |
volatile unsigned long Tempo |
volatile unsigned char urad_evt = FALSE |
const gpio_map_t USART_GPIO_MAP [static] |
Initial value:
{ {AES_EXAMPLE_USART_RX_PIN, AES_EXAMPLE_USART_RX_FUNCTION}, {AES_EXAMPLE_USART_TX_PIN, AES_EXAMPLE_USART_TX_FUNCTION} }
Definition at line 215 of file aes_example.c.
Referenced by main().
const usart_options_t USART_OPTIONS [static] |
Initial value:
{ .baudrate = AES_EXAMPLE_USART_BAUDRATE, .charlength = 8, .paritytype = USART_NO_PARITY, .stopbits = USART_1_STOPBIT, .channelmode = USART_NORMAL_CHMODE }
Definition at line 221 of file aes_example.c.
Referenced by main().