A Lock That's Extremely Hard to Hack (Electronic Part)

by Northstrix in Circuits > Microcontrollers

344 Views, 3 Favorites, 0 Comments

A Lock That's Extremely Hard to Hack (Electronic Part)

IMG_20220405_160540.jpg

The idea behind this project is to make a lock that can be opened by many keys without having to store the keys themselves in its internal memory.

To implement that idea, I've designed a key generation algorithm that works very similarly to the way the cryptocurrency is mined. I've also implemented an advanced encryption algorithm to make this device much harder to hack.

Supplies

IMG_20220405_161545.jpg
  • ESP32 x1
  • MG90S Servo (or a more powerful one) x1
  • Button x1
  • 4.7K Resistor x1
  • 10µF capacitor x1 *optional

Key Generation Algorithm

First of all, let me explain what the word nonce means (at least in that context).

A nonce is literally a number used once. In that case, nonce consists of up to ten characters concatenated at the beginning of the string called tkn.

By default, values of all variables that compose the nonce are set to 31.

The nonce's value incremented as follows: increment the value of the left-most element until it reaches 126 - on the next incrementation, set it equal to 32 and perform a carry. Only variables with a value that is more than 31 are concatenated to the string.

To generate a valid key that can open the lock: the key generation algorithm creates the string called tkn and extracts the values of the ten variables that comprise the nonce.

Following that, the key generation algorithm enters a loop:

1) Clear the string called tkn;

2) Concatenate the prefix and the content of the string called spart (second part of the key) to the string called tkn;

3) Hash the string called tkn with SHA-512 hash function;

4) Check if the first four characters produced by the hash function are the same as the four characters specified in the code under the names acbcccdc (all zeroes by default). If the aforementioned holds true, then the string tkn is encrypted by the encryption algorithm shown in the next step and printed to the Serial Monitor in an encrypted form;

5) Increment the nonce;

6) Check if the button connected to the D15 pin is pressed. If the button is pressed, then save the values of the variables used to comprise the nonce, exit the loop, and consequently exit the function.


Encryption Algorithm

FH2BNZCKZCPKM30.png

This device utilizes AES-256 + Serpent + AES-256 encryption algorithm to encrypt and decrypt the keys from the lock. It requires three encryption keys to function: two keys for the AES and one key for Serpent. This algorithm takes eight characters (64 bits) and three encryption keys as an input, generates 192 random bits in the encryption process and produces a sixty-four-character string in the hexadecimal format as an output.

The encryption process goes as follows:

1) The algorithm takes an input string and splits it to blocks. The maximum length of a block is 8 characters;

2) If the length of an input block isn't equal to 8 characters (64 bits), then the padding is applied;

3) Input block is passed to the AES alongside 64 random bits;

4) AES encrypts obtained 128-bit block using the first key;

5) The result of the previous step is split into two equal 64-bit halves;

6) 64 random bits are concatenated to each half;

7) Each of the 128-bit halves is encrypted using Serpent;

8) Each ciphertext from the Serpent is encrypted using AES with the second key;

9) Concatenation of two ciphertexts produced by the AES using the second key is the resulting ciphertext.

Each AES's key is incremented each time after the algorithm uses that key. And by the way, if you give the algorithm the same input more than once, the output will be different every time.

Install CP210x Driver and Configure Arduino IDE *Optional

If you've never flashed ESP32 before you need to configure Arduino IDE and install CP210x driver to upload the firmware into the board, you can download the CP210x driver for ESP32 here: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers

Configuring IDE isn't a part of this tutorial. You can read about it here: https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/

Download Code From GitHub

gh.png

You can download the code here: https://github.com/Northstrix/Infragile_lock

The repository on GitHub contains the following: Firmware for the lock; Firmware to create all required files that are needed by the lock in order to function; Program to store the keys from the lock in the encrypted form; Untested RNG.

Download and Unpack the ESP32Servo Library

l.png

