9
\$\begingroup\$

I am using an Arduino to read a keypad and open an electric strike upon keypad PIN entry. For this sketch I wanted to use some sort of lightweight encryption to store the PINs in EEProm. Does anyone know of such a library? I have heard it may be possible using TwoFish.

\$\endgroup\$

7 Answers 7

12
\$\begingroup\$

You don't want to encrypt passwords (PINs) -- you want to hash them. When someone enters a password, you hash that password, and compare the hash against the stored hash. The advantage to this method (used for over 30 years) is that even if someone gets hold of the source and the hashes, they still can't tell what PINs match the hashes, as long as you choose a strong enough hash function.

You don't want to implement encryption yourself -- you want to use someone else's library, particularly one with an open implementation that has been tested by a large community. Encryption is hard, testing is hard, and testing encryption is damned hard, so get someone else to do it for you.

You should checkout the AVR Crypto Library, which is licensed with GPLv3. There's also an implementation of Skein for AVR.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Upvoted -- A good resource, and this should be set as the answer to the question. \$\endgroup\$
    – Lou
    Nov 13, 2009 at 13:26
9
\$\begingroup\$

That link Hristos posted, while possibly useful, certainly doesn't count as "encryption". It's really only "obfuscation".

Proper cryptography is notoriously easy to get wrong, even for people who know the math.

In response to the original post - what are the attack methods that would let someone get access to the PINs in the EEProm? Surely if they've got that far into your electronics they can just "snip the red wire" and open the door?

If you somehow do have a system where attackers might get hold of the EEProm contents without already having enough access to open your door, you probably want to redesign it. You could look at one-way hash functions similar to Unix password hashing - that way the EEProm doesn't need t contain a decryption key - the problem is the search space for PINs is very small - if I can download the hashed version of the PIN, I can pretty quickly try all 10,000 possible PINs, I suspect any modern-ish laptop will run all of them in a few seconds.

\$\endgroup\$
1
  • \$\begingroup\$ I agree (and agreed above), a one way hash would be useful and if you are programming the system then you could make the pin as long as you want eg 8 digits gives 100 000 000 combinations, which should take much longer. \$\endgroup\$
    – Amos
    Nov 12, 2009 at 11:46
1
\$\begingroup\$

The problem I forsee is that if they can see your pins they can also see your program which encrypts/checks/decrypts your pins. Plus if they have your chip, can they not just alter the program to always give a positive result (effectively bypassing the check) for any pin entered.

\$\endgroup\$
1
\$\begingroup\$

How do you plan to decode the encrypted PINs, in order to check if the user entered a valid PIN? You'll need to store the decryption key...at which point if the attacker can read your eeprom, he can also read your flash to find the encryption key. Basically rendering your entire encryption completely useless. Also as the other people said, if he already has the ability to read your chip, he could just write a new program. Much simpler to just kick the door open, I doubt anyone would ever go to the trouble of trying to hack your chip.

\$\endgroup\$
1
\$\begingroup\$

Here is a method of simple encription in C that could easily be ported to the Arduino. This seems like the easiest way to encrypt data with the arduino's limited resources.

-EDIT- To keep the key out of your program you could make half of the PIN the key. This means that your program takes the key half of the PIN to decrypt the encrypted 1/2 PIN stored in EEProm. If the decrypted key from EEProm match the part of your pin that is not the key, the door would unlock. This would only work in a situation where it is not possible for the intruders to break down the door or reprogram the Arduino.

\$\endgroup\$
1
  • \$\begingroup\$ But if they have no access to your chip you don't need to encrypt the pin. \$\endgroup\$
    – Amos
    Nov 12, 2009 at 11:54
1
\$\begingroup\$

I hate not answering the question while asking another, but ...

Is there some reason why your device is not tamper proof? I've seen push button switches in screw holes implemented 'on the bench' to detect the kind of tampering you are worried about. Then .. here comes the kid with a butane micro torch that manages to get your chip without unscrewing anything (or damaging the chip).. somehow, he knew the design of your tamper proof system which (also, hopefully) includes detecting changes in ambient light and / or sound. When the cover comes off, both become quite different .. day or night.

If that's the case, it should be a two part system where the exposed pieces communicate with something where encryption is more easily implemented. Plus, checksums (help) account for the kid with the torch.

I think you are asking a screwdriver to be a hammer.

\$\endgroup\$
1
\$\begingroup\$

These comments are really spot-on. There's nothing wrong with trying to experiment to learn about encryption, but this isn't really a good project for learning such things. You really want a good textbook and a computer, and as @bigiain says, the math is notoriously easy to get wrong.

For a better understanding of how cryptography works and what you're up against, the Handbook of Applied Cryptography is excellent and free:

If you just want to secure your project, this is an inefficient way of doing so. If you're interested in cryptography, start with this book and a computer.

\$\endgroup\$
3
  • \$\begingroup\$ I understand cryptography, read Bruce Schneier, and have programmed for over twenty years. I understand the real threat is just breaking the door down and walking past any sort of Arduino controller. I just can't in good conscience install it with clear text PINs in teh EEProm if it can be avoided. Fly \$\endgroup\$
    – Fly
    Nov 12, 2009 at 16:25
  • \$\begingroup\$ There's any number of simple obfuscation methods that would be just as effective in this role if you want to avoid storing clear-text PINs. The responders above were only trying to help you understand what cryptography does and does not do. Here's an AES library: hoozi.com/Articles/AESEncryption.htm I'd also like to say that just because you've programmed for 20 years, it doesn't mean you "understand" cryptography. It is a totally different field. A 20-year auto mechanic is a skilled person, but I wouldn't expect him to design a CAN bus from scratch. Check your attitude, please. \$\endgroup\$
    – Lou
    Nov 13, 2009 at 13:26
  • \$\begingroup\$ Oh god... 20 years coding and you think it's possible to encrypt runtime data????? Quit. \$\endgroup\$
    – MickLH
    May 24, 2016 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.