matthijskooijman / arduino-lmic

:warning: This library is deprecated, see the README for alternatives.
705 stars 651 forks source link

AES understanding #177

Closed ghost closed 6 years ago

ghost commented 6 years ago

I transmit several times the same message "ABC" but each time I receive different data on server-side. I'm using the original AES encryption set in config.h. However, I don't understand where the 256-bits key is stored (in ../aes/lmic.c ?) and why my data are encrypted differently for each transmission? Is there a way to decrypt my data?

I've also observed that each time I reset the arduino, I reset the encryption "loop". I guess there is a loop mechanism that change the 256-bits key according to the Tables found in aes/lmic.c. Am I right ?

Exemple :

Original message : "ABC"

1st data received : "CfGy" 2nd data received : "LutR" 3rd data received : "boOp" --> Arduino Reset 4th data received : "CfGy" 5th data received : "LutR" 6th data received : "boOp"

matthijskooijman commented 6 years ago

However, I don't understand where the 256-bits key is stored (in ../aes/lmic.c ?)

The key is stored in the AESKEY variable:https://github.com/matthijskooijman/arduino-lmic/blob/ba1265d5d2f775177cdc7c82186724e4f0bdc3a8/src/lmic/oslmic.h#L73 and accessed using the AESkey macro: https://github.com/matthijskooijman/arduino-lmic/blob/ba1265d5d2f775177cdc7c82186724e4f0bdc3a8/src/lmic/oslmic.h#L74

and why my data are encrypted differently for each transmission?

I suspect that the headers (in particular the frame counter) is used in the encryption process.

Is there a way to decrypt my data?

There might be possibilities, depending on the server-side software you use, but I have not specific suggestions. All of the encryption applied is of course specified in the LoRaWAN specification, which is available for free and might help you figure this out.