I wish to transfer data securely from an arduino (a microcontroller) to a server.
The obvious solution is probably to use TLS, but arduino does not have the capability to run it.
I did not find any other lightweight implementations either that could run on an arduino with the the needed features (encryption and authentication).
However, I have found implementations of both AES128-CBC and HMAC-SHA256 that can run on an arduino. I would like to use these algorithms.
The problem is that AES requires an initialization vector. This is hard to achieve using a microcontroller and I do not wish to string up some hardware random number generator.
Enter the danger zone:
Ask the server to generate one for me.
Assuming there are two keys that both the arduino and the server have in memory:
- Send some sort of HELLO SERVER packet to the server
- The server generates a random initialization vector using /dev/random, appends a HMAC-SHA256 hash to it, and sends it back to the arduino.
- The arduino verifies the received IV with the HMAC-SHA256 hash.
- The arduino encrypts the plaintext using AES128-CBC (with the IV it received) and then runs it through HMAC-SHA256, appending the resulting hash to the ciphertext.
- Arduino sends the result to the server
- The server verifies the HMAC and then decrypts the ciphertext using the IV it remembers.
Does this sound viable at all?
Would I need to use two unique pre-shared keys? One for AES and the other for HMAC? Does using one key only make the security of AES dependent on SHA256?
Are there other ways to achieve what I want without additional hardware?
Disclaimer: This is just for fun learning purposes: my temperature data isn't that sensitive.