Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not the same result while repeating the same operation #18

Open
Raphyyy opened this issue Jul 26, 2017 · 14 comments
Open

Not the same result while repeating the same operation #18

Raphyyy opened this issue Jul 26, 2017 · 14 comments

Comments

@Raphyyy
Copy link

Raphyyy commented Jul 26, 2017

Hi, thank you for your work :)

Environment : ESP8266 12E

I tested your librairy 3 times on the same string, but the results are not the same on each.

Here's my code :

#include <AES.h>
#include <Base64.h>

AES aes;

byte key[] = {0x4C, 0x7E, 0x19, 0x16, 0x28, 0x87, 0xD2, 0xA8, 0xAB, 0xF1, 0x15, 0x88, 0x02, 0xCF, 0x4E, 0x3C};
byte iv[] = {0x46, 0xc5, 0x12, 0x05, 0x3f, 0x1c, 0xc7, 0x1d, 0x2a, 0xa1, 0x27, 0xcd, 0xab, 0x7d, 0xcc, 0x9a};

char* message1 = "pmscnv687,232o,0";
char* message2 = "pmscnv687,232o,0";
char* message3 = "pmscnv687,232o,0";

void setup() {
  Serial.begin(115200);
  Serial.println("Booting...");  

  char encryptMsg1[200];
  encryptAES(message1, encryptMsg1);
  Serial.println(encryptMsg1);

  char encryptMsg2[200];
  encryptAES(message2, encryptMsg2);
  Serial.println(encryptMsg2);

  char encryptMsg3[200];
  encryptAES(message3, encryptMsg3);
  Serial.println(encryptMsg3);
}

void encryptAES(char* message, char* output)
{
  aes.set_key(key, sizeof(key));
  
  byte cipher[300];
  char b64data[300];

  memset(cipher, 0x00, 300);
  memset(b64data, '\0', 300);

  Serial.println("===");
  Serial.printf("%s , %d\n", message, strlen(message));

  //int b64len = base64_encode(b64data, message, strlen(message));
  // Encrypt! With AES128, our key and IV, CBC and pkcs7 padding    
  aes.do_aes_encrypt((byte*)message, strlen(message), cipher, key, 128, iv);
  base64_encode(output, (char*)cipher, aes.get_size());
}

Here the output :

===
pmscnv687,232o,0 , 16
rxUZg7tFONY5TjW8Kk6ehw==
===
pmscnv687,232o,0 , 16
hC/xnjNW7EiVgLM7u60bmw==
===
pmscnv687,232o,0 , 16
gm9YHW9WE8XPWRZEoJgTqg==

The first result is ok while decrypting, the 2 others are not.

I try to initialize the AES object in my encryptAES() function, I had the same result.

If I reset the sketch, I have exactly the same output.

@spaniakos
Copy link
Owner

spaniakos commented Jul 26, 2017 via email

@Raphyyy
Copy link
Author

Raphyyy commented Jul 27, 2017

Thanks a lot for doing that.
Could you please tell me an approximate day when it could be fixed ?
It's for an important project and I came accross all Github but your solution seems to be the only one which permit an AES128 CBC and include a padding to crypt variable length message.

@spaniakos
Copy link
Owner

spaniakos commented Jul 27, 2017 via email

@alxferraz
Copy link

Looking forward the next steps in ESP8266! Thanks for the lib! It's Great!

@spaniakos
Copy link
Owner

spaniakos commented Aug 11, 2017 via email

@spaniakos
Copy link
Owner

actually I think that you might have found a little bug there, still trying to understand it ^^

@pbabics
Copy link

pbabics commented Apr 2, 2018

Hello, was there any success with adding support for esp8266 ? I looked at this issue and the problem seems to be that iv passed to do_aes_encrypt gets modified on every call, it is used internally as a buffer for a block.

Maybe I'm not getting the issue, but i can be solved by passing a copy of iv,
something like:

void encryptAES(char* message, char* output)
{
  aes.set_key(key, sizeof(key));
 
  byte temp_iv[sizeof(iv)];
  memcpy(temp_iv, iv, sizeof(iv));
 
  byte cipher[300];
  char b64data[300];

  memset(cipher, 0x00, 300);
  memset(b64data, '\0', 300);

  Serial.println("===");
  Serial.printf("%s , %d\n", message, strlen(message));

  //int b64len = base64_encode(b64data, message, strlen(message));
  // Encrypt! With AES128, our key and IV, CBC and pkcs7 padding    
  aes.do_aes_encrypt((byte*)message, strlen(message), cipher, key, 128, temp_iv);
  rbase64_encode(output, (char*)cipher, aes.get_size());
}

Tested on ESP8266-01

@ghost
Copy link

ghost commented Aug 16, 2018

Hello,
Good Day !!!
Has a solution been found for the issue ?
Even I am not getting a proper output?
Are there any criteria for the input text ?
Following is the sample run on Ubuntu:-

===testng mode

PLAIN :abcdefghij1234567890ABCDEFGHIJ

�C�I�C�B�>����P|N��$����۪

Plain2:abcdefgiij1234577890ABCDEFGHIJ

============================================================
Thanks.

@spaniakos
Copy link
Owner

spaniakos commented Aug 16, 2018 via email

@ghost
Copy link

ghost commented Aug 16, 2018

@spaniakos
Hello,
Where can I send you the code files ?
Thanks.

@spaniakos
Copy link
Owner

spaniakos commented Aug 16, 2018 via email

@spaniakos
Copy link
Owner

@HitChand
are you using ESP8266 or NodeMCU?

@ghost
Copy link

ghost commented Aug 18, 2018 via email

@spaniakos
Copy link
Owner

i will check it on a NodeMCU, i am expecting mine to come between 21st and 31st of august (got 2 NodeMCU) that i need for a project.
Since NodeMCU have an ESP8266 core, and since ESP8266 core has a known BUG with my printf.h file i need to mode the library and make it ESP8266/NodeMCU compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants