Plain AES-128 implementation (Rijndael Algorithm) for embedded system and IoT module (Tested in Particle Photon). References of this implementation (Many thanks to them):
Project Nayuki: https://www.nayuki.io/page/cryptographic-primitives-in-plain-python
This implementation use sensor data from BME280 environmental sensor for plaintext. Added lines for send ciphertext via UDP and TCP/IP (Particle device only). Although it's resulted fair performance and good value of Avalanche Effect, but it can't be used for securing real IoT system because its vulnerabilities of using default mode (ECB mode) that can be analyzed with Side Channel Attack. This code is just for simplicity and readability to explain how AES algorithm is.
USE FOR EDUCATIONAL PURPOSE ONLY.
General: https://github.com/kokke/tiny-AES-c
Embedded system: https://tls.mbed.org/
ESP32: https://github.com/espressif/arduino-esp32/tree/master/tools/sdk/include/mbedtls
This lines is for TCP/IP and UDP function.
To define TCP/IP connection, you can change this line with your destination IP and port.
TCPClient client;
IPAddress tcpIP(192,168,43,113);
int tcpPort = 5050;
To define UDP connection, you can change this line.
UDP Udp;
IPAddress remoteIP(192,168,43,113);
int udpPort = 1337;
To send packet, you can use this line:
- For TCP/IP
if (client.connected())
{
client.write(enc);
}
- For UDP
if (Udp.sendPacket(enc, sizeof(enc), remoteIP, udpPort) < 0)
{
Serial.printlnf("Error");
}
Fore more line functions, you can explore in this reference:
Particle Docs. https://docs.particle.io/reference/device-os/firmware/photon/
View aes_upnocon.c file.
This test purpose is to find throughput and Avalanche Effect of the algorithm implementation in the system. The test results was taken from 10 times encryption.
The time of encryption can be measured with the formula below:For the throughput can be measured with this formula below:
Notes:
X-axis is encryption time (microseconds)
Y-Axis is troughput (bits/second)
This test purpose is to find how much energy used for one time encryption. The method used for this test is calculate Vshunt of the IoT modules such in the picture below.
The value of energy consumption is measured in 12 miliseconds time interval using oscilloscope. The results is the average of power and energy consumed for encryption in time interval.
The power needed for one cycle encryption process (12 miliseconds) can be measured with the formula below:And the energy needed for one cycle encryption can be measured with the formula below:
Notes:
X-axis is conditition (encrypt/idle)
Y-Axis is Energy consumption (milliJoules)
Abdelgawad, A., 2014. Distributed data fusion algorithm for Wireless Sensor Network. Miami, IEEE.
Elminaam, D. S. A., Kader, H. M. A. & Hadhoud, M. M., 2010. Evaluating The Performance of Symmetric Encryption Algorithms. International Journal of Network Security, 10(3), pp. 213-219.
Donnay, V. J., 2013. Solar Panels, Energy and Area Under the Curve Teacher Guide, Bryn Mawr: Bryn Mawr College.
Moreno, C. & Fischmeister, S., 2017. Accurate Measurement of Small Execution Times โ Getting Around Measurement Errors, Waterloo: University of Waterloo.