Download library here: https://github.com/madhephaestus/ESP32Servo

And then unpack the content of the archive into the folder: ...\Arduino\libraries.

Every other required library is already installed in one way or another.

Install ESP32 Filesystem Uploader

FRZ1QYCKWEYXY1H.png

The primary purpose of the ESP32 Filesystem Uploader is to let you upload files into ESP's filesystem. In this tutorial, the purpose of this tool is to upload an empty SPIFFS image into ESP.

Download the file called ESP32FS-1.0.zip from here: https://github.com/me-no-dev/arduino-esp32fs-plugin/releases/

then extract the content of the archive into the folder: ...\Arduino\Tools\

After that, restart the Arduino IDE.

Upload an Empty SPIFFS Image Into ESP

s.png

Click Tools -> ESP32 Sketch Data Upload. Then click Yes in the pop-up window. It's going to upload an empty SPIFFS image into the ESP. I have no rational explanation for that, but after that step, the file system finally begins to work as it's intended to.

Some boards will flash without any problems.

Unfortunately, that's not the case for all boards. If you configured IDE correctly, installed drivers, selected the corresponding port, and still keep getting this error: A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header. Connect a 10µF capacitor to the board while flashing.

Connect the positive lead of the capacitor to the EN pin of the ESP32;

Connect the negative lead of the capacitor (usually indicated by the gray stripe) to the GND pin of the ESP32.

Don't forget to disconnect the capacitor after the board flashes.

Upload the Firmware to Create Required Files Into ESP

f.png

To create all files that are required by the lock to function - upload the firmware from the folder Create_required_files into the ESP32.

If done correctly, you'll see the message Setup completed successfully! in the Serial Monitor.

Generate the New Unique Values for the Spart, *keys, Key, Second_key

g.png

At first, I wanted to throw a dice, but then I suddenly came up with a faster and more user-friendly solution. I've decided to modify one of my previous projects to generate all the required values. I did my best here, but I can't guarantee that the generated values are random.

To generate the new unique values for all four variables:

1) Launch gen.exe from the Untested RNG folder;

2) Click Action;

3) In the roll-down menu, click Generate unique values for the lock.

Modify the Firmware

md.png

Open the file called Firmware_for_the_lock.ino and replace the existing values with those you've generated.

Upload the Firmware Required for the Lock to Function Into ESP

mf.png

Upload the modified firmware from the folder Firmware_for_the_lock into the ESP32.

Assemble the Device

Circuit diagram.png

That shouldn't be hard. The device only has four components.

Set the Master Password and IV *optional

If you need more security, you can modify the encryption keys by setting the master password (12.Derive part of the key from the string) and then increment two of the keys by the desired number of times (10.Increment key (IV) n times).

If you decide to set the master password and IV, beware that you need to enter the same master password and IV every time you power up the device. Otherwise, the lock won't be able to decrypt the keys that you've generated earlier.

Generate the Keys for the Lock

k.png

To generate the keys for the lock: open the Serial Monitor, Enter 1 to the text field, and then press Send button.

The key generation process might take a while

Press the button connected to the D15 pin to stop the key generation process.

Even though you can generate a lot of keys, the maximum number of available keys is limited.

After the device tries all of the 95^10 combinations, it will stop the key generation process and show you the message No more combinations to try!

I left the device for 10 minutes and obtained these ciphertexts (encrypted keys).

508229de2de3f4b9e647392a5c84eb98c4b368c0a0f371e331aa6f077ea28b4fa601c10eda1b769fbe24f442de690e59398bf4ca9538a4dc747b48e658030ee0806bd0b185465716cb33373574c827dbd2979d58eaa9c1d36af52692926ca561a6417ebcc65baf83c7d6e04f0d2bd0caaaa223449dc8d7e8233f84fb618421727fb4a42e287f4cae4ef68e2f828a3b3089ff53e46a2586f722da1e450ed0a0dd187cdc262bbf9ea7ac5d721ca898da53237c27e406bc891c56f7c3d510291770ee23660cadcaea0ca840e532e8542a76558befba71018bd04827f391e751d55a60f367978186ccf68836200c449dc9422392cffb9d65005427c33b0e76886ff4af27d0a643d8d56bed402f889785f00da6dbd19d42d66aa0c847932ecacd6f7c08e166870ebeebd3e10994d4e1e82ae33d537892da0f12d7e9ba785514827527

