Recently, I got my hands on the RTL8720DN development board. After spending some time testing the boardβs capabilities, I made a decision to make an RTL8720 version of Midbar. During the development process, Iβve discovered that although this board is equipped with a decent library for the ILI9341 display and has enough memory for several lock screens, it doesnβt seem to have a functioning random number generator, and it lacks the support for the rotary encoder and the PS/2 keyboard. To compensate for these insufficiencies, I paired the RTL8720DN with Arduino and made the Arduino handle the input devices and random number generation.
Eventually, I developed a version of Midbar that can store sixteen login credentials and ten credit cards in the RTL8720DNβs flash, all encrypted by the βAES + Blowfishβ encryption algorithm in the cipher block chaining (CBC) mode.
As for why this project is called MidbarβββMidbar (ΧΧΧΧ¨) is a Hebrew word that means βpasture, β βuninhabited land, β βwilderness, β βlarge tracts of wilderness (around cities), β and βdesert.β I had two reasons for choosing the word Midbar as the name of this project. Firstβββwhile working on my previous projects, I noticed that the so-called βdevice that keeps your personal data secure in an encrypted formβ market is pretty much a βdesert around the oasis of the password manager market.β SecondβββI couldnβt find a better word to describe this project. At first, I wanted to call it a βPassword Vault, β but itβs more than that. So, I decided to call it Midbar.
You can also read this tutorial on Instructables and Medium.
AES + Blowfish Encryption Algorithm in CBC ModeInitially, I wanted to use the β3DES + AES + Blowfish + Serpentβ encryption algorithm to encrypt and decrypt the user data. Unfortunately, the RTL8720DN refused to work with the implementation of the Serpent that Iβm familiar with. Therefore Iβve changed the encryption algorithm for that version of Midbar.
The βAES + Blowfishβ encryption algorithm in cipher block chaining mode encrypts the data in 128-bit blocks. To reduce the size of the record stored in the RTL8720DNβs flash, Iβve allotted a single IV for a record.
Flash PartitioningIβve learned from the mistakes I made in the Midbar (ESP8266 Version) and Midbar (Teensy 4.1 Version) V2.0 and partitioned Flash better this time. Additionally, I have optimized the usage of the encryption algorithm to reduce the amount of space taken up by ciphertexts.
For comparison:
Midbar (ESP8266 Version) was only able to store eight login credentials and four credit cards;
Midbar (Teensy 4.1 Version) V2.0 was able to store sixteen login credentials (in its EEPROM);
Midbar (RTL8720DN Version) is able to store sixteen login credentials and ten credit cards in its Flash.
EEPROM Integrity CheckSince thereβs not much space available in the RTL8720DNβs flash, Iβve decided not just to allot a single IV for a record but also to verify the integrity of the whole flash area utilized by the Midbar instead of individually verifying the integrity of each record.
That feature came from Midbar (Teensy 4.1 Version) V2.0.
Prepare the SoftwareYou need to set up the Arduino IDE before flashing the RTL8720DN. You can read about it here:
https://www.amebaiot.com/en/amebad-bw16-arduino-getting-started/
Download FirmwareYou can download the firmware for Midbar from one of these sources.
SourceForge: https://sourceforge.net/projects/midbar/
GitHub: https://github.com/Northstrix/Midbar
If you just need the firmware for the device alongside the RNG, then I would advise you to download the archive that weighs less than 2Mb either from SourceForge or the code section down below.
But if you need the firmware for all versions of Midbar alongside the extra code, photos, and diagrams, in that case, I would advise you to download the 224 MB archive from GitHub.
Download and Install the LibrariesEncButton: https://github.com/GyverLibs/EncButton
PS2KeyAdvanced: https://github.com/techpaul/PS2KeyAdvanced
PS2KeyMap: https://github.com/techpaul/PS2KeyMap
The process of unpacking libraries is typical. You can unpack the content of the archive into the folder: β¦\Arduino\libraries. Or open the Arduino IDE, click to the Sketch -> Include Library -> Add.ZIP Libraryβ¦ and select every archive with libraries.
Other required libraries are already present in one way or another.
Generate KeysTo make the unauthorized deciphering of your data computationally infeasibleβββIt is crucial to generate your own keys and never reuse them
Itβs entirely up to you how to generate the keys. I can only offer you an option to do so.
Iβve modified one of my previous projects to work as a random number generator, the generated output seems βrandom enoughβ for me, but I havenβt run any tests. So, I canβt guarantee that itβs random.
Use it at your own risk!
To generate the keysβββlaunch gen.exe from the βRTL8720DN Version\V1.0\Untested RNGβ folder and click the βGenerate keys for Midbarβ button. The background turns from dark gray to light gray when you press that button.
Modify FirmwareOpen the βFirmware_for_RTL8720DN.inoβ file from the βRTL8720DN Version\V1.0\Firmware_for_RTL8720DNβ folder, and then replace my keys with those youβve generated.
Upload the Modified Firmware Into RTL8720DNUpload the modified firmware from the βRTL8720DN Version\V1.0\Firmware_for_RTL8720DNβ folder into RTL8720DN.
Flash ArduinoUpload firmware from the βRTL8720DN Version\V1.0\Firmware_for_Arduinoβ folder into Arduino.
Assemble MidbarAssembling the Midbar shouldnβt be hard. In my opinion, the most tangled part of the process is to connect the encoder with its periphery the right way.
As for the possible component replacements:
- You can replace 4.7k resistors with 2.2kβββ10k resistors;
- And you can replace the capacitors with 22nfβββ100nf capacitors.
After powering the Midbar up, you should see the word βΧΧΧΧ¨β alongside the βMidbar RTL8720DNβ and βPress Any Keyβ inscriptions.
Press any key to get to the next tab.
*Credit for photos:
Photo by Jakob Rosen on Unsplash
Photo by Robert Bye on Unsplash
Image by JORGE TAPIA from Pixabay
Photo by Samuel Agbetunsin on Unsplash
Photo by Morgan Petroski on Unsplash
Photo by Tommaso Scalera on Unsplash
Photo by Micah Camper on Unsplash
Photo by Albert Stoynov on Unsplash
Photo by Claudio Schwarz on Unsplash
Set Master PasswordTo use the Midbar, you first need to set the master password.
You canβt change your master password without performing the factory reset first!
Midbar wonβt be able to decrypt your data without your master password because the keys for the encryption algorithms are partially derived from it. Perhaps, it wonβt even unlock without the correct master password.
When youβre done entering your master password, either quad-click the encoder button or press the βEnterβ on the PS/2 keyboard.
After youβve unlocked the vault and got to the main menu:
- Either turn the rotary encoder to the right or press the βββ (DOWNWARDS ARROW) key on the PS/2 keyboard to go down the menu.
- Either turn the rotary encoder to the left or press the βββ (UPWARDS ARROW) key on the PS/2 keyboard to go up the menu.
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard to open the selected menu.
- While in the submenu, press either the βBβ button or the βEscβ key on the PS/2 keyboard to return to the main menu.
While entering a text in a tab:
- Either quad-click the encoder button four or press βEnterβ on the PS/2 keyboard to continue;
- Either quintuple-click the encoder button (click it five times in quick succession) or press the βEscβ button on the PS/2 keyboard to cancel the current operation.
*If the hex value decreases when you rotate the encoder to the right, I would advise you to swap the wires connected to the Arduinoβs β10β and β11β pins.
Add LoginAs Iβve mentioned earlier in this tutorial, this version of Midbar has the ability to store up to 16 login credentials.
To add a login:
- Select the βLoginsβ line in the main menu;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard;
- Select the βAddβ line;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard;
- Choose the slot you want to put the login to either by rotating the encoder or by pressing the βββ (Leftwards Arrow) and βββ (Rightwards Arrow) keys on the PS/2 keyboard;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard;
- Enter the username;
- Either quad-click the encoder button or press βEnterβ on the PS/2 keyboard;
- Enter the password;
- Either quad-click the encoder button or press βEnterβ on the PS/2 keyboard;
- Enter the website;
- Either quad-click the encoder button or press βEnterβ on the PS/2 keyboard.
*All credentials demonstrated here are entirely fictitious. Any similarity to actual credentials is purely coincidental.
View LoginTo view a login:
- Select the βLoginsβ line in the main menu;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard;
- Select the βViewβ line;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard;
- Choose the slot you want to view login from either by rotating the encoder or by pressing the βββ (Leftwards Arrow) and βββ (Rightwards Arrow) keys on the PS/2 keyboard;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard;
- Press either the βAβ key on the PS/2 keyboard or the βAβ button to print the record to the serial terminal.
*All credentials demonstrated here are entirely fictitious. Any similarity to actual credentials is purely coincidental.
Delete LoginTo delete a login:
- Select the βLoginsβ line;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard;
- Select the βDeleteβ line;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard;
- Select the login you would like to delete either by rotating the encoder or by pressing the βββ (Leftwards Arrow) and βββ (Rightwards Arrow) keys on the PS/2 keyboard;
- Press either the βAβ button or the βEnterβ key on the PS/2 keyboard.
The process of working with credit cards is very similar to the process of working with logins.
Find a Good Use for MidbarSure, Midbar (RTL8720DN Version) isnβt perfect, has some flaws, and involves a bit odd workaround that allows it to function. But nevertheless, itβs a fully functional tool for storing your login credentials and credit cards in an encrypted form.
And while Midbar is no guarantee of world peace or social harmony, I do believe that itβs an important contribution to the protection of your data from unauthorized access.
I think itβs also worth mentioning that Midbarβs source code is distributed under the MIT license. That grants you the freedom to customize, adapt and modify Midbar according to your needs and preferences. In other words, you can create your own version of Midbar or use it as a starting point for building new projects without the need for external permission.
If you found this tutorial to be useful, please consider sharing it.
Thank you for reading this tutorial.













_3u05Tpwasz.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)
Comments