freaklabs / chibiArduino

A lightweight wireless sensor library for Arduino
https://freaklabs.org/chibiarduino/
83 stars 33 forks source link

AES Encryption/Decryption Swapped #5

Open onizenso opened 9 years ago

onizenso commented 9 years ago

I was reading source in for the AES encryption and decryption function, and it looks like you have gotten the purpose of the functions mixed up (unless I am misunderstanding something).

In the chb_aes_encryption function, you have plaintext as write data and ciphertext as read data. That's just semantically incorrect. Encryption functions read plaintext and write ciphertext. The reverse is also true in your chb_aes_decryption function.

With AES in ECB mode, the encryption machine is inversely reversible. But using the ciphertext buffer for writing in an encryption function can't be a good idea. At the very least, its very confusing.

freaklabs commented 9 years ago

Thanks for the feedback and nice catch. I don't think it's been a heavily used function so there hasn't been much peer review of it. I'll re-examine the encryption part of the code since I will be using it in a project in the future.

onizenso commented 9 years ago

Hey no problem, it just hit me weird.

I really enjoy using your library in my current project. Hopefully, when I get more familiar I can add some significant features/fixes/attacks.

This weird 'bug' is the only thing I've wrong with the library. The comments and coding style have really helped simplify the more complex interactions with the Freakduino.

edit: I'm looking forward to what you find in the AES en/decryption functions.