f5534962534b50f56b5ecd32cb0867c59cfc1dbf11b8dc8e5b08d5352de8d20fbd63fe069acc8e213be75a5a42037d70439e957c32a9c51a73cf63664274553689d2ee7a2370c3027063473f6e3cead018b196345c5c1c735947a8050f502368370d6272ac700d1fec09d611d00203d6a381dd5f2385aa5a86de0377b4b0de6a615ffd95f36907598eecc13766a7e3a0dfff852adc4d7c4c094fc2f8231ac0bea7e9973b10ba206863f4c803d22410098cfee737adb359a93e77a8e789b4019497c8234a66152c3369e8a151d4434a318d754ee7e676f290f78d9d028e35764bb09b26e1a29e4a72f3f65d6d1bbb8dde2e33361e4959d083c30483281e4128f2858e0bf3e4270ba5d1213a84d1e24425563e28bc51897e34cb45c39c689bd5d1a89ed98b621c139b1e606883dbdadc63ca2c96fed7a4a3797b234d518730fa4e

d2c1ba8fc3134fe921550615d8f62f3883b2fcd0d3548a1f50bf34b4511cd79bf0f98cda927ad5875a0d84169c4742dfc76dca6ab4a860b3be426315599dfc5f433a7e1d8ad7ae5597831c74c55830a7c0fb2c77d610a96bcfdb44c93fecc186e7eb6e302cab9340233c5dae937fc6f8b7cd4783b47fcfba687762dd15744fd25769cbe951d1e0284981f1672f91ab3d2a951d7f3735f7f1baa7bf028e3ab31e898c5b3b7c7110cf65c99e03eed36e25567f0c98be9695ea7f22b9815fa4ca8c78ee8d772349f8b45364c14503335e6a00a3d44fb50d1d30603c3164e7239f88c1799333a42c401be77e3b08b1a888194298fe9e116e2b90600edc5b9e0f36480b349bcd96f92192e2eb268ecb1f10dc886a7229acb653d85c3d9a5deca16d874f8258c4810ad628afe64d415b1926729eac343a2eb2bc30ef8109e5501c9713

ddac6971fbf374697a98e75d17b44f0e41a854e939596584633d44e91f24fba9586e923f946ebca5dc7e87296820ba2afb47f529e57fad6acd0a983681ffae0f882208bcd8adbc2b7b80f950694bd9e10c5ce5527b1bf494200c0aae06e5a0d4360efc31df9dbb430ec4288b309e2c6a6ca320110b353eb384997e8ed3798a07a0c3ab043c6d5468debc03d2c9c1bda744d75f9a20829f51547262866c4e1571e7ebe873a100588ab4911414c3e8f1664896a97a679ef32e053437a1d6fa6fea265a3aab14d086288d9dd60315d6dc66a2dd83b91987b5df89a28be6a5c38a2e5bc3cbad2733c018836d960b77ed8cef42a5d8da320e9f5d03760b72f6795be9a2d81e5f2ab058f83ed654ddba67a3d7085514a8e230bc5458aaba10329c8b4d57a4edd1a62e621efd83d24fc6c8e0c1a06d9f286b230a0ff4b8ff637a107a27

