STM32 Key Part 1 — DES implementation

This is the first part of the STM32 Key series. For your convenience you can find other parts using the links below (or by guessing the address):
Part 1 — DES implementation
Part 2 — Chat application
Part 3 — ARP, IP, UDP
Part 4 — Server

Today we start a new series in which we will make an encryption key using STM32 microcontroller. Let’s begin.


We assume that we want to communicate with someone in the same LAN and we would like to have our traffic completely encrypted. We get two identical STM32 microcontrollers to use them as an encryption keys — we stick one of them in our machine, our friend does the same with his own. Next, we send packet from our machine to STM, it encrypts it and sends to another STM which in turn decrypts it and delivers to friend application.

Since this is just an academic project (I was implementing it few years ago during my CS studies), we don’t want to over-engineer it so we will use DES as an encryption algorithm and we will only handle UDP traffic. Also, here and there we will hard-code some things just to make them easier but also (what’s more important) to not exceed the limit of source code allowed in free environment.

This is the idea, implementation will be a little different. We will have chat application operating in one of two modes: encryption and decryption. Encryption will take plaintext and send it to STM on port A. STM will encrypt the data and send it back from port B. Chat application in decryption mode will listen on port B and present received data in hex format. If we send anything from decryption chat, it will go to port B of STM, be decrypted there and sent back from port A. So we cant test STM on one machine.

I will not describe all the details since right now they are probably outdated. I will just focus on the core details of logic, not necessarily on the SPI communication and technical stuff.


DES is simple enough to be implemented in small amount of code and yet not too naive. Do not use it in production anymore since it is not secure but in academic environment we might ignore this little obstacle. The code goes like this:

The application works in one of two modes, it either encrypts or decrypts data.




In next part we are going to write very simple chat application using Java, Swing and Netbeans. So old!