AES Encryption for Teensy 3.0

Status
Not open for further replies.
Hi there

I'm very interested in encryption for Teensy devices but also very much a novice.

Please could post more details about your AES implementation that you managed to get working?

I'm trying to implement RSA however AES would be a good start.

Many thanks

Andy
 
Hi

For some reason I decided to make cosmetic, not functional, changes to the library referenced previously replacing all occurrences of rijndael with AES. Apart from that the library is essentially unchanged.

It is not my work and I credit the author:

Philip J. Erdelsky
pje@efgh.com
http://www.alumni.caltech.edu/~pje/

and reference the source:
http://www.efgh.com/software/rijndael.htm

Anyway I have knocked up a demo sketch to get you on your way, I am also a novice so don't be too hard on me. I use the hardware serial output of the Teensy 3 for debugging so you may need to edit that to see some output but the code is self explanatory. Please post back any advances with your work as I am interested in hardening my encryption. I have zipped the sketch and library which was all tested on Arduino 1.0.5 with Teensyduino 1.16 and attached it, hope it helps you or others.

Copy the AES folder to \arduino-1.0.5\libraries folder, copy the AESDemo folder to your sketch folder and run it up

Have fun :)

Ex
 

Attachments

  • Zip.zip
    20 KB · Views: 462
Hi Ex

Thank you very much for taking the time to package your work. I'm very keen to have a look and see it working unfortunately I'm still waiting for my Teensy in the post so I have to be patient and wait. I'm good with modern programming and encryption concepts but a complete novice in C and C++ and especially in packaging these sketches. So you creating a starting sketch all packaged is great because I can then work on understanding it and can make tweaks if I can spot anything.

I'll give an update when I have the chance to use it :)

Thanks

Andy
 
Hi Ex

I've had a quick look at the library and it certainly looks like it should do the trick. What was the performance of the library like? How long did encryption and decryption take?

Thanks

Andy
 
Hi

I too am a complete novice with C and C++. I am a really a hobbyist programmer and write mainly in C# using the .NET framework so C and C++ are quite alien to me. I must admit I have never bench marked the performance as yet. I am encrypting small keyboard macros for saving to SD card and decrypting them when they are read back; the data volume is small so performance has not been an issue to date. I am writing a client server type application which is constantly evolving as I go so lots of debug code and little concern about performance as yet :).

With regard to taking the time to package it up I did this as others on this forum have spent their time helping me and have been very generous so I thought I should give something back.

If you are waiting for the Teensy and wish to use the sketch I sent as is you will need a TTL to USB converter or similar to connect the Teensy hardware serial to the PC. I prefer to use the hardware serial for debug output as you do not have to keep reconnecting every time you download. I am also using the software serial for my application so it is not available.

Anyway if you are interested this is what I use to connect the hardware serial to the PC:
http://www.amazon.co.uk/gp/product/B008AGDTA4

Cheap as chips and works great. As you can see from the link I am in the UK, not sure where you are. If you do get that cable you need to link the green cable to Pin0 and the white to Pin1 on the T3. If you are using the same USB hub for the Teensy and the TTL converter you don't need to connect the red or black wires. Find what serial port the TTL converter is on and connect to it with your a PC terminal emulator, set the baud to 38400, 8 databits, no parity and 1 stop bit

Hope that helps
Ex.
 
Last edited:
Hi Ex

I'm in the UK too. This device you mention, is my understanding correct that you are using that because it makes it easier to work with the Teensy 3.0 than connecting the micro USB cable? However I don't have to have it? Sounds like a useful purchase, just trying to get my head round it.

That performance sounds fine, I would only be looking at encrypting a small packet of information which it sounds like could be done very quickly. My preference is RSA encryption but due to performance I'm not sure how secure it will be because of the concessions I need to make. So at least this AES should definitely work and maybe I could combine it with my potentially weak RSA. I would probably look to add some kind of initialisation vector to the AES code if there isn't one already.

One of the scenario I'm catering for is that the device itself has been compromised. With AES the private key could be swiped. With a public key it wouldn't matter.

Cheers

Andy
 
Hi

The device is used to allow a permanent connection to the Teensy for debugging. Most users will use the software serial for this job, which in Windows will require a driver to be installed. However when new code is downloaded to the T3 the connection to the software serial is lost and must be reopened. By using hardware serial for debug output I can just leave my terminal window open on the PC and as soon as the T3 boots it can output serial debugging messages and I see them without worrying about timing issues. If using software serial you cannot connect to the T3 until after it boots and has opened the USB serial port. I use the software serial for communication between my PC application and the T3 and so it is not an option for me for debugging. The device is a couple of quid and well worth having even if you do not intend to use it yet. It does not replace the micro USB connection it is in addition.

To get over the private key issue I use a keypad and a PIN. I format the 2048 bytes of EEPROM with random data and use an algorithm to retrieve 16 bytes from the 2048 for the private key based on the PIN entered. If the PIN is entered 3 times incorrectly the EEPROM is wiped and the SD card data is effectively rendered garbage. It works for me at the moment. Had considered some kind of RFID or similar enhancement later.

Ex
 
Hi

I too am a complete novice with C and C++. I am a really a hobbyist programmer and write mainly in C# using the .NET framework so C and C++ are quite alien to me. I must admit I have never bench marked the performance as yet.
In Microsoft's .net for C#, I believe it's correct to say that all programs written from that environment compile to bytecode for the virtual machine interpreter (MS has their own names for these, e.g., common runtime environment). But my experience (limited it be) with this bytecode interpreter scheme is that C/C++ code written to run on the CPU rather than via the interpreter, is a 100 times faster, as is the case for most all bytecode interpreters, including, say, the one for Java on windows or linux.
Whenever I run a C program that doesn't need the interpreter, and does not use the windows GUI/graphics, I am ever dumbfounded how fast this kind of code runs on today's fast CPUs in PCs. When burdened with MS's interpreter, and the layer upon layer of abstractions in object-oriented-overdone, we see the lackluster response time in GUI programs. If only...
 
@Experimentalist - AES expert

Along the encryption lines ... this is a "tad off topic" but have you ever worked with 1-wire Atmel ATSHA204 on the Teensy 3?
I am trying to make this chip work on the T3 but due to timing it seems to not function.

https://www.sparkfun.com/products/11551
 
Last edited:
You should be able to use LibTomCrypt, which is written in ANSI C. It supports many ciphers, including AES and RSA.

Don't forget to use a chaining mode (I recommend CBC mode) and an IV (e.g. all zero's with CBC mode) when you use a block-cipher like AES.

Also, make sure you have sufficient entropy (from mouse movements or a noise diode, for example) to seed the CSPRNG (cryptographically secure pseudo-random number generator) which you use to generate encryption keys!
 
Last edited:
Sorry for the slow response, somehow unsubscribed from the thread. In answer to your question no I have not worked with any hardware based solutions and I really am no expert, just trying to help others as best I can in return for what others have done for me on this forum :0)
 
You should be able to use LibTomCrypt

Thanks for the pointer looks like a great piece of work and well worth investigating further. It also looks like I need to spend some time reading up on chaining modes and CSPRNG. It seems like the thread is turning into a general encryption on the Teensy thread which can only be a good thing. I originally went for AES as it was reasonably light weight but I was really just looking for options of protecting data on my SD card and a mechanism for rendering it useless if the project was stolen. I have recently restarted work on this project and any improvements can only be a good thing.
 
Status
Not open for further replies.
Back
Top