e73b205b39db80aa36624854a3156e1ac7117f6c7a051eb0ac7756bc392a591ef8c39094784df74c85422744c59210c1613ef5cbe00af759e78e36eb27b14f5d3d796bff996c023d8abcf6f26af30410879fd23a48e490b2e8755c8f6541cf602541e2e69836bb3911aa742db4a17e00f5dfb0120d435961d185bac7aff8cff8689abe8351c75c6c1c9f16b3540c61149662a47261923e31f7091faf151c0feb2f3e1f9a1497e26131f55d33cbd25478fb59bca1313dffe955f051e0b19708ae27fe487ca2cf4daeab91ff101bec90863cce752c1828a667098661c03f800f412e6da954d4bef11797c75e2a414858a01c2430e0168bff7fde41535258c0a0138088bf97594ecf865256f5f46310e0bfcfb0147b73efca2d2305e5434412f7b38e132e6545acb4fb684938448c7e41d978286201d13ce978f24721f3fd29513b

a796f2b2e49a3f02fff3b8cffc5013ab926a65829d165543e1126aa23be56faec5457b6bf0a73e7cadb6417925c72243fd597bde2279143abc378c37a1b5ea04f92868d81bf4e6796500f4e1d73a96ba6afff34eed1c2353d10cdda3b959856a9b1518692b2bb6db4c41b6b3e938a6f73c7d7266d5e2a77892397f25b3b34bddf9b64f700f34752a8407b56f197baba59cd5095caf6b49e1494bfba7ed84ea5ebdbbaf62ebbf188e981ba7e5d87ebc780ba61d691712af173741813220403e41a491209c20f8b9a0b1bf86cb4c873bb5b3b71892fe26b74200eebf957b82a30096e98665ae288c7000a1fd13ac3373bafcb6996e47fe94352262c8d4ff46e1a97d646cf129bb5dd31a79d688101de81afc77c4cf2a47550090795bfb7637ffdba7ce54a7c2c7d0333a36fb1f2a9eda59bd516634e443026d966f423fad526c19

f6b53d17860666968171bd1bbea358766f428954ff7519b98b7dfba7340b684738bb3f027d0ee89292d23c788514554dd0ac2538685cc95e3890c2d4133aef375312a31179026a1758b4611f39125973a77b8f8cedc808f1ebad42a36d0429d3eefa28f69e72ccfd048b75d4e6c6497fd4d74e8c3c36f5b01b8fca92ee3f8c7f400a1785a36113629e91413f899b942920e06abc17df013fd201496c0b0df89fcd734dceaf05dc5a7aed28224073547c66b7d4d08bba5e83d5353bbbcd34da5e121f9412fb32aa4fb9f7886f8220a8a7377263608f6771d5dd71c88d7544696ee9f5216ffadeaee63ccb0437b1128b7e641f3889d5bd3371dad0e78b2d55891070bb52f58faff30959ea5096adb96d1e503587e87d3a66f2cc3b2919633de7f3c6fa75d3d86c86e91170c5fbe344adba8df8f6328bc7875a53fe15c806de6c4e

9c95721b2bbc6e6461d424f6967ccf7ba32133c677b54fe211c83a2e8160dfa075a534a3aba3c400401ff1356ccc4ad19d3e881c54b8a1469ceb70d84edf996c5935b10aaff62448e63d9cef596f2365db1a20cc1b216642c40c2615653c0f78c7560869c67418d2f1e0a1cdf42435a7311f6555ace6d9a90f2060436fb643f354f4ac585b589222cf7debe0948418777cd37714eed470e556b80de2b22d44b5d5c3ae98d1cb47ed3cb78ca428b8aac006eef2a8fbd4cbf897f649daa1d3c7dee729b0a2ac18aef6b8784ca69a05a3f92497381340d11a3f23c8902b6fd6fe58f109e39721fc55e869f8b2663779cf77077eef90d9817d776079a4ffc2946112bf19d8a5ecf5640aff3f570616dc8d74ad5ab29ab738a163ddd48f0533eca3620a6add718f1bd5477bce2378f25344ae32d4ca6a0063d194f581bef07c104dd4

