spaniakos / AES

AES for microcontrollers (Arduino & Raspberry pi)
http://spaniakos.github.io/AES/
GNU Affero General Public License v3.0
126 stars 55 forks source link

padedLength and time #31

Closed PabloGN closed 5 years ago

PabloGN commented 5 years ago

padedLength error in aes.pde (Arduino code) When plainLength doesn't need to round up (plainLength % N_BLOCK == 0) padedLength is greater than plainLength.

int plainLength = sizeof(plain)-1;  // don't count the trailing /0 of the string !
int padedLength = plainLength + N_BLOCK - plainLength % N_BLOCK;
int padedLength = plainLength;
if (plainLength % N_BLOCK !=0)
     padedLength += N_BLOCK - plainLength % N_BLOCK;

Time measure Serial.println(micros() - ms); adds the time to send printed string. It should be:

endtime=micros();
Serial.println( endtime - ms);
spaniakos commented 5 years ago

you are correct about the time , i will fix that.

now about the padded length plainLength % N_BLOCK == 0 the standard for encryption on PKCS7 padding (including AES CSB) is to always pad at least 1 byte. if the plaintext is equal to a multiple of N_BLOCK then a full block of padding is added.

https://tools.ietf.org/html/rfc2315 page 21, section 2

PabloGN commented 5 years ago

Thank you!