AES128 CBC encryption/decryption problem on arduino mega2560

I use this library to https://github.com/DavyLandman/AESLib

here is the code

#include <AESLib.h>
void setup() {
Serial.begin(57600);
Serial.println(“Welcome to Encryption”);
uint8_t key = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//168 = 128 bytes
uint16_t in[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
uint8_t IV[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
char data[] = “The wifi Password is Bobby8990!.”; //chars == bytes
unsigned long start1 = micros();//When the timer starts running before encryption
//aes128_enc_single(key, data);// encryption algorithm
//aes128_enc_multiple(key, data, in);//multiple encryption algorithm
aes128_cbc_enc(key, IV, data, in);//multiple cbc (single calls)
Serial.println(“encrypted:”);
for (int i=0; i<sizeof(data);i++)
{
Serial.print(data
&0xFF, HEX);*
}
Serial.println(" ");
unsigned long diff1 = micros() - start1;// End time - start time
Serial.println(diff1);// Overall time used for encryption
unsigned long start2 = micros(); // timer starts running for decryption
//aes128_dec_single(key, data);
//aes128_dec_multiple(key, data, in);
aes128_cbc_dec(key, IV, data, in);
Serial.println(“decrypted:”);
Serial.println(data);
Serial.println(“Decryption time”);
unsigned long diff2 = micros()- start2;
Serial.println(diff2);
Serial.println(“Time difference”);
Serial.println(diff2-diff1);// time for encryption and decryption to occur.
Serial.println(“Total time”);
Serial.println(diff2+diff1);
}
void loop(){
}
The program works very well with data size 16,24 but it is not properly working for 32 all in Arduino Mega2560
but the program works perfectly well in Arduino Uno
i would like to know if i am the one doing nonsense.

DO NOT double post. See your other post for how to proceed, after reading the "How to use this forum" post.

Here is my code I have a problem running 32 char data on Mega, it works well with (16 and 24).
But the mystery is that the 32 char data works on Uno.
https://github.com/DavyLandman/AESLib i download the library from here.

#include <AESLib.h>
void setup() {
 Serial.begin(57600);
 Serial.println("Welcome to Encryption"); 
//uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//16*8 = 128 bytes
//uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
uint16_t in[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
uint8_t IV[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
char data[] = "The wifi password is Bobby8990!."; //chars == bytes
  unsigned long start1 = micros();//When the timer starts running before encryption
 //aes128_enc_single(key, data);// encryption algorithm
//aes128_enc_multiple(key, data, in);//multiple encryption algorithm
 aes128_cbc_enc(key, IV, data, in);//multiple cbc (single calls) 
// aes256_enc_single(key, data);
//aes256_enc_multiple(key, data, in);
  Serial.println("encrypted:");
  for (int i=0; i<sizeof(data);i++)
  {
  Serial.print(data[i]&0xFF, HEX);
  }
  Serial.println(" ");
  unsigned long diff1 = micros() - start1;// End time - start time
  Serial.println(diff1);// Overall time used for encryption
  unsigned long start2 = micros(); // timer starts running for decryption
 // aes128_dec_single(key, data);
//aes128_dec_multiple(key, data, in);
aes128_cbc_dec(key, IV, data, in);
 //aes256_dec_single(key, data);
//aes256_dec_multiple(key, data, in);
  Serial.println("decrypted:");
  Serial.println(data);
  Serial.println("Decryption time");
  unsigned long diff2 = micros()- start2;
  Serial.println(diff2);
  Serial.println("Time difference");
  Serial.println(diff2-diff1);// time for encryption and decryption to occur.
  Serial.println("Total time");
  Serial.println(diff2+diff1);
}
void loop(){
}[code]
  uint16_t in[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  aes128_cbc_enc(key, IV, data, in); //multiple cbc (single calls)
/Users/john/Documents/Arduino/sketch_may10a/sketch_may10a.ino:14:35: warning: invalid conversion from 'uint16_t* {aka unsigned int*}' to 'uint16_t {aka unsigned int}' [-fpermissive]
   aes128_cbc_enc(key, IV, data, in);//multiple cbc (single calls)
                                   ^
In file included from /Users/john/Documents/Arduino/sketch_may10a/sketch_may10a.ino:1:0:
/Users/john/Documents/Arduino/libraries/AESLib/AESLib.h:26:6: note:   initializing argument 4 of 'void aes128_cbc_enc(const uint8_t*, const uint8_t*, void*, uint16_t)'
 void aes128_cbc_enc(const uint8_t* key, const uint8_t* iv, void* data, const uint16_t data_len);
      ^~~~~~~~~~~~~~

You seem to be passing the array 'in' to the 4th argument to aes128_cbc_enc() which is declared: const uint16_t data_len. That seems like a mistake.

so i should rename it or change the value.

olasco79:
so i should rename it or change the value.

You are passing the wrong KIND of value so it is clear you are passing the wrong value. You should look at the documentation or examples for aes128_cbc_enc() to see what value you are supposed to be passing.
The name implies that the value is a ‘length’. If you pass a bogus value you are likely to get unexpected results, including failures that vary by platform.

Thank you i figure it out.