9929ebd1447eedff55cec2d9b4599eec09f8e92c79f6c62d18abe2f45450630b75fc764dac56a31de2f9925e723dbffbc10be189f3b45ab563a194b8dced25c5218754a9446e9b384fb6211577a92b70d00afad1fff37e7309b496f51a68815c9d63b771e26260f254bcbb1ea7513995335cd4c6093737c9fc11fed4d08686a8ee3b3bbb74c3a26c50b240b9b9a36ce69de1a90d6c5ee53a7bec61122a9c3fcfb1a62dc0bd4fb24059fa816243511a84f4258bad2e466706bbe0e959596bfd9b4e4a01c325f32777c592637887356d4c6eb07fe3afd00c9adf1be657e7e347d1398c0886d8552e48f548a3a91059e3877b360eb4bd489969fc39cffce49387d4315f2504c7e55cdf4fc3ce3da673d69e52b8d243c7c3514c19eebffad6d90cbe8a875dbe3ee987c1c1fbaea2aa17e83ef70d847d110e935a0ef627ff7e0e2e2e

01618047c587f7b2f8ebfb75ddd725c21bd1f3a03edf136f065b690eebac0026b8f0a14cc9cbe43f7c51b39cd7171f86e2daa9de1bbbb1883807c3534ec827d79bb1383a30a2feb70d9b3423ea16e632ab85598a3fc38f76ca40cff1c44b6ae3624af3edc2cadadbdb3343a002424a7b608f42bac9b2b971811bd00b9585b9b6214fe93f39165f4d1610feeeb4e1eb0711b3a3c38f93c5a36414f17c295e232d7abe256b3b6ab63a163bc535155a1e9cb485e95b142d806427b6c1629691c7e8fd2d66113132f3481dc4185eca1f41ef4e721d1efd13f0c8b2851d6d56bb6b4404f382c5edd59c33a313be36f9f5547762fbcf27b304ecaddd680b84de816ba3c68251a034691f4f6c4e186db6f9fb70f355dcbadd82e57b911218a38383d4c60f60f1b32939cefa8afebaaf9dea6b14607c0308a4696d829f6b5c20d9ef2d47

0d9a07da7330d9c11558319598823da335b05d1726684d7519ae14c68cb44d2d90052cf14d9db57f252587666c2e126dc3d5252d75a1d86db3a1d8ea374bed80d8ff23b6b00da955f9ebe9b28632a5c6ffaa48ae19ec5c83bcb250ac6b9cd26250cc6e92be15efd414f2340bb50b52468e1febc0c330fb757e8e1680af47ef440a9ff91d6ea6ecae8479fa588f8b8ba609d11b7eb1781167e2b88cba7667cad5dc2ca1c7e88b684ec04021fa78f6a1e5705699f3b896dff08a70dffa93fb4d3321e9479e63919e8fcdb048b36728a46bdddfaca8a0d5e11c7f8c0d06dd17518f19322e51def6e3e5fc5c8390de4457047e498b2951f48b459e04a758b68717222e2f7013b6e7bd6044ba5b562eeadebb78588828544264ecbb153cc6deee21a782a749996a904f8a007e0eab5fa23586cb5d34dc43db454f162f454a7e00a574

1684472f44660d1fcdb02b949fa6cde8bd9f28dd6a01bae00248d6b4c2d333e2082eabd9fc2bb1a7291fb051bcd574e34834f2821d7f27c3b7a3df924f1fa6278eb737180a4c897a7f2c02e202278848bf6ba07b37bd673f73719e54736b183f1b788164f6ad819b832e24a1c90f9ccc24e7d9bdf07feff7be6d4fcfb0775e672033ffd274f154177b83df6bf5bfa08126b33e46397c1ab867f43cb75cd04de3f6b718ba8d13ac569f38adf087ddd9b2bddefc39c65cdadbb4a4d5659a8fabed5de1e5b58a24e103fa3faa647d0e5b41adc9a612baf0034e16de3efc3ef91dd1aa068fc7aa071d5a94e9f4a27221d3c7fe0dd61b4b9cda05c914530b6f68f412ce259f27009088eb3570da8b7b3b0f2e002eadb9836aab82b2765228b1fb84ac3b952f19e72428cd1e74b675752ba34999a3b2217220d16393e9380b867130de

