Problem running AES library on Arduino DUE

Hello,

I am trying to run this code:

#include <AESLib.h>

void setup() 
{
   // put your setup code here, to run once:
   Serial.begin(57600);

   uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
   char data[] = "0123456789012345"; //16 chars == 16 bytes

   unsigned long start = micros();
   aes128_enc_single(key, data);
   unsigned long end = micros();
   Serial.print("encrypted:");
   Serial.println(data);
   unsigned long delta = end - start;
   Serial.println("Encryption time in usec:");
   Serial.println(delta);

   start = micros();
   aes128_dec_single(key, data);
   end = micros();
   Serial.print("decrypted:");
   Serial.println(data);
   delta = end - start;
   Serial.println("Dencryption time in usec:");
   Serial.println(delta);
}

void loop()
{
  
}

taken from this library:

AES_library

on Arduino DUE, but when compiling I get this error:

. . . 

In file included from C:\Users\alex\Documents\Arduino\libraries\AESLib-master\aes_dec-asm_faster.S:28:0:

C:\Users\alex\Documents\Arduino\libraries\AESLib-master\avr-asm-macros.S:31:20: fatal error: avr/io.h: No such file or directory

 #include <avr/io.h>

                    ^

compilation terminated.
 . . .

Can someone tell me what to do?

Thank you...

Can someone tell me what to do?

Compile and link the code for the type of board (AVR) that it was written for.

Compiled for Arduino UNO ---> everything ok
Compiled for Arduino MEGA 2560 ----> not ok
Compiled for Arduino DUE ----> not ok

So maybe I should modify it to run in 32-bit ? But why not running on 8-bit Arduino MEGA 2560 R3 ?

Maybe your installation is corrupt, 'cause there is no reason why it does not work for MEGA 2560.

zwieblum:
Maybe your installation is corrupt, 'cause there is no reason why it does not work for MEGA 2560.

How do I fix that?

Reinstall arduino.

Nothing changed, but I found another AES library that runs on DUE...

I did a few experiments with this library: http://utter.chaos.org.uk/~markt/AES-library.zip

on Arduino DUE. I changed the part of the code here:

void prekey_test_var_plaintext (int bits)
{
  Serial.println () ;
  Serial.print ("ECB Varying Plaintext ") ;
  Serial.print (bits) ;
  Serial.println (" bits") ;
  Serial.println () ;
 
  byte succ ;
  set_bits (bits, key, 0) ;  // all zero key
  succ = aes.set_key (key, bits) ;
  if (succ != SUCCESS)
    Serial.println ("Failure set_key") ;


  for (int bitcount = 1 ; bitcount <= 128 ; bitcount++)
    {
      Serial.print ("COUNT = ") ; Serial.println (bitcount-1) ;
      print_value ("KEY = ", key, bits) ;
      set_bits (128, plain, bitcount) ;
      
      print_value ("PLAINTEXT = ", plain, 128) ;

      unsigned long start = micros();
      succ = aes.encrypt (plain, cipher) ;
      unsigned long end_ = micros();
      
      if (succ != SUCCESS)
        Serial.println ("Failure encrypt") ;

      print_value ("CIPHERTEXT = ", cipher, 128) ;

      unsigned long delta = end_ - start;
      Serial.println("Encryption time in usec:");
      Serial.println(delta);

      
      start = micros();
      succ = aes.decrypt (cipher, check) ;
      end_ = micros();
      
      if (succ != SUCCESS)
        Serial.println ("Failure decrypt") ;

      //print_value ("CHECK = ", check, 128) ;
      check_same (plain, check, 128) ;
      Serial.println () ;
    }
}

and I use micros in order to calculate encryption time. I get these results:

COUNT = 0
KEY = 00000000000000000000000000000000
PLAINTEXT = 80000000000000000000000000000000
CIPHERTEXT = 3ad78e726c1ec02b7ebfe92b23d9ec34
Encryption time in usec:
95

COUNT = 1
KEY = 00000000000000000000000000000000
PLAINTEXT = c0000000000000000000000000000000
CIPHERTEXT = aae5939c8efdf2f04e60b9fe7117b2c2
Encryption time in usec:
95

COUNT = 2
KEY = 00000000000000000000000000000000
PLAINTEXT = e0000000000000000000000000000000
CIPHERTEXT = f031d4d74f5dcbf39daaf8ca3af6e527
Encryption time in usec:
97

COUNT = 3
KEY = 00000000000000000000000000000000
PLAINTEXT = f0000000000000000000000000000000
CIPHERTEXT = 96d9fd5cc4f07441727df0f33e401a36
Encryption time in usec:
95

This guy here: new AES library - Libraries - Arduino Forum

on post #2 gets:

128 bit, ECB, encryption  0.58ms / block (27.5kB/s) which metered on us is 580us. This is a huge difference between 16MHz 8-bit cpu and 32-bit 84MHz cpu or I am missing something??

What I mean is that this AES code running on ATmega328p, 16MHz 8-bit takes 0.58ms = 580us to complete encryption, and when running on my DUE 84MHz, 32-bit 95us. And I am curious if this is really an obvious result, or I did something wrong on the implementation I posted in my previous post...

Thank you...