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.
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.
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.
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.
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.
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.
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.
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.