c62cfa8421e12000354cea26190c8371a33b1edb42427bd1a2a216cadc93cb14b1c1b37a65015c5acb5d47f697d46e02f87cbc9036066a1feb231e21828e33ce94e0b7fc1935cd36d63560cdd97c1b63d6700ef56677cbc7c3c35ec74080f7db8e39c972422f4969e1ffa76d8167a0558476434694c1b0db94484e6390aa58cb7599bd581a66d9cca06c771b60231c760870f91b4fe9e3267afa148d11e626485fc2c5f7c76a5b02445539570c0f998606056528f5fd4387024b1fba5f7fe1cf894dad78d7fcab09bf0da817f2377c8e34f29b2a3a80c5dbfd597fc9a5914ea2825add71abf1cb55f76a1f38c147c818b8ccd70e94614424b311aeceb5c02ea61c4365fd35226c20c28e176c33591e96b74bfa05efad45888c69d0befbb2cc7f00140f7eadceae83ce877d31718eb4f3399c694931bcf8af71988afdf572a01a

574f528ce54a877e515f1a2a8c83dd7a09b6f67ba9b3252c82532879b58e2b3c68871d1263c06c60263998ccdc64948ea11d581386d34cc07f2d1e65ce4002ca2585bedabd4b20ccbb31321c9fba56e8fa3f676f8bf1922329f338fe67f9d64fb2f5b80e10b7d06d943dd61852b2b847e057f16b5ab29aa77ff1ac982a3f57c6edcd840d6ac45057a965f6729b5cd89778c8a2b6e966b63c225d1d527743cf6dc6141c2b9a1d8e7c61cd73f79c2e4fb843a397a0d32e8b329393a01eb415889e081ec277f2562fb3b86959c92908bdc36cdd619f4a2281f877164048b97b8cdee7bbf929ffb13b0ad0621130d80b82ff7fc62f97dca90cf5270bc5f166e57bd14e3150ff1c7f25b0498d54ccc9f557043a200976b5c28cb24bbe229fb9bc7a7467815f3979626c9a9e7ae72ee363014d08e1f8848d53f2d8649535efeb17f714

b28e8becdbf376ca54b856474815256a3d16cf75b9041dea5ce048749ff17df511a99bd11f7ff29cdcc8496d150af4bd9ab7dd705df49c7a2595212ad4fde355535e984dfc4ec45edd74ceabc985a47a5033d3c14c887f92221b2190d4917f2ee5d8dec52c5e0f446e73194492edd571adcf5218e4aecb056710362167e7e5787a4c0ac3d6ef09b374025e7bf02a159d4915c79aee1e892716603349db181d72d5587856eabe2e8f251e75416e83cb495ae1e59ea5c79298d83472d2baa76dd1337956b0bade3da93be67632cedbf5cfae5977e2f3ce5b36ffce65c7f072cfa97791b866a59b1413c19f3ec88917e005f941382cdf0063bf6cb0853b0d79dbeef0be3bad9fec5235079162df349357c7d66ae436eb9066dd607056c01297fb247d9d6f3d164fb0ccfb9c7a179d6ee96aa135e23c243a6f6c9689cd56cb35200c

Generate and Load the Key for the Database

1.png
2.png
3.png
4.png

Generating keys is one thing - securely storing them is another. I wrote a program to give the ability to securely store the keys in the encrypted database. You can find it in the folder called Key storage.

First of all, launch Key storage.exe

To generate the key for the database:

1) Click Encr. key;

2) In the roll-down menu, click Generate;

3) Choose where you want to save the key and specify the name for the newly generated key (I named mine - key.txt);

4) Press the Save button.


After that, you'll need to load the key to use the database, to do so:

1) Click Encr. key;

2) In the roll-down menu, click Load;

3) Navigate to the file with the key and select it;

4) Press the Open button.


You need to load the key every time you're launching the program.

Put the Key to the Database

db.png

Keys are stored in records.

Every record has two fields - one for the title (label) and one for the key.

To add a record to the database:

1) Load the key (if it's not loaded);

2) Click Record;

3) In the roll-down menu, click Add;

4) Set the title of the record and paste the key to the pop-up window;

5) Press Add.

Extract the Key From the Database

ext.png

To extract the key from the record:

1) Load the key (if it's not loaded);

2) Click Record;

3) In the roll-down menu, click Extract;

4) In the pop-up window, select the record you want to extract;

5) Press Extract;

6) Copy the extracted value from the pop-up window.


Remove Record From the Database

rm.png

To remove record:

1) Load the key (if it's not loaded);

2) Click Record;

3) In the roll-down menu, click Delete;

4) In the pop-up window, select the record you want to delete;

5) Press Delete.


List All Records That Are Stored in the Database

l1.png

To list all records that are stored in the database:

1) Load the key (if it's not loaded);

2) Click Record;

3) In the roll-down menu, click List all.


Extract All Records That Are Stored in the Database to the .csv File

l2.png

To export all records that are stored in the database to the .csv file:

1) Load the key (if it's not loaded);

2) Click Record;

3) In the roll-down menu, click Export all to the .csv file.

The file records.csv will appear in the folder with the executable file.


Open the Lock

ezgif-2-e6027329ed.gif

I did my best to make this lock as unhackable as possible. First and foremost the encrypted key is decrypted and sent to the hash function. Right after being passed to the hash function, the key is hashed with SHA-512 and at the same time compared with the value of the string called spart (second part of the key).

Following that, check if the first four characters produced by the hash function are the same as the four characters specified in the code under the names acbcccdc (all zeroes by default) and also check if the string with the key ends with the value from the string called spart. If the aforementioned holds true, then check if the key is blacklisted. If the key isn't in the black list then open the lock.

*If you've set the master password and IV at the moment of the key generation, then set the same master password and IV before opening the lock.

To open the lock:

1) Open the Serial Monitor;

2) Enter 2 to the text field;

3) Press Send;

4) Paste the encrypted key to the text field;

5) Press Send.

Press the button connected to the D15 pin to close the lock.

Blacklist the Key

bl.png

Let's suppose that you need to take a key out of circulation.

To do this:

1) Open the Serial Monitor;

2) Enter 3 to the text field;

3) Press Send;

4) Paste the encrypted key that you want to blacklist to the text field;

5) Press Send;

6) Enter the number of the slot (from 0 to 9) that you want to put the key in;

7) If you changed your mind and want to cancel the operation, clear the text field and enter c;

8) Press Send.

Now, let me explain in simple terms how the blacklisting process works.

When the lock generates the key, it passes the key to the encryption algorithm. After that, the lock gives that key to you. But instead of giving you the key itself, the lock gives you the safe with the key. When the lock blacklists the key, it first takes the key out of the safe and then puts it on the blacklist. Even if you put the blacklisted key in another safe, the lock will reject it. Because the lock doesn't care about the safe, it cares about the key that's in the safe.

Hopefully, that explanation is clear enough. Anyway, if you have any questions, you can ask them in the comment section.

If you try to open the lock with the blacklisted key, you'll get the message That key was taken out of circulation!

Find a Good Use for This Project

No matter how secure the electronic part is, it will be useless if you attach it to the weak physical lock. I wish I could design a reliable mechanic part too, but my mechanical skills are close to zero. So, I can only develop an electronic part and leave the rest to you.

I hope you'll be able to find a good use for this device.

If you like this tutorial, please share it.

Thank you for reading this tutorial.